Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / accessible_pane_view.h
blob1fc5c2d68bf1aa5f1f79386b6d72a1dfa16d7783
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.
5 #ifndef UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_
6 #define UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_
8 #include "base/containers/hash_tables.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "ui/base/accelerators/accelerator.h"
12 #include "ui/views/focus/focus_manager.h"
13 #include "ui/views/view.h"
15 namespace views {
16 class FocusSearch;
18 // This class provides keyboard access to any view that extends it, typically
19 // a toolbar. The user sets focus to a control in this view by pressing
20 // F6 to traverse all panes, or by pressing a shortcut that jumps directly
21 // to this pane.
22 class VIEWS_EXPORT AccessiblePaneView : public View,
23 public FocusChangeListener,
24 public FocusTraversable {
25 public:
26 AccessiblePaneView();
27 ~AccessiblePaneView() override;
29 // Set focus to the pane with complete keyboard access.
30 // Focus will be restored to the last focused view if the user escapes.
31 // If |initial_focus| is not NULL, that control will get
32 // the initial focus, if it's enabled and focusable. Returns true if
33 // the pane was able to receive focus.
34 virtual bool SetPaneFocus(View* initial_focus);
36 // Set focus to the pane with complete keyboard access, with the
37 // focus initially set to the default child. Focus will be restored
38 // to the last focused view if the user escapes.
39 // Returns true if the pane was able to receive focus.
40 virtual bool SetPaneFocusAndFocusDefault();
42 // Overridden from View:
43 FocusTraversable* GetPaneFocusTraversable() override;
44 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
45 void SetVisible(bool flag) override;
46 void GetAccessibleState(ui::AXViewState* state) override;
47 void RequestFocus() override;
49 // Overridden from FocusChangeListener:
50 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
51 void OnDidChangeFocus(View* focused_before, View* focused_now) override;
53 // Overridden from FocusTraversable:
54 FocusSearch* GetFocusSearch() override;
55 FocusTraversable* GetFocusTraversableParent() override;
56 View* GetFocusTraversableParentView() override;
58 // For testing only.
59 const ui::Accelerator& home_key() const { return home_key_; }
60 const ui::Accelerator& end_key() const { return end_key_; }
61 const ui::Accelerator& escape_key() const { return escape_key_; }
62 const ui::Accelerator& left_key() const { return left_key_; }
63 const ui::Accelerator& right_key() const { return right_key_; }
65 protected:
66 // A subclass can override this to provide a default focusable child
67 // other than the first focusable child.
68 virtual View* GetDefaultFocusableChild();
70 // Returns the parent of |v|. Subclasses can override this if
71 // they need custom focus search behavior.
72 virtual View* GetParentForFocusSearch(View* v);
74 // Returns true if |v| is contained within the hierarchy rooted at |root|
75 // for the purpose of focus searching. Subclasses can override this if
76 // they need custom focus search behavior.
77 virtual bool ContainsForFocusSearch(View* root, const View* v);
79 // Remove pane focus.
80 virtual void RemovePaneFocus();
82 View* GetFirstFocusableChild();
83 View* GetLastFocusableChild();
85 FocusManager* focus_manager() const { return focus_manager_; }
87 // When finishing navigation by pressing ESC, it is allowed to surrender the
88 // focus to another window if if |allow| is set and no previous view can be
89 // found.
90 void set_allow_deactivate_on_esc(bool allow) {
91 allow_deactivate_on_esc_ = allow;
94 private:
95 bool pane_has_focus_;
97 // If true, the panel should be de-activated upon escape when no active view
98 // is known where to return to.
99 bool allow_deactivate_on_esc_;
101 // Save the focus manager rather than calling GetFocusManager(),
102 // so that we can remove focus listeners in the destructor.
103 FocusManager* focus_manager_;
105 // Our custom focus search implementation that traps focus in this
106 // pane and traverses all views that are focusable for accessibility,
107 // not just those that are normally focusable.
108 scoped_ptr<FocusSearch> focus_search_;
110 // Registered accelerators
111 ui::Accelerator home_key_;
112 ui::Accelerator end_key_;
113 ui::Accelerator escape_key_;
114 ui::Accelerator left_key_;
115 ui::Accelerator right_key_;
117 // View storage id for the last focused view that's not within this pane.
118 int last_focused_view_storage_id_;
120 friend class AccessiblePaneViewFocusSearch;
122 base::WeakPtrFactory<AccessiblePaneView> method_factory_;
124 DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView);
127 } // namespace views
129 #endif // UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_