Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / gtk / extensions / extension_keybinding_registry_gtk.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_GTK_H_
7
8 #include <gdk/gdk.h>
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/extensions/extension_keybinding_registry.h"
13 #include "ui/base/accelerators/accelerator.h"
14 #include "ui/base/gtk/gtk_signal.h"
15 #include "ui/gfx/native_widget_types.h"
16
17 class Profile;
18
19 namespace extensions {
20 class Extension;
21 }
22
23 typedef struct _GtkAccelGroup GtkAccelGroup;
24 typedef struct _GdkEventKey GdkEventKey;
25
26 // The ExtensionKeybindingRegistryGtk is the GTK specialization of the
27 // ExtensionKeybindingRegistry class that handles turning keyboard shortcuts
28 // into events that get sent to the extension.
29
30 // ExtensionKeybindingRegistryGtk is a class that handles GTK-specific
31 // implemenation of the Extension Keybinding shortcuts (keyboard accelerators).
32 // Note: It keeps track of browserAction and pageAction commands, but does not
33 // route the events to them -- that is handled elsewhere. This class registers
34 // the accelerators on behalf of the extensions and routes the commands to them
35 // via the BrowserEventRouter.
36 class ExtensionKeybindingRegistryGtk
37     : public extensions::ExtensionKeybindingRegistry {
38  public:
39   ExtensionKeybindingRegistryGtk(Profile* profile,
40                                  gfx::NativeWindow window,
41                                  ExtensionFilter extension_filter,
42                                  Delegate* delegate);
43   virtual ~ExtensionKeybindingRegistryGtk();
44
45   static void set_shortcut_handling_suspended(bool suspended) {
46     shortcut_handling_suspended_ = suspended;
47   }
48   static bool shortcut_handling_suspended() {
49     return shortcut_handling_suspended_;
50   }
51
52   // Whether this class has any registered keyboard shortcuts that correspond
53   // to |event|.
54   gboolean HasPriorityHandler(const GdkEventKey* event) const;
55
56  protected:
57   // Overridden from ExtensionKeybindingRegistry:
58   virtual void AddExtensionKeybinding(
59       const extensions::Extension* extension,
60       const std::string& command_name) OVERRIDE;
61   virtual void RemoveExtensionKeybindingImpl(
62       const ui::Accelerator& accelerator,
63       const std::string& command_name) OVERRIDE;
64
65  private:
66   // The accelerator handler for when the extension command shortcuts are
67   // struck.
68   CHROMEG_CALLBACK_3(ExtensionKeybindingRegistryGtk, gboolean, OnGtkAccelerator,
69                      GtkAccelGroup*, GObject*, guint, GdkModifierType);
70
71   // Keeps track of whether shortcut handling is currently suspended. Shortcuts
72   // are suspended briefly while capturing which shortcut to assign to an
73   // extension command in the Config UI. If handling isn't suspended while
74   // capturing then trying to assign Ctrl+F to a command would instead result
75   // in the Find box opening.
76   static bool shortcut_handling_suspended_;
77
78   // Weak pointer to the our profile. Not owned by us.
79   Profile* profile_;
80
81   // The browser window the accelerators are associated with.
82   gfx::NativeWindow window_;
83
84   // The accelerator group used to handle accelerators, owned by this object.
85   GtkAccelGroup* accel_group_;
86
87   // The content notification registrar for listening to extension events.
88   content::NotificationRegistrar registrar_;
89
90   DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistryGtk);
91 };
92
93 #endif  // CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_GTK_H_