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 81 // BackgroundAnimatorDelegate: 82 virtual void UpdateBackground(int alpha) OVERRIDE; 83 84 // Called whenever the shelf alignment changes. 85 virtual void SetShelfAlignment(ShelfAlignment alignment); 86 87 // Called when the anchor (tray or bubble) may have moved or changed. AnchorUpdated()88 virtual void AnchorUpdated() {} 89 90 // Called from GetAccessibleState, must return a valid accessible name. 91 virtual base::string16 GetAccessibleNameForTray() = 0; 92 93 // Called when the bubble is resized. BubbleResized(const views::TrayBubbleView * bubble_view)94 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} 95 96 // Hides the bubble associated with |bubble_view|. Called when the widget 97 // is closed. 98 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; 99 100 // Called by the bubble wrapper when a click event occurs outside the bubble. 101 // May close the bubble. Returns true if the event is handled. 102 virtual bool ClickedOutsideBubble() = 0; 103 104 // Sets |contents| as a child. 105 void SetContents(views::View* contents); 106 107 // Creates and sets contents background to |background_|. 108 void SetContentsBackground(); 109 110 // Sets whether the tray paints a background. Default is true, but is set to 111 // false if a window overlaps the shelf. 112 void SetPaintsBackground(bool value, 113 BackgroundAnimatorChangeType change_type); 114 115 // Initializes animations for the bubble. 116 void InitializeBubbleAnimations(views::Widget* bubble_widget); 117 118 // Returns the window hosting the bubble. 119 aura::Window* GetBubbleWindowContainer() const; 120 121 // Returns the anchor rect for the bubble. 122 gfx::Rect GetBubbleAnchorRect( 123 views::Widget* anchor_widget, 124 views::TrayBubbleView::AnchorType anchor_type, 125 views::TrayBubbleView::AnchorAlignment anchor_alignment) const; 126 127 // Returns the bubble anchor alignment based on |shelf_alignment_|. 128 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; 129 130 // Forces the background to be drawn active if set to true. 131 void SetDrawBackgroundAsActive(bool visible); 132 133 // Returns true when the the background was overridden to be drawn as active. draw_background_as_active()134 bool draw_background_as_active() const {return draw_background_as_active_; } 135 status_area_widget()136 StatusAreaWidget* status_area_widget() { 137 return status_area_widget_; 138 } status_area_widget()139 const StatusAreaWidget* status_area_widget() const { 140 return status_area_widget_; 141 } tray_container()142 TrayContainer* tray_container() const { return tray_container_; } shelf_alignment()143 ShelfAlignment shelf_alignment() const { return shelf_alignment_; } tray_event_filter()144 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } 145 146 ShelfLayoutManager* GetShelfLayoutManager(); 147 148 // Updates the arrow visibility based on the launcher visibility. 149 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); 150 151 private: 152 class TrayWidgetObserver; 153 154 // Called from Initialize after all status area trays have been created. 155 // Sets the border based on the position of the view. 156 void SetTrayBorder(); 157 158 // ui::ImplicitAnimationObserver: 159 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 160 161 // Applies transformations to the |layer()| to animate the view when 162 // SetVisible(false) is called. 163 void HideTransformation(); 164 165 // Unowned pointer to parent widget. 166 StatusAreaWidget* status_area_widget_; 167 168 // Convenience pointer to the contents view. 169 TrayContainer* tray_container_; 170 171 // Shelf alignment. 172 ShelfAlignment shelf_alignment_; 173 174 // Owned by the view passed to SetContents(). 175 TrayBackground* background_; 176 177 // Animators for the background. They are only used for the old shelf layout. 178 BackgroundAnimator hide_background_animator_; 179 BackgroundAnimator hover_background_animator_; 180 181 // True if the background gets hovered. 182 bool hovered_; 183 184 // This variable stores the activation override which will tint the background 185 // differently if set to true. 186 bool draw_background_as_active_; 187 188 scoped_ptr<TrayWidgetObserver> widget_observer_; 189 scoped_ptr<TrayEventFilter> tray_event_filter_; 190 191 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); 192 }; 193 194 } // namespace ash 195 196 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ 197