OLD | NEW |
(Empty) | |
| 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 <map> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 |
| 12 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 13 #include "ui/base/accelerators/accelerator.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, gfx::NativeWindow window); |
| 37 virtual ~ExtensionKeybindingRegistryCocoa(); |
| 38 |
| 39 static void set_shortcut_handling_suspended(bool suspended) { |
| 40 shortcut_handling_suspended_ = suspended; |
| 41 } |
| 42 static bool shortcut_handling_suspended() { |
| 43 return shortcut_handling_suspended_; |
| 44 } |
| 45 |
| 46 // For a given keyboard |event|, see if a known Extension Command registration |
| 47 // exists and route the event to it. Returns true if the event was handled, |
| 48 // false otherwise. |
| 49 bool ProcessKeyEvent(const content::NativeWebKeyboardEvent& event); |
| 50 |
| 51 protected: |
| 52 // Overridden from ExtensionKeybindingRegistry: |
| 53 virtual void AddExtensionKeybinding( |
| 54 const extensions::Extension* extension, |
| 55 const std::string& command_name) OVERRIDE; |
| 56 virtual void RemoveExtensionKeybinding( |
| 57 const extensions::Extension* extension, |
| 58 const std::string& command_name) OVERRIDE; |
| 59 |
| 60 private: |
| 61 // Keeps track of whether shortcut handling is currently suspended. Shortcuts |
| 62 // are suspended briefly while capturing which shortcut to assign to an |
| 63 // extension command in the Config UI. If handling isn't suspended while |
| 64 // capturing then trying to assign Ctrl+F to a command would instead result |
| 65 // in the Find box opening. |
| 66 static bool shortcut_handling_suspended_; |
| 67 |
| 68 // Weak pointer to the our profile. Not owned by us. |
| 69 Profile* profile_; |
| 70 |
| 71 // The window we are associated with. |
| 72 gfx::NativeWindow window_; |
| 73 |
| 74 // Maps an accelerator to a string pair (extension id, command name) for |
| 75 // commands that have been registered. Unlike its Views counterpart, this map |
| 76 // contains browserAction and pageAction commands (but does not route those |
| 77 // events), so that we can query priority handlers in HasPriorityHandler(...). |
| 78 typedef std::map< ui::Accelerator, |
| 79 std::pair<std::string, std::string> > EventTargets; |
| 80 EventTargets event_targets_; |
| 81 |
| 82 // The content notification registrar for listening to extension events. |
| 83 content::NotificationRegistrar registrar_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistryCocoa); |
| 86 }; |
| 87 |
| 88 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCO
A_H_ |
OLD | NEW |