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

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

Issue 2807653002: Ensure default dialog button focus remains after a dialog update. (Closed)
Patch Set: Update DialogClientView to track if a default button focus exists and ensure it remains after dialo… Created 3 years, 8 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
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/base/material_design/material_design_controller.h" 10 #include "ui/base/material_design/material_design_controller.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 View* third = ok_button_; 312 View* third = ok_button_;
313 if (kIsOkButtonOnLeftSide) 313 if (kIsOkButtonOnLeftSide)
314 std::swap(second, third); 314 std::swap(second, third);
315 return {{first, second, third}}; 315 return {{first, second, third}};
316 } 316 }
317 317
318 void DialogClientView::SetupLayout() { 318 void DialogClientView::SetupLayout() {
319 base::AutoReset<bool> auto_reset(&adding_or_removing_views_, true); 319 base::AutoReset<bool> auto_reset(&adding_or_removing_views_, true);
320 GridLayout* layout = new GridLayout(button_row_container_); 320 GridLayout* layout = new GridLayout(button_row_container_);
321 layout->set_minimum_size(minimum_size_); 321 layout->set_minimum_size(minimum_size_);
322 default_focus_ = GetDialogDelegate()->GetInitiallyFocusedView();
322 323
323 // Clobber any existing LayoutManager since it has weak references to child 324 // Clobber any existing LayoutManager since it has weak references to child
324 // Views which may be removed by SetupViews(). 325 // Views which may be removed by SetupViews().
325 button_row_container_->SetLayoutManager(layout); 326 button_row_container_->SetLayoutManager(layout);
326 SetupViews(); 327 SetupViews();
327 const std::array<View*, kNumButtons> views = GetButtonRowViews(); 328 const std::array<View*, kNumButtons> views = GetButtonRowViews();
328 329
329 // Visibility changes on |extra_view_| must be observed to re-Layout. However, 330 // Visibility changes on |extra_view_| must be observed to re-Layout. However,
330 // when hidden it's not included in the button row (it can't influence layout) 331 // when hidden it's not included in the button row (it can't influence layout)
331 // and it can't be added to |button_row_container_| (GridLayout complains). 332 // and it can't be added to |button_row_container_| (GridLayout complains).
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 393 }
393 394
394 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 395 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
395 // Only link the extra view column if it is a button. 396 // Only link the extra view column if it is a button.
396 if (views[0] && !CustomButton::AsCustomButton(views[0])) 397 if (views[0] && !CustomButton::AsCustomButton(views[0]))
397 column_set->LinkColumnSizes(link[1], link[2], -1); 398 column_set->LinkColumnSizes(link[1], link[2], -1);
398 else 399 else
399 column_set->LinkColumnSizes(link[0], link[1], link[2], -1); 400 column_set->LinkColumnSizes(link[0], link[1], link[2], -1);
400 } 401 }
401 layout->AddPaddingRow(kFixed, insets.bottom()); 402 layout->AddPaddingRow(kFixed, insets.bottom());
403
404 if (default_focus_) {
405 default_focus_->RequestFocus();
Devlin 2017/04/12 19:36:31 Maybe add a comment why we need to do this.
Ackerman 2017/04/28 18:22:59 Done.
406 }
402 } 407 }
403 408
404 void DialogClientView::SetupViews() { 409 void DialogClientView::SetupViews() {
405 button_row_container_->RemoveAllChildViews(false /* delete children */); 410 button_row_container_->RemoveAllChildViews(false /* delete children */);
406 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can 411 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can
407 // be re-added to the layout when becoming visible. 412 // be re-added to the layout when becoming visible.
408 if (extra_view_) 413 if (extra_view_)
409 RemoveChildView(extra_view_); 414 RemoveChildView(extra_view_);
410 415
411 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); 416 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK);
412 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); 417 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL);
413 418
414 if (extra_view_) 419 if (extra_view_)
415 return; 420 return;
416 421
417 extra_view_ = GetDialogDelegate()->CreateExtraView(); 422 extra_view_ = GetDialogDelegate()->CreateExtraView();
418 if (extra_view_) 423 if (extra_view_)
419 extra_view_->SetGroup(kButtonGroup); 424 extra_view_->SetGroup(kButtonGroup);
420 } 425 }
421 426
422 } // namespace views 427 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698