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

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

Issue 2660553005: Harmony - convert hung renderer dialog. (Closed)
Patch Set: merge Created 3 years, 10 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"
(...skipping 24 matching lines...) Expand all
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
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 213 }
219 if (extra_view_) { 214 if (extra_view_) {
220 int custom_padding = 0; 215 int custom_padding = 0;
221 if (has_dialog_buttons() && 216 if (has_dialog_buttons() &&
222 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) { 217 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) {
223 // The call to LayoutButton() will already have accounted for some of 218 // The call to LayoutButton() will already have accounted for some of
224 // the padding. 219 // the padding.
225 custom_padding -= GetButtonsAndExtraViewRowTopPadding(); 220 custom_padding -= GetButtonsAndExtraViewRowTopPadding();
226 row_bounds.set_width(row_bounds.width() - custom_padding); 221 row_bounds.set_width(row_bounds.width() - custom_padding);
227 } 222 }
228 row_bounds.set_width(std::min(row_bounds.width(), 223 if (GetDialogDelegate()->GroupExtraViewWithButtons()) {
229 extra_view_->GetPreferredSize().width())); 224 LayoutButton(extra_view_, &row_bounds, button_height);
tapted 2017/02/03 02:07:54 I think |extra_view_| is sometimes not a button --
Bret 2017/02/03 21:58:35 Right, LayoutButton is agnostic to whether the vie
230 extra_view_->SetBoundsRect(row_bounds); 225 } else {
226 row_bounds.set_width(std::min(row_bounds.width(),
227 extra_view_->GetPreferredSize().width()));
228 extra_view_->SetBoundsRect(row_bounds);
229 }
231 } 230 }
232 231
233 if (height > 0) 232 if (height > 0)
234 bounds.Inset(0, 0, 0, height + GetButtonsAndExtraViewRowTopPadding()); 233 bounds.Inset(0, 0, 0, height + GetButtonsAndExtraViewRowTopPadding());
235 } 234 }
236 235
237 // Layout the contents view to the top and side edges of the contents bounds. 236 // 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. 237 // NOTE: The local insets do not apply to the contents view sides or top.
239 const gfx::Rect contents_bounds = GetContentsBounds(); 238 const gfx::Rect contents_bounds = GetContentsBounds();
240 contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(), 239 contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 PlatformStyle::kDialogDefaultButtonCanBeCancel); 338 PlatformStyle::kDialogDefaultButtonCanBeCancel);
340 339
341 // The default button is always blue in Harmony. 340 // The default button is always blue in Harmony.
342 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() || 341 if (is_default && (ui::MaterialDesignController::IsSecondaryUiMaterial() ||
343 GetDialogDelegate()->ShouldDefaultButtonBeBlue())) { 342 GetDialogDelegate()->ShouldDefaultButtonBeBlue())) {
344 button = MdTextButton::CreateSecondaryUiBlueButton(this, title); 343 button = MdTextButton::CreateSecondaryUiBlueButton(this, title);
345 } else { 344 } else {
346 button = MdTextButton::CreateSecondaryUiButton(this, title); 345 button = MdTextButton::CreateSecondaryUiButton(this, title);
347 } 346 }
348 347
349 const int kDialogMinButtonWidth = 75; 348 // In harmony the minimum size is handled by MdTextButton.
350 button->SetMinSize(gfx::Size(kDialogMinButtonWidth, 0)); 349 if (!ui::MaterialDesignController::IsSecondaryUiMaterial())
350 button->SetMinSize(gfx::Size(kDialogMinimumButtonWidth, 0));
351 button->SetGroup(kButtonGroup); 351 button->SetGroup(kButtonGroup);
352 return button; 352 return button;
353 } 353 }
354 354
355 int DialogClientView::GetButtonHeight() const { 355 int DialogClientView::GetButtonHeight() const {
356 return std::max( 356 return std::max(
357 ok_button_ ? ok_button_->GetPreferredSize().height() : 0, 357 ok_button_ ? ok_button_->GetPreferredSize().height() : 0,
358 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0); 358 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0);
359 } 359 }
360 360
361 int DialogClientView::GetExtraViewHeight() const { 361 int DialogClientView::GetExtraViewHeight() const {
362 return ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().height() : 0; 362 return ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().height() : 0;
363 } 363 }
364 364
365 int DialogClientView::GetButtonsAndExtraViewRowHeight() const { 365 int DialogClientView::GetButtonsAndExtraViewRowHeight() const {
366 return std::max(GetExtraViewHeight(), GetButtonHeight()); 366 return std::max(GetExtraViewHeight(), GetButtonHeight());
367 } 367 }
368 368
369 gfx::Insets DialogClientView::GetButtonRowInsets() const { 369 gfx::Insets DialogClientView::GetButtonRowInsets() const {
370 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() 370 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets()
371 : button_row_insets_; 371 : button_row_insets_;
372 } 372 }
373 373
374 int DialogClientView::GetButtonsAndExtraViewRowTopPadding() const { 374 int DialogClientView::GetButtonsAndExtraViewRowTopPadding() const {
375 // Harmony does not use the extra padding.
376 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
377 return 0;
378
375 int spacing = button_row_insets_.top(); 379 int spacing = button_row_insets_.top();
376 // Some subclasses of DialogClientView, in order to do their own layout, set 380 // Some subclasses of DialogClientView, in order to do their own layout, set
377 // button_row_insets_ to gfx::Insets(). To avoid breaking behavior of those 381 // button_row_insets_ to gfx::Insets(). To avoid breaking behavior of those
378 // dialogs, supplying 0 for the top inset of the row falls back to 382 // dialogs, supplying 0 for the top inset of the row falls back to
379 // ViewsDelegate::GetRelatedControlVerticalSpacing or 383 // ViewsDelegate::GetRelatedControlVerticalSpacing or
380 // kRelatedControlVerticalSpacing. 384 // kRelatedControlVerticalSpacing.
381 if (!spacing) 385 if (!spacing)
382 spacing = ViewsDelegate::GetInstance() 386 spacing = ViewsDelegate::GetInstance()
383 ? ViewsDelegate::GetInstance() 387 ? ViewsDelegate::GetInstance()
384 ->GetDialogRelatedControlVerticalSpacing() 388 ->GetDialogRelatedControlVerticalSpacing()
(...skipping 19 matching lines...) Expand all
404 std::remove(child_views.begin(), child_views.end(), nullptr), 408 std::remove(child_views.begin(), child_views.end(), nullptr),
405 child_views.end()); 409 child_views.end());
406 410
407 // Setup focus by reordering views. It is not safe to use SetNextFocusableView 411 // Setup focus by reordering views. It is not safe to use SetNextFocusableView
408 // since child views may be added externally to this view. 412 // since child views may be added externally to this view.
409 for (size_t i = 0; i < child_views.size(); i++) 413 for (size_t i = 0; i < child_views.size(); i++)
410 ReorderChildView(child_views[i], i); 414 ReorderChildView(child_views[i], i);
411 } 415 }
412 416
413 } // namespace views 417 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698