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/system/web_notification/ash_popup_alignment_delegate.h" | 5 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/display/window_tree_host_manager.h" | 11 #include "ash/display/window_tree_host_manager.h" |
12 #include "ash/screen_util.h" | 12 #include "ash/screen_util.h" |
13 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf.h" |
14 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
15 #include "ash/shelf/shelf_types.h" | 15 #include "ash/shelf/shelf_types.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/memory/ptr_util.h" |
20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
21 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
22 #include "ui/keyboard/keyboard_switches.h" | 23 #include "ui/keyboard/keyboard_switches.h" |
23 #include "ui/keyboard/keyboard_util.h" | 24 #include "ui/keyboard/keyboard_util.h" |
24 #include "ui/message_center/message_center_style.h" | 25 #include "ui/message_center/message_center_style.h" |
25 | 26 |
26 namespace ash { | 27 namespace ash { |
27 | 28 |
28 class AshPopupAlignmentDelegateTest : public test::AshTestBase { | 29 class AshPopupAlignmentDelegateTest : public test::AshTestBase { |
29 public: | 30 public: |
30 AshPopupAlignmentDelegateTest() {} | 31 AshPopupAlignmentDelegateTest() {} |
31 ~AshPopupAlignmentDelegateTest() override {} | 32 ~AshPopupAlignmentDelegateTest() override {} |
32 | 33 |
33 void SetUp() override { | 34 void SetUp() override { |
34 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 35 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
35 keyboard::switches::kEnableVirtualKeyboard); | 36 keyboard::switches::kEnableVirtualKeyboard); |
36 test::AshTestBase::SetUp(); | 37 test::AshTestBase::SetUp(); |
37 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( | 38 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( |
38 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 39 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
39 } | 40 } |
40 | 41 |
41 void TearDown() override { | 42 void TearDown() override { |
42 alignment_delegate_.reset(); | 43 alignment_delegate_.reset(); |
43 test::AshTestBase::TearDown(); | 44 test::AshTestBase::TearDown(); |
44 } | 45 } |
45 | 46 |
46 void SetKeyboardBounds(const gfx::Rect& new_bounds) { | 47 void SetKeyboardBounds(const gfx::Rect& new_bounds) { |
47 Shelf::ForPrimaryDisplay() | 48 Shelf::ForPrimaryDisplay() |
(...skipping 14 matching lines...) Expand all Loading... |
62 return alignment_delegate_.get(); | 63 return alignment_delegate_.get(); |
63 } | 64 } |
64 | 65 |
65 void UpdateWorkArea(AshPopupAlignmentDelegate* alignment_delegate, | 66 void UpdateWorkArea(AshPopupAlignmentDelegate* alignment_delegate, |
66 const gfx::Display& display) { | 67 const gfx::Display& display) { |
67 alignment_delegate->StartObserving(gfx::Screen::GetScreen(), display); | 68 alignment_delegate->StartObserving(gfx::Screen::GetScreen(), display); |
68 // Update the layout | 69 // Update the layout |
69 alignment_delegate->OnDisplayWorkAreaInsetsChanged(); | 70 alignment_delegate->OnDisplayWorkAreaInsetsChanged(); |
70 } | 71 } |
71 | 72 |
72 void SetAlignmentDelegate(scoped_ptr<AshPopupAlignmentDelegate> delegate) { | 73 void SetAlignmentDelegate( |
| 74 std::unique_ptr<AshPopupAlignmentDelegate> delegate) { |
73 if (!delegate.get()) { | 75 if (!delegate.get()) { |
74 alignment_delegate_.reset(); | 76 alignment_delegate_.reset(); |
75 return; | 77 return; |
76 } | 78 } |
77 alignment_delegate_ = std::move(delegate); | 79 alignment_delegate_ = std::move(delegate); |
78 UpdateWorkArea(alignment_delegate_.get(), | 80 UpdateWorkArea(alignment_delegate_.get(), |
79 gfx::Screen::GetScreen()->GetPrimaryDisplay()); | 81 gfx::Screen::GetScreen()->GetPrimaryDisplay()); |
80 } | 82 } |
81 | 83 |
82 Position GetPositionInDisplay(const gfx::Point& point) { | 84 Position GetPositionInDisplay(const gfx::Point& point) { |
83 const gfx::Rect& work_area = | 85 const gfx::Rect& work_area = |
84 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 86 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
85 const gfx::Point center_point = work_area.CenterPoint(); | 87 const gfx::Point center_point = work_area.CenterPoint(); |
86 if (work_area.x() > point.x() || work_area.y() > point.y() || | 88 if (work_area.x() > point.x() || work_area.y() > point.y() || |
87 work_area.right() < point.x() || work_area.bottom() < point.y()) { | 89 work_area.right() < point.x() || work_area.bottom() < point.y()) { |
88 return OUTSIDE; | 90 return OUTSIDE; |
89 } | 91 } |
90 | 92 |
91 if (center_point.x() < point.x()) | 93 if (center_point.x() < point.x()) |
92 return (center_point.y() < point.y()) ? BOTTOM_RIGHT : TOP_RIGHT; | 94 return (center_point.y() < point.y()) ? BOTTOM_RIGHT : TOP_RIGHT; |
93 else | 95 else |
94 return (center_point.y() < point.y()) ? BOTTOM_LEFT : TOP_LEFT; | 96 return (center_point.y() < point.y()) ? BOTTOM_LEFT : TOP_LEFT; |
95 } | 97 } |
96 | 98 |
97 gfx::Rect GetWorkArea() { | 99 gfx::Rect GetWorkArea() { |
98 return alignment_delegate_->work_area_; | 100 return alignment_delegate_->work_area_; |
99 } | 101 } |
100 | 102 |
101 private: | 103 private: |
102 scoped_ptr<AshPopupAlignmentDelegate> alignment_delegate_; | 104 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; |
103 }; | 105 }; |
104 | 106 |
105 #if defined(OS_WIN) && !defined(USE_ASH) | 107 #if defined(OS_WIN) && !defined(USE_ASH) |
106 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 108 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
107 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment | 109 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment |
108 #else | 110 #else |
109 #define MAYBE_ShelfAlignment ShelfAlignment | 111 #define MAYBE_ShelfAlignment ShelfAlignment |
110 #endif | 112 #endif |
111 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) { | 113 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) { |
112 const gfx::Rect toast_size(0, 0, 10, 10); | 114 const gfx::Rect toast_size(0, 0, 10, 10); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 163 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
162 } | 164 } |
163 | 165 |
164 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { | 166 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { |
165 const gfx::Rect toast_size(0, 0, 10, 10); | 167 const gfx::Rect toast_size(0, 0, 10, 10); |
166 UpdateDisplay("600x600"); | 168 UpdateDisplay("600x600"); |
167 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 169 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
168 int baseline = alignment_delegate()->GetBaseLine(); | 170 int baseline = alignment_delegate()->GetBaseLine(); |
169 | 171 |
170 // Create a window, otherwise autohide doesn't work. | 172 // Create a window, otherwise autohide doesn't work. |
171 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 173 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
172 Shell::GetInstance()->SetShelfAutoHideBehavior( | 174 Shell::GetInstance()->SetShelfAutoHideBehavior( |
173 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 175 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
174 Shell::GetPrimaryRootWindow()); | 176 Shell::GetPrimaryRootWindow()); |
175 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->UpdateAutoHideStateNow(); | 177 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->UpdateAutoHideStateNow(); |
176 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 178 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
177 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); | 179 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); |
178 } | 180 } |
179 | 181 |
180 // Verify that docked window doesn't affect the popup alignment. | 182 // Verify that docked window doesn't affect the popup alignment. |
181 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { | 183 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { |
182 const gfx::Rect toast_size(0, 0, 10, 10); | 184 const gfx::Rect toast_size(0, 0, 10, 10); |
183 UpdateDisplay("600x600"); | 185 UpdateDisplay("600x600"); |
184 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 186 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
185 int baseline = alignment_delegate()->GetBaseLine(); | 187 int baseline = alignment_delegate()->GetBaseLine(); |
186 | 188 |
187 scoped_ptr<aura::Window> window( | 189 std::unique_ptr<aura::Window> window( |
188 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 50, 50))); | 190 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 50, 50))); |
189 aura::Window* docked_container = Shell::GetContainer( | 191 aura::Window* docked_container = Shell::GetContainer( |
190 Shell::GetPrimaryRootWindow(), | 192 Shell::GetPrimaryRootWindow(), |
191 kShellWindowId_DockedContainer); | 193 kShellWindowId_DockedContainer); |
192 docked_container->AddChild(window.get()); | 194 docked_container->AddChild(window.get()); |
193 | 195 |
194 // Left-side dock should not affect popup alignment | 196 // Left-side dock should not affect popup alignment |
195 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 197 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
196 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 198 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
197 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 199 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 267 |
266 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 268 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
267 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, | 269 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, |
268 alignment_delegate()->GetBaseLine()); | 270 alignment_delegate()->GetBaseLine()); |
269 } | 271 } |
270 | 272 |
271 TEST_F(AshPopupAlignmentDelegateTest, Extended) { | 273 TEST_F(AshPopupAlignmentDelegateTest, Extended) { |
272 if (!SupportsMultipleDisplays()) | 274 if (!SupportsMultipleDisplays()) |
273 return; | 275 return; |
274 UpdateDisplay("600x600,800x800"); | 276 UpdateDisplay("600x600,800x800"); |
275 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( | 277 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( |
276 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 278 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
277 | 279 |
278 gfx::Display second_display = ScreenUtil::GetSecondaryDisplay(); | 280 gfx::Display second_display = ScreenUtil::GetSecondaryDisplay(); |
279 aura::Window* second_root = | 281 aura::Window* second_root = |
280 Shell::GetInstance() | 282 Shell::GetInstance() |
281 ->window_tree_host_manager() | 283 ->window_tree_host_manager() |
282 ->GetRootWindowForDisplayId(second_display.id()); | 284 ->GetRootWindowForDisplayId(second_display.id()); |
283 AshPopupAlignmentDelegate for_2nd_display( | 285 AshPopupAlignmentDelegate for_2nd_display( |
284 Shelf::ForWindow(second_root)->shelf_layout_manager()); | 286 Shelf::ForWindow(second_root)->shelf_layout_manager()); |
285 UpdateWorkArea(&for_2nd_display, second_display); | 287 UpdateWorkArea(&for_2nd_display, second_display); |
286 // Make sure that the toast position on the secondary display is | 288 // Make sure that the toast position on the secondary display is |
287 // positioned correctly. | 289 // positioned correctly. |
288 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 290 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
289 EXPECT_LT(700, for_2nd_display.GetBaseLine()); | 291 EXPECT_LT(700, for_2nd_display.GetBaseLine()); |
290 } | 292 } |
291 | 293 |
292 TEST_F(AshPopupAlignmentDelegateTest, Unified) { | 294 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
293 if (!SupportsMultipleDisplays()) | 295 if (!SupportsMultipleDisplays()) |
294 return; | 296 return; |
295 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 297 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
296 display_manager->SetUnifiedDesktopEnabled(true); | 298 display_manager->SetUnifiedDesktopEnabled(true); |
297 | 299 |
298 // Reset the delegate as the primary display's shelf will be destroyed during | 300 // Reset the delegate as the primary display's shelf will be destroyed during |
299 // transition. | 301 // transition. |
300 SetAlignmentDelegate(nullptr); | 302 SetAlignmentDelegate(nullptr); |
301 | 303 |
302 UpdateDisplay("600x600,800x800"); | 304 UpdateDisplay("600x600,800x800"); |
303 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( | 305 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( |
304 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 306 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
305 | 307 |
306 EXPECT_GT(600, | 308 EXPECT_GT(600, |
307 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 309 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
308 } | 310 } |
309 | 311 |
310 // Tests that when the keyboard is showing that notifications appear above it, | 312 // Tests that when the keyboard is showing that notifications appear above it, |
311 // and that they return to normal once the keyboard is gone. | 313 // and that they return to normal once the keyboard is gone. |
312 #if defined(OS_WIN) && !defined(USE_ASH) | 314 #if defined(OS_WIN) && !defined(USE_ASH) |
313 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 315 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
(...skipping 12 matching lines...) Expand all Loading... |
326 SetKeyboardBounds(keyboard_bounds); | 328 SetKeyboardBounds(keyboard_bounds); |
327 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 329 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
328 EXPECT_NE(baseline, keyboard_baseline); | 330 EXPECT_NE(baseline, keyboard_baseline); |
329 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 331 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
330 | 332 |
331 SetKeyboardBounds(gfx::Rect()); | 333 SetKeyboardBounds(gfx::Rect()); |
332 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 334 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
333 } | 335 } |
334 | 336 |
335 } // namespace ash | 337 } // namespace ash |
OLD | NEW |