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 #include "ash/wm/window_state.h" | 5 #include "ash/wm/window_state.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/wm/window_properties.h" | 10 #include "ash/wm/window_properties.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 129 |
| 130 void WindowState::Maximize() { | 130 void WindowState::Maximize() { |
| 131 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 131 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void WindowState::SnapLeft(const gfx::Rect& bounds) { | 134 void WindowState::SnapLeft(const gfx::Rect& bounds) { |
| 135 SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); | 135 SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void WindowState::SnapRight(const gfx::Rect& bounds) { | 138 void WindowState::SnapRight(const gfx::Rect& bounds) { |
| 139 SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); | 139 SnapWindow(SHOW_TYPE_RIGHT_SNAPPED, bounds); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void WindowState::Minimize() { | 142 void WindowState::Minimize() { |
| 143 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 143 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void WindowState::Unminimize() { | 146 void WindowState::Unminimize() { |
| 147 window_->SetProperty( | 147 window_->SetProperty( |
| 148 aura::client::kShowStateKey, | 148 aura::client::kShowStateKey, |
| 149 window_->GetProperty(aura::client::kRestoreShowStateKey)); | 149 window_->GetProperty(aura::client::kRestoreShowStateKey)); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 | 237 |
| 238 void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) { | 238 void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) { |
| 239 if (tracked_by_workspace_ == tracked_by_workspace) | 239 if (tracked_by_workspace_ == tracked_by_workspace) |
| 240 return; | 240 return; |
| 241 bool old = tracked_by_workspace_; | 241 bool old = tracked_by_workspace_; |
| 242 tracked_by_workspace_ = tracked_by_workspace; | 242 tracked_by_workspace_ = tracked_by_workspace; |
| 243 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, | 243 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, |
| 244 OnTrackedByWorkspaceChanged(this, old)); | 244 OnTrackedByWorkspaceChanged(this, old)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void WindowState::SetWindowShowTypeUnsnapped() { | |
| 248 if (window_show_type_ != SHOW_TYPE_LEFT_SNAPPED && | |
| 249 window_show_type_ != SHOW_TYPE_RIGHT_SNAPPED) { | |
| 250 return; | |
| 251 } | |
| 252 window_show_type_ = SHOW_TYPE_NORMAL; | |
|
oshima
2013/11/25 23:20:40
if (window_show_type_ == ||
varkha
2013/11/26 22:16:58
Done.
| |
| 253 } | |
| 254 | |
| 255 void WindowState::SetBoundsChangedByUser(bool bounds_changed_by_user) { | |
| 256 bounds_changed_by_user_ = bounds_changed_by_user; | |
| 257 if (bounds_changed_by_user_) | |
| 258 SetWindowShowTypeUnsnapped(); | |
| 259 } | |
| 260 | |
| 247 void WindowState::OnWindowPropertyChanged(aura::Window* window, | 261 void WindowState::OnWindowPropertyChanged(aura::Window* window, |
| 248 const void* key, | 262 const void* key, |
| 249 intptr_t old) { | 263 intptr_t old) { |
| 250 DCHECK_EQ(window, window_); | 264 DCHECK_EQ(window, window_); |
| 251 if (key == aura::client::kShowStateKey) { | 265 if (key == aura::client::kShowStateKey) { |
| 252 window_show_type_ = ToWindowShowType(GetShowState()); | 266 window_show_type_ = ToWindowShowType(GetShowState()); |
| 253 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | 267 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); |
| 254 // TODO(oshima): Notify only when the state has changed. | 268 // TODO(oshima): Notify only when the state has changed. |
| 255 // Doing so break a few tests now. | 269 // Doing so break a few tests now. |
| 256 FOR_EACH_OBSERVER( | 270 FOR_EACH_OBSERVER( |
| 257 WindowStateObserver, observer_list_, | 271 WindowStateObserver, observer_list_, |
| 258 OnWindowShowTypeChanged(this, ToWindowShowType(old_state))); | 272 OnWindowShowTypeChanged(this, ToWindowShowType(old_state))); |
| 259 } | 273 } |
| 260 } | 274 } |
| 261 | 275 |
| 262 void WindowState::OnWindowDestroying(aura::Window* window) { | 276 void WindowState::OnWindowDestroying(aura::Window* window) { |
| 263 window_->RemoveObserver(this); | 277 window_->RemoveObserver(this); |
| 264 } | 278 } |
| 265 | 279 |
| 266 void WindowState::SnapWindow(WindowShowType left_or_right, | 280 void WindowState::SnapWindow(WindowShowType left_or_right, |
| 267 const gfx::Rect& bounds) { | 281 const gfx::Rect& bounds) { |
| 268 if (IsMaximizedOrFullscreen()) { | 282 gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ? |
| 283 GetRestoreBoundsInScreen() : window_->GetBoundsInScreen()); | |
| 284 | |
| 285 bool was_maximized = IsMaximizedOrFullscreen(); | |
| 286 if (was_maximized) { | |
| 269 // Before we can set the bounds we need to restore the window. | 287 // Before we can set the bounds we need to restore the window. |
| 270 // Restoring the window will set the window to its restored bounds. | 288 // Restoring the window will set the window to its restored bounds. |
| 271 // To avoid an unnecessary bounds changes (which may have side effects) | 289 // To avoid an unnecessary bounds changes (which may have side effects) |
| 272 // we set the restore bounds to the bounds we want, restore the window, | 290 // we set the restore bounds to the bounds we want, restore the window, |
| 273 // then reset the restore bounds. This way no unnecessary bounds | 291 // then recover the restore bounds. This way no unnecessary bounds |
| 274 // changes occurs and the original restore bounds is remembered. | 292 // changes occurs and the original restore bounds are remembered. |
| 275 gfx::Rect restore_bounds_in_screen = | |
| 276 GetRestoreBoundsInScreen(); | |
| 277 SetRestoreBoundsInParent(bounds); | 293 SetRestoreBoundsInParent(bounds); |
| 294 // Restore will cause OnWindowPropertyChanged so it needs to be done | |
| 295 // before notifying about show type change to snapped. | |
| 278 Restore(); | 296 Restore(); |
| 279 SetRestoreBoundsInScreen(restore_bounds_in_screen); | |
| 280 } else { | |
| 281 window_->SetBounds(bounds); | |
| 282 } | 297 } |
| 283 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || | 298 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || |
| 284 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); | 299 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); |
| 300 WindowShowType old_type = window_show_type_; | |
| 285 window_show_type_ = left_or_right; | 301 window_show_type_ = left_or_right; |
| 302 FOR_EACH_OBSERVER( | |
| 303 WindowStateObserver, observer_list_, | |
| 304 OnWindowShowTypeChanged(this, old_type)); | |
| 305 if (!was_maximized) | |
| 306 window_->SetBounds(bounds); | |
| 307 SetRestoreBoundsInScreen(restore_bounds_in_screen); | |
| 286 } | 308 } |
| 287 | 309 |
| 288 WindowState* GetActiveWindowState() { | 310 WindowState* GetActiveWindowState() { |
| 289 aura::Window* active = GetActiveWindow(); | 311 aura::Window* active = GetActiveWindow(); |
| 290 return active ? GetWindowState(active) : NULL; | 312 return active ? GetWindowState(active) : NULL; |
| 291 } | 313 } |
| 292 | 314 |
| 293 WindowState* GetWindowState(aura::Window* window) { | 315 WindowState* GetWindowState(aura::Window* window) { |
| 294 if (!window) | 316 if (!window) |
| 295 return NULL; | 317 return NULL; |
| 296 WindowState* settings = window->GetProperty(internal::kWindowStateKey); | 318 WindowState* settings = window->GetProperty(internal::kWindowStateKey); |
| 297 if(!settings) { | 319 if(!settings) { |
| 298 settings = new WindowState(window); | 320 settings = new WindowState(window); |
| 299 window->SetProperty(internal::kWindowStateKey, settings); | 321 window->SetProperty(internal::kWindowStateKey, settings); |
| 300 } | 322 } |
| 301 return settings; | 323 return settings; |
| 302 } | 324 } |
| 303 | 325 |
| 304 const WindowState* GetWindowState(const aura::Window* window) { | 326 const WindowState* GetWindowState(const aura::Window* window) { |
| 305 return GetWindowState(const_cast<aura::Window*>(window)); | 327 return GetWindowState(const_cast<aura::Window*>(window)); |
| 306 } | 328 } |
| 307 | 329 |
| 308 } // namespace wm | 330 } // namespace wm |
| 309 } // namespace ash | 331 } // namespace ash |
| OLD | NEW |