Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: ash/shelf/shelf_view.cc

Issue 2861873002: Align the base of the shelf's context menu to the top edge of the shelf. (Closed)
Patch Set: Rebased and adressed comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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())
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(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 break; 1724 break;
1703 case SHELF_ALIGNMENT_LEFT: 1725 case SHELF_ALIGNMENT_LEFT:
1704 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT; 1726 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT;
1705 break; 1727 break;
1706 case SHELF_ALIGNMENT_RIGHT: 1728 case SHELF_ALIGNMENT_RIGHT:
1707 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT; 1729 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT;
1708 break; 1730 break;
1709 } 1731 }
1710 } 1732 }
1711 1733
1734 // Distinguish the touch events that triggered on the bottom shelf or
1735 // left / right shelf. Since they should have different |MenuAnchorPosition|.
1736 if (source_type == ui::MENU_SOURCE_TOUCH) {
1737 if (wm_shelf_->IsHorizontalAlignment())
1738 source_type = ui::MENU_SOURCE_TOUCH_BOTTOM_ANCHOR;
1739 else
1740 source_type = ui::MENU_SOURCE_TOUCH_SIDE_ANCHOR;
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698