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