Chromium Code Reviews| 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_SETTINGS_H_ | 5 #ifndef ASH_WM_WINDOW_STATE_H_ |
| 6 #define ASH_WM_WINDOW_SETTINGS_H_ | 6 #define ASH_WM_WINDOW_STATE_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "ui/base/ui_base_types.h" | |
| 11 | 13 |
| 12 namespace aura { | 14 namespace aura { |
| 13 class Window; | 15 class Window; |
| 14 } | 16 } |
| 15 | 17 |
| 18 namespace gfx { | |
| 19 class Rect; | |
| 20 } | |
| 21 | |
| 16 namespace ash { | 22 namespace ash { |
| 17 namespace wm { | 23 namespace wm { |
| 18 | 24 |
| 19 // Per managed window information should be stored here | 25 // WindowState manages and defines ash specific window state and |
| 20 // instead of using plain aura window property. | 26 // behavior. Ash specific per-window state (such as ones that controls |
| 21 class ASH_EXPORT WindowSettings { | 27 // window manager behavior) and ash specific window behavior (such as |
| 28 // Maximize, minimize, snap sizing etc) should be added here instead | |
|
James Cook
2013/09/19 03:49:53
Maximize -> maximize
oshima
2013/09/19 17:44:05
Done.
| |
| 29 // of defining separate functions (like |MaximizeWindow(aura::Window* | |
| 30 // window)|) nor using aura Window property. | |
|
James Cook
2013/09/19 03:49:53
nor -> or
oshima
2013/09/19 17:44:05
Done.
| |
| 31 // The WindowState gets created when first accessed by | |
| 32 // |wm::GetWindowState|, and deleted when the window is deleted. | |
|
James Cook
2013/09/19 03:49:53
You might also mention here your design principle
oshima
2013/09/19 17:44:05
Done.
| |
| 33 class ASH_EXPORT WindowState { | |
| 22 public: | 34 public: |
| 23 class ASH_EXPORT Observer { | 35 class ASH_EXPORT Observer { |
| 24 public: | 36 public: |
| 25 // Called when the tracked_by_workspace has changed. | 37 // Called when the tracked_by_workspace has changed. |
| 26 virtual void OnTrackedByWorkspaceChanged(aura::Window* window, | 38 virtual void OnTrackedByWorkspaceChanged(aura::Window* window, |
| 27 bool old_value) {} | 39 bool old_value) {} |
| 28 }; | 40 }; |
| 29 | 41 |
| 30 explicit WindowSettings(aura::Window* window); | 42 static bool IsMaximizedOrFullscreenState(ui::WindowShowState state); |
| 31 ~WindowSettings(); | 43 |
| 44 explicit WindowState(aura::Window* window); | |
| 45 ~WindowState(); | |
| 46 | |
| 47 aura::Window* window() { return window_; } | |
| 48 const aura::Window* window() const { return window_; } | |
| 49 | |
| 50 // Returns the window's current shows tate. | |
| 51 ui::WindowShowState GetShowState() const; | |
| 52 | |
| 53 // Predicates to check window state. | |
| 54 bool IsMinimized() const; | |
| 55 bool IsMaximized() const; | |
| 56 bool IsFullscreen() const; | |
| 57 bool IsMaximizedOrFullscreen() const; | |
| 58 // True if the window's show state is SHOW_STATE_NORMAL or | |
| 59 // SHOW_STATE_DEFAULT. | |
| 60 bool IsNormalShowState() const; | |
| 61 bool IsActive() const; | |
| 62 | |
| 63 // Checks if the window can change its state accordingly. | |
| 64 bool CanMaximize() const; | |
| 65 bool CanMinimize() const; | |
| 66 bool CanResize() const; | |
| 67 bool CanSnap() const; | |
| 68 bool CanActivate() const; | |
| 69 | |
| 70 // Returns true if the window has restore bounds. | |
| 71 bool HasRestoreBounds() const; | |
| 72 | |
| 73 void Maximize(); | |
| 74 void Minimize(); | |
| 75 void Unminimize(); | |
| 76 void Activate(); | |
| 77 void Deactivate(); | |
| 78 void Restore(); | |
| 79 void ToggleMaximized(); | |
| 80 | |
| 81 // Sets the window's bounds in screen coordinates. | |
| 82 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen); | |
| 83 | |
| 84 // Saves the current bounds to be used as a restore bounds. | |
| 85 void SaveCurrentBoundsForRestore(); | |
| 86 | |
| 87 // Same as |GetRestoreBoundsInScreen| except that it returns the | |
| 88 // bounds in the parent's coordinates. | |
| 89 gfx::Rect GetRestoreBoundsInParent() const; | |
| 90 | |
| 91 // Returns the restore bounds property on the window in the virtual screen | |
| 92 // coordinates. The bounds can be NULL if the bounds property does not | |
| 93 // exist for the window. The window owns the bounds object. | |
| 94 gfx::Rect GetRestoreBoundsInScreen() const; | |
| 95 | |
| 96 // Same as |SetRestoreBoundsInScreen| except that the bounds is in the | |
| 97 // parent's coordinates. | |
| 98 void SetRestoreBoundsInParent(const gfx::Rect& bounds_in_parent); | |
| 99 | |
| 100 // Sets the restore bounds property on the window in the virtual screen | |
| 101 // coordinates. Deletes existing bounds value if exists. | |
| 102 void SetRestoreBoundsInScreen(const gfx::Rect& bounds_in_screen); | |
| 103 | |
| 104 // Deletes and clears the restore bounds property on the window. | |
| 105 void ClearRestoreBounds(); | |
| 106 | |
| 107 // Sets whether the window should always be restored to the restore bounds | |
| 108 // (sometimes the workspace layout manager restores the window to its original | |
| 109 // bounds instead of the restore bounds. Setting this key overrides that | |
| 110 // behaviour). The flag is reset to the default value after the window is | |
| 111 // restored. | |
| 112 bool always_restores_to_restore_bounds() const { | |
| 113 return always_restores_to_restore_bounds_; | |
| 114 } | |
| 115 void set_always_restores_to_restore_bounds(bool value) { | |
| 116 always_restores_to_restore_bounds_ = value; | |
| 117 } | |
| 118 | |
| 119 // Gets/Sets the bounds of the window before it was moved by the auto window | |
| 120 // management. As long as it was not auto-managed, it will return NULL. | |
| 121 const gfx::Rect* pre_auto_manage_window_bounds() const { | |
| 122 return pre_auto_manage_window_bounds_.get(); | |
| 123 } | |
| 124 void SetPreAutoManageWindowBounds(const gfx::Rect& bounds); | |
| 125 | |
| 126 // Layout related properties | |
| 32 | 127 |
| 33 void AddObserver(Observer* observer); | 128 void AddObserver(Observer* observer); |
| 34 void RemoveObserver(Observer* observer); | 129 void RemoveObserver(Observer* observer); |
| 35 | 130 |
| 36 // Whether the window is tracked by workspace code. Default is | 131 // Whether the window is tracked by workspace code. Default is |
| 37 // true. If set to false the workspace does not switch the current | 132 // true. If set to false the workspace does not switch the current |
| 38 // workspace, nor does it attempt to impose constraints on the | 133 // workspace, nor does it attempt to impose constraints on the |
| 39 // bounds of the window. This is intended for tab dragging. | 134 // bounds of the window. This is intended for tab dragging. |
| 40 bool tracked_by_workspace() const { return tracked_by_workspace_; } | 135 bool tracked_by_workspace() const { return tracked_by_workspace_; } |
| 41 void SetTrackedByWorkspace(bool tracked_by_workspace); | 136 void SetTrackedByWorkspace(bool tracked_by_workspace); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 // The owner of this window settings. | 176 // The owner of this window settings. |
| 82 aura::Window* window_; | 177 aura::Window* window_; |
| 83 | 178 |
| 84 bool tracked_by_workspace_; | 179 bool tracked_by_workspace_; |
| 85 bool window_position_managed_; | 180 bool window_position_managed_; |
| 86 bool bounds_changed_by_user_; | 181 bool bounds_changed_by_user_; |
| 87 bool panel_attached_; | 182 bool panel_attached_; |
| 88 bool continue_drag_after_reparent_; | 183 bool continue_drag_after_reparent_; |
| 89 bool ignored_by_shelf_; | 184 bool ignored_by_shelf_; |
| 90 | 185 |
| 186 bool always_restores_to_restore_bounds_; | |
| 187 | |
| 188 // A property to remember the window position which was set before the | |
| 189 // auto window position manager changed the window bounds, so that it can get | |
| 190 // restored when only this one window gets shown. | |
| 191 scoped_ptr<gfx::Rect> pre_auto_manage_window_bounds_; | |
| 192 | |
| 91 ObserverList<Observer> observer_list_; | 193 ObserverList<Observer> observer_list_; |
| 92 | 194 |
| 93 DISALLOW_COPY_AND_ASSIGN(WindowSettings); | 195 DISALLOW_COPY_AND_ASSIGN(WindowState); |
| 94 }; | 196 }; |
| 95 | 197 |
| 96 // Returns the WindowSettings for |window|. Creates WindowSettings | 198 // Returns the WindowState for active window. Returns |NULL| |
| 199 // if there is no active window. | |
| 200 ASH_EXPORT WindowState* GetActiveWindowState(); | |
| 201 | |
| 202 // Returns the WindowState for |window|. Creates WindowState | |
| 97 // if it didn't exist. The settings object is owned by |window|. | 203 // if it didn't exist. The settings object is owned by |window|. |
| 98 ASH_EXPORT WindowSettings* GetWindowSettings(aura::Window* window); | 204 ASH_EXPORT WindowState* GetWindowState(aura::Window* window); |
| 99 | 205 |
| 100 // const version of GetWindowSettings. | 206 // const version of GetWindowState. |
| 101 ASH_EXPORT const WindowSettings* | 207 ASH_EXPORT const WindowState* |
| 102 GetWindowSettings(const aura::Window* window); | 208 GetWindowState(const aura::Window* window); |
| 103 | 209 |
| 104 } // namespace wm | 210 } // namespace wm |
| 105 } // namespace ash | 211 } // namespace ash |
| 106 | 212 |
| 107 #endif // ASH_WM_WINDOW_SETTINGS_H_ | 213 #endif // ASH_WM_WINDOW_STATE_H_ |
| OLD | NEW |