Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/views/window/dialog_client_view.cc

Issue 2696263002: Refactor ViewsDelegate and MD-ify the icon-to-text spacing for checkbox and radiobutton (Closed)
Patch Set: Use 'related control spacing' constant for icon-to-text spacing Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_constants.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/views_delegate.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 #include "ui/views/window/dialog_delegate.h" 23 #include "ui/views/window/dialog_delegate.h"
23 24
24 namespace views { 25 namespace views {
25 26
26 namespace { 27 namespace {
27 28
28 // The group used by the buttons. This name is chosen voluntarily big not to 29 // The group used by the buttons. This name is chosen voluntarily big not to
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 DialogClientView* const owner_; 69 DialogClientView* const owner_;
69 70
70 DISALLOW_COPY_AND_ASSIGN(ButtonRowContainer); 71 DISALLOW_COPY_AND_ASSIGN(ButtonRowContainer);
71 }; 72 };
72 73
73 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
74 // DialogClientView, public: 75 // DialogClientView, public:
75 76
76 DialogClientView::DialogClientView(Widget* owner, View* contents_view) 77 DialogClientView::DialogClientView(Widget* owner, View* contents_view)
77 : ClientView(owner, contents_view), 78 : ClientView(owner, contents_view),
78 button_row_insets_( 79 button_row_insets_(ViewsDelegate::GetInstance()->GetInsetsMetric(
79 ViewsDelegate::GetInstance()->GetDialogButtonInsets()) { 80 InsetsMetric::DIALOG_BUTTON)) {
80 // Doing this now ensures this accelerator will have lower priority than 81 // Doing this now ensures this accelerator will have lower priority than
81 // one set by the contents view. 82 // one set by the contents view.
82 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 83 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
83 button_row_container_ = new ButtonRowContainer(this); 84 button_row_container_ = new ButtonRowContainer(this);
84 AddChildView(button_row_container_); 85 AddChildView(button_row_container_);
85 } 86 }
86 87
87 DialogClientView::~DialogClientView() {} 88 DialogClientView::~DialogClientView() {}
88 89
89 void DialogClientView::AcceptWindow() { 90 void DialogClientView::AcceptWindow() {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 PlatformStyle::kDialogDefaultButtonCanBeCancel); 275 PlatformStyle::kDialogDefaultButtonCanBeCancel);
275 276
276 // The default button is always blue in Harmony. 277 // The default button is always blue in Harmony.
277 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() || 278 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() ||
278 delegate->ShouldDefaultButtonBeBlue())) { 279 delegate->ShouldDefaultButtonBeBlue())) {
279 button = MdTextButton::CreateSecondaryUiBlueButton(this, title); 280 button = MdTextButton::CreateSecondaryUiBlueButton(this, title);
280 } else { 281 } else {
281 button = MdTextButton::CreateSecondaryUiButton(this, title); 282 button = MdTextButton::CreateSecondaryUiButton(this, title);
282 } 283 }
283 284
284 const int minimum_width = 285 const int minimum_width = ViewsDelegate::GetInstance()->GetDistanceMetric(
285 ViewsDelegate::GetInstance()->GetDialogButtonMinimumWidth(); 286 views::DistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH);
286 button->SetMinSize(gfx::Size(minimum_width, 0)); 287 button->SetMinSize(gfx::Size(minimum_width, 0));
287 288
288 button->SetGroup(kButtonGroup); 289 button->SetGroup(kButtonGroup);
289 290
290 *member = button; 291 *member = button;
291 } 292 }
292 293
293 delegate->UpdateButton(*member, type); 294 delegate->UpdateButton(*member, type);
294 } 295 }
295 296
296 int DialogClientView::GetExtraViewSpacing() const { 297 int DialogClientView::GetExtraViewSpacing() const {
297 if (!ShouldShow(extra_view_) || !(ok_button_ || cancel_button_)) 298 if (!ShouldShow(extra_view_) || !(ok_button_ || cancel_button_))
298 return 0; 299 return 0;
299 300
300 int extra_view_padding = 0; 301 int extra_view_padding = 0;
301 if (GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding)) 302 if (GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding))
302 return extra_view_padding; 303 return extra_view_padding;
303 304
304 return ViewsDelegate::GetInstance() 305 return ViewsDelegate::GetInstance()->GetDistanceMetric(
305 ->GetDialogRelatedButtonHorizontalSpacing(); 306 views::DistanceMetric::RELATED_BUTTON_HORIZONTAL);
306 } 307 }
307 308
308 std::array<View*, DialogClientView::kNumButtons> 309 std::array<View*, DialogClientView::kNumButtons>
309 DialogClientView::GetButtonRowViews() { 310 DialogClientView::GetButtonRowViews() {
310 View* first = ShouldShow(extra_view_) ? extra_view_ : nullptr; 311 View* first = ShouldShow(extra_view_) ? extra_view_ : nullptr;
311 View* second = cancel_button_; 312 View* second = cancel_button_;
312 View* third = ok_button_; 313 View* third = ok_button_;
313 if (kIsOkButtonOnLeftSide) 314 if (kIsOkButtonOnLeftSide)
314 std::swap(second, third); 315 std::swap(second, third);
315 return {{first, second, third}}; 316 return {{first, second, third}};
(...skipping 18 matching lines...) Expand all
334 AddChildView(extra_view_); 335 AddChildView(extra_view_);
335 336
336 if (std::count(views.begin(), views.end(), nullptr) == kNumButtons) 337 if (std::count(views.begin(), views.end(), nullptr) == kNumButtons)
337 return; 338 return;
338 339
339 gfx::Insets insets = button_row_insets_; 340 gfx::Insets insets = button_row_insets_;
340 // Support dialogs that clear |button_row_insets_| to do their own layout. 341 // Support dialogs that clear |button_row_insets_| to do their own layout.
341 // They expect GetDialogRelatedControlVerticalSpacing() in this case. 342 // They expect GetDialogRelatedControlVerticalSpacing() in this case.
342 // TODO(tapted): Remove this under Harmony. 343 // TODO(tapted): Remove this under Harmony.
343 if (insets.top() == 0) { 344 if (insets.top() == 0) {
344 const int top = 345 const int top = ViewsDelegate::GetInstance()->GetDistanceMetric(
345 ViewsDelegate::GetInstance()->GetDialogRelatedControlVerticalSpacing(); 346 views::DistanceMetric::RELATED_CONTROL_VERTICAL);
346 insets.Set(top, insets.left(), insets.bottom(), insets.right()); 347 insets.Set(top, insets.left(), insets.bottom(), insets.right());
347 } 348 }
348 349
349 // The |resize_percent| constants. There's only one stretchy column (padding 350 // The |resize_percent| constants. There's only one stretchy column (padding
350 // to the left of ok/cancel buttons). 351 // to the left of ok/cancel buttons).
351 constexpr float kFixed = 0.f; 352 constexpr float kFixed = 0.f;
352 constexpr float kStretchy = 1.f; 353 constexpr float kStretchy = 1.f;
353 354
354 // 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>
355 // 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.
356 // GetExtraViewSpacing() handles <pad+stretchy>. 357 // GetExtraViewSpacing() handles <pad+stretchy>.
357 const int button_spacing = 358 const int button_spacing =
358 (ok_button_ && cancel_button_) 359 (ok_button_ && cancel_button_)
359 ? ViewsDelegate::GetInstance() 360 ? ViewsDelegate::GetInstance()->GetDistanceMetric(
360 ->GetDialogRelatedButtonHorizontalSpacing() 361 views::DistanceMetric::RELATED_BUTTON_HORIZONTAL)
361 : 0; 362 : 0;
362 363
363 constexpr int kButtonRowId = 0; 364 constexpr int kButtonRowId = 0;
364 ColumnSet* column_set = layout->AddColumnSet(kButtonRowId); 365 ColumnSet* column_set = layout->AddColumnSet(kButtonRowId);
365 366
366 // Rather than giving |button_row_container_| a Border, incorporate the insets 367 // Rather than giving |button_row_container_| a Border, incorporate the insets
367 // into the layout. This simplifies min/max size calculations. 368 // into the layout. This simplifies min/max size calculations.
368 column_set->AddPaddingColumn(kFixed, insets.left()); 369 column_set->AddPaddingColumn(kFixed, insets.left());
369 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed, 370 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kFixed,
370 GridLayout::USE_PREF, 0, 0); 371 GridLayout::USE_PREF, 0, 0);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 414
414 if (extra_view_) 415 if (extra_view_)
415 return; 416 return;
416 417
417 extra_view_ = GetDialogDelegate()->CreateExtraView(); 418 extra_view_ = GetDialogDelegate()->CreateExtraView();
418 if (extra_view_) 419 if (extra_view_)
419 extra_view_->SetGroup(kButtonGroup); 420 extra_view_->SetGroup(kButtonGroup);
420 } 421 }
421 422
422 } // namespace views 423 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698