| 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" |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
| 12 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
| 13 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
| 14 #include "ui/views/controls/button/blue_button.h" | 14 #include "ui/views/controls/button/blue_button.h" |
| 15 #include "ui/views/controls/button/custom_button.h" | 15 #include "ui/views/controls/button/custom_button.h" |
| 16 #include "ui/views/controls/button/label_button.h" | 16 #include "ui/views/controls/button/label_button.h" |
| 17 #include "ui/views/controls/button/md_text_button.h" | 17 #include "ui/views/controls/button/md_text_button.h" |
| 18 #include "ui/views/layout/grid_layout.h" | 18 #include "ui/views/layout/grid_layout.h" |
| 19 #include "ui/views/layout/layout_provider.h" |
| 19 #include "ui/views/style/platform_style.h" | 20 #include "ui/views/style/platform_style.h" |
| 20 #include "ui/views/views_delegate.h" | |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/window/dialog_delegate.h" | 22 #include "ui/views/window/dialog_delegate.h" |
| 23 | 23 |
| 24 namespace views { | 24 namespace views { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // The group used by the buttons. This name is chosen voluntarily big not to | 28 // The group used by the buttons. This name is chosen voluntarily big not to |
| 29 // conflict with other groups that could be in the dialog content. | 29 // conflict with other groups that could be in the dialog content. |
| 30 const int kButtonGroup = 6666; | 30 const int kButtonGroup = 6666; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 DialogClientView* const owner_; | 68 DialogClientView* const owner_; |
| 69 | 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(ButtonRowContainer); | 70 DISALLOW_COPY_AND_ASSIGN(ButtonRowContainer); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 /////////////////////////////////////////////////////////////////////////////// | 73 /////////////////////////////////////////////////////////////////////////////// |
| 74 // DialogClientView, public: | 74 // DialogClientView, public: |
| 75 | 75 |
| 76 DialogClientView::DialogClientView(Widget* owner, View* contents_view) | 76 DialogClientView::DialogClientView(Widget* owner, View* contents_view) |
| 77 : ClientView(owner, contents_view), | 77 : ClientView(owner, contents_view), |
| 78 button_row_insets_(ViewsDelegate::GetInstance()->GetInsetsMetric( | 78 button_row_insets_( |
| 79 InsetsMetric::DIALOG_BUTTON)) { | 79 LayoutProvider::Get()->GetInsetsMetric(INSETS_DIALOG_BUTTON)) { |
| 80 // Doing this now ensures this accelerator will have lower priority than | 80 // Doing this now ensures this accelerator will have lower priority than |
| 81 // one set by the contents view. | 81 // one set by the contents view. |
| 82 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 82 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 83 button_row_container_ = new ButtonRowContainer(this); | 83 button_row_container_ = new ButtonRowContainer(this); |
| 84 AddChildView(button_row_container_); | 84 AddChildView(button_row_container_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 DialogClientView::~DialogClientView() {} | 87 DialogClientView::~DialogClientView() {} |
| 88 | 88 |
| 89 void DialogClientView::AcceptWindow() { | 89 void DialogClientView::AcceptWindow() { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 PlatformStyle::kDialogDefaultButtonCanBeCancel); | 274 PlatformStyle::kDialogDefaultButtonCanBeCancel); |
| 275 | 275 |
| 276 // The default button is always blue in Harmony. | 276 // The default button is always blue in Harmony. |
| 277 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() || | 277 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() || |
| 278 delegate->ShouldDefaultButtonBeBlue())) { | 278 delegate->ShouldDefaultButtonBeBlue())) { |
| 279 button = MdTextButton::CreateSecondaryUiBlueButton(this, title); | 279 button = MdTextButton::CreateSecondaryUiBlueButton(this, title); |
| 280 } else { | 280 } else { |
| 281 button = MdTextButton::CreateSecondaryUiButton(this, title); | 281 button = MdTextButton::CreateSecondaryUiButton(this, title); |
| 282 } | 282 } |
| 283 | 283 |
| 284 const int minimum_width = ViewsDelegate::GetInstance()->GetDistanceMetric( | 284 const int minimum_width = LayoutProvider::Get()->GetDistanceMetric( |
| 285 views::DistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH); | 285 views::DISTANCE_DIALOG_BUTTON_MINIMUM_WIDTH); |
| 286 button->SetMinSize(gfx::Size(minimum_width, 0)); | 286 button->SetMinSize(gfx::Size(minimum_width, 0)); |
| 287 | 287 |
| 288 button->SetGroup(kButtonGroup); | 288 button->SetGroup(kButtonGroup); |
| 289 | 289 |
| 290 *member = button; | 290 *member = button; |
| 291 } | 291 } |
| 292 | 292 |
| 293 delegate->UpdateButton(*member, type); | 293 delegate->UpdateButton(*member, type); |
| 294 } | 294 } |
| 295 | 295 |
| 296 int DialogClientView::GetExtraViewSpacing() const { | 296 int DialogClientView::GetExtraViewSpacing() const { |
| 297 if (!ShouldShow(extra_view_) || !(ok_button_ || cancel_button_)) | 297 if (!ShouldShow(extra_view_) || !(ok_button_ || cancel_button_)) |
| 298 return 0; | 298 return 0; |
| 299 | 299 |
| 300 int extra_view_padding = 0; | 300 int extra_view_padding = 0; |
| 301 if (GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding)) | 301 if (GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding)) |
| 302 return extra_view_padding; | 302 return extra_view_padding; |
| 303 | 303 |
| 304 return ViewsDelegate::GetInstance()->GetDistanceMetric( | 304 return LayoutProvider::Get()->GetDistanceMetric( |
| 305 views::DistanceMetric::RELATED_BUTTON_HORIZONTAL); | 305 views::DISTANCE_RELATED_BUTTON_HORIZONTAL); |
| 306 } | 306 } |
| 307 | 307 |
| 308 std::array<View*, DialogClientView::kNumButtons> | 308 std::array<View*, DialogClientView::kNumButtons> |
| 309 DialogClientView::GetButtonRowViews() { | 309 DialogClientView::GetButtonRowViews() { |
| 310 View* first = ShouldShow(extra_view_) ? extra_view_ : nullptr; | 310 View* first = ShouldShow(extra_view_) ? extra_view_ : nullptr; |
| 311 View* second = cancel_button_; | 311 View* second = cancel_button_; |
| 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}}; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 334 AddChildView(extra_view_); | 334 AddChildView(extra_view_); |
| 335 | 335 |
| 336 if (std::count(views.begin(), views.end(), nullptr) == kNumButtons) | 336 if (std::count(views.begin(), views.end(), nullptr) == kNumButtons) |
| 337 return; | 337 return; |
| 338 | 338 |
| 339 gfx::Insets insets = button_row_insets_; | 339 gfx::Insets insets = button_row_insets_; |
| 340 // Support dialogs that clear |button_row_insets_| to do their own layout. | 340 // Support dialogs that clear |button_row_insets_| to do their own layout. |
| 341 // They expect GetDialogRelatedControlVerticalSpacing() in this case. | 341 // They expect GetDialogRelatedControlVerticalSpacing() in this case. |
| 342 // TODO(tapted): Remove this under Harmony. | 342 // TODO(tapted): Remove this under Harmony. |
| 343 if (insets.top() == 0) { | 343 if (insets.top() == 0) { |
| 344 const int top = ViewsDelegate::GetInstance()->GetDistanceMetric( | 344 const int top = LayoutProvider::Get()->GetDistanceMetric( |
| 345 views::DistanceMetric::RELATED_CONTROL_VERTICAL); | 345 views::DISTANCE_RELATED_CONTROL_VERTICAL); |
| 346 insets.Set(top, insets.left(), insets.bottom(), insets.right()); | 346 insets.Set(top, insets.left(), insets.bottom(), insets.right()); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // The |resize_percent| constants. There's only one stretchy column (padding | 349 // The |resize_percent| constants. There's only one stretchy column (padding |
| 350 // to the left of ok/cancel buttons). | 350 // to the left of ok/cancel buttons). |
| 351 constexpr float kFixed = 0.f; | 351 constexpr float kFixed = 0.f; |
| 352 constexpr float kStretchy = 1.f; | 352 constexpr float kStretchy = 1.f; |
| 353 | 353 |
| 354 // Button row is [ extra <pad+stretchy> second <pad> third ]. Ensure the <pad> | 354 // Button row is [ extra <pad+stretchy> second <pad> third ]. Ensure the <pad> |
| 355 // column is zero width if there isn't a button on either side. | 355 // column is zero width if there isn't a button on either side. |
| 356 // GetExtraViewSpacing() handles <pad+stretchy>. | 356 // GetExtraViewSpacing() handles <pad+stretchy>. |
| 357 const int button_spacing = | 357 const int button_spacing = |
| 358 (ok_button_ && cancel_button_) | 358 (ok_button_ && cancel_button_) |
| 359 ? ViewsDelegate::GetInstance()->GetDistanceMetric( | 359 ? LayoutProvider::Get()->GetDistanceMetric( |
| 360 views::DistanceMetric::RELATED_BUTTON_HORIZONTAL) | 360 views::DISTANCE_RELATED_BUTTON_HORIZONTAL) |
| 361 : 0; | 361 : 0; |
| 362 | 362 |
| 363 constexpr int kButtonRowId = 0; | 363 constexpr int kButtonRowId = 0; |
| 364 ColumnSet* column_set = layout->AddColumnSet(kButtonRowId); | 364 ColumnSet* column_set = layout->AddColumnSet(kButtonRowId); |
| 365 | 365 |
| 366 // Rather than giving |button_row_container_| a Border, incorporate the insets | 366 // Rather than giving |button_row_container_| a Border, incorporate the insets |
| 367 // into the layout. This simplifies min/max size calculations. | 367 // into the layout. This simplifies min/max size calculations. |
| 368 column_set->AddPaddingColumn(kFixed, insets.left()); | 368 column_set->AddPaddingColumn(kFixed, insets.left()); |
| 369 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, | 369 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, |
| 370 GridLayout::USE_PREF, 0, 0); | 370 GridLayout::USE_PREF, 0, 0); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 413 |
| 414 if (extra_view_) | 414 if (extra_view_) |
| 415 return; | 415 return; |
| 416 | 416 |
| 417 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 417 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
| 418 if (extra_view_) | 418 if (extra_view_) |
| 419 extra_view_->SetGroup(kButtonGroup); | 419 extra_view_->SetGroup(kButtonGroup); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace views | 422 } // namespace views |
| OLD | NEW |