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" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 views::FocusManager* focus_manager, | 22 views::FocusManager* focus_manager, |
23 ExtensionFilter extension_filter, | 23 ExtensionFilter extension_filter, |
24 Delegate* delegate) | 24 Delegate* delegate) |
25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), | 25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), |
26 profile_(profile), | 26 profile_(profile), |
27 focus_manager_(focus_manager) { | 27 focus_manager_(focus_manager) { |
28 Init(); | 28 Init(); |
29 } | 29 } |
30 | 30 |
31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { | 31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { |
32 EventTargets::const_iterator iter; | 32 EventTargets::const_iterator eit; |
33 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) | 33 for (eit = event_targets_.begin(); eit != event_targets_.end(); ++eit) |
34 focus_manager_->UnregisterAccelerator(iter->first, this); | 34 focus_manager_->UnregisterAccelerator(eit->first, this); |
35 | |
36 MediaKeysEventTargets::const_iterator mit; | |
37 for (mit = media_keys_event_targets_.begin(); | |
38 mit != media_keys_event_targets_.end(); | |
39 ++mit) { | |
40 focus_manager_->UnregisterAccelerator(mit->first, this); | |
41 } | |
Finnur
2013/11/12 16:27:54
nit: Single line if clause, you can skip the brace
zhchbin
2013/11/13 05:01:57
Done.
| |
35 } | 42 } |
36 | 43 |
37 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( | 44 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( |
38 const extensions::Extension* extension, | 45 const extensions::Extension* extension, |
39 const std::string& command_name) { | 46 const std::string& command_name) { |
40 // This object only handles named commands, not browser/page actions. | 47 // This object only handles named commands, not browser/page actions. |
41 if (ShouldIgnoreCommand(command_name)) | 48 if (ShouldIgnoreCommand(command_name)) |
42 return; | 49 return; |
43 | 50 |
44 extensions::CommandService* command_service = | 51 extensions::CommandService* command_service = |
45 extensions::CommandService::Get(profile_); | 52 extensions::CommandService::Get(profile_); |
46 // Add all the active keybindings (except page actions and browser actions, | 53 // Add all the active keybindings (except page actions and browser actions, |
47 // which are handled elsewhere). | 54 // which are handled elsewhere). |
48 extensions::CommandMap commands; | 55 extensions::CommandMap commands; |
49 if (!command_service->GetNamedCommands( | 56 if (!command_service->GetNamedCommands( |
50 extension->id(), | 57 extension->id(), |
51 extensions::CommandService::ACTIVE_ONLY, | 58 extensions::CommandService::ACTIVE_ONLY, |
52 extensions::CommandService::REGULAR, | 59 extensions::CommandService::REGULAR, |
53 &commands)) | 60 &commands)) |
54 return; | 61 return; |
55 extensions::CommandMap::const_iterator iter = commands.begin(); | 62 extensions::CommandMap::const_iterator iter = commands.begin(); |
56 for (; iter != commands.end(); ++iter) { | 63 for (; iter != commands.end(); ++iter) { |
57 if (!command_name.empty() && (iter->second.command_name() != command_name)) | 64 if (!command_name.empty() && (iter->second.command_name() != command_name)) |
58 continue; | 65 continue; |
59 | 66 |
60 event_targets_[iter->second.accelerator()] = | 67 if (extensions::CommandService::IsMediaKey(iter->second.accelerator())) { |
61 std::make_pair(extension->id(), iter->second.command_name()); | 68 std::pair<std::string, std::string> target = |
69 std::make_pair(extension->id(), iter->second.command_name()); | |
70 media_keys_event_targets_[iter->second.accelerator()].push_back(target); | |
71 } else { | |
72 event_targets_[iter->second.accelerator()] = | |
73 std::make_pair(extension->id(), iter->second.command_name()); | |
74 } | |
62 focus_manager_->RegisterAccelerator( | 75 focus_manager_->RegisterAccelerator( |
63 iter->second.accelerator(), | 76 iter->second.accelerator(), |
64 ui::AcceleratorManager::kHighPriority, this); | 77 ui::AcceleratorManager::kHighPriority, this); |
65 } | 78 } |
66 } | 79 } |
67 | 80 |
68 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( | 81 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( |
69 const ui::Accelerator& accelerator, | 82 const ui::Accelerator& accelerator, |
70 const std::string& command_name) { | 83 const std::string& command_name) { |
71 focus_manager_->UnregisterAccelerator(accelerator, this); | 84 focus_manager_->UnregisterAccelerator(accelerator, this); |
72 } | 85 } |
73 | 86 |
74 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( | 87 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( |
75 const ui::Accelerator& accelerator) { | 88 const ui::Accelerator& accelerator) { |
76 EventTargets::iterator it = event_targets_.find(accelerator); | 89 return ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator( |
77 if (it == event_targets_.end()) { | 90 accelerator); |
Finnur
2013/11/12 16:27:54
It is good to consolidate this in the base class.
| |
78 NOTREACHED(); // Shouldn't get this event for something not registered. | |
79 return false; | |
80 } | |
81 | |
82 CommandExecuted(it->second.first, it->second.second); | |
83 | |
84 return true; | |
85 } | 91 } |
86 | 92 |
87 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { | 93 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { |
88 return true; | 94 return true; |
89 } | 95 } |
OLD | NEW |