• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCOA_H_
7 
8 #include <string>
9 #include <utility>
10 
11 #include "chrome/browser/extensions/extension_keybinding_registry.h"
12 #include "ui/base/accelerators/accelerator.h"
13 #include "ui/base/accelerators/accelerator_manager.h"
14 #include "ui/gfx/native_widget_types.h"
15 
16 class Profile;
17 
18 namespace content {
19   struct NativeWebKeyboardEvent;
20 }
21 namespace extensions {
22   class Extension;
23 }
24 
25 // The ExtensionKeybindingRegistryCocoa is the Cocoa specialization of the
26 // ExtensionKeybindingRegistry class that handles turning keyboard shortcuts
27 // into events that get sent to the extension.
28 
29 // ExtensionKeybindingRegistryCocoa is a class that handles Cocoa-specific
30 // implemenation of the Extension Commands shortcuts (keyboard accelerators).
31 // It also routes the events to the intended recipient (ie. to the browser
32 // action button in case of browser action commands).
33 class ExtensionKeybindingRegistryCocoa
34     : public extensions::ExtensionKeybindingRegistry {
35  public:
36   ExtensionKeybindingRegistryCocoa(Profile* profile,
37                                    gfx::NativeWindow window,
38                                    ExtensionFilter extension_filter,
39                                    Delegate* delegate);
40   virtual ~ExtensionKeybindingRegistryCocoa();
41 
set_shortcut_handling_suspended(bool suspended)42   static void set_shortcut_handling_suspended(bool suspended) {
43     shortcut_handling_suspended_ = suspended;
44   }
shortcut_handling_suspended()45   static bool shortcut_handling_suspended() {
46     return shortcut_handling_suspended_;
47   }
48 
49   // For a given keyboard |event|, see if a known Extension Command registration
50   // exists and route the event to it. Returns true if the event was handled,
51   // false otherwise.
52   bool ProcessKeyEvent(const content::NativeWebKeyboardEvent& event,
53                        ui::AcceleratorManager::HandlerPriority priority);
54 
55  protected:
56   // Overridden from ExtensionKeybindingRegistry:
57   virtual void AddExtensionKeybinding(
58       const extensions::Extension* extension,
59       const std::string& command_name) OVERRIDE;
60   virtual void RemoveExtensionKeybindingImpl(
61       const ui::Accelerator& accelerator,
62       const std::string& command_name) OVERRIDE;
63 
64  private:
65   // Keeps track of whether shortcut handling is currently suspended. Shortcuts
66   // are suspended briefly while capturing which shortcut to assign to an
67   // extension command in the Config UI. If handling isn't suspended while
68   // capturing then trying to assign Ctrl+F to a command would instead result
69   // in the Find box opening.
70   static bool shortcut_handling_suspended_;
71 
72   // Weak pointer to the our profile. Not owned by us.
73   Profile* profile_;
74 
75   // The window we are associated with.
76   gfx::NativeWindow window_;
77 
78   // The content notification registrar for listening to extension events.
79   content::NotificationRegistrar registrar_;
80 
81   DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistryCocoa);
82 };
83 
84 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCOA_H_
85