Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Unified Diff: ash/wm/window_state.cc

Issue 68033003: Undocks window first before side-snapping bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undocks window first before side-snapping bounds (comments) Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/wm/window_state.h ('k') | ash/wm/workspace/workspace_layout_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/wm/window_state.cc
diff --git a/ash/wm/window_state.cc b/ash/wm/window_state.cc
index 1a06a58da1bb0a0b876bb2c64457d10d234feab1..1ea5ae2b461529f8919c4a8fdb497ed9dc5affde 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,7 @@ void WindowState::Deactivate() {
}
void WindowState::Restore() {
+ SetWindowShowTypeUnsnapped();
window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
}
@@ -244,6 +250,12 @@ void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) {
OnTrackedByWorkspaceChanged(this, old));
}
+void WindowState::SetBoundsChangedByUser(bool bounds_changed_by_user) {
+ bounds_changed_by_user_ = bounds_changed_by_user;
+ if (bounds_changed_by_user_)
+ SetWindowShowTypeUnsnapped();
+}
+
void WindowState::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
@@ -265,24 +277,38 @@ 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);
+ gfx::Rect restore_bounds_in_screen(HasRestoreBounds() ?
+ GetRestoreBoundsInScreen() : window_->GetBoundsInScreen());
+ // 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 recover the restore bounds. This way no unnecessary bounds
+ // changes occurs and the original restore bounds are remembered.
+ SetRestoreBoundsInParent(bounds);
+
+ bool was_maximized = IsMaximizedOrFullscreen();
+ // Restore will cause OnWindowPropertyChanged so it needs to be done
+ // before notifying about show type change to snapped.
+ 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.
+ if (!was_maximized)
+ window_->SetBounds(bounds);
+ SetRestoreBoundsInScreen(restore_bounds_in_screen);
+}
+
+void WindowState::SetWindowShowTypeUnsnapped() {
+ if (IsSnapped())
+ window_show_type_ = SHOW_TYPE_NORMAL;
}
WindowState* GetActiveWindowState() {
« no previous file with comments | « ash/wm/window_state.h ('k') | ash/wm/workspace/workspace_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698