| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_WM_WINDOW_STATE_H_ | 5 #ifndef ASH_WM_WINDOW_STATE_H_ |
| 6 #define ASH_WM_WINDOW_STATE_H_ | 6 #define ASH_WM_WINDOW_STATE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/wm/aura/wm_window_aura.h" |
| 11 #include "ash/wm/drag_details.h" | 12 #include "ash/wm/drag_details.h" |
| 12 #include "ash/wm/wm_types.h" | 13 #include "ash/wm/wm_types.h" |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 16 #include "ui/aura/window_observer.h" | |
| 17 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
| 18 | 18 |
| 19 namespace aura { | 19 namespace aura { |
| 20 class Window; | 20 class Window; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace gfx { | 23 namespace gfx { |
| 24 class Rect; | 24 class Rect; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace ash { | 27 namespace ash { |
| 28 class WorkspaceLayoutManager; | |
| 29 class LockWindowState; | 28 class LockWindowState; |
| 30 class MaximizeModeWindowState; | 29 class MaximizeModeWindowState; |
| 31 | 30 |
| 32 namespace wm { | 31 namespace wm { |
| 33 class WindowStateDelegate; | 32 class WindowStateDelegate; |
| 34 class WindowStateObserver; | 33 class WindowStateObserver; |
| 35 class WMEvent; | 34 class WMEvent; |
| 35 class WmWindow; |
| 36 | 36 |
| 37 // WindowState manages and defines ash specific window state and | 37 // WindowState manages and defines ash specific window state and |
| 38 // behavior. Ash specific per-window state (such as ones that controls | 38 // behavior. Ash specific per-window state (such as ones that controls |
| 39 // window manager behavior) and ash specific window behavior (such as | 39 // window manager behavior) and ash specific window behavior (such as |
| 40 // maximize, minimize, snap sizing etc) should be added here instead | 40 // maximize, minimize, snap sizing etc) should be added here instead |
| 41 // of defining separate functions (like |MaximizeWindow(aura::Window* | 41 // of defining separate functions (like |MaximizeWindow(aura::Window* |
| 42 // window)|) or using aura Window property. | 42 // window)|) or using aura Window property. |
| 43 // The WindowState gets created when first accessed by | 43 // The WindowState gets created when first accessed by |
| 44 // |wm::GetWindowState|, and deleted when the window is deleted. | 44 // |wm::GetWindowState|, and deleted when the window is deleted. |
| 45 // Prefer using this class instead of passing aura::Window* around in | 45 // Prefer using this class instead of passing aura::Window* around in |
| 46 // ash code as this is often what you need to interact with, and | 46 // ash code as this is often what you need to interact with, and |
| 47 // accessing the window using |window()| is cheap. | 47 // accessing the window using |window()| is cheap. |
| 48 class ASH_EXPORT WindowState : public aura::WindowObserver { | 48 class ASH_EXPORT WindowState { |
| 49 public: | 49 public: |
| 50 | 50 |
| 51 // A subclass of State class represents one of the window's states | 51 // A subclass of State class represents one of the window's states |
| 52 // that corresponds to WindowStateType in Ash environment, e.g. | 52 // that corresponds to WindowStateType in Ash environment, e.g. |
| 53 // maximized, minimized or side snapped, as subclass. | 53 // maximized, minimized or side snapped, as subclass. |
| 54 // Each subclass defines its own behavior and transition for each WMEvent. | 54 // Each subclass defines its own behavior and transition for each WMEvent. |
| 55 class State { | 55 class State { |
| 56 public: | 56 public: |
| 57 State() {} | 57 State() {} |
| 58 virtual ~State() {} | 58 virtual ~State() {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 // Gets called before the state objects gets deactivated / detached from the | 73 // Gets called before the state objects gets deactivated / detached from the |
| 74 // window, so that it can save the various states it is interested in. | 74 // window, so that it can save the various states it is interested in. |
| 75 // Note: This only gets called when the state object gets changed. | 75 // Note: This only gets called when the state object gets changed. |
| 76 virtual void DetachState(WindowState* window_state) = 0; | 76 virtual void DetachState(WindowState* window_state) = 0; |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(State); | 79 DISALLOW_COPY_AND_ASSIGN(State); |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // Call GetWindowState() to instantiate this class. | 82 // Call GetWindowState() to instantiate this class. |
| 83 ~WindowState() override; | 83 ~WindowState(); |
| 84 | 84 |
| 85 aura::Window* window() { return window_; } | 85 // TODO(sky): remove these. They are temporary until converted to common |
| 86 const aura::Window* window() const { return window_; } | 86 // types. |
| 87 aura::Window* aura_window() { return WmWindowAura::GetAuraWindow(window_); } |
| 88 const aura::Window* aura_window() const { |
| 89 return WmWindowAura::GetAuraWindow(window_); |
| 90 } |
| 91 |
| 92 WmWindow* window() { return window_; } |
| 93 const WmWindow* window() const { return window_; } |
| 87 | 94 |
| 88 bool HasDelegate() const; | 95 bool HasDelegate() const; |
| 89 void SetDelegate(std::unique_ptr<WindowStateDelegate> delegate); | 96 void SetDelegate(std::unique_ptr<WindowStateDelegate> delegate); |
| 90 | 97 |
| 91 // Returns the window's current ash state type. | 98 // Returns the window's current ash state type. |
| 92 // Refer to WindowStateType definition in wm_types.h as for why Ash | 99 // Refer to WindowStateType definition in wm_types.h as for why Ash |
| 93 // has its own state type. | 100 // has its own state type. |
| 94 WindowStateType GetStateType() const; | 101 WindowStateType GetStateType() const; |
| 95 | 102 |
| 96 // Predicates to check window state. | 103 // Predicates to check window state. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 138 |
| 132 void Activate(); | 139 void Activate(); |
| 133 void Deactivate(); | 140 void Deactivate(); |
| 134 | 141 |
| 135 // Set the window state to normal. | 142 // Set the window state to normal. |
| 136 // TODO(oshima): Change to use RESTORE event. | 143 // TODO(oshima): Change to use RESTORE event. |
| 137 void Restore(); | 144 void Restore(); |
| 138 | 145 |
| 139 // Caches, then disables always on top state and then stacks |window_| below | 146 // Caches, then disables always on top state and then stacks |window_| below |
| 140 // |window_on_top| if a |window_| is currently in always on top state. | 147 // |window_on_top| if a |window_| is currently in always on top state. |
| 141 void DisableAlwaysOnTop(aura::Window* window_on_top); | 148 void DisableAlwaysOnTop(WmWindow* window_on_top); |
| 142 | 149 |
| 143 // Restores always on top state that a window might have cached. | 150 // Restores always on top state that a window might have cached. |
| 144 void RestoreAlwaysOnTop(); | 151 void RestoreAlwaysOnTop(); |
| 145 | 152 |
| 146 // Invoked when a WMevent occurs, which drives the internal | 153 // Invoked when a WMevent occurs, which drives the internal |
| 147 // state machine. | 154 // state machine. |
| 148 void OnWMEvent(const WMEvent* event); | 155 void OnWMEvent(const WMEvent* event); |
| 149 | 156 |
| 150 // TODO(oshima): Try hiding these methods and making them accessible only to | 157 // TODO(oshima): Try hiding these methods and making them accessible only to |
| 151 // state impl. State changes should happen through events (as much | 158 // state impl. State changes should happen through events (as much |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // also allow the shelf to be shown in some situations. | 290 // also allow the shelf to be shown in some situations. |
| 284 bool in_immersive_fullscreen() const { | 291 bool in_immersive_fullscreen() const { |
| 285 return in_immersive_fullscreen_; | 292 return in_immersive_fullscreen_; |
| 286 } | 293 } |
| 287 void set_in_immersive_fullscreen(bool enable) { | 294 void set_in_immersive_fullscreen(bool enable) { |
| 288 in_immersive_fullscreen_ = enable; | 295 in_immersive_fullscreen_ = enable; |
| 289 } | 296 } |
| 290 | 297 |
| 291 // Creates and takes ownership of a pointer to DragDetails when resizing is | 298 // Creates and takes ownership of a pointer to DragDetails when resizing is |
| 292 // active. This should be done before a resizer gets created. | 299 // active. This should be done before a resizer gets created. |
| 293 void CreateDragDetails(aura::Window* window, | 300 void CreateDragDetails(const gfx::Point& point_in_parent, |
| 294 const gfx::Point& point_in_parent, | |
| 295 int window_component, | 301 int window_component, |
| 296 aura::client::WindowMoveSource source); | 302 aura::client::WindowMoveSource source); |
| 297 | 303 |
| 298 // Deletes and clears a pointer to DragDetails. This should be done when the | 304 // Deletes and clears a pointer to DragDetails. This should be done when the |
| 299 // resizer gets destroyed. | 305 // resizer gets destroyed. |
| 300 void DeleteDragDetails(); | 306 void DeleteDragDetails(); |
| 301 | 307 |
| 302 // Sets the currently stored restore bounds and clears the restore bounds. | 308 // Sets the currently stored restore bounds and clears the restore bounds. |
| 303 void SetAndClearRestoreBounds(); | 309 void SetAndClearRestoreBounds(); |
| 304 | 310 |
| 305 // Returns a pointer to DragDetails during drag operations. | 311 // Returns a pointer to DragDetails during drag operations. |
| 306 const DragDetails* drag_details() const { return drag_details_.get(); } | 312 const DragDetails* drag_details() const { return drag_details_.get(); } |
| 307 DragDetails* drag_details() { return drag_details_.get(); } | 313 DragDetails* drag_details() { return drag_details_.get(); } |
| 308 | 314 |
| 309 // aura::WindowObserver overrides: | 315 // Called from the associated WmWindow once the show state changes. |
| 310 void OnWindowPropertyChanged(aura::Window* window, | 316 void OnWindowShowStateChanged(); |
| 311 const void* key, | |
| 312 intptr_t old) override; | |
| 313 | 317 |
| 314 private: | 318 private: |
| 315 friend class DefaultState; | 319 friend class DefaultState; |
| 316 friend class ash::LockWindowState; | 320 friend class ash::LockWindowState; |
| 317 friend class ash::MaximizeModeWindowState; | 321 friend class ash::MaximizeModeWindowState; |
| 318 friend ASH_EXPORT WindowState* GetWindowState(aura::Window*); | 322 friend ASH_EXPORT WindowState* GetWindowState(aura::Window*); |
| 319 FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, CrossFadeToBounds); | 323 FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, CrossFadeToBounds); |
| 320 FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, | 324 FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, |
| 321 CrossFadeToBoundsFromTransform); | 325 CrossFadeToBoundsFromTransform); |
| 322 | 326 |
| 323 explicit WindowState(aura::Window* window); | 327 explicit WindowState(WmWindow* window); |
| 324 | 328 |
| 325 WindowStateDelegate* delegate() { return delegate_.get(); } | 329 WindowStateDelegate* delegate() { return delegate_.get(); } |
| 326 | 330 |
| 327 // Returns the window's current always_on_top state. | 331 // Returns the window's current always_on_top state. |
| 328 bool GetAlwaysOnTop() const; | 332 bool GetAlwaysOnTop() const; |
| 329 | 333 |
| 330 // Returns the window's current show state. | 334 // Returns the window's current show state. |
| 331 ui::WindowShowState GetShowState() const; | 335 ui::WindowShowState GetShowState() const; |
| 332 | 336 |
| 333 // Sets the window's bounds in screen coordinates. | 337 // Sets the window's bounds in screen coordinates. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 353 | 357 |
| 354 // Sets the wndow's |bounds| and transitions to the new bounds with | 358 // Sets the wndow's |bounds| and transitions to the new bounds with |
| 355 // a scale animation. | 359 // a scale animation. |
| 356 void SetBoundsDirectAnimated(const gfx::Rect& bounds); | 360 void SetBoundsDirectAnimated(const gfx::Rect& bounds); |
| 357 | 361 |
| 358 // Sets the window's |bounds| and transition to the new bounds with | 362 // Sets the window's |bounds| and transition to the new bounds with |
| 359 // a cross fade animation. | 363 // a cross fade animation. |
| 360 void SetBoundsDirectCrossFade(const gfx::Rect& bounds); | 364 void SetBoundsDirectCrossFade(const gfx::Rect& bounds); |
| 361 | 365 |
| 362 // The owner of this window settings. | 366 // The owner of this window settings. |
| 363 aura::Window* window_; | 367 WmWindow* window_; |
| 364 std::unique_ptr<WindowStateDelegate> delegate_; | 368 std::unique_ptr<WindowStateDelegate> delegate_; |
| 365 | 369 |
| 366 bool window_position_managed_; | 370 bool window_position_managed_; |
| 367 bool bounds_changed_by_user_; | 371 bool bounds_changed_by_user_; |
| 368 bool panel_attached_; | 372 bool panel_attached_; |
| 369 bool ignored_by_shelf_; | 373 bool ignored_by_shelf_; |
| 370 bool can_consume_system_keys_; | 374 bool can_consume_system_keys_; |
| 371 bool top_row_keys_are_function_keys_; | 375 bool top_row_keys_are_function_keys_; |
| 372 std::unique_ptr<DragDetails> drag_details_; | 376 std::unique_ptr<DragDetails> drag_details_; |
| 373 | 377 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 387 | 391 |
| 388 // True to ignore a property change event to avoid reentrance in | 392 // True to ignore a property change event to avoid reentrance in |
| 389 // UpdateWindowStateType() | 393 // UpdateWindowStateType() |
| 390 bool ignore_property_change_; | 394 bool ignore_property_change_; |
| 391 | 395 |
| 392 std::unique_ptr<State> current_state_; | 396 std::unique_ptr<State> current_state_; |
| 393 | 397 |
| 394 DISALLOW_COPY_AND_ASSIGN(WindowState); | 398 DISALLOW_COPY_AND_ASSIGN(WindowState); |
| 395 }; | 399 }; |
| 396 | 400 |
| 397 // Returns the WindowState for active window. Returns |NULL| | |
| 398 // if there is no active window. | |
| 399 ASH_EXPORT WindowState* GetActiveWindowState(); | |
| 400 | |
| 401 // Returns the WindowState for |window|. Creates WindowState | |
| 402 // if it didn't exist. The settings object is owned by |window|. | |
| 403 ASH_EXPORT WindowState* GetWindowState(aura::Window* window); | |
| 404 | |
| 405 // const version of GetWindowState. | |
| 406 ASH_EXPORT const WindowState* | |
| 407 GetWindowState(const aura::Window* window); | |
| 408 | |
| 409 } // namespace wm | 401 } // namespace wm |
| 410 } // namespace ash | 402 } // namespace ash |
| 411 | 403 |
| 412 #endif // ASH_WM_WINDOW_STATE_H_ | 404 #endif // ASH_WM_WINDOW_STATE_H_ |
| OLD | NEW |