Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(); | |
|
sky
2017/04/28 20:49:52
There should be no need for the member as it's onl
ackermanb
2017/05/17 17:20:54
Done.
| |
| 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 Loading... | |
| 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 // The default focus is lost when child views are added back into the dialog. | |
| 405 // This restores focus to the default. | |
| 406 if (default_focus_) { | |
| 407 default_focus_->RequestFocus(); | |
| 408 } | |
| 402 } | 409 } |
| 403 | 410 |
| 404 void DialogClientView::SetupViews() { | 411 void DialogClientView::SetupViews() { |
| 405 button_row_container_->RemoveAllChildViews(false /* delete children */); | 412 button_row_container_->RemoveAllChildViews(false /* delete children */); |
| 406 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can | 413 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can |
| 407 // be re-added to the layout when becoming visible. | 414 // be re-added to the layout when becoming visible. |
| 408 if (extra_view_) | 415 if (extra_view_) |
| 409 RemoveChildView(extra_view_); | 416 RemoveChildView(extra_view_); |
| 410 | 417 |
| 411 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); | 418 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); |
| 412 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); | 419 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); |
| 413 | 420 |
| 414 if (extra_view_) | 421 if (extra_view_) |
| 415 return; | 422 return; |
| 416 | 423 |
| 417 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 424 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
| 418 if (extra_view_) | 425 if (extra_view_) |
| 419 extra_view_->SetGroup(kButtonGroup); | 426 extra_view_->SetGroup(kButtonGroup); |
| 420 } | 427 } |
| 421 | 428 |
| 422 } // namespace views | 429 } // namespace views |
| OLD | NEW |