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

Use set_fixed_width() for remaining dialogs

Replaces remaining CalculatePreferredSize() overrides that are used to
unconditionally set a specific fixed width.

Bug: 1128500
Change-Id: I93abc6b85be7fa956e65608819806aaac23d8d9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2538131Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827470}
parent 41ddf6d6
......@@ -35,6 +35,11 @@ IdleActionWarningDialogView::IdleActionWarningDialogView(
: idle_action_time_(idle_action_time) {
DialogDelegate::SetButtons(ui::DIALOG_BUTTON_NONE);
SetModalType(ui::MODAL_TYPE_SYSTEM);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
SetBorder(views::CreateEmptyBorder(
ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(views::TEXT,
views::TEXT)));
......@@ -66,10 +71,6 @@ void IdleActionWarningDialogView::Update(base::TimeTicks idle_action_time) {
UpdateTitle();
}
ui::ModalType IdleActionWarningDialogView::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
base::string16 IdleActionWarningDialogView::GetWindowTitle() const {
const base::TimeDelta time_until_idle_action =
std::max(idle_action_time_ - base::TimeTicks::Now(), base::TimeDelta());
......@@ -80,18 +81,6 @@ base::string16 IdleActionWarningDialogView::GetWindowTitle() const {
time_until_idle_action));
}
bool IdleActionWarningDialogView::ShouldShowCloseButton() const {
return false;
}
gfx::Size IdleActionWarningDialogView::CalculatePreferredSize() const {
const int default_width = views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH);
return gfx::Size(
default_width,
GetLayoutManager()->GetPreferredHeightForWidth(this, default_width));
}
IdleActionWarningDialogView::~IdleActionWarningDialogView() = default;
void IdleActionWarningDialogView::UpdateTitle() {
......
......@@ -24,12 +24,7 @@ class IdleActionWarningDialogView : public views::DialogDelegateView {
void Update(base::TimeTicks idle_action_time);
// views::DialogDelegateView:
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
private:
~IdleActionWarningDialogView() override;
......
......@@ -39,6 +39,15 @@ LocalCardMigrationErrorDialogView::LocalCardMigrationErrorDialogView(
SetCancelCallback(
base::BindOnce(&LocalCardMigrationDialogController::OnDoneButtonClicked,
base::Unretained(controller_)));
// The error dialog should be a modal dialog blocking the whole browser
// which is consistent with other dialogs. It should make sure that the
// user can see the error message.
SetModalType(ui::MODAL_TYPE_WINDOW);
SetShowCloseButton(false);
set_fixed_width(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_LARGE_MODAL_DIALOG_PREFERRED_WIDTH));
set_close_on_deactivate(false);
set_margins(gfx::Insets());
}
......@@ -57,24 +66,6 @@ void LocalCardMigrationErrorDialogView::CloseDialog() {
GetWidget()->Close();
}
gfx::Size LocalCardMigrationErrorDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_LARGE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
ui::ModalType LocalCardMigrationErrorDialogView::GetModalType() const {
// The error dialog should be a modal dialog blocking the whole browser
// which is consistent with other dialogs. It should make sure that the
// user can see the error message.
return ui::MODAL_TYPE_WINDOW;
}
bool LocalCardMigrationErrorDialogView::ShouldShowCloseButton() const {
return false;
}
void LocalCardMigrationErrorDialogView::WindowClosing() {
if (controller_) {
controller_->OnDialogClosed();
......
......@@ -29,14 +29,11 @@ class LocalCardMigrationErrorDialogView
content::WebContents* web_contents);
~LocalCardMigrationErrorDialogView() override;
// LocalCardMigrationDialog
// LocalCardMigrationDialog:
void ShowDialog() override;
void CloseDialog() override;
// views::BubbleDialogDelegateView
gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override;
bool ShouldShowCloseButton() const override;
// views::BubbleDialogDelegateView:
void Init() override;
void WindowClosing() override;
......
......@@ -27,6 +27,7 @@ namespace autofill {
VirtualCardSelectionDialogViewImpl::VirtualCardSelectionDialogViewImpl(
VirtualCardSelectionDialogController* controller)
: controller_(controller) {
SetShowTitle(true);
SetButtonLabel(ui::DIALOG_BUTTON_OK, controller_->GetOkButtonLabel());
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL, controller_->GetCancelButtonLabel());
SetAcceptCallback(
......@@ -35,6 +36,11 @@ VirtualCardSelectionDialogViewImpl::VirtualCardSelectionDialogViewImpl(
SetCancelCallback(base::BindOnce(
&VirtualCardSelectionDialogController::OnCancelButtonClicked,
base::Unretained(controller_)));
SetModalType(ui::MODAL_TYPE_CHILD);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
}
VirtualCardSelectionDialogViewImpl::~VirtualCardSelectionDialogViewImpl() {
......@@ -65,12 +71,6 @@ void VirtualCardSelectionDialogViewImpl::Hide() {
GetWidget()->Close();
}
gfx::Size VirtualCardSelectionDialogViewImpl::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH);
return gfx::Size(width, GetHeightForWidth(width));
}
void VirtualCardSelectionDialogViewImpl::AddedToWidget() {
// TODO(crbug.com/1020740): The header image is not ready. Implement it later.
}
......@@ -81,10 +81,6 @@ bool VirtualCardSelectionDialogViewImpl::IsDialogButtonEnabled(
: true;
}
ui::ModalType VirtualCardSelectionDialogViewImpl::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
views::View* VirtualCardSelectionDialogViewImpl::GetContentsView() {
RemoveAllChildViews(/*delete_children=*/true);
......@@ -111,12 +107,4 @@ base::string16 VirtualCardSelectionDialogViewImpl::GetWindowTitle() const {
return controller_->GetContentTitle();
}
bool VirtualCardSelectionDialogViewImpl::ShouldShowWindowTitle() const {
return true;
}
bool VirtualCardSelectionDialogViewImpl::ShouldShowCloseButton() const {
return false;
}
} // namespace autofill
......@@ -26,14 +26,10 @@ class VirtualCardSelectionDialogViewImpl
void Hide() override;
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
void AddedToWidget() override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
ui::ModalType GetModalType() const override;
View* GetContentsView() override;
base::string16 GetWindowTitle() const override;
bool ShouldShowWindowTitle() const override;
bool ShouldShowCloseButton() const override;
private:
VirtualCardSelectionDialogController* controller_ = nullptr;
......
......@@ -23,6 +23,7 @@ WebauthnDialogViewImpl::WebauthnDialogViewImpl(
WebauthnDialogController* controller,
WebauthnDialogState dialog_state)
: controller_(controller) {
SetShowTitle(false);
SetLayoutManager(std::make_unique<views::FillLayout>());
std::unique_ptr<WebauthnDialogModel> model =
std::make_unique<WebauthnDialogModel>(dialog_state);
......@@ -32,6 +33,11 @@ WebauthnDialogViewImpl::WebauthnDialogViewImpl(
AddChildView(CreateSheetViewForAutofillWebAuthn(std::move(model)));
sheet_view_->ReInitChildViews();
SetModalType(ui::MODAL_TYPE_CHILD);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
SetButtonLabel(ui::DIALOG_BUTTON_OK, model_->GetAcceptButtonLabel());
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL, model_->GetCancelButtonLabel());
SetButtons(model_->IsAcceptButtonVisible()
......@@ -78,12 +84,6 @@ void WebauthnDialogViewImpl::OnDialogStateChanged() {
}
}
gfx::Size WebauthnDialogViewImpl::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH);
return gfx::Size(width, GetHeightForWidth(width));
}
bool WebauthnDialogViewImpl::Accept() {
DCHECK_EQ(model_->dialog_state(), WebauthnDialogState::kOffer);
controller_->OnOkButtonClicked();
......@@ -106,22 +106,10 @@ bool WebauthnDialogViewImpl::IsDialogButtonEnabled(
: true;
}
ui::ModalType WebauthnDialogViewImpl::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
base::string16 WebauthnDialogViewImpl::GetWindowTitle() const {
return model_->GetStepTitle();
}
bool WebauthnDialogViewImpl::ShouldShowWindowTitle() const {
return false;
}
bool WebauthnDialogViewImpl::ShouldShowCloseButton() const {
return false;
}
void WebauthnDialogViewImpl::Hide() {
// Reset controller reference if the controller has been destroyed before the
// view being destroyed. This happens if browser window is closed when the
......
......@@ -32,14 +32,10 @@ class WebauthnDialogViewImpl : public WebauthnDialogView,
void OnDialogStateChanged() override;
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
bool Accept() override;
bool Cancel() override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowWindowTitle() const override;
bool ShouldShowCloseButton() const override;
private:
// Closes the dialog.
......
......@@ -58,6 +58,7 @@ ChromeCleanerDialog::ChromeCleanerDialog(
DCHECK(dialog_controller_);
DCHECK(cleaner_controller_);
SetTitle(IDS_CHROME_CLEANUP_PROMPT_TITLE);
SetButtonLabel(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_PROMPT_REMOVE_BUTTON_LABEL));
......@@ -77,6 +78,11 @@ ChromeCleanerDialog::ChromeCleanerDialog(
base::Unretained(this),
DialogInteractionResult::kClose));
SetModalType(ui::MODAL_TYPE_WINDOW);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get();
set_margins(
layout_provider->GetDialogInsetsForContentType(views::TEXT, views::TEXT));
......@@ -133,17 +139,6 @@ void ChromeCleanerDialog::Show(Browser* browser) {
cleaner_controller_->AddObserver(this);
}
// WidgetDelegate overrides.
ui::ModalType ChromeCleanerDialog::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
base::string16 ChromeCleanerDialog::GetWindowTitle() const {
DCHECK(dialog_controller_);
return l10n_util::GetStringUTF16(IDS_CHROME_CLEANUP_PROMPT_TITLE);
}
views::View* ChromeCleanerDialog::GetInitiallyFocusedView() {
// Set focus away from the Remove/OK button to prevent accidental prompt
// acceptance if the user is typing as the dialog appears.
......@@ -151,19 +146,6 @@ views::View* ChromeCleanerDialog::GetInitiallyFocusedView() {
return details_button_;
}
bool ChromeCleanerDialog::ShouldShowCloseButton() const {
return false;
}
// View overrides.
gfx::Size ChromeCleanerDialog::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
// safe_browsing::ChromeCleanerController::Observer overrides
void ChromeCleanerDialog::OnIdle(
......
......@@ -46,14 +46,8 @@ class ChromeCleanerDialog
void Show(Browser* browser);
// views::WidgetDelegate overrides.
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
// views::DialogDelegateView:
views::View* GetInitiallyFocusedView() override;
bool ShouldShowCloseButton() const override;
// views::View overrides.
gfx::Size CalculatePreferredSize() const override;
// safe_browsing::ChromeCleanerController::Observer overrides.
void OnIdle(
......
......@@ -49,17 +49,6 @@ views::Widget* CrostiniForceCloseView::Show(
return dialog_widget;
}
ui::ModalType CrostiniForceCloseView::GetModalType() const {
return ui::ModalType::MODAL_TYPE_WINDOW;
}
gfx::Size CrostiniForceCloseView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
CrostiniForceCloseView::CrostiniForceCloseView(
const base::string16& app_name,
base::OnceClosure force_close_callback) {
......@@ -74,6 +63,10 @@ CrostiniForceCloseView::CrostiniForceCloseView(
l10n_util::GetStringUTF16(IDS_CROSTINI_FORCE_CLOSE_ACCEPT_BUTTON));
SetAcceptCallback(std::move(force_close_callback));
SetModalType(ui::ModalType::MODAL_TYPE_WINDOW);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
......
......@@ -36,10 +36,6 @@ class CrostiniForceCloseView : public views::BubbleDialogDelegateView {
gfx::NativeView closable_view,
base::OnceClosure force_close_callback);
// BubbleDialogDelegateView overrides.
ui::ModalType GetModalType() const override;
gfx::Size CalculatePreferredSize() const override;
private:
CrostiniForceCloseView(const base::string16& app_name,
base::OnceClosure force_close_callback);
......
......@@ -32,13 +32,6 @@ void CrostiniPackageInstallFailureView::Show(const std::string& error_message) {
->Show();
}
gfx::Size CrostiniPackageInstallFailureView::CalculatePreferredSize() const {
const int dialog_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(dialog_width, GetHeightForWidth(dialog_width));
}
CrostiniPackageInstallFailureView::CrostiniPackageInstallFailureView(
const std::string& error_message) {
SetShowCloseButton(false);
......@@ -51,6 +44,8 @@ CrostiniPackageInstallFailureView::CrostiniPackageInstallFailureView(
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
set_margins(provider->GetDialogInsetsForContentType(
views::DialogContentType::TEXT, views::DialogContentType::TEXT));
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
views::StyledLabel* message_label =
AddChildView(std::make_unique<views::StyledLabel>());
......
......@@ -13,9 +13,6 @@ class CrostiniPackageInstallFailureView
public:
static void Show(const std::string& error_message);
// BubbleDialogDelegateView overrides.
gfx::Size CalculatePreferredSize() const override;
private:
explicit CrostiniPackageInstallFailureView(const std::string& error_message);
......
......@@ -46,6 +46,8 @@ DownloadInProgressDialogView::DownloadInProgressDialogView(
SetLayoutManager(std::make_unique<views::FillLayout>());
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT));
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
auto run_callback = [](DownloadInProgressDialogView* dialog, bool accept) {
// Note that accepting this dialog means "cancel the download", while cancel
......@@ -86,12 +88,5 @@ DownloadInProgressDialogView::DownloadInProgressDialogView(
DownloadInProgressDialogView::~DownloadInProgressDialogView() = default;
gfx::Size DownloadInProgressDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
BEGIN_METADATA(DownloadInProgressDialogView, views::DialogDelegateView)
END_METADATA
......@@ -32,9 +32,6 @@ class DownloadInProgressDialogView : public views::DialogDelegateView {
const base::Callback<void(bool)>& callback);
~DownloadInProgressDialogView() override;
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
const base::Callback<void(bool)> callback_;
DISALLOW_COPY_AND_ASSIGN(DownloadInProgressDialogView);
......
......@@ -70,6 +70,13 @@ ExtensionInstallBlockedDialogView::ExtensionInstallBlockedDialogView(
SetTitle(
l10n_util::GetStringFUTF16(IDS_EXTENSION_BLOCKED_BY_POLICY_PROMPT_TITLE,
base::UTF8ToUTF16(extension_name)));
// Make sure user know the installation is blocked before taking further
// action.
SetModalType(ui::MODAL_TYPE_CHILD);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
set_draggable(true);
set_close_on_deactivate(false);
SetLayoutManager(std::make_unique<views::FillLayout>());
......@@ -82,19 +89,6 @@ ExtensionInstallBlockedDialogView::~ExtensionInstallBlockedDialogView() {
std::move(done_callback_).Run();
}
gfx::Size ExtensionInstallBlockedDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
ui::ModalType ExtensionInstallBlockedDialogView::GetModalType() const {
// Make sure user know the installation is blocked before taking further
// action.
return ui::MODAL_TYPE_CHILD;
}
void ExtensionInstallBlockedDialogView::AddCustomMessageContents(
const base::string16& custom_error_message) {
DCHECK(!custom_error_message.empty());
......
......@@ -35,10 +35,6 @@ class ExtensionInstallBlockedDialogView
~ExtensionInstallBlockedDialogView() override;
private:
// views::BubbleDialogDelegateView
gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override;
// Creates the contents area that contains custom error message that is set by
// administrator.
void AddCustomMessageContents(const base::string16& custom_error_message);
......
......@@ -221,6 +221,10 @@ ExtensionInstallDialogView::ExtensionInstallDialogView(
default_button = ui::DIALOG_BUTTON_OK;
#endif
SetModalType(ui::MODAL_TYPE_WINDOW);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
SetDefaultButton(default_button);
SetButtons(buttons);
SetAcceptCallback(base::BindOnce(
......@@ -265,13 +269,6 @@ void ExtensionInstallDialogView::ResizeWidget() {
GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
}
gfx::Size ExtensionInstallDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
void ExtensionInstallDialogView::VisibilityChanged(views::View* starting_from,
bool is_visible) {
if (is_visible) {
......@@ -398,6 +395,10 @@ bool ExtensionInstallDialogView::IsDialogButtonEnabled(
return true;
}
base::string16 ExtensionInstallDialogView::GetAccessibleWindowTitle() const {
return title_;
}
void ExtensionInstallDialogView::CloseDialog() {
GetWidget()->Close();
}
......@@ -421,14 +422,6 @@ void ExtensionInstallDialogView::OnShutdown(
CloseDialog();
}
base::string16 ExtensionInstallDialogView::GetAccessibleWindowTitle() const {
return title_;
}
ui::ModalType ExtensionInstallDialogView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
void ExtensionInstallDialogView::LinkClicked() {
GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() +
prompt_->extension()->id());
......
......@@ -53,11 +53,11 @@ class ExtensionInstallDialogView
// Changes the widget size to accommodate the contents' preferred size.
void ResizeWidget();
// views::BubbleDialogDelegate:
gfx::Size CalculatePreferredSize() const override;
// views::BubbleDialogDelegateView:
void VisibilityChanged(views::View* starting_from, bool is_visible) override;
void AddedToWidget() override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
base::string16 GetAccessibleWindowTitle() const override;
private:
void CloseDialog();
......@@ -68,10 +68,6 @@ class ExtensionInstallDialogView
extensions::UninstallReason reason) override;
void OnShutdown(extensions::ExtensionRegistry* registry) override;
// views::WidgetDelegate:
base::string16 GetAccessibleWindowTitle() const override;
ui::ModalType GetModalType() const override;
void LinkClicked();
void OnDialogCanceled();
void OnDialogAccepted();
......
......@@ -43,11 +43,10 @@ SettingsOverriddenDialogView::SettingsOverriddenDialogView(
SetCancelCallback(make_result_callback(DialogResult::kKeepNewSettings));
SetCloseCallback(make_result_callback(DialogResult::kDialogDismissed));
// Modals shouldn't show a close button according to the latest style
// guidelines. Note the dialog can still be dismissed by user action via the
// escape key (in addition to closing automatically if the parent widget
// is destroyed).
SetModalType(ui::MODAL_TYPE_WINDOW);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
SettingsOverriddenDialogController::ShowParams show_params =
controller_->GetShowParams();
......@@ -90,17 +89,6 @@ void SettingsOverriddenDialogView::Show(gfx::NativeWindow parent) {
controller_->OnDialogShown();
}
ui::ModalType SettingsOverriddenDialogView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
gfx::Size SettingsOverriddenDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
void SettingsOverriddenDialogView::NotifyControllerOfResult(
SettingsOverriddenDialogController::DialogResult result) {
DCHECK(!result_)
......
......@@ -27,10 +27,6 @@ class SettingsOverriddenDialogView : public views::DialogDelegateView {
void Show(gfx::NativeWindow parent);
private:
// views::DialogDelegateView:
ui::ModalType GetModalType() const override;
gfx::Size CalculatePreferredSize() const override;
// Notifies the |controller_| of the |result|.
void NotifyControllerOfResult(
SettingsOverriddenDialogController::DialogResult result);
......
......@@ -47,6 +47,8 @@ void ImportLockDialogView::Show(gfx::NativeWindow parent,
ImportLockDialogView::ImportLockDialogView(
base::OnceCallback<void(bool)> callback)
: callback_(std::move(callback)) {
SetTitle(IDS_IMPORTER_LOCK_TITLE);
SetButtonLabel(ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_OK));
......@@ -61,6 +63,10 @@ ImportLockDialogView::ImportLockDialogView(
SetCancelCallback(
base::BindOnce(done_callback, base::Unretained(this), false));
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
SetLayoutManager(std::make_unique<views::FillLayout>());
views::Label* description_label =
new views::Label(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT));
......@@ -73,19 +79,4 @@ ImportLockDialogView::ImportLockDialogView(
chrome::RecordDialogCreation(chrome::DialogIdentifier::IMPORT_LOCK);
}
ImportLockDialogView::~ImportLockDialogView() {
}
gfx::Size ImportLockDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH);
return gfx::Size(width, GetHeightForWidth(width));
}
base::string16 ImportLockDialogView::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE);
}
bool ImportLockDialogView::ShouldShowCloseButton() const {
return false;
}
ImportLockDialogView::~ImportLockDialogView() = default;
......@@ -21,15 +21,6 @@ class ImportLockDialogView : public views::DialogDelegateView {
explicit ImportLockDialogView(base::OnceCallback<void(bool)> callback);
~ImportLockDialogView() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
// views::DialogDelegate:
base::string16 GetWindowTitle() const override;
// views::WidgetDelegate:
bool ShouldShowCloseButton() const override;
private:
// Called with the result of the dialog.
base::OnceCallback<void(bool)> callback_;
......
......@@ -107,6 +107,8 @@ CookieControlsBubbleView::CookieControlsBubbleView(
content_settings::CookieControlsController* controller)
: LocationBarBubbleDelegateView(anchor_view, web_contents),
controller_(controller) {
SetShowTitle(true);
SetShowCloseButton(true);
controller_observer_.Add(controller);
SetButtons(ui::DIALOG_BUTTON_NONE);
}
......@@ -255,14 +257,6 @@ base::string16 CookieControlsBubbleView::GetWindowTitle() const {
}
}
bool CookieControlsBubbleView::ShouldShowWindowTitle() const {
return true;
}
bool CookieControlsBubbleView::ShouldShowCloseButton() const {
return true;
}
void CookieControlsBubbleView::WindowClosing() {
// |cookie_bubble_| can be a new bubble by this point (as Close(); doesn't
// call this right away). Only set to nullptr when it's this bubble.
......
......@@ -65,8 +65,6 @@ class CookieControlsBubbleView : public LocationBarBubbleDelegateView,
void CloseBubble() override;
void Init() override;
base::string16 GetWindowTitle() const override;
bool ShouldShowWindowTitle() const override;
bool ShouldShowCloseButton() const override;
void WindowClosing() override;
gfx::Size CalculatePreferredSize() const override;
void AddedToWidget() override;
......
......@@ -27,6 +27,11 @@ AutoSigninFirstRunDialogView::AutoSigninFirstRunDialogView(
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_TURN_OFF));
SetModalType(ui::MODAL_TYPE_CHILD);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
using ControllerCallbackFn = void (CredentialManagerDialogController::*)();
auto call_controller = [](AutoSigninFirstRunDialogView* dialog,
ControllerCallbackFn func) {
......@@ -59,25 +64,10 @@ void AutoSigninFirstRunDialogView::ControllerGone() {
controller_ = nullptr;
}
ui::ModalType AutoSigninFirstRunDialogView::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
base::string16 AutoSigninFirstRunDialogView::GetWindowTitle() const {
return controller_->GetAutoSigninPromoTitle();
}
bool AutoSigninFirstRunDialogView::ShouldShowCloseButton() const {
return false;
}
gfx::Size AutoSigninFirstRunDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
void AutoSigninFirstRunDialogView::WindowClosing() {
if (controller_)
controller_->OnCloseDialog();
......
......@@ -22,10 +22,7 @@ class AutoSigninFirstRunDialogView : public views::DialogDelegateView,
private:
// views::DialogDelegateView:
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
gfx::Size CalculatePreferredSize() const override;
void WindowClosing() override;
// Sets up the child views.
......
......@@ -65,7 +65,12 @@ CredentialLeakDialogView::CredentialLeakDialogView(
SetButtonLabel(ui::DIALOG_BUTTON_OK, controller_->GetAcceptButtonLabel());
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL, controller_->GetCancelButtonLabel());
using ControllerClosureFn = void (CredentialLeakDialogController::*)(void);
SetModalType(ui::MODAL_TYPE_CHILD);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
using ControllerClosureFn = void (CredentialLeakDialogController::*)();
auto close_callback = [](CredentialLeakDialogController** controller,
ControllerClosureFn fn) {
// Null out the controller pointer stored in the parent object, to avoid any
......@@ -106,21 +111,6 @@ void CredentialLeakDialogView::ControllerGone() {
GetWidget()->Close();
}
ui::ModalType CredentialLeakDialogView::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
gfx::Size CredentialLeakDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
bool CredentialLeakDialogView::ShouldShowCloseButton() const {
return false;
}
void CredentialLeakDialogView::OnThemeChanged() {
views::DialogDelegateView::OnThemeChanged();
GetBubbleFrameView()->SetHeaderView(
......
......@@ -28,9 +28,6 @@ class CredentialLeakDialogView : public views::DialogDelegateView,
private:
// views::DialogDelegateView:
ui::ModalType GetModalType() const override;
gfx::Size CalculatePreferredSize() const override;
bool ShouldShowCloseButton() const override;
void OnThemeChanged() override;
base::string16 GetWindowTitle() const override;
......
......@@ -58,18 +58,10 @@ void RelaunchRequiredDialogView::SetDeadline(base::Time deadline) {
relaunch_required_timer_.SetDeadline(deadline);
}
ui::ModalType RelaunchRequiredDialogView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
base::string16 RelaunchRequiredDialogView::GetWindowTitle() const {
return relaunch_required_timer_.GetWindowTitle();
}
bool RelaunchRequiredDialogView::ShouldShowCloseButton() const {
return false;
}
gfx::ImageSkia RelaunchRequiredDialogView::GetWindowIcon() {
return gfx::CreateVectorIcon(
gfx::IconDescription(vector_icons::kBusinessIcon,
......@@ -78,13 +70,6 @@ gfx::ImageSkia RelaunchRequiredDialogView::GetWindowIcon() {
gfx::kChromeIconGrey));
}
gfx::Size RelaunchRequiredDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
// |relaunch_required_timer_| automatically starts for the next time the title
// needs to be updated (e.g., from "2 days" to "3 days").
RelaunchRequiredDialogView::RelaunchRequiredDialogView(
......@@ -110,6 +95,12 @@ RelaunchRequiredDialogView::RelaunchRequiredDialogView(
SetCancelCallback(base::BindOnce(
base::RecordAction, base::UserMetricsAction("RelaunchRequired_Close")));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetModalType(ui::MODAL_TYPE_WINDOW);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
chrome::RecordDialogCreation(chrome::DialogIdentifier::RELAUNCH_REQUIRED);
const ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
set_margins(
......
......@@ -38,15 +38,9 @@ class RelaunchRequiredDialogView : views::DialogDelegateView {
void SetDeadline(base::Time deadline);
// views::DialogDelegateView:
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
gfx::ImageSkia GetWindowIcon() override;
protected:
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
private:
RelaunchRequiredDialogView(base::Time deadline,
base::RepeatingClosure on_accept);
......
......@@ -73,7 +73,11 @@ WebAppUninstallDialogDelegateView::WebAppUninstallDialogDelegateView(
std::make_unique<WebAppInfoImageSource>(kIconSizeInDip, icon_bitmaps),
image_size);
SetModalType(ui::MODAL_TYPE_WINDOW);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
SetShowIcon(true);
SetTitle(l10n_util::GetStringFUTF16(
IDS_EXTENSION_PROMPT_UNINSTALL_TITLE,
......@@ -143,17 +147,6 @@ void WebAppUninstallDialogDelegateView::OnDialogCanceled() {
std::exchange(dialog_, nullptr)->CallCallback(/*uninstalled=*/false);
}
gfx::Size WebAppUninstallDialogDelegateView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
ui::ModalType WebAppUninstallDialogDelegateView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
gfx::ImageSkia WebAppUninstallDialogDelegateView::GetWindowIcon() {
return image_;
}
......
......@@ -51,10 +51,6 @@ class WebAppUninstallDialogDelegateView : public views::DialogDelegateView {
private:
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
// views::WidgetDelegate:
ui::ModalType GetModalType() const override;
gfx::ImageSkia GetWindowIcon() override;
// Uninstalls the web app. Returns true on success.
......
......@@ -149,12 +149,6 @@ bool AuthenticatorRequestDialogView::ShouldOtherTransportsButtonBeVisible()
sheet_->model()->GetOtherTransportsMenuModel()->GetItemCount();
}
gfx::Size AuthenticatorRequestDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH);
return gfx::Size(width, GetHeightForWidth(width));
}
bool AuthenticatorRequestDialogView::Accept() {
sheet()->model()->OnAccept();
return false;
......@@ -206,22 +200,10 @@ views::View* AuthenticatorRequestDialogView::GetInitiallyFocusedView() {
return nullptr;
}
ui::ModalType AuthenticatorRequestDialogView::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
base::string16 AuthenticatorRequestDialogView::GetWindowTitle() const {
return sheet()->model()->GetStepTitle();
}
bool AuthenticatorRequestDialogView::ShouldShowWindowTitle() const {
return false;
}
bool AuthenticatorRequestDialogView::ShouldShowCloseButton() const {
return false;
}
void AuthenticatorRequestDialogView::OnModelDestroyed() {
NOTREACHED();
}
......@@ -282,6 +264,7 @@ AuthenticatorRequestDialogView::AuthenticatorRequestDialogView(
l10n_util::GetStringUTF16(IDS_WEBAUTHN_TRANSPORT_POPUP_LABEL)))),
web_contents_hidden_(web_contents->GetVisibility() ==
content::Visibility::HIDDEN) {
SetShowTitle(false);
DCHECK(!model_->should_dialog_be_closed());
model_->AddObserver(this);
......@@ -289,6 +272,11 @@ AuthenticatorRequestDialogView::AuthenticatorRequestDialogView(
base::BindOnce(&AuthenticatorRequestDialogView::OnDialogClosing,
base::Unretained(this)));
SetModalType(ui::MODAL_TYPE_CHILD);
SetShowCloseButton(false);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
// Currently, all sheets have a label on top and controls at the bottom.
// Consider moving this to AuthenticatorRequestSheetView if this changes.
SetLayoutManager(std::make_unique<views::FillLayout>());
......
......@@ -63,15 +63,11 @@ class AuthenticatorRequestDialogView
}
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
bool Accept() override;
bool Cancel() override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
View* GetInitiallyFocusedView() override;
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowWindowTitle() const override;
bool ShouldShowCloseButton() const override;
// AuthenticatorRequestDialogModel::Observer:
void OnModelDestroyed() override;
......
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