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/shelf_item_delegate.h" | 12 #include "ash/public/cpp/shelf_item_delegate.h" |
13 #include "ash/scoped_root_window_for_new_windows.h" | 13 #include "ash/scoped_root_window_for_new_windows.h" |
14 #include "ash/screen_util.h" | |
14 #include "ash/shelf/app_list_button.h" | 15 #include "ash/shelf/app_list_button.h" |
15 #include "ash/shelf/overflow_bubble.h" | 16 #include "ash/shelf/overflow_bubble.h" |
16 #include "ash/shelf/overflow_bubble_view.h" | 17 #include "ash/shelf/overflow_bubble_view.h" |
17 #include "ash/shelf/overflow_button.h" | 18 #include "ash/shelf/overflow_button.h" |
18 #include "ash/shelf/shelf_application_menu_model.h" | 19 #include "ash/shelf/shelf_application_menu_model.h" |
19 #include "ash/shelf/shelf_button.h" | 20 #include "ash/shelf/shelf_button.h" |
20 #include "ash/shelf/shelf_constants.h" | 21 #include "ash/shelf/shelf_constants.h" |
21 #include "ash/shelf/shelf_model.h" | 22 #include "ash/shelf/shelf_model.h" |
22 #include "ash/shelf/shelf_widget.h" | 23 #include "ash/shelf/shelf_widget.h" |
23 #include "ash/shelf/wm_shelf.h" | 24 #include "ash/shelf/wm_shelf.h" |
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1632 } | 1633 } |
1633 } | 1634 } |
1634 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed. | 1635 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed. |
1635 if (!IsShowingMenu()) | 1636 if (!IsShowingMenu()) |
1636 scoped_root_window_for_new_windows_.reset(); | 1637 scoped_root_window_for_new_windows_.reset(); |
1637 } | 1638 } |
1638 | 1639 |
1639 void ShelfView::ShowContextMenuForView(views::View* source, | 1640 void ShelfView::ShowContextMenuForView(views::View* source, |
1640 const gfx::Point& point, | 1641 const gfx::Point& point, |
1641 ui::MenuSourceType source_type) { | 1642 ui::MenuSourceType source_type) { |
1643 // Align the context menu to the edge of the shelf. | |
1644 aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); | |
1645 gfx::Rect shelf_bounds = | |
1646 is_overflow_mode() | |
1647 ? (owner_overflow_bubble_->bubble_view()->GetBubbleBounds()) | |
msw
2017/05/10 22:18:22
nit: extra parens not needed here or on the next l
msw
2017/05/11 17:13:39
Just FYI, I would appreciate it if you respond to
| |
1648 : (ScreenUtil::GetDisplayBoundsWithShelf(shelf_window)); | |
1649 | |
1650 gfx::Point context_menu_point; | |
1651 switch (wm_shelf_->GetAlignment()) { | |
1652 case SHELF_ALIGNMENT_BOTTOM: | |
1653 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | |
1654 context_menu_point.SetPoint(point.x(), | |
1655 shelf_bounds.bottom() - kShelfSize); | |
1656 break; | |
1657 case SHELF_ALIGNMENT_LEFT: | |
1658 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); | |
1659 break; | |
1660 case SHELF_ALIGNMENT_RIGHT: | |
1661 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); | |
1662 break; | |
1663 } | |
1642 last_pressed_index_ = -1; | 1664 last_pressed_index_ = -1; |
1643 | 1665 |
1644 const ShelfItem* item = ShelfItemForView(source); | 1666 const ShelfItem* item = ShelfItemForView(source); |
1645 if (!item) { | 1667 if (!item) { |
1646 ShellPort::Get()->ShowContextMenu(point, source_type); | 1668 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); |
1647 return; | 1669 return; |
1648 } | 1670 } |
1649 | 1671 |
1650 std::unique_ptr<ui::MenuModel> context_menu_model( | 1672 std::unique_ptr<ui::MenuModel> context_menu_model( |
1651 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); | 1673 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); |
1652 if (!context_menu_model) | 1674 if (!context_menu_model) |
1653 return; | 1675 return; |
1654 | 1676 |
1655 context_menu_id_ = item ? item->id : ShelfID(); | 1677 context_menu_id_ = item ? item->id : ShelfID(); |
1656 ShowMenu(std::move(context_menu_model), source, point, true, source_type, | 1678 ShowMenu(std::move(context_menu_model), source, context_menu_point, true, |
1657 nullptr); | 1679 source_type, nullptr); |
1658 } | 1680 } |
1659 | 1681 |
1660 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, | 1682 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, |
1661 views::View* source, | 1683 views::View* source, |
1662 const gfx::Point& click_point, | 1684 const gfx::Point& click_point, |
1663 bool context_menu, | 1685 bool context_menu, |
1664 ui::MenuSourceType source_type, | 1686 ui::MenuSourceType source_type, |
1665 views::InkDrop* ink_drop) { | 1687 views::InkDrop* ink_drop) { |
1666 menu_model_ = std::move(menu_model); | 1688 menu_model_ = std::move(menu_model); |
1667 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1689 menu_model_adapter_.reset(new views::MenuModelAdapter( |
1668 menu_model_.get(), | 1690 menu_model_.get(), |
1669 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1691 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
1670 | 1692 |
1671 closing_event_time_ = base::TimeTicks(); | 1693 closing_event_time_ = base::TimeTicks(); |
1672 int run_types = 0; | 1694 int run_types = 0; |
1673 if (context_menu) | 1695 if (context_menu) |
1674 run_types |= views::MenuRunner::CONTEXT_MENU; | 1696 run_types |= |
1697 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::SHELF_CONTEXT_MENU; | |
1675 launcher_menu_runner_.reset( | 1698 launcher_menu_runner_.reset( |
1676 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1699 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
1677 | 1700 |
1678 // Place new windows on the same display as the button that spawned the menu. | 1701 // Place new windows on the same display as the button that spawned the menu. |
1679 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); | 1702 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); |
1680 scoped_root_window_for_new_windows_.reset( | 1703 scoped_root_window_for_new_windows_.reset( |
1681 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1704 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
1682 | 1705 |
1683 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1706 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
1684 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1707 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
(...skipping 17 matching lines...) Expand all Loading... | |
1702 break; | 1725 break; |
1703 case SHELF_ALIGNMENT_LEFT: | 1726 case SHELF_ALIGNMENT_LEFT: |
1704 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT; | 1727 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT; |
1705 break; | 1728 break; |
1706 case SHELF_ALIGNMENT_RIGHT: | 1729 case SHELF_ALIGNMENT_RIGHT: |
1707 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT; | 1730 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT; |
1708 break; | 1731 break; |
1709 } | 1732 } |
1710 } | 1733 } |
1711 | 1734 |
1735 // Distinguish the touch events that triggered on the bottom shelf or | |
msw
2017/05/10 22:18:22
Should this be clobbering the |menu_alignment| val
minch1
2017/05/11 16:34:02
Oh, here will reassign the menu_alignment if |if(!
msw
2017/05/11 17:13:39
aside: it'd be nice if UX wanted both menus to loo
| |
1736 // left / right shelf. Since they should have different |MenuAnchorPosition|. | |
1737 if (wm_shelf_->IsHorizontalAlignment()) | |
1738 menu_alignment = views::MENU_ANCHOR_FIXED_BOTTOMCENTER; | |
1739 else | |
1740 menu_alignment = views::MENU_ANCHOR_SIDECENTER; | |
1741 | |
1712 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1742 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
1713 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, | 1743 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
1714 menu_alignment, source_type); | 1744 menu_alignment, source_type); |
1715 } | 1745 } |
1716 | 1746 |
1717 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1747 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
1718 context_menu_id_ = ShelfID(); | 1748 context_menu_id_ = ShelfID(); |
1719 | 1749 |
1720 // Hide the hide overflow bubble after showing a context menu for its items. | 1750 // Hide the hide overflow bubble after showing a context menu for its items. |
1721 if (owner_overflow_bubble_) | 1751 if (owner_overflow_bubble_) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 // Bail if dragging has already begun, or if no item has been pressed. | 1818 // Bail if dragging has already begun, or if no item has been pressed. |
1789 if (dragging() || !drag_view_) | 1819 if (dragging() || !drag_view_) |
1790 return false; | 1820 return false; |
1791 | 1821 |
1792 // Dragging only begins once the pointer has travelled a minimum distance. | 1822 // Dragging only begins once the pointer has travelled a minimum distance. |
1793 if ((std::abs(event.x() - drag_origin_.x()) < kMinimumDragDistance) && | 1823 if ((std::abs(event.x() - drag_origin_.x()) < kMinimumDragDistance) && |
1794 (std::abs(event.y() - drag_origin_.y()) < kMinimumDragDistance)) { | 1824 (std::abs(event.y() - drag_origin_.y()) < kMinimumDragDistance)) { |
1795 return false; | 1825 return false; |
1796 } | 1826 } |
1797 | 1827 |
1798 // Touch dragging only begins after a dealy from the press event. This | 1828 // Touch dragging only begins after a delay from the press event. This |
1799 // prevents accidental dragging on swipe or scroll gestures. | 1829 // prevents accidental dragging on swipe or scroll gestures. |
1800 if (pointer == TOUCH && | 1830 if (pointer == TOUCH && |
1801 (base::TimeTicks::Now() - touch_press_time_) < | 1831 (base::TimeTicks::Now() - touch_press_time_) < |
1802 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1832 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
1803 return false; | 1833 return false; |
1804 } | 1834 } |
1805 | 1835 |
1806 return true; | 1836 return true; |
1807 } | 1837 } |
1808 | 1838 |
1809 } // namespace ash | 1839 } // namespace ash |
OLD | NEW |