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

Side by Side Diff: ui/views/window/dialog_client_view.cc

Issue 1690133003: DialogClientView: Correct the order in which subviews are focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Add tests. Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « ui/views/window/dialog_client_view.h ('k') | ui/views/window/dialog_client_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/window/dialog_client_view.h" 5 #include "ui/views/window/dialog_client_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (details.is_add && details.child == this) { 249 if (details.is_add && details.child == this) {
250 UpdateDialogButtons(); 250 UpdateDialogButtons();
251 CreateExtraView(); 251 CreateExtraView();
252 CreateFootnoteView(); 252 CreateFootnoteView();
253 } else if (!details.is_add && details.child != this) { 253 } else if (!details.is_add && details.child != this) {
254 if (details.child == ok_button_) 254 if (details.child == ok_button_)
255 ok_button_ = NULL; 255 ok_button_ = NULL;
256 if (details.child == cancel_button_) 256 if (details.child == cancel_button_)
257 cancel_button_ = NULL; 257 cancel_button_ = NULL;
258 } 258 }
259
260 SetupFocusChain();
259 } 261 }
260 262
261 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 263 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
262 // The old dialog style needs an explicit background color, while the new 264 // The old dialog style needs an explicit background color, while the new
263 // dialog style simply inherits the bubble's frame view color. 265 // dialog style simply inherits the bubble's frame view color.
264 const DialogDelegate* dialog = GetDialogDelegate(); 266 const DialogDelegate* dialog = GetDialogDelegate();
265 267
266 if (dialog && !dialog->UseNewStyleForThisDialog()) { 268 if (dialog && !dialog->UseNewStyleForThisDialog()) {
267 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> 269 set_background(views::Background::CreateSolidBackground(GetNativeTheme()->
268 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); 270 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() : 375 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() :
374 gfx::Insets(0, kButtonHEdgeMarginNew, 376 gfx::Insets(0, kButtonHEdgeMarginNew,
375 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); 377 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew);
376 } 378 }
377 379
378 void DialogClientView::Close() { 380 void DialogClientView::Close() {
379 GetWidget()->Close(); 381 GetWidget()->Close();
380 GetDialogDelegate()->OnClosed(); 382 GetDialogDelegate()->OnClosed();
381 } 383 }
382 384
385 void DialogClientView::SetupFocusChain() {
386 // Create a vector of child views in the order of intended focus.
387 std::vector<View*> child_views;
388 child_views.push_back(contents_view());
389 child_views.push_back(extra_view_);
390 if (kIsOkButtonOnLeftSide) {
391 child_views.push_back(ok_button_);
392 child_views.push_back(cancel_button_);
393 } else {
394 child_views.push_back(cancel_button_);
395 child_views.push_back(ok_button_);
396 }
397 child_views.push_back(footnote_view_);
398
399 // Remove all null views from the vector.
400 child_views.erase(
401 std::remove(child_views.begin(), child_views.end(), nullptr),
402 child_views.end());
403
404 // Add a dummy null view, so that the last view has null as the next focusable
405 // view.
406 child_views.push_back(nullptr);
sky 2016/02/17 18:18:26 I actually prefer you don't do this. Otherwise we
karandeepb 2016/02/18 01:44:59 Done.
407
408 // Setup focus.
409 for (size_t i = 0; i < child_views.size() - 1; i++)
410 child_views[i]->SetNextFocusableView(child_views[i + 1]);
411 }
412
383 } // namespace views 413 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/dialog_client_view.h ('k') | ui/views/window/dialog_client_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698