OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/screen_util.h" | 5 #include "ash/screen_util.h" |
6 | 6 |
7 #include "ash/common/wm/wm_screen_util.h" | 7 #include "ash/common/wm/wm_screen_util.h" |
8 #include "ash/common/wm_lookup.h" | 8 #include "ash/common/wm_lookup.h" |
9 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/test/ash_md_test_base.h" | 11 #include "ash/test/ash_md_test_base.h" |
12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/display/manager/display_manager.h" | 16 #include "ui/display/manager/display_manager.h" |
17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
18 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
| 19 #include "ui/wm/core/coordinate_conversion.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 namespace test { | 22 namespace test { |
22 | 23 |
23 using ScreenUtilTest = AshMDTestBase; | 24 using ScreenUtilTest = AshMDTestBase; |
24 | 25 |
25 INSTANTIATE_TEST_CASE_P( | 26 INSTANTIATE_TEST_CASE_P( |
26 /* prefix intentionally left blank due to only one parameterization */, | 27 /* prefix intentionally left blank due to only one parameterization */, |
27 ScreenUtilTest, | 28 ScreenUtilTest, |
28 testing::Values(MaterialDesignController::NON_MATERIAL, | 29 testing::Values(MaterialDesignController::NON_MATERIAL, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 TEST_P(ScreenUtilTest, ConvertRect) { | 89 TEST_P(ScreenUtilTest, ConvertRect) { |
89 UpdateDisplay("600x600,500x500"); | 90 UpdateDisplay("600x600,500x500"); |
90 | 91 |
91 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 92 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
92 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 93 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
93 primary->Show(); | 94 primary->Show(); |
94 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 95 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
95 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 96 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
96 secondary->Show(); | 97 secondary->Show(); |
97 | 98 |
98 EXPECT_EQ("0,0 100x100", | 99 gfx::Rect r1(10, 10, 100, 100); |
99 ScreenUtil::ConvertRectFromScreen(primary->GetNativeView(), | 100 ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1); |
100 gfx::Rect(10, 10, 100, 100)) | 101 EXPECT_EQ("0,0 100x100", r1.ToString()); |
101 .ToString()); | |
102 EXPECT_EQ("10,10 100x100", | |
103 ScreenUtil::ConvertRectFromScreen(secondary->GetNativeView(), | |
104 gfx::Rect(620, 20, 100, 100)) | |
105 .ToString()); | |
106 | 102 |
107 EXPECT_EQ("40,40 100x100", | 103 gfx::Rect r2(620, 20, 100, 100); |
108 ScreenUtil::ConvertRectToScreen(primary->GetNativeView(), | 104 ::wm::ConvertRectFromScreen(secondary->GetNativeView(), &r2); |
109 gfx::Rect(30, 30, 100, 100)) | 105 EXPECT_EQ("10,10 100x100", r2.ToString()); |
110 .ToString()); | 106 |
111 EXPECT_EQ("650,50 100x100", | 107 gfx::Rect r3(30, 30, 100, 100); |
112 ScreenUtil::ConvertRectToScreen(secondary->GetNativeView(), | 108 ::wm::ConvertRectToScreen(primary->GetNativeView(), &r3); |
113 gfx::Rect(40, 40, 100, 100)) | 109 EXPECT_EQ("40,40 100x100", r3.ToString()); |
114 .ToString()); | 110 |
| 111 gfx::Rect r4(40, 40, 100, 100); |
| 112 ::wm::ConvertRectToScreen(secondary->GetNativeView(), &r4); |
| 113 EXPECT_EQ("650,50 100x100", r4.ToString()); |
115 } | 114 } |
116 | 115 |
117 TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { | 116 TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { |
118 display_manager()->SetUnifiedDesktopEnabled(true); | 117 display_manager()->SetUnifiedDesktopEnabled(true); |
119 | 118 |
120 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 119 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
121 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 120 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
122 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 121 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
123 | 122 |
124 UpdateDisplay("500x400"); | 123 UpdateDisplay("500x400"); |
125 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 124 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
126 | 125 |
127 UpdateDisplay("500x400,600x400"); | 126 UpdateDisplay("500x400,600x400"); |
128 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 127 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
129 | 128 |
130 // Move to the 2nd physical display. Shelf's display still should be | 129 // Move to the 2nd physical display. Shelf's display still should be |
131 // the first. | 130 // the first. |
132 widget->SetBounds(gfx::Rect(800, 0, 100, 100)); | 131 widget->SetBounds(gfx::Rect(800, 0, 100, 100)); |
133 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); | 132 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); |
134 | 133 |
135 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 134 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
136 | 135 |
137 UpdateDisplay("600x500"); | 136 UpdateDisplay("600x500"); |
138 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); | 137 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); |
139 } | 138 } |
140 | 139 |
141 } // namespace test | 140 } // namespace test |
142 } // namespace ash | 141 } // namespace ash |
OLD | NEW |