| 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 "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/wm/window_state_delegate.h" |
| 9 #include "ash/wm/wm_types.h" | 10 #include "ash/wm/wm_types.h" |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 13 #include "ui/aura/window_observer.h" | 14 #include "ui/aura/window_observer.h" |
| 14 #include "ui/base/ui_base_types.h" | 15 #include "ui/base/ui_base_types.h" |
| 15 | 16 |
| 16 namespace aura { | 17 namespace aura { |
| 17 class Window; | 18 class Window; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace gfx { | 21 namespace gfx { |
| 21 class Rect; | 22 class Rect; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace ash { | 25 namespace ash { |
| 25 namespace wm { | 26 namespace wm { |
| 27 class WindowStateDelegate; |
| 26 class WindowStateObserver; | 28 class WindowStateObserver; |
| 27 | 29 |
| 28 // WindowState manages and defines ash specific window state and | 30 // WindowState manages and defines ash specific window state and |
| 29 // behavior. Ash specific per-window state (such as ones that controls | 31 // behavior. Ash specific per-window state (such as ones that controls |
| 30 // window manager behavior) and ash specific window behavior (such as | 32 // window manager behavior) and ash specific window behavior (such as |
| 31 // maximize, minimize, snap sizing etc) should be added here instead | 33 // maximize, minimize, snap sizing etc) should be added here instead |
| 32 // of defining separate functions (like |MaximizeWindow(aura::Window* | 34 // of defining separate functions (like |MaximizeWindow(aura::Window* |
| 33 // window)|) or using aura Window property. | 35 // window)|) or using aura Window property. |
| 34 // The WindowState gets created when first accessed by | 36 // The WindowState gets created when first accessed by |
| 35 // |wm::GetWindowState|, and deleted when the window is deleted. | 37 // |wm::GetWindowState|, and deleted when the window is deleted. |
| 36 // Prefer using this class instead of passing aura::Window* around in | 38 // Prefer using this class instead of passing aura::Window* around in |
| 37 // ash code as this is often what you need to interact with, and | 39 // ash code as this is often what you need to interact with, and |
| 38 // accessing the window using |window()| is cheap. | 40 // accessing the window using |window()| is cheap. |
| 39 class ASH_EXPORT WindowState : public aura::WindowObserver { | 41 class ASH_EXPORT WindowState : public aura::WindowObserver { |
| 40 public: | 42 public: |
| 41 static bool IsMaximizedOrFullscreenState(ui::WindowShowState state); | 43 static bool IsMaximizedOrFullscreenState(ui::WindowShowState state); |
| 42 | 44 |
| 43 explicit WindowState(aura::Window* window); | 45 explicit WindowState(aura::Window* window); |
| 44 virtual ~WindowState(); | 46 virtual ~WindowState(); |
| 45 | 47 |
| 46 aura::Window* window() { return window_; } | 48 aura::Window* window() { return window_; } |
| 47 const aura::Window* window() const { return window_; } | 49 const aura::Window* window() const { return window_; } |
| 48 | 50 |
| 51 void SetDelegate(WindowStateDelegate* delegate); |
| 52 |
| 49 // Returns the window's current show state. | 53 // Returns the window's current show state. |
| 50 ui::WindowShowState GetShowState() const; | 54 ui::WindowShowState GetShowState() const; |
| 51 | 55 |
| 52 // Returns the window's current ash show type. | 56 // Returns the window's current ash show type. |
| 53 // Refer to WindowShowType definition in wm_types.h as for why Ash | 57 // Refer to WindowShowType definition in wm_types.h as for why Ash |
| 54 // has its own show type. | 58 // has its own show type. |
| 55 WindowShowType window_show_type() const { return window_show_type_; } | 59 WindowShowType window_show_type() const { return window_show_type_; } |
| 56 | 60 |
| 57 // Predicates to check window state. | 61 // Predicates to check window state. |
| 58 bool IsMinimized() const; | 62 bool IsMinimized() const; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 // Returns true if the window has restore bounds. | 78 // Returns true if the window has restore bounds. |
| 75 bool HasRestoreBounds() const; | 79 bool HasRestoreBounds() const; |
| 76 | 80 |
| 77 void Maximize(); | 81 void Maximize(); |
| 78 void Minimize(); | 82 void Minimize(); |
| 79 void Unminimize(); | 83 void Unminimize(); |
| 80 void Activate(); | 84 void Activate(); |
| 81 void Deactivate(); | 85 void Deactivate(); |
| 82 void Restore(); | 86 void Restore(); |
| 83 void ToggleMaximized(); | 87 void ToggleMaximized(); |
| 88 void ToggleFullscreen(); |
| 84 void SnapLeft(const gfx::Rect& bounds); | 89 void SnapLeft(const gfx::Rect& bounds); |
| 85 void SnapRight(const gfx::Rect& bounds); | 90 void SnapRight(const gfx::Rect& bounds); |
| 86 | 91 |
| 87 // Sets the window's bounds in screen coordinates. | 92 // Sets the window's bounds in screen coordinates. |
| 88 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen); | 93 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen); |
| 89 | 94 |
| 90 // Saves the current bounds to be used as a restore bounds. | 95 // Saves the current bounds to be used as a restore bounds. |
| 91 void SaveCurrentBoundsForRestore(); | 96 void SaveCurrentBoundsForRestore(); |
| 92 | 97 |
| 93 // Same as |GetRestoreBoundsInScreen| except that it returns the | 98 // Same as |GetRestoreBoundsInScreen| except that it returns the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 115 // bounds instead of the restore bounds. Setting this key overrides that | 120 // bounds instead of the restore bounds. Setting this key overrides that |
| 116 // behaviour). The flag is reset to the default value after the window is | 121 // behaviour). The flag is reset to the default value after the window is |
| 117 // restored. | 122 // restored. |
| 118 bool always_restores_to_restore_bounds() const { | 123 bool always_restores_to_restore_bounds() const { |
| 119 return always_restores_to_restore_bounds_; | 124 return always_restores_to_restore_bounds_; |
| 120 } | 125 } |
| 121 void set_always_restores_to_restore_bounds(bool value) { | 126 void set_always_restores_to_restore_bounds(bool value) { |
| 122 always_restores_to_restore_bounds_ = value; | 127 always_restores_to_restore_bounds_ = value; |
| 123 } | 128 } |
| 124 | 129 |
| 130 // Sets/gets the flag to suppress the cross-fade animation for |
| 131 // the transition to the fullscreen state. |
| 132 bool animate_to_fullscreen() const { |
| 133 return animate_to_fullscreen_; |
| 134 } |
| 135 void set_animate_to_fullscreen(bool value) { |
| 136 animate_to_fullscreen_ = value; |
| 137 } |
| 138 |
| 125 // Gets/Sets the bounds of the window before it was moved by the auto window | 139 // Gets/Sets the bounds of the window before it was moved by the auto window |
| 126 // management. As long as it was not auto-managed, it will return NULL. | 140 // management. As long as it was not auto-managed, it will return NULL. |
| 127 const gfx::Rect* pre_auto_manage_window_bounds() const { | 141 const gfx::Rect* pre_auto_manage_window_bounds() const { |
| 128 return pre_auto_manage_window_bounds_.get(); | 142 return pre_auto_manage_window_bounds_.get(); |
| 129 } | 143 } |
| 130 void SetPreAutoManageWindowBounds(const gfx::Rect& bounds); | 144 void SetPreAutoManageWindowBounds(const gfx::Rect& bounds); |
| 131 | 145 |
| 132 // Layout related properties | 146 // Layout related properties |
| 133 | 147 |
| 134 void AddObserver(WindowStateObserver* observer); | 148 void AddObserver(WindowStateObserver* observer); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 intptr_t old) OVERRIDE; | 215 intptr_t old) OVERRIDE; |
| 202 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | 216 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 203 | 217 |
| 204 private: | 218 private: |
| 205 // Snaps the window to left or right of the desktop with given bounds. | 219 // Snaps the window to left or right of the desktop with given bounds. |
| 206 void SnapWindow(WindowShowType left_or_right, | 220 void SnapWindow(WindowShowType left_or_right, |
| 207 const gfx::Rect& bounds); | 221 const gfx::Rect& bounds); |
| 208 | 222 |
| 209 // The owner of this window settings. | 223 // The owner of this window settings. |
| 210 aura::Window* window_; | 224 aura::Window* window_; |
| 225 scoped_ptr<WindowStateDelegate> delegate_; |
| 211 | 226 |
| 212 bool tracked_by_workspace_; | 227 bool tracked_by_workspace_; |
| 213 bool window_position_managed_; | 228 bool window_position_managed_; |
| 214 bool bounds_changed_by_user_; | 229 bool bounds_changed_by_user_; |
| 215 bool panel_attached_; | 230 bool panel_attached_; |
| 216 bool continue_drag_after_reparent_; | 231 bool continue_drag_after_reparent_; |
| 217 bool ignored_by_shelf_; | 232 bool ignored_by_shelf_; |
| 218 bool can_consume_system_keys_; | 233 bool can_consume_system_keys_; |
| 219 bool top_row_keys_are_function_keys_; | 234 bool top_row_keys_are_function_keys_; |
| 220 | |
| 221 bool always_restores_to_restore_bounds_; | 235 bool always_restores_to_restore_bounds_; |
| 236 bool animate_to_fullscreen_; |
| 222 | 237 |
| 223 // A property to remember the window position which was set before the | 238 // A property to remember the window position which was set before the |
| 224 // auto window position manager changed the window bounds, so that it can get | 239 // auto window position manager changed the window bounds, so that it can get |
| 225 // restored when only this one window gets shown. | 240 // restored when only this one window gets shown. |
| 226 scoped_ptr<gfx::Rect> pre_auto_manage_window_bounds_; | 241 scoped_ptr<gfx::Rect> pre_auto_manage_window_bounds_; |
| 227 | 242 |
| 228 ObserverList<WindowStateObserver> observer_list_; | 243 ObserverList<WindowStateObserver> observer_list_; |
| 229 | 244 |
| 230 WindowShowType window_show_type_; | 245 WindowShowType window_show_type_; |
| 231 | 246 |
| 232 DISALLOW_COPY_AND_ASSIGN(WindowState); | 247 DISALLOW_COPY_AND_ASSIGN(WindowState); |
| 233 }; | 248 }; |
| 234 | 249 |
| 235 // Returns the WindowState for active window. Returns |NULL| | 250 // Returns the WindowState for active window. Returns |NULL| |
| 236 // if there is no active window. | 251 // if there is no active window. |
| 237 ASH_EXPORT WindowState* GetActiveWindowState(); | 252 ASH_EXPORT WindowState* GetActiveWindowState(); |
| 238 | 253 |
| 239 // Returns the WindowState for |window|. Creates WindowState | 254 // Returns the WindowState for |window|. Creates WindowState |
| 240 // if it didn't exist. The settings object is owned by |window|. | 255 // if it didn't exist. The settings object is owned by |window|. |
| 241 ASH_EXPORT WindowState* GetWindowState(aura::Window* window); | 256 ASH_EXPORT WindowState* GetWindowState(aura::Window* window); |
| 242 | 257 |
| 243 // const version of GetWindowState. | 258 // const version of GetWindowState. |
| 244 ASH_EXPORT const WindowState* | 259 ASH_EXPORT const WindowState* |
| 245 GetWindowState(const aura::Window* window); | 260 GetWindowState(const aura::Window* window); |
| 246 | 261 |
| 247 } // namespace wm | 262 } // namespace wm |
| 248 } // namespace ash | 263 } // namespace ash |
| 249 | 264 |
| 250 #endif // ASH_WM_WINDOW_STATE_H_ | 265 #endif // ASH_WM_WINDOW_STATE_H_ |
| OLD | NEW |