OLD | NEW |
| (Empty) |
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_COMMON_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/shelf/shelf_types.h" | |
12 #include "ash/common/system/tray/actionable_view.h" | |
13 #include "ash/common/wm/background_animator.h" | |
14 #include "base/macros.h" | |
15 #include "ui/compositor/layer_animation_observer.h" | |
16 #include "ui/views/bubble/tray_bubble_view.h" | |
17 | |
18 namespace ash { | |
19 class ShelfLayoutManager; | |
20 class TrayEventFilter; | |
21 class TrayBackground; | |
22 class WmShelf; | |
23 | |
24 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray, | |
25 // LogoutButtonTray, OverviewButtonTray. | |
26 // This class handles setting and animating the background when the Launcher | |
27 // his shown/hidden. It also inherits from ActionableView so that the tray | |
28 // items can override PerformAction when clicked on. | |
29 class ASH_EXPORT TrayBackgroundView : public ActionableView, | |
30 public BackgroundAnimatorDelegate, | |
31 public ui::ImplicitAnimationObserver { | |
32 public: | |
33 static const char kViewClassName[]; | |
34 | |
35 // Base class for tray containers. Sets the border and layout. The container | |
36 // auto-resizes the widget when necessary. | |
37 class TrayContainer : public views::View { | |
38 public: | |
39 explicit TrayContainer(ShelfAlignment alignment); | |
40 ~TrayContainer() override {} | |
41 | |
42 void SetAlignment(ShelfAlignment alignment); | |
43 | |
44 void set_size(const gfx::Size& size) { size_ = size; } | |
45 | |
46 // views::View: | |
47 gfx::Size GetPreferredSize() const override; | |
48 | |
49 protected: | |
50 // views::View: | |
51 void ChildPreferredSizeChanged(views::View* child) override; | |
52 void ChildVisibilityChanged(View* child) override; | |
53 void ViewHierarchyChanged( | |
54 const ViewHierarchyChangedDetails& details) override; | |
55 | |
56 private: | |
57 void UpdateLayout(); | |
58 | |
59 ShelfAlignment alignment_; | |
60 gfx::Size size_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(TrayContainer); | |
63 }; | |
64 | |
65 explicit TrayBackgroundView(WmShelf* wm_shelf); | |
66 ~TrayBackgroundView() override; | |
67 | |
68 // Called after the tray has been added to the widget containing it. | |
69 virtual void Initialize(); | |
70 | |
71 // Initializes animations for the bubble. | |
72 static void InitializeBubbleAnimations(views::Widget* bubble_widget); | |
73 | |
74 // views::View: | |
75 void SetVisible(bool visible) override; | |
76 const char* GetClassName() const override; | |
77 void ChildPreferredSizeChanged(views::View* child) override; | |
78 void GetAccessibleState(ui::AXViewState* state) override; | |
79 void AboutToRequestFocusFromTabTraversal(bool reverse) override; | |
80 | |
81 // ActionableView: | |
82 bool PerformAction(const ui::Event& event) override; | |
83 gfx::Rect GetFocusBounds() override; | |
84 void OnGestureEvent(ui::GestureEvent* event) override; | |
85 | |
86 // BackgroundAnimatorDelegate: | |
87 void UpdateBackground(int alpha) override; | |
88 | |
89 // Called whenever the shelf alignment changes. | |
90 virtual void SetShelfAlignment(ShelfAlignment alignment); | |
91 | |
92 // Called when the anchor (tray or bubble) may have moved or changed. | |
93 virtual void AnchorUpdated() {} | |
94 | |
95 // Called from GetAccessibleState, must return a valid accessible name. | |
96 virtual base::string16 GetAccessibleNameForTray() = 0; | |
97 | |
98 // Called when the bubble is resized. | |
99 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} | |
100 | |
101 // Hides the bubble associated with |bubble_view|. Called when the widget | |
102 // is closed. | |
103 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; | |
104 | |
105 // Called by the bubble wrapper when a click event occurs outside the bubble. | |
106 // May close the bubble. | |
107 virtual void ClickedOutsideBubble() = 0; | |
108 | |
109 // Sets |contents| as a child. | |
110 void SetContents(views::View* contents); | |
111 | |
112 // Creates and sets contents background to |background_|. | |
113 void SetContentsBackground(); | |
114 | |
115 // Returns the anchor rect for the bubble. | |
116 gfx::Rect GetBubbleAnchorRect( | |
117 views::Widget* anchor_widget, | |
118 views::TrayBubbleView::AnchorType anchor_type, | |
119 views::TrayBubbleView::AnchorAlignment anchor_alignment) const; | |
120 | |
121 // Returns the bubble anchor alignment based on |shelf_alignment_|. | |
122 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; | |
123 | |
124 // Forces the background to be drawn active if set to true. | |
125 void SetDrawBackgroundAsActive(bool visible); | |
126 | |
127 // Returns true when the the background was overridden to be drawn as active. | |
128 bool draw_background_as_active() const {return draw_background_as_active_; } | |
129 | |
130 TrayContainer* tray_container() const { return tray_container_; } | |
131 ShelfAlignment shelf_alignment() const { return shelf_alignment_; } | |
132 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } | |
133 WmShelf* shelf() { return wm_shelf_; } | |
134 | |
135 // Updates the arrow visibility based on the launcher visibility. | |
136 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); | |
137 | |
138 private: | |
139 class TrayWidgetObserver; | |
140 | |
141 // Called from Initialize after all status area trays have been created. | |
142 // Sets the border based on the position of the view. | |
143 void SetTrayBorder(); | |
144 | |
145 // ui::ImplicitAnimationObserver: | |
146 void OnImplicitAnimationsCompleted() override; | |
147 bool RequiresNotificationWhenAnimatorDestroyed() const override; | |
148 | |
149 // Applies transformations to the |layer()| to animate the view when | |
150 // SetVisible(false) is called. | |
151 void HideTransformation(); | |
152 | |
153 // The shelf containing the system tray for this view. | |
154 WmShelf* wm_shelf_; | |
155 | |
156 // Convenience pointer to the contents view. | |
157 TrayContainer* tray_container_; | |
158 | |
159 // Shelf alignment. | |
160 // TODO(jamescook): Don't cache this, get it from WmShelf. | |
161 ShelfAlignment shelf_alignment_; | |
162 | |
163 // Owned by the view passed to SetContents(). | |
164 TrayBackground* background_; | |
165 | |
166 // This variable stores the activation override which will tint the background | |
167 // differently if set to true. | |
168 bool draw_background_as_active_; | |
169 | |
170 std::unique_ptr<TrayWidgetObserver> widget_observer_; | |
171 std::unique_ptr<TrayEventFilter> tray_event_filter_; | |
172 | |
173 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); | |
174 }; | |
175 | |
176 } // namespace ash | |
177 | |
178 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
OLD | NEW |