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

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

Issue 25007002: Add GTK support for global Extension Commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revise. 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
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // only unregister the ones we registered targets for. 143 // only unregister the ones we registered targets for.
143 if (!ShouldIgnoreCommand(iter->second.second)) { 144 if (!ShouldIgnoreCommand(iter->second.second)) {
144 gtk_accel_group_disconnect_key( 145 gtk_accel_group_disconnect_key(
145 accel_group_, 146 accel_group_,
146 ui::GetGdkKeyCodeForAccelerator(iter->first), 147 ui::GetGdkKeyCodeForAccelerator(iter->first),
147 ui::GetGdkModifierForAccelerator(iter->first)); 148 ui::GetGdkModifierForAccelerator(iter->first));
148 } 149 }
149 150
150 EventTargets::iterator old = iter++; 151 EventTargets::iterator old = iter++;
151 event_targets_.erase(old); 152 event_targets_.erase(old);
153
154 // If a specific command_name was requested, it has now been deleted so
155 // no further work is required.
156 if (!command_name.empty())
157 break;
152 } 158 }
153 } 159 }
154 160
155 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator( 161 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator(
156 GtkAccelGroup* group, 162 GtkAccelGroup* group,
157 GObject* acceleratable, 163 GObject* acceleratable,
158 guint keyval, 164 guint keyval,
159 GdkModifierType modifier) { 165 GdkModifierType modifier) {
160 ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier( 166 ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier(
161 keyval, modifier); 167 keyval, modifier);
162 168
163 EventTargets::iterator it = event_targets_.find(accelerator); 169 EventTargets::iterator it = event_targets_.find(accelerator);
164 if (it == event_targets_.end()) { 170 if (it == event_targets_.end()) {
165 NOTREACHED(); // Shouldn't get this event for something not registered. 171 NOTREACHED(); // Shouldn't get this event for something not registered.
166 return FALSE; 172 return FALSE;
167 } 173 }
168 174
169 CommandExecuted(it->second.first, it->second.second); 175 CommandExecuted(it->second.first, it->second.second);
170 return TRUE; 176 return TRUE;
171 } 177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698