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); |
|
varkha
2013/11/20 00:11:13
We did not really use this show type so everything
| |
| 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; | |
| 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) { |
| 282 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || | |
| 283 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); | |
| 284 WindowShowType old_type = window_show_type_; | |
| 285 window_show_type_ = left_or_right; | |
| 286 FOR_EACH_OBSERVER( | |
| 287 WindowStateObserver, observer_list_, | |
| 288 OnWindowShowTypeChanged(this, old_type)); | |
| 268 if (IsMaximizedOrFullscreen()) { | 289 if (IsMaximizedOrFullscreen()) { |
| 269 // Before we can set the bounds we need to restore the window. | 290 // Before we can set the bounds we need to restore the window. |
| 270 // Restoring the window will set the window to its restored bounds. | 291 // Restoring the window will set the window to its restored bounds. |
| 271 // To avoid an unnecessary bounds changes (which may have side effects) | 292 // 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, | 293 // we set the restore bounds to the bounds we want, restore the window, |
| 273 // then reset the restore bounds. This way no unnecessary bounds | 294 // then reset the restore bounds. This way no unnecessary bounds |
| 274 // changes occurs and the original restore bounds is remembered. | 295 // changes occurs and the original restore bounds is remembered. |
| 275 gfx::Rect restore_bounds_in_screen = | 296 gfx::Rect restore_bounds_in_screen = |
| 276 GetRestoreBoundsInScreen(); | 297 GetRestoreBoundsInScreen(); |
| 277 SetRestoreBoundsInParent(bounds); | 298 SetRestoreBoundsInParent(bounds); |
| 278 Restore(); | 299 Restore(); |
| 279 SetRestoreBoundsInScreen(restore_bounds_in_screen); | 300 SetRestoreBoundsInScreen(restore_bounds_in_screen); |
| 280 } else { | 301 } else { |
| 281 window_->SetBounds(bounds); | 302 window_->SetBounds(bounds); |
| 282 } | 303 } |
| 283 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || | |
| 284 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); | |
| 285 window_show_type_ = left_or_right; | |
| 286 } | 304 } |
| 287 | 305 |
| 288 WindowState* GetActiveWindowState() { | 306 WindowState* GetActiveWindowState() { |
| 289 aura::Window* active = GetActiveWindow(); | 307 aura::Window* active = GetActiveWindow(); |
| 290 return active ? GetWindowState(active) : NULL; | 308 return active ? GetWindowState(active) : NULL; |
| 291 } | 309 } |
| 292 | 310 |
| 293 WindowState* GetWindowState(aura::Window* window) { | 311 WindowState* GetWindowState(aura::Window* window) { |
| 294 if (!window) | 312 if (!window) |
| 295 return NULL; | 313 return NULL; |
| 296 WindowState* settings = window->GetProperty(internal::kWindowStateKey); | 314 WindowState* settings = window->GetProperty(internal::kWindowStateKey); |
| 297 if(!settings) { | 315 if(!settings) { |
| 298 settings = new WindowState(window); | 316 settings = new WindowState(window); |
| 299 window->SetProperty(internal::kWindowStateKey, settings); | 317 window->SetProperty(internal::kWindowStateKey, settings); |
| 300 } | 318 } |
| 301 return settings; | 319 return settings; |
| 302 } | 320 } |
| 303 | 321 |
| 304 const WindowState* GetWindowState(const aura::Window* window) { | 322 const WindowState* GetWindowState(const aura::Window* window) { |
| 305 return GetWindowState(const_cast<aura::Window*>(window)); | 323 return GetWindowState(const_cast<aura::Window*>(window)); |
| 306 } | 324 } |
| 307 | 325 |
| 308 } // namespace wm | 326 } // namespace wm |
| 309 } // namespace ash | 327 } // namespace ash |
| OLD | NEW |