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/command_service.h" |
8 #include "chrome/browser/extensions/api/commands/extension_command_service_facto
ry.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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" | 13 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
14 | 14 |
15 ExtensionKeybindingRegistryGtk::ExtensionKeybindingRegistryGtk( | 15 ExtensionKeybindingRegistryGtk::ExtensionKeybindingRegistryGtk( |
16 Profile* profile, gfx::NativeWindow window) | 16 Profile* profile, gfx::NativeWindow window) |
17 : ExtensionKeybindingRegistry(profile), | 17 : ExtensionKeybindingRegistry(profile), |
18 profile_(profile), | 18 profile_(profile), |
(...skipping 18 matching lines...) Expand all Loading... |
37 const GdkEventKey* event) const { | 37 const GdkEventKey* event) const { |
38 ui::AcceleratorGtk accelerator(ui::WindowsKeyCodeForGdkKeyCode(event->keyval), | 38 ui::AcceleratorGtk accelerator(ui::WindowsKeyCodeForGdkKeyCode(event->keyval), |
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 extensions::Extension* extension) { | 46 const extensions::Extension* extension) { |
47 extensions::ExtensionCommandService* command_service = | 47 extensions::CommandService* command_service = |
48 extensions::ExtensionCommandServiceFactory::GetForProfile(profile_); | 48 extensions::CommandServiceFactory::GetForProfile(profile_); |
49 const extensions::CommandMap& commands = | 49 const extensions::CommandMap& commands = |
50 command_service->GetNamedCommands( | 50 command_service->GetNamedCommands( |
51 extension->id(), | 51 extension->id(), |
52 extensions::ExtensionCommandService::ACTIVE_ONLY); | 52 extensions::CommandService::ACTIVE_ONLY); |
53 extensions::CommandMap::const_iterator iter = commands.begin(); | 53 extensions::CommandMap::const_iterator iter = commands.begin(); |
54 for (; iter != commands.end(); ++iter) { | 54 for (; iter != commands.end(); ++iter) { |
55 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), | 55 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), |
56 iter->second.accelerator().IsShiftDown(), | 56 iter->second.accelerator().IsShiftDown(), |
57 iter->second.accelerator().IsCtrlDown(), | 57 iter->second.accelerator().IsCtrlDown(), |
58 iter->second.accelerator().IsAltDown()); | 58 iter->second.accelerator().IsAltDown()); |
59 event_targets_[accelerator] = | 59 event_targets_[accelerator] = |
60 std::make_pair(extension->id(), iter->second.command_name()); | 60 std::make_pair(extension->id(), iter->second.command_name()); |
61 | 61 |
62 if (!accel_group_) { | 62 if (!accel_group_) { |
63 accel_group_ = gtk_accel_group_new(); | 63 accel_group_ = gtk_accel_group_new(); |
64 gtk_window_add_accel_group(window_, accel_group_); | 64 gtk_window_add_accel_group(window_, accel_group_); |
65 } | 65 } |
66 | 66 |
67 gtk_accel_group_connect( | 67 gtk_accel_group_connect( |
68 accel_group_, | 68 accel_group_, |
69 accelerator.GetGdkKeyCode(), | 69 accelerator.GetGdkKeyCode(), |
70 accelerator.gdk_modifier_type(), | 70 accelerator.gdk_modifier_type(), |
71 GtkAccelFlags(0), | 71 GtkAccelFlags(0), |
72 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); | 72 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); |
73 } | 73 } |
74 | 74 |
75 // Unlike on Windows, we need to explicitly add the browser action and page | 75 // Unlike on Windows, we need to explicitly add the browser action and page |
76 // action to the event_targets_, even though we don't register them as | 76 // action to the event_targets_, even though we don't register them as |
77 // handlers. See http://crbug.com/124873. | 77 // handlers. See http://crbug.com/124873. |
78 const extensions::Command* browser_action = | 78 const extensions::Command* browser_action = |
79 command_service->GetBrowserActionCommand( | 79 command_service->GetBrowserActionCommand( |
80 extension->id(), | 80 extension->id(), |
81 extensions::ExtensionCommandService::ACTIVE_ONLY); | 81 extensions::CommandService::ACTIVE_ONLY); |
82 if (browser_action) { | 82 if (browser_action) { |
83 ui::AcceleratorGtk accelerator(browser_action->accelerator().key_code(), | 83 ui::AcceleratorGtk accelerator(browser_action->accelerator().key_code(), |
84 browser_action->accelerator().IsShiftDown(), | 84 browser_action->accelerator().IsShiftDown(), |
85 browser_action->accelerator().IsCtrlDown(), | 85 browser_action->accelerator().IsCtrlDown(), |
86 browser_action->accelerator().IsAltDown()); | 86 browser_action->accelerator().IsAltDown()); |
87 event_targets_[accelerator] = | 87 event_targets_[accelerator] = |
88 std::make_pair(extension->id(), browser_action->command_name()); | 88 std::make_pair(extension->id(), browser_action->command_name()); |
89 } | 89 } |
90 | 90 |
91 const extensions::Command* page_action = | 91 const extensions::Command* page_action = |
92 command_service->GetPageActionCommand( | 92 command_service->GetPageActionCommand( |
93 extension->id(), | 93 extension->id(), |
94 extensions::ExtensionCommandService::ACTIVE_ONLY); | 94 extensions::CommandService::ACTIVE_ONLY); |
95 if (page_action) { | 95 if (page_action) { |
96 ui::AcceleratorGtk accelerator(page_action->accelerator().key_code(), | 96 ui::AcceleratorGtk accelerator(page_action->accelerator().key_code(), |
97 page_action->accelerator().IsShiftDown(), | 97 page_action->accelerator().IsShiftDown(), |
98 page_action->accelerator().IsCtrlDown(), | 98 page_action->accelerator().IsCtrlDown(), |
99 page_action->accelerator().IsAltDown()); | 99 page_action->accelerator().IsAltDown()); |
100 event_targets_[accelerator] = | 100 event_targets_[accelerator] = |
101 std::make_pair(extension->id(), page_action->command_name()); | 101 std::make_pair(extension->id(), page_action->command_name()); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (it == event_targets_.end()) { | 139 if (it == event_targets_.end()) { |
140 NOTREACHED(); // Shouldn't get this event for something not registered. | 140 NOTREACHED(); // Shouldn't get this event for something not registered. |
141 return FALSE; | 141 return FALSE; |
142 } | 142 } |
143 | 143 |
144 service->browser_event_router()->CommandExecuted( | 144 service->browser_event_router()->CommandExecuted( |
145 profile_, it->second.first, it->second.second); | 145 profile_, it->second.first, it->second.second); |
146 | 146 |
147 return TRUE; | 147 return TRUE; |
148 } | 148 } |
OLD | NEW |