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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 case TYPE_UNDEFINED: | 458 case TYPE_UNDEFINED: |
458 NOTREACHED() << "ShelfItemType must be set."; | 459 NOTREACHED() << "ShelfItemType must be set."; |
459 break; | 460 break; |
460 } | 461 } |
461 | 462 |
462 const int64_t display_id = | 463 const int64_t display_id = |
463 display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); | 464 display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); |
464 | 465 |
465 // Notify the item of its selection; handle the result in AfterItemSelected. | 466 // Notify the item of its selection; handle the result in AfterItemSelected. |
466 const ShelfItem& item = model_->items()[last_pressed_index_]; | 467 const ShelfItem& item = model_->items()[last_pressed_index_]; |
468 // Mash requires conversion of mouse and touch events to pointer events. | |
469 std::unique_ptr<ui::Event> passed_event = ui::Event::Clone(event); | |
470 if (Shell::GetAshConfig() == Config::MASH && | |
471 ui::PointerEvent::CanConvertFrom(event)) { | |
472 if (event.IsMouseEvent()) | |
473 passed_event = base::MakeUnique<ui::PointerEvent>(*event.AsMouseEvent()); | |
474 else if (event.IsTouchEvent()) | |
475 passed_event = base::MakeUnique<ui::PointerEvent>(*event.AsTouchEvent()); | |
476 else | |
477 NOTREACHED() << "Need conversion of event to pointer event."; | |
478 } | |
467 model_->GetShelfItemDelegate(item.id)->ItemSelected( | 479 model_->GetShelfItemDelegate(item.id)->ItemSelected( |
468 ui::Event::Clone(event), display_id, LAUNCH_FROM_UNKNOWN, | 480 ui::Event::Clone(*passed_event), display_id, LAUNCH_FROM_UNKNOWN, |
James Cook
2017/05/30 22:47:47
Can you avoid cloning the event twice? Maybe move
msw
2017/05/31 16:55:21
Done. This miserable client code is a sign of poor
| |
469 base::Bind(&ShelfView::AfterItemSelected, weak_factory_.GetWeakPtr(), | 481 base::Bind(&ShelfView::AfterItemSelected, weak_factory_.GetWeakPtr(), |
470 item, sender, base::Passed(ui::Event::Clone(event)), | 482 item, sender, base::Passed(ui::Event::Clone(*passed_event)), |
471 ink_drop)); | 483 ink_drop)); |
472 } | 484 } |
473 | 485 |
474 //////////////////////////////////////////////////////////////////////////////// | 486 //////////////////////////////////////////////////////////////////////////////// |
475 // ShelfView, FocusTraversable implementation: | 487 // ShelfView, FocusTraversable implementation: |
476 | 488 |
477 views::FocusSearch* ShelfView::GetFocusSearch() { | 489 views::FocusSearch* ShelfView::GetFocusSearch() { |
478 return focus_search_.get(); | 490 return focus_search_.get(); |
479 } | 491 } |
480 | 492 |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1589 void ShelfView::ShelfItemMoved(int start_index, int target_index) { | 1601 void ShelfView::ShelfItemMoved(int start_index, int target_index) { |
1590 view_model_->Move(start_index, target_index); | 1602 view_model_->Move(start_index, target_index); |
1591 // When cancelling a drag due to a shelf item being added, the currently | 1603 // When cancelling a drag due to a shelf item being added, the currently |
1592 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1604 // dragged item is moved back to its initial position. AnimateToIdealBounds |
1593 // will be called again when the new item is added to the |view_model_| but | 1605 // will be called again when the new item is added to the |view_model_| but |
1594 // at this time the |view_model_| is inconsistent with the |model_|. | 1606 // at this time the |view_model_| is inconsistent with the |model_|. |
1595 if (!cancelling_drag_model_changed_) | 1607 if (!cancelling_drag_model_changed_) |
1596 AnimateToIdealBounds(); | 1608 AnimateToIdealBounds(); |
1597 } | 1609 } |
1598 | 1610 |
1611 void ShelfView::ShelfItemDelegateChanged(const ShelfID& id, | |
1612 ShelfItemDelegate* delegate) {} | |
1613 | |
1599 void ShelfView::AfterItemSelected( | 1614 void ShelfView::AfterItemSelected( |
1600 const ShelfItem& item, | 1615 const ShelfItem& item, |
1601 views::Button* sender, | 1616 views::Button* sender, |
1602 std::unique_ptr<ui::Event> event, | 1617 std::unique_ptr<ui::Event> event, |
1603 views::InkDrop* ink_drop, | 1618 views::InkDrop* ink_drop, |
1604 ShelfAction action, | 1619 ShelfAction action, |
1605 base::Optional<std::vector<mojom::MenuItemPtr>> menu_items) { | 1620 base::Optional<std::vector<mojom::MenuItemPtr>> menu_items) { |
1606 shelf_button_pressed_metric_tracker_.ButtonPressed(*event, sender, action); | 1621 shelf_button_pressed_metric_tracker_.ButtonPressed(*event, sender, action); |
1607 | 1622 |
1608 // The app list handles its own ink drop effect state changes. | 1623 // The app list handles its own ink drop effect state changes. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1822 if (pointer == TOUCH && | 1837 if (pointer == TOUCH && |
1823 (base::TimeTicks::Now() - touch_press_time_) < | 1838 (base::TimeTicks::Now() - touch_press_time_) < |
1824 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1839 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
1825 return false; | 1840 return false; |
1826 } | 1841 } |
1827 | 1842 |
1828 return true; | 1843 return true; |
1829 } | 1844 } |
1830 | 1845 |
1831 } // namespace ash | 1846 } // namespace ash |
OLD | NEW |