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/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/extensions/accelerator_priority.h" | 10 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
11 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
12 #include "ui/views/focus/focus_manager.h" | 12 #include "ui/views/focus/focus_manager.h" |
13 | 13 |
14 // static | |
15 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( | |
16 bool suspended) { | |
17 views::FocusManager::set_shortcut_handling_suspended(suspended); | |
18 } | |
19 | |
20 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( | 14 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( |
21 Profile* profile, | 15 Profile* profile, |
22 views::FocusManager* focus_manager, | 16 views::FocusManager* focus_manager, |
23 ExtensionFilter extension_filter, | 17 ExtensionFilter extension_filter, |
24 Delegate* delegate) | 18 Delegate* delegate) |
25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), | 19 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), |
26 profile_(profile), | 20 profile_(profile), |
27 focus_manager_(focus_manager) { | 21 focus_manager_(focus_manager) { |
28 Init(); | 22 Init(); |
23 focus_manager->AddAcceleratorPreProcessor(this); | |
Devlin
2015/01/09 17:09:26
This is somewhat less definitive than the old impl
| |
29 } | 24 } |
30 | 25 |
31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { | 26 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { |
27 focus_manager_->RemoveAcceleratorProcessor(this); | |
32 focus_manager_->UnregisterAccelerators(this); | 28 focus_manager_->UnregisterAccelerators(this); |
33 } | 29 } |
34 | 30 |
35 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( | 31 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( |
36 const extensions::Extension* extension, | 32 const extensions::Extension* extension, |
37 const std::string& command_name) { | 33 const std::string& command_name) { |
38 // This object only handles named commands, not browser/page actions. | 34 // This object only handles named commands, not browser/page actions. |
39 if (ShouldIgnoreCommand(command_name)) | 35 if (ShouldIgnoreCommand(command_name)) |
40 return; | 36 return; |
41 | 37 |
(...skipping 21 matching lines...) Expand all Loading... | |
63 AddEventTarget(accelerator, extension->id(), iter->second.command_name()); | 59 AddEventTarget(accelerator, extension->id(), iter->second.command_name()); |
64 } | 60 } |
65 } | 61 } |
66 | 62 |
67 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( | 63 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( |
68 const ui::Accelerator& accelerator, | 64 const ui::Accelerator& accelerator, |
69 const std::string& command_name) { | 65 const std::string& command_name) { |
70 focus_manager_->UnregisterAccelerator(accelerator, this); | 66 focus_manager_->UnregisterAccelerator(accelerator, this); |
71 } | 67 } |
72 | 68 |
69 bool ExtensionKeybindingRegistryViews::ProcessAccelerator( | |
70 const ui::Accelerator& accelerator) { | |
71 // Consume the accelerator if shortcut handling is suspended. | |
72 return IsShortcutHandlingSuspended(); | |
73 } | |
74 | |
75 ui::AcceleratorTarget* | |
76 ExtensionKeybindingRegistryViews::GetTargetForAccelerator( | |
77 const ui::Accelerator& accelerator) const { | |
78 return nullptr; | |
79 } | |
80 | |
73 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( | 81 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( |
74 const ui::Accelerator& accelerator) { | 82 const ui::Accelerator& accelerator) { |
75 std::string extension_id, command_name; | 83 std::string extension_id, command_name; |
76 GetFirstTarget(accelerator, &extension_id, &command_name); | 84 GetFirstTarget(accelerator, &extension_id, &command_name); |
77 const ui::AcceleratorManager::HandlerPriority priority = | 85 const ui::AcceleratorManager::HandlerPriority priority = |
78 GetAcceleratorPriorityById(accelerator, extension_id, browser_context()); | 86 GetAcceleratorPriorityById(accelerator, extension_id, browser_context()); |
79 // Normal priority shortcuts must be handled via standard browser commands to | 87 // Normal priority shortcuts must be handled via standard browser commands to |
80 // be processed at the proper time. | 88 // be processed at the proper time. |
81 return (priority == ui::AcceleratorManager::kHighPriority) && | 89 return (priority == ui::AcceleratorManager::kHighPriority) && |
82 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 90 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
83 } | 91 } |
84 | 92 |
85 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { | 93 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { |
86 return true; | 94 return true; |
87 } | 95 } |
OLD | NEW |