diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 06:24:46 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 06:24:46 +0000 |
commit | 37ea9a6d57233773d2a5daeab5ac44d14aa93882 (patch) | |
tree | 8a7edf93ee80fe0fff5af7e44f322c6dce7bfef3 /ui/views | |
parent | 3ef3607d8621f5a75dd7475012ff8d2f6c432cbf (diff) | |
download | chromium_src-37ea9a6d57233773d2a5daeab5ac44d14aa93882.zip chromium_src-37ea9a6d57233773d2a5daeab5ac44d14aa93882.tar.gz chromium_src-37ea9a6d57233773d2a5daeab5ac44d14aa93882.tar.bz2 |
Clamp keyboard context menu locations to visible ancestor areas.
Previously, the menu could anchor outside an ancestor view.
See before/after pics at http://crbug.com/330496
BUG=330496
TEST=Keyboard-triggered context menus (via the Menu key or Shift+F10) show in reasonable locations.
R=sky@chromium.org
Review URL: https://codereview.chromium.org/179053002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253377 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/widget/root_view.cc | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index f4b7a43..2e4ea9e 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -117,20 +117,18 @@ void RootView::DispatchKeyEvent(ui::KeyEvent* event) { View* v = NULL; if (GetFocusManager()) // NULL in unittests. v = GetFocusManager()->GetFocusedView(); - // Special case to handle right-click context menus triggered by the - // keyboard. + // Special case to handle keyboard-triggered context menus. if (v && v->enabled() && ((event->key_code() == ui::VKEY_APPS) || (event->key_code() == ui::VKEY_F10 && event->IsShiftDown()))) { - // Showing the context menu outside the visible bounds may result in a - // context menu appearing over a completely different window. Constrain - // location to visible bounds so this doesn't happen. - gfx::Rect visible_bounds(v->ConvertRectToWidget(v->GetVisibleBounds())); - visible_bounds.Offset( - widget_->GetClientAreaBoundsInScreen().OffsetFromOrigin()); - gfx::Rect keyboard_loc(v->GetKeyboardContextMenuLocation(), - gfx::Size(1, 1)); - keyboard_loc.AdjustToFit(visible_bounds); - v->ShowContextMenu(keyboard_loc.origin(), ui::MENU_SOURCE_KEYBOARD); + // Clamp the menu location within the visible bounds of each ancestor view + // to avoid showing the menu over a completely different view or window. + gfx::Point location = v->GetKeyboardContextMenuLocation(); + for (View* parent = v->parent(); parent; parent = parent->parent()) { + const gfx::Rect& parent_bounds = parent->GetBoundsInScreen(); + location.SetToMax(parent_bounds.origin()); + location.SetToMin(parent_bounds.bottom_right()); + } + v->ShowContextMenu(location, ui::MENU_SOURCE_KEYBOARD); event->StopPropagation(); return; } |