Chromium Code Reviews| Index: ui/views/view.cc |
| diff --git a/ui/views/view.cc b/ui/views/view.cc |
| index 349b0ddbcaa5d9b8ae97176ad97076c36e14eb01..bb9ff1ab878e4e3e33b12ca26564db084afc2c17 100644 |
| --- a/ui/views/view.cc |
| +++ b/ui/views/view.cc |
| @@ -406,6 +406,7 @@ void View::SetVisible(bool visible) { |
| SchedulePaint(); |
| visible_ = visible; |
| + AdvanceFocusIfNecessary(); |
| // Notify the parent. |
| if (parent_) |
| @@ -428,6 +429,7 @@ bool View::IsDrawn() const { |
| void View::SetEnabled(bool enabled) { |
| if (enabled != enabled_) { |
| enabled_ = enabled; |
| + AdvanceFocusIfNecessary(); |
| OnEnabledChanged(); |
| } |
| } |
| @@ -1144,6 +1146,7 @@ void View::SetFocusable(bool focusable) { |
| return; |
| focusable_ = focusable; |
| + AdvanceFocusIfNecessary(); |
| } |
| bool View::IsFocusable() const { |
| @@ -1159,6 +1162,7 @@ void View::SetAccessibilityFocusable(bool accessibility_focusable) { |
| return; |
| accessibility_focusable_ = accessibility_focusable; |
| + AdvanceFocusIfNecessary(); |
| } |
| FocusManager* View::GetFocusManager() { |
| @@ -2371,6 +2375,19 @@ void View::InitFocusSiblings(View* v, int index) { |
| } |
| } |
| +void View::AdvanceFocusIfNecessary() { |
| + // Focus should only be advanced if this is the focused view and has become |
| + // unfocusable. If the view is still focusable or is not focused, we can |
| + // return early avoiding furthur unnecessary checks. Focusability check is |
| + // performed first as it tends to be faster. |
| + if (IsAccessibilityFocusable() || !HasFocus()) |
|
sky
2014/08/11 16:10:51
HasFocus has to walk the tree to find the FM, whic
mohsen
2014/08/11 16:30:00
The goal for this early out is not improving effic
|
| + return; |
| + |
| + FocusManager* focus_manager = GetFocusManager(); |
| + if (focus_manager) |
| + focus_manager->AdvanceFocusIfNecessary(); |
| +} |
| + |
| // System events --------------------------------------------------------------- |
| void View::PropagateThemeChanged() { |