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/gtk/extensions/extension_keybinding_registry_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.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/api/commands/command_service_factory.h" | 8 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
9 #include "chrome/browser/extensions/extension_browser_event_router.h" | 9 #include "chrome/browser/extensions/extension_browser_event_router.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 return FALSE; | 47 return FALSE; |
48 | 48 |
49 ui::AcceleratorGtk accelerator(ui::WindowsKeyCodeForGdkKeyCode(event->keyval), | 49 ui::AcceleratorGtk accelerator(ui::WindowsKeyCodeForGdkKeyCode(event->keyval), |
50 event->state & GDK_SHIFT_MASK, | 50 event->state & GDK_SHIFT_MASK, |
51 event->state & GDK_CONTROL_MASK, | 51 event->state & GDK_CONTROL_MASK, |
52 event->state & GDK_MOD1_MASK); | 52 event->state & GDK_MOD1_MASK); |
53 return event_targets_.find(accelerator) != event_targets_.end(); | 53 return event_targets_.find(accelerator) != event_targets_.end(); |
54 } | 54 } |
55 | 55 |
56 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding( | 56 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding( |
57 const extensions::Extension* extension) { | 57 const extensions::Extension* extension, |
58 const std::string& command_name) { | |
58 extensions::CommandService* command_service = | 59 extensions::CommandService* command_service = |
59 extensions::CommandServiceFactory::GetForProfile(profile_); | 60 extensions::CommandServiceFactory::GetForProfile(profile_); |
60 extensions::CommandMap commands; | 61 extensions::CommandMap commands; |
61 if (!command_service->GetNamedCommands( | 62 if (!command_service->GetNamedCommands( |
62 extension->id(), | 63 extension->id(), |
63 extensions::CommandService::ACTIVE_ONLY, | 64 extensions::CommandService::ACTIVE_ONLY, |
64 &commands)) { | 65 &commands)) { |
65 return; | 66 return; |
66 } | 67 } |
67 | 68 |
68 extensions::CommandMap::const_iterator iter = commands.begin(); | 69 extensions::CommandMap::const_iterator iter = commands.begin(); |
Evan Stade
2012/06/29 18:39:07
this should be inside the for statement
| |
69 for (; iter != commands.end(); ++iter) { | 70 for (; iter != commands.end(); ++iter) { |
71 if (!command_name.empty() && (iter->second.command_name() != command_name)) | |
Yoyo Zhou
2012/06/28 22:40:51
Would it make any sense to do this instead in GetN
Finnur
2012/06/28 22:49:01
Maybe. I'll take a look tomorrow. If it does I mig
| |
72 continue; | |
73 | |
70 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), | 74 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), |
71 iter->second.accelerator().IsShiftDown(), | 75 iter->second.accelerator().IsShiftDown(), |
72 iter->second.accelerator().IsCtrlDown(), | 76 iter->second.accelerator().IsCtrlDown(), |
73 iter->second.accelerator().IsAltDown()); | 77 iter->second.accelerator().IsAltDown()); |
74 event_targets_[accelerator] = | 78 event_targets_[accelerator] = |
75 std::make_pair(extension->id(), iter->second.command_name()); | 79 std::make_pair(extension->id(), iter->second.command_name()); |
76 | 80 |
77 if (!accel_group_) { | 81 if (!accel_group_) { |
78 accel_group_ = gtk_accel_group_new(); | 82 accel_group_ = gtk_accel_group_new(); |
79 gtk_window_add_accel_group(window_, accel_group_); | 83 gtk_window_add_accel_group(window_, accel_group_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 ui::AcceleratorGtk accelerator(page_action.accelerator().key_code(), | 117 ui::AcceleratorGtk accelerator(page_action.accelerator().key_code(), |
114 page_action.accelerator().IsShiftDown(), | 118 page_action.accelerator().IsShiftDown(), |
115 page_action.accelerator().IsCtrlDown(), | 119 page_action.accelerator().IsCtrlDown(), |
116 page_action.accelerator().IsAltDown()); | 120 page_action.accelerator().IsAltDown()); |
117 event_targets_[accelerator] = | 121 event_targets_[accelerator] = |
118 std::make_pair(extension->id(), page_action.command_name()); | 122 std::make_pair(extension->id(), page_action.command_name()); |
119 } | 123 } |
120 } | 124 } |
121 | 125 |
122 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding( | 126 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding( |
123 const extensions::Extension* extension) { | 127 const extensions::Extension* extension, |
128 const std::string& command_name) { | |
124 EventTargets::iterator iter = event_targets_.begin(); | 129 EventTargets::iterator iter = event_targets_.begin(); |
125 while (iter != event_targets_.end()) { | 130 while (iter != event_targets_.end()) { |
126 if (iter->second.first != extension->id()) { | 131 if (iter->second.first != extension->id() || |
132 (!command_name.empty() && (iter->second.second != command_name))) { | |
Evan Stade
2012/06/29 18:39:07
don't need these parens around the != clause
| |
127 ++iter; | 133 ++iter; |
128 continue; // Not the extension we asked for. | 134 continue; // Not the extension or command we asked for. |
129 } | 135 } |
130 | 136 |
131 // On GTK, unlike Windows, the Event Targets contain all events but we must | 137 // On GTK, unlike Windows, the Event Targets contain all events but we must |
132 // only unregister the ones we own. | 138 // only unregister the ones we own. |
133 if (ShouldIgnoreCommand(iter->second.second)) { | 139 if (ShouldIgnoreCommand(iter->second.second)) { |
134 ++iter; | 140 ++iter; |
135 continue; | 141 continue; |
136 } | 142 } |
137 | 143 |
138 gtk_accel_group_disconnect_key(accel_group_, | 144 gtk_accel_group_disconnect_key(accel_group_, |
(...skipping 17 matching lines...) Expand all Loading... | |
156 if (it == event_targets_.end()) { | 162 if (it == event_targets_.end()) { |
157 NOTREACHED(); // Shouldn't get this event for something not registered. | 163 NOTREACHED(); // Shouldn't get this event for something not registered. |
158 return FALSE; | 164 return FALSE; |
159 } | 165 } |
160 | 166 |
161 service->browser_event_router()->CommandExecuted( | 167 service->browser_event_router()->CommandExecuted( |
162 profile_, it->second.first, it->second.second); | 168 profile_, it->second.first, it->second.second); |
163 | 169 |
164 return TRUE; | 170 return TRUE; |
165 } | 171 } |
OLD | NEW |