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

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

Issue 64273008: [Windows] Finish global and non-global media keys support on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 7 years, 1 month 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 extension->id(), 65 extension->id(),
66 extensions::CommandService::ACTIVE_ONLY, 66 extensions::CommandService::ACTIVE_ONLY,
67 extensions::CommandService::REGULAR, 67 extensions::CommandService::REGULAR,
68 &commands); 68 &commands);
69 69
70 for (extensions::CommandMap::const_iterator iter = commands.begin(); 70 for (extensions::CommandMap::const_iterator iter = commands.begin();
71 iter != commands.end(); ++iter) { 71 iter != commands.end(); ++iter) {
72 if (!command_name.empty() && (iter->second.command_name() != command_name)) 72 if (!command_name.empty() && (iter->second.command_name() != command_name))
73 continue; 73 continue;
74 74
75 ui::Accelerator accelerator(iter->second.accelerator()); 75 event_targets_[iter->second.accelerator()].push_back(
76 event_targets_[accelerator] = 76 std::make_pair(extension->id(), iter->second.command_name()));
77 std::make_pair(extension->id(), iter->second.command_name()); 77 // Shortcuts except media keys have only one target in the list. See comment
78 // about |event_targets_|.
79 if (!extensions::CommandService::IsMediaKey(iter->second.accelerator()))
80 DCHECK(event_targets_[iter->second.accelerator()].size() == 1);
78 81
79 if (!accel_group_) { 82 if (!accel_group_) {
80 accel_group_ = gtk_accel_group_new(); 83 accel_group_ = gtk_accel_group_new();
81 gtk_window_add_accel_group(window_, accel_group_); 84 gtk_window_add_accel_group(window_, accel_group_);
82 } 85 }
83 86
84 gtk_accel_group_connect( 87 gtk_accel_group_connect(
85 accel_group_, 88 accel_group_,
86 ui::GetGdkKeyCodeForAccelerator(accelerator), 89 ui::GetGdkKeyCodeForAccelerator(accelerator),
87 ui::GetGdkModifierForAccelerator(accelerator), 90 ui::GetGdkModifierForAccelerator(accelerator),
88 GtkAccelFlags(0), 91 GtkAccelFlags(0),
89 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); 92 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL));
90 } 93 }
91 94
92 // Unlike on Windows, we need to explicitly add the browser action and page 95 // Unlike on Windows, we need to explicitly add the browser action and page
93 // action to the event_targets_, even though we don't register them as 96 // action to the event_targets_, even though we don't register them as
94 // handlers. See http://crbug.com/124873. 97 // handlers. See http://crbug.com/124873.
95 extensions::Command browser_action; 98 extensions::Command browser_action;
96 if (command_service->GetBrowserActionCommand( 99 if (command_service->GetBrowserActionCommand(
97 extension->id(), 100 extension->id(),
98 extensions::CommandService::ACTIVE_ONLY, 101 extensions::CommandService::ACTIVE_ONLY,
99 &browser_action, 102 &browser_action,
100 NULL)) { 103 NULL)) {
101 ui::Accelerator accelerator(browser_action.accelerator()); 104 ui::Accelerator accelerator(browser_action.accelerator());
102 event_targets_[accelerator] = 105 event_targets_[accelerator].push_back(
103 std::make_pair(extension->id(), browser_action.command_name()); 106 std::make_pair(extension->id(), browser_action.command_name()));
107 // We should have only one target. See comment about |event_targets_|.
108 DCHECK(event_targets_[Accelerator].size() == 1);
104 } 109 }
105 110
106 // Add the Page Action (if any). 111 // Add the Page Action (if any).
107 extensions::Command page_action; 112 extensions::Command page_action;
108 if (command_service->GetPageActionCommand( 113 if (command_service->GetPageActionCommand(
109 extension->id(), 114 extension->id(),
110 extensions::CommandService::ACTIVE_ONLY, 115 extensions::CommandService::ACTIVE_ONLY,
111 &page_action, 116 &page_action,
112 NULL)) { 117 NULL)) {
113 ui::Accelerator accelerator(page_action.accelerator()); 118 ui::Accelerator accelerator(page_action.accelerator());
114 event_targets_[accelerator] = 119 event_targets_[accelerator].push_back(
115 std::make_pair(extension->id(), page_action.command_name()); 120 std::make_pair(extension->id(), page_action.command_name()));
121 DCHECK(event_targets_[Accelerator].size() == 1); // Ditto.
116 } 122 }
117 123
118 // Add the Script Badge (if any). 124 // Add the Script Badge (if any).
119 extensions::Command script_badge; 125 extensions::Command script_badge;
120 if (command_service->GetScriptBadgeCommand( 126 if (command_service->GetScriptBadgeCommand(
121 extension->id(), 127 extension->id(),
122 extensions::CommandService::ACTIVE_ONLY, 128 extensions::CommandService::ACTIVE_ONLY,
123 &script_badge, 129 &script_badge,
124 NULL)) { 130 NULL)) {
125 ui::Accelerator accelerator(script_badge.accelerator()); 131 ui::Accelerator accelerator(script_badge.accelerator());
126 event_targets_[accelerator] = 132 event_targets_[accelerator].push_back(
127 std::make_pair(extension->id(), script_badge.command_name()); 133 std::make_pair(extension->id(), script_badge.command_name()));
134 DCHECK(event_targets_[Accelerator].size() == 1); // Ditto.
128 } 135 }
129 } 136 }
130 137
131 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybindingImpl( 138 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybindingImpl(
132 const ui::Accelerator& accelerator, 139 const ui::Accelerator& accelerator,
133 const std::string& command_name) { 140 const std::string& command_name) {
134 // On GTK, unlike Windows, the Event Targets contain all events but we must 141 // On GTK, unlike Windows, the Event Targets contain all events but we must
135 // only unregister the ones we registered targets for. 142 // only unregister the ones we registered targets for.
136 if (!ShouldIgnoreCommand(command_name)) { 143 if (!ShouldIgnoreCommand(command_name)) {
137 gtk_accel_group_disconnect_key( 144 gtk_accel_group_disconnect_key(
138 accel_group_, 145 accel_group_,
139 ui::GetGdkKeyCodeForAccelerator(accelerator), 146 ui::GetGdkKeyCodeForAccelerator(accelerator),
140 ui::GetGdkModifierForAccelerator(accelerator)); 147 ui::GetGdkModifierForAccelerator(accelerator));
141 } 148 }
142 } 149 }
143 150
144 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator( 151 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator(
145 GtkAccelGroup* group, 152 GtkAccelGroup* group,
146 GObject* acceleratable, 153 GObject* acceleratable,
147 guint keyval, 154 guint keyval,
148 GdkModifierType modifier) { 155 GdkModifierType modifier) {
149 ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier( 156 ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier(
150 keyval, modifier); 157 keyval, modifier);
151 158 return ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator(
152 EventTargets::iterator it = event_targets_.find(accelerator); 159 accelerator);
153 if (it == event_targets_.end()) {
154 NOTREACHED(); // Shouldn't get this event for something not registered.
155 return FALSE;
156 }
157
158 CommandExecuted(it->second.first, it->second.second);
159 return TRUE;
160 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698