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

Side by Side Diff: chrome/browser/views/accessible_toolbar_view.cc

Issue 2817022: Small tweaks to improve toolbar keyboard accessibility: Put focus rects... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "chrome/browser/view_ids.h" 6 #include "chrome/browser/view_ids.h"
7 #include "chrome/browser/views/frame/browser_view.h" 7 #include "chrome/browser/views/frame/browser_view.h"
8 #include "chrome/browser/views/location_bar/location_bar_view.h"
8 #include "chrome/browser/views/accessible_toolbar_view.h" 9 #include "chrome/browser/views/accessible_toolbar_view.h"
9 #include "views/controls/button/menu_button.h" 10 #include "views/controls/button/menu_button.h"
10 #include "views/controls/native/native_view_host.h" 11 #include "views/controls/native/native_view_host.h"
11 #include "views/focus/focus_search.h" 12 #include "views/focus/focus_search.h"
12 #include "views/focus/view_storage.h" 13 #include "views/focus/view_storage.h"
13 #include "views/widget/tooltip_manager.h" 14 #include "views/widget/tooltip_manager.h"
14 #include "views/widget/widget.h" 15 #include "views/widget/widget.h"
15 16
16 AccessibleToolbarView::AccessibleToolbarView() 17 AccessibleToolbarView::AccessibleToolbarView()
17 : toolbar_has_focus_(false), 18 : toolbar_has_focus_(false),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 focus_manager_->AddFocusChangeListener(this); 75 focus_manager_->AddFocusChangeListener(this);
75 76
76 return true; 77 return true;
77 } 78 }
78 79
79 bool AccessibleToolbarView::SetToolbarFocusAndFocusDefault( 80 bool AccessibleToolbarView::SetToolbarFocusAndFocusDefault(
80 int view_storage_id) { 81 int view_storage_id) {
81 return SetToolbarFocus(view_storage_id, GetDefaultFocusableChild()); 82 return SetToolbarFocus(view_storage_id, GetDefaultFocusableChild());
82 } 83 }
83 84
84 void AccessibleToolbarView::RemoveToolbarFocusIfNoChildHasFocus() {
85 views::View* focused_view = focus_manager_->GetFocusedView();
86 if (toolbar_has_focus_ && (!focused_view || !IsParentOf(focused_view)))
87 RemoveToolbarFocus();
88 }
89
90 void AccessibleToolbarView::RemoveToolbarFocus() { 85 void AccessibleToolbarView::RemoveToolbarFocus() {
91 focus_manager_->RemoveFocusChangeListener(this); 86 focus_manager_->RemoveFocusChangeListener(this);
92 toolbar_has_focus_ = false; 87 toolbar_has_focus_ = false;
93 88
94 focus_manager_->UnregisterAccelerator(home_key_, this); 89 focus_manager_->UnregisterAccelerator(home_key_, this);
95 focus_manager_->UnregisterAccelerator(end_key_, this); 90 focus_manager_->UnregisterAccelerator(end_key_, this);
96 focus_manager_->UnregisterAccelerator(escape_key_, this); 91 focus_manager_->UnregisterAccelerator(escape_key_, this);
97 focus_manager_->UnregisterAccelerator(left_key_, this); 92 focus_manager_->UnregisterAccelerator(left_key_, this);
98 focus_manager_->UnregisterAccelerator(right_key_, this); 93 focus_manager_->UnregisterAccelerator(right_key_, this);
99 } 94 }
100 95
96 void AccessibleToolbarView::RemoveToolbarFocusIfNoChildHasFocus() {
97 views::View* focused_view = focus_manager_->GetFocusedView();
98 if (toolbar_has_focus_ && (!focused_view || !IsParentOf(focused_view)))
99 RemoveToolbarFocus();
100 }
101
101 void AccessibleToolbarView::RestoreLastFocusedView() { 102 void AccessibleToolbarView::RestoreLastFocusedView() {
102 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); 103 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
103 views::View* last_focused_view = 104 views::View* last_focused_view =
104 view_storage->RetrieveView(last_focused_view_storage_id_); 105 view_storage->RetrieveView(last_focused_view_storage_id_);
105 if (last_focused_view) { 106 if (last_focused_view) {
106 focus_manager_->SetFocusedView(last_focused_view); 107 focus_manager_->SetFocusedView(last_focused_view);
107 } else { 108 } else {
108 // Focus the location bar 109 // Focus the location bar
109 views::View* view = GetAncestorWithClassName(BrowserView::kViewClassName); 110 views::View* view = GetAncestorWithClassName(BrowserView::kViewClassName);
110 if (view) { 111 if (view) {
(...skipping 24 matching lines...) Expand all
135 136
136 views::FocusTraversable* AccessibleToolbarView::GetPaneFocusTraversable() { 137 views::FocusTraversable* AccessibleToolbarView::GetPaneFocusTraversable() {
137 if (toolbar_has_focus_) 138 if (toolbar_has_focus_)
138 return this; 139 return this;
139 else 140 else
140 return NULL; 141 return NULL;
141 } 142 }
142 143
143 bool AccessibleToolbarView::AcceleratorPressed( 144 bool AccessibleToolbarView::AcceleratorPressed(
144 const views::Accelerator& accelerator) { 145 const views::Accelerator& accelerator) {
145 // Special case: don't handle arrows for native views, like the 146 // Special case: don't handle arrows for certain views, like the
146 // location bar's edit text view, which needs them for text editing. 147 // location bar's edit text view, which need them for text editing.
147 views::View* focused_view = focus_manager_->GetFocusedView(); 148 views::View* focused_view = focus_manager_->GetFocusedView();
148 if (focused_view->GetClassName() == views::NativeViewHost::kViewClassName && 149 if ((focused_view->GetClassName() == LocationBarView::kViewClassName ||
150 focused_view->GetClassName() == views::NativeViewHost::kViewClassName) &&
149 (accelerator.GetKeyCode() == base::VKEY_LEFT || 151 (accelerator.GetKeyCode() == base::VKEY_LEFT ||
150 accelerator.GetKeyCode() == base::VKEY_RIGHT)) { 152 accelerator.GetKeyCode() == base::VKEY_RIGHT)) {
151 return false; 153 return false;
152 } 154 }
153 155
154 switch (accelerator.GetKeyCode()) { 156 switch (accelerator.GetKeyCode()) {
155 case base::VKEY_ESCAPE: 157 case base::VKEY_ESCAPE:
156 RemoveToolbarFocus(); 158 RemoveToolbarFocus();
157 RestoreLastFocusedView(); 159 RestoreLastFocusedView();
158 return true; 160 return true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 221
220 views::FocusTraversable* AccessibleToolbarView::GetFocusTraversableParent() { 222 views::FocusTraversable* AccessibleToolbarView::GetFocusTraversableParent() {
221 DCHECK(toolbar_has_focus_); 223 DCHECK(toolbar_has_focus_);
222 return NULL; 224 return NULL;
223 } 225 }
224 226
225 views::View* AccessibleToolbarView::GetFocusTraversableParentView() { 227 views::View* AccessibleToolbarView::GetFocusTraversableParentView() {
226 DCHECK(toolbar_has_focus_); 228 DCHECK(toolbar_has_focus_);
227 return NULL; 229 return NULL;
228 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698