OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ | 5 #ifndef UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ |
6 #define UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ | 6 #define UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "ui/base/accelerators/accelerator_manager.h" |
15 #include "ui/base/accelerators/accelerator.h" | 16 #include "ui/base/accelerators/accelerator.h" |
16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/views/events/event.h" | 18 #include "ui/views/events/event.h" |
18 #include "ui/views/views_export.h" | 19 #include "ui/views/views_export.h" |
19 | 20 |
20 // The FocusManager class is used to handle focus traversal, store/restore | 21 // The FocusManager class is used to handle focus traversal, store/restore |
21 // focused views and handle keyboard accelerators. | 22 // focused views and handle keyboard accelerators. |
22 // | 23 // |
23 // There are 2 types of focus: | 24 // There are 2 types of focus: |
24 // - the native focus, which is the focus that an gfx::NativeView has. | 25 // - the native focus, which is the focus that an gfx::NativeView has. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 183 |
183 // Clears the stored focused view. | 184 // Clears the stored focused view. |
184 void ClearStoredFocusedView(); | 185 void ClearStoredFocusedView(); |
185 | 186 |
186 // Returns true if in the process of changing the focused view. | 187 // Returns true if in the process of changing the focused view. |
187 bool is_changing_focus() const { return is_changing_focus_; } | 188 bool is_changing_focus() const { return is_changing_focus_; } |
188 | 189 |
189 // Register a keyboard accelerator for the specified target. If multiple | 190 // Register a keyboard accelerator for the specified target. If multiple |
190 // targets are registered for an accelerator, a target registered later has | 191 // targets are registered for an accelerator, a target registered later has |
191 // higher priority. | 192 // higher priority. |
| 193 // |accelerator| is the accelerator to register. |
| 194 // |priority| denotes the priority of the handler. |
| 195 // NOTE: In almost all cases, you should specify kPriorityNormal for this |
| 196 // parameter. Setting it to kPriorityHigh prevents Chrome from sending the |
| 197 // shortcut to the webpage if the renderer has focus, which is not desirable |
| 198 // except for very isolated cases. |
| 199 // |target| is the AcceleratorTarget that handles the event once the |
| 200 // accelerator is pressed. |
192 // Note that we are currently limited to accelerators that are either: | 201 // Note that we are currently limited to accelerators that are either: |
193 // - a key combination including Ctrl or Alt | 202 // - a key combination including Ctrl or Alt |
194 // - the escape key | 203 // - the escape key |
195 // - the enter key | 204 // - the enter key |
196 // - any F key (F1, F2, F3 ...) | 205 // - any F key (F1, F2, F3 ...) |
197 // - any browser specific keys (as available on special keyboards) | 206 // - any browser specific keys (as available on special keyboards) |
198 void RegisterAccelerator(const ui::Accelerator& accelerator, | 207 void RegisterAccelerator(const ui::Accelerator& accelerator, |
| 208 ui::AcceleratorManager::HandlerPriority priority, |
199 ui::AcceleratorTarget* target); | 209 ui::AcceleratorTarget* target); |
200 | 210 |
201 // Unregister the specified keyboard accelerator for the specified target. | 211 // Unregister the specified keyboard accelerator for the specified target. |
202 void UnregisterAccelerator(const ui::Accelerator& accelerator, | 212 void UnregisterAccelerator(const ui::Accelerator& accelerator, |
203 ui::AcceleratorTarget* target); | 213 ui::AcceleratorTarget* target); |
204 | 214 |
205 // Unregister all keyboard accelerator for the specified target. | 215 // Unregister all keyboard accelerator for the specified target. |
206 void UnregisterAccelerators(ui::AcceleratorTarget* target); | 216 void UnregisterAccelerators(ui::AcceleratorTarget* target); |
207 | 217 |
208 // Activate the target associated with the specified accelerator. | 218 // Activate the target associated with the specified accelerator. |
(...skipping 23 matching lines...) Expand all Loading... |
232 // the focused view is about to change. | 242 // the focused view is about to change. |
233 void AddFocusChangeListener(FocusChangeListener* listener); | 243 void AddFocusChangeListener(FocusChangeListener* listener); |
234 void RemoveFocusChangeListener(FocusChangeListener* listener); | 244 void RemoveFocusChangeListener(FocusChangeListener* listener); |
235 | 245 |
236 // Returns the AcceleratorTarget that should be activated for the specified | 246 // Returns the AcceleratorTarget that should be activated for the specified |
237 // keyboard accelerator, or NULL if no view is registered for that keyboard | 247 // keyboard accelerator, or NULL if no view is registered for that keyboard |
238 // accelerator. | 248 // accelerator. |
239 ui::AcceleratorTarget* GetCurrentTargetForAccelerator( | 249 ui::AcceleratorTarget* GetCurrentTargetForAccelerator( |
240 const ui::Accelerator& accelertor) const; | 250 const ui::Accelerator& accelertor) const; |
241 | 251 |
| 252 // Whether the given |accelerator| has a priority handler associated with it. |
| 253 bool HasPriorityHandler(const ui::Accelerator& accelerator) const; |
| 254 |
242 // Clears the native view having the focus. | 255 // Clears the native view having the focus. |
243 virtual void ClearNativeFocus(); | 256 virtual void ClearNativeFocus(); |
244 | 257 |
245 // Convenience method that returns true if the passed |key_event| should | 258 // Convenience method that returns true if the passed |key_event| should |
246 // trigger tab traversal (if it is a TAB key press with or without SHIFT | 259 // trigger tab traversal (if it is a TAB key press with or without SHIFT |
247 // pressed). | 260 // pressed). |
248 static bool IsTabTraversalKeyEvent(const KeyEvent& key_event); | 261 static bool IsTabTraversalKeyEvent(const KeyEvent& key_event); |
249 | 262 |
250 private: | 263 private: |
251 // Returns the next focusable view. | 264 // Returns the next focusable view. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 298 |
286 // See description above getter. | 299 // See description above getter. |
287 bool is_changing_focus_; | 300 bool is_changing_focus_; |
288 | 301 |
289 DISALLOW_COPY_AND_ASSIGN(FocusManager); | 302 DISALLOW_COPY_AND_ASSIGN(FocusManager); |
290 }; | 303 }; |
291 | 304 |
292 } // namespace views | 305 } // namespace views |
293 | 306 |
294 #endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ | 307 #endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ |
OLD | NEW |