| 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/extension_command_service.h" | 7 #include "chrome/browser/extensions/api/commands/extension_command_service.h" |
| 8 #include "chrome/browser/extensions/api/commands/extension_command_service_facto
ry.h" | 8 #include "chrome/browser/extensions/api/commands/extension_command_service_facto
ry.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 28 matching lines...) Expand all Loading... |
| 39 event->state & GDK_SHIFT_MASK, | 39 event->state & GDK_SHIFT_MASK, |
| 40 event->state & GDK_CONTROL_MASK, | 40 event->state & GDK_CONTROL_MASK, |
| 41 event->state & GDK_MOD1_MASK); | 41 event->state & GDK_MOD1_MASK); |
| 42 return event_targets_.find(accelerator) != event_targets_.end(); | 42 return event_targets_.find(accelerator) != event_targets_.end(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding( | 45 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding( |
| 46 const Extension* extension) { | 46 const Extension* extension) { |
| 47 ExtensionCommandService* command_service = | 47 ExtensionCommandService* command_service = |
| 48 ExtensionCommandServiceFactory::GetForProfile(profile_); | 48 ExtensionCommandServiceFactory::GetForProfile(profile_); |
| 49 const Extension::CommandMap& commands = | 49 const extensions::CommandMap& commands = |
| 50 command_service->GetActiveNamedCommands(extension->id()); | 50 command_service->GetActiveNamedCommands(extension->id()); |
| 51 Extension::CommandMap::const_iterator iter = commands.begin(); | 51 extensions::CommandMap::const_iterator iter = commands.begin(); |
| 52 for (; iter != commands.end(); ++iter) { | 52 for (; iter != commands.end(); ++iter) { |
| 53 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), | 53 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), |
| 54 iter->second.accelerator().IsShiftDown(), | 54 iter->second.accelerator().IsShiftDown(), |
| 55 iter->second.accelerator().IsCtrlDown(), | 55 iter->second.accelerator().IsCtrlDown(), |
| 56 iter->second.accelerator().IsAltDown()); | 56 iter->second.accelerator().IsAltDown()); |
| 57 event_targets_[accelerator] = | 57 event_targets_[accelerator] = |
| 58 std::make_pair(extension->id(), iter->second.command_name()); | 58 std::make_pair(extension->id(), iter->second.command_name()); |
| 59 | 59 |
| 60 if (!accel_group_) { | 60 if (!accel_group_) { |
| 61 accel_group_ = gtk_accel_group_new(); | 61 accel_group_ = gtk_accel_group_new(); |
| 62 gtk_window_add_accel_group(window_, accel_group_); | 62 gtk_window_add_accel_group(window_, accel_group_); |
| 63 } | 63 } |
| 64 | 64 |
| 65 gtk_accel_group_connect( | 65 gtk_accel_group_connect( |
| 66 accel_group_, | 66 accel_group_, |
| 67 accelerator.GetGdkKeyCode(), | 67 accelerator.GetGdkKeyCode(), |
| 68 accelerator.gdk_modifier_type(), | 68 accelerator.gdk_modifier_type(), |
| 69 GtkAccelFlags(0), | 69 GtkAccelFlags(0), |
| 70 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); | 70 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Unlike on Windows, we need to explicitly add the browser action and page | 73 // Unlike on Windows, we need to explicitly add the browser action and page |
| 74 // action to the event_targets_, even though we don't register them as | 74 // action to the event_targets_, even though we don't register them as |
| 75 // handlers. See http://crbug.com/124873. | 75 // handlers. See http://crbug.com/124873. |
| 76 const Extension::Command* browser_action = | 76 const extensions::Command* browser_action = |
| 77 command_service->GetActiveBrowserActionCommand(extension->id()); | 77 command_service->GetActiveBrowserActionCommand(extension->id()); |
| 78 if (browser_action) { | 78 if (browser_action) { |
| 79 ui::AcceleratorGtk accelerator(browser_action->accelerator().key_code(), | 79 ui::AcceleratorGtk accelerator(browser_action->accelerator().key_code(), |
| 80 browser_action->accelerator().IsShiftDown(), | 80 browser_action->accelerator().IsShiftDown(), |
| 81 browser_action->accelerator().IsCtrlDown(), | 81 browser_action->accelerator().IsCtrlDown(), |
| 82 browser_action->accelerator().IsAltDown()); | 82 browser_action->accelerator().IsAltDown()); |
| 83 event_targets_[accelerator] = | 83 event_targets_[accelerator] = |
| 84 std::make_pair(extension->id(), browser_action->command_name()); | 84 std::make_pair(extension->id(), browser_action->command_name()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 const Extension::Command* page_action = | 87 const extensions::Command* page_action = |
| 88 command_service->GetActivePageActionCommand(extension->id()); | 88 command_service->GetActivePageActionCommand(extension->id()); |
| 89 if (page_action) { | 89 if (page_action) { |
| 90 ui::AcceleratorGtk accelerator(page_action->accelerator().key_code(), | 90 ui::AcceleratorGtk accelerator(page_action->accelerator().key_code(), |
| 91 page_action->accelerator().IsShiftDown(), | 91 page_action->accelerator().IsShiftDown(), |
| 92 page_action->accelerator().IsCtrlDown(), | 92 page_action->accelerator().IsCtrlDown(), |
| 93 page_action->accelerator().IsAltDown()); | 93 page_action->accelerator().IsAltDown()); |
| 94 event_targets_[accelerator] = | 94 event_targets_[accelerator] = |
| 95 std::make_pair(extension->id(), page_action->command_name()); | 95 std::make_pair(extension->id(), page_action->command_name()); |
| 96 } | 96 } |
| 97 } | 97 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (it == event_targets_.end()) { | 133 if (it == event_targets_.end()) { |
| 134 NOTREACHED(); // Shouldn't get this event for something not registered. | 134 NOTREACHED(); // Shouldn't get this event for something not registered. |
| 135 return FALSE; | 135 return FALSE; |
| 136 } | 136 } |
| 137 | 137 |
| 138 service->browser_event_router()->CommandExecuted( | 138 service->browser_event_router()->CommandExecuted( |
| 139 profile_, it->second.first, it->second.second); | 139 profile_, it->second.first, it->second.second); |
| 140 | 140 |
| 141 return TRUE; | 141 return TRUE; |
| 142 } | 142 } |
| OLD | NEW |