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 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/commands/command_service.h" | 7 #include "chrome/browser/extensions/api/commands/command_service.h" |
8 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 8 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
12 #include "ui/views/focus/focus_manager.h" | 12 #include "ui/views/focus/focus_manager.h" |
13 | 13 |
14 #if defined(USE_ASH) | |
15 #include "ash/accelerators/accelerator_table.h" | |
16 #endif // USE_ASH | |
17 | |
18 #if defined(USE_AURA) | |
19 #include "chrome/browser/ui/views/accelerator_table.h" | |
20 #elif defined(OS_WIN) | |
21 #include "chrome/browser/ui/browser_finder.h" | |
22 #include "chrome/browser/ui/views/frame/browser_view.h" | |
23 #endif // USE_AURA | |
24 | |
14 // static | 25 // static |
15 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( | 26 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( |
16 bool suspended) { | 27 bool suspended) { |
17 views::FocusManager::set_shortcut_handling_suspended(suspended); | 28 views::FocusManager::set_shortcut_handling_suspended(suspended); |
18 } | 29 } |
19 | 30 |
31 // static | |
32 bool extensions::ExtensionKeybindingRegistry::IsChromeAccelerator( | |
33 const ui::Accelerator& accelerator, Profile* profile) { | |
34 #if defined(USE_ASH) | |
35 for (size_t i = 0; i < ash::kAcceleratorDataLength; ++i) { | |
36 const ash::AcceleratorData& accel_data = ash::kAcceleratorData[i]; | |
37 if (accel_data.keycode == accelerator.key_code() && | |
38 accel_data.modifiers == accelerator.modifiers()) { | |
39 return true; | |
40 } | |
41 } | |
42 #endif // USE_ASH | |
43 | |
44 #if defined(USE_AURA) | |
45 std::vector<chrome::AcceleratorMapping> accelerators = | |
46 chrome::GetAcceleratorList(); | |
47 for (std::vector<chrome::AcceleratorMapping>::const_iterator it = | |
48 accelerators.begin(); it != accelerators.end(); ++it) { | |
49 if (it->keycode == accelerator.key_code() && | |
50 it->modifiers == accelerator.modifiers()) | |
51 return true; | |
52 } | |
53 #elif defined(OS_WIN) | |
54 Browser* browser = chrome::FindLastActiveWithProfile( | |
sky
2013/04/10 15:34:31
You need to NULL check this.
| |
55 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | |
56 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( | |
57 browser->window()->GetNativeWindow()); | |
58 return browser_view->IsAcceleratorRegistered(accelerator); | |
59 #endif // USE_AURA | |
60 | |
61 return false; | |
62 } | |
63 | |
20 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( | 64 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( |
21 Profile* profile, | 65 Profile* profile, |
22 views::FocusManager* focus_manager, | 66 views::FocusManager* focus_manager, |
23 ExtensionFilter extension_filter, | 67 ExtensionFilter extension_filter, |
24 Delegate* delegate) | 68 Delegate* delegate) |
25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), | 69 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), |
26 profile_(profile), | 70 profile_(profile), |
27 focus_manager_(focus_manager) { | 71 focus_manager_(focus_manager) { |
28 Init(); | 72 Init(); |
29 } | 73 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 137 } |
94 | 138 |
95 CommandExecuted(it->second.first, it->second.second); | 139 CommandExecuted(it->second.first, it->second.second); |
96 | 140 |
97 return true; | 141 return true; |
98 } | 142 } |
99 | 143 |
100 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { | 144 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { |
101 return true; | 145 return true; |
102 } | 146 } |
OLD | NEW |