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

Side by Side Diff: ui/views/focus/focus_manager.cc

Issue 1690543004: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix FocusManagerTest.StoreFocusedView Created 4 years, 10 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
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/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 17 matching lines...) Expand all
28 28
29 bool FocusManager::arrow_key_traversal_enabled_ = false; 29 bool FocusManager::arrow_key_traversal_enabled_ = false;
30 30
31 FocusManager::FocusManager(Widget* widget, FocusManagerDelegate* delegate) 31 FocusManager::FocusManager(Widget* widget, FocusManagerDelegate* delegate)
32 : widget_(widget), 32 : widget_(widget),
33 delegate_(delegate), 33 delegate_(delegate),
34 focused_view_(NULL), 34 focused_view_(NULL),
35 accelerator_manager_(new ui::AcceleratorManager), 35 accelerator_manager_(new ui::AcceleratorManager),
36 shortcut_handling_suspended_(false), 36 shortcut_handling_suspended_(false),
37 focus_change_reason_(kReasonDirectFocusChange), 37 focus_change_reason_(kReasonDirectFocusChange),
38 is_changing_focus_(false) { 38 is_changing_focus_(false),
39 keyboard_accessibility_(false) {
39 DCHECK(widget_); 40 DCHECK(widget_);
40 stored_focused_view_storage_id_ = 41 stored_focused_view_storage_id_ =
41 ViewStorage::GetInstance()->CreateStorageID(); 42 ViewStorage::GetInstance()->CreateStorageID();
42 } 43 }
43 44
44 FocusManager::~FocusManager() { 45 FocusManager::~FocusManager() {
45 } 46 }
46 47
47 bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) { 48 bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) {
48 const int key_code = event.key_code(); 49 const int key_code = event.key_code();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // the starting views widget or |widget_|. 291 // the starting views widget or |widget_|.
291 Widget* widget = original_starting_view->GetWidget(); 292 Widget* widget = original_starting_view->GetWidget();
292 if (widget->widget_delegate()->ShouldAdvanceFocusToTopLevelWidget()) 293 if (widget->widget_delegate()->ShouldAdvanceFocusToTopLevelWidget())
293 widget = widget_; 294 widget = widget_;
294 return GetNextFocusableView(NULL, widget, reverse, true); 295 return GetNextFocusableView(NULL, widget, reverse, true);
295 } 296 }
296 } 297 }
297 return NULL; 298 return NULL;
298 } 299 }
299 300
301 void FocusManager::SetKeyboardAccessibility(bool keyboard_accessibility) {
302 keyboard_accessibility_ = keyboard_accessibility;
tapted 2016/02/23 03:01:19 this should early-exit if there is no change
karandeepb 2016/03/15 02:19:50 Done.
303 // Disabling keyboard accessibility may cause the focused view to become not
304 // focusable. Hence advance focus if necessary.
305 AdvanceFocusIfNecessary();
306 }
307
300 void FocusManager::SetFocusedViewWithReason( 308 void FocusManager::SetFocusedViewWithReason(
301 View* view, FocusChangeReason reason) { 309 View* view, FocusChangeReason reason) {
302 if (focused_view_ == view) 310 if (focused_view_ == view)
303 return; 311 return;
304 312
305 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); 313 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true);
306 // Update the reason for the focus change (since this is checked by 314 // Update the reason for the focus change (since this is checked by
307 // some listeners), then notify all listeners. 315 // some listeners), then notify all listeners.
308 focus_change_reason_ = reason; 316 focus_change_reason_ = reason;
309 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, 317 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_,
(...skipping 24 matching lines...) Expand all
334 } 342 }
335 343
336 void FocusManager::AdvanceFocusIfNecessary() { 344 void FocusManager::AdvanceFocusIfNecessary() {
337 // If widget is inactive, there is no focused view to check. The stored view 345 // If widget is inactive, there is no focused view to check. The stored view
338 // will also be checked for focusability when it is being restored. 346 // will also be checked for focusability when it is being restored.
339 if (!widget_->IsActive()) 347 if (!widget_->IsActive())
340 return; 348 return;
341 349
342 // If widget is active and focused view is not focusable, advance focus or, 350 // If widget is active and focused view is not focusable, advance focus or,
343 // if not possible, clear focus. 351 // if not possible, clear focus.
344 if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) { 352 if (focused_view_ && !IsFocusable(focused_view_)) {
345 AdvanceFocus(false); 353 AdvanceFocus(false);
346 if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) 354 if (focused_view_ && !IsFocusable(focused_view_))
347 ClearFocus(); 355 ClearFocus();
348 } 356 }
349 } 357 }
350 358
351 void FocusManager::StoreFocusedView(bool clear_native_focus) { 359 void FocusManager::StoreFocusedView(bool clear_native_focus) {
352 View* focused_view = focused_view_; 360 View* focused_view = focused_view_;
353 // Don't do anything if no focused view. Storing the view (which is NULL), in 361 // Don't do anything if no focused view. Storing the view (which is NULL), in
354 // this case, would clobber the view that was previously saved. 362 // this case, would clobber the view that was previously saved.
355 if (!focused_view_) 363 if (!focused_view_)
356 return; 364 return;
(...skipping 29 matching lines...) Expand all
386 // This usually just sets the focus if this view is focusable, but 394 // This usually just sets the focus if this view is focusable, but
387 // let the view override RequestFocus if necessary. 395 // let the view override RequestFocus if necessary.
388 view->RequestFocus(); 396 view->RequestFocus();
389 397
390 // If it succeeded, the reason would be incorrect; set it to 398 // If it succeeded, the reason would be incorrect; set it to
391 // focus restore. 399 // focus restore.
392 if (focused_view_ == view) 400 if (focused_view_ == view)
393 focus_change_reason_ = kReasonFocusRestore; 401 focus_change_reason_ = kReasonFocusRestore;
394 } 402 }
395 } 403 }
396 return true; 404 // The keyboard_accessibility_ mode may have changed while the widget was
405 // inactive.
406 AdvanceFocusIfNecessary();
397 } 407 }
398 return false; 408 return view == focused_view_;
399 } 409 }
400 410
401 void FocusManager::SetStoredFocusView(View* focus_view) { 411 void FocusManager::SetStoredFocusView(View* focus_view) {
402 ViewStorage* view_storage = ViewStorage::GetInstance(); 412 ViewStorage* view_storage = ViewStorage::GetInstance();
403 if (!view_storage) { 413 if (!view_storage) {
404 // This should never happen but bug 981648 seems to indicate it could. 414 // This should never happen but bug 981648 seems to indicate it could.
405 NOTREACHED(); 415 NOTREACHED();
406 return; 416 return;
407 } 417 }
408 418
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return true; 545 return true;
536 } 546 }
537 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { 547 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) {
538 AdvanceFocus(false); 548 AdvanceFocus(false);
539 return true; 549 return true;
540 } 550 }
541 551
542 return false; 552 return false;
543 } 553 }
544 554
555 bool FocusManager::IsFocusable(View* v) {
tapted 2016/02/23 03:01:19 v -> view
karandeepb 2016/03/15 02:19:50 Done.
556 if (keyboard_accessibility_)
557 return v && v->IsAccessibilityFocusable();
tapted 2016/02/23 03:01:19 I think the null checks are redundant - perhaps DC
karandeepb 2016/03/15 02:19:50 Done.
558 return v && v->IsFocusable();
559 }
560
545 } // namespace views 561 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698