cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / accelerators / accelerator_controller.h
bloba6c0a152d2096d2e274034b8a0288eeb8cc07f89
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.
5 #ifndef ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_
6 #define ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_
8 #include <map>
9 #include <set>
11 #include "ash/accelerators/accelerator_table.h"
12 #include "ash/accelerators/exit_warning_handler.h"
13 #include "ash/ash_export.h"
14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h"
16 #include "base/gtest_prod_util.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/accelerators/accelerator_history.h"
21 namespace ui {
22 class AcceleratorManager;
25 namespace ash {
27 struct AcceleratorData;
28 class BrightnessControlDelegate;
29 class ExitWarningHandler;
30 class ImeControlDelegate;
31 class KeyboardBrightnessControlDelegate;
32 class ScreenshotDelegate;
33 class VolumeControlDelegate;
35 // AcceleratorController provides functions for registering or unregistering
36 // global keyboard accelerators, which are handled earlier than any windows. It
37 // also implements several handlers as an accelerator target.
38 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
39 public:
40 AcceleratorController();
41 ~AcceleratorController() override;
43 // A list of possible ways in which an accelerator should be restricted before
44 // processing. Any target registered with this controller should respect
45 // restrictions by calling |GetCurrentAcceleratorRestriction| during
46 // processing.
47 enum AcceleratorProcessingRestriction {
48 // Process the accelerator normally.
49 RESTRICTION_NONE,
51 // Don't process the accelerator.
52 RESTRICTION_PREVENT_PROCESSING,
54 // Don't process the accelerator and prevent propagation to other targets.
55 RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
58 // Registers a global keyboard accelerator for the specified target. If
59 // multiple targets are registered for an accelerator, a target registered
60 // later has higher priority.
61 void Register(const ui::Accelerator& accelerator,
62 ui::AcceleratorTarget* target);
64 // Unregisters the specified keyboard accelerator for the specified target.
65 void Unregister(const ui::Accelerator& accelerator,
66 ui::AcceleratorTarget* target);
68 // Unregisters all keyboard accelerators for the specified target.
69 void UnregisterAll(ui::AcceleratorTarget* target);
71 // Activates the target associated with the specified accelerator.
72 // First, AcceleratorPressed handler of the most recently registered target
73 // is called, and if that handler processes the event (i.e. returns true),
74 // this method immediately returns. If not, we do the same thing on the next
75 // target, and so on.
76 // Returns true if an accelerator was activated.
77 bool Process(const ui::Accelerator& accelerator);
79 // Returns true if the |accelerator| is registered.
80 bool IsRegistered(const ui::Accelerator& accelerator) const;
82 // Returns true if the |accelerator| is preferred. A preferred accelerator
83 // is handled before being passed to an window/web contents, unless
84 // the window is in fullscreen state.
85 bool IsPreferred(const ui::Accelerator& accelerator) const;
87 // Returns true if the |accelerator| is reserved. A reserved accelerator
88 // is always handled and will never be passed to an window/web contents.
89 bool IsReserved(const ui::Accelerator& accelerator) const;
91 // Returns true if the |accelerator| is deprecated. Deprecated accelerators
92 // can be consumed by web contents if needed.
93 bool IsDeprecated(const ui::Accelerator& accelerator) const;
95 // Performs the specified action if it is enabled. Returns whether the action
96 // was performed successfully.
97 bool PerformActionIfEnabled(AcceleratorAction action);
99 // Returns the restriction for the current context.
100 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction();
102 void SetBrightnessControlDelegate(
103 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate);
104 void SetImeControlDelegate(
105 scoped_ptr<ImeControlDelegate> ime_control_delegate);
106 void SetScreenshotDelegate(
107 scoped_ptr<ScreenshotDelegate> screenshot_delegate);
108 BrightnessControlDelegate* brightness_control_delegate() const {
109 return brightness_control_delegate_.get();
111 ScreenshotDelegate* screenshot_delegate() {
112 return screenshot_delegate_.get();
115 // Provides access to the ExitWarningHandler for testing.
116 ExitWarningHandler* GetExitWarningHandlerForTest() {
117 return &exit_warning_handler_;
120 ui::AcceleratorHistory* accelerator_history() {
121 return accelerator_history_.get();
124 // Overridden from ui::AcceleratorTarget:
125 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
126 bool CanHandleAccelerators() const override;
128 private:
129 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators);
130 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest,
131 DontRepeatToggleFullscreen);
133 // Initializes the accelerators this class handles as a target.
134 void Init();
136 // Registers the specified accelerators.
137 void RegisterAccelerators(const AcceleratorData accelerators[],
138 size_t accelerators_length);
140 // Registers the deprecated accelerators and their replacing new ones.
141 void RegisterDeprecatedAccelerators();
143 // Returns whether |action| can be performed. The |accelerator| may provide
144 // additional data the action needs.
145 bool CanPerformAction(AcceleratorAction action,
146 const ui::Accelerator& accelerator);
148 // Performs the specified action. The |accelerator| may provide additional
149 // data the action needs.
150 void PerformAction(AcceleratorAction action,
151 const ui::Accelerator& accelerator);
153 // Returns whether performing |action| should consume the key event.
154 bool ShouldActionConsumeKeyEvent(AcceleratorAction action);
156 // Get the accelerator restriction for the given action. Supply an |action|
157 // of -1 to get restrictions that apply for the current context.
158 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction(
159 int action);
161 void SetKeyboardBrightnessControlDelegate(
162 scoped_ptr<KeyboardBrightnessControlDelegate>
163 keyboard_brightness_control_delegate);
165 scoped_ptr<ui::AcceleratorManager> accelerator_manager_;
167 // A tracker for the current and previous accelerators.
168 scoped_ptr<ui::AcceleratorHistory> accelerator_history_;
170 // TODO(derat): BrightnessControlDelegate is also used by the system tray;
171 // move it outside of this class.
172 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_;
173 scoped_ptr<ImeControlDelegate> ime_control_delegate_;
174 scoped_ptr<KeyboardBrightnessControlDelegate>
175 keyboard_brightness_control_delegate_;
176 scoped_ptr<ScreenshotDelegate> screenshot_delegate_;
178 // Handles the exit accelerator which requires a double press to exit and
179 // shows a popup with an explanation.
180 ExitWarningHandler exit_warning_handler_;
182 // A map from accelerators to the AcceleratorAction values, which are used in
183 // the implementation.
184 std::map<ui::Accelerator, AcceleratorAction> accelerators_;
186 std::map<AcceleratorAction, const DeprecatedAcceleratorData*>
187 actions_with_deprecations_;
188 std::set<ui::Accelerator> deprecated_accelerators_;
190 // Actions allowed when the user is not signed in.
191 std::set<int> actions_allowed_at_login_screen_;
192 // Actions allowed when the screen is locked.
193 std::set<int> actions_allowed_at_lock_screen_;
194 // Actions allowed when a modal window is up.
195 std::set<int> actions_allowed_at_modal_window_;
196 // Preferred actions. See accelerator_table.h for details.
197 std::set<int> preferred_actions_;
198 // Reserved actions. See accelerator_table.h for details.
199 std::set<int> reserved_actions_;
200 // Actions which will not be repeated while holding the accelerator key.
201 std::set<int> nonrepeatable_actions_;
202 // Actions allowed in app mode.
203 std::set<int> actions_allowed_in_app_mode_;
204 // Actions disallowed if there are no windows.
205 std::set<int> actions_needing_window_;
207 DISALLOW_COPY_AND_ASSIGN(AcceleratorController);
210 } // namespace ash
212 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_