Commit 82982a2b authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Use set_fixed_width() for *_BUBBLE_PREFERRED_WIDTH

Removes CalculatePreferredSize() use for a chunk of remaining dialogs
that specify a fixed preferred width.

Bug: 1128500
Change-Id: Ib8c072f758a1ae7e3532c5472181be8229e1f53b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493666
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarCharlene Yan <cyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820405}
parent 5ab05eb5
......@@ -60,6 +60,10 @@ LocalCardMigrationBubbleViews::LocalCardMigrationBubbleViews(
SetAcceptCallback(
base::BindOnce(&LocalCardMigrationBubbleViews::OnDialogAccepted,
base::Unretained(this)));
SetShowCloseButton(true);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH));
}
void LocalCardMigrationBubbleViews::Show(DisplayReason reason) {
......@@ -91,13 +95,6 @@ void LocalCardMigrationBubbleViews::OnDialogCancelled() {
controller_->OnCancelButtonClicked();
}
gfx::Size LocalCardMigrationBubbleViews::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
void LocalCardMigrationBubbleViews::AddedToWidget() {
auto title_container = std::make_unique<views::View>();
title_container->SetLayoutManager(std::make_unique<views::BoxLayout>(
......@@ -139,10 +136,6 @@ void LocalCardMigrationBubbleViews::AddedToWidget() {
GetBubbleFrameView()->SetTitleView(std::move(title_container));
}
bool LocalCardMigrationBubbleViews::ShouldShowCloseButton() const {
return true;
}
base::string16 LocalCardMigrationBubbleViews::GetWindowTitle() const {
return controller_ ? l10n_util::GetStringUTF16(
IDS_AUTOFILL_LOCAL_CARD_MIGRATION_BUBBLE_TITLE)
......
......@@ -35,9 +35,7 @@ class LocalCardMigrationBubbleViews : public LocalCardMigrationBubble,
void Hide() override;
// LocationBarBubbleDelegateView:
gfx::Size CalculatePreferredSize() const override;
void AddedToWidget() override;
bool ShouldShowCloseButton() const override;
base::string16 GetWindowTitle() const override;
void WindowClosing() override;
void OnWidgetClosing(views::Widget* widget) override;
......
......@@ -52,13 +52,17 @@ SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
SaveCardBubbleController* controller)
: LocationBarBubbleDelegateView(anchor_view, web_contents),
controller_(controller) {
DCHECK(controller);
SetButtonLabel(ui::DIALOG_BUTTON_OK, controller->GetAcceptButtonText());
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL, controller->GetDeclineButtonText());
SetCancelCallback(base::BindOnce(&SaveCardBubbleViews::OnDialogCancelled,
base::Unretained(this)));
SetAcceptCallback(base::BindOnce(&SaveCardBubbleViews::OnDialogAccepted,
base::Unretained(this)));
DCHECK(controller);
SetShowCloseButton(true);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH));
chrome::RecordDialogCreation(chrome::DialogIdentifier::SAVE_CARD);
}
......@@ -92,13 +96,6 @@ void SaveCardBubbleViews::OnDialogCancelled() {
controller_->OnCancelButton();
}
gfx::Size SaveCardBubbleViews::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
void SaveCardBubbleViews::AddedToWidget() {
// Use a custom title container if offering to upload a server card.
// Done when this view is added to the widget, so the bubble frame
......@@ -110,10 +107,6 @@ void SaveCardBubbleViews::AddedToWidget() {
std::make_unique<TitleWithIconAndSeparatorView>(GetWindowTitle()));
}
bool SaveCardBubbleViews::ShouldShowCloseButton() const {
return true;
}
base::string16 SaveCardBubbleViews::GetWindowTitle() const {
return controller_ ? controller_->GetWindowTitle() : base::string16();
}
......
......@@ -39,12 +39,8 @@ class SaveCardBubbleViews : public SaveCardBubbleView,
// SaveCardBubbleView:
void Hide() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
// LocationBarBubbleDelegateView:
void AddedToWidget() override;
// views::WidgetDelegate:
bool ShouldShowCloseButton() const override;
base::string16 GetWindowTitle() const override;
void WindowClosing() override;
void OnWidgetClosing(views::Widget* widget) override;
......@@ -86,7 +82,7 @@ class SaveCardBubbleViews : public SaveCardBubbleView,
// Attributes IDs to the dialog's DialogDelegate-supplied buttons.
void AssignIdsToDialogButtons();
// views::BubbleDialogDelegateView:
// LocationBarBubbleDelegateView:
void Init() override;
void OnDialogAccepted();
......
......@@ -20,12 +20,16 @@ SaveUPIOfferBubbleViews::SaveUPIOfferBubbleViews(
controller_(controller) {
DCHECK(controller_);
SetTitle(l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_UPI_PROMPT_TITLE));
SetButtonLabel(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_UPI_PROMPT_ACCEPT));
SetButtonLabel(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_UPI_PROMPT_REJECT));
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH));
}
SaveUPIOfferBubbleViews::~SaveUPIOfferBubbleViews() = default;
......@@ -34,22 +38,11 @@ void SaveUPIOfferBubbleViews::Show() {
ShowForReason(LocationBarBubbleDelegateView::DisplayReason::AUTOMATIC);
}
gfx::Size SaveUPIOfferBubbleViews::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
bool SaveUPIOfferBubbleViews::Accept() {
controller_->OnAccept();
return true;
}
base::string16 SaveUPIOfferBubbleViews::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_UPI_PROMPT_TITLE);
}
void SaveUPIOfferBubbleViews::Hide() {
if (controller_)
controller_->OnBubbleClosed();
......
......@@ -31,20 +31,14 @@ class SaveUPIOfferBubbleViews : public autofill::SaveUPIBubble,
// Displays the bubble.
void Show();
// LocationBarBubbleDelegateView:
gfx::Size CalculatePreferredSize() const override;
private:
// views::View:
bool Accept() override;
// views::WidgetDelegate:
base::string16 GetWindowTitle() const override;
// autofill::SaveUPIBubble:
void Hide() override;
// views::BubbleDialogDelegateView:
// LocationBarBubbleDelegateView:
void Init() override;
~SaveUPIOfferBubbleViews() override;
......
......@@ -74,13 +74,6 @@ base::string16 CrostiniAnsibleSoftwareConfigView::GetSubtextLabel() const {
}
}
gfx::Size CrostiniAnsibleSoftwareConfigView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
void CrostiniAnsibleSoftwareConfigView::
OnAnsibleSoftwareConfigurationStarted() {}
......@@ -119,6 +112,9 @@ CrostiniAnsibleSoftwareConfigView::CrostiniAnsibleSoftwareConfigView(
crostini::AnsibleManagementService::GetForProfile(profile)) {
ansible_management_service_->AddObserver(this);
set_fixed_width(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
......
......@@ -22,7 +22,6 @@ class CrostiniAnsibleSoftwareConfigView
public:
// views::DialogDelegateView:
bool Accept() override;
gfx::Size CalculatePreferredSize() const override;
// crostini::AnsibleManagementService::Observer:
void OnAnsibleSoftwareConfigurationStarted() override;
......
......@@ -62,13 +62,6 @@ void CrostiniRecoveryView::Show(Profile* profile,
g_crostini_recovery_view->GetWidget()->Show();
}
gfx::Size CrostiniRecoveryView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
bool CrostiniRecoveryView::Accept() {
SetButtonEnabled(ui::DIALOG_BUTTON_OK, false);
SetButtonEnabled(ui::DIALOG_BUTTON_CANCEL, false);
......@@ -126,6 +119,8 @@ CrostiniRecoveryView::CrostiniRecoveryView(
l10n_util::GetStringUTF16(IDS_CROSTINI_RECOVERY_TERMINAL_BUTTON));
SetShowCloseButton(false);
SetTitle(IDS_CROSTINI_RECOVERY_TITLE);
set_fixed_width(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
......
......@@ -27,7 +27,6 @@ class CrostiniRecoveryView : public views::BubbleDialogDelegateView {
crostini::CrostiniSuccessCallback callback);
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
bool Accept() override;
bool Cancel() override;
......
......@@ -78,13 +78,6 @@ bool CrostiniUninstallerView::Cancel() {
return true; // Should close the dialog
}
gfx::Size CrostiniUninstallerView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
// static
CrostiniUninstallerView* CrostiniUninstallerView::GetActiveViewForTesting() {
return g_crostini_uninstaller_view;
......@@ -97,7 +90,8 @@ CrostiniUninstallerView::CrostiniUninstallerView(Profile* profile)
SetButtonLabel(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_CROSTINI_UNINSTALLER_UNINSTALL_BUTTON));
set_fixed_width(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
......
......@@ -36,7 +36,6 @@ class CrostiniUninstallerView : public views::BubbleDialogDelegateView {
// views::DialogDelegateView:
bool Accept() override;
bool Cancel() override;
gfx::Size CalculatePreferredSize() const override;
static CrostiniUninstallerView* GetActiveViewForTesting();
void set_destructor_callback_for_testing(base::OnceClosure callback) {
......
......@@ -46,13 +46,6 @@ void CrostiniUpdateComponentView::Show(Profile* profile) {
g_crostini_upgrade_view->GetWidget()->Show();
}
gfx::Size CrostiniUpdateComponentView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
// static
CrostiniUpdateComponentView*
CrostiniUpdateComponentView::GetActiveViewForTesting() {
......@@ -63,6 +56,8 @@ CrostiniUpdateComponentView::CrostiniUpdateComponentView() {
SetButtons(ui::DIALOG_BUTTON_OK);
SetShowCloseButton(false);
SetTitle(IDS_CROSTINI_TERMINA_UPDATE_REQUIRED);
set_fixed_width(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
......
......@@ -19,9 +19,6 @@ class CrostiniUpdateComponentView : public views::BubbleDialogDelegateView {
public:
static void Show(Profile* profile);
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
static CrostiniUpdateComponentView* GetActiveViewForTesting();
private:
......
......@@ -90,13 +90,6 @@ void CrostiniUpdateFilesystemView::Show(Profile* profile) {
g_crostini_update_filesystem_view_dialog->GetWidget()->Show();
}
gfx::Size CrostiniUpdateFilesystemView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
// static
CrostiniUpdateFilesystemView*
CrostiniUpdateFilesystemView::GetActiveViewForTesting() {
......@@ -110,6 +103,9 @@ CrostiniUpdateFilesystemView::CrostiniUpdateFilesystemView() {
SetTitle(IDS_CROSTINI_UPGRADING_LABEL);
SetButtons(ui::DIALOG_BUTTON_OK);
set_fixed_width(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
......
......@@ -19,9 +19,6 @@ class CrostiniUpdateFilesystemView : public views::BubbleDialogDelegateView {
public:
static void Show(Profile* profile);
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
static CrostiniUpdateFilesystemView* GetActiveViewForTesting();
private:
......
......@@ -52,7 +52,6 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
void InvokeActionForTesting(Action action) override;
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
base::string16 GetWindowTitle() const override;
ui::ModalType GetModalType() const override;
......@@ -89,6 +88,9 @@ DownloadDangerPromptViews::DownloadDangerPromptViews(
? l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD)
: l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN));
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH));
auto make_done_callback = [&](DownloadDangerPrompt::Action action) {
return base::BindOnce(&DownloadDangerPromptViews::RunDone,
base::Unretained(this), action);
......@@ -182,13 +184,6 @@ void DownloadDangerPromptViews::OnDownloadUpdated(
}
}
gfx::Size DownloadDangerPromptViews::CalculatePreferredSize() const {
int preferred_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(preferred_width, GetHeightForWidth(preferred_width));
}
base::string16 DownloadDangerPromptViews::GetMessageBody() const {
if (show_context_) {
switch (download_->GetDangerType()) {
......
......@@ -111,6 +111,13 @@ gfx::Size DialogClientView::CalculatePreferredSize() const {
}
gfx::Size DialogClientView::GetMinimumSize() const {
// TODO(pbos): Try to find a way for ClientView::GetMinimumSize() to be
// fixed-width aware. For now this uses min-size = preferred size for
// fixed-width dialogs (even though min height might not be preferred height).
// Fixing this might require View::GetMinHeightForWidth().
if (GetDialogDelegate()->fixed_width())
return CalculatePreferredSize();
return GetBoundingSizeForVerticalStack(
ClientView::GetMinimumSize(), button_row_container_->GetMinimumSize());
}
......
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