| 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/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
| 9 #include "ash/common/accessibility_delegate.h" | 9 #include "ash/common/accessibility_delegate.h" |
| 10 #include "ash/common/accessibility_types.h" | 10 #include "ash/common/accessibility_types.h" |
| 11 #include "ash/common/ash_switches.h" | 11 #include "ash/common/ash_switches.h" |
| 12 #include "ash/common/material_design/material_design_controller.h" | 12 #include "ash/common/material_design/material_design_controller.h" |
| 13 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
| 14 #include "ash/common/wm/mru_window_tracker.h" | 14 #include "ash/common/wm/mru_window_tracker.h" |
| 15 #include "ash/common/wm/overview/window_grid.h" | 15 #include "ash/common/wm/overview/window_grid.h" |
| 16 #include "ash/common/wm/overview/window_selector.h" | 16 #include "ash/common/wm/overview/window_selector.h" |
| 17 #include "ash/common/wm/overview/window_selector_controller.h" | 17 #include "ash/common/wm/overview/window_selector_controller.h" |
| 18 #include "ash/common/wm/overview/window_selector_item.h" | 18 #include "ash/common/wm/overview/window_selector_item.h" |
| 19 #include "ash/common/wm/panels/panel_layout_manager.h" | 19 #include "ash/common/wm/panels/panel_layout_manager.h" |
| 20 #include "ash/common/wm/window_state.h" | 20 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm/wm_event.h" | 21 #include "ash/common/wm/wm_event.h" |
| 22 #include "ash/common/wm_shell.h" |
| 22 #include "ash/drag_drop/drag_drop_controller.h" | 23 #include "ash/drag_drop/drag_drop_controller.h" |
| 23 #include "ash/root_window_controller.h" | 24 #include "ash/root_window_controller.h" |
| 24 #include "ash/screen_util.h" | 25 #include "ash/screen_util.h" |
| 25 #include "ash/shelf/shelf.h" | 26 #include "ash/shelf/shelf.h" |
| 26 #include "ash/shelf/shelf_widget.h" | 27 #include "ash/shelf/shelf_widget.h" |
| 27 #include "ash/shell.h" | 28 #include "ash/shell.h" |
| 28 #include "ash/test/ash_test_base.h" | 29 #include "ash/test/ash_test_base.h" |
| 29 #include "ash/test/display_manager_test_api.h" | 30 #include "ash/test/display_manager_test_api.h" |
| 30 #include "ash/test/material_design_controller_test_api.h" | 31 #include "ash/test/material_design_controller_test_api.h" |
| 31 #include "ash/test/shelf_test_api.h" | 32 #include "ash/test/shelf_test_api.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 167 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 167 return window; | 168 return window; |
| 168 } | 169 } |
| 169 | 170 |
| 170 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { | 171 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { |
| 171 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); | 172 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); |
| 172 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); | 173 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); |
| 173 return window1_bounds.Intersects(window2_bounds); | 174 return window1_bounds.Intersects(window2_bounds); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void ToggleOverview() { | 177 WindowSelectorController* window_selector_controller() { |
| 177 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); | 178 return WmShell::Get()->window_selector_controller(); |
| 178 } | 179 } |
| 179 | 180 |
| 181 WindowSelector* window_selector() { |
| 182 return window_selector_controller()->window_selector_.get(); |
| 183 } |
| 184 |
| 185 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } |
| 186 |
| 180 gfx::RectF GetTransformedBounds(aura::Window* window) { | 187 gfx::RectF GetTransformedBounds(aura::Window* window) { |
| 181 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen( | 188 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen( |
| 182 window->parent(), window->layer()->bounds())); | 189 window->parent(), window->layer()->bounds())); |
| 183 gfx::Transform transform(gfx::TransformAboutPivot( | 190 gfx::Transform transform(gfx::TransformAboutPivot( |
| 184 gfx::ToFlooredPoint(bounds.origin()), | 191 gfx::ToFlooredPoint(bounds.origin()), |
| 185 window->layer()->transform())); | 192 window->layer()->transform())); |
| 186 transform.TransformRect(&bounds); | 193 transform.TransformRect(&bounds); |
| 187 return bounds; | 194 return bounds; |
| 188 } | 195 } |
| 189 | 196 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 215 ui::test::EventGenerator event_generator(window->GetRootWindow(), window); | 222 ui::test::EventGenerator event_generator(window->GetRootWindow(), window); |
| 216 event_generator.ClickLeftButton(); | 223 event_generator.ClickLeftButton(); |
| 217 } | 224 } |
| 218 | 225 |
| 219 void SendKey(ui::KeyboardCode key) { | 226 void SendKey(ui::KeyboardCode key) { |
| 220 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); | 227 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); |
| 221 event_generator.PressKey(key, 0); | 228 event_generator.PressKey(key, 0); |
| 222 event_generator.ReleaseKey(key, 0); | 229 event_generator.ReleaseKey(key, 0); |
| 223 } | 230 } |
| 224 | 231 |
| 225 bool IsSelecting() { | 232 bool IsSelecting() { return window_selector_controller()->IsSelecting(); } |
| 226 return ash::Shell::GetInstance()->window_selector_controller()-> | |
| 227 IsSelecting(); | |
| 228 } | |
| 229 | 233 |
| 230 aura::Window* GetFocusedWindow() { | 234 aura::Window* GetFocusedWindow() { |
| 231 return aura::client::GetFocusClient( | 235 return aura::client::GetFocusClient( |
| 232 Shell::GetPrimaryRootWindow())->GetFocusedWindow(); | 236 Shell::GetPrimaryRootWindow())->GetFocusedWindow(); |
| 233 } | 237 } |
| 234 | 238 |
| 235 const std::vector<WindowSelectorItem*>& GetWindowItemsForRoot(int index) { | 239 const std::vector<WindowSelectorItem*>& GetWindowItemsForRoot(int index) { |
| 236 return ash::Shell::GetInstance()->window_selector_controller()-> | 240 return window_selector()->grid_list_[index]->window_list_.get(); |
| 237 window_selector_->grid_list_[index]->window_list_.get(); | |
| 238 } | 241 } |
| 239 | 242 |
| 240 WindowSelectorItem* GetWindowItemForWindow(int grid_index, | 243 WindowSelectorItem* GetWindowItemForWindow(int grid_index, |
| 241 aura::Window* window) { | 244 aura::Window* window) { |
| 242 const std::vector<WindowSelectorItem*>& windows = | 245 const std::vector<WindowSelectorItem*>& windows = |
| 243 GetWindowItemsForRoot(grid_index); | 246 GetWindowItemsForRoot(grid_index); |
| 244 auto iter = std::find_if(windows.cbegin(), windows.cend(), | 247 auto iter = std::find_if(windows.cbegin(), windows.cend(), |
| 245 [window](const WindowSelectorItem* item) { | 248 [window](const WindowSelectorItem* item) { |
| 246 return item->Contains(WmWindowAura::Get(window)); | 249 return item->Contains(WmWindowAura::Get(window)); |
| 247 }); | 250 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 if (start_window == window) | 263 if (start_window == window) |
| 261 return true; | 264 return true; |
| 262 do { | 265 do { |
| 263 SendKey(ui::VKEY_TAB); | 266 SendKey(ui::VKEY_TAB); |
| 264 } while (GetSelectedWindow() != window && | 267 } while (GetSelectedWindow() != window && |
| 265 GetSelectedWindow() != start_window); | 268 GetSelectedWindow() != start_window); |
| 266 return GetSelectedWindow() == window; | 269 return GetSelectedWindow() == window; |
| 267 } | 270 } |
| 268 | 271 |
| 269 const aura::Window* GetSelectedWindow() { | 272 const aura::Window* GetSelectedWindow() { |
| 270 WindowSelector* ws = ash::Shell::GetInstance()-> | 273 WindowSelector* ws = window_selector(); |
| 271 window_selector_controller()->window_selector_.get(); | |
| 272 WindowSelectorItem* item = | 274 WindowSelectorItem* item = |
| 273 ws->grid_list_[ws->selected_grid_index_]->SelectedWindow(); | 275 ws->grid_list_[ws->selected_grid_index_]->SelectedWindow(); |
| 274 if (!item) | 276 if (!item) |
| 275 return nullptr; | 277 return nullptr; |
| 276 return WmWindowAura::GetAuraWindow(item->GetWindow()); | 278 return WmWindowAura::GetAuraWindow(item->GetWindow()); |
| 277 } | 279 } |
| 278 | 280 |
| 279 bool selection_widget_active() { | 281 bool selection_widget_active() { |
| 280 WindowSelector* ws = ash::Shell::GetInstance()-> | 282 WindowSelector* ws = window_selector(); |
| 281 window_selector_controller()->window_selector_.get(); | |
| 282 return ws->grid_list_[ws->selected_grid_index_]->is_selecting(); | 283 return ws->grid_list_[ws->selected_grid_index_]->is_selecting(); |
| 283 } | 284 } |
| 284 | 285 |
| 285 bool showing_filter_widget() { | 286 bool showing_filter_widget() { |
| 286 WindowSelector* ws = ash::Shell::GetInstance()-> | 287 return window_selector() |
| 287 window_selector_controller()->window_selector_.get(); | 288 ->text_filter_widget_->GetNativeWindow() |
| 288 return ws->text_filter_widget_->GetNativeWindow()->layer()-> | 289 ->layer() |
| 289 GetTargetTransform().IsIdentity(); | 290 ->GetTargetTransform() |
| 291 .IsIdentity(); |
| 290 } | 292 } |
| 291 | 293 |
| 292 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { | 294 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { |
| 293 return window->close_button_->GetWidget(); | 295 return window->close_button_->GetWidget(); |
| 294 } | 296 } |
| 295 | 297 |
| 296 views::LabelButton* GetLabelButtonView(ash::WindowSelectorItem* window) { | 298 views::LabelButton* GetLabelButtonView(ash::WindowSelectorItem* window) { |
| 297 return window->window_label_button_view_; | 299 return window->window_label_button_view_; |
| 298 } | 300 } |
| 299 | 301 |
| 300 // Tests that a window is contained within a given WindowSelectorItem, and | 302 // Tests that a window is contained within a given WindowSelectorItem, and |
| 301 // that both the window and its matching close button are within the same | 303 // that both the window and its matching close button are within the same |
| 302 // screen. | 304 // screen. |
| 303 void IsWindowAndCloseButtonInScreen(aura::Window* window, | 305 void IsWindowAndCloseButtonInScreen(aura::Window* window, |
| 304 WindowSelectorItem* window_item) { | 306 WindowSelectorItem* window_item) { |
| 305 aura::Window* root_window = | 307 aura::Window* root_window = |
| 306 WmWindowAura::GetAuraWindow(window_item->root_window()); | 308 WmWindowAura::GetAuraWindow(window_item->root_window()); |
| 307 EXPECT_TRUE(window_item->Contains(WmWindowAura::Get(window))); | 309 EXPECT_TRUE(window_item->Contains(WmWindowAura::Get(window))); |
| 308 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( | 310 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( |
| 309 ToEnclosingRect(GetTransformedTargetBounds(window)))); | 311 ToEnclosingRect(GetTransformedTargetBounds(window)))); |
| 310 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( | 312 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( |
| 311 ToEnclosingRect(GetTransformedTargetBounds( | 313 ToEnclosingRect(GetTransformedTargetBounds( |
| 312 GetCloseButton(window_item)->GetNativeView())))); | 314 GetCloseButton(window_item)->GetNativeView())))); |
| 313 } | 315 } |
| 314 | 316 |
| 315 void FilterItems(const base::StringPiece& pattern) { | 317 void FilterItems(const base::StringPiece& pattern) { |
| 316 ash::Shell::GetInstance()-> | 318 window_selector()->ContentsChanged(nullptr, base::UTF8ToUTF16(pattern)); |
| 317 window_selector_controller()->window_selector_.get()-> | |
| 318 ContentsChanged(nullptr, base::UTF8ToUTF16(pattern)); | |
| 319 } | 319 } |
| 320 | 320 |
| 321 test::ShelfViewTestAPI* shelf_view_test() { | 321 test::ShelfViewTestAPI* shelf_view_test() { |
| 322 return shelf_view_test_.get(); | 322 return shelf_view_test_.get(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 views::Widget* text_filter_widget() { | 325 views::Widget* text_filter_widget() { |
| 326 return ash::Shell::GetInstance()-> | 326 return window_selector()->text_filter_widget_.get(); |
| 327 window_selector_controller()->window_selector_.get()-> | |
| 328 text_filter_widget_.get(); | |
| 329 } | 327 } |
| 330 | 328 |
| 331 private: | 329 private: |
| 332 aura::test::TestWindowDelegate delegate_; | 330 aura::test::TestWindowDelegate delegate_; |
| 333 NonActivatableActivationDelegate non_activatable_activation_delegate_; | 331 NonActivatableActivationDelegate non_activatable_activation_delegate_; |
| 334 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; | 332 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; |
| 335 std::unique_ptr<test::MaterialDesignControllerTestAPI> material_design_state_; | 333 std::unique_ptr<test::MaterialDesignControllerTestAPI> material_design_state_; |
| 336 | 334 |
| 337 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); | 335 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); |
| 338 }; | 336 }; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 ToggleOverview(); | 609 ToggleOverview(); |
| 612 | 610 |
| 613 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); | 611 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); |
| 614 // Docked windows stays the same. | 612 // Docked windows stays the same. |
| 615 EXPECT_EQ(docked_bounds.ToString(), docked1->GetBoundsInScreen().ToString()); | 613 EXPECT_EQ(docked_bounds.ToString(), docked1->GetBoundsInScreen().ToString()); |
| 616 EXPECT_FALSE(docked2->IsVisible()); | 614 EXPECT_FALSE(docked2->IsVisible()); |
| 617 | 615 |
| 618 // Docked window can still be activated, which will exit the overview mode. | 616 // Docked window can still be activated, which will exit the overview mode. |
| 619 ClickWindow(docked1.get()); | 617 ClickWindow(docked1.get()); |
| 620 EXPECT_TRUE(wm::IsActiveWindow(docked1.get())); | 618 EXPECT_TRUE(wm::IsActiveWindow(docked1.get())); |
| 621 EXPECT_FALSE( | 619 EXPECT_FALSE(window_selector_controller()->IsSelecting()); |
| 622 ash::Shell::GetInstance()->window_selector_controller()->IsSelecting()); | |
| 623 } | 620 } |
| 624 | 621 |
| 625 // Tests selecting a window by tapping on it. | 622 // Tests selecting a window by tapping on it. |
| 626 TEST_P(WindowSelectorTest, BasicGesture) { | 623 TEST_P(WindowSelectorTest, BasicGesture) { |
| 627 gfx::Rect bounds(0, 0, 400, 400); | 624 gfx::Rect bounds(0, 0, 400, 400); |
| 628 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 625 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 629 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 626 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 630 wm::ActivateWindow(window1.get()); | 627 wm::ActivateWindow(window1.get()); |
| 631 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 628 EXPECT_EQ(window1.get(), GetFocusedWindow()); |
| 632 ToggleOverview(); | 629 ToggleOverview(); |
| (...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 bounds.y()); | 1827 bounds.y()); |
| 1831 EXPECT_LE(transformed_rect.bottom(), bounds.bottom()); | 1828 EXPECT_LE(transformed_rect.bottom(), bounds.bottom()); |
| 1832 EXPECT_NEAR(transformed_rect.x() - bounds.x(), | 1829 EXPECT_NEAR(transformed_rect.x() - bounds.x(), |
| 1833 bounds.right() - transformed_rect.right(), 1); | 1830 bounds.right() - transformed_rect.right(), 1); |
| 1834 EXPECT_NEAR( | 1831 EXPECT_NEAR( |
| 1835 transformed_rect.y() + (int)(scale * inset) - header_height - bounds.y(), | 1832 transformed_rect.y() + (int)(scale * inset) - header_height - bounds.y(), |
| 1836 bounds.bottom() - transformed_rect.bottom(), 1); | 1833 bounds.bottom() - transformed_rect.bottom(), 1); |
| 1837 } | 1834 } |
| 1838 | 1835 |
| 1839 } // namespace ash | 1836 } // namespace ash |
| OLD | NEW |