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 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
14 #include "ui/base/accelerators/accelerator.h" | 15 #include "ui/base/accelerators/accelerator.h" |
15 #include "ui/base/accelerators/accelerator_manager.h" | 16 #include "ui/base/accelerators/accelerator_manager.h" |
16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
18 | 19 |
19 // The FocusManager class is used to handle focus traversal, store/restore | 20 // The FocusManager class is used to handle focus traversal, store/restore |
20 // focused views and handle keyboard accelerators. | 21 // focused views and handle keyboard accelerators. |
21 // | 22 // |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 219 |
219 // Changes the text input focus to |view->GetTextInputClient()| iff |view| | 220 // Changes the text input focus to |view->GetTextInputClient()| iff |view| |
220 // is focused. Views must call this method when their internal | 221 // is focused. Views must call this method when their internal |
221 // TextInputClient instance changes. | 222 // TextInputClient instance changes. |
222 void OnTextInputClientChanged(View* view); | 223 void OnTextInputClientChanged(View* view); |
223 | 224 |
224 // Moves the text input focus into/out from |view|. | 225 // Moves the text input focus into/out from |view|. |
225 void FocusTextInputClient(View* view); | 226 void FocusTextInputClient(View* view); |
226 void BlurTextInputClient(View* view); | 227 void BlurTextInputClient(View* view); |
227 | 228 |
228 // Disable shortcut handling. | 229 // Installs a callback to control whether to disable shortcut handling. |
229 static void set_shortcut_handling_suspended(bool suspended) { | 230 // Accelerator processing is skipped if |callback| returns true. |
230 shortcut_handling_suspended_ = suspended; | 231 typedef base::Callback<bool()> ReturnBoolCallback; |
231 } | 232 void set_shortcut_handling_suspended_callback(ReturnBoolCallback* callback); |
| 233 |
232 // Returns whether shortcut handling is currently suspended. | 234 // Returns whether shortcut handling is currently suspended. |
233 bool shortcut_handling_suspended() { return shortcut_handling_suspended_; } | 235 bool shortcut_handling_suspended() const; |
234 | 236 |
235 // Register a keyboard accelerator for the specified target. If multiple | 237 // Register a keyboard accelerator for the specified target. If multiple |
236 // targets are registered for an accelerator, a target registered later has | 238 // targets are registered for an accelerator, a target registered later has |
237 // higher priority. | 239 // higher priority. |
238 // |accelerator| is the accelerator to register. | 240 // |accelerator| is the accelerator to register. |
239 // |priority| denotes the priority of the handler. | 241 // |priority| denotes the priority of the handler. |
240 // NOTE: In almost all cases, you should specify kNormalPriority for this | 242 // NOTE: In almost all cases, you should specify kNormalPriority for this |
241 // parameter. Setting it to kHighPriority prevents Chrome from sending the | 243 // parameter. Setting it to kHighPriority prevents Chrome from sending the |
242 // shortcut to the webpage if the renderer has focus, which is not desirable | 244 // shortcut to the webpage if the renderer has focus, which is not desirable |
243 // except for very isolated cases. | 245 // except for very isolated cases. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // hierarchy. | 339 // hierarchy. |
338 // Returns NULL if no focusable view were found. | 340 // Returns NULL if no focusable view were found. |
339 View* FindFocusableView(FocusTraversable* focus_traversable, | 341 View* FindFocusableView(FocusTraversable* focus_traversable, |
340 View* starting_view, | 342 View* starting_view, |
341 bool reverse); | 343 bool reverse); |
342 | 344 |
343 // Process arrow key traversal. Returns true if the event has been consumed | 345 // Process arrow key traversal. Returns true if the event has been consumed |
344 // and should not be processed further. | 346 // and should not be processed further. |
345 bool ProcessArrowKeyTraversal(const ui::KeyEvent& event); | 347 bool ProcessArrowKeyTraversal(const ui::KeyEvent& event); |
346 | 348 |
347 // Keeps track of whether shortcut handling is currently suspended. | |
348 static bool shortcut_handling_suspended_; | |
349 | |
350 // Whether arrow key traversal is enabled. | 349 // Whether arrow key traversal is enabled. |
351 static bool arrow_key_traversal_enabled_; | 350 static bool arrow_key_traversal_enabled_; |
352 | 351 |
353 // The top-level Widget this FocusManager is associated with. | 352 // The top-level Widget this FocusManager is associated with. |
354 Widget* widget_; | 353 Widget* widget_; |
355 | 354 |
356 // The object which handles an accelerator when |accelerator_manager_| doesn't | 355 // The object which handles an accelerator when |accelerator_manager_| doesn't |
357 // handle it. | 356 // handle it. |
358 scoped_ptr<FocusManagerDelegate> delegate_; | 357 scoped_ptr<FocusManagerDelegate> delegate_; |
359 | 358 |
360 // The view that currently is focused. | 359 // The view that currently is focused. |
361 View* focused_view_; | 360 View* focused_view_; |
362 | 361 |
363 // The AcceleratorManager this FocusManager is associated with. | 362 // The AcceleratorManager this FocusManager is associated with. |
364 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; | 363 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; |
365 | 364 |
| 365 // Accelerator processing is skipped if this callback returns true. |
| 366 ReturnBoolCallback* shortcut_handling_suspended_callback_; |
| 367 |
366 // The storage id used in the ViewStorage to store/restore the view that last | 368 // The storage id used in the ViewStorage to store/restore the view that last |
367 // had focus. | 369 // had focus. |
368 int stored_focused_view_storage_id_; | 370 int stored_focused_view_storage_id_; |
369 | 371 |
370 // The reason why the focus most recently changed. | 372 // The reason why the focus most recently changed. |
371 FocusChangeReason focus_change_reason_; | 373 FocusChangeReason focus_change_reason_; |
372 | 374 |
373 // The list of registered FocusChange listeners. | 375 // The list of registered FocusChange listeners. |
374 ObserverList<FocusChangeListener, true> focus_change_listeners_; | 376 ObserverList<FocusChangeListener, true> focus_change_listeners_; |
375 | 377 |
376 // See description above getter. | 378 // See description above getter. |
377 bool is_changing_focus_; | 379 bool is_changing_focus_; |
378 | 380 |
379 DISALLOW_COPY_AND_ASSIGN(FocusManager); | 381 DISALLOW_COPY_AND_ASSIGN(FocusManager); |
380 }; | 382 }; |
381 | 383 |
382 } // namespace views | 384 } // namespace views |
383 | 385 |
384 #endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ | 386 #endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ |
OLD | NEW |