1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ 6 #define ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/shelf/background_animator.h" 10 #include "ash/shelf/shelf_types.h" 11 #include "ash/system/tray/actionable_view.h" 12 #include "ui/compositor/layer_animation_observer.h" 13 #include "ui/views/bubble/tray_bubble_view.h" 14 15 namespace ash { 16 class ShelfLayoutManager; 17 class StatusAreaWidget; 18 class TrayEventFilter; 19 class TrayBackground; 20 21 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray, 22 // LogoutButtonTray, OverviewButtonTray. 23 // This class handles setting and animating the background when the Launcher 24 // his shown/hidden. It also inherits from ActionableView so that the tray 25 // items can override PerformAction when clicked on. 26 class ASH_EXPORT TrayBackgroundView : public ActionableView, 27 public BackgroundAnimatorDelegate, 28 public ui::ImplicitAnimationObserver { 29 public: 30 static const char kViewClassName[]; 31 32 // Base class for tray containers. Sets the border and layout. The container 33 // auto-resizes the widget when necessary. 34 class TrayContainer : public views::View { 35 public: 36 explicit TrayContainer(ShelfAlignment alignment); ~TrayContainer()37 virtual ~TrayContainer() {} 38 39 void SetAlignment(ShelfAlignment alignment); 40 set_size(const gfx::Size & size)41 void set_size(const gfx::Size& size) { size_ = size; } 42 43 // views::View: 44 virtual gfx::Size GetPreferredSize() const OVERRIDE; 45 46 protected: 47 // views::View: 48 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; 49 virtual void ChildVisibilityChanged(View* child) OVERRIDE; 50 virtual void ViewHierarchyChanged( 51 const ViewHierarchyChangedDetails& details) OVERRIDE; 52 53 private: 54 void UpdateLayout(); 55 56 ShelfAlignment alignment_; 57 gfx::Size size_; 58 59 DISALLOW_COPY_AND_ASSIGN(TrayContainer); 60 }; 61 62 explicit TrayBackgroundView(StatusAreaWidget* status_area_widget); 63 virtual ~TrayBackgroundView(); 64 65 // Called after the tray has been added to the widget containing it. 66 virtual void Initialize(); 67 68 // views::View: 69 virtual void SetVisible(bool visible) OVERRIDE; 70 virtual const char* GetClassName() const OVERRIDE; 71 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 72 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 73 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; 74 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 75 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; 76 77 // ActionableView: 78 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 79 virtual gfx::Rect GetFocusBounds() OVERRIDE; 80 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 81 82 // BackgroundAnimatorDelegate: 83 virtual void UpdateBackground(int alpha) OVERRIDE; 84 85 // Called whenever the shelf alignment changes. 86 virtual void SetShelfAlignment(ShelfAlignment alignment); 87 88 // Called when the anchor (tray or bubble) may have moved or changed. AnchorUpdated()89 virtual void AnchorUpdated() {} 90 91 // Called from GetAccessibleState, must return a valid accessible name. 92 virtual base::string16 GetAccessibleNameForTray() = 0; 93 94 // Called when the bubble is resized. BubbleResized(const views::TrayBubbleView * bubble_view)95 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} 96 97 // Hides the bubble associated with |bubble_view|. Called when the widget 98 // is closed. 99 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; 100 101 // Called by the bubble wrapper when a click event occurs outside the bubble. 102 // May close the bubble. Returns true if the event is handled. 103 virtual bool ClickedOutsideBubble() = 0; 104 105 // Sets |contents| as a child. 106 void SetContents(views::View* contents); 107 108 // Creates and sets contents background to |background_|. 109 void SetContentsBackground(); 110 111 // Sets whether the tray paints a background. Default is true, but is set to 112 // false if a window overlaps the shelf. 113 void SetPaintsBackground(bool value, 114 BackgroundAnimatorChangeType change_type); 115 116 // Initializes animations for the bubble. 117 void InitializeBubbleAnimations(views::Widget* bubble_widget); 118 119 // Returns the window hosting the bubble. 120 aura::Window* GetBubbleWindowContainer() const; 121 122 // Returns the anchor rect for the bubble. 123 gfx::Rect GetBubbleAnchorRect( 124 views::Widget* anchor_widget, 125 views::TrayBubbleView::AnchorType anchor_type, 126 views::TrayBubbleView::AnchorAlignment anchor_alignment) const; 127 128 // Returns the bubble anchor alignment based on |shelf_alignment_|. 129 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; 130 131 // Forces the background to be drawn active if set to true. 132 void SetDrawBackgroundAsActive(bool visible); 133 134 // Returns true when the the background was overridden to be drawn as active. draw_background_as_active()135 bool draw_background_as_active() const {return draw_background_as_active_; } 136 status_area_widget()137 StatusAreaWidget* status_area_widget() { 138 return status_area_widget_; 139 } status_area_widget()140 const StatusAreaWidget* status_area_widget() const { 141 return status_area_widget_; 142 } tray_container()143 TrayContainer* tray_container() const { return tray_container_; } shelf_alignment()144 ShelfAlignment shelf_alignment() const { return shelf_alignment_; } tray_event_filter()145 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } 146 147 ShelfLayoutManager* GetShelfLayoutManager(); 148 149 // Updates the arrow visibility based on the launcher visibility. 150 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); 151 152 private: 153 class TrayWidgetObserver; 154 155 // Called from Initialize after all status area trays have been created. 156 // Sets the border based on the position of the view. 157 void SetTrayBorder(); 158 159 // ui::ImplicitAnimationObserver: 160 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 161 162 // Applies transformations to the |layer()| to animate the view when 163 // SetVisible(false) is called. 164 void HideTransformation(); 165 166 // Unowned pointer to parent widget. 167 StatusAreaWidget* status_area_widget_; 168 169 // Convenience pointer to the contents view. 170 TrayContainer* tray_container_; 171 172 // Shelf alignment. 173 ShelfAlignment shelf_alignment_; 174 175 // Owned by the view passed to SetContents(). 176 TrayBackground* background_; 177 178 // Animators for the background. They are only used for the old shelf layout. 179 BackgroundAnimator hide_background_animator_; 180 BackgroundAnimator hover_background_animator_; 181 182 // True if the background gets hovered. 183 bool hovered_; 184 185 // This variable stores the activation override which will tint the background 186 // differently if set to true. 187 bool draw_background_as_active_; 188 189 // True if touch view feedback command line flag has been enabled. When 190 // enabled touch gestures will toggle rendering the background as active. 191 bool touch_feedback_enabled_; 192 193 scoped_ptr<TrayWidgetObserver> widget_observer_; 194 scoped_ptr<TrayEventFilter> tray_event_filter_; 195 196 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); 197 }; 198 199 } // namespace ash 200 201 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ 202