OLD | NEW |
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 Loading... |
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 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 1153 // Non-ChromeOS aura windows have an associated FocusManagerEventHandler which |
| 1154 // adds currently focused view as an event PreTarget (see |
| 1155 // DesktopNativeWidgetAura::InitNativeWidget). However, the focused view isn't |
| 1156 // always the right view to handle accelerators: It should only handle them |
| 1157 // when active. Only top level widgets can be active, so for child widgets |
| 1158 // check if they are focused instead. ChromeOS also behaves different than |
| 1159 // Linux when an extension popup is about to handle the accelerator. |
| 1160 bool child = widget && widget->GetTopLevelWidget() != widget; |
| 1161 bool focus_in_child = |
| 1162 widget && |
| 1163 widget->GetRootView()->Contains(GetFocusManager()->GetFocusedView()); |
| 1164 if ((child && !focus_in_child) || (!child && !widget->IsActive())) |
| 1165 return false; |
| 1166 #endif |
| 1167 return true; |
1150 } | 1168 } |
1151 | 1169 |
1152 // Focus ----------------------------------------------------------------------- | 1170 // Focus ----------------------------------------------------------------------- |
1153 | 1171 |
1154 bool View::HasFocus() const { | 1172 bool View::HasFocus() const { |
1155 const FocusManager* focus_manager = GetFocusManager(); | 1173 const FocusManager* focus_manager = GetFocusManager(); |
1156 return focus_manager && (focus_manager->GetFocusedView() == this); | 1174 return focus_manager && (focus_manager->GetFocusedView() == this); |
1157 } | 1175 } |
1158 | 1176 |
1159 View* View::GetNextFocusableView() { | 1177 View* View::GetNextFocusableView() { |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2404 // Message the RootView to do the drag and drop. That way if we're removed | 2422 // 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. | 2423 // the RootView can detect it and avoid calling us back. |
2406 gfx::Point widget_location(event.location()); | 2424 gfx::Point widget_location(event.location()); |
2407 ConvertPointToWidget(this, &widget_location); | 2425 ConvertPointToWidget(this, &widget_location); |
2408 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2426 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2409 // WARNING: we may have been deleted. | 2427 // WARNING: we may have been deleted. |
2410 return true; | 2428 return true; |
2411 } | 2429 } |
2412 | 2430 |
2413 } // namespace views | 2431 } // namespace views |
OLD | NEW |