| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/display/display_manager.h" | 5 #include "ash/display/display_manager.h" |
| 6 #include "ash/root_window_controller.h" | 6 #include "ash/root_window_controller.h" |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/wm/coordinate_conversion.h" | 12 #include "ash/wm/coordinate_conversion.h" |
| 13 #include "ash/wm/window_properties.h" | 13 #include "ash/wm/window_properties.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "ui/aura/client/capture_client.h" | 17 #include "ui/aura/client/capture_client.h" |
| 18 #include "ui/aura/client/focus_client.h" | 18 #include "ui/aura/client/focus_client.h" |
| 19 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
| 20 #include "ui/aura/test/window_test_api.h" | 20 #include "ui/aura/test/window_test_api.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 23 #include "ui/base/cursor/cursor.h" | 23 #include "ui/base/cursor/cursor.h" |
| 24 #include "ui/display/manager/display_layout.h" |
| 24 #include "ui/events/event_handler.h" | 25 #include "ui/events/event_handler.h" |
| 25 #include "ui/events/test/event_generator.h" | 26 #include "ui/events/test/event_generator.h" |
| 26 #include "ui/gfx/display.h" | 27 #include "ui/gfx/display.h" |
| 27 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 28 #include "ui/views/controls/textfield/textfield.h" | 29 #include "ui/views/controls/textfield/textfield.h" |
| 29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 30 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
| 31 #include "ui/wm/public/activation_client.h" | 32 #include "ui/wm/public/activation_client.h" |
| 32 | 33 |
| 33 namespace ash { | 34 namespace ash { |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 void SetSecondaryDisplayLayout(DisplayPlacement::Position position) { | 37 void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) { |
| 37 scoped_ptr<DisplayLayout> layout = | 38 scoped_ptr<display::DisplayLayout> layout = |
| 38 Shell::GetInstance()->display_manager()->GetCurrentDisplayLayout().Copy(); | 39 Shell::GetInstance()->display_manager()->GetCurrentDisplayLayout().Copy(); |
| 39 layout->placement_list[0].position = position; | 40 layout->placement_list[0].position = position; |
| 40 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( | 41 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( |
| 41 std::move(layout)); | 42 std::move(layout)); |
| 42 } | 43 } |
| 43 | 44 |
| 44 class ModalWidgetDelegate : public views::WidgetDelegateView { | 45 class ModalWidgetDelegate : public views::WidgetDelegateView { |
| 45 public: | 46 public: |
| 46 ModalWidgetDelegate() {} | 47 ModalWidgetDelegate() {} |
| 47 ~ModalWidgetDelegate() override {} | 48 ~ModalWidgetDelegate() override {} |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 304 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 304 EXPECT_TRUE(root_window0_test_api.ContainsMouse()); | 305 EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 305 EXPECT_FALSE(root_window1_test_api.ContainsMouse()); | 306 EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 306 } | 307 } |
| 307 | 308 |
| 308 TEST_F(ExtendedDesktopTest, GetRootWindowAt) { | 309 TEST_F(ExtendedDesktopTest, GetRootWindowAt) { |
| 309 if (!SupportsMultipleDisplays()) | 310 if (!SupportsMultipleDisplays()) |
| 310 return; | 311 return; |
| 311 | 312 |
| 312 UpdateDisplay("700x500,500x500"); | 313 UpdateDisplay("700x500,500x500"); |
| 313 SetSecondaryDisplayLayout(DisplayPlacement::LEFT); | 314 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT); |
| 314 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 315 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 315 | 316 |
| 316 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); | 317 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); |
| 317 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); | 318 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); |
| 318 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); | 319 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); |
| 319 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300))); | 320 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300))); |
| 320 | 321 |
| 321 // Zero origin. | 322 // Zero origin. |
| 322 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); | 323 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); |
| 323 | 324 |
| 324 // Out of range point should return the nearest root window | 325 // Out of range point should return the nearest root window |
| 325 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0))); | 326 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0))); |
| 326 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); | 327 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); |
| 327 } | 328 } |
| 328 | 329 |
| 329 TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { | 330 TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { |
| 330 if (!SupportsMultipleDisplays()) | 331 if (!SupportsMultipleDisplays()) |
| 331 return; | 332 return; |
| 332 | 333 |
| 333 UpdateDisplay("700x500,500x500"); | 334 UpdateDisplay("700x500,500x500"); |
| 334 SetSecondaryDisplayLayout(DisplayPlacement::LEFT); | 335 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT); |
| 335 | 336 |
| 336 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 337 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 337 | 338 |
| 338 // Containing rect. | 339 // Containing rect. |
| 339 EXPECT_EQ(root_windows[1], | 340 EXPECT_EQ(root_windows[1], |
| 340 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); | 341 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); |
| 341 EXPECT_EQ(root_windows[0], | 342 EXPECT_EQ(root_windows[0], |
| 342 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); | 343 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); |
| 343 | 344 |
| 344 // Intersecting rect. | 345 // Intersecting rect. |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 | 726 |
| 726 // Convert point in the Root1's window to the Root2's window Coord. | 727 // Convert point in the Root1's window to the Root2's window Coord. |
| 727 p.SetPoint(0, 0); | 728 p.SetPoint(0, 0); |
| 728 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); | 729 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
| 729 EXPECT_EQ("-1000,0", p.ToString()); | 730 EXPECT_EQ("-1000,0", p.ToString()); |
| 730 p.SetPoint(0, 0); | 731 p.SetPoint(0, 0); |
| 731 aura::Window::ConvertPointToTarget(d1, d2, &p); | 732 aura::Window::ConvertPointToTarget(d1, d2, &p); |
| 732 EXPECT_EQ("-1010,-10", p.ToString()); | 733 EXPECT_EQ("-1010,-10", p.ToString()); |
| 733 | 734 |
| 734 // Move the 2nd display to the bottom and test again. | 735 // Move the 2nd display to the bottom and test again. |
| 735 SetSecondaryDisplayLayout(DisplayPlacement::BOTTOM); | 736 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); |
| 736 | 737 |
| 737 display_2 = screen->GetDisplayNearestWindow(root_windows[1]); | 738 display_2 = screen->GetDisplayNearestWindow(root_windows[1]); |
| 738 EXPECT_EQ("0,600", display_2.bounds().origin().ToString()); | 739 EXPECT_EQ("0,600", display_2.bounds().origin().ToString()); |
| 739 | 740 |
| 740 // Convert point in Root2's window to Root1's window Coord. | 741 // Convert point in Root2's window to Root1's window Coord. |
| 741 p.SetPoint(0, 0); | 742 p.SetPoint(0, 0); |
| 742 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); | 743 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
| 743 EXPECT_EQ("0,600", p.ToString()); | 744 EXPECT_EQ("0,600", p.ToString()); |
| 744 p.SetPoint(0, 0); | 745 p.SetPoint(0, 0); |
| 745 aura::Window::ConvertPointToTarget(d2, d1, &p); | 746 aura::Window::ConvertPointToTarget(d2, d1, &p); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 generator.ReleaseLeftButton(); | 929 generator.ReleaseLeftButton(); |
| 929 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); | 930 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); |
| 930 | 931 |
| 931 generator.MoveMouseTo(400, 150); | 932 generator.MoveMouseTo(400, 150); |
| 932 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); | 933 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); |
| 933 | 934 |
| 934 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 935 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 935 } | 936 } |
| 936 | 937 |
| 937 } // namespace ash | 938 } // namespace ash |
| OLD | NEW |