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