| 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_window.h" | 10 #include "ash/aura/wm_window_aura.h" |
| 11 #include "ash/public/cpp/shell_window_ids.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/observer_list.h" | 12 |
| 14 #include "services/ui/public/cpp/window_observer.h" | 13 namespace aura { |
| 14 class Window; |
| 15 } |
| 15 | 16 |
| 16 namespace views { | 17 namespace views { |
| 17 class Widget; | 18 class Widget; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 21 | |
| 22 namespace wm { | |
| 23 class WmLayoutManager; | |
| 24 } | |
| 25 | |
| 26 namespace mus { | 22 namespace mus { |
| 27 | 23 |
| 28 class MusLayoutManagerAdapter; | |
| 29 class WmRootWindowControllerMus; | 24 class WmRootWindowControllerMus; |
| 30 class WmWindowMusTestApi; | 25 class WmWindowMusTestApi; |
| 31 | 26 |
| 32 // WmWindow implementation for mus. | 27 // WmWindow implementation for mus. |
| 33 // | 28 // |
| 34 // WmWindowMus is tied to the life of the underlying ui::Window (it is stored | 29 // WmWindowMus is tied to the life of the underlying aura::Window (it is stored |
| 35 // as an owned property). | 30 // as an owned property). |
| 36 class WmWindowMus : public WmWindow, public ui::WindowObserver { | 31 class WmWindowMus : public WmWindowAura { |
| 37 public: | 32 public: |
| 38 // Indicates the source of the widget creation. | 33 // Indicates the source of the widget creation. |
| 39 enum class WidgetCreationType { | 34 enum class WidgetCreationType { |
| 40 // The widget was created internally, and not at the request of a client. | 35 // The widget was created internally, and not at the request of a client. |
| 41 // For example, overview mode creates a number of widgets. These widgets are | 36 // For example, overview mode creates a number of widgets. These widgets are |
| 42 // created with a type of INTERNAL. | 37 // created with a type of INTERNAL. |
| 43 INTERNAL, | 38 INTERNAL, |
| 44 | 39 |
| 45 // The widget was created for a client. In other words there is a client | 40 // The widget was created for a client. In other words there is a client |
| 46 // embedded in the ui::Window. For example, when Chrome creates a new | 41 // embedded in the aura::Window. For example, when Chrome creates a new |
| 47 // browser window the window manager is asked to create the ui::Window. | 42 // browser window the window manager is asked to create the aura::Window. |
| 48 // The window manager creates a ui::Window and a views::Widget to show the | 43 // The window manager creates an aura::Window and a views::Widget to show |
| 49 // non-client frame decorations. In this case the creation type is | 44 // the non-client frame decorations. In this case the creation type is |
| 50 // FOR_CLIENT. | 45 // FOR_CLIENT. |
| 51 FOR_CLIENT, | 46 FOR_CLIENT, |
| 52 }; | 47 }; |
| 53 | 48 |
| 54 explicit WmWindowMus(ui::Window* window); | 49 explicit WmWindowMus(aura::Window* window); |
| 55 // NOTE: this class is owned by the corresponding window. You shouldn't delete | 50 // NOTE: this class is owned by the corresponding window. You shouldn't delete |
| 56 // TODO(sky): friend deleter and make private. | 51 // TODO(sky): friend deleter and make private. |
| 57 ~WmWindowMus() override; | 52 ~WmWindowMus() override; |
| 58 | 53 |
| 59 // Returns a WmWindow for an ui::Window, creating if necessary. | 54 // Returns a WmWindow for an aura::Window, creating if necessary. |
| 60 static WmWindowMus* Get(ui::Window* window) { | 55 static WmWindowMus* Get(aura::Window* window) { |
| 61 return const_cast<WmWindowMus*>(Get(const_cast<const ui::Window*>(window))); | 56 return const_cast<WmWindowMus*>( |
| 57 Get(const_cast<const aura::Window*>(window))); |
| 62 } | 58 } |
| 63 static const WmWindowMus* Get(const ui::Window* window); | 59 static const WmWindowMus* Get(const aura::Window* window); |
| 64 | 60 |
| 65 static WmWindowMus* Get(views::Widget* widget); | 61 static WmWindowMus* Get(views::Widget* widget); |
| 66 | 62 |
| 67 static ui::Window* GetMusWindow(WmWindow* wm_window) { | |
| 68 return const_cast<ui::Window*>( | |
| 69 GetMusWindow(const_cast<const WmWindow*>(wm_window))); | |
| 70 } | |
| 71 static const ui::Window* GetMusWindow(const WmWindow* wm_window); | |
| 72 | |
| 73 static std::vector<WmWindow*> FromMusWindows( | |
| 74 const std::vector<ui::Window*>& mus_windows); | |
| 75 | |
| 76 void set_wm_window_type(ui::wm::WindowType type) { | |
| 77 wm_window_type_ = type; | |
| 78 is_wm_window_type_set_ = true; | |
| 79 } | |
| 80 | |
| 81 // Sets the widget associated with the window. The widget is used to query | 63 // Sets the widget associated with the window. The widget is used to query |
| 82 // state, such as min/max size. The widget is not owned by the WmWindowMus. | 64 // state, such as min/max size. The widget is not owned by the WmWindowMus. |
| 83 void set_widget(views::Widget* widget, WidgetCreationType type) { | 65 void set_widget(views::Widget* widget, WidgetCreationType type) { |
| 84 widget_ = widget; | 66 widget_ = widget; |
| 85 widget_creation_type_ = type; | 67 widget_creation_type_ = type; |
| 86 } | 68 } |
| 87 | 69 |
| 88 ui::Window* mus_window() { return window_; } | |
| 89 const ui::Window* mus_window() const { return window_; } | |
| 90 | |
| 91 WmRootWindowControllerMus* GetRootWindowControllerMus() { | 70 WmRootWindowControllerMus* GetRootWindowControllerMus() { |
| 92 return const_cast<WmRootWindowControllerMus*>( | 71 return const_cast<WmRootWindowControllerMus*>( |
| 93 const_cast<const WmWindowMus*>(this)->GetRootWindowControllerMus()); | 72 const_cast<const WmWindowMus*>(this)->GetRootWindowControllerMus()); |
| 94 } | 73 } |
| 95 const WmRootWindowControllerMus* GetRootWindowControllerMus() const; | 74 const WmRootWindowControllerMus* GetRootWindowControllerMus() const; |
| 96 | 75 |
| 97 static WmWindowMus* AsWmWindowMus(WmWindow* window) { | 76 static WmWindowMus* AsWmWindowMus(WmWindow* window) { |
| 98 return static_cast<WmWindowMus*>(window); | 77 return static_cast<WmWindowMus*>(window); |
| 99 } | 78 } |
| 100 static const WmWindowMus* AsWmWindowMus(const WmWindow* window) { | 79 static const WmWindowMus* AsWmWindowMus(const WmWindow* window) { |
| 101 return static_cast<const WmWindowMus*>(window); | 80 return static_cast<const WmWindowMus*>(window); |
| 102 } | 81 } |
| 103 | 82 |
| 104 wm::WindowState* GetWindowState() { return WmWindow::GetWindowState(); } | |
| 105 | |
| 106 // See description of |children_use_extended_hit_region_|. | 83 // See description of |children_use_extended_hit_region_|. |
| 107 bool ShouldUseExtendedHitRegion() const; | 84 bool ShouldUseExtendedHitRegion() const; |
| 108 | 85 |
| 109 // Returns true if this window is considered a shell window container. | 86 // Returns true if this window is considered a shell window container. |
| 110 bool IsContainer() const; | 87 bool IsContainer() const; |
| 111 | 88 |
| 112 // WmWindow: | 89 // WmWindow: |
| 113 void Destroy() override; | |
| 114 const WmWindow* GetRootWindow() const override; | 90 const WmWindow* GetRootWindow() const override; |
| 115 WmRootWindowController* GetRootWindowController() override; | 91 WmRootWindowController* GetRootWindowController() override; |
| 116 WmShell* GetShell() const override; | 92 WmShell* GetShell() const override; |
| 117 void SetName(const char* name) override; | |
| 118 std::string GetName() const override; | |
| 119 void SetTitle(const base::string16& title) override; | |
| 120 base::string16 GetTitle() const override; | |
| 121 void SetShellWindowId(int id) override; | |
| 122 int GetShellWindowId() const override; | |
| 123 WmWindow* GetChildByShellWindowId(int id) override; | |
| 124 ui::wm::WindowType GetType() const override; | |
| 125 int GetAppType() const override; | |
| 126 void SetAppType(int app_type) const override; | |
| 127 bool IsBubble() override; | 93 bool IsBubble() override; |
| 128 ui::Layer* GetLayer() override; | |
| 129 bool GetLayerTargetVisibility() override; | |
| 130 bool GetLayerVisible() override; | |
| 131 display::Display GetDisplayNearestWindow() override; | |
| 132 bool HasNonClientArea() override; | 94 bool HasNonClientArea() override; |
| 133 int GetNonClientComponent(const gfx::Point& location) override; | 95 int GetNonClientComponent(const gfx::Point& location) override; |
| 134 gfx::Point ConvertPointToTarget(const WmWindow* target, | |
| 135 const gfx::Point& point) const override; | |
| 136 gfx::Point ConvertPointToScreen(const gfx::Point& point) const override; | |
| 137 gfx::Point ConvertPointFromScreen(const gfx::Point& point) const override; | |
| 138 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const override; | |
| 139 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const override; | |
| 140 gfx::Size GetMinimumSize() const override; | 96 gfx::Size GetMinimumSize() const override; |
| 141 gfx::Size GetMaximumSize() const override; | 97 gfx::Size GetMaximumSize() const override; |
| 142 bool GetTargetVisibility() const override; | |
| 143 bool IsVisible() const override; | |
| 144 void SetOpacity(float opacity) override; | |
| 145 float GetTargetOpacity() const override; | |
| 146 gfx::Rect GetMinimizeAnimationTargetBoundsInScreen() const override; | 98 gfx::Rect GetMinimizeAnimationTargetBoundsInScreen() const override; |
| 147 void SetTransform(const gfx::Transform& transform) override; | |
| 148 gfx::Transform GetTargetTransform() const override; | |
| 149 bool IsSystemModal() const override; | 99 bool IsSystemModal() const override; |
| 150 bool GetBoolProperty(WmWindowProperty key) override; | 100 bool GetBoolProperty(WmWindowProperty key) override; |
| 151 SkColor GetColorProperty(WmWindowProperty key) override; | |
| 152 void SetColorProperty(WmWindowProperty key, SkColor value) override; | |
| 153 int GetIntProperty(WmWindowProperty key) override; | 101 int GetIntProperty(WmWindowProperty key) override; |
| 154 void SetIntProperty(WmWindowProperty key, int value) override; | |
| 155 std::string GetStringProperty(WmWindowProperty key) override; | |
| 156 void SetStringProperty(WmWindowProperty key, | |
| 157 const std::string& value) override; | |
| 158 gfx::ImageSkia GetWindowIcon() override; | |
| 159 gfx::ImageSkia GetAppIcon() override; | |
| 160 const wm::WindowState* GetWindowState() const override; | |
| 161 WmWindow* GetToplevelWindow() override; | 102 WmWindow* GetToplevelWindow() override; |
| 162 WmWindow* GetToplevelWindowForFocus() override; | 103 WmWindow* GetToplevelWindowForFocus() override; |
| 163 void SetParentUsingContext(WmWindow* context, | |
| 164 const gfx::Rect& screen_bounds) override; | |
| 165 void AddChild(WmWindow* window) override; | |
| 166 void RemoveChild(WmWindow* child) override; | |
| 167 const WmWindow* GetParent() const override; | |
| 168 const WmWindow* GetTransientParent() const override; | |
| 169 std::vector<WmWindow*> GetTransientChildren() override; | |
| 170 bool MoveToEventRoot(const ui::Event& event) override; | 104 bool MoveToEventRoot(const ui::Event& event) override; |
| 171 void SetLayoutManager( | |
| 172 std::unique_ptr<WmLayoutManager> layout_manager) override; | |
| 173 WmLayoutManager* GetLayoutManager() override; | |
| 174 void SetVisibilityChangesAnimated() override; | |
| 175 void SetVisibilityAnimationType(int type) override; | |
| 176 void SetVisibilityAnimationDuration(base::TimeDelta delta) override; | |
| 177 void SetVisibilityAnimationTransition( | |
| 178 ::wm::WindowVisibilityAnimationTransition transition) override; | |
| 179 void Animate(::wm::WindowAnimationType type) override; | |
| 180 void StopAnimatingProperty( | |
| 181 ui::LayerAnimationElement::AnimatableProperty property) override; | |
| 182 void SetChildWindowVisibilityChangesAnimated() override; | |
| 183 void SetMasksToBounds(bool value) override; | |
| 184 void SetBounds(const gfx::Rect& bounds) override; | |
| 185 void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | |
| 186 base::TimeDelta delta) override; | |
| 187 void SetBoundsDirect(const gfx::Rect& bounds) override; | |
| 188 void SetBoundsDirectAnimated(const gfx::Rect& bounds) override; | |
| 189 void SetBoundsDirectCrossFade(const gfx::Rect& bounds) override; | |
| 190 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | 105 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, |
| 191 const display::Display& dst_display) override; | 106 const display::Display& dst_display) override; |
| 192 gfx::Rect GetBoundsInScreen() const override; | |
| 193 const gfx::Rect& GetBounds() const override; | |
| 194 gfx::Rect GetTargetBounds() override; | |
| 195 void ClearRestoreBounds() override; | |
| 196 void SetRestoreBoundsInScreen(const gfx::Rect& bounds) override; | |
| 197 gfx::Rect GetRestoreBoundsInScreen() const override; | |
| 198 bool Contains(const WmWindow* other) const override; | |
| 199 void SetShowState(ui::WindowShowState show_state) override; | |
| 200 ui::WindowShowState GetShowState() const override; | |
| 201 void SetRestoreShowState(ui::WindowShowState show_state) override; | |
| 202 void SetRestoreOverrides(const gfx::Rect& bounds_override, | |
| 203 ui::WindowShowState window_state_override) override; | |
| 204 void SetLockedToRoot(bool value) override; | |
| 205 bool IsLockedToRoot() const override; | |
| 206 void SetCapture() override; | |
| 207 bool HasCapture() override; | |
| 208 void ReleaseCapture() override; | |
| 209 bool HasRestoreBounds() const override; | |
| 210 void SetPinned(bool trusted) override; | 107 void SetPinned(bool trusted) override; |
| 211 void SetAlwaysOnTop(bool value) override; | |
| 212 bool IsAlwaysOnTop() const override; | |
| 213 void Hide() override; | |
| 214 void Show() override; | |
| 215 views::Widget* GetInternalWidget() override; | 108 views::Widget* GetInternalWidget() override; |
| 216 void CloseWidget() override; | 109 void CloseWidget() override; |
| 217 void SetFocused() override; | |
| 218 bool IsFocused() const override; | |
| 219 bool IsActive() const override; | |
| 220 void Activate() override; | |
| 221 void Deactivate() override; | |
| 222 void SetFullscreen() override; | |
| 223 void Maximize() override; | |
| 224 void Minimize() override; | |
| 225 void Unminimize() override; | |
| 226 void SetExcludedFromMru(bool) override; | |
| 227 bool CanMaximize() const override; | |
| 228 bool CanMinimize() const override; | |
| 229 bool CanResize() const override; | |
| 230 bool CanActivate() const override; | 110 bool CanActivate() const override; |
| 231 void StackChildAtTop(WmWindow* child) override; | |
| 232 void StackChildAtBottom(WmWindow* child) override; | |
| 233 void StackChildAbove(WmWindow* child, WmWindow* target) override; | |
| 234 void StackChildBelow(WmWindow* child, WmWindow* target) override; | |
| 235 std::vector<WmWindow*> GetChildren() override; | |
| 236 void ShowResizeShadow(int component) override; | 111 void ShowResizeShadow(int component) override; |
| 237 void HideResizeShadow() override; | 112 void HideResizeShadow() override; |
| 238 void InstallResizeHandleWindowTargeter( | 113 void InstallResizeHandleWindowTargeter( |
| 239 ImmersiveFullscreenController* immersive_fullscreen_controller) override; | 114 ImmersiveFullscreenController* immersive_fullscreen_controller) override; |
| 240 void SetBoundsInScreenBehaviorForChildren( | 115 void SetBoundsInScreenBehaviorForChildren( |
| 241 BoundsInScreenBehavior behavior) override; | 116 BoundsInScreenBehavior behavior) override; |
| 242 void SetSnapsChildrenToPhysicalPixelBoundary() override; | 117 void SetSnapsChildrenToPhysicalPixelBoundary() override; |
| 243 void SnapToPixelBoundaryIfNecessary() override; | 118 void SnapToPixelBoundaryIfNecessary() override; |
| 244 void SetChildrenUseExtendedHitRegion() override; | 119 void SetChildrenUseExtendedHitRegion() override; |
| 245 std::unique_ptr<views::View> CreateViewWithRecreatedLayers() override; | |
| 246 void AddObserver(WmWindowObserver* observer) override; | |
| 247 void RemoveObserver(WmWindowObserver* observer) override; | |
| 248 bool HasObserver(const WmWindowObserver* observer) const override; | |
| 249 void AddTransientWindowObserver(WmTransientWindowObserver* observer) override; | |
| 250 void RemoveTransientWindowObserver( | |
| 251 WmTransientWindowObserver* observer) override; | |
| 252 void AddLimitedPreTargetHandler(ui::EventHandler* handler) override; | 120 void AddLimitedPreTargetHandler(ui::EventHandler* handler) override; |
| 253 void RemoveLimitedPreTargetHandler(ui::EventHandler* handler) override; | |
| 254 | 121 |
| 255 private: | 122 private: |
| 256 friend class WmWindowMusTestApi; | 123 friend class WmWindowMusTestApi; |
| 257 | 124 |
| 258 // ui::WindowObserver: | |
| 259 void OnTreeChanging(const TreeChangeParams& params) override; | |
| 260 void OnTreeChanged(const TreeChangeParams& params) override; | |
| 261 void OnWindowReordered(ui::Window* window, | |
| 262 ui::Window* relative_window, | |
| 263 ui::mojom::OrderDirection direction) override; | |
| 264 void OnWindowSharedPropertyChanged( | |
| 265 ui::Window* window, | |
| 266 const std::string& name, | |
| 267 const std::vector<uint8_t>* old_data, | |
| 268 const std::vector<uint8_t>* new_data) override; | |
| 269 void OnWindowBoundsChanged(ui::Window* window, | |
| 270 const gfx::Rect& old_bounds, | |
| 271 const gfx::Rect& new_bounds) override; | |
| 272 void OnWindowDestroying(ui::Window* window) override; | |
| 273 void OnWindowDestroyed(ui::Window* window) override; | |
| 274 void OnWindowVisibilityChanging(ui::Window* window, bool visible) override; | |
| 275 void OnWindowVisibilityChanged(ui::Window* window, bool visible) override; | |
| 276 void OnTransientChildAdded(ui::Window* window, | |
| 277 ui::Window* transient) override; | |
| 278 void OnTransientChildRemoved(ui::Window* window, | |
| 279 ui::Window* transient) override; | |
| 280 | |
| 281 ui::Window* window_; | |
| 282 | |
| 283 // The shell window id of this window. Shell window ids are defined in | |
| 284 // ash/public/cpp/shell_window_ids.h. | |
| 285 int shell_window_id_ = kShellWindowId_Invalid; | |
| 286 | |
| 287 std::unique_ptr<wm::WindowState> window_state_; | |
| 288 | |
| 289 views::Widget* widget_ = nullptr; | 125 views::Widget* widget_ = nullptr; |
| 290 | 126 |
| 291 WidgetCreationType widget_creation_type_ = WidgetCreationType::INTERNAL; | 127 WidgetCreationType widget_creation_type_ = WidgetCreationType::INTERNAL; |
| 292 | 128 |
| 293 base::ObserverList<WmWindowObserver> observers_; | |
| 294 | |
| 295 std::unique_ptr<MusLayoutManagerAdapter> layout_manager_adapter_; | |
| 296 | |
| 297 ui::WindowShowState restore_show_state_ = ui::SHOW_STATE_DEFAULT; | |
| 298 | |
| 299 bool snap_children_to_pixel_boundary_ = false; | 129 bool snap_children_to_pixel_boundary_ = false; |
| 300 | 130 |
| 301 // If true child windows should get a slightly larger hit region to make | 131 // If true child windows should get a slightly larger hit region to make |
| 302 // resizing easier. | 132 // resizing easier. |
| 303 bool children_use_extended_hit_region_ = false; | 133 bool children_use_extended_hit_region_ = false; |
| 304 | 134 |
| 305 base::ObserverList<WmTransientWindowObserver, true> transient_observers_; | 135 // Default value for |use_empty_minimum_size_for_testing_|. |
| 136 static bool default_use_empty_minimum_size_for_testing_; |
| 306 | 137 |
| 307 // If true the minimum size is 0x0, default is minimum size comes from widget. | 138 // If true the minimum size is 0x0, default is minimum size comes from widget. |
| 308 bool use_empty_minimum_size_for_testing_ = false; | 139 bool use_empty_minimum_size_for_testing_ = false; |
| 309 | 140 |
| 310 ui::wm::WindowType wm_window_type_ = ui::wm::WINDOW_TYPE_UNKNOWN; | |
| 311 // Set to true if set_window_type() is called. | |
| 312 bool is_wm_window_type_set_ = false; | |
| 313 | |
| 314 BoundsInScreenBehavior child_bounds_in_screen_behavior_ = | 141 BoundsInScreenBehavior child_bounds_in_screen_behavior_ = |
| 315 BoundsInScreenBehavior::USE_LOCAL_COORDINATES; | 142 BoundsInScreenBehavior::USE_LOCAL_COORDINATES; |
| 316 | 143 |
| 317 bool locked_to_root_ = false; | |
| 318 | |
| 319 DISALLOW_COPY_AND_ASSIGN(WmWindowMus); | 144 DISALLOW_COPY_AND_ASSIGN(WmWindowMus); |
| 320 }; | 145 }; |
| 321 | 146 |
| 322 } // namespace mus | 147 } // namespace mus |
| 323 } // namespace ash | 148 } // namespace ash |
| 324 | 149 |
| 325 #endif // ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ | 150 #endif // ASH_MUS_BRIDGE_WM_WINDOW_MUS_H_ |
| OLD | NEW |