OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ | 5 #ifndef ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ |
6 #define ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ | 6 #define ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/common/wm/wm_window.h" | 10 #include "ash/common/wm_window.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "components/mus/public/cpp/window_observer.h" | 13 #include "components/mus/public/cpp/window_observer.h" |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 class Widget; | 16 class Widget; |
17 } | 17 } |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 | 20 |
21 namespace wm { | 21 namespace wm { |
22 class WmLayoutManager; | 22 class WmLayoutManager; |
23 } | 23 } |
24 | 24 |
25 namespace mus { | 25 namespace mus { |
26 | 26 |
27 class MusLayoutManagerAdapter; | 27 class MusLayoutManagerAdapter; |
28 class WmRootWindowControllerMus; | 28 class WmRootWindowControllerMus; |
29 | 29 |
30 // WmWindow implementation for mus. | 30 // WmWindow implementation for mus. |
31 // | 31 // |
32 // WmWindowMus is tied to the life of the underlying ::mus::Window (it is stored | 32 // WmWindowMus is tied to the life of the underlying ::mus::Window (it is stored |
33 // as an owned property). | 33 // as an owned property). |
34 class WmWindowMus : public wm::WmWindow, public ::mus::WindowObserver { | 34 class WmWindowMus : public WmWindow, public ::mus::WindowObserver { |
35 public: | 35 public: |
36 // Indicates the source of the widget creation. | 36 // Indicates the source of the widget creation. |
37 enum class WidgetCreationType { | 37 enum class WidgetCreationType { |
38 // The widget was created internally, and not at the request of a client. | 38 // The widget was created internally, and not at the request of a client. |
39 // For example, overview mode creates a number of widgets. These widgets are | 39 // For example, overview mode creates a number of widgets. These widgets are |
40 // created with a type of INTERNAL. | 40 // created with a type of INTERNAL. |
41 INTERNAL, | 41 INTERNAL, |
42 | 42 |
43 // The widget was created for a client. In other words there is a client | 43 // The widget was created for a client. In other words there is a client |
44 // embedded in the mus::Window. For example, when Chrome creates a new | 44 // embedded in the mus::Window. For example, when Chrome creates a new |
45 // browser window the window manager is asked to create the mus::Window. | 45 // browser window the window manager is asked to create the mus::Window. |
46 // The window manager creates a mus::Window and a views::Widget to show the | 46 // The window manager creates a mus::Window and a views::Widget to show the |
47 // non-client frame decorations. In this case the creation type is | 47 // non-client frame decorations. In this case the creation type is |
48 // FOR_CLIENT. | 48 // FOR_CLIENT. |
49 | 49 |
50 FOR_CLIENT, | 50 FOR_CLIENT, |
51 }; | 51 }; |
52 | 52 |
53 explicit WmWindowMus(::mus::Window* window); | 53 explicit WmWindowMus(::mus::Window* window); |
54 // NOTE: this class is owned by the corresponding window. You shouldn't delete | 54 // NOTE: this class is owned by the corresponding window. You shouldn't delete |
55 // TODO(sky): friend deleter and make private. | 55 // TODO(sky): friend deleter and make private. |
56 ~WmWindowMus() override; | 56 ~WmWindowMus() override; |
57 | 57 |
58 // Returns a WmWindow for an mus::Window, creating if necessary. | 58 // Returns a WmWindow for an mus::Window, creating if necessary. |
59 static WmWindowMus* Get(::mus::Window* window); | 59 static WmWindowMus* Get(::mus::Window* window); |
60 | 60 |
61 static WmWindowMus* Get(views::Widget* widget); | 61 static WmWindowMus* Get(views::Widget* widget); |
62 | 62 |
63 static ::mus::Window* GetMusWindow(wm::WmWindow* wm_window) { | 63 static ::mus::Window* GetMusWindow(WmWindow* wm_window) { |
64 return const_cast<::mus::Window*>( | 64 return const_cast<::mus::Window*>( |
65 GetMusWindow(const_cast<const wm::WmWindow*>(wm_window))); | 65 GetMusWindow(const_cast<const WmWindow*>(wm_window))); |
66 } | 66 } |
67 static const ::mus::Window* GetMusWindow(const wm::WmWindow* wm_window); | 67 static const ::mus::Window* GetMusWindow(const WmWindow* wm_window); |
68 | 68 |
69 static std::vector<WmWindow*> FromMusWindows( | 69 static std::vector<WmWindow*> FromMusWindows( |
70 const std::vector<::mus::Window*>& mus_windows); | 70 const std::vector<::mus::Window*>& mus_windows); |
71 | 71 |
72 // Sets the widget associated with the window. The widget is used to query | 72 // Sets the widget associated with the window. The widget is used to query |
73 // state, such as min/max size. The widget is not owned by the WmWindowMus. | 73 // state, such as min/max size. The widget is not owned by the WmWindowMus. |
74 void set_widget(views::Widget* widget, WidgetCreationType type) { | 74 void set_widget(views::Widget* widget, WidgetCreationType type) { |
75 widget_ = widget; | 75 widget_ = widget; |
76 widget_creation_type_ = type; | 76 widget_creation_type_ = type; |
77 } | 77 } |
78 | 78 |
79 ::mus::Window* mus_window() { return window_; } | 79 ::mus::Window* mus_window() { return window_; } |
80 const ::mus::Window* mus_window() const { return window_; } | 80 const ::mus::Window* mus_window() const { return window_; } |
81 | 81 |
82 WmRootWindowControllerMus* GetRootWindowControllerMus() { | 82 WmRootWindowControllerMus* GetRootWindowControllerMus() { |
83 return const_cast<WmRootWindowControllerMus*>( | 83 return const_cast<WmRootWindowControllerMus*>( |
84 const_cast<const WmWindowMus*>(this)->GetRootWindowControllerMus()); | 84 const_cast<const WmWindowMus*>(this)->GetRootWindowControllerMus()); |
85 } | 85 } |
86 const WmRootWindowControllerMus* GetRootWindowControllerMus() const; | 86 const WmRootWindowControllerMus* GetRootWindowControllerMus() const; |
87 | 87 |
88 static WmWindowMus* AsWmWindowMus(wm::WmWindow* window) { | 88 static WmWindowMus* AsWmWindowMus(WmWindow* window) { |
89 return static_cast<WmWindowMus*>(window); | 89 return static_cast<WmWindowMus*>(window); |
90 } | 90 } |
91 static const WmWindowMus* AsWmWindowMus(const wm::WmWindow* window) { | 91 static const WmWindowMus* AsWmWindowMus(const WmWindow* window) { |
92 return static_cast<const WmWindowMus*>(window); | 92 return static_cast<const WmWindowMus*>(window); |
93 } | 93 } |
94 | 94 |
95 wm::WindowState* GetWindowState() { return wm::WmWindow::GetWindowState(); } | 95 wm::WindowState* GetWindowState() { return WmWindow::GetWindowState(); } |
96 | 96 |
97 // See description of |children_use_extended_hit_region_|. | 97 // See description of |children_use_extended_hit_region_|. |
98 bool ShouldUseExtendedHitRegion() const; | 98 bool ShouldUseExtendedHitRegion() const; |
99 | 99 |
100 // WmWindow: | 100 // WmWindow: |
101 const wm::WmWindow* GetRootWindow() const override; | 101 const WmWindow* GetRootWindow() const override; |
102 wm::WmRootWindowController* GetRootWindowController() override; | 102 WmRootWindowController* GetRootWindowController() override; |
103 wm::WmGlobals* GetGlobals() const override; | 103 WmShell* GetShell() const override; |
104 void SetName(const char* name) override; | 104 void SetName(const char* name) override; |
105 base::string16 GetTitle() const override; | 105 base::string16 GetTitle() const override; |
106 void SetShellWindowId(int id) override; | 106 void SetShellWindowId(int id) override; |
107 int GetShellWindowId() const override; | 107 int GetShellWindowId() const override; |
108 wm::WmWindow* GetChildByShellWindowId(int id) override; | 108 WmWindow* GetChildByShellWindowId(int id) override; |
109 ui::wm::WindowType GetType() const override; | 109 ui::wm::WindowType GetType() const override; |
110 ui::Layer* GetLayer() override; | 110 ui::Layer* GetLayer() override; |
111 display::Display GetDisplayNearestWindow() override; | 111 display::Display GetDisplayNearestWindow() override; |
112 bool HasNonClientArea() override; | 112 bool HasNonClientArea() override; |
113 int GetNonClientComponent(const gfx::Point& location) override; | 113 int GetNonClientComponent(const gfx::Point& location) override; |
114 gfx::Point ConvertPointToTarget(const wm::WmWindow* target, | 114 gfx::Point ConvertPointToTarget(const WmWindow* target, |
115 const gfx::Point& point) const override; | 115 const gfx::Point& point) const override; |
116 gfx::Point ConvertPointToScreen(const gfx::Point& point) const override; | 116 gfx::Point ConvertPointToScreen(const gfx::Point& point) const override; |
117 gfx::Point ConvertPointFromScreen(const gfx::Point& point) const override; | 117 gfx::Point ConvertPointFromScreen(const gfx::Point& point) const override; |
118 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const override; | 118 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const override; |
119 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const override; | 119 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const override; |
120 gfx::Size GetMinimumSize() const override; | 120 gfx::Size GetMinimumSize() const override; |
121 gfx::Size GetMaximumSize() const override; | 121 gfx::Size GetMaximumSize() const override; |
122 bool GetTargetVisibility() const override; | 122 bool GetTargetVisibility() const override; |
123 bool IsVisible() const override; | 123 bool IsVisible() const override; |
124 void SetOpacity(float opacity) override; | 124 void SetOpacity(float opacity) override; |
125 float GetTargetOpacity() const override; | 125 float GetTargetOpacity() const override; |
126 void SetTransform(const gfx::Transform& transform) override; | 126 void SetTransform(const gfx::Transform& transform) override; |
127 gfx::Transform GetTargetTransform() const override; | 127 gfx::Transform GetTargetTransform() const override; |
128 bool IsSystemModal() const override; | 128 bool IsSystemModal() const override; |
129 bool GetBoolProperty(wm::WmWindowProperty key) override; | 129 bool GetBoolProperty(WmWindowProperty key) override; |
130 int GetIntProperty(wm::WmWindowProperty key) override; | 130 int GetIntProperty(WmWindowProperty key) override; |
131 const wm::WindowState* GetWindowState() const override; | 131 const wm::WindowState* GetWindowState() const override; |
132 wm::WmWindow* GetToplevelWindow() override; | 132 WmWindow* GetToplevelWindow() override; |
133 void SetParentUsingContext(wm::WmWindow* context, | 133 void SetParentUsingContext(WmWindow* context, |
134 const gfx::Rect& screen_bounds) override; | 134 const gfx::Rect& screen_bounds) override; |
135 void AddChild(wm::WmWindow* window) override; | 135 void AddChild(WmWindow* window) override; |
136 wm::WmWindow* GetParent() override; | 136 WmWindow* GetParent() override; |
137 const wm::WmWindow* GetTransientParent() const override; | 137 const WmWindow* GetTransientParent() const override; |
138 std::vector<wm::WmWindow*> GetTransientChildren() override; | 138 std::vector<WmWindow*> GetTransientChildren() override; |
139 void SetLayoutManager( | 139 void SetLayoutManager( |
140 std::unique_ptr<wm::WmLayoutManager> layout_manager) override; | 140 std::unique_ptr<WmLayoutManager> layout_manager) override; |
141 wm::WmLayoutManager* GetLayoutManager() override; | 141 WmLayoutManager* GetLayoutManager() override; |
142 void SetVisibilityAnimationType(int type) override; | 142 void SetVisibilityAnimationType(int type) override; |
143 void SetVisibilityAnimationDuration(base::TimeDelta delta) override; | 143 void SetVisibilityAnimationDuration(base::TimeDelta delta) override; |
144 void SetVisibilityAnimationTransition( | 144 void SetVisibilityAnimationTransition( |
145 ::wm::WindowVisibilityAnimationTransition transition) override; | 145 ::wm::WindowVisibilityAnimationTransition transition) override; |
146 void Animate(::wm::WindowAnimationType type) override; | 146 void Animate(::wm::WindowAnimationType type) override; |
147 void StopAnimatingProperty( | 147 void StopAnimatingProperty( |
148 ui::LayerAnimationElement::AnimatableProperty property) override; | 148 ui::LayerAnimationElement::AnimatableProperty property) override; |
149 void SetChildWindowVisibilityChangesAnimated() override; | 149 void SetChildWindowVisibilityChangesAnimated() override; |
150 void SetMasksToBounds(bool value) override; | 150 void SetMasksToBounds(bool value) override; |
151 void SetBounds(const gfx::Rect& bounds) override; | 151 void SetBounds(const gfx::Rect& bounds) override; |
152 void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | 152 void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, |
153 base::TimeDelta delta) override; | 153 base::TimeDelta delta) override; |
154 void SetBoundsDirect(const gfx::Rect& bounds) override; | 154 void SetBoundsDirect(const gfx::Rect& bounds) override; |
155 void SetBoundsDirectAnimated(const gfx::Rect& bounds) override; | 155 void SetBoundsDirectAnimated(const gfx::Rect& bounds) override; |
156 void SetBoundsDirectCrossFade(const gfx::Rect& bounds) override; | 156 void SetBoundsDirectCrossFade(const gfx::Rect& bounds) override; |
157 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | 157 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, |
158 const display::Display& dst_display) override; | 158 const display::Display& dst_display) override; |
159 gfx::Rect GetBoundsInScreen() const override; | 159 gfx::Rect GetBoundsInScreen() const override; |
160 const gfx::Rect& GetBounds() const override; | 160 const gfx::Rect& GetBounds() const override; |
161 gfx::Rect GetTargetBounds() override; | 161 gfx::Rect GetTargetBounds() override; |
162 void ClearRestoreBounds() override; | 162 void ClearRestoreBounds() override; |
163 void SetRestoreBoundsInScreen(const gfx::Rect& bounds) override; | 163 void SetRestoreBoundsInScreen(const gfx::Rect& bounds) override; |
164 gfx::Rect GetRestoreBoundsInScreen() const override; | 164 gfx::Rect GetRestoreBoundsInScreen() const override; |
165 bool Contains(const wm::WmWindow* other) const override; | 165 bool Contains(const WmWindow* other) const override; |
166 void SetShowState(ui::WindowShowState show_state) override; | 166 void SetShowState(ui::WindowShowState show_state) override; |
167 ui::WindowShowState GetShowState() const override; | 167 ui::WindowShowState GetShowState() const override; |
168 void SetRestoreShowState(ui::WindowShowState show_state) override; | 168 void SetRestoreShowState(ui::WindowShowState show_state) override; |
169 void SetLockedToRoot(bool value) override; | 169 void SetLockedToRoot(bool value) override; |
170 void SetCapture() override; | 170 void SetCapture() override; |
171 bool HasCapture() override; | 171 bool HasCapture() override; |
172 void ReleaseCapture() override; | 172 void ReleaseCapture() override; |
173 bool HasRestoreBounds() const override; | 173 bool HasRestoreBounds() const override; |
174 void SetAlwaysOnTop(bool value) override; | 174 void SetAlwaysOnTop(bool value) override; |
175 bool IsAlwaysOnTop() const override; | 175 bool IsAlwaysOnTop() const override; |
176 void Hide() override; | 176 void Hide() override; |
177 void Show() override; | 177 void Show() override; |
178 void CloseWidget() override; | 178 void CloseWidget() override; |
179 bool IsFocused() const override; | 179 bool IsFocused() const override; |
180 bool IsActive() const override; | 180 bool IsActive() const override; |
181 void Activate() override; | 181 void Activate() override; |
182 void Deactivate() override; | 182 void Deactivate() override; |
183 void SetFullscreen() override; | 183 void SetFullscreen() override; |
184 void Maximize() override; | 184 void Maximize() override; |
185 void Minimize() override; | 185 void Minimize() override; |
186 void Unminimize() override; | 186 void Unminimize() override; |
187 bool CanMaximize() const override; | 187 bool CanMaximize() const override; |
188 bool CanMinimize() const override; | 188 bool CanMinimize() const override; |
189 bool CanResize() const override; | 189 bool CanResize() const override; |
190 bool CanActivate() const override; | 190 bool CanActivate() const override; |
191 void StackChildAtTop(wm::WmWindow* child) override; | 191 void StackChildAtTop(WmWindow* child) override; |
192 void StackChildAtBottom(wm::WmWindow* child) override; | 192 void StackChildAtBottom(WmWindow* child) override; |
193 void StackChildAbove(wm::WmWindow* child, wm::WmWindow* target) override; | 193 void StackChildAbove(WmWindow* child, WmWindow* target) override; |
194 void StackChildBelow(wm::WmWindow* child, wm::WmWindow* target) override; | 194 void StackChildBelow(WmWindow* child, WmWindow* target) override; |
195 std::vector<wm::WmWindow*> GetChildren() override; | 195 std::vector<WmWindow*> GetChildren() override; |
196 void ShowResizeShadow(int component) override; | 196 void ShowResizeShadow(int component) override; |
197 void HideResizeShadow() override; | 197 void HideResizeShadow() override; |
198 void SetBoundsInScreenBehaviorForChildren( | 198 void SetBoundsInScreenBehaviorForChildren( |
199 BoundsInScreenBehavior behavior) override; | 199 BoundsInScreenBehavior behavior) override; |
200 void SetSnapsChildrenToPhysicalPixelBoundary() override; | 200 void SetSnapsChildrenToPhysicalPixelBoundary() override; |
201 void SnapToPixelBoundaryIfNecessary() override; | 201 void SnapToPixelBoundaryIfNecessary() override; |
202 void SetChildrenUseExtendedHitRegion() override; | 202 void SetChildrenUseExtendedHitRegion() override; |
203 void SetDescendantsStayInSameRootWindow(bool value) override; | 203 void SetDescendantsStayInSameRootWindow(bool value) override; |
204 void AddObserver(wm::WmWindowObserver* observer) override; | 204 void AddObserver(WmWindowObserver* observer) override; |
205 void RemoveObserver(wm::WmWindowObserver* observer) override; | 205 void RemoveObserver(WmWindowObserver* observer) override; |
206 | 206 |
207 private: | 207 private: |
208 // mus::WindowObserver: | 208 // mus::WindowObserver: |
209 void OnTreeChanged(const TreeChangeParams& params) override; | 209 void OnTreeChanged(const TreeChangeParams& params) override; |
210 void OnWindowReordered(::mus::Window* window, | 210 void OnWindowReordered(::mus::Window* window, |
211 ::mus::Window* relative_window, | 211 ::mus::Window* relative_window, |
212 ::mus::mojom::OrderDirection direction) override; | 212 ::mus::mojom::OrderDirection direction) override; |
213 void OnWindowSharedPropertyChanged( | 213 void OnWindowSharedPropertyChanged( |
214 ::mus::Window* window, | 214 ::mus::Window* window, |
215 const std::string& name, | 215 const std::string& name, |
216 const std::vector<uint8_t>* old_data, | 216 const std::vector<uint8_t>* old_data, |
217 const std::vector<uint8_t>* new_data) override; | 217 const std::vector<uint8_t>* new_data) override; |
218 void OnWindowBoundsChanged(::mus::Window* window, | 218 void OnWindowBoundsChanged(::mus::Window* window, |
219 const gfx::Rect& old_bounds, | 219 const gfx::Rect& old_bounds, |
220 const gfx::Rect& new_bounds) override; | 220 const gfx::Rect& new_bounds) override; |
221 void OnWindowDestroying(::mus::Window* window) override; | 221 void OnWindowDestroying(::mus::Window* window) override; |
222 | 222 |
223 ::mus::Window* window_; | 223 ::mus::Window* window_; |
224 | 224 |
225 // The shell window id of this window. Shell window ids are defined in | 225 // The shell window id of this window. Shell window ids are defined in |
226 // ash/common/shell_window_ids.h. | 226 // ash/common/shell_window_ids.h. |
227 int shell_window_id_ = -1; | 227 int shell_window_id_ = -1; |
228 | 228 |
229 std::unique_ptr<wm::WindowState> window_state_; | 229 std::unique_ptr<wm::WindowState> window_state_; |
230 | 230 |
231 views::Widget* widget_ = nullptr; | 231 views::Widget* widget_ = nullptr; |
232 | 232 |
233 WidgetCreationType widget_creation_type_ = WidgetCreationType::INTERNAL; | 233 WidgetCreationType widget_creation_type_ = WidgetCreationType::INTERNAL; |
234 | 234 |
235 base::ObserverList<wm::WmWindowObserver> observers_; | 235 base::ObserverList<WmWindowObserver> observers_; |
236 | 236 |
237 std::unique_ptr<MusLayoutManagerAdapter> layout_manager_adapter_; | 237 std::unique_ptr<MusLayoutManagerAdapter> layout_manager_adapter_; |
238 | 238 |
239 std::unique_ptr<gfx::Rect> restore_bounds_in_screen_; | 239 std::unique_ptr<gfx::Rect> restore_bounds_in_screen_; |
240 | 240 |
241 ui::WindowShowState restore_show_state_ = ui::SHOW_STATE_DEFAULT; | 241 ui::WindowShowState restore_show_state_ = ui::SHOW_STATE_DEFAULT; |
242 | 242 |
243 bool snap_children_to_pixel_boundary_ = false; | 243 bool snap_children_to_pixel_boundary_ = false; |
244 | 244 |
245 // If true child windows should get a slightly larger hit region to make | 245 // If true child windows should get a slightly larger hit region to make |
246 // resizing easier. | 246 // resizing easier. |
247 bool children_use_extended_hit_region_ = false; | 247 bool children_use_extended_hit_region_ = false; |
248 | 248 |
249 DISALLOW_COPY_AND_ASSIGN(WmWindowMus); | 249 DISALLOW_COPY_AND_ASSIGN(WmWindowMus); |
250 }; | 250 }; |
251 | 251 |
252 } // namespace mus | 252 } // namespace mus |
253 } // namespace ash | 253 } // namespace ash |
254 | 254 |
255 #endif // ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ | 255 #endif // ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ |
OLD | NEW |