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

Unified Diff: ui/views/widget/widget.cc

Issue 2604303002: (Mac)Views: Widgets focus first View in traversal order if initial focus fails. (Closed)
Patch Set: Add test. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/widget/widget.cc
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index 08578add8f534fe637481183fd005dbc34a58a1c..a3e135398ac3406bd2935bf38d000ef0d9e7c4d1 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -1303,17 +1303,26 @@ const Widget* Widget::AsWidget() const {
}
bool Widget::SetInitialFocus(ui::WindowShowState show_state) {
+ FocusManager* focus_manager = GetFocusManager();
+ if (!focus_manager)
+ return false;
tapted 2017/01/06 11:45:15 oh drat - I missed that this early exit would chan
Patti Lor 2017/01/12 02:16:22 Yeah, I read the comment description for this meth
tapted 2017/01/12 02:25:43 yep - this seems good/safest
+
View* v = widget_delegate_->GetInitiallyFocusedView();
if (!focus_on_creation_ || show_state == ui::SHOW_STATE_INACTIVE ||
show_state == ui::SHOW_STATE_MINIMIZED) {
// If not focusing the window now, tell the focus manager which view to
// focus when the window is restored.
- if (v && focus_manager_.get())
- focus_manager_->SetStoredFocusView(v);
+ if (v)
+ focus_manager->SetStoredFocusView(v);
return true;
}
- if (v)
+ if (v) {
v->RequestFocus();
+ // If the request for focus was unsuccessful, fall back to using the first
+ // focusable View instead.
+ if (v != focus_manager->GetFocusedView())
+ focus_manager->AdvanceFocus(false);
+ }
return !!v;
}
« no previous file with comments | « no previous file | ui/views/window/dialog_delegate_unittest.cc » ('j') | ui/views/window/dialog_delegate_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698