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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/window_properties.h" | 11 #include "ash/wm/window_properties.h" |
| 12 #include "ash/wm/window_state_delegate.h" | 12 #include "ash/wm/window_state_delegate.h" |
| 13 #include "ash/wm/window_state_observer.h" | 13 #include "ash/wm/window_state_observer.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/wm_types.h" | 15 #include "ash/wm/wm_types.h" |
| 16 #include "base/auto_reset.h" | |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 17 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/gfx/display.h" | 21 #include "ui/gfx/display.h" |
| 21 #include "ui/views/corewm/window_util.h" | 22 #include "ui/views/corewm/window_util.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 namespace wm { | 25 namespace wm { |
| 25 | 26 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 36 panel_attached_(true), | 37 panel_attached_(true), |
| 37 continue_drag_after_reparent_(false), | 38 continue_drag_after_reparent_(false), |
| 38 ignored_by_shelf_(false), | 39 ignored_by_shelf_(false), |
| 39 can_consume_system_keys_(false), | 40 can_consume_system_keys_(false), |
| 40 top_row_keys_are_function_keys_(false), | 41 top_row_keys_are_function_keys_(false), |
| 41 window_resizer_(NULL), | 42 window_resizer_(NULL), |
| 42 always_restores_to_restore_bounds_(false), | 43 always_restores_to_restore_bounds_(false), |
| 43 hide_shelf_when_fullscreen_(true), | 44 hide_shelf_when_fullscreen_(true), |
| 44 animate_to_fullscreen_(true), | 45 animate_to_fullscreen_(true), |
| 45 minimum_visibility_(false), | 46 minimum_visibility_(false), |
| 47 in_set_window_show_type_(false), | |
| 46 window_show_type_(ToWindowShowType(GetShowState())) { | 48 window_show_type_(ToWindowShowType(GetShowState())) { |
| 47 window_->AddObserver(this); | 49 window_->AddObserver(this); |
| 48 | 50 |
| 49 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 50 // NOTE(pkotwicz): Animating to immersive fullscreen does not look good. When | 52 // NOTE(pkotwicz): Animating to immersive fullscreen does not look good. When |
| 51 // the kAshEnableImmersiveFullscreenForAllWindows flag is set most windows | 53 // the kAshEnableImmersiveFullscreenForAllWindows flag is set most windows |
| 52 // can be put into immersive fullscreen. It is not worth the added complexity | 54 // can be put into immersive fullscreen. It is not worth the added complexity |
| 53 // to only animate to fullscreen if the window is put into immersive | 55 // to only animate to fullscreen if the window is put into immersive |
| 54 // fullscreen. | 56 // fullscreen. |
| 55 animate_to_fullscreen_ = !CommandLine::ForCurrentProcess()->HasSwitch( | 57 animate_to_fullscreen_ = !CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 } | 173 } |
| 172 | 174 |
| 173 void WindowState::Activate() { | 175 void WindowState::Activate() { |
| 174 ActivateWindow(window_); | 176 ActivateWindow(window_); |
| 175 } | 177 } |
| 176 | 178 |
| 177 void WindowState::Deactivate() { | 179 void WindowState::Deactivate() { |
| 178 DeactivateWindow(window_); | 180 DeactivateWindow(window_); |
| 179 } | 181 } |
| 180 | 182 |
| 181 void WindowState::Restore() { | 183 void WindowState::Restore() { |
|
pkotwicz
2013/12/09 22:29:03
I removed this code because it is not helpful. In
| |
| 182 // Set |window_show_type_| to SHOW_TYPE_NORMAL now so that an observer | |
| 183 // observing kShowStateKey gets the correct value when querying IsSnapped(). | |
| 184 window_show_type_ = SHOW_TYPE_NORMAL; | |
| 185 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 184 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 186 } | 185 } |
| 187 | 186 |
| 188 void WindowState::ToggleMaximized() { | 187 void WindowState::ToggleMaximized() { |
| 189 if (IsMaximized()) | 188 if (IsMaximized()) |
| 190 Restore(); | 189 Restore(); |
| 191 else if (CanMaximize()) | 190 else if (CanMaximize()) |
| 192 Maximize(); | 191 Maximize(); |
| 193 } | 192 } |
| 194 | 193 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 } | 254 } |
| 256 | 255 |
| 257 void WindowState::RemoveObserver(WindowStateObserver* observer) { | 256 void WindowState::RemoveObserver(WindowStateObserver* observer) { |
| 258 observer_list_.RemoveObserver(observer); | 257 observer_list_.RemoveObserver(observer); |
| 259 } | 258 } |
| 260 | 259 |
| 261 void WindowState::OnWindowPropertyChanged(aura::Window* window, | 260 void WindowState::OnWindowPropertyChanged(aura::Window* window, |
| 262 const void* key, | 261 const void* key, |
| 263 intptr_t old) { | 262 intptr_t old) { |
| 264 DCHECK_EQ(window, window_); | 263 DCHECK_EQ(window, window_); |
| 265 if (key == aura::client::kShowStateKey) { | 264 if (key == aura::client::kShowStateKey) |
| 266 window_show_type_ = ToWindowShowType(GetShowState()); | 265 SetWindowShowType(ToWindowShowType(GetShowState())); |
| 267 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | |
| 268 // TODO(oshima): Notify only when the state has changed. | |
|
pkotwicz
2013/12/09 22:29:03
I actually did not find any tests which are broken
| |
| 269 // Doing so break a few tests now. | |
| 270 FOR_EACH_OBSERVER( | |
| 271 WindowStateObserver, observer_list_, | |
| 272 OnWindowShowTypeChanged(this, ToWindowShowType(old_state))); | |
| 273 } | |
| 274 } | 266 } |
| 275 | 267 |
| 276 void WindowState::SnapWindow(WindowShowType left_or_right, | 268 void WindowState::SnapWindow(WindowShowType left_or_right, |
| 277 const gfx::Rect& bounds) { | 269 const gfx::Rect& bounds) { |
| 270 if (window_show_type_ == left_or_right) { | |
| 271 window_->SetBounds(bounds); | |
| 272 return; | |
| 273 } | |
| 274 | |
| 278 // Compute the bounds that the window will restore to. If the window does not | 275 // Compute the bounds that the window will restore to. If the window does not |
| 279 // already have restore bounds, it will be restored (when un-snapped) to the | 276 // already have restore bounds, it will be restored (when un-snapped) to the |
| 280 // last bounds that it had before getting snapped. | 277 // last bounds that it had before getting snapped. |
| 281 gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ? | 278 gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ? |
| 282 GetRestoreBoundsInScreen() : window_->GetBoundsInScreen()); | 279 GetRestoreBoundsInScreen() : window_->GetBoundsInScreen()); |
| 283 // Set the window's restore bounds so that WorkspaceLayoutManager knows | 280 // Set the window's restore bounds so that WorkspaceLayoutManager knows |
| 284 // which width to use when the snapped window is moved to the edge. | 281 // which width to use when the snapped window is moved to the edge. |
| 285 SetRestoreBoundsInParent(bounds); | 282 SetRestoreBoundsInParent(bounds); |
| 286 | 283 |
| 287 bool was_maximized = IsMaximizedOrFullscreen(); | |
| 288 // Before we can set the bounds we need to restore the window. | |
| 289 // Restoring the window will set the window to its restored bounds set above. | |
| 290 // Restore will cause OnWindowPropertyChanged() so it needs to be done | |
| 291 // before notifying that the WindowShowType has changed to |left_or_right|. | |
| 292 if (was_maximized) | |
| 293 Restore(); | |
| 294 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || | 284 DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || |
| 295 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); | 285 left_or_right == SHOW_TYPE_RIGHT_SNAPPED); |
| 296 WindowShowType old_type = window_show_type_; | 286 SetWindowShowType(left_or_right); |
| 297 window_show_type_ = left_or_right; | |
| 298 FOR_EACH_OBSERVER( | |
| 299 WindowStateObserver, observer_list_, | |
| 300 OnWindowShowTypeChanged(this, old_type)); | |
| 301 // TODO(varkha): Ideally the bounds should be changed in a LayoutManager upon | 287 // TODO(varkha): Ideally the bounds should be changed in a LayoutManager upon |
| 302 // observing the WindowShowType change. | 288 // observing the WindowShowType change. |
| 303 // If the window is a child of kShellWindowId_DockedContainer such as during | 289 // If the window is a child of kShellWindowId_DockedContainer such as during |
| 304 // a drag, the window's bounds are not set in | 290 // a drag, the window's bounds are not set in |
| 305 // WorkspaceLayoutManager::OnWindowShowTypeChanged(). Set them here. Skip | 291 // WorkspaceLayoutManager::OnWindowShowTypeChanged(). Set them here. Skip |
| 306 // setting the bounds otherwise to avoid stopping the slide animation which | 292 // setting the bounds otherwise to avoid stopping the slide animation which |
| 307 // was started as a result of OnWindowShowTypeChanged(). | 293 // was started as a result of OnWindowShowTypeChanged(). |
| 308 if (IsDocked()) | 294 if (IsDocked()) |
| 309 window_->SetBounds(bounds); | 295 window_->SetBounds(bounds); |
| 310 SetRestoreBoundsInScreen(restore_bounds_in_screen); | 296 SetRestoreBoundsInScreen(restore_bounds_in_screen); |
| 311 } | 297 } |
| 312 | 298 |
| 299 void WindowState::SetWindowShowType(WindowShowType new_window_show_type) { | |
| 300 if (in_set_window_show_type_) | |
| 301 return; | |
| 302 base::AutoReset<bool>(&in_set_window_show_type_, true); | |
| 303 | |
| 304 ui::WindowShowState new_window_state = | |
| 305 ToWindowShowState(new_window_show_type); | |
| 306 if (new_window_state != GetShowState()) | |
| 307 window_->SetProperty(aura::client::kShowStateKey, new_window_state); | |
| 308 WindowShowType old_window_show_type = window_show_type_; | |
| 309 window_show_type_ = new_window_show_type; | |
| 310 if (old_window_show_type != window_show_type_) { | |
| 311 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, | |
| 312 OnWindowShowTypeChanged(this, old_window_show_type)); | |
| 313 } | |
| 314 } | |
| 315 | |
| 313 WindowState* GetActiveWindowState() { | 316 WindowState* GetActiveWindowState() { |
| 314 aura::Window* active = GetActiveWindow(); | 317 aura::Window* active = GetActiveWindow(); |
| 315 return active ? GetWindowState(active) : NULL; | 318 return active ? GetWindowState(active) : NULL; |
| 316 } | 319 } |
| 317 | 320 |
| 318 WindowState* GetWindowState(aura::Window* window) { | 321 WindowState* GetWindowState(aura::Window* window) { |
| 319 if (!window) | 322 if (!window) |
| 320 return NULL; | 323 return NULL; |
| 321 WindowState* settings = window->GetProperty(internal::kWindowStateKey); | 324 WindowState* settings = window->GetProperty(internal::kWindowStateKey); |
| 322 if(!settings) { | 325 if(!settings) { |
| 323 settings = new WindowState(window); | 326 settings = new WindowState(window); |
| 324 window->SetProperty(internal::kWindowStateKey, settings); | 327 window->SetProperty(internal::kWindowStateKey, settings); |
| 325 } | 328 } |
| 326 return settings; | 329 return settings; |
| 327 } | 330 } |
| 328 | 331 |
| 329 const WindowState* GetWindowState(const aura::Window* window) { | 332 const WindowState* GetWindowState(const aura::Window* window) { |
| 330 return GetWindowState(const_cast<aura::Window*>(window)); | 333 return GetWindowState(const_cast<aura::Window*>(window)); |
| 331 } | 334 } |
| 332 | 335 |
| 333 } // namespace wm | 336 } // namespace wm |
| 334 } // namespace ash | 337 } // namespace ash |
| OLD | NEW |