Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1614)

Side by Side Diff: ui/views/accessible_pane_view.cc

Issue 10949005: Fix toolbar keyboard accessibility on Views (alternative impl). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux_chromeos compile Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "ui/views/accessible_pane_view.h" 5 #include "ui/views/accessible_pane_view.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "ui/base/accessibility/accessible_view_state.h" 8 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "ui/views/focus/focus_search.h" 9 #include "ui/views/focus/focus_search.h"
10 #include "ui/views/focus/view_storage.h" 10 #include "ui/views/focus/view_storage.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 class AccessiblePaneViewFocusSearch : public FocusSearch {
sky 2012/09/18 21:46:06 Document why this is needed.
dmazzoni 2012/09/19 00:23:40 Done.
16 public:
17 explicit AccessiblePaneViewFocusSearch(AccessiblePaneView* pane_view)
18 : FocusSearch(pane_view, true, true),
19 accessible_pane_view_(pane_view) {}
20
21 protected:
22 virtual View* GetParent(View* v) OVERRIDE {
23 return accessible_pane_view_->ContainsForFocusSearch(root(), v) ?
24 accessible_pane_view_->GetParentForFocusSearch(v) : NULL;
25 }
26
27 // Returns true if |v| is contained within the hierarchy rooted at |root|.
28 // Subclasses can override this if they need custom focus search behavior.
29 virtual bool Contains(View* root, const View* v) OVERRIDE {
30 return accessible_pane_view_->ContainsForFocusSearch(root, v);
31 }
32
33 private:
34 AccessiblePaneView* accessible_pane_view_;
35 };
sky 2012/09/18 21:46:06 DISALLOW_...
dmazzoni 2012/09/19 00:23:40 Done.
36
15 AccessiblePaneView::AccessiblePaneView() 37 AccessiblePaneView::AccessiblePaneView()
16 : pane_has_focus_(false), 38 : pane_has_focus_(false),
17 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 39 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
18 focus_manager_(NULL), 40 focus_manager_(NULL),
19 home_key_(ui::VKEY_HOME, ui::EF_NONE), 41 home_key_(ui::VKEY_HOME, ui::EF_NONE),
20 end_key_(ui::VKEY_END, ui::EF_NONE), 42 end_key_(ui::VKEY_END, ui::EF_NONE),
21 escape_key_(ui::VKEY_ESCAPE, ui::EF_NONE), 43 escape_key_(ui::VKEY_ESCAPE, ui::EF_NONE),
22 left_key_(ui::VKEY_LEFT, ui::EF_NONE), 44 left_key_(ui::VKEY_LEFT, ui::EF_NONE),
23 right_key_(ui::VKEY_RIGHT, ui::EF_NONE) { 45 right_key_(ui::VKEY_RIGHT, ui::EF_NONE) {
24 focus_search_.reset(new views::FocusSearch(this, true, true)); 46 focus_search_.reset(new AccessiblePaneViewFocusSearch(this));
25 } 47 }
26 48
27 AccessiblePaneView::~AccessiblePaneView() { 49 AccessiblePaneView::~AccessiblePaneView() {
28 if (pane_has_focus_) { 50 if (pane_has_focus_) {
29 focus_manager_->RemoveFocusChangeListener(this); 51 focus_manager_->RemoveFocusChangeListener(this);
30 } 52 }
31 } 53 }
32 54
33 bool AccessiblePaneView::SetPaneFocus(views::View* initial_focus) { 55 bool AccessiblePaneView::SetPaneFocus(views::View* initial_focus) {
34 if (!visible()) 56 if (!visible())
35 return false; 57 return false;
36 58
37 if (!focus_manager_) 59 if (!focus_manager_)
38 focus_manager_ = GetFocusManager(); 60 focus_manager_ = GetFocusManager();
39 61
40 focus_manager_->StoreFocusedView(); 62 focus_manager_->StoreFocusedView();
41 63
42 // Use the provided initial focus if it's visible and enabled, otherwise 64 // Use the provided initial focus if it's visible and enabled, otherwise
43 // use the first focusable child. 65 // use the first focusable child.
44 if (!initial_focus || 66 if (!initial_focus ||
45 !Contains(initial_focus) || 67 !ContainsForFocusSearch(this, initial_focus) ||
46 !initial_focus->visible() || 68 !initial_focus->visible() ||
47 !initial_focus->enabled()) { 69 !initial_focus->enabled()) {
48 initial_focus = GetFirstFocusableChild(); 70 initial_focus = GetFirstFocusableChild();
49 } 71 }
50 72
51 // Return false if there are no focusable children. 73 // Return false if there are no focusable children.
52 if (!initial_focus) 74 if (!initial_focus)
53 return false; 75 return false;
54 76
55 focus_manager_->SetFocusedView(initial_focus); 77 focus_manager_->SetFocusedView(initial_focus);
(...skipping 17 matching lines...) Expand all
73 } 95 }
74 96
75 bool AccessiblePaneView::SetPaneFocusAndFocusDefault() { 97 bool AccessiblePaneView::SetPaneFocusAndFocusDefault() {
76 return SetPaneFocus(GetDefaultFocusableChild()); 98 return SetPaneFocus(GetDefaultFocusableChild());
77 } 99 }
78 100
79 views::View* AccessiblePaneView::GetDefaultFocusableChild() { 101 views::View* AccessiblePaneView::GetDefaultFocusableChild() {
80 return NULL; 102 return NULL;
81 } 103 }
82 104
105 View* AccessiblePaneView::GetParentForFocusSearch(View* v) {
106 return v->parent();
107 }
108
109 bool AccessiblePaneView::ContainsForFocusSearch(View* root, const View* v) {
110 return root->Contains(v);
111 }
112
83 void AccessiblePaneView::RemovePaneFocus() { 113 void AccessiblePaneView::RemovePaneFocus() {
84 focus_manager_->RemoveFocusChangeListener(this); 114 focus_manager_->RemoveFocusChangeListener(this);
85 pane_has_focus_ = false; 115 pane_has_focus_ = false;
86 116
87 focus_manager_->UnregisterAccelerator(home_key_, this); 117 focus_manager_->UnregisterAccelerator(home_key_, this);
88 focus_manager_->UnregisterAccelerator(end_key_, this); 118 focus_manager_->UnregisterAccelerator(end_key_, this);
89 focus_manager_->UnregisterAccelerator(escape_key_, this); 119 focus_manager_->UnregisterAccelerator(escape_key_, this);
90 focus_manager_->UnregisterAccelerator(left_key_, this); 120 focus_manager_->UnregisterAccelerator(left_key_, this);
91 focus_manager_->UnregisterAccelerator(right_key_, this); 121 focus_manager_->UnregisterAccelerator(right_key_, this);
92 } 122 }
(...skipping 21 matching lines...) Expand all
114 if (pane_has_focus_) 144 if (pane_has_focus_)
115 return this; 145 return this;
116 else 146 else
117 return NULL; 147 return NULL;
118 } 148 }
119 149
120 bool AccessiblePaneView::AcceleratorPressed( 150 bool AccessiblePaneView::AcceleratorPressed(
121 const ui::Accelerator& accelerator) { 151 const ui::Accelerator& accelerator) {
122 152
123 const views::View* focused_view = focus_manager_->GetFocusedView(); 153 const views::View* focused_view = focus_manager_->GetFocusedView();
124 if (!Contains(focused_view)) 154 if (!ContainsForFocusSearch(this, focused_view))
125 return false; 155 return false;
126 156
127 switch (accelerator.key_code()) { 157 switch (accelerator.key_code()) {
128 case ui::VKEY_ESCAPE: 158 case ui::VKEY_ESCAPE:
129 RemovePaneFocus(); 159 RemovePaneFocus();
130 focus_manager_->RestoreFocusedView(); 160 focus_manager_->RestoreFocusedView();
131 return true; 161 return true;
132 case ui::VKEY_LEFT: 162 case ui::VKEY_LEFT:
133 focus_manager_->AdvanceFocus(true); 163 focus_manager_->AdvanceFocus(true);
134 return true; 164 return true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 199 }
170 200
171 void AccessiblePaneView::OnDidChangeFocus(views::View* focused_before, 201 void AccessiblePaneView::OnDidChangeFocus(views::View* focused_before,
172 views::View* focused_now) { 202 views::View* focused_now) {
173 if (!focused_now) 203 if (!focused_now)
174 return; 204 return;
175 205
176 views::FocusManager::FocusChangeReason reason = 206 views::FocusManager::FocusChangeReason reason =
177 focus_manager_->focus_change_reason(); 207 focus_manager_->focus_change_reason();
178 208
179 if (!Contains(focused_now) || 209 if (!ContainsForFocusSearch(this, focused_now) ||
180 reason == views::FocusManager::kReasonDirectFocusChange) { 210 reason == views::FocusManager::kReasonDirectFocusChange) {
181 // We should remove pane focus (i.e. make most of the controls 211 // We should remove pane focus (i.e. make most of the controls
182 // not focusable again) because the focus has left the pane, 212 // not focusable again) because the focus has left the pane,
183 // or because the focus changed within the pane due to the user 213 // or because the focus changed within the pane due to the user
184 // directly focusing to a specific view (e.g., clicking on it). 214 // directly focusing to a specific view (e.g., clicking on it).
185 RemovePaneFocus(); 215 RemovePaneFocus();
186 } 216 }
187 } 217 }
188 218
189 //////////////////////////////////////////////////////////////////////////////// 219 ////////////////////////////////////////////////////////////////////////////////
190 // FocusTraversable overrides: 220 // FocusTraversable overrides:
191 221
192 views::FocusSearch* AccessiblePaneView::GetFocusSearch() { 222 views::FocusSearch* AccessiblePaneView::GetFocusSearch() {
193 DCHECK(pane_has_focus_); 223 DCHECK(pane_has_focus_);
194 return focus_search_.get(); 224 return focus_search_.get();
195 } 225 }
196 226
197 views::FocusTraversable* AccessiblePaneView::GetFocusTraversableParent() { 227 views::FocusTraversable* AccessiblePaneView::GetFocusTraversableParent() {
198 DCHECK(pane_has_focus_); 228 DCHECK(pane_has_focus_);
199 return NULL; 229 return NULL;
200 } 230 }
201 231
202 views::View* AccessiblePaneView::GetFocusTraversableParentView() { 232 views::View* AccessiblePaneView::GetFocusTraversableParentView() {
203 DCHECK(pane_has_focus_); 233 DCHECK(pane_has_focus_);
204 return NULL; 234 return NULL;
205 } 235 }
206 236
207 } // namespace views 237 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698