| 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // Visibility changes on |extra_view_| must be observed to re-Layout. However, | 335 // Visibility changes on |extra_view_| must be observed to re-Layout. However, |
| 336 // when hidden it's not included in the button row (it can't influence layout) | 336 // when hidden it's not included in the button row (it can't influence layout) |
| 337 // and it can't be added to |button_row_container_| (GridLayout complains). | 337 // and it can't be added to |button_row_container_| (GridLayout complains). |
| 338 // So add it, hidden, to |this| so it can be observed. | 338 // So add it, hidden, to |this| so it can be observed. |
| 339 if (extra_view_ && !views[0]) | 339 if (extra_view_ && !views[0]) |
| 340 AddChildView(extra_view_); | 340 AddChildView(extra_view_); |
| 341 | 341 |
| 342 if (std::count(views.begin(), views.end(), nullptr) == kNumButtons) | 342 if (std::count(views.begin(), views.end(), nullptr) == kNumButtons) |
| 343 return; | 343 return; |
| 344 | 344 |
| 345 gfx::Insets insets = button_row_insets_; | |
| 346 LayoutProvider* const layout_provider = LayoutProvider::Get(); | |
| 347 // Support dialogs that clear |button_row_insets_| to do their own layout. | |
| 348 // They expect GetDialogRelatedControlVerticalSpacing() in this case. | |
| 349 if (insets.top() == 0 && | |
| 350 !ui::MaterialDesignController::IsSecondaryUiMaterial()) { | |
| 351 const int top = | |
| 352 layout_provider->GetDistanceMetric(DISTANCE_RELATED_CONTROL_VERTICAL); | |
| 353 insets.Set(top, insets.left(), insets.bottom(), insets.right()); | |
| 354 } | |
| 355 | |
| 356 // The |resize_percent| constants. There's only one stretchy column (padding | 345 // The |resize_percent| constants. There's only one stretchy column (padding |
| 357 // to the left of ok/cancel buttons). | 346 // to the left of ok/cancel buttons). |
| 358 constexpr float kFixed = 0.f; | 347 constexpr float kFixed = 0.f; |
| 359 constexpr float kStretchy = 1.f; | 348 constexpr float kStretchy = 1.f; |
| 360 | 349 |
| 361 // Button row is [ extra <pad+stretchy> second <pad> third ]. Ensure the <pad> | 350 // Button row is [ extra <pad+stretchy> second <pad> third ]. Ensure the <pad> |
| 362 // column is zero width if there isn't a button on either side. | 351 // column is zero width if there isn't a button on either side. |
| 363 // GetExtraViewSpacing() handles <pad+stretchy>. | 352 // GetExtraViewSpacing() handles <pad+stretchy>. |
| 353 LayoutProvider* const layout_provider = LayoutProvider::Get(); |
| 364 const int button_spacing = (ok_button_ && cancel_button_) | 354 const int button_spacing = (ok_button_ && cancel_button_) |
| 365 ? layout_provider->GetDistanceMetric( | 355 ? layout_provider->GetDistanceMetric( |
| 366 DISTANCE_RELATED_BUTTON_HORIZONTAL) | 356 DISTANCE_RELATED_BUTTON_HORIZONTAL) |
| 367 : 0; | 357 : 0; |
| 368 | 358 |
| 369 constexpr int kButtonRowId = 0; | 359 constexpr int kButtonRowId = 0; |
| 370 ColumnSet* column_set = layout->AddColumnSet(kButtonRowId); | 360 ColumnSet* column_set = layout->AddColumnSet(kButtonRowId); |
| 371 | 361 |
| 372 // Rather than giving |button_row_container_| a Border, incorporate the insets | 362 // Rather than giving |button_row_container_| a Border, incorporate the insets |
| 373 // into the layout. This simplifies min/max size calculations. | 363 // into the layout. This simplifies min/max size calculations. |
| 374 column_set->AddPaddingColumn(kFixed, insets.left()); | 364 column_set->AddPaddingColumn(kFixed, button_row_insets_.left()); |
| 375 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, | 365 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, |
| 376 GridLayout::USE_PREF, 0, 0); | 366 GridLayout::USE_PREF, 0, 0); |
| 377 column_set->AddPaddingColumn(kStretchy, GetExtraViewSpacing()); | 367 column_set->AddPaddingColumn(kStretchy, GetExtraViewSpacing()); |
| 378 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, | 368 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, |
| 379 GridLayout::USE_PREF, 0, 0); | 369 GridLayout::USE_PREF, 0, 0); |
| 380 column_set->AddPaddingColumn(kFixed, button_spacing); | 370 column_set->AddPaddingColumn(kFixed, button_spacing); |
| 381 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, | 371 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, |
| 382 GridLayout::USE_PREF, 0, 0); | 372 GridLayout::USE_PREF, 0, 0); |
| 383 column_set->AddPaddingColumn(kFixed, insets.right()); | 373 column_set->AddPaddingColumn(kFixed, button_row_insets_.right()); |
| 384 | 374 |
| 385 // Track which columns to link sizes under MD. | 375 // Track which columns to link sizes under MD. |
| 386 constexpr int kViewToColumnIndex[] = {1, 3, 5}; | 376 constexpr int kViewToColumnIndex[] = {1, 3, 5}; |
| 387 int link[] = {-1, -1, -1}; | 377 int link[] = {-1, -1, -1}; |
| 388 size_t link_index = 0; | 378 size_t link_index = 0; |
| 389 | 379 |
| 390 layout->StartRowWithPadding(kFixed, kButtonRowId, kFixed, insets.top()); | 380 layout->StartRowWithPadding(kFixed, kButtonRowId, kFixed, |
| 381 button_row_insets_.top()); |
| 391 for (size_t view_index = 0; view_index < kNumButtons; ++view_index) { | 382 for (size_t view_index = 0; view_index < kNumButtons; ++view_index) { |
| 392 if (views[view_index]) { | 383 if (views[view_index]) { |
| 393 layout->AddView(views[view_index]); | 384 layout->AddView(views[view_index]); |
| 394 link[link_index++] = kViewToColumnIndex[view_index]; | 385 link[link_index++] = kViewToColumnIndex[view_index]; |
| 395 } else { | 386 } else { |
| 396 layout->SkipColumns(1); | 387 layout->SkipColumns(1); |
| 397 } | 388 } |
| 398 } | 389 } |
| 399 | 390 |
| 400 column_set->set_linked_column_size_limit( | 391 column_set->set_linked_column_size_limit( |
| 401 layout_provider->GetDistanceMetric(DISTANCE_BUTTON_MAX_LINKABLE_WIDTH)); | 392 layout_provider->GetDistanceMetric(DISTANCE_BUTTON_MAX_LINKABLE_WIDTH)); |
| 402 | 393 |
| 403 // If |views[0]| is non-null, it is a visible |extra_view_| and its column | 394 // If |views[0]| is non-null, it is a visible |extra_view_| and its column |
| 404 // will be in |link[0]|. Skip that if it is not a button, or if it is a | 395 // will be in |link[0]|. Skip that if it is not a button, or if it is a |
| 405 // Checkbox (which extends LabelButton). Otherwise, link everything. | 396 // Checkbox (which extends LabelButton). Otherwise, link everything. |
| 406 bool skip_first_link = | 397 bool skip_first_link = |
| 407 views[0] && (!CustomButton::AsCustomButton(views[0]) || | 398 views[0] && (!CustomButton::AsCustomButton(views[0]) || |
| 408 views[0]->GetClassName() == Checkbox::kViewClassName); | 399 views[0]->GetClassName() == Checkbox::kViewClassName); |
| 409 if (skip_first_link) | 400 if (skip_first_link) |
| 410 column_set->LinkColumnSizes(link[1], link[2], -1); | 401 column_set->LinkColumnSizes(link[1], link[2], -1); |
| 411 else | 402 else |
| 412 column_set->LinkColumnSizes(link[0], link[1], link[2], -1); | 403 column_set->LinkColumnSizes(link[0], link[1], link[2], -1); |
| 413 | 404 |
| 414 layout->AddPaddingRow(kFixed, insets.bottom()); | 405 layout->AddPaddingRow(kFixed, button_row_insets_.bottom()); |
| 415 | 406 |
| 416 // The default focus is lost when child views are added back into the dialog. | 407 // The default focus is lost when child views are added back into the dialog. |
| 417 // This restores focus if the button is still available. | 408 // This restores focus if the button is still available. |
| 418 View* previously_focused_view = view_tracker.view(); | 409 View* previously_focused_view = view_tracker.view(); |
| 419 if (previously_focused_view && !focus_manager->GetFocusedView() && | 410 if (previously_focused_view && !focus_manager->GetFocusedView() && |
| 420 Contains(previously_focused_view)) { | 411 Contains(previously_focused_view)) { |
| 421 previously_focused_view->RequestFocus(); | 412 previously_focused_view->RequestFocus(); |
| 422 } | 413 } |
| 423 } | 414 } |
| 424 | 415 |
| 425 void DialogClientView::SetupViews() { | 416 void DialogClientView::SetupViews() { |
| 426 button_row_container_->RemoveAllChildViews(false /* delete children */); | 417 button_row_container_->RemoveAllChildViews(false /* delete children */); |
| 427 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can | 418 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can |
| 428 // be re-added to the layout when becoming visible. | 419 // be re-added to the layout when becoming visible. |
| 429 if (extra_view_) | 420 if (extra_view_) |
| 430 RemoveChildView(extra_view_); | 421 RemoveChildView(extra_view_); |
| 431 | 422 |
| 432 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); | 423 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); |
| 433 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); | 424 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); |
| 434 | 425 |
| 435 if (extra_view_) | 426 if (extra_view_) |
| 436 return; | 427 return; |
| 437 | 428 |
| 438 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 429 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
| 439 if (extra_view_) | 430 if (extra_view_) |
| 440 extra_view_->SetGroup(kButtonGroup); | 431 extra_view_->SetGroup(kButtonGroup); |
| 441 } | 432 } |
| 442 | 433 |
| 443 } // namespace views | 434 } // namespace views |
| OLD | NEW |