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

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: Add back the unit test, disable logic on ChromeOS Created 4 years, 11 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
Index: ui/views/view.cc
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 45467ab23dbfc0fdbf68fdd9ad1ef9532bd20e64..9232987ea608bec2b6b593c9d2da9977f4d11dbb 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -1146,7 +1146,21 @@ 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(OS_CHROMEOS)
+ // Should only handle accelerators when active. However, only top level
+ // widgets can be active, so for child widgets check if they are focused
+ // instead. This check is disabled on ChromeOS as ChromeOS already handles
+ // this logic properly.
+ if ((IsChildWidget() && !FocusInChildWidget()) ||
sky 2016/01/28 16:23:45 I wouldn't bother with the new functions, instead:
meacer 2016/01/28 18:39:26 This was so that I could override them in unit tes
meacer 2016/01/29 00:37:36 Done now.
+ (!IsChildWidget() && !widget->IsActive())) {
+ return false;
+ }
+ #endif
sadrul 2016/01/28 08:11:00 I don't think this behaviour should be OS specific
meacer 2016/01/28 18:39:26 Sure, but ChromeOS seems to handle accelerators fi
sky 2016/01/28 21:18:38 What I don't understand is how this works in chrom
meacer 2016/01/29 00:14:22 For the original bug (https://crbug.com/541415): t
+ return true;
}
// Focus -----------------------------------------------------------------------
@@ -2410,4 +2424,14 @@ bool View::DoDrag(const ui::LocatedEvent& event,
return true;
}
+bool View::IsChildWidget() const {
+ return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget();
+}
+
+bool View::FocusInChildWidget() const {
+ return GetWidget() &&
+ GetWidget()->GetRootView()->Contains(
+ GetFocusManager()->GetFocusedView());
+}
+
} // namespace views
« ui/views/view.h ('K') | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698