Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc

Issue 23812010: Implement first part of supporting global extension commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gclient sync Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "chrome/browser/extensions/api/commands/command_service.h" 9 #include "chrome/browser/extensions/api/commands/command_service.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding( 58 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding(
59 const extensions::Extension* extension, 59 const extensions::Extension* extension,
60 const std::string& command_name) { 60 const std::string& command_name) {
61 extensions::CommandService* command_service = 61 extensions::CommandService* command_service =
62 extensions::CommandService::Get(profile_); 62 extensions::CommandService::Get(profile_);
63 extensions::CommandMap commands; 63 extensions::CommandMap commands;
64 command_service->GetNamedCommands( 64 command_service->GetNamedCommands(
65 extension->id(), 65 extension->id(),
66 extensions::CommandService::ACTIVE_ONLY, 66 extensions::CommandService::ACTIVE_ONLY,
67 extensions::CommandService::REGULAR,
67 &commands); 68 &commands);
68 69
69 for (extensions::CommandMap::const_iterator iter = commands.begin(); 70 for (extensions::CommandMap::const_iterator iter = commands.begin();
70 iter != commands.end(); ++iter) { 71 iter != commands.end(); ++iter) {
71 if (!command_name.empty() && (iter->second.command_name() != command_name)) 72 if (!command_name.empty() && (iter->second.command_name() != command_name))
72 continue; 73 continue;
73 74
74 ui::Accelerator accelerator(iter->second.accelerator()); 75 ui::Accelerator accelerator(iter->second.accelerator());
75 event_targets_[accelerator] = 76 event_targets_[accelerator] =
76 std::make_pair(extension->id(), iter->second.command_name()); 77 std::make_pair(extension->id(), iter->second.command_name());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 extension->id(), 121 extension->id(),
121 extensions::CommandService::ACTIVE_ONLY, 122 extensions::CommandService::ACTIVE_ONLY,
122 &script_badge, 123 &script_badge,
123 NULL)) { 124 NULL)) {
124 ui::Accelerator accelerator(script_badge.accelerator()); 125 ui::Accelerator accelerator(script_badge.accelerator());
125 event_targets_[accelerator] = 126 event_targets_[accelerator] =
126 std::make_pair(extension->id(), script_badge.command_name()); 127 std::make_pair(extension->id(), script_badge.command_name());
127 } 128 }
128 } 129 }
129 130
130 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding( 131 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybindingImpl(
131 const extensions::Extension* extension, 132 const ui::Accelerator& accelerator,
132 const std::string& command_name) { 133 const std::string& command_name) {
133 EventTargets::iterator iter = event_targets_.begin(); 134 // On GTK, unlike Windows, the Event Targets contain all events but we must
134 while (iter != event_targets_.end()) { 135 // only unregister the ones we registered targets for.
135 if (iter->second.first != extension->id() || 136 if (!ShouldIgnoreCommand(command_name)) {
136 (!command_name.empty() && iter->second.second != command_name)) { 137 gtk_accel_group_disconnect_key(
137 ++iter; 138 accel_group_,
138 continue; // Not the extension or command we asked for. 139 ui::GetGdkKeyCodeForAccelerator(accelerator),
139 } 140 ui::GetGdkModifierForAccelerator(accelerator));
140
141 // On GTK, unlike Windows, the Event Targets contain all events but we must
142 // only unregister the ones we registered targets for.
143 if (!ShouldIgnoreCommand(iter->second.second)) {
144 gtk_accel_group_disconnect_key(
145 accel_group_,
146 ui::GetGdkKeyCodeForAccelerator(iter->first),
147 ui::GetGdkModifierForAccelerator(iter->first));
148 }
149
150 EventTargets::iterator old = iter++;
151 event_targets_.erase(old);
152 } 141 }
153 } 142 }
154 143
155 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator( 144 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator(
156 GtkAccelGroup* group, 145 GtkAccelGroup* group,
157 GObject* acceleratable, 146 GObject* acceleratable,
158 guint keyval, 147 guint keyval,
159 GdkModifierType modifier) { 148 GdkModifierType modifier) {
160 ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier( 149 ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier(
161 keyval, modifier); 150 keyval, modifier);
162 151
163 EventTargets::iterator it = event_targets_.find(accelerator); 152 EventTargets::iterator it = event_targets_.find(accelerator);
164 if (it == event_targets_.end()) { 153 if (it == event_targets_.end()) {
165 NOTREACHED(); // Shouldn't get this event for something not registered. 154 NOTREACHED(); // Shouldn't get this event for something not registered.
166 return FALSE; 155 return FALSE;
167 } 156 }
168 157
169 CommandExecuted(it->second.first, it->second.second); 158 CommandExecuted(it->second.first, it->second.second);
170 return TRUE; 159 return TRUE;
171 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698