Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: ash/wm/window_state.cc

Issue 1890713002: Adds WmWindow and converts WindowState to use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge again Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/window_state.h ('k') | ash/wm/window_state_aura.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ash/wm/window_state.h" 5 #include "ash/wm/window_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
11 #include "ash/screen_util.h" 11 #include "ash/screen_util.h"
12 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
13 #include "ash/wm/common/wm_event.h" 13 #include "ash/wm/common/wm_event.h"
14 #include "ash/wm/common/wm_screen_util.h"
14 #include "ash/wm/default_state.h" 15 #include "ash/wm/default_state.h"
15 #include "ash/wm/window_animations.h"
16 #include "ash/wm/window_properties.h"
17 #include "ash/wm/window_state_delegate.h" 16 #include "ash/wm/window_state_delegate.h"
18 #include "ash/wm/window_state_observer.h" 17 #include "ash/wm/window_state_observer.h"
19 #include "ash/wm/window_util.h" 18 #include "ash/wm/window_util.h"
20 #include "base/auto_reset.h" 19 #include "base/auto_reset.h"
21 #include "base/command_line.h"
22 #include "ui/aura/client/aura_constants.h" 20 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/layout_manager.h"
24 #include "ui/aura/window.h"
25 #include "ui/aura/window_delegate.h"
26 #include "ui/compositor/layer_tree_owner.h"
27 #include "ui/compositor/scoped_layer_animation_settings.h"
28 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
29 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
30 #include "ui/wm/core/window_util.h"
31 23
32 namespace ash { 24 namespace ash {
33 namespace wm { 25 namespace wm {
34 26
35 namespace { 27 namespace {
36 28
37 // A tentative class to set the bounds on the window.
38 // TODO(oshima): Once all logic is cleaned up, move this to the real layout
39 // manager with proper friendship.
40 class BoundsSetter : public aura::LayoutManager {
41 public:
42 BoundsSetter() {}
43 ~BoundsSetter() override {}
44
45 // aura::LayoutManager overrides:
46 void OnWindowResized() override {}
47 void OnWindowAddedToLayout(aura::Window* child) override {}
48 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
49 void OnWindowRemovedFromLayout(aura::Window* child) override {}
50 void OnChildWindowVisibilityChanged(aura::Window* child,
51 bool visible) override {}
52 void SetChildBounds(aura::Window* child,
53 const gfx::Rect& requested_bounds) override {}
54
55 void SetBounds(aura::Window* window, const gfx::Rect& bounds) {
56 SetChildBoundsDirect(window, bounds);
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(BoundsSetter);
61 };
62
63 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { 29 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) {
64 switch (requested_show_state) { 30 switch (requested_show_state) {
65 case ui::SHOW_STATE_DEFAULT: 31 case ui::SHOW_STATE_DEFAULT:
66 case ui::SHOW_STATE_NORMAL: 32 case ui::SHOW_STATE_NORMAL:
67 return WM_EVENT_NORMAL; 33 return WM_EVENT_NORMAL;
68 case ui::SHOW_STATE_MINIMIZED: 34 case ui::SHOW_STATE_MINIMIZED:
69 return WM_EVENT_MINIMIZE; 35 return WM_EVENT_MINIMIZE;
70 case ui::SHOW_STATE_MAXIMIZED: 36 case ui::SHOW_STATE_MAXIMIZED:
71 return WM_EVENT_MAXIMIZE; 37 return WM_EVENT_MAXIMIZE;
72 case ui::SHOW_STATE_FULLSCREEN: 38 case ui::SHOW_STATE_FULLSCREEN:
73 return WM_EVENT_FULLSCREEN; 39 return WM_EVENT_FULLSCREEN;
74 case ui::SHOW_STATE_INACTIVE: 40 case ui::SHOW_STATE_INACTIVE:
75 return WM_EVENT_SHOW_INACTIVE; 41 return WM_EVENT_SHOW_INACTIVE;
76 case ui::SHOW_STATE_DOCKED: 42 case ui::SHOW_STATE_DOCKED:
77 return WM_EVENT_DOCK; 43 return WM_EVENT_DOCK;
78 case ui::SHOW_STATE_END: 44 case ui::SHOW_STATE_END:
79 NOTREACHED() << "No WMEvent defined for the show state:" 45 NOTREACHED() << "No WMEvent defined for the show state:"
80 << requested_show_state; 46 << requested_show_state;
81 } 47 }
82 return WM_EVENT_NORMAL; 48 return WM_EVENT_NORMAL;
83 } 49 }
84 50
85 } // namespace 51 } // namespace
86 52
87 WindowState::~WindowState() { 53 WindowState::~WindowState() {
88 // WindowState is registered as an owned property of |window_|, and window
89 // unregisters all of its observers in its d'tor before destroying its
90 // properties. As a result, window_->RemoveObserver() doesn't need to (and
91 // shouldn't) be called here.
92 } 54 }
93 55
94 bool WindowState::HasDelegate() const { 56 bool WindowState::HasDelegate() const {
95 return !!delegate_; 57 return !!delegate_;
96 } 58 }
97 59
98 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { 60 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) {
99 DCHECK(!delegate_.get()); 61 DCHECK(!delegate_.get());
100 delegate_ = std::move(delegate); 62 delegate_ = std::move(delegate);
101 } 63 }
(...skipping 28 matching lines...) Expand all
130 bool WindowState::IsNormalStateType() const { 92 bool WindowState::IsNormalStateType() const {
131 return GetStateType() == WINDOW_STATE_TYPE_NORMAL || 93 return GetStateType() == WINDOW_STATE_TYPE_NORMAL ||
132 GetStateType() == WINDOW_STATE_TYPE_DEFAULT; 94 GetStateType() == WINDOW_STATE_TYPE_DEFAULT;
133 } 95 }
134 96
135 bool WindowState::IsNormalOrSnapped() const { 97 bool WindowState::IsNormalOrSnapped() const {
136 return IsNormalStateType() || IsSnapped(); 98 return IsNormalStateType() || IsSnapped();
137 } 99 }
138 100
139 bool WindowState::IsActive() const { 101 bool WindowState::IsActive() const {
140 return IsActiveWindow(window_); 102 return window_->IsActive();
141 } 103 }
142 104
143 bool WindowState::IsDocked() const { 105 bool WindowState::IsDocked() const {
144 return GetStateType() == WINDOW_STATE_TYPE_DOCKED || 106 return GetStateType() == WINDOW_STATE_TYPE_DOCKED ||
145 GetStateType() == WINDOW_STATE_TYPE_DOCKED_MINIMIZED; 107 GetStateType() == WINDOW_STATE_TYPE_DOCKED_MINIMIZED;
146 } 108 }
147 109
148 bool WindowState::IsUserPositionable() const { 110 bool WindowState::IsUserPositionable() const {
149 return (window()->type() == ui::wm::WINDOW_TYPE_NORMAL || 111 return (window_->GetType() == ui::wm::WINDOW_TYPE_NORMAL ||
150 window()->type() == ui::wm::WINDOW_TYPE_PANEL); 112 window_->GetType() == ui::wm::WINDOW_TYPE_PANEL);
151 } 113 }
152 114
153 bool WindowState::CanMaximize() const { 115 bool WindowState::CanMaximize() const {
154 // Window must have the kCanMaximizeKey and have no maximum width or height. 116 // Window must have the kCanMaximizeKey and have no maximum width or height.
155 if (!window()->GetProperty(aura::client::kCanMaximizeKey)) 117 if (!window_->CanMaximize())
156 return false; 118 return false;
157 119
158 if (!window()->delegate()) 120 if (!window_->HasNonClientArea())
159 return true; 121 return true;
160 122
161 gfx::Size max_size = window_->delegate()->GetMaximumSize(); 123 gfx::Size max_size = window_->GetMaximumSize();
162 return !max_size.width() && !max_size.height(); 124 return !max_size.width() && !max_size.height();
163 } 125 }
164 126
165 bool WindowState::CanMinimize() const { 127 bool WindowState::CanMinimize() const {
166 return window()->GetProperty(aura::client::kCanMinimizeKey); 128 return window_->CanMinimize();
167 } 129 }
168 130
169 bool WindowState::CanResize() const { 131 bool WindowState::CanResize() const {
170 return window_->GetProperty(aura::client::kCanResizeKey); 132 return window_->CanResize();
171 } 133 }
172 134
173 bool WindowState::CanActivate() const { 135 bool WindowState::CanActivate() const {
174 return ::wm::CanActivateWindow(window_); 136 return window_->CanActivate();
175 } 137 }
176 138
177 bool WindowState::CanSnap() const { 139 bool WindowState::CanSnap() const {
178 if (!CanResize() || window_->type() == ui::wm::WINDOW_TYPE_PANEL || 140 if (!CanResize() || window_->GetType() == ui::wm::WINDOW_TYPE_PANEL ||
179 ::wm::GetTransientParent(window_)) 141 window_->GetTransientParent()) {
180 return false; 142 return false;
143 }
181 // If a window cannot be maximized, assume it cannot snap either. 144 // If a window cannot be maximized, assume it cannot snap either.
182 // TODO(oshima): We should probably snap if the maximum size is greater than 145 // TODO(oshima): We should probably snap if the maximum size is greater than
183 // the snapped size. 146 // the snapped size.
184 return CanMaximize(); 147 return CanMaximize();
185 } 148 }
186 149
187 bool WindowState::HasRestoreBounds() const { 150 bool WindowState::HasRestoreBounds() const {
188 return window_->GetProperty(aura::client::kRestoreBoundsKey) != NULL; 151 return window_->HasRestoreBounds();
189 } 152 }
190 153
191 void WindowState::Maximize() { 154 void WindowState::Maximize() {
192 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 155 window_->Maximize();
193 } 156 }
194 157
195 void WindowState::Minimize() { 158 void WindowState::Minimize() {
196 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 159 window_->Minimize();
197 } 160 }
198 161
199 void WindowState::Unminimize() { 162 void WindowState::Unminimize() {
200 window_->SetProperty( 163 window_->Unminimize();
201 aura::client::kShowStateKey,
202 window_->GetProperty(aura::client::kRestoreShowStateKey));
203 window_->ClearProperty(aura::client::kRestoreShowStateKey);
204 } 164 }
205 165
206 void WindowState::Activate() { 166 void WindowState::Activate() {
207 ActivateWindow(window_); 167 window_->Activate();
208 } 168 }
209 169
210 void WindowState::Deactivate() { 170 void WindowState::Deactivate() {
211 DeactivateWindow(window_); 171 window_->Deactivate();
212 } 172 }
213 173
214 void WindowState::Restore() { 174 void WindowState::Restore() {
215 if (!IsNormalStateType()) { 175 if (!IsNormalStateType()) {
216 const WMEvent event(WM_EVENT_NORMAL); 176 const WMEvent event(WM_EVENT_NORMAL);
217 OnWMEvent(&event); 177 OnWMEvent(&event);
218 } 178 }
219 } 179 }
220 180
221 void WindowState::DisableAlwaysOnTop(aura::Window* window_on_top) { 181 void WindowState::DisableAlwaysOnTop(WmWindow* window_on_top) {
222 DCHECK(window_on_top); 182 DCHECK(window_on_top);
223 if (GetAlwaysOnTop()) { 183 if (GetAlwaysOnTop()) {
224 // |window_| is hidden first to avoid canceling fullscreen mode when it is 184 // |window_| is hidden first to avoid canceling fullscreen mode when it is
225 // no longer always on top and gets added to default container. This avoids 185 // no longer always on top and gets added to default container. This avoids
226 // sending redundant OnFullscreenStateChanged to the layout manager. The 186 // sending redundant OnFullscreenStateChanged to the layout manager. The
227 // |window_| visibility is restored after it no longer obscures the 187 // |window_| visibility is restored after it no longer obscures the
228 // |window_on_top|. 188 // |window_on_top|.
229 bool visible = window_->IsVisible(); 189 bool visible = window_->IsVisible();
230 if (visible) 190 if (visible)
231 window_->Hide(); 191 window_->Hide();
232 window_->SetProperty(aura::client::kAlwaysOnTopKey, false); 192 window_->SetAlwaysOnTop(false);
233 // Technically it is possible that a |window_| could make itself 193 // Technically it is possible that a |window_| could make itself
234 // always_on_top really quickly. This is probably not a realistic case but 194 // always_on_top really quickly. This is probably not a realistic case but
235 // check if the two windows are in the same container just in case. 195 // check if the two windows are in the same container just in case.
236 if (window_on_top->parent() == window_->parent()) 196 if (window_on_top->GetParent() == window_->GetParent())
237 window_->parent()->StackChildAbove(window_on_top, window_); 197 window_->GetParent()->StackChildAbove(window_on_top, window_);
238 if (visible) 198 if (visible)
239 window_->Show(); 199 window_->Show();
240 cached_always_on_top_ = true; 200 cached_always_on_top_ = true;
241 } 201 }
242 } 202 }
243 203
244 void WindowState::RestoreAlwaysOnTop() { 204 void WindowState::RestoreAlwaysOnTop() {
245 if (delegate() && delegate()->RestoreAlwaysOnTop(this)) 205 if (delegate() && delegate()->RestoreAlwaysOnTop(this))
246 return; 206 return;
247 if (cached_always_on_top_) { 207 if (cached_always_on_top_) {
248 cached_always_on_top_ = false; 208 cached_always_on_top_ = false;
249 window_->SetProperty(aura::client::kAlwaysOnTopKey, true); 209 window_->SetAlwaysOnTop(true);
250 } 210 }
251 } 211 }
252 212
253 void WindowState::OnWMEvent(const WMEvent* event) { 213 void WindowState::OnWMEvent(const WMEvent* event) {
254 current_state_->OnWMEvent(this, event); 214 current_state_->OnWMEvent(this, event);
255 } 215 }
256 216
257 void WindowState::SaveCurrentBoundsForRestore() { 217 void WindowState::SaveCurrentBoundsForRestore() {
258 gfx::Rect bounds_in_screen = 218 gfx::Rect bounds_in_screen =
259 ScreenUtil::ConvertRectToScreen(window_->parent(), 219 window_->GetParent()->ConvertRectToScreen(window_->GetBounds());
260 window_->bounds());
261 SetRestoreBoundsInScreen(bounds_in_screen); 220 SetRestoreBoundsInScreen(bounds_in_screen);
262 } 221 }
263 222
264 gfx::Rect WindowState::GetRestoreBoundsInScreen() const { 223 gfx::Rect WindowState::GetRestoreBoundsInScreen() const {
265 return *window_->GetProperty(aura::client::kRestoreBoundsKey); 224 return window_->GetRestoreBoundsInScreen();
266 } 225 }
267 226
268 gfx::Rect WindowState::GetRestoreBoundsInParent() const { 227 gfx::Rect WindowState::GetRestoreBoundsInParent() const {
269 return ScreenUtil::ConvertRectFromScreen(window_->parent(), 228 return window_->GetParent()->ConvertRectFromScreen(
270 GetRestoreBoundsInScreen()); 229 GetRestoreBoundsInScreen());
271 } 230 }
272 231
273 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { 232 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) {
274 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); 233 window_->SetRestoreBoundsInScreen(bounds);
275 } 234 }
276 235
277 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) { 236 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) {
278 SetRestoreBoundsInScreen( 237 SetRestoreBoundsInScreen(window_->GetParent()->ConvertRectToScreen(bounds));
279 ScreenUtil::ConvertRectToScreen(window_->parent(), bounds));
280 } 238 }
281 239
282 void WindowState::ClearRestoreBounds() { 240 void WindowState::ClearRestoreBounds() {
283 window_->ClearProperty(aura::client::kRestoreBoundsKey); 241 window_->ClearRestoreBounds();
284 } 242 }
285 243
286 std::unique_ptr<WindowState::State> WindowState::SetStateObject( 244 std::unique_ptr<WindowState::State> WindowState::SetStateObject(
287 std::unique_ptr<WindowState::State> new_state) { 245 std::unique_ptr<WindowState::State> new_state) {
288 current_state_->DetachState(this); 246 current_state_->DetachState(this);
289 std::unique_ptr<WindowState::State> old_object = std::move(current_state_); 247 std::unique_ptr<WindowState::State> old_object = std::move(current_state_);
290 current_state_ = std::move(new_state); 248 current_state_ = std::move(new_state);
291 current_state_->AttachState(this, old_object.get()); 249 current_state_->AttachState(this, old_object.get());
292 return old_object; 250 return old_object;
293 } 251 }
(...skipping 10 matching lines...) Expand all
304 void WindowState::RemoveObserver(WindowStateObserver* observer) { 262 void WindowState::RemoveObserver(WindowStateObserver* observer) {
305 observer_list_.RemoveObserver(observer); 263 observer_list_.RemoveObserver(observer);
306 } 264 }
307 265
308 void WindowState::set_bounds_changed_by_user(bool bounds_changed_by_user) { 266 void WindowState::set_bounds_changed_by_user(bool bounds_changed_by_user) {
309 bounds_changed_by_user_ = bounds_changed_by_user; 267 bounds_changed_by_user_ = bounds_changed_by_user;
310 if (bounds_changed_by_user) 268 if (bounds_changed_by_user)
311 pre_auto_manage_window_bounds_.reset(); 269 pre_auto_manage_window_bounds_.reset();
312 } 270 }
313 271
314 void WindowState::CreateDragDetails(aura::Window* window, 272 void WindowState::CreateDragDetails(const gfx::Point& point_in_parent,
315 const gfx::Point& point_in_parent,
316 int window_component, 273 int window_component,
317 aura::client::WindowMoveSource source) { 274 aura::client::WindowMoveSource source) {
318 drag_details_.reset( 275 drag_details_.reset(
319 new DragDetails(window, point_in_parent, window_component, source)); 276 new DragDetails(window_, point_in_parent, window_component, source));
320 } 277 }
321 278
322 void WindowState::DeleteDragDetails() { 279 void WindowState::DeleteDragDetails() {
323 drag_details_.reset(); 280 drag_details_.reset();
324 } 281 }
325 282
326 void WindowState::SetAndClearRestoreBounds() { 283 void WindowState::SetAndClearRestoreBounds() {
327 DCHECK(HasRestoreBounds()); 284 DCHECK(HasRestoreBounds());
328 SetBoundsInScreen(GetRestoreBoundsInScreen()); 285 SetBoundsInScreen(GetRestoreBoundsInScreen());
329 ClearRestoreBounds(); 286 ClearRestoreBounds();
330 } 287 }
331 288
332 void WindowState::OnWindowPropertyChanged(aura::Window* window, 289 void WindowState::OnWindowShowStateChanged() {
333 const void* key, 290 if (!ignore_property_change_) {
334 intptr_t old) {
335 DCHECK_EQ(window, window_);
336 if (key == aura::client::kShowStateKey && !ignore_property_change_) {
337 WMEvent event(WMEventTypeFromShowState(GetShowState())); 291 WMEvent event(WMEventTypeFromShowState(GetShowState()));
338 OnWMEvent(&event); 292 OnWMEvent(&event);
339 } 293 }
340 } 294 }
341 295
342 WindowState::WindowState(aura::Window* window) 296 WindowState::WindowState(WmWindow* window)
343 : window_(window), 297 : window_(window),
344 window_position_managed_(false), 298 window_position_managed_(false),
345 bounds_changed_by_user_(false), 299 bounds_changed_by_user_(false),
346 panel_attached_(true), 300 panel_attached_(true),
347 ignored_by_shelf_(false), 301 ignored_by_shelf_(false),
348 can_consume_system_keys_(false), 302 can_consume_system_keys_(false),
349 top_row_keys_are_function_keys_(false), 303 top_row_keys_are_function_keys_(false),
350 unminimize_to_restore_bounds_(false), 304 unminimize_to_restore_bounds_(false),
351 in_immersive_fullscreen_(false), 305 in_immersive_fullscreen_(false),
352 hide_shelf_when_fullscreen_(true), 306 hide_shelf_when_fullscreen_(true),
353 minimum_visibility_(false), 307 minimum_visibility_(false),
354 can_be_dragged_(true), 308 can_be_dragged_(true),
355 cached_always_on_top_(false), 309 cached_always_on_top_(false),
356 ignore_property_change_(false), 310 ignore_property_change_(false),
357 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) { 311 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {}
358 window_->AddObserver(this);
359 }
360 312
361 bool WindowState::GetAlwaysOnTop() const { 313 bool WindowState::GetAlwaysOnTop() const {
362 return window_->GetProperty(aura::client::kAlwaysOnTopKey); 314 return window_->IsAlwaysOnTop();
363 } 315 }
364 316
365 ui::WindowShowState WindowState::GetShowState() const { 317 ui::WindowShowState WindowState::GetShowState() const {
366 return window_->GetProperty(aura::client::kShowStateKey); 318 return window_->GetShowState();
367 } 319 }
368 320
369 void WindowState::SetBoundsInScreen( 321 void WindowState::SetBoundsInScreen(
370 const gfx::Rect& bounds_in_screen) { 322 const gfx::Rect& bounds_in_screen) {
371 gfx::Rect bounds_in_parent = 323 gfx::Rect bounds_in_parent =
372 ScreenUtil::ConvertRectFromScreen(window_->parent(), 324 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen);
373 bounds_in_screen);
374 window_->SetBounds(bounds_in_parent); 325 window_->SetBounds(bounds_in_parent);
375 } 326 }
376 327
377 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { 328 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) {
378 if (is_dragged() || !IsSnapped()) 329 if (is_dragged() || !IsSnapped())
379 return; 330 return;
380 gfx::Rect maximized_bounds = ScreenUtil::GetMaximizedWindowBoundsInParent( 331 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_);
381 window_);
382 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) 332 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED)
383 bounds->set_x(maximized_bounds.x()); 333 bounds->set_x(maximized_bounds.x());
384 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) 334 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED)
385 bounds->set_x(maximized_bounds.right() - bounds->width()); 335 bounds->set_x(maximized_bounds.right() - bounds->width());
386 bounds->set_y(maximized_bounds.y()); 336 bounds->set_y(maximized_bounds.y());
387 bounds->set_height(maximized_bounds.height()); 337 bounds->set_height(maximized_bounds.height());
388 } 338 }
389 339
390 void WindowState::UpdateWindowShowStateFromStateType() { 340 void WindowState::UpdateWindowShowStateFromStateType() {
391 ui::WindowShowState new_window_state = 341 ui::WindowShowState new_window_state =
392 ToWindowShowState(current_state_->GetType()); 342 ToWindowShowState(current_state_->GetType());
393 if (new_window_state != GetShowState()) { 343 if (new_window_state != GetShowState()) {
394 base::AutoReset<bool> resetter(&ignore_property_change_, true); 344 base::AutoReset<bool> resetter(&ignore_property_change_, true);
395 window_->SetProperty(aura::client::kShowStateKey, new_window_state); 345 window_->SetShowState(new_window_state);
396 } 346 }
397 } 347 }
398 348
399 void WindowState::NotifyPreStateTypeChange( 349 void WindowState::NotifyPreStateTypeChange(
400 WindowStateType old_window_state_type) { 350 WindowStateType old_window_state_type) {
401 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, 351 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_,
402 OnPreWindowStateTypeChange(this, old_window_state_type)); 352 OnPreWindowStateTypeChange(this, old_window_state_type));
403 } 353 }
404 354
405 void WindowState::NotifyPostStateTypeChange( 355 void WindowState::NotifyPostStateTypeChange(
406 WindowStateType old_window_state_type) { 356 WindowStateType old_window_state_type) {
407 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, 357 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_,
408 OnPostWindowStateTypeChange(this, old_window_state_type)); 358 OnPostWindowStateTypeChange(this, old_window_state_type));
409 } 359 }
410 360
411 void WindowState::SetBoundsDirect(const gfx::Rect& bounds) { 361 void WindowState::SetBoundsDirect(const gfx::Rect& bounds) {
412 gfx::Rect actual_new_bounds(bounds); 362 gfx::Rect actual_new_bounds(bounds);
413 // Ensure we don't go smaller than our minimum bounds in "normal" window 363 // Ensure we don't go smaller than our minimum bounds in "normal" window
414 // modes 364 // modes
415 if (window_->delegate() && !IsMaximized() && !IsFullscreen()) { 365 if (window_->HasNonClientArea() && !IsMaximized() && !IsFullscreen()) {
416 // Get the minimum usable size of the minimum size and the screen size. 366 // Get the minimum usable size of the minimum size and the screen size.
417 gfx::Size min_size = window_->delegate()->GetMinimumSize(); 367 gfx::Size min_size = window_->GetMinimumSize();
418 min_size.SetToMin(gfx::Screen::GetScreen() 368 min_size.SetToMin(window_->GetDisplayNearestWindow().work_area().size());
419 ->GetDisplayNearestWindow(window_)
420 .work_area()
421 .size());
422 369
423 actual_new_bounds.set_width( 370 actual_new_bounds.set_width(
424 std::max(min_size.width(), actual_new_bounds.width())); 371 std::max(min_size.width(), actual_new_bounds.width()));
425 actual_new_bounds.set_height( 372 actual_new_bounds.set_height(
426 std::max(min_size.height(), actual_new_bounds.height())); 373 std::max(min_size.height(), actual_new_bounds.height()));
427 } 374 }
428 BoundsSetter().SetBounds(window_, actual_new_bounds); 375 window_->SetBoundsDirect(actual_new_bounds);
429 SnapWindowToPixelBoundary(window_);
430 } 376 }
431 377
432 void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) { 378 void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) {
433 gfx::Rect work_area_in_parent = 379 gfx::Rect work_area_in_parent = GetDisplayWorkAreaBoundsInParent(window_);
434 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_);
435 gfx::Rect child_bounds(bounds); 380 gfx::Rect child_bounds(bounds);
436 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 381 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds);
437 SetBoundsDirect(child_bounds); 382 SetBoundsDirect(child_bounds);
438 } 383 }
439 384
440 void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) { 385 void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) {
441 const int kBoundsChangeSlideDurationMs = 120; 386 window_->SetBoundsDirectAnimated(bounds);
442
443 ui::Layer* layer = window_->layer();
444 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator());
445 slide_settings.SetPreemptionStrategy(
446 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
447 slide_settings.SetTransitionDuration(
448 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs));
449 SetBoundsDirect(bounds);
450 } 387 }
451 388
452 void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) { 389 void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) {
453 // Some test results in invoking CrossFadeToBounds when window is not visible. 390 // Some test results in invoking CrossFadeToBounds when window is not visible.
454 // No animation is necessary in that case, thus just change the bounds and 391 // No animation is necessary in that case, thus just change the bounds and
455 // quit. 392 // quit.
456 if (!window_->TargetVisibility()) { 393 if (!window_->GetTargetVisibility()) {
457 SetBoundsConstrained(new_bounds); 394 SetBoundsConstrained(new_bounds);
458 return; 395 return;
459 } 396 }
460 397
461 const gfx::Rect old_bounds = window_->bounds(); 398 window_->SetBoundsDirectCrossFade(new_bounds);
462
463 // Create fresh layers for the window and all its children to paint into.
464 // Takes ownership of the old layer and all its children, which will be
465 // cleaned up after the animation completes.
466 // Specify |set_bounds| to true here to keep the old bounds in the child
467 // windows of |window|.
468 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner =
469 ::wm::RecreateLayers(window_);
470 ui::Layer* old_layer = old_layer_owner->root();
471 DCHECK(old_layer);
472 ui::Layer* new_layer = window_->layer();
473
474 // Resize the window to the new size, which will force a layout and paint.
475 SetBoundsDirect(new_bounds);
476
477 // Ensure the higher-resolution layer is on top.
478 bool old_on_top = (old_bounds.width() > new_bounds.width());
479 if (old_on_top)
480 old_layer->parent()->StackBelow(new_layer, old_layer);
481 else
482 old_layer->parent()->StackAbove(new_layer, old_layer);
483
484 CrossFadeAnimation(window_, std::move(old_layer_owner), gfx::Tween::EASE_OUT);
485 }
486
487 WindowState* GetActiveWindowState() {
488 aura::Window* active = GetActiveWindow();
489 return active ? GetWindowState(active) : NULL;
490 }
491
492 WindowState* GetWindowState(aura::Window* window) {
493 if (!window)
494 return NULL;
495 WindowState* settings = window->GetProperty(kWindowStateKey);
496 if(!settings) {
497 settings = new WindowState(window);
498 window->SetProperty(kWindowStateKey, settings);
499 }
500 return settings;
501 }
502
503 const WindowState* GetWindowState(const aura::Window* window) {
504 return GetWindowState(const_cast<aura::Window*>(window));
505 } 399 }
506 400
507 } // namespace wm 401 } // namespace wm
508 } // namespace ash 402 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_state.h ('k') | ash/wm/window_state_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698