Chromium Code Reviews| Index: ash/wm/window_state.cc |
| diff --git a/ash/wm/window_state.cc b/ash/wm/window_state.cc |
| index 1a06a58da1bb0a0b876bb2c64457d10d234feab1..6be72dd7a32932ece2aad480fcd58664cdd5a2e0 100644 |
| --- a/ash/wm/window_state.cc |
| +++ b/ash/wm/window_state.cc |
| @@ -88,6 +88,11 @@ bool WindowState::IsDocked() const { |
| window_->parent()->id() == internal::kShellWindowId_DockedContainer; |
| } |
| +bool WindowState::IsSnapped() const { |
| + return window_show_type_ == SHOW_TYPE_LEFT_SNAPPED || |
| + window_show_type_ == SHOW_TYPE_RIGHT_SNAPPED; |
| +} |
| + |
| bool WindowState::CanMaximize() const { |
| return window_->GetProperty(aura::client::kCanMaximizeKey); |
| } |
| @@ -136,7 +141,7 @@ void WindowState::SnapLeft(const gfx::Rect& bounds) { |
| } |
| void WindowState::SnapRight(const gfx::Rect& bounds) { |
| - SnapWindow(SHOW_TYPE_LEFT_SNAPPED, bounds); |
| + SnapWindow(SHOW_TYPE_RIGHT_SNAPPED, bounds); |
| } |
| void WindowState::Minimize() { |
| @@ -159,6 +164,11 @@ void WindowState::Deactivate() { |
| } |
| void WindowState::Restore() { |
| + // When a window |IsSnapped| it is auto-positioned by layout manager to stay |
| + // snapped at a screen edge. Stop this auto-positioning when Restore() is |
| + // called such as at the end of a drag or when centering a window. |
| + if (IsSnapped()) |
| + window_show_type_ = SHOW_TYPE_NORMAL; |
|
pkotwicz
2013/11/28 06:15:10
Nit: Let's set |window_show_type_| to SHOW_TYPE_NO
varkha
2013/11/28 15:39:40
Done.
|
| window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| } |
| @@ -265,24 +275,36 @@ void WindowState::OnWindowDestroying(aura::Window* window) { |
| void WindowState::SnapWindow(WindowShowType left_or_right, |
| const gfx::Rect& bounds) { |
| - if (IsMaximizedOrFullscreen()) { |
| - // Before we can set the bounds we need to restore the window. |
| - // Restoring the window will set the window to its restored bounds. |
| - // To avoid an unnecessary bounds changes (which may have side effects) |
| - // we set the restore bounds to the bounds we want, restore the window, |
| - // then reset the restore bounds. This way no unnecessary bounds |
| - // changes occurs and the original restore bounds is remembered. |
| - gfx::Rect restore_bounds_in_screen = |
| - GetRestoreBoundsInScreen(); |
| - SetRestoreBoundsInParent(bounds); |
| + // Original restore bounds (if they exist) or the current bounds are |
| + // preserved in order to allow restoring a window that has been snapped to its |
| + // original restored bounds regardless of the WindowShowType it had when it |
| + // got snapped. |
|
pkotwicz
2013/11/28 06:15:10
How about: "Compute the bounds that the window wil
varkha
2013/11/28 15:39:40
Done (slightly modified).
|
| + gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ? |
| + GetRestoreBoundsInScreen() : window_->GetBoundsInScreen()); |
| + SetRestoreBoundsInParent(bounds); |
|
pkotwicz
2013/11/28 06:15:10
How about: "Set the window's restore bounds so tha
varkha
2013/11/28 15:39:40
Done.
|
| + |
| + bool was_maximized = IsMaximizedOrFullscreen(); |
| + // Before we can set the bounds we need to restore the window. |
| + // Restoring the window will set the window to its restored bounds set above. |
| + // Restore will cause OnWindowPropertyChanged() so it needs to be done |
| + // before notifying that the WindowShowType has changed to |left_or_right|. |
| + if (was_maximized) |
| Restore(); |
| - SetRestoreBoundsInScreen(restore_bounds_in_screen); |
| - } else { |
| - window_->SetBounds(bounds); |
| - } |
| DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED || |
| left_or_right == SHOW_TYPE_RIGHT_SNAPPED); |
| + WindowShowType old_type = window_show_type_; |
| window_show_type_ = left_or_right; |
| + FOR_EACH_OBSERVER( |
| + WindowStateObserver, observer_list_, |
| + OnWindowShowTypeChanged(this, old_type)); |
| + // TODO(varkha): Ideally the bounds should be changed in a LayoutManager upon |
| + // observing the WindowShowType change. |
|
pkotwicz
2013/11/28 06:15:10
How about: "If the window is a child of kShellWind
varkha
2013/11/28 15:39:40
Done.
|
| + // When window is not docked such as when it is snapped using shortcuts |
| + // setting bounds here would have stopped slide animation that was started |
| + // in WorkspaceLayoutManager. |
| + if (IsDocked()) |
| + window_->SetBounds(bounds); |
| + SetRestoreBoundsInScreen(restore_bounds_in_screen); |
| } |
| WindowState* GetActiveWindowState() { |