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

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

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Rebased. Created 4 years, 8 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_accessible_(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::SetKeyboardAccessible(bool keyboard_accessible) {
302 if (keyboard_accessible == keyboard_accessible_)
303 return;
304
305 keyboard_accessible_ = keyboard_accessible;
306 // Disabling keyboard accessibility may cause the focused view to become not
307 // focusable. Hence advance focus if necessary.
308 AdvanceFocusIfNecessary();
309 }
310
300 void FocusManager::SetFocusedViewWithReason( 311 void FocusManager::SetFocusedViewWithReason(
301 View* view, FocusChangeReason reason) { 312 View* view, FocusChangeReason reason) {
302 if (focused_view_ == view) 313 if (focused_view_ == view)
303 return; 314 return;
304 315
305 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); 316 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true);
306 // Update the reason for the focus change (since this is checked by 317 // Update the reason for the focus change (since this is checked by
307 // some listeners), then notify all listeners. 318 // some listeners), then notify all listeners.
308 focus_change_reason_ = reason; 319 focus_change_reason_ = reason;
309 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, 320 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_,
(...skipping 24 matching lines...) Expand all
334 } 345 }
335 346
336 void FocusManager::AdvanceFocusIfNecessary() { 347 void FocusManager::AdvanceFocusIfNecessary() {
337 // If widget is inactive, there is no focused view to check. The stored view 348 // 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. 349 // will also be checked for focusability when it is being restored.
339 if (!widget_->IsActive()) 350 if (!widget_->IsActive())
340 return; 351 return;
341 352
342 // If widget is active and focused view is not focusable, advance focus or, 353 // If widget is active and focused view is not focusable, advance focus or,
343 // if not possible, clear focus. 354 // if not possible, clear focus.
344 if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) { 355 if (focused_view_ && !IsFocusable(focused_view_)) {
345 AdvanceFocus(false); 356 AdvanceFocus(false);
346 if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) 357 if (focused_view_ && !IsFocusable(focused_view_))
347 ClearFocus(); 358 ClearFocus();
348 } 359 }
349 } 360 }
350 361
351 void FocusManager::StoreFocusedView(bool clear_native_focus) { 362 void FocusManager::StoreFocusedView(bool clear_native_focus) {
352 View* focused_view = focused_view_; 363 View* focused_view = focused_view_;
353 // Don't do anything if no focused view. Storing the view (which is NULL), in 364 // 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. 365 // this case, would clobber the view that was previously saved.
355 if (!focused_view_) 366 if (!focused_view_)
356 return; 367 return;
(...skipping 29 matching lines...) Expand all
386 // This usually just sets the focus if this view is focusable, but 397 // This usually just sets the focus if this view is focusable, but
387 // let the view override RequestFocus if necessary. 398 // let the view override RequestFocus if necessary.
388 view->RequestFocus(); 399 view->RequestFocus();
389 400
390 // If it succeeded, the reason would be incorrect; set it to 401 // If it succeeded, the reason would be incorrect; set it to
391 // focus restore. 402 // focus restore.
392 if (focused_view_ == view) 403 if (focused_view_ == view)
393 focus_change_reason_ = kReasonFocusRestore; 404 focus_change_reason_ = kReasonFocusRestore;
394 } 405 }
395 } 406 }
396 return true; 407 // The |keyboard_accessible_| mode may have changed while the widget was
408 // inactive.
409 AdvanceFocusIfNecessary();
397 } 410 }
398 return false; 411 return view && view == focused_view_;
399 } 412 }
400 413
401 void FocusManager::SetStoredFocusView(View* focus_view) { 414 void FocusManager::SetStoredFocusView(View* focus_view) {
402 ViewStorage* view_storage = ViewStorage::GetInstance(); 415 ViewStorage* view_storage = ViewStorage::GetInstance();
403 if (!view_storage) { 416 if (!view_storage) {
404 // This should never happen but bug 981648 seems to indicate it could. 417 // This should never happen but bug 981648 seems to indicate it could.
405 NOTREACHED(); 418 NOTREACHED();
406 return; 419 return;
407 } 420 }
408 421
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return true; 548 return true;
536 } 549 }
537 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { 550 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) {
538 AdvanceFocus(false); 551 AdvanceFocus(false);
539 return true; 552 return true;
540 } 553 }
541 554
542 return false; 555 return false;
543 } 556 }
544 557
558 bool FocusManager::IsFocusable(View* view) const {
559 DCHECK(view);
560
561 // |keyboard_accessible_| is only used on Mac.
562 #if defined(OS_MACOSX)
563 return keyboard_accessible_ ? view->IsAccessibilityFocusable()
564 : view->IsFocusable();
565 #else
566 return view->IsAccessibilityFocusable();
567 #endif
568 }
569
545 } // namespace views 570 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698