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.
5 #ifndef ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
6 #define ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
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"
15 class ShelfLayoutManager;
16 class StatusAreaWidget;
17 class TrayEventFilter;
20 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray,
22 // This class handles setting and animating the background when the Launcher
23 // his shown/hidden. It also inherits from ActionableView so that the tray
24 // items can override PerformAction when clicked on.
25 class ASH_EXPORT TrayBackgroundView : public ActionableView,
26 public BackgroundAnimatorDelegate {
28 static const char kViewClassName[];
30 // Base class for tray containers. Sets the border and layout. The container
31 // auto-resizes the widget when necessary.
32 class TrayContainer : public views::View {
34 explicit TrayContainer(ShelfAlignment alignment);
35 virtual ~TrayContainer() {}
37 void SetAlignment(ShelfAlignment alignment);
39 void set_size(const gfx::Size& size) { size_ = size; }
41 // Overridden from views::View.
42 virtual gfx::Size GetPreferredSize() OVERRIDE;
45 // Overridden from views::View.
46 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
47 virtual void ChildVisibilityChanged(View* child) OVERRIDE;
48 virtual void ViewHierarchyChanged(
49 const ViewHierarchyChangedDetails& details) OVERRIDE;
54 ShelfAlignment alignment_;
57 DISALLOW_COPY_AND_ASSIGN(TrayContainer);
60 explicit TrayBackgroundView(StatusAreaWidget* status_area_widget);
61 virtual ~TrayBackgroundView();
63 // Called after the tray has been added to the widget containing it.
64 virtual void Initialize();
66 // Overridden from views::View.
67 virtual const char* GetClassName() const OVERRIDE;
68 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
69 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
70 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
71 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
72 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
74 // Overridden from ActionableView.
75 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
76 virtual gfx::Rect GetFocusBounds() OVERRIDE;
78 // Overridden from BackgroundAnimatorDelegate.
79 virtual void UpdateBackground(int alpha) OVERRIDE;
81 // Called whenever the shelf alignment changes.
82 virtual void SetShelfAlignment(ShelfAlignment alignment);
84 // Called when the anchor (tray or bubble) may have moved or changed.
85 virtual void AnchorUpdated() {}
87 // Called from GetAccessibleState, must return a valid accessible name.
88 virtual base::string16 GetAccessibleNameForTray() = 0;
90 // Called when the bubble is resized.
91 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {}
93 // Hides the bubble associated with |bubble_view|. Called when the widget
95 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0;
97 // Called by the bubble wrapper when a click event occurs outside the bubble.
98 // May close the bubble. Returns true if the event is handled.
99 virtual bool ClickedOutsideBubble() = 0;
101 // Sets |contents| as a child.
102 void SetContents(views::View* contents);
104 // Creates and sets contents background to |background_|.
105 void SetContentsBackground();
107 // Sets whether the tray paints a background. Default is true, but is set to
108 // false if a window overlaps the shelf.
109 void SetPaintsBackground(bool value,
110 BackgroundAnimatorChangeType change_type);
112 // Initializes animations for the bubble.
113 void InitializeBubbleAnimations(views::Widget* bubble_widget);
115 // Returns the window hosting the bubble.
116 aura::Window* GetBubbleWindowContainer() const;
118 // Returns the anchor rect for the bubble.
119 gfx::Rect GetBubbleAnchorRect(
120 views::Widget* anchor_widget,
121 views::TrayBubbleView::AnchorType anchor_type,
122 views::TrayBubbleView::AnchorAlignment anchor_alignment) const;
124 // Returns the bubble anchor alignment based on |shelf_alignment_|.
125 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const;
127 // Forces the background to be drawn active if set to true.
128 void SetDrawBackgroundAsActive(bool visible);
130 // Returns true when the the background was overridden to be drawn as active.
131 bool draw_background_as_active() const {return draw_background_as_active_; }
133 StatusAreaWidget* status_area_widget() {
134 return status_area_widget_;
136 const StatusAreaWidget* status_area_widget() const {
137 return status_area_widget_;
139 TrayContainer* tray_container() const { return tray_container_; }
140 ShelfAlignment shelf_alignment() const { return shelf_alignment_; }
141 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); }
143 ShelfLayoutManager* GetShelfLayoutManager();
145 // Updates the arrow visibility based on the launcher visibility.
146 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view);
149 class TrayWidgetObserver;
151 // Called from Initialize after all status area trays have been created.
152 // Sets the border based on the position of the view.
153 void SetTrayBorder();
155 // Unowned pointer to parent widget.
156 StatusAreaWidget* status_area_widget_;
158 // Convenience pointer to the contents view.
159 TrayContainer* tray_container_;
162 ShelfAlignment shelf_alignment_;
164 // Owned by the view passed to SetContents().
165 TrayBackground* background_;
167 // Animators for the background. They are only used for the old shelf layout.
168 BackgroundAnimator hide_background_animator_;
169 BackgroundAnimator hover_background_animator_;
171 // True if the background gets hovered.
174 // This variable stores the activation override which will tint the background
175 // differently if set to true.
176 bool draw_background_as_active_;
178 scoped_ptr<TrayWidgetObserver> widget_observer_;
179 scoped_ptr<TrayEventFilter> tray_event_filter_;
181 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView);
186 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_