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