Commit 82eb4a31 authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[Dice] Adjust submenu positioning on Mac

The accounts submenu positioning has to be
adjusted because native combobox menus on
Mac are always TOPLEFT aligned.

Screenshots:
https://drive.google.com/file/d/1yibhKX3giSaMrXaDXfEyQM99MAwIg2RF/view?usp=sharing
https://drive.google.com/file/d/14k2wIXyL37IPSQm0jNt9zj9ePZXBXZB-/view?usp=sharing

Bug: 813805
Change-Id: I04c60167f0123a320c10e579b77e834bc63a0b6f
Reviewed-on: https://chromium-review.googlesource.com/959321
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542783}
parent 0f8d1fe0
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/profiles/dice_accounts_menu.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -92,13 +93,25 @@ void DiceAccountsMenu::Show(views::View* anchor_view) {
// Calculate custom anchor bounds to position the menu.
// The menu is aligned along the right edge (left edge in RTL mode) of the
// anchor, slightly shifted inside by |kAnchorInset| and overlapping
// |anchor_view| on the bottom by |kAnchorInset|. |anchor_bounds|' width is
// set to 0 so that the menu only is as wide as it needs to be.
// |anchor_view| on the bottom by |kAnchorInset|. |anchor_bounds| is collapsed
// so the menu only takes the width it needs.
gfx::Rect anchor_bounds = anchor_view->GetBoundsInScreen();
anchor_bounds.Inset(
base::i18n::IsRTL() ? kAnchorInset : anchor_bounds.width() - kAnchorInset,
kAnchorInset, 0, kAnchorInset);
anchor_bounds.set_width(0);
anchor_bounds.Inset(kAnchorInset, kAnchorInset);
#if defined(OS_MACOSX)
// On Mac, menus align to the left of the anchor, so collapse the right side
// of the rect.
bool collapse_right = true;
#else
bool collapse_right = false;
#endif
if (base::i18n::IsRTL())
collapse_right = !collapse_right;
if (collapse_right)
anchor_bounds.Inset(0, 0, anchor_bounds.width(), 0);
else
anchor_bounds.Inset(anchor_bounds.width(), 0, 0, 0);
runner_->RunMenuAt(anchor_view->GetWidget(), nullptr, anchor_bounds,
views::MENU_ANCHOR_TOPRIGHT, ui::MENU_SOURCE_MOUSE);
}
......
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