OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/window_state.h" | |
6 | |
7 #include "ash/root_window_controller.h" | |
8 #include "ash/screen_ash.h" | |
9 #include "ash/shell_window_ids.h" | |
10 #include "ash/wm/window_properties.h" | |
11 #include "ash/wm/window_util.h" | |
12 #include "ui/aura/client/aura_constants.h" | |
13 #include "ui/aura/window.h" | |
14 #include "ui/aura/window_delegate.h" | |
15 #include "ui/gfx/display.h" | |
16 #include "ui/views/corewm/window_util.h" | |
17 | |
18 namespace ash { | |
19 namespace wm { | |
20 | |
21 // static | |
22 bool WindowState::IsMaximizedOrFullscreenState(ui::WindowShowState show_state) { | |
23 return show_state == ui::SHOW_STATE_FULLSCREEN || | |
24 show_state == ui::SHOW_STATE_MAXIMIZED; | |
25 } | |
26 | |
27 WindowState::WindowState(aura::Window* window) | |
28 : window_(window), | |
29 tracked_by_workspace_(true), | |
30 window_position_managed_(false), | |
31 bounds_changed_by_user_(false), | |
32 panel_attached_(true), | |
33 continue_drag_after_reparent_(false), | |
34 ignored_by_shelf_(false), | |
35 always_restores_to_restore_bounds_(false) { | |
36 } | |
37 | |
38 WindowState::~WindowState() { | |
39 } | |
40 | |
41 ui::WindowShowState WindowState::GetShowState() const { | |
42 return window_->GetProperty(aura::client::kShowStateKey); | |
43 } | |
44 | |
45 bool WindowState::IsMinimized() const { | |
46 return GetShowState() == ui::SHOW_STATE_MINIMIZED; | |
47 } | |
48 | |
49 bool WindowState::IsMaximized() const { | |
50 return GetShowState() == ui::SHOW_STATE_MAXIMIZED; | |
51 } | |
52 | |
53 bool WindowState::IsFullscreen() const { | |
54 return GetShowState() == ui::SHOW_STATE_FULLSCREEN; | |
55 } | |
56 | |
57 bool WindowState::IsMaximizedOrFullscreen() const { | |
58 return IsMaximizedOrFullscreenState(GetShowState()); | |
59 } | |
60 | |
61 bool WindowState::IsNormal() const { | |
62 ui::WindowShowState state = window_->GetProperty(aura::client::kShowStateKey); | |
63 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT; | |
64 } | |
65 | |
66 bool WindowState::IsActive() const { | |
67 return IsActiveWindow(window_); | |
68 } | |
69 | |
70 bool WindowState::CanMaximize() const { | |
71 return window_->GetProperty(aura::client::kCanMaximizeKey); | |
72 } | |
73 | |
74 bool WindowState::CanMinimize() const { | |
James Cook
2013/09/18 20:44:17
I like how all the Ash-specific logic for this typ
| |
75 internal::RootWindowController* controller = | |
76 internal::RootWindowController::ForWindow(window_); | |
77 if (!controller) | |
78 return false; | |
79 aura::Window* lockscreen = controller->GetContainer( | |
80 internal::kShellWindowId_LockScreenContainersContainer); | |
81 if (lockscreen->Contains(window_)) | |
82 return false; | |
83 | |
84 return true; | |
85 } | |
86 | |
87 bool WindowState::CanResize() const { | |
88 return window_->GetProperty(aura::client::kCanResizeKey); | |
89 } | |
90 | |
91 bool WindowState::CanActivate() const { | |
92 return views::corewm::CanActivateWindow(window_); | |
93 } | |
94 | |
95 bool WindowState::CanSnap() const { | |
96 if (!CanResize()) | |
97 return false; | |
98 if (window_->type() == aura::client::WINDOW_TYPE_PANEL) | |
99 return false; | |
100 // If a window has a maximum size defined, snapping may make it too big. | |
101 return window_->delegate() ? window_->delegate()->GetMaximumSize().IsEmpty() : | |
102 true; | |
103 } | |
104 | |
105 bool WindowState::HasRestoreBounds() const { | |
106 return window_->GetProperty(aura::client::kRestoreBoundsKey) != NULL; | |
107 } | |
108 | |
109 void WindowState::Maximize() { | |
110 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
111 } | |
112 | |
113 void WindowState::Minimize() { | |
114 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
115 } | |
116 | |
117 void WindowState::Unminimize() { | |
118 window_->SetProperty( | |
119 aura::client::kShowStateKey, | |
120 window_->GetProperty(aura::client::kRestoreShowStateKey)); | |
James Cook
2013/09/18 20:44:17
Do we care what happens if this property doesn't e
oshima
2013/09/19 01:52:01
I'm not sure. This is what we are doing right now.
| |
121 window_->ClearProperty(aura::client::kRestoreShowStateKey); | |
122 } | |
123 | |
124 void WindowState::Activate() { | |
125 ActivateWindow(window_); | |
126 } | |
127 | |
128 void WindowState::Normalize() { | |
129 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
130 } | |
131 | |
132 void WindowState::Deactivate() { | |
133 DeactivateWindow(window_); | |
134 } | |
135 | |
136 void WindowState::Restore() { | |
137 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
138 } | |
139 | |
140 void WindowState::ToggleMaximized() { | |
141 if (IsMaximized()) | |
142 Restore(); | |
143 else if (CanMaximize()) | |
144 Maximize(); | |
145 } | |
146 | |
147 void WindowState::SetBoundsInScreen( | |
148 const gfx::Rect& bounds_in_screen) { | |
149 gfx::Rect bounds_in_parent = | |
150 ScreenAsh::ConvertRectFromScreen(window_->parent(), | |
151 bounds_in_screen); | |
152 window_->SetBounds(bounds_in_parent); | |
153 } | |
154 | |
155 void WindowState::SaveCurrentBoundsForRestore() { | |
156 gfx::Rect bounds_in_screen = | |
157 ScreenAsh::ConvertRectToScreen(window_->parent(), | |
158 window_->bounds()); | |
159 SetRestoreBoundsInScreen(bounds_in_screen); | |
160 } | |
161 | |
162 gfx::Rect WindowState::GetRestoreBoundsInScreen() const { | |
163 return *window_->GetProperty(aura::client::kRestoreBoundsKey); | |
James Cook
2013/09/18 20:44:17
Should this check if kRestoreBoundsKey exists?
oshima
2013/09/19 01:52:01
Another option is to return empty rect, but it may
James Cook
2013/09/19 03:49:53
Failing sounds fine here, especially since the old
| |
164 } | |
165 | |
166 gfx::Rect WindowState::GetRestoreBoundsInParent() const { | |
167 return ScreenAsh::ConvertRectFromScreen(window_->parent(), | |
168 GetRestoreBoundsInScreen()); | |
169 } | |
170 | |
171 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { | |
172 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); | |
173 } | |
174 | |
175 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) { | |
176 SetRestoreBoundsInScreen( | |
177 ScreenAsh::ConvertRectToScreen(window_->parent(), bounds)); | |
178 } | |
179 | |
180 void WindowState::ClearRestoreBounds() { | |
181 window_->ClearProperty(aura::client::kRestoreBoundsKey); | |
182 } | |
183 | |
184 void WindowState::SetPreAutoManageWindowBounds( | |
185 const gfx::Rect& bounds) { | |
186 pre_auto_manage_window_bounds_.reset(new gfx::Rect(bounds)); | |
187 } | |
188 | |
189 void WindowState::AddObserver(Observer* observer) { | |
190 observer_list_.AddObserver(observer); | |
191 } | |
192 | |
193 void WindowState::RemoveObserver(Observer* observer) { | |
194 observer_list_.RemoveObserver(observer); | |
195 } | |
196 | |
197 void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) { | |
198 if (tracked_by_workspace_ == tracked_by_workspace) | |
199 return; | |
200 bool old = tracked_by_workspace_; | |
201 tracked_by_workspace_ = tracked_by_workspace; | |
202 FOR_EACH_OBSERVER(Observer, observer_list_, | |
203 OnTrackedByWorkspaceChanged(window_, old)); | |
204 } | |
205 | |
206 WindowState* GetActiveWindowState() { | |
207 aura::Window* active = GetActiveWindow(); | |
208 return active ? GetWindowState(active) : NULL; | |
209 } | |
210 | |
211 WindowState* GetWindowState(aura::Window* window) { | |
212 if (!window) | |
213 return NULL; | |
214 WindowState* settings = window->GetProperty(internal::kWindowStateKey); | |
215 if(!settings) { | |
216 settings = new WindowState(window); | |
217 window->SetProperty(internal::kWindowStateKey, settings); | |
218 } | |
219 return settings; | |
220 } | |
221 | |
222 const WindowState* GetWindowState(const aura::Window* window) { | |
223 return GetWindowState(const_cast<aura::Window*>(window)); | |
224 } | |
225 | |
226 } // namespace wm | |
227 } // namespace ash | |
OLD | NEW |