summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.h
blob: 0f28a3b9980f21d0470b68acd7c96ee3e004ebd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCOA_H_

#include <string>
#include <utility>

#include "base/macros.h"
#include "chrome/browser/extensions/extension_keybinding_registry.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/accelerator_manager.h"
#include "ui/gfx/native_widget_types.h"

class Profile;

namespace content {
  struct NativeWebKeyboardEvent;
}
namespace extensions {
  class Extension;
}

// The ExtensionKeybindingRegistryCocoa is the Cocoa specialization of the
// ExtensionKeybindingRegistry class that handles turning keyboard shortcuts
// into events that get sent to the extension.

// ExtensionKeybindingRegistryCocoa is a class that handles Cocoa-specific
// implemenation of the Extension Commands shortcuts (keyboard accelerators).
// It also routes the events to the intended recipient (ie. to the browser
// action button in case of browser action commands).
class ExtensionKeybindingRegistryCocoa
    : public extensions::ExtensionKeybindingRegistry {
 public:
  ExtensionKeybindingRegistryCocoa(Profile* profile,
                                   gfx::NativeWindow window,
                                   ExtensionFilter extension_filter,
                                   Delegate* delegate);
  ~ExtensionKeybindingRegistryCocoa() override;

  // For a given keyboard |event|, see if a known Extension Command registration
  // exists and route the event to it. Returns true if the event was handled,
  // false otherwise.
  bool ProcessKeyEvent(const content::NativeWebKeyboardEvent& event,
                       ui::AcceleratorManager::HandlerPriority priority);

 protected:
  // Overridden from ExtensionKeybindingRegistry:
  void AddExtensionKeybindings(const extensions::Extension* extension,
                               const std::string& command_name) override;
  void RemoveExtensionKeybindingImpl(const ui::Accelerator& accelerator,
                                     const std::string& command_name) override;

 private:
  // Weak pointer to the our profile. Not owned by us.
  Profile* profile_;

  // The window we are associated with.
  gfx::NativeWindow window_;

  // The content notification registrar for listening to extension events.
  content::NotificationRegistrar registrar_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistryCocoa);
};

#endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_COCOA_H_