| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ash/wm/panels/panel_window_resizer.h" | 5 #include "ash/wm/panels/panel_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/config.h" | 7 #include "ash/public/cpp/config.h" |
| 8 #include "ash/public/cpp/shelf_types.h" | 8 #include "ash/public/cpp/shelf_types.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/public/cpp/window_properties.h" | 10 #include "ash/public/cpp/window_properties.h" |
| 11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
| 13 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 14 #include "ash/shelf/shelf_widget.h" |
| 15 #include "ash/shelf/wm_shelf.h" | 15 #include "ash/shelf/wm_shelf.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/shell_port.h" | 17 #include "ash/shell_port.h" |
| 18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/test/cursor_manager_test_api.h" | 19 #include "ash/test/cursor_manager_test_api.h" |
| 20 #include "ash/test/test_shelf_delegate.h" | 20 #include "ash/test/shelf_view_test_api.h" |
| 21 #include "ash/wm/drag_window_resizer.h" | 21 #include "ash/wm/drag_window_resizer.h" |
| 22 #include "ash/wm/window_properties.h" | 22 #include "ash/wm/window_properties.h" |
| 23 #include "ash/wm/window_state.h" | 23 #include "ash/wm/window_state.h" |
| 24 #include "ash/wm/window_state_aura.h" | 24 #include "ash/wm/window_state_aura.h" |
| 25 #include "ash/wm/wm_event.h" | 25 #include "ash/wm/wm_event.h" |
| 26 #include "ash/wm_window.h" | 26 #include "ash/wm_window.h" |
| 27 #include "base/i18n/rtl.h" | 27 #include "base/i18n/rtl.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 28 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/aura/window_event_dispatcher.h" | 29 #include "ui/aura/window_event_dispatcher.h" |
| 30 #include "ui/base/hit_test.h" | 30 #include "ui/base/hit_test.h" |
| 31 #include "ui/base/ui_base_types.h" | 31 #include "ui/base/ui_base_types.h" |
| 32 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
| 33 #include "ui/wm/core/window_util.h" | 33 #include "ui/wm/core/window_util.h" |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| 36 | 36 |
| 37 class PanelWindowResizerTest : public test::AshTestBase { | 37 class PanelWindowResizerTest : public test::AshTestBase { |
| 38 public: | 38 public: |
| 39 PanelWindowResizerTest() {} | 39 PanelWindowResizerTest() {} |
| 40 ~PanelWindowResizerTest() override {} | 40 ~PanelWindowResizerTest() override {} |
| 41 | 41 |
| 42 void SetUp() override { | 42 void SetUp() override { |
| 43 AshTestBase::SetUp(); | 43 AshTestBase::SetUp(); |
| 44 UpdateDisplay("600x400"); | 44 UpdateDisplay("600x400"); |
| 45 model_ = Shell::Get()->shelf_model(); | 45 shelf_view_test_.reset(new test::ShelfViewTestAPI( |
| 46 GetPrimaryShelf()->GetShelfViewForTesting())); |
| 47 shelf_view_test_->SetAnimationDuration(1); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void TearDown() override { AshTestBase::TearDown(); } | 50 void TearDown() override { AshTestBase::TearDown(); } |
| 49 | 51 |
| 50 protected: | 52 protected: |
| 51 gfx::Point CalculateDragPoint(const WindowResizer& resizer, | 53 gfx::Point CalculateDragPoint(const WindowResizer& resizer, |
| 52 int delta_x, | 54 int delta_x, |
| 53 int delta_y) const { | 55 int delta_y) const { |
| 54 gfx::Point location = resizer.GetInitialLocation(); | 56 gfx::Point location = resizer.GetInitialLocation(); |
| 55 location.set_x(location.x() + delta_x); | 57 location.set_x(location.x() + delta_x); |
| 56 location.set_y(location.y() + delta_y); | 58 location.set_y(location.y() + delta_y); |
| 57 return location; | 59 return location; |
| 58 } | 60 } |
| 59 | 61 |
| 60 aura::Window* CreatePanelWindow(const gfx::Point& origin) { | 62 aura::Window* CreatePanelWindow(const gfx::Point& origin) { |
| 61 gfx::Rect bounds(origin, gfx::Size(101, 101)); | 63 gfx::Rect bounds(origin, gfx::Size(101, 101)); |
| 62 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 64 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
| 63 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, bounds); | 65 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, bounds); |
| 64 test::TestShelfDelegate::instance()->AddShelfItem(WmWindow::Get(window)); | 66 shelf_view_test_->RunMessageLoopUntilAnimationsDone(); |
| 65 return window; | 67 return window; |
| 66 } | 68 } |
| 67 | 69 |
| 68 void DragStart(aura::Window* window) { | 70 void DragStart(aura::Window* window) { |
| 69 resizer_.reset(CreateWindowResizer(WmWindow::Get(window), | 71 resizer_ = |
| 70 window->bounds().origin(), HTCAPTION, | 72 CreateWindowResizer(WmWindow::Get(window), window->bounds().origin(), |
| 71 aura::client::WINDOW_MOVE_SOURCE_MOUSE) | 73 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 72 .release()); | |
| 73 ASSERT_TRUE(resizer_.get()); | |
| 74 } | 74 } |
| 75 | 75 |
| 76 void DragMove(int dx, int dy) { | 76 void DragMove(int dx, int dy) { |
| 77 resizer_->Drag(CalculateDragPoint(*resizer_, dx, dy), 0); | 77 resizer_->Drag(CalculateDragPoint(*resizer_, dx, dy), 0); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void DragEnd() { | 80 void DragEnd() { |
| 81 resizer_->CompleteDrag(); | 81 resizer_->CompleteDrag(); |
| 82 resizer_.reset(); | 82 resizer_.reset(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void DragRevert() { | 85 void DragRevert() { |
| 86 resizer_->RevertDrag(); | 86 resizer_->RevertDrag(); |
| 87 resizer_.reset(); | 87 resizer_.reset(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Test dragging the panel slightly, then detaching, and then reattaching | 90 // Test dragging the panel slightly, then detaching, and then reattaching, |
| 91 // dragging out by the vector (dx, dy). | 91 // dragging out by the vector (dx, dy). |
| 92 void DetachReattachTest(aura::Window* window, int dx, int dy) { | 92 void DetachReattachTest(aura::Window* window, int dx, int dy) { |
| 93 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); | 93 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); |
| 94 aura::Window* root_window = window->GetRootWindow(); | 94 aura::Window* root_window = window->GetRootWindow(); |
| 95 EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id()); | 95 EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id()); |
| 96 DragStart(window); | 96 DragStart(window); |
| 97 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 97 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 98 | 98 |
| 99 // Drag the panel slightly. The window should still be snapped to the | 99 // Drag slightly, the panel window should remain attached to the shelf. |
| 100 // launcher. | |
| 101 DragMove(dx * 5, dy * 5); | 100 DragMove(dx * 5, dy * 5); |
| 102 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); | 101 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
| 103 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); | 102 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); |
| 104 | 103 |
| 105 // Drag further out and the window should now move to the cursor. | 104 // Drag further out, the panel window should detach and move to the cursor. |
| 106 DragMove(dx * 100, dy * 100); | 105 DragMove(dx * 100, dy * 100); |
| 107 EXPECT_EQ(initial_bounds.x() + dx * 100, window->GetBoundsInScreen().x()); | 106 EXPECT_EQ(initial_bounds.x() + dx * 100, window->GetBoundsInScreen().x()); |
| 108 EXPECT_EQ(initial_bounds.y() + dy * 100, window->GetBoundsInScreen().y()); | 107 EXPECT_EQ(initial_bounds.y() + dy * 100, window->GetBoundsInScreen().y()); |
| 109 | |
| 110 // The panel should be detached when the drag completes. | |
| 111 DragEnd(); | 108 DragEnd(); |
| 112 | 109 |
| 113 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); | 110 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); |
| 114 EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id()); | 111 EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id()); |
| 115 EXPECT_EQ(root_window, window->GetRootWindow()); | 112 EXPECT_EQ(root_window, window->GetRootWindow()); |
| 116 | 113 |
| 114 // Drag back towards the shelf, the panel window should re-attach. |
| 117 DragStart(window); | 115 DragStart(window); |
| 118 // Drag the panel down. | |
| 119 DragMove(dx * -95, dy * -95); | 116 DragMove(dx * -95, dy * -95); |
| 120 // Release the mouse and the panel should be reattached. | |
| 121 DragEnd(); | 117 DragEnd(); |
| 122 | 118 |
| 123 // The panel should be reattached and have snapped to the launcher. | |
| 124 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); | 119 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); |
| 125 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); | 120 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
| 126 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); | 121 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); |
| 127 EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id()); | 122 EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id()); |
| 128 } | 123 } |
| 129 | 124 |
| 130 void TestWindowOrder(const std::vector<aura::Window*>& window_order) { | 125 // Ensure |first| and its shelf item come before those of |second|: |
| 131 int panel_index = model_->FirstPanelIndex(); | 126 // - |first| should be left of |second| in an LTR bottom-aligned shelf. |
| 132 EXPECT_EQ((int)(panel_index + window_order.size()), model_->item_count()); | 127 // - |first| should be right of |second| in an RTL bottom-aligned shelf. |
| 133 for (std::vector<aura::Window *>::const_iterator | 128 // - |first| should be above |second| in a left- or right-aligned shelf. |
| 134 iter = window_order.begin(); | 129 void CheckWindowAndItemPlacement(aura::Window* first, aura::Window* second) { |
| 135 iter != window_order.end(); ++iter, ++panel_index) { | 130 WmShelf* shelf = GetPrimaryShelf(); |
| 136 ShelfID id = (*iter)->GetProperty(kShelfIDKey); | 131 const gfx::Rect first_item_bounds = |
| 137 EXPECT_EQ(id, model_->items()[panel_index].id); | 132 shelf->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(first)); |
| 133 const gfx::Rect second_item_bounds = |
| 134 shelf->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(second)); |
| 135 if (!base::i18n::IsRTL()) { |
| 136 EXPECT_TRUE((first->bounds().x() < second->bounds().x()) || |
| 137 (first->bounds().y() < second->bounds().y())); |
| 138 EXPECT_TRUE((first_item_bounds.x() < second_item_bounds.x()) || |
| 139 (first_item_bounds.y() < second_item_bounds.y())); |
| 140 } else { |
| 141 EXPECT_TRUE((first->bounds().x() > second->bounds().x()) || |
| 142 (first->bounds().y() < second->bounds().y())); |
| 143 EXPECT_TRUE((first_item_bounds.x() > second_item_bounds.x()) || |
| 144 (first_item_bounds.y() < second_item_bounds.y())); |
| 138 } | 145 } |
| 139 } | 146 } |
| 140 | 147 |
| 141 // Test dragging panel window along the shelf and verify that panel icons | 148 // Test dragging panel window along the shelf and verify that panel icons are |
| 142 // are reordered appropriately. | 149 // reordered appropriately. New shelf items for panels are inserted before |
| 150 // existing panel items (eg. to the left in an LTR bottom-aligned shelf). |
| 143 void DragAlongShelfReorder(int dx, int dy) { | 151 void DragAlongShelfReorder(int dx, int dy) { |
| 144 gfx::Point origin(0, 0); | 152 std::unique_ptr<aura::Window> w1(CreatePanelWindow(gfx::Point())); |
| 145 std::unique_ptr<aura::Window> w1(CreatePanelWindow(origin)); | 153 std::unique_ptr<aura::Window> w2(CreatePanelWindow(gfx::Point())); |
| 146 std::unique_ptr<aura::Window> w2(CreatePanelWindow(origin)); | 154 CheckWindowAndItemPlacement(w2.get(), w1.get()); |
| 147 std::vector<aura::Window*> window_order_original; | |
| 148 std::vector<aura::Window*> window_order_swapped; | |
| 149 window_order_original.push_back(w1.get()); | |
| 150 window_order_original.push_back(w2.get()); | |
| 151 window_order_swapped.push_back(w2.get()); | |
| 152 window_order_swapped.push_back(w1.get()); | |
| 153 TestWindowOrder(window_order_original); | |
| 154 | 155 |
| 155 // Drag window #2 to the beginning of the shelf. | 156 // Drag window #1 to the beginning of the shelf, the items should swap. |
| 156 DragStart(w2.get()); | 157 DragStart(w1.get()); |
| 157 DragMove(400 * dx, 400 * dy); | 158 DragMove(400 * dx, 400 * dy); |
| 158 TestWindowOrder(window_order_swapped); | 159 CheckWindowAndItemPlacement(w1.get(), w2.get()); |
| 159 DragEnd(); | 160 DragEnd(); |
| 161 CheckWindowAndItemPlacement(w1.get(), w2.get()); |
| 160 | 162 |
| 161 // Expect swapped window order. | 163 // Drag window #1 back to the end, the items should swap back. |
| 162 TestWindowOrder(window_order_swapped); | 164 DragStart(w1.get()); |
| 163 | |
| 164 // Drag window #2 back to the end. | |
| 165 DragStart(w2.get()); | |
| 166 DragMove(-400 * dx, -400 * dy); | 165 DragMove(-400 * dx, -400 * dy); |
| 167 TestWindowOrder(window_order_original); | 166 CheckWindowAndItemPlacement(w2.get(), w1.get()); |
| 168 DragEnd(); | 167 DragEnd(); |
| 169 | 168 CheckWindowAndItemPlacement(w2.get(), w1.get()); |
| 170 // Expect original order. | |
| 171 TestWindowOrder(window_order_original); | |
| 172 } | 169 } |
| 173 | 170 |
| 174 private: | 171 private: |
| 175 std::unique_ptr<WindowResizer> resizer_; | 172 std::unique_ptr<WindowResizer> resizer_; |
| 176 ShelfModel* model_; | 173 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; |
| 177 | 174 |
| 178 DISALLOW_COPY_AND_ASSIGN(PanelWindowResizerTest); | 175 DISALLOW_COPY_AND_ASSIGN(PanelWindowResizerTest); |
| 179 }; | 176 }; |
| 180 | 177 |
| 181 class PanelWindowResizerTextDirectionTest | 178 class PanelWindowResizerTextDirectionTest |
| 182 : public PanelWindowResizerTest, | 179 : public PanelWindowResizerTest, |
| 183 public testing::WithParamInterface<bool> { | 180 public testing::WithParamInterface<bool> { |
| 184 public: | 181 public: |
| 185 PanelWindowResizerTextDirectionTest() : is_rtl_(GetParam()) {} | 182 PanelWindowResizerTextDirectionTest() : is_rtl_(GetParam()) {} |
| 186 virtual ~PanelWindowResizerTextDirectionTest() {} | 183 virtual ~PanelWindowResizerTextDirectionTest() {} |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id()); | 549 EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id()); |
| 553 EXPECT_EQ(kShellWindowId_DefaultContainer, child->parent()->id()); | 550 EXPECT_EQ(kShellWindowId_DefaultContainer, child->parent()->id()); |
| 554 } | 551 } |
| 555 | 552 |
| 556 INSTANTIATE_TEST_CASE_P(LtrRtl, | 553 INSTANTIATE_TEST_CASE_P(LtrRtl, |
| 557 PanelWindowResizerTextDirectionTest, | 554 PanelWindowResizerTextDirectionTest, |
| 558 testing::Bool()); | 555 testing::Bool()); |
| 559 INSTANTIATE_TEST_CASE_P(NormalPanelPopup, | 556 INSTANTIATE_TEST_CASE_P(NormalPanelPopup, |
| 560 PanelWindowResizerTransientTest, | 557 PanelWindowResizerTransientTest, |
| 561 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 558 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
| 562 ui::wm::WINDOW_TYPE_PANEL, | |
| 563 ui::wm::WINDOW_TYPE_POPUP)); | 559 ui::wm::WINDOW_TYPE_POPUP)); |
| 564 | 560 |
| 565 } // namespace ash | 561 } // namespace ash |
| OLD | NEW |