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/views/bubble/tray_bubble_view.h" 13 14 namespace ash { 15 namespace internal { 16 17 class ShelfLayoutManager; 18 class StatusAreaWidget; 19 class TrayEventFilter; 20 class TrayBackground; 21 22 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray, 23 // LogoutButtonTray. 24 // This class handles setting and animating the background when the Launcher 25 // his shown/hidden. It also inherits from ActionableView so that the tray 26 // items can override PerformAction when clicked on. 27 class ASH_EXPORT TrayBackgroundView : public ActionableView, 28 public BackgroundAnimatorDelegate { 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); 37 virtual ~TrayContainer() {} 38 39 void SetAlignment(ShelfAlignment alignment); 40 41 void set_size(const gfx::Size& size) { size_ = size; } 42 43 // Overridden from views::View. 44 virtual gfx::Size GetPreferredSize() OVERRIDE; 45 46 protected: 47 // Overridden from 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(internal::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 // Overridden from views::View. 69 virtual const char* GetClassName() const OVERRIDE; 70 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 71 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 72 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; 73 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 74 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; 75 76 // Overridden from internal::ActionableView. 77 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 78 virtual gfx::Rect GetFocusBounds() OVERRIDE; 79 80 // Overridden from internal::BackgroundAnimatorDelegate. 81 virtual void UpdateBackground(int alpha) OVERRIDE; 82 83 // Called whenever the shelf alignment changes. 84 virtual void SetShelfAlignment(ShelfAlignment alignment); 85 86 // Called when the anchor (tray or bubble) may have moved or changed. 87 virtual void AnchorUpdated() {} 88 89 // Called from GetAccessibleState, must return a valid accessible name. 90 virtual base::string16 GetAccessibleNameForTray() = 0; 91 92 // Called when the bubble is resized. 93 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} 94 95 // Hides the bubble associated with |bubble_view|. Called when the widget 96 // is closed. 97 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; 98 99 // Called by the bubble wrapper when a click event occurs outside the bubble. 100 // May close the bubble. Returns true if the event is handled. 101 virtual bool ClickedOutsideBubble() = 0; 102 103 // Sets |contents| as a child. 104 void SetContents(views::View* contents); 105 106 // Creates and sets contents background to |background_|. 107 void SetContentsBackground(); 108 109 // Sets whether the tray paints a background. Default is true, but is set to 110 // false if a window overlaps the shelf. 111 void SetPaintsBackground(bool value, 112 BackgroundAnimatorChangeType change_type); 113 114 // Initializes animations for the bubble. 115 void InitializeBubbleAnimations(views::Widget* bubble_widget); 116 117 // Returns the window hosting the bubble. 118 aura::Window* GetBubbleWindowContainer() const; 119 120 // Returns the anchor rect for the bubble. 121 gfx::Rect GetBubbleAnchorRect( 122 views::Widget* anchor_widget, 123 views::TrayBubbleView::AnchorType anchor_type, 124 views::TrayBubbleView::AnchorAlignment anchor_alignment) const; 125 126 // Returns the bubble anchor alignment based on |shelf_alignment_|. 127 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; 128 129 // Forces the background to be drawn active if set to true. 130 void SetDrawBackgroundAsActive(bool visible); 131 132 // Returns true when the the background was overridden to be drawn as active. 133 bool draw_background_as_active() const {return draw_background_as_active_; } 134 135 StatusAreaWidget* status_area_widget() { 136 return status_area_widget_; 137 } 138 const StatusAreaWidget* status_area_widget() const { 139 return status_area_widget_; 140 } 141 TrayContainer* tray_container() const { return tray_container_; } 142 ShelfAlignment shelf_alignment() const { return shelf_alignment_; } 143 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } 144 145 ShelfLayoutManager* GetShelfLayoutManager(); 146 147 // Updates the arrow visibility based on the launcher visibility. 148 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); 149 150 private: 151 class TrayWidgetObserver; 152 153 // Called from Initialize after all status area trays have been created. 154 // Sets the border based on the position of the view. 155 void SetBorder(); 156 157 // Unowned pointer to parent widget. 158 StatusAreaWidget* status_area_widget_; 159 160 // Convenience pointer to the contents view. 161 TrayContainer* tray_container_; 162 163 // Shelf alignment. 164 ShelfAlignment shelf_alignment_; 165 166 // Owned by the view passed to SetContents(). 167 internal::TrayBackground* background_; 168 169 // Animators for the background. They are only used for the old shelf layout. 170 internal::BackgroundAnimator hide_background_animator_; 171 internal::BackgroundAnimator hover_background_animator_; 172 173 // True if the background gets hovered. 174 bool hovered_; 175 176 // This variable stores the activation override which will tint the background 177 // differently if set to true. 178 bool draw_background_as_active_; 179 180 scoped_ptr<TrayWidgetObserver> widget_observer_; 181 scoped_ptr<TrayEventFilter> tray_event_filter_; 182 183 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); 184 }; 185 186 } // namespace internal 187 } // namespace ash 188 189 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ 190