Chromium Code Reviews| Index: ui/views/view.cc |
| diff --git a/ui/views/view.cc b/ui/views/view.cc |
| index f74d0f9e79014748448da8bbece2de023ab2217d..5562a2252a276dcc6e3caa767eb30d1f87fcefae 100644 |
| --- a/ui/views/view.cc |
| +++ b/ui/views/view.cc |
| @@ -454,6 +454,13 @@ void View::SetVisible(bool visible) { |
| visible_ = visible; |
| + if (!visible) { |
|
sky
2013/12/07 00:29:13
You have this code in a bunch of places. I think w
mohsen
2013/12/11 20:10:12
I have extracted the common code and moved it to t
|
| + // If the View has focus or contains the focused view, clear focus. |
| + FocusManager* focus_manager = GetFocusManager(); |
| + if (focus_manager && Contains(focus_manager->GetFocusedView())) |
| + focus_manager->ClearFocus(); |
| + } |
| + |
| // Notify the parent. |
| if (parent_) |
| parent_->ChildVisibilityChanged(this); |
| @@ -475,6 +482,12 @@ bool View::IsDrawn() const { |
| void View::SetEnabled(bool enabled) { |
| if (enabled != enabled_) { |
| enabled_ = enabled; |
| + if (!enabled) { |
| + // If the View has focus, clear focus. |
| + FocusManager* focus_manager = GetFocusManager(); |
| + if (focus_manager && focus_manager->GetFocusedView() == this) |
| + focus_manager->ClearFocus(); |
| + } |
| OnEnabledChanged(); |
| } |
| } |
| @@ -1205,6 +1218,16 @@ void View::SetNextFocusableView(View* view) { |
| next_focusable_view_ = view; |
| } |
| +void View::SetFocusable(bool focusable) { |
| + focusable_ = focusable; |
| + if (!focusable && !IsAccessibilityFocusable()) { |
| + // If the View has focus, clear focus. |
| + FocusManager* focus_manager = GetFocusManager(); |
| + if (focus_manager && focus_manager->GetFocusedView() == this) |
| + focus_manager->ClearFocus(); |
| + } |
| +} |
| + |
| bool View::IsFocusable() const { |
| return focusable_ && enabled_ && IsDrawn(); |
| } |
| @@ -1213,6 +1236,16 @@ bool View::IsAccessibilityFocusable() const { |
| return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); |
| } |
| +void View::SetAccessibilityFocusable(bool accessibility_focusable) { |
| + accessibility_focusable_ = accessibility_focusable; |
| + if (!accessibility_focusable && !IsFocusable()) { |
| + // If the View has focus, clear focus. |
| + FocusManager* focus_manager = GetFocusManager(); |
| + if (focus_manager && focus_manager->GetFocusedView() == this) |
| + focus_manager->ClearFocus(); |
| + } |
| +} |
| + |
| FocusManager* View::GetFocusManager() { |
| Widget* widget = GetWidget(); |
| return widget ? widget->GetFocusManager() : NULL; |