Index: ash/wm/window_state.cc |
diff --git a/ash/wm/window_state.cc b/ash/wm/window_state.cc |
index 1a06a58da1bb0a0b876bb2c64457d10d234feab1..7e8d874e980a643b0ddeb2bbe90eff90eb413a25 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 |
pkotwicz
2013/11/27 20:24:43
You can actually kill the if statement completely.
varkha
2013/11/28 01:09:37
I don't think we can rely on WindowState::OnWindow
|
+ // 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; |
window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
} |
@@ -265,24 +275,35 @@ 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); |
+ // We set the restore bounds to the bounds we want, restore the window if |
+ // necessary or set the bounds explicitly, then recover the restore bounds. |
+ // This way no unnecessary bounds changes occurs and the original restore |
+ // bounds are remembered. |
+ gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ? |
+ GetRestoreBoundsInScreen() : window_->GetBoundsInScreen()); |
+ SetRestoreBoundsInParent(bounds); |
+ |
+ 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. |
+ // There is no need to SetBounds second time if a window used to be maximized. |
+ // In that case the bounds were already set when Restore() was called above. |
+ if (!was_maximized) |
+ window_->SetBounds(bounds); |
+ SetRestoreBoundsInScreen(restore_bounds_in_screen); |
} |
WindowState* GetActiveWindowState() { |