diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-13 22:00:02 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-13 22:00:02 +0000 |
commit | 5fcf3279b4e112924cfce72732108c2047a1107d (patch) | |
tree | cdbe6be18b91500ea174891853d301f2bcf04584 /ash | |
parent | 761cc4739ca2ba8b0d64c4829ce0bfcd4899b732 (diff) | |
download | chromium_src-5fcf3279b4e112924cfce72732108c2047a1107d.zip chromium_src-5fcf3279b4e112924cfce72732108c2047a1107d.tar.gz chromium_src-5fcf3279b4e112924cfce72732108c2047a1107d.tar.bz2 |
Makes sure that after we maximize a window all descendants that had
bounds still have bounds. Some windows (in this case constrained
windows) don't reset their children when the parent changes.
BUG=147373
TEST=see bug, covered by tests now too
R=jamescook@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10905273
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156648 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager2.cc | 37 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager2_unittest.cc | 27 |
2 files changed, 51 insertions, 13 deletions
diff --git a/ash/wm/workspace/workspace_layout_manager2.cc b/ash/wm/workspace/workspace_layout_manager2.cc index 3ce869e..6ffb7015 100644 --- a/ash/wm/workspace/workspace_layout_manager2.cc +++ b/ash/wm/workspace/workspace_layout_manager2.cc @@ -29,6 +29,32 @@ using aura::Window; namespace ash { namespace internal { +namespace { + +typedef std::map<const aura::Window*, gfx::Rect> BoundsMap; + +// Adds an entry from |window| to its bounds and recursively invokes this for +// all children. +void BuildWindowBoundsMap(const aura::Window* window, BoundsMap* bounds_map) { + (*bounds_map)[window] = window->bounds(); + for (size_t i = 0; i < window->children().size(); ++i) + BuildWindowBoundsMap(window->children()[i], bounds_map); +} + +// Resets |window|s bounds from |bounds_map| if currently empty. Recusively +// invokes this for all children. +void ResetBoundsIfNecessary(const BoundsMap& bounds_map, aura::Window* window) { + if (window->bounds().IsEmpty() && window->GetTargetBounds().IsEmpty()) { + BoundsMap::const_iterator i = bounds_map.find(window); + if (i != bounds_map.end()) + window->SetBounds(i->second); + } + for (size_t i = 0; i < window->children().size(); ++i) + ResetBoundsIfNecessary(bounds_map, window->children()[i]); +} + +} // namespace + WorkspaceLayoutManager2::WorkspaceLayoutManager2(Workspace2* workspace) : root_window_(workspace->window()->GetRootWindow()), workspace_(workspace), @@ -138,15 +164,26 @@ void WorkspaceLayoutManager2::OnWindowPropertyChanged(Window* window, // BaseLayoutManager, but that proves problematic. In particular when // restoring we need to animate on top of the workspace animating in. ui::Layer* cloned_layer = NULL; + BoundsMap bounds_map; if (wm::IsActiveWindow(window) && ((WorkspaceManager2::IsMaximizedState(new_state) && wm::IsWindowStateNormal(old_state)) || (!WorkspaceManager2::IsMaximizedState(new_state) && WorkspaceManager2::IsMaximizedState(old_state) && new_state != ui::SHOW_STATE_MINIMIZED))) { + BuildWindowBoundsMap(window, &bounds_map); cloned_layer = wm::RecreateWindowLayers(window, false); } UpdateBoundsFromShowState(window); + + if (cloned_layer) { + // Even though we just set the bounds not all descendants may have valid + // bounds. For example, constrained windows don't resize with the parent. + // Ensure that all windows that had a bounds before we cloned the layer + // have a bounds now. + ResetBoundsIfNecessary(bounds_map, window); + } + ShowStateChanged(window, old_state, cloned_layer); // Set the restore rectangle to the previously set restore rectangle. diff --git a/ash/wm/workspace/workspace_layout_manager2_unittest.cc b/ash/wm/workspace/workspace_layout_manager2_unittest.cc index 0701f57..9bb237a 100644 --- a/ash/wm/workspace/workspace_layout_manager2_unittest.cc +++ b/ash/wm/workspace/workspace_layout_manager2_unittest.cc @@ -23,19 +23,6 @@ class WorkspaceLayoutManager2Test : public test::AshTestBase { WorkspaceLayoutManager2Test() {} virtual ~WorkspaceLayoutManager2Test() {} - virtual void SetUp() OVERRIDE { - test::AshTestBase::SetUp(); - Shell::GetInstance()->SetDisplayWorkAreaInsets( - Shell::GetPrimaryRootWindow(), - gfx::Insets(1, 2, 3, 4)); - Shell::GetPrimaryRootWindow()->SetHostSize(gfx::Size(800, 600)); - aura::Window* default_container = Shell::GetContainer( - Shell::GetPrimaryRootWindow(), - internal::kShellWindowId_DefaultContainer); - default_container->SetLayoutManager(new internal::BaseLayoutManager( - Shell::GetPrimaryRootWindow())); - } - aura::Window* CreateTestWindow(const gfx::Rect& bounds) { return aura::test::CreateTestWindowWithBounds(bounds, NULL); } @@ -58,6 +45,20 @@ TEST_F(WorkspaceLayoutManager2Test, RestoreFromMinimizeKeepsRestore) { EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString()); } +// Verifies when a window is maximized all descendant windows have a size. +TEST_F(WorkspaceLayoutManager2Test, ChildBoundsResetOnMaximize) { + scoped_ptr<aura::Window> window( + CreateTestWindow(gfx::Rect(10, 20, 30, 40))); + window->Show(); + ash::wm::ActivateWindow(window.get()); + scoped_ptr<aura::Window> child_window( + aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), + window.get())); + child_window->Show(); + ash::wm::MaximizeWindow(window.get()); + EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); +} + } // namespace } // namespace ash |