| 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/extension_browser_event_router.h" | 7 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
| 11 | 12 |
| 12 ExtensionKeybindingRegistryGtk::ExtensionKeybindingRegistryGtk( | 13 ExtensionKeybindingRegistryGtk::ExtensionKeybindingRegistryGtk( |
| 13 Profile* profile, gfx::NativeWindow window) | 14 Profile* profile, gfx::NativeWindow window) |
| 14 : ExtensionKeybindingRegistry(profile), | 15 : ExtensionKeybindingRegistry(profile), |
| 15 profile_(profile), | 16 profile_(profile), |
| 16 window_(window), | 17 window_(window), |
| 17 accel_group_(NULL) { | 18 accel_group_(NULL) { |
| 18 Init(); | 19 Init(); |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 continue; | 58 continue; |
| 58 | 59 |
| 59 if (!accel_group_) { | 60 if (!accel_group_) { |
| 60 accel_group_ = gtk_accel_group_new(); | 61 accel_group_ = gtk_accel_group_new(); |
| 61 gtk_window_add_accel_group(window_, accel_group_); | 62 gtk_window_add_accel_group(window_, accel_group_); |
| 62 } | 63 } |
| 63 | 64 |
| 64 gtk_accel_group_connect( | 65 gtk_accel_group_connect( |
| 65 accel_group_, | 66 accel_group_, |
| 66 accelerator.GetGdkKeyCode(), | 67 accelerator.GetGdkKeyCode(), |
| 67 accelerator.gdk_modifier_type(), | 68 accelerator.GetGdkModifierType(), |
| 68 GtkAccelFlags(0), | 69 GtkAccelFlags(0), |
| 69 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); | 70 g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL)); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding( | 74 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding( |
| 74 const Extension* extension) { | 75 const Extension* extension) { |
| 75 EventTargets::iterator iter = event_targets_.begin(); | 76 EventTargets::iterator iter = event_targets_.begin(); |
| 76 while (iter != event_targets_.end()) { | 77 while (iter != event_targets_.end()) { |
| 77 if (iter->second.first != extension->id()) { | 78 if (iter->second.first != extension->id()) { |
| 78 ++iter; | 79 ++iter; |
| 79 continue; // Not the extension we asked for. | 80 continue; // Not the extension we asked for. |
| 80 } | 81 } |
| 81 | 82 |
| 82 // On GTK, unlike Windows, the Event Targets contain all events. | 83 // On GTK, unlike Windows, the Event Targets contain all events. |
| 83 if (ShouldIgnoreCommand(iter->second.second)) { | 84 if (ShouldIgnoreCommand(iter->second.second)) { |
| 84 ++iter; | 85 ++iter; |
| 85 continue; | 86 continue; |
| 86 } | 87 } |
| 87 | 88 |
| 88 gtk_accel_group_disconnect_key(accel_group_, | 89 gtk_accel_group_disconnect_key(accel_group_, |
| 89 iter->first.GetGdkKeyCode(), | 90 iter->first.GetGdkKeyCode(), |
| 90 iter->first.gdk_modifier_type()); | 91 iter->first.GetGdkModifierType()); |
| 91 EventTargets::iterator old = iter++; | 92 EventTargets::iterator old = iter++; |
| 92 event_targets_.erase(old); | 93 event_targets_.erase(old); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator( | 97 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator( |
| 97 GtkAccelGroup* group, | 98 GtkAccelGroup* group, |
| 98 GObject* acceleratable, | 99 GObject* acceleratable, |
| 99 guint keyval, | 100 guint keyval, |
| 100 GdkModifierType modifier) { | 101 GdkModifierType modifier) { |
| 101 ui::AcceleratorGtk accelerator(keyval, modifier); | 102 ui::AcceleratorGtk accelerator(keyval, modifier); |
| 102 | 103 |
| 103 ExtensionService* service = profile_->GetExtensionService(); | 104 ExtensionService* service = profile_->GetExtensionService(); |
| 104 | 105 |
| 105 EventTargets::iterator it = event_targets_.find(accelerator); | 106 EventTargets::iterator it = event_targets_.find(accelerator); |
| 106 if (it == event_targets_.end()) { | 107 if (it == event_targets_.end()) { |
| 107 NOTREACHED(); // Shouldn't get this event for something not registered. | 108 NOTREACHED(); // Shouldn't get this event for something not registered. |
| 108 return FALSE; | 109 return FALSE; |
| 109 } | 110 } |
| 110 | 111 |
| 111 service->browser_event_router()->CommandExecuted( | 112 service->browser_event_router()->CommandExecuted( |
| 112 profile_, it->second.first, it->second.second); | 113 profile_, it->second.first, it->second.second); |
| 113 | 114 |
| 114 return TRUE; | 115 return TRUE; |
| 115 } | 116 } |
| OLD | NEW |