Commit 90ad13a3 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Views] Allow dialog delegates to use a custom padding for the extra view

Add a new method to allow a DialogDelegate to provide a custom
amount to use as the minimum padding between the extra view and the
button strip in the dialog.
Use this to adjust the padding in the extension uninstall dialog.

BUG=441377

Review URL: https://codereview.chromium.org/1141253002

Cr-Commit-Position: refs/heads/master@{#330622}
parent 2b192b9f
......@@ -80,6 +80,7 @@ class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
private:
// views::DialogDelegate:
views::View* CreateExtraView() override;
bool GetExtraViewPadding(int* padding) override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
int GetDefaultDialogButton() const override {
// Default to accept when triggered via chrome://extensions page.
......@@ -201,6 +202,13 @@ views::View* ExtensionUninstallDialogDelegateView::CreateExtraView() {
return report_abuse_checkbox_;
}
bool ExtensionUninstallDialogDelegateView::GetExtraViewPadding(int* padding) {
// We want a little more padding between the "report abuse" checkbox and the
// buttons.
*padding = views::kUnrelatedControlLargeHorizontalSpacing;
return true;
}
base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
......
......@@ -177,13 +177,16 @@ void DialogClientView::OnDidChangeFocus(View* focused_before,
gfx::Size DialogClientView::GetPreferredSize() const {
// Initialize the size to fit the buttons and extra view row.
int extra_view_padding = 0;
if (!GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding))
extra_view_padding = kRelatedButtonHSpacing;
gfx::Size size(
(ok_button_ ? ok_button_->GetPreferredSize().width() : 0) +
(cancel_button_ ? cancel_button_->GetPreferredSize().width() : 0) +
(cancel_button_ && ok_button_ ? kRelatedButtonHSpacing : 0) +
(ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) +
(ShouldShow(extra_view_) && has_dialog_buttons() ?
kRelatedButtonHSpacing : 0),
extra_view_padding : 0),
0);
int buttons_height = GetButtonsAndExtraViewRowHeight();
......@@ -239,6 +242,14 @@ void DialogClientView::Layout() {
LayoutButton(cancel_button_, &row_bounds);
}
if (extra_view_) {
int custom_padding = 0;
if (has_dialog_buttons() &&
GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) {
// The call to LayoutButton() will already have accounted for some of
// the padding.
custom_padding -= kRelatedButtonHSpacing;
row_bounds.set_width(row_bounds.width() - custom_padding);
}
row_bounds.set_width(std::min(row_bounds.width(),
extra_view_->GetPreferredSize().width()));
extra_view_->SetBoundsRect(row_bounds);
......
......@@ -59,6 +59,11 @@ class DialogClientViewTest : public ViewsTestBase,
// DialogDelegateView implementation.
View* GetContentsView() override { return contents_.get(); }
View* CreateExtraView() override { return extra_view_; }
bool GetExtraViewPadding(int* padding) override {
if (extra_view_padding_)
*padding = *extra_view_padding_;
return extra_view_padding_.get() != nullptr;
}
View* CreateFootnoteView() override { return footnote_view_; }
int GetDialogButtons() const override { return dialog_buttons_; }
......@@ -93,6 +98,13 @@ class DialogClientViewTest : public ViewsTestBase,
client_view_->CreateExtraViews();
}
// Sets the extra view padding.
void SetExtraViewPadding(int padding) {
DCHECK(!extra_view_padding_);
extra_view_padding_.reset(new int(padding));
client_view_->Layout();
}
// Sets the footnote view.
void SetFootnoteView(View* view) {
DCHECK(!footnote_view_);
......@@ -110,6 +122,7 @@ class DialogClientViewTest : public ViewsTestBase,
// The bitmask of buttons to show in the dialog.
int dialog_buttons_;
View* extra_view_; // weak
scoped_ptr<int> extra_view_padding_; // Null by default.
View* footnote_view_; // weak
DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest);
......@@ -182,8 +195,14 @@ TEST_F(DialogClientViewTest, LayoutWithButtons) {
SetExtraView(extra_view);
CheckContentsIsSetToPreferredSize();
EXPECT_GT(client_view()->bounds().height(), no_extra_view_size.height());
int width_of_dialog = client_view()->bounds().width();
int width_of_extra_view = extra_view->bounds().width();
// Try with an adjusted padding for the extra view.
SetExtraViewPadding(250);
CheckContentsIsSetToPreferredSize();
EXPECT_GT(client_view()->bounds().width(), width_of_dialog);
// Visibility of extra view is respected.
extra_view->SetVisible(false);
CheckContentsIsSetToPreferredSize();
......@@ -194,7 +213,7 @@ TEST_F(DialogClientViewTest, LayoutWithButtons) {
extra_view->SetVisible(true);
client_view()->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), no_extra_view_size));
client_view()->Layout();
DCHECK_GT(width_of_extra_view, extra_view->bounds().width());
EXPECT_GT(width_of_extra_view, extra_view->bounds().width());
}
// Test the effect of the footnote view on layout.
......
......@@ -77,6 +77,10 @@ View* DialogDelegate::CreateExtraView() {
return NULL;
}
bool DialogDelegate::GetExtraViewPadding(int* padding) {
return false;
}
View* DialogDelegate::CreateTitlebarExtraView() {
return NULL;
}
......
......@@ -49,6 +49,12 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
// Overrides may construct the view; this will only be called once per dialog.
virtual View* CreateExtraView();
// Override this function to adjust the padding between the extra view and
// the confirm/cancel buttons. Note that if there are no buttons, this will
// not be used.
// If a custom padding should be used, returns true and populates |padding|.
virtual bool GetExtraViewPadding(int* padding);
// Override this function to display an extra view in the titlebar.
// Overrides may construct the view; this will only be called once per dialog.
// Note: this only works for new style dialogs.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment