| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/app_list/views/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 const gfx::Point& from, | 148 const gfx::Point& from, |
| 149 const gfx::Point& to) { | 149 const gfx::Point& to) { |
| 150 AppListItemView* view = GetItemViewForPoint(from); | 150 AppListItemView* view = GetItemViewForPoint(from); |
| 151 DCHECK(view); | 151 DCHECK(view); |
| 152 | 152 |
| 153 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( | 153 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( |
| 154 from - view->bounds().origin()); | 154 from - view->bounds().origin()); |
| 155 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin( | 155 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin( |
| 156 to - view->bounds().origin()); | 156 to - view->bounds().origin()); |
| 157 | 157 |
| 158 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, translated_from, from, | 158 ui::MouseEvent pressed_event( |
| 159 ui::EventTimeForNow(), 0, 0); | 159 ui::ET_MOUSE_PRESSED, translated_from, from, ui::EventTimeForNow(), 0, |
| 160 0, ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 160 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); | 161 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); |
| 161 | 162 |
| 162 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, | 163 ui::MouseEvent drag_event( |
| 163 ui::EventTimeForNow(), 0, 0); | 164 ui::ET_MOUSE_DRAGGED, translated_to, to, ui::EventTimeForNow(), 0, 0, |
| 165 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 164 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); | 166 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); |
| 165 return view; | 167 return view; |
| 166 } | 168 } |
| 167 | 169 |
| 168 void SimulateKeyPress(ui::KeyboardCode key_code) { | 170 void SimulateKeyPress(ui::KeyboardCode key_code) { |
| 169 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); | 171 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); |
| 170 apps_grid_view_->OnKeyPressed(key_event); | 172 apps_grid_view_->OnKeyPressed(key_event); |
| 171 } | 173 } |
| 172 | 174 |
| 173 scoped_ptr<AppListTestModel> model_; | 175 scoped_ptr<AppListTestModel> model_; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 test_api_->LayoutToIdealBounds(); | 301 test_api_->LayoutToIdealBounds(); |
| 300 | 302 |
| 301 // Adding a launcher item cancels the drag and respects the order. | 303 // Adding a launcher item cancels the drag and respects the order. |
| 302 SimulateDrag(AppsGridView::MOUSE, from, to); | 304 SimulateDrag(AppsGridView::MOUSE, from, to); |
| 303 EXPECT_TRUE(apps_grid_view_->has_dragged_view()); | 305 EXPECT_TRUE(apps_grid_view_->has_dragged_view()); |
| 304 model_->CreateAndAddItem("Extra"); | 306 model_->CreateAndAddItem("Extra"); |
| 305 // No need to EndDrag explicitly - adding an item should do this. | 307 // No need to EndDrag explicitly - adding an item should do this. |
| 306 EXPECT_FALSE(apps_grid_view_->has_dragged_view()); | 308 EXPECT_FALSE(apps_grid_view_->has_dragged_view()); |
| 307 // Even though cancelled, mouse move events can still arrive via the item | 309 // Even though cancelled, mouse move events can still arrive via the item |
| 308 // view. Ensure that behaves sanely, and doesn't start a new drag. | 310 // view. Ensure that behaves sanely, and doesn't start a new drag. |
| 309 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), | 311 ui::MouseEvent drag_event( |
| 310 gfx::Point(2, 2), ui::EventTimeForNow(), 0, 0); | 312 ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), gfx::Point(2, 2), |
| 313 ui::EventTimeForNow(), 0, 0, |
| 314 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 311 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); | 315 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); |
| 312 EXPECT_FALSE(apps_grid_view_->has_dragged_view()); | 316 EXPECT_FALSE(apps_grid_view_->has_dragged_view()); |
| 313 | 317 |
| 314 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"), | 318 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"), |
| 315 model_->GetModelContent()); | 319 model_->GetModelContent()); |
| 316 test_api_->LayoutToIdealBounds(); | 320 test_api_->LayoutToIdealBounds(); |
| 317 } | 321 } |
| 318 | 322 |
| 319 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { | 323 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { |
| 320 EnsureFoldersEnabled(); | 324 EnsureFoldersEnabled(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 448 |
| 445 // The grid now looks like | blank | folder |. | 449 // The grid now looks like | blank | folder |. |
| 446 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint())); | 450 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint())); |
| 447 EXPECT_EQ(folder_view, | 451 EXPECT_EQ(folder_view, |
| 448 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint())); | 452 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint())); |
| 449 | 453 |
| 450 // Move onto the folder and end the drag. | 454 // Move onto the folder and end the drag. |
| 451 to = GetItemTileRectAt(0, 1).CenterPoint(); | 455 to = GetItemTileRectAt(0, 1).CenterPoint(); |
| 452 gfx::Point translated_to = | 456 gfx::Point translated_to = |
| 453 gfx::PointAtOffsetFromOrigin(to - dragged_view->bounds().origin()); | 457 gfx::PointAtOffsetFromOrigin(to - dragged_view->bounds().origin()); |
| 454 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, | 458 ui::MouseEvent drag_event( |
| 455 ui::EventTimeForNow(), 0, 0); | 459 ui::ET_MOUSE_DRAGGED, translated_to, to, ui::EventTimeForNow(), 0, 0, |
| 460 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 456 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); | 461 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); |
| 457 apps_grid_view_->EndDrag(false); | 462 apps_grid_view_->EndDrag(false); |
| 458 | 463 |
| 459 // The item should not have moved into the folder. | 464 // The item should not have moved into the folder. |
| 460 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 465 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
| 461 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); | 466 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); |
| 462 test_api_->LayoutToIdealBounds(); | 467 test_api_->LayoutToIdealBounds(); |
| 463 } | 468 } |
| 464 | 469 |
| 465 TEST_F(AppsGridViewTest, MouseDragItemReorder) { | 470 TEST_F(AppsGridViewTest, MouseDragItemReorder) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 AppListItemView* item_view = GetItemViewAt(0); | 789 AppListItemView* item_view = GetItemViewAt(0); |
| 785 ASSERT_TRUE(item_view); | 790 ASSERT_TRUE(item_view); |
| 786 const views::Label* title_label = item_view->title(); | 791 const views::Label* title_label = item_view->title(); |
| 787 EXPECT_FALSE(title_label->GetTooltipText( | 792 EXPECT_FALSE(title_label->GetTooltipText( |
| 788 title_label->bounds().CenterPoint(), &actual_tooltip)); | 793 title_label->bounds().CenterPoint(), &actual_tooltip)); |
| 789 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 794 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
| 790 } | 795 } |
| 791 | 796 |
| 792 } // namespace test | 797 } // namespace test |
| 793 } // namespace app_list | 798 } // namespace app_list |
| OLD | NEW |