| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/accessibility_types.h" | 9 #include "ash/accessibility_types.h" |
| 10 #include "ash/drag_drop/drag_drop_controller.h" | 10 #include "ash/drag_drop/drag_drop_controller.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 WindowSelector* window_selector() { | 167 WindowSelector* window_selector() { |
| 168 return window_selector_controller()->window_selector_.get(); | 168 return window_selector_controller()->window_selector_.get(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } | 171 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } |
| 172 | 172 |
| 173 aura::Window* GetOverviewWindowForMinimizedState(int index, | 173 aura::Window* GetOverviewWindowForMinimizedState(int index, |
| 174 aura::Window* window) { | 174 aura::Window* window) { |
| 175 WindowSelectorItem* selector = GetWindowItemForWindow(index, window); | 175 WindowSelectorItem* selector = GetWindowItemForWindow(index, window); |
| 176 return WmWindow::GetAuraWindow( | 176 return selector->GetOverviewWindowForMinimizedStateForTest(); |
| 177 selector->GetOverviewWindowForMinimizedStateForTest()); | |
| 178 } | 177 } |
| 179 | 178 |
| 180 gfx::Rect GetTransformedBounds(aura::Window* window) { | 179 gfx::Rect GetTransformedBounds(aura::Window* window) { |
| 181 gfx::Rect bounds_in_screen = window->layer()->bounds(); | 180 gfx::Rect bounds_in_screen = window->layer()->bounds(); |
| 182 ::wm::ConvertRectToScreen(window->parent(), &bounds_in_screen); | 181 ::wm::ConvertRectToScreen(window->parent(), &bounds_in_screen); |
| 183 gfx::RectF bounds(bounds_in_screen); | 182 gfx::RectF bounds(bounds_in_screen); |
| 184 gfx::Transform transform(gfx::TransformAboutPivot( | 183 gfx::Transform transform(gfx::TransformAboutPivot( |
| 185 gfx::ToFlooredPoint(bounds.origin()), window->layer()->transform())); | 184 gfx::ToFlooredPoint(bounds.origin()), window->layer()->transform())); |
| 186 transform.TransformRect(&bounds); | 185 transform.TransformRect(&bounds); |
| 187 return gfx::ToEnclosingRect(bounds); | 186 return gfx::ToEnclosingRect(bounds); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return window_selector()->grid_list_[index]->window_list(); | 237 return window_selector()->grid_list_[index]->window_list(); |
| 239 } | 238 } |
| 240 | 239 |
| 241 WindowSelectorItem* GetWindowItemForWindow(int grid_index, | 240 WindowSelectorItem* GetWindowItemForWindow(int grid_index, |
| 242 aura::Window* window) { | 241 aura::Window* window) { |
| 243 const std::vector<std::unique_ptr<WindowSelectorItem>>& windows = | 242 const std::vector<std::unique_ptr<WindowSelectorItem>>& windows = |
| 244 GetWindowItemsForRoot(grid_index); | 243 GetWindowItemsForRoot(grid_index); |
| 245 auto iter = | 244 auto iter = |
| 246 std::find_if(windows.cbegin(), windows.cend(), | 245 std::find_if(windows.cbegin(), windows.cend(), |
| 247 [window](const std::unique_ptr<WindowSelectorItem>& item) { | 246 [window](const std::unique_ptr<WindowSelectorItem>& item) { |
| 248 return item->Contains(WmWindow::Get(window)); | 247 return item->Contains(window); |
| 249 }); | 248 }); |
| 250 if (iter == windows.end()) | 249 if (iter == windows.end()) |
| 251 return nullptr; | 250 return nullptr; |
| 252 return iter->get(); | 251 return iter->get(); |
| 253 } | 252 } |
| 254 | 253 |
| 255 gfx::SlideAnimation* GetBackgroundViewAnimationForWindow( | 254 gfx::SlideAnimation* GetBackgroundViewAnimationForWindow( |
| 256 int grid_index, | 255 int grid_index, |
| 257 aura::Window* window) { | 256 aura::Window* window) { |
| 258 return GetWindowItemForWindow(grid_index, window) | 257 return GetWindowItemForWindow(grid_index, window) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 274 GetSelectedWindow() != start_window); | 273 GetSelectedWindow() != start_window); |
| 275 return GetSelectedWindow() == window; | 274 return GetSelectedWindow() == window; |
| 276 } | 275 } |
| 277 | 276 |
| 278 const aura::Window* GetSelectedWindow() { | 277 const aura::Window* GetSelectedWindow() { |
| 279 WindowSelector* ws = window_selector(); | 278 WindowSelector* ws = window_selector(); |
| 280 WindowSelectorItem* item = | 279 WindowSelectorItem* item = |
| 281 ws->grid_list_[ws->selected_grid_index_]->SelectedWindow(); | 280 ws->grid_list_[ws->selected_grid_index_]->SelectedWindow(); |
| 282 if (!item) | 281 if (!item) |
| 283 return nullptr; | 282 return nullptr; |
| 284 return WmWindow::GetAuraWindow(item->GetWindow()); | 283 return item->GetWindow(); |
| 285 } | 284 } |
| 286 | 285 |
| 287 bool selection_widget_active() { | 286 bool selection_widget_active() { |
| 288 WindowSelector* ws = window_selector(); | 287 WindowSelector* ws = window_selector(); |
| 289 return ws->grid_list_[ws->selected_grid_index_]->is_selecting(); | 288 return ws->grid_list_[ws->selected_grid_index_]->is_selecting(); |
| 290 } | 289 } |
| 291 | 290 |
| 292 bool showing_filter_widget() { | 291 bool showing_filter_widget() { |
| 293 return window_selector() | 292 return window_selector() |
| 294 ->text_filter_widget_->GetNativeWindow() | 293 ->text_filter_widget_->GetNativeWindow() |
| 295 ->layer() | 294 ->layer() |
| 296 ->GetTargetTransform() | 295 ->GetTargetTransform() |
| 297 .IsIdentity(); | 296 .IsIdentity(); |
| 298 } | 297 } |
| 299 | 298 |
| 300 views::Widget* GetCloseButton(WindowSelectorItem* window) { | 299 views::Widget* GetCloseButton(WindowSelectorItem* window) { |
| 301 return window->close_button_->GetWidget(); | 300 return window->close_button_->GetWidget(); |
| 302 } | 301 } |
| 303 | 302 |
| 304 views::Label* GetLabelView(WindowSelectorItem* window) { | 303 views::Label* GetLabelView(WindowSelectorItem* window) { |
| 305 return window->label_view_; | 304 return window->label_view_; |
| 306 } | 305 } |
| 307 | 306 |
| 308 // Tests that a window is contained within a given WindowSelectorItem, and | 307 // Tests that a window is contained within a given WindowSelectorItem, and |
| 309 // that both the window and its matching close button are within the same | 308 // that both the window and its matching close button are within the same |
| 310 // screen. | 309 // screen. |
| 311 void IsWindowAndCloseButtonInScreen(aura::Window* window, | 310 void IsWindowAndCloseButtonInScreen(aura::Window* window, |
| 312 WindowSelectorItem* window_item) { | 311 WindowSelectorItem* window_item) { |
| 313 aura::Window* root_window = | 312 aura::Window* root_window = window_item->root_window(); |
| 314 WmWindow::GetAuraWindow(window_item->root_window()); | 313 EXPECT_TRUE(window_item->Contains(window)); |
| 315 EXPECT_TRUE(window_item->Contains(WmWindow::Get(window))); | |
| 316 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( | 314 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( |
| 317 GetTransformedTargetBounds(window))); | 315 GetTransformedTargetBounds(window))); |
| 318 EXPECT_TRUE( | 316 EXPECT_TRUE( |
| 319 root_window->GetBoundsInScreen().Contains(GetTransformedTargetBounds( | 317 root_window->GetBoundsInScreen().Contains(GetTransformedTargetBounds( |
| 320 GetCloseButton(window_item)->GetNativeView()))); | 318 GetCloseButton(window_item)->GetNativeView()))); |
| 321 } | 319 } |
| 322 | 320 |
| 323 void FilterItems(const base::StringPiece& pattern) { | 321 void FilterItems(const base::StringPiece& pattern) { |
| 324 window_selector()->ContentsChanged(nullptr, base::UTF8ToUTF16(pattern)); | 322 window_selector()->ContentsChanged(nullptr, base::UTF8ToUTF16(pattern)); |
| 325 } | 323 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 gfx::Rect bounds(0, 0, 400, 400); | 509 gfx::Rect bounds(0, 0, 400, 400); |
| 512 std::unique_ptr<aura::Window> window1(CreateWindowWithId(bounds, 1)); | 510 std::unique_ptr<aura::Window> window1(CreateWindowWithId(bounds, 1)); |
| 513 std::unique_ptr<aura::Window> window2(CreateWindowWithId(bounds, 2)); | 511 std::unique_ptr<aura::Window> window2(CreateWindowWithId(bounds, 2)); |
| 514 std::unique_ptr<aura::Window> window3(CreateWindowWithId(bounds, 3)); | 512 std::unique_ptr<aura::Window> window3(CreateWindowWithId(bounds, 3)); |
| 515 | 513 |
| 516 // The order of windows in overview mode is MRU. | 514 // The order of windows in overview mode is MRU. |
| 517 wm::GetWindowState(window1.get())->Activate(); | 515 wm::GetWindowState(window1.get())->Activate(); |
| 518 ToggleOverview(); | 516 ToggleOverview(); |
| 519 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview1 = | 517 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview1 = |
| 520 GetWindowItemsForRoot(0); | 518 GetWindowItemsForRoot(0); |
| 521 EXPECT_EQ(1, overview1[0]->GetWindow()->aura_window()->id()); | 519 EXPECT_EQ(1, overview1[0]->GetWindow()->id()); |
| 522 EXPECT_EQ(3, overview1[1]->GetWindow()->aura_window()->id()); | 520 EXPECT_EQ(3, overview1[1]->GetWindow()->id()); |
| 523 EXPECT_EQ(2, overview1[2]->GetWindow()->aura_window()->id()); | 521 EXPECT_EQ(2, overview1[2]->GetWindow()->id()); |
| 524 ToggleOverview(); | 522 ToggleOverview(); |
| 525 | 523 |
| 526 // Activate the second window. | 524 // Activate the second window. |
| 527 wm::GetWindowState(window2.get())->Activate(); | 525 wm::GetWindowState(window2.get())->Activate(); |
| 528 ToggleOverview(); | 526 ToggleOverview(); |
| 529 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview2 = | 527 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview2 = |
| 530 GetWindowItemsForRoot(0); | 528 GetWindowItemsForRoot(0); |
| 531 | 529 |
| 532 // The order should be MRU. | 530 // The order should be MRU. |
| 533 EXPECT_EQ(2, overview2[0]->GetWindow()->aura_window()->id()); | 531 EXPECT_EQ(2, overview2[0]->GetWindow()->id()); |
| 534 EXPECT_EQ(1, overview2[1]->GetWindow()->aura_window()->id()); | 532 EXPECT_EQ(1, overview2[1]->GetWindow()->id()); |
| 535 EXPECT_EQ(3, overview2[2]->GetWindow()->aura_window()->id()); | 533 EXPECT_EQ(3, overview2[2]->GetWindow()->id()); |
| 536 ToggleOverview(); | 534 ToggleOverview(); |
| 537 } | 535 } |
| 538 | 536 |
| 539 // Tests selecting a window by tapping on it. | 537 // Tests selecting a window by tapping on it. |
| 540 TEST_F(WindowSelectorTest, BasicGesture) { | 538 TEST_F(WindowSelectorTest, BasicGesture) { |
| 541 gfx::Rect bounds(0, 0, 400, 400); | 539 gfx::Rect bounds(0, 0, 400, 400); |
| 542 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 540 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 543 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 541 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 544 wm::ActivateWindow(window1.get()); | 542 wm::ActivateWindow(window1.get()); |
| 545 EXPECT_EQ(window1.get(), wm::GetFocusedWindow()); | 543 EXPECT_EQ(window1.get(), wm::GetFocusedWindow()); |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 // Tests traversing some windows in overview mode with the tab key. | 1339 // Tests traversing some windows in overview mode with the tab key. |
| 1342 TEST_F(WindowSelectorTest, BasicTabKeyNavigation) { | 1340 TEST_F(WindowSelectorTest, BasicTabKeyNavigation) { |
| 1343 gfx::Rect bounds(0, 0, 100, 100); | 1341 gfx::Rect bounds(0, 0, 100, 100); |
| 1344 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 1342 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 1345 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 1343 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 1346 ToggleOverview(); | 1344 ToggleOverview(); |
| 1347 | 1345 |
| 1348 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_windows = | 1346 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_windows = |
| 1349 GetWindowItemsForRoot(0); | 1347 GetWindowItemsForRoot(0); |
| 1350 SendKey(ui::VKEY_TAB); | 1348 SendKey(ui::VKEY_TAB); |
| 1351 EXPECT_EQ(GetSelectedWindow(), | 1349 EXPECT_EQ(GetSelectedWindow(), overview_windows[0]->GetWindow()); |
| 1352 WmWindow::GetAuraWindow(overview_windows[0]->GetWindow())); | |
| 1353 SendKey(ui::VKEY_TAB); | 1350 SendKey(ui::VKEY_TAB); |
| 1354 EXPECT_EQ(GetSelectedWindow(), | 1351 EXPECT_EQ(GetSelectedWindow(), overview_windows[1]->GetWindow()); |
| 1355 WmWindow::GetAuraWindow(overview_windows[1]->GetWindow())); | |
| 1356 SendKey(ui::VKEY_TAB); | 1352 SendKey(ui::VKEY_TAB); |
| 1357 EXPECT_EQ(GetSelectedWindow(), | 1353 EXPECT_EQ(GetSelectedWindow(), overview_windows[0]->GetWindow()); |
| 1358 WmWindow::GetAuraWindow(overview_windows[0]->GetWindow())); | |
| 1359 } | 1354 } |
| 1360 | 1355 |
| 1361 // Tests that pressing Ctrl+W while a window is selected in overview closes it. | 1356 // Tests that pressing Ctrl+W while a window is selected in overview closes it. |
| 1362 TEST_F(WindowSelectorTest, CloseWindowWithKey) { | 1357 TEST_F(WindowSelectorTest, CloseWindowWithKey) { |
| 1363 gfx::Rect bounds(0, 0, 100, 100); | 1358 gfx::Rect bounds(0, 0, 100, 100); |
| 1364 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 1359 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 1365 std::unique_ptr<views::Widget> widget = | 1360 std::unique_ptr<views::Widget> widget = |
| 1366 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | 1361 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); |
| 1367 aura::Window* window1 = widget->GetNativeWindow(); | 1362 aura::Window* window1 = widget->GetNativeWindow(); |
| 1368 ToggleOverview(); | 1363 ToggleOverview(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1398 for (size_t key_index = 0; key_index < arraysize(arrow_keys); key_index++) { | 1393 for (size_t key_index = 0; key_index < arraysize(arrow_keys); key_index++) { |
| 1399 ToggleOverview(); | 1394 ToggleOverview(); |
| 1400 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_windows = | 1395 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_windows = |
| 1401 GetWindowItemsForRoot(0); | 1396 GetWindowItemsForRoot(0); |
| 1402 for (size_t i = 0; i < test_windows + 1; i++) { | 1397 for (size_t i = 0; i < test_windows + 1; i++) { |
| 1403 SendKey(arrow_keys[key_index]); | 1398 SendKey(arrow_keys[key_index]); |
| 1404 // TODO(flackr): Add a more readable error message by constructing a | 1399 // TODO(flackr): Add a more readable error message by constructing a |
| 1405 // string from the window IDs. | 1400 // string from the window IDs. |
| 1406 const int index = index_path_for_direction[key_index][i]; | 1401 const int index = index_path_for_direction[key_index][i]; |
| 1407 EXPECT_EQ(GetSelectedWindow()->id(), | 1402 EXPECT_EQ(GetSelectedWindow()->id(), |
| 1408 overview_windows[index - 1]->GetWindow()->aura_window()->id()); | 1403 overview_windows[index - 1]->GetWindow()->id()); |
| 1409 } | 1404 } |
| 1410 ToggleOverview(); | 1405 ToggleOverview(); |
| 1411 } | 1406 } |
| 1412 } | 1407 } |
| 1413 | 1408 |
| 1414 // Tests basic selection across multiple monitors. | 1409 // Tests basic selection across multiple monitors. |
| 1415 TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) { | 1410 TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) { |
| 1416 UpdateDisplay("400x400,400x400"); | 1411 UpdateDisplay("400x400,400x400"); |
| 1417 gfx::Rect bounds1(0, 0, 100, 100); | 1412 gfx::Rect bounds1(0, 0, 100, 100); |
| 1418 gfx::Rect bounds2(450, 0, 100, 100); | 1413 gfx::Rect bounds2(450, 0, 100, 100); |
| 1419 std::unique_ptr<aura::Window> window4(CreateWindow(bounds2)); | 1414 std::unique_ptr<aura::Window> window4(CreateWindow(bounds2)); |
| 1420 std::unique_ptr<aura::Window> window3(CreateWindow(bounds2)); | 1415 std::unique_ptr<aura::Window> window3(CreateWindow(bounds2)); |
| 1421 std::unique_ptr<aura::Window> window2(CreateWindow(bounds1)); | 1416 std::unique_ptr<aura::Window> window2(CreateWindow(bounds1)); |
| 1422 std::unique_ptr<aura::Window> window1(CreateWindow(bounds1)); | 1417 std::unique_ptr<aura::Window> window1(CreateWindow(bounds1)); |
| 1423 | 1418 |
| 1424 ToggleOverview(); | 1419 ToggleOverview(); |
| 1425 | 1420 |
| 1426 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_root1 = | 1421 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_root1 = |
| 1427 GetWindowItemsForRoot(0); | 1422 GetWindowItemsForRoot(0); |
| 1428 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_root2 = | 1423 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview_root2 = |
| 1429 GetWindowItemsForRoot(1); | 1424 GetWindowItemsForRoot(1); |
| 1430 SendKey(ui::VKEY_RIGHT); | 1425 SendKey(ui::VKEY_RIGHT); |
| 1431 EXPECT_EQ(GetSelectedWindow(), | 1426 EXPECT_EQ(GetSelectedWindow(), overview_root1[0]->GetWindow()); |
| 1432 WmWindow::GetAuraWindow(overview_root1[0]->GetWindow())); | |
| 1433 SendKey(ui::VKEY_RIGHT); | 1427 SendKey(ui::VKEY_RIGHT); |
| 1434 EXPECT_EQ(GetSelectedWindow(), | 1428 EXPECT_EQ(GetSelectedWindow(), overview_root1[1]->GetWindow()); |
| 1435 WmWindow::GetAuraWindow(overview_root1[1]->GetWindow())); | |
| 1436 SendKey(ui::VKEY_RIGHT); | 1429 SendKey(ui::VKEY_RIGHT); |
| 1437 EXPECT_EQ(GetSelectedWindow(), | 1430 EXPECT_EQ(GetSelectedWindow(), overview_root2[0]->GetWindow()); |
| 1438 WmWindow::GetAuraWindow(overview_root2[0]->GetWindow())); | |
| 1439 SendKey(ui::VKEY_RIGHT); | 1431 SendKey(ui::VKEY_RIGHT); |
| 1440 EXPECT_EQ(GetSelectedWindow(), | 1432 EXPECT_EQ(GetSelectedWindow(), overview_root2[1]->GetWindow()); |
| 1441 WmWindow::GetAuraWindow(overview_root2[1]->GetWindow())); | |
| 1442 } | 1433 } |
| 1443 | 1434 |
| 1444 // Tests first monitor when display order doesn't match left to right screen | 1435 // Tests first monitor when display order doesn't match left to right screen |
| 1445 // positions. | 1436 // positions. |
| 1446 TEST_F(WindowSelectorTest, MultiMonitorReversedOrder) { | 1437 TEST_F(WindowSelectorTest, MultiMonitorReversedOrder) { |
| 1447 // TODO: SetLayoutForCurrentDisplays() needs to ported to mash. | 1438 // TODO: SetLayoutForCurrentDisplays() needs to ported to mash. |
| 1448 // http://crbug.com/698043. | 1439 // http://crbug.com/698043. |
| 1449 if (Shell::GetAshConfig() == Config::MASH) | 1440 if (Shell::GetAshConfig() == Config::MASH) |
| 1450 return; | 1441 return; |
| 1451 | 1442 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 1847 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 1857 ASSERT_TRUE(resizer.get()); | 1848 ASSERT_TRUE(resizer.get()); |
| 1858 gfx::Point location = resizer->GetInitialLocation(); | 1849 gfx::Point location = resizer->GetInitialLocation(); |
| 1859 location.Offset(20, 20); | 1850 location.Offset(20, 20); |
| 1860 resizer->Drag(location, 0); | 1851 resizer->Drag(location, 0); |
| 1861 ToggleOverview(); | 1852 ToggleOverview(); |
| 1862 resizer->RevertDrag(); | 1853 resizer->RevertDrag(); |
| 1863 } | 1854 } |
| 1864 | 1855 |
| 1865 } // namespace ash | 1856 } // namespace ash |
| OLD | NEW |