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

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: nits. 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
« no previous file with comments | « no previous file | chrome/browser/ui/window_sizer/window_sizer_ash_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 } 1625 }
1625 } 1626 }
1626 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed. 1627 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed.
1627 if (!IsShowingMenu()) 1628 if (!IsShowingMenu())
1628 scoped_root_window_for_new_windows_.reset(); 1629 scoped_root_window_for_new_windows_.reset();
1629 } 1630 }
1630 1631
1631 void ShelfView::ShowContextMenuForView(views::View* source, 1632 void ShelfView::ShowContextMenuForView(views::View* source,
1632 const gfx::Point& point, 1633 const gfx::Point& point,
1633 ui::MenuSourceType source_type) { 1634 ui::MenuSourceType source_type) {
1635 // Align the context menu to the edge of the shelf.
1636 aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
1637 gfx::Rect shelf_bounds =
1638 is_overflow_mode()
1639 ? owner_overflow_bubble_->bubble_view()->GetBubbleBounds()
1640 : ScreenUtil::GetDisplayBoundsWithShelf(shelf_window);
1641
1642 gfx::Point context_menu_point;
1643 switch (wm_shelf_->GetAlignment()) {
1644 case SHELF_ALIGNMENT_BOTTOM:
1645 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
1646 context_menu_point.SetPoint(point.x(),
1647 shelf_bounds.bottom() - kShelfSize);
1648 break;
1649 case SHELF_ALIGNMENT_LEFT:
1650 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y());
1651 break;
1652 case SHELF_ALIGNMENT_RIGHT:
1653 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y());
1654 break;
1655 }
1634 last_pressed_index_ = -1; 1656 last_pressed_index_ = -1;
1635 1657
1636 const ShelfItem* item = ShelfItemForView(source); 1658 const ShelfItem* item = ShelfItemForView(source);
1637 if (!item) { 1659 if (!item) {
1638 ShellPort::Get()->ShowContextMenu(point, source_type); 1660 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type);
1639 return; 1661 return;
1640 } 1662 }
1641 1663
1642 std::unique_ptr<ui::MenuModel> context_menu_model( 1664 std::unique_ptr<ui::MenuModel> context_menu_model(
1643 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); 1665 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item));
1644 if (!context_menu_model) 1666 if (!context_menu_model)
1645 return; 1667 return;
1646 1668
1647 context_menu_id_ = item ? item->id : ShelfID(); 1669 context_menu_id_ = item ? item->id : ShelfID();
1648 ShowMenu(std::move(context_menu_model), source, point, true, source_type, 1670 ShowMenu(std::move(context_menu_model), source, context_menu_point, true,
1649 nullptr); 1671 source_type, nullptr);
1650 } 1672 }
1651 1673
1652 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, 1674 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model,
1653 views::View* source, 1675 views::View* source,
1654 const gfx::Point& click_point, 1676 const gfx::Point& click_point,
1655 bool context_menu, 1677 bool context_menu,
1656 ui::MenuSourceType source_type, 1678 ui::MenuSourceType source_type,
1657 views::InkDrop* ink_drop) { 1679 views::InkDrop* ink_drop) {
1658 menu_model_ = std::move(menu_model); 1680 menu_model_ = std::move(menu_model);
1659 menu_model_adapter_.reset(new views::MenuModelAdapter( 1681 menu_model_adapter_.reset(new views::MenuModelAdapter(
1660 menu_model_.get(), 1682 menu_model_.get(),
1661 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); 1683 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop)));
1662 1684
1663 closing_event_time_ = base::TimeTicks(); 1685 closing_event_time_ = base::TimeTicks();
1664 int run_types = 0; 1686 int run_types = 0;
1665 if (context_menu) 1687 if (context_menu)
1666 run_types |= views::MenuRunner::CONTEXT_MENU; 1688 run_types |=
1689 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR;
1667 launcher_menu_runner_.reset( 1690 launcher_menu_runner_.reset(
1668 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); 1691 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types));
1669 1692
1670 // Place new windows on the same display as the button that spawned the menu. 1693 // Place new windows on the same display as the button that spawned the menu.
1671 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); 1694 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow());
1672 scoped_root_window_for_new_windows_.reset( 1695 scoped_root_window_for_new_windows_.reset(
1673 new ScopedRootWindowForNewWindows(window->GetRootWindow())); 1696 new ScopedRootWindowForNewWindows(window->GetRootWindow()));
1674 1697
1675 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; 1698 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT;
1676 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); 1699 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size());
(...skipping 15 matching lines...) Expand all
1692 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 1715 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
1693 menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE; 1716 menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE;
1694 break; 1717 break;
1695 case SHELF_ALIGNMENT_LEFT: 1718 case SHELF_ALIGNMENT_LEFT:
1696 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT; 1719 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT;
1697 break; 1720 break;
1698 case SHELF_ALIGNMENT_RIGHT: 1721 case SHELF_ALIGNMENT_RIGHT:
1699 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT; 1722 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT;
1700 break; 1723 break;
1701 } 1724 }
1725 } else {
1726 // Distinguish the touch events that triggered on the bottom or left / right
1727 // shelf. Since they should have different |MenuAnchorPosition|.
1728 if (wm_shelf_->IsHorizontalAlignment())
1729 menu_alignment = views::MENU_ANCHOR_FIXED_BOTTOMCENTER;
1730 else
1731 menu_alignment = views::MENU_ANCHOR_FIXED_SIDECENTER;
1702 } 1732 }
1703 1733
1704 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. 1734 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code.
1705 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, 1735 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor,
1706 menu_alignment, source_type); 1736 menu_alignment, source_type);
1707 } 1737 }
1708 1738
1709 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { 1739 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) {
1710 context_menu_id_ = ShelfID(); 1740 context_menu_id_ = ShelfID();
1711 1741
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 // Bail if dragging has already begun, or if no item has been pressed. 1810 // Bail if dragging has already begun, or if no item has been pressed.
1781 if (dragging() || !drag_view_) 1811 if (dragging() || !drag_view_)
1782 return false; 1812 return false;
1783 1813
1784 // Dragging only begins once the pointer has travelled a minimum distance. 1814 // Dragging only begins once the pointer has travelled a minimum distance.
1785 if ((std::abs(event.x() - drag_origin_.x()) < kMinimumDragDistance) && 1815 if ((std::abs(event.x() - drag_origin_.x()) < kMinimumDragDistance) &&
1786 (std::abs(event.y() - drag_origin_.y()) < kMinimumDragDistance)) { 1816 (std::abs(event.y() - drag_origin_.y()) < kMinimumDragDistance)) {
1787 return false; 1817 return false;
1788 } 1818 }
1789 1819
1790 // Touch dragging only begins after a dealy from the press event. This 1820 // Touch dragging only begins after a delay from the press event. This
1791 // prevents accidental dragging on swipe or scroll gestures. 1821 // prevents accidental dragging on swipe or scroll gestures.
1792 if (pointer == TOUCH && 1822 if (pointer == TOUCH &&
1793 (base::TimeTicks::Now() - touch_press_time_) < 1823 (base::TimeTicks::Now() - touch_press_time_) <
1794 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { 1824 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) {
1795 return false; 1825 return false;
1796 } 1826 }
1797 1827
1798 return true; 1828 return true;
1799 } 1829 }
1800 1830
1801 } // namespace ash 1831 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/window_sizer/window_sizer_ash_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698