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_test_base.h" | 11 #include "ash/test/ash_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 = AshTestBase; | 24 using ScreenUtilTest = AshTestBase; |
24 | 25 |
25 TEST_F(ScreenUtilTest, Bounds) { | 26 TEST_F(ScreenUtilTest, Bounds) { |
26 UpdateDisplay("600x600,500x500"); | 27 UpdateDisplay("600x600,500x500"); |
27 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 28 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
28 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 29 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 TEST_F(ScreenUtilTest, ConvertRect) { | 80 TEST_F(ScreenUtilTest, ConvertRect) { |
80 UpdateDisplay("600x600,500x500"); | 81 UpdateDisplay("600x600,500x500"); |
81 | 82 |
82 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 83 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
83 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 84 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
84 primary->Show(); | 85 primary->Show(); |
85 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 86 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
86 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 87 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
87 secondary->Show(); | 88 secondary->Show(); |
88 | 89 |
89 EXPECT_EQ("0,0 100x100", | 90 gfx::Rect r1(10, 10, 100, 100); |
90 ScreenUtil::ConvertRectFromScreen(primary->GetNativeView(), | 91 ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1); |
91 gfx::Rect(10, 10, 100, 100)) | 92 EXPECT_EQ("0,0 100x100", r1.ToString()); |
92 .ToString()); | |
93 EXPECT_EQ("10,10 100x100", | |
94 ScreenUtil::ConvertRectFromScreen(secondary->GetNativeView(), | |
95 gfx::Rect(620, 20, 100, 100)) | |
96 .ToString()); | |
97 | 93 |
98 EXPECT_EQ("40,40 100x100", | 94 gfx::Rect r2(620, 20, 100, 100); |
99 ScreenUtil::ConvertRectToScreen(primary->GetNativeView(), | 95 ::wm::ConvertRectFromScreen(secondary->GetNativeView(), &r2); |
100 gfx::Rect(30, 30, 100, 100)) | 96 EXPECT_EQ("10,10 100x100", r2.ToString()); |
101 .ToString()); | 97 |
102 EXPECT_EQ("650,50 100x100", | 98 gfx::Rect r3(30, 30, 100, 100); |
103 ScreenUtil::ConvertRectToScreen(secondary->GetNativeView(), | 99 ::wm::ConvertRectToScreen(primary->GetNativeView(), &r3); |
104 gfx::Rect(40, 40, 100, 100)) | 100 EXPECT_EQ("40,40 100x100", r3.ToString()); |
105 .ToString()); | 101 |
| 102 gfx::Rect r4(40, 40, 100, 100); |
| 103 ::wm::ConvertRectToScreen(secondary->GetNativeView(), &r4); |
| 104 EXPECT_EQ("650,50 100x100", r4.ToString()); |
106 } | 105 } |
107 | 106 |
108 TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { | 107 TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { |
109 display_manager()->SetUnifiedDesktopEnabled(true); | 108 display_manager()->SetUnifiedDesktopEnabled(true); |
110 | 109 |
111 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 110 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
112 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 111 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
113 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 112 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
114 | 113 |
115 UpdateDisplay("500x400"); | 114 UpdateDisplay("500x400"); |
116 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 115 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
117 | 116 |
118 UpdateDisplay("500x400,600x400"); | 117 UpdateDisplay("500x400,600x400"); |
119 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 118 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
120 | 119 |
121 // Move to the 2nd physical display. Shelf's display still should be | 120 // Move to the 2nd physical display. Shelf's display still should be |
122 // the first. | 121 // the first. |
123 widget->SetBounds(gfx::Rect(800, 0, 100, 100)); | 122 widget->SetBounds(gfx::Rect(800, 0, 100, 100)); |
124 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); | 123 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); |
125 | 124 |
126 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 125 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
127 | 126 |
128 UpdateDisplay("600x500"); | 127 UpdateDisplay("600x500"); |
129 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); | 128 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); |
130 } | 129 } |
131 | 130 |
132 } // namespace test | 131 } // namespace test |
133 } // namespace ash | 132 } // namespace ash |
OLD | NEW |