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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 void View::ResetAccelerators() { 1139 void View::ResetAccelerators() {
1140 if (accelerators_.get()) 1140 if (accelerators_.get())
1141 UnregisterAccelerators(false); 1141 UnregisterAccelerators(false);
1142 } 1142 }
1143 1143
1144 bool View::AcceleratorPressed(const ui::Accelerator& accelerator) { 1144 bool View::AcceleratorPressed(const ui::Accelerator& accelerator) {
1145 return false; 1145 return false;
1146 } 1146 }
1147 1147
1148 bool View::CanHandleAccelerators() const { 1148 bool View::CanHandleAccelerators() const {
1149 return enabled() && IsDrawn() && GetWidget() && GetWidget()->IsVisible(); 1149 const Widget* widget = GetWidget();
1150 if (!enabled() || !IsDrawn() || !widget || !widget->IsVisible()) {
1151 return false;
1152 }
1153 #if !defined(OS_CHROMEOS)
1154 // Should only handle accelerators when active. However, only top level
1155 // widgets can be active, so for child widgets check if they are focused
1156 // instead. This check is disabled on ChromeOS as ChromeOS already handles
1157 // this logic properly.
1158 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.
1159 (!IsChildWidget() && !widget->IsActive())) {
1160 return false;
1161 }
1162 #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
1163 return true;
1150 } 1164 }
1151 1165
1152 // Focus ----------------------------------------------------------------------- 1166 // Focus -----------------------------------------------------------------------
1153 1167
1154 bool View::HasFocus() const { 1168 bool View::HasFocus() const {
1155 const FocusManager* focus_manager = GetFocusManager(); 1169 const FocusManager* focus_manager = GetFocusManager();
1156 return focus_manager && (focus_manager->GetFocusedView() == this); 1170 return focus_manager && (focus_manager->GetFocusedView() == this);
1157 } 1171 }
1158 1172
1159 View* View::GetNextFocusableView() { 1173 View* View::GetNextFocusableView() {
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 2417
2404 // Message the RootView to do the drag and drop. That way if we're removed 2418 // Message the RootView to do the drag and drop. That way if we're removed
2405 // the RootView can detect it and avoid calling us back. 2419 // the RootView can detect it and avoid calling us back.
2406 gfx::Point widget_location(event.location()); 2420 gfx::Point widget_location(event.location());
2407 ConvertPointToWidget(this, &widget_location); 2421 ConvertPointToWidget(this, &widget_location);
2408 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2422 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2409 // WARNING: we may have been deleted. 2423 // WARNING: we may have been deleted.
2410 return true; 2424 return true;
2411 } 2425 }
2412 2426
2427 bool View::IsChildWidget() const {
2428 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget();
2429 }
2430
2431 bool View::FocusInChildWidget() const {
2432 return GetWidget() &&
2433 GetWidget()->GetRootView()->Contains(
2434 GetFocusManager()->GetFocusedView());
2435 }
2436
2413 } // namespace views 2437 } // namespace views
OLDNEW
« 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