Commit c6e8c574 authored by sky@chromium.org's avatar sky@chromium.org

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
parent f250fd51
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/base/event.h" #include "ui/base/event.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/gfx/rect.h"
using aura::Window; using aura::Window;
...@@ -49,7 +48,9 @@ gfx::Rect BoundsWithScreenEdgeVisible( ...@@ -49,7 +48,9 @@ gfx::Rect BoundsWithScreenEdgeVisible(
WorkspaceLayoutManager2::WorkspaceLayoutManager2(Workspace2* workspace) WorkspaceLayoutManager2::WorkspaceLayoutManager2(Workspace2* workspace)
: root_window_(workspace->window()->GetRootWindow()), : root_window_(workspace->window()->GetRootWindow()),
workspace_(workspace) { workspace_(workspace),
work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
workspace->window()->parent())) {
Shell::GetInstance()->AddShellObserver(this); Shell::GetInstance()->AddShellObserver(this);
root_window_->AddRootWindowObserver(this); root_window_->AddRootWindowObserver(this);
root_window_->AddObserver(this); root_window_->AddObserver(this);
...@@ -115,8 +116,12 @@ void WorkspaceLayoutManager2::OnRootWindowResized(const aura::RootWindow* root, ...@@ -115,8 +116,12 @@ void WorkspaceLayoutManager2::OnRootWindowResized(const aura::RootWindow* root,
} }
void WorkspaceLayoutManager2::OnDisplayWorkAreaInsetsChanged() { void WorkspaceLayoutManager2::OnDisplayWorkAreaInsetsChanged() {
if (workspace_manager()->active_workspace_ == workspace_) if (workspace_manager()->active_workspace_ == workspace_) {
AdjustWindowSizesForScreenChange(); const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
workspace_->window()->parent()));
if (work_area != work_area_)
AdjustWindowSizesForScreenChange();
}
} }
void WorkspaceLayoutManager2::OnWindowPropertyChanged(Window* window, void WorkspaceLayoutManager2::OnWindowPropertyChanged(Window* window,
...@@ -198,6 +203,8 @@ void WorkspaceLayoutManager2::ShowStateChanged( ...@@ -198,6 +203,8 @@ void WorkspaceLayoutManager2::ShowStateChanged(
} }
void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() { void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() {
work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
workspace_->window()->parent());
// If a user plugs an external display into a laptop running Aura the // If a user plugs an external display into a laptop running Aura the
// display size will change. Maximized windows need to resize to match. // display size will change. Maximized windows need to resize to match.
// We also do this when developers running Aura on a desktop manually resize // We also do this when developers running Aura on a desktop manually resize
...@@ -212,11 +219,9 @@ void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() { ...@@ -212,11 +219,9 @@ void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() {
void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange(Window* window) { void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange(Window* window) {
if (!SetMaximizedOrFullscreenBounds(window)) { if (!SetMaximizedOrFullscreenBounds(window)) {
// The work area may be smaller than the full screen. // The work area may be smaller than the full screen. Put as much of the
gfx::Rect display_rect = // window as possible within the display area.
ScreenAsh::GetDisplayWorkAreaBoundsInParent(window->parent()->parent()); window->SetBounds(window->bounds().AdjustToFit(work_area_));
// Put as much of the window as possible within the display area.
window->SetBounds(window->bounds().AdjustToFit(display_rect));
} }
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/aura/root_window_observer.h" #include "ui/aura/root_window_observer.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/gfx/rect.h"
namespace aura { namespace aura {
class RootWindow; class RootWindow;
...@@ -101,6 +102,10 @@ class ASH_EXPORT WorkspaceLayoutManager2 ...@@ -101,6 +102,10 @@ class ASH_EXPORT WorkspaceLayoutManager2
// Set of windows we're listening to. // Set of windows we're listening to.
WindowSet windows_; WindowSet windows_;
// The work area. Cached to avoid unnecessarily moving windows during a
// workspace switch.
gfx::Rect work_area_;
DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager2); DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager2);
}; };
......
...@@ -853,5 +853,32 @@ TEST_F(WorkspaceManager2Test, VisibilityTests) { ...@@ -853,5 +853,32 @@ TEST_F(WorkspaceManager2Test, VisibilityTests) {
EXPECT_TRUE(w1->IsVisible()); 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 internal
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment