Chromium Code Reviews| Index: ui/views/focus/focus_manager.cc |
| diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc |
| index c84c3152734d2de2994673aee76b89365884d19d..932cae020ac8b7fa3fbf57ecdb57ffa52ba3483e 100644 |
| --- a/ui/views/focus/focus_manager.cc |
| +++ b/ui/views/focus/focus_manager.cc |
| @@ -35,7 +35,8 @@ FocusManager::FocusManager(Widget* widget, FocusManagerDelegate* delegate) |
| accelerator_manager_(new ui::AcceleratorManager), |
| shortcut_handling_suspended_(false), |
| focus_change_reason_(kReasonDirectFocusChange), |
| - is_changing_focus_(false) { |
| + is_changing_focus_(false), |
| + keyboard_accessible_(false) { |
| DCHECK(widget_); |
| stored_focused_view_storage_id_ = |
| ViewStorage::GetInstance()->CreateStorageID(); |
| @@ -297,6 +298,16 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view, |
| return NULL; |
| } |
| +void FocusManager::SetKeyboardAccessible(bool keyboard_accessible) { |
| + if (keyboard_accessible == keyboard_accessible_) |
| + return; |
| + |
| + keyboard_accessible_ = keyboard_accessible; |
| + // Disabling keyboard accessibility may cause the focused view to become not |
| + // focusable. Hence advance focus if necessary. |
| + AdvanceFocusIfNecessary(); |
| +} |
| + |
| void FocusManager::SetFocusedViewWithReason( |
| View* view, FocusChangeReason reason) { |
| if (focused_view_ == view) |
| @@ -341,9 +352,9 @@ void FocusManager::AdvanceFocusIfNecessary() { |
| // If widget is active and focused view is not focusable, advance focus or, |
| // if not possible, clear focus. |
| - if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) { |
| + if (focused_view_ && !IsFocusable(focused_view_)) { |
| AdvanceFocus(false); |
| - if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) |
| + if (focused_view_ && !IsFocusable(focused_view_)) |
| ClearFocus(); |
| } |
| } |
| @@ -378,6 +389,7 @@ bool FocusManager::RestoreFocusedView() { |
| View* view = GetStoredFocusView(); |
| if (view) { |
| if (ContainsView(view)) { |
| + // Todo change this. |
| if (!view->IsFocusable() && view->IsAccessibilityFocusable()) { |
|
karandeepb
2016/03/15 02:19:51
I can't understand the rationale behind this line
tapted
2016/03/15 05:05:31
So I think `RequestFocus` can be overridden by a V
karandeepb
2016/03/17 07:24:46
Thanks!
|
| // RequestFocus would fail, but we want to restore focus to controls |
| // that had focus in accessibility mode. |
| @@ -393,9 +405,11 @@ bool FocusManager::RestoreFocusedView() { |
| focus_change_reason_ = kReasonFocusRestore; |
| } |
| } |
| - return true; |
| + // The |keyboard_accessible_| mode may have changed while the widget was |
| + // inactive. |
| + AdvanceFocusIfNecessary(); |
| } |
| - return false; |
| + return view == focused_view_; |
| } |
| void FocusManager::SetStoredFocusView(View* focus_view) { |
| @@ -542,4 +556,10 @@ bool FocusManager::ProcessArrowKeyTraversal(const ui::KeyEvent& event) { |
| return false; |
| } |
| +bool FocusManager::IsFocusable(View* view) const { |
| + DCHECK(view); |
| + return keyboard_accessible_ ? view->IsAccessibilityFocusable() |
| + : view->IsFocusable(); |
| +} |
| + |
| } // namespace views |