| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 bool WindowState::IsActive() const { | 82 bool WindowState::IsActive() const { |
| 83 return IsActiveWindow(window_); | 83 return IsActiveWindow(window_); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool WindowState::IsDocked() const { | 86 bool WindowState::IsDocked() const { |
| 87 return window_->parent() && | 87 return window_->parent() && |
| 88 window_->parent()->id() == internal::kShellWindowId_DockedContainer; | 88 window_->parent()->id() == internal::kShellWindowId_DockedContainer; |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool WindowState::IsSnapped() const { |
| 92 return window_show_type_ == SHOW_TYPE_LEFT_SNAPPED || |
| 93 window_show_type_ == SHOW_TYPE_RIGHT_SNAPPED; |
| 94 } |
| 95 |
| 91 bool WindowState::CanMaximize() const { | 96 bool WindowState::CanMaximize() const { |
| 92 return window_->GetProperty(aura::client::kCanMaximizeKey); | 97 return window_->GetProperty(aura::client::kCanMaximizeKey); |
| 93 } | 98 } |
| 94 | 99 |
| 95 bool WindowState::CanMinimize() const { | 100 bool WindowState::CanMinimize() const { |
| 96 internal::RootWindowController* controller = | 101 internal::RootWindowController* controller = |
| 97 internal::RootWindowController::ForWindow(window_); | 102 internal::RootWindowController::ForWindow(window_); |
| 98 if (!controller) | 103 if (!controller) |
| 99 return false; | 104 return false; |
| 100 aura::Window* lockscreen = controller->GetContainer( | 105 aura::Window* lockscreen = controller->GetContainer( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 | 134 |
| 130 void WindowState::Maximize() { | 135 void WindowState::Maximize() { |
| 131 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 136 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 132 } | 137 } |
| 133 | 138 |
| 134 void WindowState::SnapLeft(const gfx::Rect& bounds) { | 139 void WindowState::SnapLeft(const gfx::Rect& bounds) { |
| 135 SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); | 140 SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); |
| 136 } | 141 } |
| 137 | 142 |
| 138 void WindowState::SnapRight(const gfx::Rect& bounds) { | 143 void WindowState::SnapRight(const gfx::Rect& bounds) { |
| 139 SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); | 144 SnapWindow(SHOW_TYPE_RIGHT_SNAPPED, bounds); |
| 140 } | 145 } |
| 141 | 146 |
| 142 void WindowState::Minimize() { | 147 void WindowState::Minimize() { |
| 143 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 148 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 144 } | 149 } |
| 145 | 150 |
| 146 void WindowState::Unminimize() { | 151 void WindowState::Unminimize() { |
| 147 window_->SetProperty( | 152 window_->SetProperty( |
| 148 aura::client::kShowStateKey, | 153 aura::client::kShowStateKey, |
| 149 window_->GetProperty(aura::client::kRestoreShowStateKey)); | 154 window_->GetProperty(aura::client::kRestoreShowStateKey)); |
| 150 window_->ClearProperty(aura::client::kRestoreShowStateKey); | 155 window_->ClearProperty(aura::client::kRestoreShowStateKey); |
| 151 } | 156 } |
| 152 | 157 |
| 153 void WindowState::Activate() { | 158 void WindowState::Activate() { |
| 154 ActivateWindow(window_); | 159 ActivateWindow(window_); |
| 155 } | 160 } |
| 156 | 161 |
| 157 void WindowState::Deactivate() { | 162 void WindowState::Deactivate() { |
| 158 DeactivateWindow(window_); | 163 DeactivateWindow(window_); |
| 159 } | 164 } |
| 160 | 165 |
| 161 void WindowState::Restore() { | 166 void WindowState::Restore() { |
| 167 SetWindowShowTypeUnsnapped(); |
| 162 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 168 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void WindowState::ToggleMaximized() { | 171 void WindowState::ToggleMaximized() { |
| 166 if (IsMaximized()) | 172 if (IsMaximized()) |
| 167 Restore(); | 173 Restore(); |
| 168 else if (CanMaximize()) | 174 else if (CanMaximize()) |
| 169 Maximize(); | 175 Maximize(); |
| 170 } | 176 } |
| 171 | 177 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 243 |
| 238 void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) { | 244 void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) { |
| 239 if (tracked_by_workspace_ == tracked_by_workspace) | 245 if (tracked_by_workspace_ == tracked_by_workspace) |
| 240 return; | 246 return; |
| 241 bool old = tracked_by_workspace_; | 247 bool old = tracked_by_workspace_; |
| 242 tracked_by_workspace_ = tracked_by_workspace; | 248 tracked_by_workspace_ = tracked_by_workspace; |
| 243 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, | 249 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, |
| 244 OnTrackedByWorkspaceChanged(this, old)); | 250 OnTrackedByWorkspaceChanged(this, old)); |
| 245 } | 251 } |
| 246 | 252 |
| 253 void WindowState::SetBoundsChangedByUser(bool bounds_changed_by_user) { |
| 254 bounds_changed_by_user_ = bounds_changed_by_user; |
| 255 if (bounds_changed_by_user_) |
| 256 SetWindowShowTypeUnsnapped(); |
| 257 } |
| 258 |
| 247 void WindowState::OnWindowPropertyChanged(aura::Window* window, | 259 void WindowState::OnWindowPropertyChanged(aura::Window* window, |
| 248 const void* key, | 260 const void* key, |
| 249 intptr_t old) { | 261 intptr_t old) { |
| 250 DCHECK_EQ(window, window_); | 262 DCHECK_EQ(window, window_); |
| 251 if (key == aura::client::kShowStateKey) { | 263 if (key == aura::client::kShowStateKey) { |
| 252 window_show_type_ = ToWindowShowType(GetShowState()); | 264 window_show_type_ = ToWindowShowType(GetShowState()); |
| 253 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | 265 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); |
| 254 // TODO(oshima): Notify only when the state has changed. | 266 // TODO(oshima): Notify only when the state has changed. |
| 255 // Doing so break a few tests now. | 267 // Doing so break a few tests now. |
| 256 FOR_EACH_OBSERVER( | 268 FOR_EACH_OBSERVER( |
| 257 WindowStateObserver, observer_list_, | 269 WindowStateObserver, observer_list_, |
| 258 OnWindowShowTypeChanged(this, ToWindowShowType(old_state))); | 270 OnWindowShowTypeChanged(this, ToWindowShowType(old_state))); |
| 259 } | 271 } |
| 260 } | 272 } |
| 261 | 273 |
| 262 void WindowState::OnWindowDestroying(aura::Window* window) { | 274 void WindowState::OnWindowDestroying(aura::Window* window) { |
| 263 window_->RemoveObserver(this); | 275 window_->RemoveObserver(this); |
| 264 } | 276 } |
| 265 | 277 |
| 266 void WindowState::SnapWindow(WindowShowType left_or_right, | 278 void WindowState::SnapWindow(WindowShowType left_or_right, |
| 267 const gfx::Rect& bounds) { | 279 const gfx::Rect& bounds) { |
| 268 if (IsMaximizedOrFullscreen()) { | 280 gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ? |
| 269 // Before we can set the bounds we need to restore the window. | 281 GetRestoreBoundsInScreen() : window_->GetBoundsInScreen()); |
| 270 // Restoring the window will set the window to its restored bounds. | 282 // Before we can set the bounds we need to restore the window. |
| 271 // To avoid an unnecessary bounds changes (which may have side effects) | 283 // Restoring the window will set the window to its restored bounds. |
| 272 // we set the restore bounds to the bounds we want, restore the window, | 284 // To avoid an unnecessary bounds changes (which may have side effects) |
| 273 // then reset the restore bounds. This way no unnecessary bounds | 285 // we set the restore bounds to the bounds we want, restore the window, |
| 274 // changes occurs and the original restore bounds is remembered. | 286 // then recover the restore bounds. This way no unnecessary bounds |
| 275 gfx::Rect restore_bounds_in_screen = | 287 // changes occurs and the original restore bounds are remembered. |
| 276 GetRestoreBoundsInScreen(); | 288 SetRestoreBoundsInParent(bounds); |
| 277 SetRestoreBoundsInParent(bounds); | 289 |
| 290 bool was_maximized = IsMaximizedOrFullscreen(); |
| 291 // Restore will cause OnWindowPropertyChanged so it needs to be done |
| 292 // before notifying about show type change to snapped. |
| 293 if (was_maximized) |
| 278 Restore(); | 294 Restore(); |
| 279 SetRestoreBoundsInScreen(restore_bounds_in_screen); | |
| 280 } else { | |
| 281 window_->SetBounds(bounds); | |
| 282 } | |
| 283 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || | 295 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || |
| 284 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); | 296 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); |
| 297 WindowShowType old_type = window_show_type_; |
| 285 window_show_type_ = left_or_right; | 298 window_show_type_ = left_or_right; |
| 299 FOR_EACH_OBSERVER( |
| 300 WindowStateObserver, observer_list_, |
| 301 OnWindowShowTypeChanged(this, old_type)); |
| 302 // TODO(varkha): Ideally the bounds should be changed in a LayoutManager upon |
| 303 // observing the WindowShowType change. |
| 304 if (!was_maximized) |
| 305 window_->SetBounds(bounds); |
| 306 SetRestoreBoundsInScreen(restore_bounds_in_screen); |
| 307 } |
| 308 |
| 309 void WindowState::SetWindowShowTypeUnsnapped() { |
| 310 if (IsSnapped()) |
| 311 window_show_type_ = SHOW_TYPE_NORMAL; |
| 286 } | 312 } |
| 287 | 313 |
| 288 WindowState* GetActiveWindowState() { | 314 WindowState* GetActiveWindowState() { |
| 289 aura::Window* active = GetActiveWindow(); | 315 aura::Window* active = GetActiveWindow(); |
| 290 return active ? GetWindowState(active) : NULL; | 316 return active ? GetWindowState(active) : NULL; |
| 291 } | 317 } |
| 292 | 318 |
| 293 WindowState* GetWindowState(aura::Window* window) { | 319 WindowState* GetWindowState(aura::Window* window) { |
| 294 if (!window) | 320 if (!window) |
| 295 return NULL; | 321 return NULL; |
| 296 WindowState* settings = window->GetProperty(internal::kWindowStateKey); | 322 WindowState* settings = window->GetProperty(internal::kWindowStateKey); |
| 297 if(!settings) { | 323 if(!settings) { |
| 298 settings = new WindowState(window); | 324 settings = new WindowState(window); |
| 299 window->SetProperty(internal::kWindowStateKey, settings); | 325 window->SetProperty(internal::kWindowStateKey, settings); |
| 300 } | 326 } |
| 301 return settings; | 327 return settings; |
| 302 } | 328 } |
| 303 | 329 |
| 304 const WindowState* GetWindowState(const aura::Window* window) { | 330 const WindowState* GetWindowState(const aura::Window* window) { |
| 305 return GetWindowState(const_cast<aura::Window*>(window)); | 331 return GetWindowState(const_cast<aura::Window*>(window)); |
| 306 } | 332 } |
| 307 | 333 |
| 308 } // namespace wm | 334 } // namespace wm |
| 309 } // namespace ash | 335 } // namespace ash |
| OLD | NEW |