Commit df1012dd authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: don't allow bookmark menus to be repositioned next to the anchor

Doing this prevents easy "scrubbing" through the bookmark bar menus, since the
newly-appearing menu draws over the top of the adjacent bookmark buttons.

Bug: 902344
Change-Id: Ief783f4b417810416821b717f92f796b4e6b07e6
Reviewed-on: https://chromium-review.googlesource.com/c/1335870
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608049}
parent 41a5f8f5
...@@ -188,6 +188,13 @@ void BookmarkMenuController::BookmarkModelChanged() { ...@@ -188,6 +188,13 @@ void BookmarkMenuController::BookmarkModelChanged() {
menu()->Cancel(); menu()->Cancel();
} }
bool BookmarkMenuController::ShouldTryPositioningBesideAnchor() const {
// The bookmark menu appears from the bookmark bar, which has a set of buttons positioned next to
// each other; if the bookmark menu appears beside its anchor button, it will likely overlay the
// adjacent bookmark button, which prevents easy scrubbing through the bookmark bar's menus.
return false;
}
BookmarkMenuController::~BookmarkMenuController() { BookmarkMenuController::~BookmarkMenuController() {
menu_delegate_->GetBookmarkModel()->RemoveObserver(this); menu_delegate_->GetBookmarkModel()->RemoveObserver(this);
if (observer_) if (observer_)
......
...@@ -114,6 +114,7 @@ class BookmarkMenuController : public bookmarks::BaseBookmarkModelObserver, ...@@ -114,6 +114,7 @@ class BookmarkMenuController : public bookmarks::BaseBookmarkModelObserver,
views::MenuButton** button) override; views::MenuButton** button) override;
int GetMaxWidthForMenu(views::MenuItemView* view) override; int GetMaxWidthForMenu(views::MenuItemView* view) override;
void WillShowMenu(views::MenuItemView* menu) override; void WillShowMenu(views::MenuItemView* menu) override;
bool ShouldTryPositioningBesideAnchor() const override;
// bookmarks::BaseBookmarkModelObserver: // bookmarks::BaseBookmarkModelObserver:
void BookmarkModelChanged() override; void BookmarkModelChanged() override;
......
...@@ -2156,7 +2156,7 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, ...@@ -2156,7 +2156,7 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item,
// Menu fits above anchor bounds. // Menu fits above anchor bounds.
menu_bounds.set_y(above_anchor); menu_bounds.set_y(above_anchor);
item->set_actual_menu_position(MenuItemView::POSITION_ABOVE_BOUNDS); item->set_actual_menu_position(MenuItemView::POSITION_ABOVE_BOUNDS);
} else { } else if (item->GetDelegate()->ShouldTryPositioningBesideAnchor()) {
const int left_of_anchor = anchor_bounds.x() - menu_bounds.width(); const int left_of_anchor = anchor_bounds.x() - menu_bounds.width();
const int right_of_anchor = anchor_bounds.right(); const int right_of_anchor = anchor_bounds.right();
...@@ -2174,6 +2174,11 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, ...@@ -2174,6 +2174,11 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item,
if (menu_bounds.x() < monitor_bounds.x()) if (menu_bounds.x() < monitor_bounds.x())
menu_bounds.set_x(right_of_anchor); menu_bounds.set_x(right_of_anchor);
} }
} else {
// The delegate doesn't want the menu repositioned to the side, and it
// doesn't fit on the screen in any orientation - just clip the menu to
// the screen and let the scrolling arrows appear.
menu_bounds.Intersect(monitor_bounds);
} }
} }
......
...@@ -152,4 +152,8 @@ bool MenuDelegate::ShouldReserveSpaceForSubmenuIndicator() const { ...@@ -152,4 +152,8 @@ bool MenuDelegate::ShouldReserveSpaceForSubmenuIndicator() const {
return true; return true;
} }
bool MenuDelegate::ShouldTryPositioningBesideAnchor() const {
return true;
}
} // namespace views } // namespace views
...@@ -233,6 +233,11 @@ class VIEWS_EXPORT MenuDelegate { ...@@ -233,6 +233,11 @@ class VIEWS_EXPORT MenuDelegate {
// Returns true if the labels should reserve additional spacing for e.g. // Returns true if the labels should reserve additional spacing for e.g.
// submenu indicators at the end of the line. // submenu indicators at the end of the line.
virtual bool ShouldReserveSpaceForSubmenuIndicator() const; virtual bool ShouldReserveSpaceForSubmenuIndicator() const;
// Returns true if menus should fall back to positioning beside the anchor,
// rather than directly above or below it, when the menu is too tall to fit
// within the screen.
virtual bool ShouldTryPositioningBesideAnchor() const;
}; };
} // namespace views } // namespace views
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment