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 24 matching lines...) Expand all Loading... | |
| 35 const bool kIsOkButtonOnLeftSide = false; | 35 const bool kIsOkButtonOnLeftSide = false; |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 // Returns true if the given view should be shown (i.e. exists and is | 38 // Returns true if the given view should be shown (i.e. exists and is |
| 39 // visible). | 39 // visible). |
| 40 bool ShouldShow(View* view) { | 40 bool ShouldShow(View* view) { |
| 41 return view && view->visible(); | 41 return view && view->visible(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Do the layout for a button. | 44 // Do the layout for a button. |
| 45 void LayoutButton(LabelButton* button, | 45 void LayoutButton(View* button, gfx::Rect* row_bounds, int button_height) { |
| 46 gfx::Rect* row_bounds, | |
| 47 int button_height) { | |
| 48 if (!button) | 46 if (!button) |
| 49 return; | 47 return; |
| 50 | 48 |
| 51 const gfx::Size size = button->GetPreferredSize(); | 49 const gfx::Size size = button->GetPreferredSize(); |
| 52 row_bounds->set_width(row_bounds->width() - size.width()); | 50 row_bounds->set_width(row_bounds->width() - size.width()); |
| 53 DCHECK_LE(button_height, row_bounds->height()); | 51 DCHECK_LE(button_height, row_bounds->height()); |
| 54 button->SetBounds( | 52 button->SetBounds( |
| 55 row_bounds->right(), | 53 row_bounds->right(), |
| 56 row_bounds->y() + (row_bounds->height() - button_height) / 2, | 54 row_bounds->y() + (row_bounds->height() - button_height) / 2, |
| 57 size.width(), button_height); | 55 size.width(), button_height); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 74 extra_view_(nullptr), | 72 extra_view_(nullptr), |
| 75 delegate_allowed_close_(false) { | 73 delegate_allowed_close_(false) { |
| 76 button_row_insets_ = | 74 button_row_insets_ = |
| 77 ViewsDelegate::GetInstance() | 75 ViewsDelegate::GetInstance() |
| 78 ? ViewsDelegate::GetInstance()->GetDialogButtonInsets() | 76 ? ViewsDelegate::GetInstance()->GetDialogButtonInsets() |
| 79 : gfx::Insets(0, kButtonHEdgeMarginNew, kButtonVEdgeMarginNew, | 77 : gfx::Insets(0, kButtonHEdgeMarginNew, kButtonVEdgeMarginNew, |
| 80 kButtonHEdgeMarginNew); | 78 kButtonHEdgeMarginNew); |
| 81 // Doing this now ensures this accelerator will have lower priority than | 79 // Doing this now ensures this accelerator will have lower priority than |
| 82 // one set by the contents view. | 80 // one set by the contents view. |
| 83 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 81 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 84 | |
| 85 if (ViewsDelegate::GetInstance()) | |
| 86 button_row_insets_ = ViewsDelegate::GetInstance()->GetDialogButtonInsets(); | |
| 87 } | 82 } |
| 88 | 83 |
| 89 DialogClientView::~DialogClientView() { | 84 DialogClientView::~DialogClientView() { |
| 90 } | 85 } |
| 91 | 86 |
| 92 void DialogClientView::AcceptWindow() { | 87 void DialogClientView::AcceptWindow() { |
| 93 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. | 88 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. |
| 94 if (!delegate_allowed_close_ && GetDialogDelegate()->Accept()) { | 89 if (!delegate_allowed_close_ && GetDialogDelegate()->Accept()) { |
| 95 delegate_allowed_close_ = true; | 90 delegate_allowed_close_ = true; |
| 96 GetWidget()->Close(); | 91 GetWidget()->Close(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 (cancel_button_ && ok_button_ | 166 (cancel_button_ && ok_button_ |
| 172 ? (ViewsDelegate::GetInstance() | 167 ? (ViewsDelegate::GetInstance() |
| 173 ? ViewsDelegate::GetInstance() | 168 ? ViewsDelegate::GetInstance() |
| 174 ->GetDialogRelatedButtonHorizontalSpacing() | 169 ->GetDialogRelatedButtonHorizontalSpacing() |
| 175 : kRelatedButtonHSpacing) : 0) + | 170 : kRelatedButtonHSpacing) : 0) + |
| 176 (ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) + | 171 (ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) + |
| 177 (ShouldShow(extra_view_) && has_dialog_buttons() ? extra_view_padding | 172 (ShouldShow(extra_view_) && has_dialog_buttons() ? extra_view_padding |
| 178 : 0), | 173 : 0), |
| 179 0); | 174 0); |
| 180 | 175 |
| 181 int buttons_height = GetButtonsAndExtraViewRowHeight(); | 176 int buttons_row_height = GetButtonsAndExtraViewRowHeight(); |
| 182 if (buttons_height != 0) { | 177 if (buttons_row_height != 0) { |
| 183 size.Enlarge(0, buttons_height + GetButtonsAndExtraViewRowTopPadding()); | 178 // Harmony does not use the extra padding. |
| 179 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) | |
| 180 buttons_row_height += GetButtonsAndExtraViewRowTopPadding(); | |
|
Peter Kasting
2017/02/02 00:32:30
Shouldn't this be implemented by returning 0 from
Bret
2017/02/03 01:47:17
Done.
| |
| 181 size.Enlarge(0, buttons_row_height); | |
| 184 // Inset the buttons and extra view. | 182 // Inset the buttons and extra view. |
| 185 const gfx::Insets insets = GetButtonRowInsets(); | 183 const gfx::Insets insets = GetButtonRowInsets(); |
| 186 size.Enlarge(insets.width(), insets.height()); | 184 size.Enlarge(insets.width(), insets.height()); |
| 187 } | 185 } |
| 188 | 186 |
| 189 // Increase the size as needed to fit the contents view. | 187 // Increase the size as needed to fit the contents view. |
| 190 // NOTE: The contents view is not inset on the top or side client view edges. | 188 // NOTE: The contents view is not inset on the top or side client view edges. |
| 191 gfx::Size contents_size = contents_view()->GetPreferredSize(); | 189 gfx::Size contents_size = contents_view()->GetPreferredSize(); |
| 192 size.Enlarge(0, contents_size.height()); | 190 size.Enlarge(0, contents_size.height()); |
| 193 size.set_width(std::max(size.width(), contents_size.width())); | 191 size.set_width(std::max(size.width(), contents_size.width())); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 218 } | 216 } |
| 219 if (extra_view_) { | 217 if (extra_view_) { |
| 220 int custom_padding = 0; | 218 int custom_padding = 0; |
| 221 if (has_dialog_buttons() && | 219 if (has_dialog_buttons() && |
| 222 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) { | 220 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) { |
| 223 // The call to LayoutButton() will already have accounted for some of | 221 // The call to LayoutButton() will already have accounted for some of |
| 224 // the padding. | 222 // the padding. |
| 225 custom_padding -= GetButtonsAndExtraViewRowTopPadding(); | 223 custom_padding -= GetButtonsAndExtraViewRowTopPadding(); |
| 226 row_bounds.set_width(row_bounds.width() - custom_padding); | 224 row_bounds.set_width(row_bounds.width() - custom_padding); |
| 227 } | 225 } |
| 228 row_bounds.set_width(std::min(row_bounds.width(), | 226 if (GetDialogDelegate()->GroupExtraViewWithButtons()) { |
| 229 extra_view_->GetPreferredSize().width())); | 227 LayoutButton(extra_view_, &row_bounds, button_height); |
| 230 extra_view_->SetBoundsRect(row_bounds); | 228 } else { |
| 229 row_bounds.set_width(std::min(row_bounds.width(), | |
| 230 extra_view_->GetPreferredSize().width())); | |
| 231 extra_view_->SetBoundsRect(row_bounds); | |
| 232 } | |
| 231 } | 233 } |
| 232 | 234 |
| 233 if (height > 0) | 235 if (height > 0) |
| 234 bounds.Inset(0, 0, 0, height + GetButtonsAndExtraViewRowTopPadding()); | 236 bounds.Inset(0, 0, 0, height + GetButtonsAndExtraViewRowTopPadding()); |
| 235 } | 237 } |
| 236 | 238 |
| 237 // Layout the contents view to the top and side edges of the contents bounds. | 239 // Layout the contents view to the top and side edges of the contents bounds. |
| 238 // NOTE: The local insets do not apply to the contents view sides or top. | 240 // NOTE: The local insets do not apply to the contents view sides or top. |
| 239 const gfx::Rect contents_bounds = GetContentsBounds(); | 241 const gfx::Rect contents_bounds = GetContentsBounds(); |
| 240 contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(), | 242 contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 PlatformStyle::kDialogDefaultButtonCanBeCancel); | 341 PlatformStyle::kDialogDefaultButtonCanBeCancel); |
| 340 | 342 |
| 341 // The default button is always blue in Harmony. | 343 // The default button is always blue in Harmony. |
| 342 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() || | 344 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() || |
| 343 GetDialogDelegate()->ShouldDefaultButtonBeBlue())) { | 345 GetDialogDelegate()->ShouldDefaultButtonBeBlue())) { |
| 344 button = MdTextButton::CreateSecondaryUiBlueButton(this, title); | 346 button = MdTextButton::CreateSecondaryUiBlueButton(this, title); |
| 345 } else { | 347 } else { |
| 346 button = MdTextButton::CreateSecondaryUiButton(this, title); | 348 button = MdTextButton::CreateSecondaryUiButton(this, title); |
| 347 } | 349 } |
| 348 | 350 |
| 349 const int kDialogMinButtonWidth = 75; | 351 const int minimum_button_width = |
| 350 button->SetMinSize(gfx::Size(kDialogMinButtonWidth, 0)); | 352 ViewsDelegate::GetInstance() |
| 353 ? ViewsDelegate::GetInstance()->GetDialogButtonMinimumWidth() | |
| 354 : kDialogMinimumButtonWidth; | |
| 355 button->SetMinSize(gfx::Size(minimum_button_width, 0)); | |
| 351 button->SetGroup(kButtonGroup); | 356 button->SetGroup(kButtonGroup); |
| 352 return button; | 357 return button; |
| 353 } | 358 } |
| 354 | 359 |
| 355 int DialogClientView::GetButtonHeight() const { | 360 int DialogClientView::GetButtonHeight() const { |
| 356 return std::max( | 361 return std::max( |
| 357 ok_button_ ? ok_button_->GetPreferredSize().height() : 0, | 362 ok_button_ ? ok_button_->GetPreferredSize().height() : 0, |
| 358 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0); | 363 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0); |
| 359 } | 364 } |
| 360 | 365 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 std::remove(child_views.begin(), child_views.end(), nullptr), | 409 std::remove(child_views.begin(), child_views.end(), nullptr), |
| 405 child_views.end()); | 410 child_views.end()); |
| 406 | 411 |
| 407 // Setup focus by reordering views. It is not safe to use SetNextFocusableView | 412 // Setup focus by reordering views. It is not safe to use SetNextFocusableView |
| 408 // since child views may be added externally to this view. | 413 // since child views may be added externally to this view. |
| 409 for (size_t i = 0; i < child_views.size(); i++) | 414 for (size_t i = 0; i < child_views.size(); i++) |
| 410 ReorderChildView(child_views[i], i); | 415 ReorderChildView(child_views[i], i); |
| 411 } | 416 } |
| 412 | 417 |
| 413 } // namespace views | 418 } // namespace views |
| OLD | NEW |