OLD | NEW |
| (Empty) |
1 // Copyright 2013 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_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_ | |
6 #define ASH_COMMON_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/wm/overview/scoped_transform_overview_window.h" | |
12 #include "base/macros.h" | |
13 #include "ui/aura/window_observer.h" | |
14 #include "ui/gfx/geometry/insets.h" | |
15 #include "ui/gfx/geometry/rect.h" | |
16 #include "ui/views/controls/button/button.h" | |
17 #include "ui/views/controls/button/image_button.h" | |
18 #include "ui/views/controls/label.h" | |
19 #include "ui/views/widget/widget.h" | |
20 | |
21 namespace gfx { | |
22 class SlideAnimation; | |
23 } | |
24 | |
25 namespace views { | |
26 class ImageButton; | |
27 } | |
28 | |
29 namespace ash { | |
30 | |
31 class WindowSelector; | |
32 class WmWindow; | |
33 | |
34 // This class represents an item in overview mode. | |
35 class ASH_EXPORT WindowSelectorItem : public views::ButtonListener, | |
36 public aura::WindowObserver { | |
37 public: | |
38 // An image button with a close window icon. | |
39 class OverviewCloseButton : public views::ImageButton { | |
40 public: | |
41 explicit OverviewCloseButton(views::ButtonListener* listener); | |
42 ~OverviewCloseButton() override; | |
43 | |
44 // Resets the listener so that the listener can go out of scope. | |
45 void ResetListener() { listener_ = nullptr; } | |
46 | |
47 private: | |
48 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton); | |
49 }; | |
50 | |
51 WindowSelectorItem(WmWindow* window, WindowSelector* window_selector); | |
52 ~WindowSelectorItem() override; | |
53 | |
54 WmWindow* GetWindow(); | |
55 | |
56 // Returns the root window on which this item is shown. | |
57 WmWindow* root_window() { return root_window_; } | |
58 | |
59 // Returns true if |target| is contained in this WindowSelectorItem. | |
60 bool Contains(const WmWindow* target) const; | |
61 | |
62 // Restores and animates the managed window to its non overview mode state. | |
63 void RestoreWindow(); | |
64 | |
65 // Ensures that a possibly minimized window becomes visible after restore. | |
66 void EnsureVisible(); | |
67 | |
68 // Restores stacking of window captions above the windows, then fades out. | |
69 void Shutdown(); | |
70 | |
71 // Dispatched before beginning window overview. This will do any necessary | |
72 // one time actions such as restoring minimized windows. | |
73 void PrepareForOverview(); | |
74 | |
75 // Calculates and returns an optimal scale ratio. With MD this is only | |
76 // taking into account |size.height()| as the width can vary. Without MD this | |
77 // returns the scale that allows the item to fully fit within |size|. | |
78 float GetItemScale(const gfx::Size& size); | |
79 | |
80 // Returns the union of the original target bounds of all transformed windows | |
81 // managed by |this| item, i.e. all regular (normal or panel transient | |
82 // descendants of the window returned by GetWindow()). | |
83 gfx::Rect GetTargetBoundsInScreen() const; | |
84 | |
85 // Sets the bounds of this window selector item to |target_bounds| in the | |
86 // |root_window_| root window. The bounds change will be animated as specified | |
87 // by |animation_type|. | |
88 void SetBounds(const gfx::Rect& target_bounds, | |
89 OverviewAnimationType animation_type); | |
90 | |
91 // Activates or deactivates selection depending on |selected|. | |
92 // In selected state the item's caption is shown transparent and blends with | |
93 // the selection widget. | |
94 void SetSelected(bool selected); | |
95 | |
96 // Sends an accessibility event indicating that this window became selected | |
97 // so that it's highlighted and announced if accessibility features are | |
98 // enabled. | |
99 void SendAccessibleSelectionEvent(); | |
100 | |
101 // Closes |transform_window_|. | |
102 void CloseWindow(); | |
103 | |
104 // Hides the original window header. | |
105 void HideHeader(); | |
106 | |
107 // Called when the window is minimized or unminimized. | |
108 void OnMinimizedStateChanged(); | |
109 | |
110 // Sets if the item is dimmed in the overview. Changing the value will also | |
111 // change the visibility of the transform windows. | |
112 void SetDimmed(bool dimmed); | |
113 bool dimmed() const { return dimmed_; } | |
114 | |
115 const gfx::Rect& target_bounds() const { return target_bounds_; } | |
116 | |
117 // views::ButtonListener: | |
118 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
119 | |
120 // aura::WindowObserver: | |
121 void OnWindowDestroying(aura::Window* window) override; | |
122 void OnWindowTitleChanged(aura::Window* window) override; | |
123 | |
124 private: | |
125 class CaptionContainerView; | |
126 class RoundedContainerView; | |
127 friend class WindowSelectorTest; | |
128 | |
129 enum class HeaderFadeInMode { | |
130 ENTER, | |
131 UPDATE, | |
132 EXIT, | |
133 }; | |
134 | |
135 // Sets the bounds of this selector's items to |target_bounds| in | |
136 // |root_window_|. The bounds change will be animated as specified | |
137 // by |animation_type|. | |
138 void SetItemBounds(const gfx::Rect& target_bounds, | |
139 OverviewAnimationType animation_type); | |
140 | |
141 // Changes the opacity of all the windows the item owns. | |
142 void SetOpacity(float opacity); | |
143 | |
144 // Creates the window label. | |
145 void CreateWindowLabel(const base::string16& title); | |
146 | |
147 // Updates the close button's and title label's bounds. Any change in bounds | |
148 // will be animated from the current bounds to the new bounds as per the | |
149 // |animation_type|. |mode| allows distinguishing the first time update which | |
150 // allows setting the initial bounds properly or exiting overview to fade out | |
151 // gradually. | |
152 void UpdateHeaderLayout(HeaderFadeInMode mode, | |
153 OverviewAnimationType animation_type); | |
154 | |
155 // Animates opacity of the |transform_window_| and its caption to |opacity| | |
156 // using |animation_type|. | |
157 void AnimateOpacity(float opacity, OverviewAnimationType animation_type); | |
158 | |
159 // Updates the accessibility name to match the window title. | |
160 void UpdateAccessibilityName(); | |
161 | |
162 // Fades out a window caption when exiting overview mode. | |
163 void FadeOut(std::unique_ptr<views::Widget> widget); | |
164 | |
165 // Allows a test to directly set animation state. | |
166 gfx::SlideAnimation* GetBackgroundViewAnimation(); | |
167 | |
168 WmWindow* GetOverviewWindowForMinimizedStateForTest(); | |
169 | |
170 // True if the item is being shown in the overview, false if it's being | |
171 // filtered. | |
172 bool dimmed_; | |
173 | |
174 // The root window this item is being displayed on. | |
175 WmWindow* root_window_; | |
176 | |
177 // The contained Window's wrapper. | |
178 ScopedTransformOverviewWindow transform_window_; | |
179 | |
180 // The target bounds this selector item is fit within. | |
181 gfx::Rect target_bounds_; | |
182 | |
183 // True if running SetItemBounds. This prevents recursive calls resulting from | |
184 // the bounds update when calling ::wm::RecreateWindowLayers to copy | |
185 // a window layer for display on another monitor. | |
186 bool in_bounds_update_; | |
187 | |
188 // True when |this| item is visually selected. Item header is made transparent | |
189 // when the item is selected. | |
190 bool selected_; | |
191 | |
192 // A widget that covers the |transform_window_|. The widget has | |
193 // |caption_container_view_| as its contents view. The widget is backed by a | |
194 // NOT_DRAWN layer since most of its surface is transparent. | |
195 std::unique_ptr<views::Widget> item_widget_; | |
196 | |
197 // Container view that owns a Button view covering the |transform_window_|. | |
198 // That button serves as an event shield to receive all events such as clicks | |
199 // targeting the |transform_window_| or the overview header above the window. | |
200 // The shield button owns |background_view_| which owns |label_view_| | |
201 // and |close_button_|. | |
202 CaptionContainerView* caption_container_view_; | |
203 | |
204 // A View for the text label above the window owned by the |background_view_|. | |
205 views::Label* label_view_; | |
206 | |
207 // A close button for the window in this item owned by the |background_view_|. | |
208 OverviewCloseButton* close_button_; | |
209 | |
210 // Pointer to the WindowSelector that owns the WindowGrid containing |this|. | |
211 // Guaranteed to be non-null for the lifetime of |this|. | |
212 WindowSelector* window_selector_; | |
213 | |
214 // Pointer to a view that covers the original header and has rounded top | |
215 // corners. This view can have its color and opacity animated. It has a layer | |
216 // which is the only textured layer used by the |item_widget_|. | |
217 RoundedContainerView* background_view_; | |
218 | |
219 DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem); | |
220 }; | |
221 | |
222 } // namespace ash | |
223 | |
224 #endif // ASH_COMMON_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_ | |
OLD | NEW |