| 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/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/wm/wm_globals.h" |
| 12 #include "ash/common/wm/wm_root_window_controller.h" |
| 13 #include "ash/common/wm/wm_window.h" |
| 11 #include "ash/display/display_manager.h" | 14 #include "ash/display/display_manager.h" |
| 12 #include "ash/display/window_tree_host_manager.h" | |
| 13 #include "ash/screen_util.h" | 15 #include "ash/screen_util.h" |
| 14 #include "ash/shelf/shelf.h" | 16 #include "ash/shelf/shelf.h" |
| 15 #include "ash/shelf/shelf_layout_manager.h" | 17 #include "ash/shelf/shelf_layout_manager.h" |
| 16 #include "ash/shelf/shelf_types.h" | 18 #include "ash/shelf/shelf_types.h" |
| 17 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 18 #include "ash/test/ash_test_base.h" | 20 #include "ash/test/ash_test_base.h" |
| 19 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 20 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 21 #include "ui/display/screen.h" | 23 #include "ui/display/screen.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (center_point.x() < point.x()) | 95 if (center_point.x() < point.x()) |
| 94 return (center_point.y() < point.y()) ? BOTTOM_RIGHT : TOP_RIGHT; | 96 return (center_point.y() < point.y()) ? BOTTOM_RIGHT : TOP_RIGHT; |
| 95 else | 97 else |
| 96 return (center_point.y() < point.y()) ? BOTTOM_LEFT : TOP_LEFT; | 98 return (center_point.y() < point.y()) ? BOTTOM_LEFT : TOP_LEFT; |
| 97 } | 99 } |
| 98 | 100 |
| 99 gfx::Rect GetWorkArea() { | 101 gfx::Rect GetWorkArea() { |
| 100 return alignment_delegate_->work_area_; | 102 return alignment_delegate_->work_area_; |
| 101 } | 103 } |
| 102 | 104 |
| 105 std::unique_ptr<views::Widget> CreateTestWidget(int container_id) { |
| 106 std::unique_ptr<views::Widget> widget(new views::Widget); |
| 107 views::Widget::InitParams params; |
| 108 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 109 params.bounds = gfx::Rect(0, 0, 50, 50); |
| 110 wm::WmGlobals::Get() |
| 111 ->GetPrimaryRootWindow() |
| 112 ->GetRootWindowController() |
| 113 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id, |
| 114 ¶ms); |
| 115 widget->Init(params); |
| 116 widget->Show(); |
| 117 return widget; |
| 118 } |
| 119 |
| 103 private: | 120 private: |
| 104 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; | 121 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; |
| 105 }; | 122 }; |
| 106 | 123 |
| 107 #if defined(OS_WIN) && !defined(USE_ASH) | 124 #if defined(OS_WIN) && !defined(USE_ASH) |
| 108 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 125 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
| 109 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment | 126 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment |
| 110 #else | 127 #else |
| 111 #define MAYBE_ShelfAlignment ShelfAlignment | 128 #define MAYBE_ShelfAlignment ShelfAlignment |
| 112 #endif | 129 #endif |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 174 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
| 158 } | 175 } |
| 159 | 176 |
| 160 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { | 177 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { |
| 161 const gfx::Rect toast_size(0, 0, 10, 10); | 178 const gfx::Rect toast_size(0, 0, 10, 10); |
| 162 UpdateDisplay("600x600"); | 179 UpdateDisplay("600x600"); |
| 163 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 180 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
| 164 int baseline = alignment_delegate()->GetBaseLine(); | 181 int baseline = alignment_delegate()->GetBaseLine(); |
| 165 | 182 |
| 166 // Create a window, otherwise autohide doesn't work. | 183 // Create a window, otherwise autohide doesn't work. |
| 167 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 184 std::unique_ptr<views::Widget> widget = |
| 185 CreateTestWidget(kShellWindowId_DefaultContainer); |
| 168 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 186 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 169 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 187 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 170 shelf->shelf_layout_manager()->UpdateAutoHideStateNow(); | 188 shelf->shelf_layout_manager()->UpdateAutoHideStateNow(); |
| 171 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 189 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
| 172 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); | 190 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); |
| 173 } | 191 } |
| 174 | 192 |
| 175 // Verify that docked window doesn't affect the popup alignment. | 193 // Verify that docked window doesn't affect the popup alignment. |
| 176 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { | 194 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { |
| 177 const gfx::Rect toast_size(0, 0, 10, 10); | 195 const gfx::Rect toast_size(0, 0, 10, 10); |
| 178 UpdateDisplay("600x600"); | 196 UpdateDisplay("600x600"); |
| 179 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 197 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
| 180 int baseline = alignment_delegate()->GetBaseLine(); | 198 int baseline = alignment_delegate()->GetBaseLine(); |
| 181 | 199 |
| 182 std::unique_ptr<aura::Window> window( | 200 std::unique_ptr<views::Widget> widget = |
| 183 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 50, 50))); | 201 CreateTestWidget(kShellWindowId_DockedContainer); |
| 184 aura::Window* docked_container = Shell::GetContainer( | |
| 185 Shell::GetPrimaryRootWindow(), | |
| 186 kShellWindowId_DockedContainer); | |
| 187 docked_container->AddChild(window.get()); | |
| 188 | 202 |
| 189 // Left-side dock should not affect popup alignment | 203 // Left-side dock should not affect popup alignment |
| 190 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 204 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
| 191 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 205 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
| 192 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 206 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
| 193 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 207 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
| 194 | 208 |
| 195 // Force dock to right-side | 209 // Force dock to right-side |
| 196 Shelf::ForPrimaryDisplay()->SetAlignment(wm::SHELF_ALIGNMENT_LEFT); | 210 Shelf::ForPrimaryDisplay()->SetAlignment(wm::SHELF_ALIGNMENT_LEFT); |
| 197 Shelf::ForPrimaryDisplay()->SetAlignment(wm::SHELF_ALIGNMENT_BOTTOM); | 211 Shelf::ForPrimaryDisplay()->SetAlignment(wm::SHELF_ALIGNMENT_BOTTOM); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 276 } |
| 263 | 277 |
| 264 TEST_F(AshPopupAlignmentDelegateTest, Extended) { | 278 TEST_F(AshPopupAlignmentDelegateTest, Extended) { |
| 265 if (!SupportsMultipleDisplays()) | 279 if (!SupportsMultipleDisplays()) |
| 266 return; | 280 return; |
| 267 UpdateDisplay("600x600,800x800"); | 281 UpdateDisplay("600x600,800x800"); |
| 268 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( | 282 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( |
| 269 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 283 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
| 270 | 284 |
| 271 display::Display second_display = ScreenUtil::GetSecondaryDisplay(); | 285 display::Display second_display = ScreenUtil::GetSecondaryDisplay(); |
| 272 aura::Window* second_root = | |
| 273 Shell::GetInstance() | |
| 274 ->window_tree_host_manager() | |
| 275 ->GetRootWindowForDisplayId(second_display.id()); | |
| 276 AshPopupAlignmentDelegate for_2nd_display( | 286 AshPopupAlignmentDelegate for_2nd_display( |
| 277 Shelf::ForWindow(second_root)->shelf_layout_manager()); | 287 Shelf::ForDisplayId(second_display.id())->shelf_layout_manager()); |
| 278 UpdateWorkArea(&for_2nd_display, second_display); | 288 UpdateWorkArea(&for_2nd_display, second_display); |
| 279 // Make sure that the toast position on the secondary display is | 289 // Make sure that the toast position on the secondary display is |
| 280 // positioned correctly. | 290 // positioned correctly. |
| 281 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 291 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
| 282 EXPECT_LT(700, for_2nd_display.GetBaseLine()); | 292 EXPECT_LT(700, for_2nd_display.GetBaseLine()); |
| 283 } | 293 } |
| 284 | 294 |
| 285 TEST_F(AshPopupAlignmentDelegateTest, Unified) { | 295 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
| 286 if (!SupportsMultipleDisplays()) | 296 if (!SupportsMultipleDisplays()) |
| 287 return; | 297 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 SetKeyboardBounds(keyboard_bounds); | 329 SetKeyboardBounds(keyboard_bounds); |
| 320 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 330 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
| 321 EXPECT_NE(baseline, keyboard_baseline); | 331 EXPECT_NE(baseline, keyboard_baseline); |
| 322 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 332 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
| 323 | 333 |
| 324 SetKeyboardBounds(gfx::Rect()); | 334 SetKeyboardBounds(gfx::Rect()); |
| 325 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 335 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
| 326 } | 336 } |
| 327 | 337 |
| 328 } // namespace ash | 338 } // namespace ash |
| OLD | NEW |