This source file includes following definitions.
- SetShortcutHandlingSuspended
- accel_group_
- HasPriorityHandler
- AddExtensionKeybinding
- RemoveExtensionKeybindingImpl
- OnGtkAccelerator
#include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h"
#include <gtk/gtk.h>
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "extensions/common/extension.h"
#include "ui/base/accelerators/platform_accelerator_gtk.h"
void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended(
bool suspended) {
ExtensionKeybindingRegistryGtk::set_shortcut_handling_suspended(suspended);
}
bool ExtensionKeybindingRegistryGtk::shortcut_handling_suspended_ = false;
ExtensionKeybindingRegistryGtk::ExtensionKeybindingRegistryGtk(
Profile* profile,
gfx::NativeWindow window,
ExtensionFilter extension_filter,
Delegate* delegate)
: ExtensionKeybindingRegistry(profile, extension_filter, delegate),
profile_(profile),
window_(window),
accel_group_(NULL) {
Init();
}
ExtensionKeybindingRegistryGtk::~ExtensionKeybindingRegistryGtk() {
if (accel_group_) {
gtk_accel_group_disconnect(accel_group_,
NULL);
gtk_window_remove_accel_group(window_, accel_group_);
g_object_unref(accel_group_);
accel_group_ = NULL;
}
}
gboolean ExtensionKeybindingRegistryGtk::HasPriorityHandler(
const GdkEventKey* event) const {
if (shortcut_handling_suspended_)
return FALSE;
ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier(
event->keyval, static_cast<GdkModifierType>(event->state));
return IsAcceleratorRegistered(accelerator);
}
void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding(
const extensions::Extension* extension,
const std::string& command_name) {
extensions::CommandService* command_service =
extensions::CommandService::Get(profile_);
extensions::CommandMap commands;
command_service->GetNamedCommands(
extension->id(),
extensions::CommandService::ACTIVE_ONLY,
extensions::CommandService::REGULAR,
&commands);
for (extensions::CommandMap::const_iterator iter = commands.begin();
iter != commands.end(); ++iter) {
if (!command_name.empty() && (iter->second.command_name() != command_name))
continue;
ui::Accelerator accelerator(iter->second.accelerator());
AddEventTarget(accelerator, extension->id(), iter->second.command_name());
if (!accel_group_) {
accel_group_ = gtk_accel_group_new();
gtk_window_add_accel_group(window_, accel_group_);
}
gtk_accel_group_connect(
accel_group_,
ui::GetGdkKeyCodeForAccelerator(accelerator),
ui::GetGdkModifierForAccelerator(accelerator),
GtkAccelFlags(0),
g_cclosure_new(G_CALLBACK(OnGtkAcceleratorThunk), this, NULL));
}
extensions::Command browser_action;
if (command_service->GetBrowserActionCommand(
extension->id(),
extensions::CommandService::ACTIVE_ONLY,
&browser_action,
NULL)) {
AddEventTarget(browser_action.accelerator(),
extension->id(),
browser_action.command_name());
}
extensions::Command page_action;
if (command_service->GetPageActionCommand(
extension->id(),
extensions::CommandService::ACTIVE_ONLY,
&page_action,
NULL)) {
AddEventTarget(
page_action.accelerator(), extension->id(), page_action.command_name());
}
}
void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybindingImpl(
const ui::Accelerator& accelerator,
const std::string& command_name) {
if (!ShouldIgnoreCommand(command_name)) {
gtk_accel_group_disconnect_key(
accel_group_,
ui::GetGdkKeyCodeForAccelerator(accelerator),
ui::GetGdkModifierForAccelerator(accelerator));
}
}
gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator(
GtkAccelGroup* group,
GObject* acceleratable,
guint keyval,
GdkModifierType modifier) {
ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier(
keyval, modifier);
return ExtensionKeybindingRegistry::NotifyEventTargets(accelerator);
}