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

Unified Diff: ui/views/view.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698