| 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 "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
| 11 #include "ash/drag_drop/drag_image_view.h" | 11 #include "ash/drag_drop/drag_image_view.h" |
| 12 #include "ash/public/cpp/config.h" |
| 12 #include "ash/public/cpp/shelf_item_delegate.h" | 13 #include "ash/public/cpp/shelf_item_delegate.h" |
| 13 #include "ash/scoped_root_window_for_new_windows.h" | 14 #include "ash/scoped_root_window_for_new_windows.h" |
| 14 #include "ash/screen_util.h" | 15 #include "ash/screen_util.h" |
| 15 #include "ash/shelf/app_list_button.h" | 16 #include "ash/shelf/app_list_button.h" |
| 16 #include "ash/shelf/overflow_bubble.h" | 17 #include "ash/shelf/overflow_bubble.h" |
| 17 #include "ash/shelf/overflow_bubble_view.h" | 18 #include "ash/shelf/overflow_bubble_view.h" |
| 18 #include "ash/shelf/overflow_button.h" | 19 #include "ash/shelf/overflow_button.h" |
| 19 #include "ash/shelf/shelf.h" | 20 #include "ash/shelf/shelf.h" |
| 20 #include "ash/shelf/shelf_application_menu_model.h" | 21 #include "ash/shelf/shelf_application_menu_model.h" |
| 21 #include "ash/shelf/shelf_button.h" | 22 #include "ash/shelf/shelf_button.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 case TYPE_UNDEFINED: | 457 case TYPE_UNDEFINED: |
| 457 NOTREACHED() << "ShelfItemType must be set."; | 458 NOTREACHED() << "ShelfItemType must be set."; |
| 458 break; | 459 break; |
| 459 } | 460 } |
| 460 | 461 |
| 461 const int64_t display_id = | 462 const int64_t display_id = |
| 462 display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); | 463 display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); |
| 463 | 464 |
| 464 // Notify the item of its selection; handle the result in AfterItemSelected. | 465 // Notify the item of its selection; handle the result in AfterItemSelected. |
| 465 const ShelfItem& item = model_->items()[last_pressed_index_]; | 466 const ShelfItem& item = model_->items()[last_pressed_index_]; |
| 467 // Mash requires conversion of mouse and touch events to pointer events. |
| 468 std::unique_ptr<ui::Event> pointer_event; |
| 469 if (Shell::GetAshConfig() == Config::MASH && |
| 470 ui::PointerEvent::CanConvertFrom(event)) { |
| 471 if (event.IsMouseEvent()) |
| 472 pointer_event = base::MakeUnique<ui::PointerEvent>(*event.AsMouseEvent()); |
| 473 else if (event.IsTouchEvent()) |
| 474 pointer_event = base::MakeUnique<ui::PointerEvent>(*event.AsTouchEvent()); |
| 475 else |
| 476 NOTREACHED() << "Need conversion of event to pointer event."; |
| 477 } |
| 478 const ui::Event* event_to_pass = pointer_event ? pointer_event.get() : &event; |
| 466 model_->GetShelfItemDelegate(item.id)->ItemSelected( | 479 model_->GetShelfItemDelegate(item.id)->ItemSelected( |
| 467 ui::Event::Clone(event), display_id, LAUNCH_FROM_UNKNOWN, | 480 ui::Event::Clone(*event_to_pass), display_id, LAUNCH_FROM_UNKNOWN, |
| 468 base::Bind(&ShelfView::AfterItemSelected, weak_factory_.GetWeakPtr(), | 481 base::Bind(&ShelfView::AfterItemSelected, weak_factory_.GetWeakPtr(), |
| 469 item, sender, base::Passed(ui::Event::Clone(event)), | 482 item, sender, base::Passed(ui::Event::Clone(*event_to_pass)), |
| 470 ink_drop)); | 483 ink_drop)); |
| 471 } | 484 } |
| 472 | 485 |
| 473 //////////////////////////////////////////////////////////////////////////////// | 486 //////////////////////////////////////////////////////////////////////////////// |
| 474 // ShelfView, FocusTraversable implementation: | 487 // ShelfView, FocusTraversable implementation: |
| 475 | 488 |
| 476 views::FocusSearch* ShelfView::GetFocusSearch() { | 489 views::FocusSearch* ShelfView::GetFocusSearch() { |
| 477 return focus_search_.get(); | 490 return focus_search_.get(); |
| 478 } | 491 } |
| 479 | 492 |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 void ShelfView::ShelfItemMoved(int start_index, int target_index) { | 1600 void ShelfView::ShelfItemMoved(int start_index, int target_index) { |
| 1588 view_model_->Move(start_index, target_index); | 1601 view_model_->Move(start_index, target_index); |
| 1589 // When cancelling a drag due to a shelf item being added, the currently | 1602 // When cancelling a drag due to a shelf item being added, the currently |
| 1590 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1603 // dragged item is moved back to its initial position. AnimateToIdealBounds |
| 1591 // will be called again when the new item is added to the |view_model_| but | 1604 // will be called again when the new item is added to the |view_model_| but |
| 1592 // at this time the |view_model_| is inconsistent with the |model_|. | 1605 // at this time the |view_model_| is inconsistent with the |model_|. |
| 1593 if (!cancelling_drag_model_changed_) | 1606 if (!cancelling_drag_model_changed_) |
| 1594 AnimateToIdealBounds(); | 1607 AnimateToIdealBounds(); |
| 1595 } | 1608 } |
| 1596 | 1609 |
| 1610 void ShelfView::ShelfItemDelegateChanged(const ShelfID& id, |
| 1611 ShelfItemDelegate* delegate) {} |
| 1612 |
| 1597 void ShelfView::AfterItemSelected( | 1613 void ShelfView::AfterItemSelected( |
| 1598 const ShelfItem& item, | 1614 const ShelfItem& item, |
| 1599 views::Button* sender, | 1615 views::Button* sender, |
| 1600 std::unique_ptr<ui::Event> event, | 1616 std::unique_ptr<ui::Event> event, |
| 1601 views::InkDrop* ink_drop, | 1617 views::InkDrop* ink_drop, |
| 1602 ShelfAction action, | 1618 ShelfAction action, |
| 1603 base::Optional<std::vector<mojom::MenuItemPtr>> menu_items) { | 1619 base::Optional<std::vector<mojom::MenuItemPtr>> menu_items) { |
| 1604 shelf_button_pressed_metric_tracker_.ButtonPressed(*event, sender, action); | 1620 shelf_button_pressed_metric_tracker_.ButtonPressed(*event, sender, action); |
| 1605 | 1621 |
| 1606 // The app list handles its own ink drop effect state changes. | 1622 // The app list handles its own ink drop effect state changes. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 if (pointer == TOUCH && | 1836 if (pointer == TOUCH && |
| 1821 (base::TimeTicks::Now() - touch_press_time_) < | 1837 (base::TimeTicks::Now() - touch_press_time_) < |
| 1822 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1838 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1823 return false; | 1839 return false; |
| 1824 } | 1840 } |
| 1825 | 1841 |
| 1826 return true; | 1842 return true; |
| 1827 } | 1843 } |
| 1828 | 1844 |
| 1829 } // namespace ash | 1845 } // namespace ash |
| OLD | NEW |