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

Unified Diff: ui/views/view.cc

Issue 1544803004: Fix accelerator handling for in-menu buttons in the app menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable the check on ChromeOS (again). Accelerator handling in extension popups is different betwee… Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/button/custom_button_unittest.cc ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view.cc
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 45467ab23dbfc0fdbf68fdd9ad1ef9532bd20e64..62ab2b1ba7ad7bfca29723305d9a7ecdbba12094 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -1146,7 +1146,25 @@ bool View::AcceleratorPressed(const ui::Accelerator& accelerator) {
}
bool View::CanHandleAccelerators() const {
- return enabled() && IsDrawn() && GetWidget() && GetWidget()->IsVisible();
+ const Widget* widget = GetWidget();
+ if (!enabled() || !IsDrawn() || !widget || !widget->IsVisible())
+ return false;
+#if defined(USE_AURA) && !defined(OS_CHROMEOS)
+ // Non-ChromeOS aura windows have an associated FocusManagerEventHandler which
+ // adds currently focused view as an event PreTarget (see
+ // DesktopNativeWidgetAura::InitNativeWidget). However, the focused view isn't
+ // always the right view to handle accelerators: It should only handle them
+ // when active. Only top level widgets can be active, so for child widgets
+ // check if they are focused instead. ChromeOS also behaves different than
+ // Linux when an extension popup is about to handle the accelerator.
+ bool child = widget && widget->GetTopLevelWidget() != widget;
+ bool focus_in_child =
+ widget &&
+ widget->GetRootView()->Contains(GetFocusManager()->GetFocusedView());
+ if ((child && !focus_in_child) || (!child && !widget->IsActive()))
+ return false;
+#endif
+ return true;
}
// Focus -----------------------------------------------------------------------
« no previous file with comments | « ui/views/controls/button/custom_button_unittest.cc ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698