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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 // Ignore if this is a repost event on the last pressed shelf item. | 633 // Ignore if this is a repost event on the last pressed shelf item. |
| 634 int index = view_model_->GetIndexOfView(view); | 634 int index = view_model_->GetIndexOfView(view); |
| 635 if (index == -1) | 635 if (index == -1) |
| 636 return false; | 636 return false; |
| 637 return !IsRepostEvent(event) || last_pressed_index_ != index; | 637 return !IsRepostEvent(event) || last_pressed_index_ != index; |
| 638 } | 638 } |
| 639 | 639 |
| 640 void ShelfView::PointerPressedOnButton(views::View* view, | 640 void ShelfView::PointerPressedOnButton(views::View* view, |
| 641 Pointer pointer, | 641 Pointer pointer, |
| 642 const ui::LocatedEvent& event) { | 642 const ui::LocatedEvent& event) { |
| 643 if (IsShowingMenu()) | |
| 644 launcher_menu_runner_->Cancel(); | |
| 643 if (drag_view_) | 645 if (drag_view_) |
| 644 return; | 646 return; |
| 645 | 647 |
| 646 int index = view_model_->GetIndexOfView(view); | 648 int index = view_model_->GetIndexOfView(view); |
| 647 if (index == -1 || view_model_->view_size() <= 1) | 649 if (index == -1 || view_model_->view_size() <= 1) |
| 648 return; // View is being deleted, ignore request. | 650 return; // View is being deleted, ignore request. |
| 649 | 651 |
| 650 if (view == GetAppListButton()) | 652 if (view == GetAppListButton()) |
| 651 return; // View is not draggable, ignore request. | 653 return; // View is not draggable, ignore request. |
| 652 | 654 |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 break; | 1651 break; |
| 1650 case SHELF_ALIGNMENT_RIGHT: | 1652 case SHELF_ALIGNMENT_RIGHT: |
| 1651 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, | 1653 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, |
| 1652 point.y()); | 1654 point.y()); |
| 1653 break; | 1655 break; |
| 1654 } | 1656 } |
| 1655 } | 1657 } |
| 1656 last_pressed_index_ = -1; | 1658 last_pressed_index_ = -1; |
| 1657 | 1659 |
| 1658 const ShelfItem* item = ShelfItemForView(source); | 1660 const ShelfItem* item = ShelfItemForView(source); |
| 1659 if (!item) { | 1661 if (!item || item->type == TYPE_APP_LIST) { |
| 1660 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); | 1662 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); |
| 1661 return; | 1663 return; |
| 1662 } | 1664 } |
| 1663 | 1665 |
| 1664 std::unique_ptr<ui::MenuModel> context_menu_model( | 1666 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1665 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item)); | 1667 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item)); |
| 1666 if (!context_menu_model) | 1668 if (!context_menu_model) |
| 1667 return; | 1669 return; |
| 1668 | 1670 |
| 1669 context_menu_id_ = item ? item->id : ShelfID(); | 1671 context_menu_id_ = item ? item->id : ShelfID(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1680 menu_model_ = std::move(menu_model); | 1682 menu_model_ = std::move(menu_model); |
| 1681 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1683 menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 1682 menu_model_.get(), | 1684 menu_model_.get(), |
| 1683 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1685 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
| 1684 | 1686 |
| 1685 closing_event_time_ = base::TimeTicks(); | 1687 closing_event_time_ = base::TimeTicks(); |
| 1686 int run_types = 0; | 1688 int run_types = 0; |
| 1687 if (context_menu) | 1689 if (context_menu) |
| 1688 run_types |= | 1690 run_types |= |
| 1689 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; | 1691 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; |
| 1692 | |
| 1693 // Shelf items can only be dragged if the shelf is not autohide. | |
|
msw
2017/06/01 20:24:27
repeated nit: s/autohide/in auto-hide/ (or 'is not
minch1
2017/06/23 23:13:02
Done.
| |
| 1694 if (shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) | |
| 1695 run_types |= views::MenuRunner::PRESERVE_CURRENT_GESTURE_FOR_OWNER; | |
| 1696 | |
| 1690 launcher_menu_runner_.reset( | 1697 launcher_menu_runner_.reset( |
| 1691 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1698 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
| 1692 | 1699 |
| 1693 // Place new windows on the same display as the button that spawned the menu. | 1700 // Place new windows on the same display as the button that spawned the menu. |
| 1694 aura::Window* window = source->GetWidget()->GetNativeWindow(); | 1701 aura::Window* window = source->GetWidget()->GetNativeWindow(); |
| 1695 scoped_root_window_for_new_windows_.reset( | 1702 scoped_root_window_for_new_windows_.reset( |
| 1696 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1703 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 1697 | 1704 |
| 1698 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1705 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| 1699 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1706 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1732 } | 1739 } |
| 1733 | 1740 |
| 1734 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1741 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| 1735 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, | 1742 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
| 1736 menu_alignment, source_type); | 1743 menu_alignment, source_type); |
| 1737 } | 1744 } |
| 1738 | 1745 |
| 1739 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1746 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
| 1740 context_menu_id_ = ShelfID(); | 1747 context_menu_id_ = ShelfID(); |
| 1741 | 1748 |
| 1742 // Hide the hide overflow bubble after showing a context menu for its items. | |
| 1743 if (owner_overflow_bubble_) | |
| 1744 owner_overflow_bubble_->Hide(); | |
| 1745 | |
| 1746 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1749 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1747 | 1750 |
| 1748 if (ink_drop) | 1751 if (ink_drop) |
| 1749 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | 1752 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); |
| 1750 | 1753 |
| 1751 launcher_menu_runner_.reset(); | 1754 launcher_menu_runner_.reset(); |
| 1752 menu_model_adapter_.reset(); | 1755 menu_model_adapter_.reset(); |
| 1753 menu_model_.reset(); | 1756 menu_model_.reset(); |
| 1754 scoped_root_window_for_new_windows_.reset(); | 1757 scoped_root_window_for_new_windows_.reset(); |
| 1755 | 1758 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 if (pointer == TOUCH && | 1825 if (pointer == TOUCH && |
| 1823 (base::TimeTicks::Now() - touch_press_time_) < | 1826 (base::TimeTicks::Now() - touch_press_time_) < |
| 1824 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1827 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1825 return false; | 1828 return false; |
| 1826 } | 1829 } |
| 1827 | 1830 |
| 1828 return true; | 1831 return true; |
| 1829 } | 1832 } |
| 1830 | 1833 |
| 1831 } // namespace ash | 1834 } // namespace ash |
| OLD | NEW |