diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 21:53:49 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 21:53:49 +0000 |
commit | 633ac083847e489751ddbd9a4fb4e7ba1abaab0f (patch) | |
tree | e4559f02bbcc3633e0aaf85689d6409ee9336335 /ash | |
parent | 546161f3e901724a01cbb90c8fb58706649d97f4 (diff) | |
download | chromium_src-633ac083847e489751ddbd9a4fb4e7ba1abaab0f.zip chromium_src-633ac083847e489751ddbd9a4fb4e7ba1abaab0f.tar.gz chromium_src-633ac083847e489751ddbd9a4fb4e7ba1abaab0f.tar.bz2 |
Fix fit to height/width to use screen coordinates
BUG=245510
TEST=covered by test
Review URL: https://chromiumcodereview.appspot.com/16518002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/wm/workspace/workspace_event_handler.cc | 18 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_event_handler_unittest.cc | 84 |
2 files changed, 88 insertions, 14 deletions
diff --git a/ash/wm/workspace/workspace_event_handler.cc b/ash/wm/workspace/workspace_event_handler.cc index 16d86ca..828f024 100644 --- a/ash/wm/workspace/workspace_event_handler.cc +++ b/ash/wm/workspace/workspace_event_handler.cc @@ -7,6 +7,7 @@ #include "ash/screen_ash.h" #include "ash/shell.h" #include "ash/shell_delegate.h" +#include "ash/wm/coordinate_conversion.h" #include "ash/wm/property_util.h" #include "ash/wm/window_util.h" #include "ash/wm/workspace/workspace_window_resizer.h" @@ -22,12 +23,15 @@ namespace ash { namespace { -void SingleAxisMaximize(aura::Window* window, const gfx::Rect& maximize_rect) { +void SingleAxisMaximize(aura::Window* window, + const gfx::Rect& maximize_rect_in_screen) { gfx::Rect bounds_in_screen = ScreenAsh::ConvertRectToScreen(window->parent(), window->bounds()); - SetRestoreBoundsInScreen(window, bounds_in_screen); - window->SetBounds(maximize_rect); + gfx::Rect bounds_in_parent = + ScreenAsh::ConvertRectFromScreen(window->parent(), + maximize_rect_in_screen); + window->SetBounds(bounds_in_parent); } void SingleAxisUnmaximize(aura::Window* window, @@ -148,8 +152,10 @@ void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( target->bounds().y() == work_area.y())) { SingleAxisUnmaximize(target, *restore_bounds); } else { + gfx::Point origin = target->bounds().origin(); + wm::ConvertPointToScreen(target->parent(), &origin); SingleAxisMaximize(target, - gfx::Rect(target->bounds().x(), + gfx::Rect(origin.x(), work_area.y(), target->bounds().width(), work_area.height())); @@ -163,9 +169,11 @@ void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( target->bounds().x() == work_area.x())) { SingleAxisUnmaximize(target, *restore_bounds); } else { + gfx::Point origin = target->bounds().origin(); + wm::ConvertPointToScreen(target->parent(), &origin); SingleAxisMaximize(target, gfx::Rect(work_area.x(), - target->bounds().y(), + origin.y(), work_area.width(), target->bounds().height())); } diff --git a/ash/wm/workspace/workspace_event_handler_unittest.cc b/ash/wm/workspace/workspace_event_handler_unittest.cc index 91a6557..e72f1ee 100644 --- a/ash/wm/workspace/workspace_event_handler_unittest.cc +++ b/ash/wm/workspace/workspace_event_handler_unittest.cc @@ -4,6 +4,7 @@ #include "ash/wm/workspace/workspace_event_handler.h" +#include "ash/screen_ash.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "ash/wm/property_util.h" @@ -17,6 +18,10 @@ #include "ui/base/hit_test.h" #include "ui/gfx/screen.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + namespace ash { namespace internal { @@ -67,15 +72,18 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) { generator.PressLeftButton(); generator.MoveMouseTo(generator.current_location(), 1); generator.ReleaseLeftButton(); - EXPECT_EQ(work_area.y(), window->bounds().y()); - EXPECT_EQ(work_area.height(), window->bounds().height()); + gfx::Rect bounds_in_screen = window->GetBoundsInScreen(); + EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); + EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); + EXPECT_EQ(work_area.y(), bounds_in_screen.y()); + EXPECT_EQ(work_area.height(), bounds_in_screen.height()); // Single-axis maximization is not considered real maximization. EXPECT_FALSE(wm::IsWindowMaximized(window.get())); // Restore. generator.DoubleClickLeftButton(); - EXPECT_EQ(restored_bounds.y(), window->bounds().y()); - EXPECT_EQ(restored_bounds.height(), window->bounds().height()); + bounds_in_screen = window->GetBoundsInScreen(); + EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); // Note that it should not even be restored at this point, it should have // also cleared the restore rectangle. EXPECT_EQ(NULL, GetRestoreBoundsInScreen(window.get())); @@ -86,17 +94,75 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) { wd.set_window_component(HTCAPTION); generator.DoubleClickLeftButton(); EXPECT_FALSE(wm::IsWindowMaximized(window.get())); - - EXPECT_EQ(restored_bounds.y(), window->bounds().y()); - EXPECT_EQ(restored_bounds.height(), window->bounds().height()); + bounds_in_screen = window->GetBoundsInScreen(); + EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); // Double clicking the left resize edge should maximize horizontally. wd.set_window_component(HTLEFT); generator.DoubleClickLeftButton(); - EXPECT_EQ(work_area.x(), window->bounds().x()); - EXPECT_EQ(work_area.width(), window->bounds().width()); + bounds_in_screen = window->GetBoundsInScreen(); + EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); + EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); + EXPECT_EQ(work_area.x(), bounds_in_screen.x()); + EXPECT_EQ(work_area.width(), bounds_in_screen.width()); // Single-axis maximization is not considered real maximization. EXPECT_FALSE(wm::IsWindowMaximized(window.get())); + + // Restore. + wd.set_window_component(HTCAPTION); + generator.DoubleClickLeftButton(); + EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); + +#if defined(OS_WIN) + // Multi display test does not run on Win8 bot. crbug.com/247427. + if (base::win::GetVersion() >= base::win::VERSION_WIN8) + return; +#endif + + // Verify the double clicking the resize edge works on 2nd display too. + UpdateDisplay("200x200,400x300"); + gfx::Rect work_area2 = ScreenAsh::GetSecondaryDisplay().work_area(); + restored_bounds.SetRect(220,20, 50, 50); + window->SetBoundsInScreen(restored_bounds, ScreenAsh::GetSecondaryDisplay()); + aura::RootWindow* second_root = Shell::GetAllRootWindows()[1]; + EXPECT_EQ(second_root, window->GetRootWindow()); + aura::test::EventGenerator generator2(second_root, window.get()); + + // Y-axis maximization. + wd.set_window_component(HTTOP); + generator2.PressLeftButton(); + generator2.ReleaseLeftButton(); + generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); + generator2.PressLeftButton(); + generator2.MoveMouseTo(generator.current_location(), 1); + generator2.ReleaseLeftButton(); + generator.DoubleClickLeftButton(); + bounds_in_screen = window->GetBoundsInScreen(); + EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); + EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); + EXPECT_EQ(work_area2.y(), bounds_in_screen.y()); + EXPECT_EQ(work_area2.height(), bounds_in_screen.height()); + EXPECT_FALSE(wm::IsWindowMaximized(window.get())); + + // Restore. + wd.set_window_component(HTCAPTION); + generator2.DoubleClickLeftButton(); + EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); + + // X-axis maximization. + wd.set_window_component(HTLEFT); + generator2.DoubleClickLeftButton(); + bounds_in_screen = window->GetBoundsInScreen(); + EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); + EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); + EXPECT_EQ(work_area2.x(), bounds_in_screen.x()); + EXPECT_EQ(work_area2.width(), bounds_in_screen.width()); + EXPECT_FALSE(wm::IsWindowMaximized(window.get())); + + // Restore. + wd.set_window_component(HTCAPTION); + generator2.DoubleClickLeftButton(); + EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); } TEST_F(WorkspaceEventHandlerTest, |