Chromium Code Reviews| 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" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 void ShelfView::Init() { | 411 void ShelfView::Init() { |
| 412 model_->AddObserver(this); | 412 model_->AddObserver(this); |
| 413 | 413 |
| 414 const ShelfItems& items(model_->items()); | 414 const ShelfItems& items(model_->items()); |
| 415 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 415 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
| 416 views::View* child = CreateViewForItem(*i); | 416 views::View* child = CreateViewForItem(*i); |
| 417 child->SetPaintToLayer(true); | 417 child->SetPaintToLayer(true); |
| 418 view_model_->Add(child, static_cast<int>(i - items.begin())); | 418 view_model_->Add(child, static_cast<int>(i - items.begin())); |
| 419 AddChildView(child); | 419 AddChildView(child); |
| 420 } | 420 } |
| 421 overflow_button_ = new OverflowButton(this, shelf_); | 421 overflow_button_ = new OverflowButton(this); |
| 422 overflow_button_->set_context_menu_controller(this); | 422 overflow_button_->set_context_menu_controller(this); |
| 423 ConfigureChildView(overflow_button_); | 423 ConfigureChildView(overflow_button_); |
| 424 AddChildView(overflow_button_); | 424 AddChildView(overflow_button_); |
| 425 | 425 |
| 426 // We'll layout when our bounds change. | 426 // We'll layout when our bounds change. |
| 427 } | 427 } |
| 428 | 428 |
| 429 void ShelfView::OnShelfAlignmentChanged() { | 429 void ShelfView::OnShelfAlignmentChanged() { |
| 430 overflow_button_->OnShelfAlignmentChanged(); | 430 overflow_button_->OnShelfAlignmentChanged(); |
| 431 LayoutToIdealBounds(); | 431 LayoutToIdealBounds(); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 // to animate back to its correct location. | 706 // to animate back to its correct location. |
| 707 AnimateToIdealBounds(); | 707 AnimateToIdealBounds(); |
| 708 } else { | 708 } else { |
| 709 drag_and_drop_view->SetSize(pre_drag_and_drop_size_); | 709 drag_and_drop_view->SetSize(pre_drag_and_drop_size_); |
| 710 } | 710 } |
| 711 } | 711 } |
| 712 | 712 |
| 713 drag_and_drop_shelf_id_ = 0; | 713 drag_and_drop_shelf_id_ = 0; |
| 714 } | 714 } |
| 715 | 715 |
| 716 bool ShelfView::WillIgnoreEventOnButton(View* view, const ui::Event& event) { | |
| 717 if (dragging()) | |
| 718 return true; | |
| 719 | |
| 720 // Ignore if we are already in a pointer event sequence started with a repost | |
| 721 // event. | |
| 722 if (is_repost_event_) | |
|
bruthig
2016/06/09 03:26:00
The interplay of |is_repost_event_|, |last_pressed
mohsen
2016/06/09 21:24:51
Probably, similar names of |is_repost_event_| and
bruthig
2016/06/10 15:25:19
Definitely looks better!
| |
| 723 return true; | |
| 724 | |
| 725 if (event.flags() & ui::EF_IS_DOUBLE_CLICK) | |
| 726 return true; | |
| 727 | |
| 728 // Ignore if this is a repost event on the last pressed shelf item. | |
| 729 int index = view_model_->GetIndexOfView(view); | |
| 730 if (index == -1) | |
| 731 return true; | |
| 732 return IsRepostEvent(event) && (last_pressed_index_ == index); | |
| 733 } | |
| 734 | |
| 716 void ShelfView::PointerPressedOnButton(views::View* view, | 735 void ShelfView::PointerPressedOnButton(views::View* view, |
| 717 Pointer pointer, | 736 Pointer pointer, |
| 718 const ui::LocatedEvent& event) { | 737 const ui::LocatedEvent& event) { |
| 719 if (drag_view_) | 738 if (drag_view_) |
| 720 return; | 739 return; |
| 721 | 740 |
| 722 int index = view_model_->GetIndexOfView(view); | 741 int index = view_model_->GetIndexOfView(view); |
| 723 if (index == -1) | 742 if (index == -1 || view_model_->view_size() <= 1) |
| 724 return; | 743 return; // View is being deleted, ignore request. |
| 725 | 744 |
| 726 ShelfItemDelegate* item_delegate = | 745 ShelfItemDelegate* item_delegate = |
| 727 item_manager_->GetShelfItemDelegate(model_->items()[index].id); | 746 item_manager_->GetShelfItemDelegate(model_->items()[index].id); |
| 728 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) | 747 if (!item_delegate->IsDraggable()) |
| 729 return; // View is being deleted or not draggable, ignore request. | 748 return; // View is not draggable, ignore request. |
| 730 | 749 |
| 731 // Only when the repost event occurs on the same shelf item, we should ignore | 750 // Only when the repost event occurs on the same shelf item, we should ignore |
| 732 // the call in ShelfView::ButtonPressed(...). | 751 // the call in ShelfView::ButtonPressed(...). |
| 733 is_repost_event_ = IsRepostEvent(event) && (last_pressed_index_ == index); | 752 is_repost_event_ = IsRepostEvent(event) && (last_pressed_index_ == index); |
| 734 | 753 |
| 735 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); | 754 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); |
| 736 drag_view_ = static_cast<ShelfButton*>(view); | 755 drag_view_ = static_cast<ShelfButton*>(view); |
| 737 drag_origin_ = gfx::Point(event.x(), event.y()); | 756 drag_origin_ = gfx::Point(event.x(), event.y()); |
| 738 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", | 757 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", |
| 739 shelf_->SelectValueForShelfAlignment( | 758 shelf_->SelectValueForShelfAlignment( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 769 FinalizeRipOffDrag(false); | 788 FinalizeRipOffDrag(false); |
| 770 drag_pointer_ = NONE; | 789 drag_pointer_ = NONE; |
| 771 AnimateToIdealBounds(); | 790 AnimateToIdealBounds(); |
| 772 } | 791 } |
| 773 // If the drag pointer is NONE, no drag operation is going on and the | 792 // If the drag pointer is NONE, no drag operation is going on and the |
| 774 // drag_view can be released. | 793 // drag_view can be released. |
| 775 if (drag_pointer_ == NONE) | 794 if (drag_pointer_ == NONE) |
| 776 drag_view_ = nullptr; | 795 drag_view_ = nullptr; |
| 777 } | 796 } |
| 778 | 797 |
| 798 void ShelfView::ButtonPressed(views::Button* sender, | |
| 799 const ui::Event& event, | |
| 800 views::InkDrop* ink_drop) { | |
| 801 if (!ButtonPressedImpl(sender, event, ink_drop) && !is_repost_event_) | |
| 802 ink_drop->AnimateToState(views::InkDropState::HIDDEN); | |
| 803 } | |
| 804 | |
| 779 void ShelfView::LayoutToIdealBounds() { | 805 void ShelfView::LayoutToIdealBounds() { |
| 780 if (bounds_animator_->IsAnimating()) { | 806 if (bounds_animator_->IsAnimating()) { |
| 781 AnimateToIdealBounds(); | 807 AnimateToIdealBounds(); |
| 782 return; | 808 return; |
| 783 } | 809 } |
| 784 | 810 |
| 785 IdealBounds ideal_bounds; | 811 IdealBounds ideal_bounds; |
| 786 CalculateIdealBounds(&ideal_bounds); | 812 CalculateIdealBounds(&ideal_bounds); |
| 787 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 813 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
| 788 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 814 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( | 1063 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( |
| 1038 model_->items()[start_drag_index_].id); | 1064 model_->items()[start_drag_index_].id); |
| 1039 if (!item_delegate->IsDraggable()) { | 1065 if (!item_delegate->IsDraggable()) { |
| 1040 CancelDrag(-1); | 1066 CancelDrag(-1); |
| 1041 return; | 1067 return; |
| 1042 } | 1068 } |
| 1043 | 1069 |
| 1044 // Move the view to the front so that it appears on top of other views. | 1070 // Move the view to the front so that it appears on top of other views. |
| 1045 ReorderChildView(drag_view_, -1); | 1071 ReorderChildView(drag_view_, -1); |
| 1046 bounds_animator_->StopAnimatingView(drag_view_); | 1072 bounds_animator_->StopAnimatingView(drag_view_); |
| 1073 | |
| 1074 drag_view_->OnDragStarted(); | |
| 1047 } | 1075 } |
| 1048 | 1076 |
| 1049 void ShelfView::ContinueDrag(const ui::LocatedEvent& event) { | 1077 void ShelfView::ContinueDrag(const ui::LocatedEvent& event) { |
| 1050 // Due to a syncing operation the application might have been removed. | 1078 // Due to a syncing operation the application might have been removed. |
| 1051 // Bail if it is gone. | 1079 // Bail if it is gone. |
| 1052 int current_index = view_model_->GetIndexOfView(drag_view_); | 1080 int current_index = view_model_->GetIndexOfView(drag_view_); |
| 1053 DCHECK_NE(-1, current_index); | 1081 DCHECK_NE(-1, current_index); |
| 1054 | 1082 |
| 1055 ShelfItemDelegate* item_delegate = | 1083 ShelfItemDelegate* item_delegate = |
| 1056 item_manager_->GetShelfItemDelegate(model_->items()[current_index].id); | 1084 item_manager_->GetShelfItemDelegate(model_->items()[current_index].id); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1389 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) const { | 1417 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) const { |
| 1390 const int first_overflow_index = last_visible_index_ + 1; | 1418 const int first_overflow_index = last_visible_index_ + 1; |
| 1391 const int last_overflow_index = last_hidden_index_; | 1419 const int last_overflow_index = last_hidden_index_; |
| 1392 DCHECK_LE(first_overflow_index, last_overflow_index); | 1420 DCHECK_LE(first_overflow_index, last_overflow_index); |
| 1393 DCHECK_LT(last_overflow_index, view_model_->view_size()); | 1421 DCHECK_LT(last_overflow_index, view_model_->view_size()); |
| 1394 | 1422 |
| 1395 overflow_view->first_visible_index_ = first_overflow_index; | 1423 overflow_view->first_visible_index_ = first_overflow_index; |
| 1396 overflow_view->last_visible_index_ = last_overflow_index; | 1424 overflow_view->last_visible_index_ = last_overflow_index; |
| 1397 } | 1425 } |
| 1398 | 1426 |
| 1427 bool ShelfView::ButtonPressedImpl(views::Button* sender, | |
|
bruthig
2016/06/09 03:25:59
Consider renaming ButtonPressed as ButtonPressedIm
mohsen
2016/06/09 21:24:51
Right. I was trying to keep the ordering suggested
| |
| 1428 const ui::Event& event, | |
| 1429 views::InkDrop* ink_drop) { | |
| 1430 // Do not handle mouse release during drag. | |
|
bruthig
2016/06/09 03:25:59
Would it be possible to replace most of these quic
mohsen
2016/06/09 21:24:51
It was not possible because for the double-click c
| |
| 1431 if (dragging()) | |
| 1432 return false; | |
| 1433 | |
| 1434 if (sender == overflow_button_) { | |
| 1435 ToggleOverflowBubble(); | |
| 1436 shelf_button_pressed_metric_tracker_.ButtonPressed( | |
| 1437 event, sender, ShelfItemDelegate::kNoAction); | |
| 1438 return false; | |
| 1439 } | |
| 1440 | |
| 1441 int view_index = view_model_->GetIndexOfView(sender); | |
| 1442 // May be -1 while in the process of animating closed. | |
| 1443 if (view_index == -1) | |
| 1444 return false; | |
| 1445 | |
| 1446 // If the menu was just closed by the same event as this one, we ignore | |
| 1447 // the call and don't open the menu again. See crbug.com/343005 for more | |
| 1448 // detail. | |
| 1449 if (is_repost_event_) | |
| 1450 return false; | |
| 1451 | |
| 1452 // Record the index for the last pressed shelf item. | |
| 1453 last_pressed_index_ = view_index; | |
| 1454 | |
| 1455 // Don't activate the item twice on double-click. Otherwise the window starts | |
| 1456 // animating open due to the first click, then immediately minimizes due to | |
| 1457 // the second click. The user most likely intended to open or minimize the | |
| 1458 // item once, not do both. | |
| 1459 if (event.flags() & ui::EF_IS_DOUBLE_CLICK) | |
| 1460 return true; | |
|
bruthig
2016/06/09 03:26:00
Shouldn't this be a return false?
mohsen
2016/06/09 21:24:51
The return value of the function means whether the
| |
| 1461 | |
| 1462 { | |
| 1463 ScopedTargetRootWindow scoped_target( | |
| 1464 sender->GetWidget()->GetNativeView()->GetRootWindow()); | |
| 1465 // Slow down activation animations if shift key is pressed. | |
| 1466 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; | |
| 1467 if (event.IsShiftDown()) { | |
| 1468 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( | |
| 1469 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | |
| 1470 } | |
| 1471 | |
| 1472 // Collect usage statistics before we decide what to do with the click. | |
| 1473 switch (model_->items()[view_index].type) { | |
| 1474 case TYPE_APP_SHORTCUT: | |
| 1475 case TYPE_WINDOWED_APP: | |
| 1476 case TYPE_PLATFORM_APP: | |
| 1477 case TYPE_BROWSER_SHORTCUT: | |
| 1478 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 1479 UMA_LAUNCHER_CLICK_ON_APP); | |
| 1480 break; | |
| 1481 | |
| 1482 case TYPE_APP_LIST: | |
| 1483 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 1484 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); | |
| 1485 break; | |
| 1486 | |
| 1487 case TYPE_APP_PANEL: | |
| 1488 case TYPE_DIALOG: | |
| 1489 case TYPE_IME_MENU: | |
| 1490 break; | |
| 1491 | |
| 1492 case TYPE_UNDEFINED: | |
| 1493 NOTREACHED() << "ShelfItemType must be set."; | |
| 1494 break; | |
| 1495 } | |
| 1496 | |
| 1497 ShelfItemDelegate::PerformedAction performed_action = | |
| 1498 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id) | |
| 1499 ->ItemSelected(event); | |
| 1500 | |
| 1501 shelf_button_pressed_metric_tracker_.ButtonPressed(event, sender, | |
| 1502 performed_action); | |
| 1503 | |
| 1504 if (performed_action != ShelfItemDelegate::kNewWindowCreated && | |
| 1505 ShowListMenuForView(model_->items()[view_index], sender, event, | |
| 1506 ink_drop)) { | |
| 1507 // Menu is run synchronously, the menu is closed now and we need to go to | |
| 1508 // the deactivated state. | |
| 1509 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | |
|
bruthig
2016/06/09 03:26:00
It might make sense to put the DEACTIVATED call in
mohsen
2016/06/09 21:24:51
Sure. Done.
| |
| 1510 return true; | |
| 1511 } | |
| 1512 ink_drop->AnimateToState(views::InkDropState::ACTION_TRIGGERED); | |
| 1513 } | |
| 1514 | |
| 1515 return true; | |
| 1516 } | |
| 1517 | |
| 1399 gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() { | 1518 gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() { |
| 1400 gfx::Size preferred_size; | 1519 gfx::Size preferred_size; |
| 1401 if (is_overflow_mode()) { | 1520 if (is_overflow_mode()) { |
| 1402 DCHECK(owner_overflow_bubble_); | 1521 DCHECK(owner_overflow_bubble_); |
| 1403 gfx::Rect bubble_bounds = | 1522 gfx::Rect bubble_bounds = |
| 1404 owner_overflow_bubble_->bubble_view()->GetBubbleBounds(); | 1523 owner_overflow_bubble_->bubble_view()->GetBubbleBounds(); |
| 1405 preferred_size = bubble_bounds.size(); | 1524 preferred_size = bubble_bounds.size(); |
| 1406 } else { | 1525 } else { |
| 1407 const int last_button_index = view_model_->view_size() - 1; | 1526 const int last_button_index = view_model_->view_size() - 1; |
| 1408 gfx::Rect last_button_bounds = | 1527 gfx::Rect last_button_bounds = |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 void ShelfView::ShelfItemMoved(int start_index, int target_index) { | 1779 void ShelfView::ShelfItemMoved(int start_index, int target_index) { |
| 1661 view_model_->Move(start_index, target_index); | 1780 view_model_->Move(start_index, target_index); |
| 1662 // When cancelling a drag due to a shelf item being added, the currently | 1781 // When cancelling a drag due to a shelf item being added, the currently |
| 1663 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1782 // dragged item is moved back to its initial position. AnimateToIdealBounds |
| 1664 // will be called again when the new item is added to the |view_model_| but | 1783 // will be called again when the new item is added to the |view_model_| but |
| 1665 // at this time the |view_model_| is inconsistent with the |model_|. | 1784 // at this time the |view_model_| is inconsistent with the |model_|. |
| 1666 if (!cancelling_drag_model_changed_) | 1785 if (!cancelling_drag_model_changed_) |
| 1667 AnimateToIdealBounds(); | 1786 AnimateToIdealBounds(); |
| 1668 } | 1787 } |
| 1669 | 1788 |
| 1670 void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) { | 1789 bool ShelfView::ShowListMenuForView(const ShelfItem& item, |
| 1671 // Do not handle mouse release during drag. | |
| 1672 if (dragging()) | |
| 1673 return; | |
| 1674 | |
| 1675 if (sender == overflow_button_) { | |
| 1676 ToggleOverflowBubble(); | |
| 1677 shelf_button_pressed_metric_tracker_.ButtonPressed( | |
| 1678 event, sender, ShelfItemDelegate::kNoAction); | |
| 1679 return; | |
| 1680 } | |
| 1681 | |
| 1682 int view_index = view_model_->GetIndexOfView(sender); | |
| 1683 // May be -1 while in the process of animating closed. | |
| 1684 if (view_index == -1) | |
| 1685 return; | |
| 1686 | |
| 1687 // If the menu was just closed by the same event as this one, we ignore | |
| 1688 // the call and don't open the menu again. See crbug.com/343005 for more | |
| 1689 // detail. | |
| 1690 if (is_repost_event_) | |
| 1691 return; | |
| 1692 | |
| 1693 // Record the index for the last pressed shelf item. | |
| 1694 last_pressed_index_ = view_index; | |
| 1695 | |
| 1696 // Don't activate the item twice on double-click. Otherwise the window starts | |
| 1697 // animating open due to the first click, then immediately minimizes due to | |
| 1698 // the second click. The user most likely intended to open or minimize the | |
| 1699 // item once, not do both. | |
| 1700 if (event.flags() & ui::EF_IS_DOUBLE_CLICK) | |
| 1701 return; | |
| 1702 | |
| 1703 { | |
| 1704 ScopedTargetRootWindow scoped_target( | |
| 1705 sender->GetWidget()->GetNativeView()->GetRootWindow()); | |
| 1706 // Slow down activation animations if shift key is pressed. | |
| 1707 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; | |
| 1708 if (event.IsShiftDown()) { | |
| 1709 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( | |
| 1710 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | |
| 1711 } | |
| 1712 | |
| 1713 // Collect usage statistics before we decide what to do with the click. | |
| 1714 switch (model_->items()[view_index].type) { | |
| 1715 case TYPE_APP_SHORTCUT: | |
| 1716 case TYPE_WINDOWED_APP: | |
| 1717 case TYPE_PLATFORM_APP: | |
| 1718 case TYPE_BROWSER_SHORTCUT: | |
| 1719 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 1720 UMA_LAUNCHER_CLICK_ON_APP); | |
| 1721 break; | |
| 1722 | |
| 1723 case TYPE_APP_LIST: | |
| 1724 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 1725 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); | |
| 1726 break; | |
| 1727 | |
| 1728 case TYPE_APP_PANEL: | |
| 1729 case TYPE_DIALOG: | |
| 1730 case TYPE_IME_MENU: | |
| 1731 break; | |
| 1732 | |
| 1733 case TYPE_UNDEFINED: | |
| 1734 NOTREACHED() << "ShelfItemType must be set."; | |
| 1735 break; | |
| 1736 } | |
| 1737 | |
| 1738 ShelfItemDelegate::PerformedAction performed_action = | |
| 1739 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id) | |
| 1740 ->ItemSelected(event); | |
| 1741 | |
| 1742 shelf_button_pressed_metric_tracker_.ButtonPressed(event, sender, | |
| 1743 performed_action); | |
| 1744 | |
| 1745 if (performed_action != ShelfItemDelegate::kNewWindowCreated) | |
| 1746 ShowListMenuForView(model_->items()[view_index], sender, event); | |
| 1747 } | |
| 1748 } | |
| 1749 | |
| 1750 void ShelfView::ShowListMenuForView(const ShelfItem& item, | |
| 1751 views::View* source, | 1790 views::View* source, |
| 1752 const ui::Event& event) { | 1791 const ui::Event& event, |
| 1792 views::InkDrop* ink_drop) { | |
| 1753 ShelfItemDelegate* item_delegate = | 1793 ShelfItemDelegate* item_delegate = |
| 1754 item_manager_->GetShelfItemDelegate(item.id); | 1794 item_manager_->GetShelfItemDelegate(item.id); |
| 1755 std::unique_ptr<ui::MenuModel> list_menu_model( | 1795 std::unique_ptr<ui::MenuModel> list_menu_model( |
| 1756 item_delegate->CreateApplicationMenu(event.flags())); | 1796 item_delegate->CreateApplicationMenu(event.flags())); |
| 1757 | 1797 |
| 1758 // Make sure we have a menu and it has at least two items in addition to the | 1798 // Make sure we have a menu and it has at least two items in addition to the |
| 1759 // application title and the 3 spacing separators. | 1799 // application title and the 3 spacing separators. |
| 1760 if (!list_menu_model.get() || list_menu_model->GetItemCount() <= 5) | 1800 if (!list_menu_model.get() || list_menu_model->GetItemCount() <= 5) |
| 1761 return; | 1801 return false; |
| 1762 | 1802 |
| 1803 ink_drop->AnimateToState(views::InkDropState::ACTIVATED); | |
| 1763 context_menu_id_ = item.id; | 1804 context_menu_id_ = item.id; |
| 1764 ShowMenu(list_menu_model.get(), source, gfx::Point(), false, | 1805 ShowMenu(list_menu_model.get(), source, gfx::Point(), false, |
| 1765 ui::GetMenuSourceTypeForEvent(event)); | 1806 ui::GetMenuSourceTypeForEvent(event)); |
| 1807 return true; | |
| 1766 } | 1808 } |
| 1767 | 1809 |
| 1768 void ShelfView::ShowContextMenuForView(views::View* source, | 1810 void ShelfView::ShowContextMenuForView(views::View* source, |
| 1769 const gfx::Point& point, | 1811 const gfx::Point& point, |
| 1770 ui::MenuSourceType source_type) { | 1812 ui::MenuSourceType source_type) { |
| 1813 last_pressed_index_ = -1; | |
| 1814 | |
| 1771 const ShelfItem* item = ShelfItemForView(source); | 1815 const ShelfItem* item = ShelfItemForView(source); |
| 1772 if (!item) { | 1816 if (!item) { |
| 1773 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1817 Shell::GetInstance()->ShowContextMenu(point, source_type); |
| 1774 return; | 1818 return; |
| 1775 } | 1819 } |
| 1776 | 1820 |
| 1777 std::unique_ptr<ui::MenuModel> context_menu_model( | 1821 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1778 Shell::GetInstance()->delegate()->CreateContextMenu(shelf_, item)); | 1822 Shell::GetInstance()->delegate()->CreateContextMenu(shelf_, item)); |
| 1779 if (!context_menu_model) | 1823 if (!context_menu_model) |
| 1780 return; | 1824 return; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1871 } | 1915 } |
| 1872 } | 1916 } |
| 1873 } | 1917 } |
| 1874 | 1918 |
| 1875 bool ShelfView::IsRepostEvent(const ui::Event& event) { | 1919 bool ShelfView::IsRepostEvent(const ui::Event& event) { |
| 1876 if (closing_event_time_.is_zero()) | 1920 if (closing_event_time_.is_zero()) |
| 1877 return false; | 1921 return false; |
| 1878 | 1922 |
| 1879 base::TimeDelta delta = | 1923 base::TimeDelta delta = |
| 1880 base::TimeDelta(event.time_stamp() - closing_event_time_); | 1924 base::TimeDelta(event.time_stamp() - closing_event_time_); |
| 1881 closing_event_time_ = base::TimeDelta(); | |
| 1882 // If the current (press down) event is a repost event, the time stamp of | 1925 // If the current (press down) event is a repost event, the time stamp of |
| 1883 // these two events should be the same. | 1926 // these two events should be the same. |
| 1884 return (delta.InMilliseconds() == 0); | 1927 return delta.InMilliseconds() == 0; |
| 1885 } | 1928 } |
| 1886 | 1929 |
| 1887 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { | 1930 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { |
| 1888 const int view_index = view_model_->GetIndexOfView(view); | 1931 const int view_index = view_model_->GetIndexOfView(view); |
| 1889 return (view_index < 0) ? nullptr : &(model_->items()[view_index]); | 1932 return (view_index < 0) ? nullptr : &(model_->items()[view_index]); |
| 1890 } | 1933 } |
| 1891 | 1934 |
| 1892 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1935 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1893 const gfx::Rect bounds = GetBoundsInScreen(); | 1936 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1894 int distance = shelf_->SelectValueForShelfAlignment( | 1937 int distance = shelf_->SelectValueForShelfAlignment( |
| 1895 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1938 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1896 bounds.x() - coordinate.x()); | 1939 bounds.x() - coordinate.x()); |
| 1897 return distance > 0 ? distance : 0; | 1940 return distance > 0 ? distance : 0; |
| 1898 } | 1941 } |
| 1899 | 1942 |
| 1900 } // namespace ash | 1943 } // namespace ash |
| OLD | NEW |