summaryrefslogtreecommitdiffstats
path: root/ui/aura_shell/shell_accelerator_controller.h
blob: 08f4a67bc4360e6536570c197fedff9833dd2c64 (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
70
71
72
73
74
75
76
77
// Copyright (c) 2011 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 UI_AURA_SHELL_SHELL_ACCELERATOR_CONTROLLER_H_
#define UI_AURA_SHELL_SHELL_ACCELERATOR_CONTROLLER_H_
#pragma once

#include <map>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura_shell/aura_shell_export.h"
#include "ui/base/accelerators/accelerator.h"

namespace ui {
class AcceleratorManager;
}

namespace aura_shell {

class ScreenshotDelegate;

// ShellAcceleratorController provides functions for registering or
// unregistering global keyboard accelerators, which are handled earlier than
// any windows. It also implements several handlers as an accelerator target.
class AURA_SHELL_EXPORT ShellAcceleratorController
    : public ui::AcceleratorTarget {
 public:
  ShellAcceleratorController();
  virtual ~ShellAcceleratorController();

  // Register a global keyboard accelerator for the specified target. If
  // multiple targets are registered for an accelerator, a target registered
  // later has higher priority.
  void Register(const ui::Accelerator& accelerator,
                ui::AcceleratorTarget* target);

  // Unregister the specified keyboard accelerator for the specified target.
  void Unregister(const ui::Accelerator& accelerator,
                  ui::AcceleratorTarget* target);

  // Unregister all keyboard accelerators for the specified target.
  void UnregisterAll(ui::AcceleratorTarget* target);

  // Activate the target associated with the specified accelerator.
  // First, AcceleratorPressed handler of the most recently registered target
  // is called, and if that handler processes the event (i.e. returns true),
  // this method immediately returns. If not, we do the same thing on the next
  // target, and so on.
  // Returns true if an accelerator was activated.
  bool Process(const ui::Accelerator& accelerator);

  // Overridden from ui::AcceleratorTarget:
  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;

  void SetScreenshotDelegate(ScreenshotDelegate* screenshot_delegate);

 private:
  // Initialize the accelerators this class handles as a target.
  void Init();

  scoped_ptr<ui::AcceleratorManager> accelerator_manager_;

  scoped_ptr<ScreenshotDelegate> screenshot_delegate_;

  // A map from accelerators to the AcceleratorAction values, which are used in
  // the implementation.
  std::map<ui::Accelerator, int> accelerators_;

  DISALLOW_COPY_AND_ASSIGN(ShellAcceleratorController);
};

}  // namespace aura_shell

#endif  // UI_AURA_SHELL_SHELL_ACCELERATOR_CONTROLLER_H_