summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-27 20:17:37 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-27 20:17:37 +0000
commitc6e8c5742418db363bf29a362a1113983f16f723 (patch)
treead424447ba606c4dd47dc9d0a12a71af9f811aab
parentf250fd5114bc8d9391915a2a0207cae526eaf70d (diff)
downloadchromium_src-c6e8c5742418db363bf29a362a1113983f16f723.zip
chromium_src-c6e8c5742418db363bf29a362a1113983f16f723.tar.gz
chromium_src-c6e8c5742418db363bf29a362a1113983f16f723.tar.bz2
Changes workspace code to only move windows when the work area changes
and the workspace is active. Without this a workspace switch (such as going from normal to maximized) causes windows to move back onscreen as the work area changes as a result of shelf visibility changing. BUG=137342 TEST=none R=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/10878079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153528 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/wm/workspace/workspace_layout_manager2.cc23
-rw-r--r--ash/wm/workspace/workspace_layout_manager2.h5
-rw-r--r--ash/wm/workspace/workspace_manager2_unittest.cc27
3 files changed, 46 insertions, 9 deletions
diff --git a/ash/wm/workspace/workspace_layout_manager2.cc b/ash/wm/workspace/workspace_layout_manager2.cc
index 763759e..3352e30 100644
--- a/ash/wm/workspace/workspace_layout_manager2.cc
+++ b/ash/wm/workspace/workspace_layout_manager2.cc
@@ -21,7 +21,6 @@
#include "ui/aura/window_observer.h"
#include "ui/base/event.h"
#include "ui/base/ui_base_types.h"
-#include "ui/gfx/rect.h"
using aura::Window;
@@ -49,7 +48,9 @@ gfx::Rect BoundsWithScreenEdgeVisible(
WorkspaceLayoutManager2::WorkspaceLayoutManager2(Workspace2* workspace)
: root_window_(workspace->window()->GetRootWindow()),
- workspace_(workspace) {
+ workspace_(workspace),
+ work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ workspace->window()->parent())) {
Shell::GetInstance()->AddShellObserver(this);
root_window_->AddRootWindowObserver(this);
root_window_->AddObserver(this);
@@ -115,8 +116,12 @@ void WorkspaceLayoutManager2::OnRootWindowResized(const aura::RootWindow* root,
}
void WorkspaceLayoutManager2::OnDisplayWorkAreaInsetsChanged() {
- if (workspace_manager()->active_workspace_ == workspace_)
- AdjustWindowSizesForScreenChange();
+ if (workspace_manager()->active_workspace_ == workspace_) {
+ const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ workspace_->window()->parent()));
+ if (work_area != work_area_)
+ AdjustWindowSizesForScreenChange();
+ }
}
void WorkspaceLayoutManager2::OnWindowPropertyChanged(Window* window,
@@ -198,6 +203,8 @@ void WorkspaceLayoutManager2::ShowStateChanged(
}
void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() {
+ work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ workspace_->window()->parent());
// If a user plugs an external display into a laptop running Aura the
// display size will change. Maximized windows need to resize to match.
// We also do this when developers running Aura on a desktop manually resize
@@ -212,11 +219,9 @@ void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() {
void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange(Window* window) {
if (!SetMaximizedOrFullscreenBounds(window)) {
- // The work area may be smaller than the full screen.
- gfx::Rect display_rect =
- ScreenAsh::GetDisplayWorkAreaBoundsInParent(window->parent()->parent());
- // Put as much of the window as possible within the display area.
- window->SetBounds(window->bounds().AdjustToFit(display_rect));
+ // The work area may be smaller than the full screen. Put as much of the
+ // window as possible within the display area.
+ window->SetBounds(window->bounds().AdjustToFit(work_area_));
}
}
diff --git a/ash/wm/workspace/workspace_layout_manager2.h b/ash/wm/workspace/workspace_layout_manager2.h
index 3c0e6ab..1f35e04 100644
--- a/ash/wm/workspace/workspace_layout_manager2.h
+++ b/ash/wm/workspace/workspace_layout_manager2.h
@@ -15,6 +15,7 @@
#include "ui/aura/root_window_observer.h"
#include "ui/base/ui_base_types.h"
#include "ui/aura/window_observer.h"
+#include "ui/gfx/rect.h"
namespace aura {
class RootWindow;
@@ -101,6 +102,10 @@ class ASH_EXPORT WorkspaceLayoutManager2
// Set of windows we're listening to.
WindowSet windows_;
+ // The work area. Cached to avoid unnecessarily moving windows during a
+ // workspace switch.
+ gfx::Rect work_area_;
+
DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager2);
};
diff --git a/ash/wm/workspace/workspace_manager2_unittest.cc b/ash/wm/workspace/workspace_manager2_unittest.cc
index 47f51b2..1676b00 100644
--- a/ash/wm/workspace/workspace_manager2_unittest.cc
+++ b/ash/wm/workspace/workspace_manager2_unittest.cc
@@ -853,5 +853,32 @@ TEST_F(WorkspaceManager2Test, VisibilityTests) {
EXPECT_TRUE(w1->IsVisible());
}
+// Verifies windows that are offscreen don't move when switching workspaces.
+TEST_F(WorkspaceManager2Test, DontMoveOnSwitch) {
+ aura::test::EventGenerator generator(
+ Shell::GetPrimaryRootWindow(), gfx::Point());
+ generator.MoveMouseTo(0, 0);
+
+ scoped_ptr<Window> w1(CreateTestWindow());
+ const gfx::Rect w1_bounds(0, 1, 101, 102);
+ ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
+ const gfx::Rect touches_shelf_bounds(
+ 0, shelf->GetIdealBounds().y() - 10, 101, 102);
+ // Move |w1| to overlap the shelf.
+ w1->SetBounds(touches_shelf_bounds);
+ w1->Show();
+ wm::ActivateWindow(w1.get());
+
+ // Create another window and maximize it.
+ scoped_ptr<Window> w2(CreateTestWindow());
+ w2->SetBounds(gfx::Rect(10, 11, 250, 251));
+ w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
+ w2->Show();
+ wm::ActivateWindow(w2.get());
+
+ // Switch to w1.
+ wm::ActivateWindow(w1.get());
+ EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString());
+}
} // namespace internal
} // namespace ash