| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // Ignore if this is a repost event on the last pressed shelf item. | 665 // Ignore if this is a repost event on the last pressed shelf item. |
| 666 int index = view_model_->GetIndexOfView(view); | 666 int index = view_model_->GetIndexOfView(view); |
| 667 if (index == -1) | 667 if (index == -1) |
| 668 return false; | 668 return false; |
| 669 return !IsRepostEvent(event) || last_pressed_index_ != index; | 669 return !IsRepostEvent(event) || last_pressed_index_ != index; |
| 670 } | 670 } |
| 671 | 671 |
| 672 void ShelfView::PointerPressedOnButton(views::View* view, | 672 void ShelfView::PointerPressedOnButton(views::View* view, |
| 673 Pointer pointer, | 673 Pointer pointer, |
| 674 const ui::LocatedEvent& event) { | 674 const ui::LocatedEvent& event) { |
| 675 if (IsShowingMenu()) |
| 676 launcher_menu_runner_->Cancel(); |
| 675 if (drag_view_) | 677 if (drag_view_) |
| 676 return; | 678 return; |
| 677 | 679 |
| 678 int index = view_model_->GetIndexOfView(view); | 680 int index = view_model_->GetIndexOfView(view); |
| 679 if (index == -1 || view_model_->view_size() <= 1) | 681 if (index == -1 || view_model_->view_size() <= 1) |
| 680 return; // View is being deleted, ignore request. | 682 return; // View is being deleted, ignore request. |
| 681 | 683 |
| 682 if (view == GetAppListButton()) | 684 if (view == GetAppListButton()) |
| 683 return; // View is not draggable, ignore request. | 685 return; // View is not draggable, ignore request. |
| 684 | 686 |
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 } | 1728 } |
| 1727 } | 1729 } |
| 1728 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed. | 1730 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed. |
| 1729 if (!IsShowingMenu()) | 1731 if (!IsShowingMenu()) |
| 1730 scoped_root_window_for_new_windows_.reset(); | 1732 scoped_root_window_for_new_windows_.reset(); |
| 1731 } | 1733 } |
| 1732 | 1734 |
| 1733 void ShelfView::AfterGetContextMenuItems( | 1735 void ShelfView::AfterGetContextMenuItems( |
| 1734 const ShelfID& shelf_id, | 1736 const ShelfID& shelf_id, |
| 1735 const gfx::Point& point, | 1737 const gfx::Point& point, |
| 1738 views::View* source, |
| 1736 ui::MenuSourceType source_type, | 1739 ui::MenuSourceType source_type, |
| 1737 std::vector<mojom::MenuItemPtr> menu_items) { | 1740 std::vector<mojom::MenuItemPtr> menu_items) { |
| 1738 context_menu_id_ = shelf_id; | 1741 context_menu_id_ = shelf_id; |
| 1739 const int64_t display_id = GetDisplayIdForView(this); | 1742 const int64_t display_id = GetDisplayIdForView(this); |
| 1740 ShowMenu(base::MakeUnique<ShelfContextMenuModel>( | 1743 ShowMenu(base::MakeUnique<ShelfContextMenuModel>( |
| 1741 std::move(menu_items), model_->GetShelfItemDelegate(shelf_id), | 1744 std::move(menu_items), model_->GetShelfItemDelegate(shelf_id), |
| 1742 display_id), | 1745 display_id), |
| 1743 nullptr /* source */, point, true /* context_menu */, source_type, | 1746 source, point, true /* context_menu */, source_type, |
| 1744 nullptr /* ink_drop */); | 1747 nullptr /* ink_drop */); |
| 1745 } | 1748 } |
| 1746 | 1749 |
| 1747 void ShelfView::ShowContextMenuForView(views::View* source, | 1750 void ShelfView::ShowContextMenuForView(views::View* source, |
| 1748 const gfx::Point& point, | 1751 const gfx::Point& point, |
| 1749 ui::MenuSourceType source_type) { | 1752 ui::MenuSourceType source_type) { |
| 1750 gfx::Point context_menu_point = point; | 1753 gfx::Point context_menu_point = point; |
| 1751 aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); | 1754 aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); |
| 1752 | 1755 |
| 1753 // Align the context menu to the edge of the shelf for touch events. | 1756 // Align the context menu to the edge of the shelf for touch events. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1781 ShowMenu(base::MakeUnique<ShelfContextMenuModel>( | 1784 ShowMenu(base::MakeUnique<ShelfContextMenuModel>( |
| 1782 std::vector<mojom::MenuItemPtr>(), nullptr, display_id), | 1785 std::vector<mojom::MenuItemPtr>(), nullptr, display_id), |
| 1783 source, context_menu_point, true, source_type, nullptr); | 1786 source, context_menu_point, true, source_type, nullptr); |
| 1784 return; | 1787 return; |
| 1785 } | 1788 } |
| 1786 | 1789 |
| 1787 // Get any custom entries; show the context menu in AfterGetContextMenuItems. | 1790 // Get any custom entries; show the context menu in AfterGetContextMenuItems. |
| 1788 model_->GetShelfItemDelegate(item->id)->GetContextMenuItems( | 1791 model_->GetShelfItemDelegate(item->id)->GetContextMenuItems( |
| 1789 display_id, base::Bind(&ShelfView::AfterGetContextMenuItems, | 1792 display_id, base::Bind(&ShelfView::AfterGetContextMenuItems, |
| 1790 weak_factory_.GetWeakPtr(), item->id, | 1793 weak_factory_.GetWeakPtr(), item->id, |
| 1791 context_menu_point, source_type)); | 1794 context_menu_point, source, source_type)); |
| 1792 } | 1795 } |
| 1793 | 1796 |
| 1794 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, | 1797 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, |
| 1795 views::View* source, | 1798 views::View* source, |
| 1796 const gfx::Point& click_point, | 1799 const gfx::Point& click_point, |
| 1797 bool context_menu, | 1800 bool context_menu, |
| 1798 ui::MenuSourceType source_type, | 1801 ui::MenuSourceType source_type, |
| 1799 views::InkDrop* ink_drop) { | 1802 views::InkDrop* ink_drop) { |
| 1800 menu_model_ = std::move(menu_model); | 1803 menu_model_ = std::move(menu_model); |
| 1801 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1804 menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 1802 menu_model_.get(), | 1805 menu_model_.get(), |
| 1803 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1806 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
| 1804 | 1807 |
| 1805 closing_event_time_ = base::TimeTicks(); | 1808 closing_event_time_ = base::TimeTicks(); |
| 1806 int run_types = 0; | 1809 int run_types = 0; |
| 1807 if (context_menu) | 1810 if (context_menu) |
| 1808 run_types |= | 1811 run_types |= |
| 1809 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; | 1812 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; |
| 1813 |
| 1814 // Selected shelf items with context menu opened can only be dragged if the |
| 1815 // shelf is not in auto-hide. |
| 1816 const ShelfItem* item = ShelfItemForView(source); |
| 1817 if (context_menu && item && item->type != TYPE_APP_LIST && |
| 1818 shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { |
| 1819 run_types |= views::MenuRunner::SEND_GESTURE_EVENTS_TO_OWNER; |
| 1820 } |
| 1821 |
| 1810 launcher_menu_runner_.reset( | 1822 launcher_menu_runner_.reset( |
| 1811 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1823 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
| 1812 | 1824 |
| 1813 // Place new windows on the same display as the button that spawned the menu. | 1825 // Place new windows on the same display as the button that spawned the menu. |
| 1814 aura::Window* window = GetWidget()->GetNativeWindow(); | 1826 aura::Window* window = GetWidget()->GetNativeWindow(); |
| 1815 scoped_root_window_for_new_windows_.reset( | 1827 scoped_root_window_for_new_windows_.reset( |
| 1816 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1828 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 1817 | 1829 |
| 1818 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1830 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| 1819 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1831 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 } | 1865 } |
| 1854 | 1866 |
| 1855 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1867 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| 1856 launcher_menu_runner_->RunMenuAt(GetWidget(), nullptr, anchor, menu_alignment, | 1868 launcher_menu_runner_->RunMenuAt(GetWidget(), nullptr, anchor, menu_alignment, |
| 1857 source_type); | 1869 source_type); |
| 1858 } | 1870 } |
| 1859 | 1871 |
| 1860 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1872 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
| 1861 context_menu_id_ = ShelfID(); | 1873 context_menu_id_ = ShelfID(); |
| 1862 | 1874 |
| 1863 // Hide the hide overflow bubble after showing a context menu for its items. | |
| 1864 if (owner_overflow_bubble_) | |
| 1865 owner_overflow_bubble_->Hide(); | |
| 1866 | |
| 1867 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1875 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1868 | 1876 |
| 1869 if (ink_drop) | 1877 if (ink_drop) |
| 1870 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | 1878 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); |
| 1871 | 1879 |
| 1872 launcher_menu_runner_.reset(); | 1880 launcher_menu_runner_.reset(); |
| 1873 menu_model_adapter_.reset(); | 1881 menu_model_adapter_.reset(); |
| 1874 menu_model_.reset(); | 1882 menu_model_.reset(); |
| 1875 scoped_root_window_for_new_windows_.reset(); | 1883 scoped_root_window_for_new_windows_.reset(); |
| 1876 | 1884 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 if (pointer == TOUCH && | 1957 if (pointer == TOUCH && |
| 1950 (base::TimeTicks::Now() - touch_press_time_) < | 1958 (base::TimeTicks::Now() - touch_press_time_) < |
| 1951 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1959 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1952 return false; | 1960 return false; |
| 1953 } | 1961 } |
| 1954 | 1962 |
| 1955 return true; | 1963 return true; |
| 1956 } | 1964 } |
| 1957 | 1965 |
| 1958 } // namespace ash | 1966 } // namespace ash |
| OLD | NEW |