OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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. | |
4 | |
5 #ifndef VIEWS_ACCESSIBLE_PANE_VIEW_H_ | |
6 #define VIEWS_ACCESSIBLE_PANE_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include "base/hash_tables.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "ui/base/accelerators/accelerator.h" | |
13 #include "ui/views/focus/focus_manager.h" | |
14 #include "ui/views/view.h" | |
15 | |
16 namespace views { | |
17 class FocusSearch; | |
18 | |
19 // This class provides keyboard access to any view that extends it, typically | |
20 // a toolbar. The user sets focus to a control in this view by pressing | |
21 // F6 to traverse all panes, or by pressing a shortcut that jumps directly | |
22 // to this pane. | |
23 class VIEWS_EXPORT AccessiblePaneView : public View, | |
24 public FocusChangeListener, | |
25 public FocusTraversable { | |
26 public: | |
27 AccessiblePaneView(); | |
28 virtual ~AccessiblePaneView(); | |
29 | |
30 // Set focus to the pane with complete keyboard access. | |
31 // Focus will be restored to the last focused view if the user escapes. | |
32 // If |initial_focus| is not NULL, that control will get | |
33 // the initial focus, if it's enabled and focusable. Returns true if | |
34 // the pane was able to receive focus. | |
35 virtual bool SetPaneFocus(View* initial_focus); | |
36 | |
37 // Set focus to the pane with complete keyboard access, with the | |
38 // focus initially set to the default child. Focus will be restored | |
39 // to the last focused view if the user escapes. | |
40 // Returns true if the pane was able to receive focus. | |
41 virtual bool SetPaneFocusAndFocusDefault(); | |
42 | |
43 // Overridden from View: | |
44 virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE; | |
45 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) | |
46 OVERRIDE; | |
47 virtual void SetVisible(bool flag) OVERRIDE; | |
48 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
49 | |
50 // Overridden from FocusChangeListener: | |
51 virtual void OnWillChangeFocus(View* focused_before, | |
52 View* focused_now) OVERRIDE; | |
53 virtual void OnDidChangeFocus(View* focused_before, | |
54 View* focused_now) OVERRIDE; | |
55 | |
56 // Overridden from FocusTraversable: | |
57 virtual FocusSearch* GetFocusSearch() OVERRIDE; | |
58 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; | |
59 virtual View* GetFocusTraversableParentView() OVERRIDE; | |
60 | |
61 protected: | |
62 // A subclass can override this to provide a default focusable child | |
63 // other than the first focusable child. | |
64 virtual View* GetDefaultFocusableChild(); | |
65 | |
66 // Remove pane focus. | |
67 virtual void RemovePaneFocus(); | |
68 | |
69 void RestoreLastFocusedView(); | |
70 | |
71 View* GetFirstFocusableChild(); | |
72 View* GetLastFocusableChild(); | |
73 | |
74 bool pane_has_focus_; | |
75 | |
76 base::WeakPtrFactory<AccessiblePaneView> method_factory_; | |
77 | |
78 // Save the focus manager rather than calling GetFocusManager(), | |
79 // so that we can remove focus listeners in the destructor. | |
80 FocusManager* focus_manager_; | |
81 | |
82 // Our custom focus search implementation that traps focus in this | |
83 // pane and traverses all views that are focusable for accessibility, | |
84 // not just those that are normally focusable. | |
85 scoped_ptr<FocusSearch> focus_search_; | |
86 | |
87 // Registered accelerators | |
88 ui::Accelerator home_key_; | |
89 ui::Accelerator end_key_; | |
90 ui::Accelerator escape_key_; | |
91 ui::Accelerator left_key_; | |
92 ui::Accelerator right_key_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView); | |
95 }; | |
96 | |
97 } // namespace views | |
98 | |
99 #endif // VIEWS_ACCESSIBLE_PANE_VIEW_H_ | |
OLD | NEW |