Commit f96f7903 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: introduce DialogDelegate::SetExtraView

This method takes ownership of a View to use for the dialog's extra view
slot. This change also has the default implementation of
DialogDelegate::CreateExtraView return the view provided by
SetExtraView. It then migrates some users of CreateExtraView to use
SetExtraView, from their constructors if possible, by:

1) Moving their Foo::CreateExtraView method to a free function inside an
   anonymous namespace
2) Invoking it from their constructor, and storing a weak raw pointer to
   the created View if needed

Further CLs will remove other uses of CreateExtraView and eventually
remove it in favor of DialogDelegate pushing the extra view to
DialogClientView.

Bug: 1011446
Change-Id: If3a9f3ebe086122dc28b76c233193e7cfb4c0152
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865597Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707209}
parent 8d6b0163
...@@ -47,6 +47,15 @@ constexpr char kLearnMoreUrl[] = ...@@ -47,6 +47,15 @@ constexpr char kLearnMoreUrl[] =
// Tag value used to uniquely identify the "learn more" (?) button. // Tag value used to uniquely identify the "learn more" (?) button.
constexpr int kLearnMoreButton = 100; constexpr int kLearnMoreButton = 100;
std::unique_ptr<views::View> CreateExtraView(views::ButtonListener* listener) {
auto learn_more = views::CreateVectorImageButton(listener);
views::SetImageFromVectorIcon(learn_more.get(),
vector_icons::kHelpOutlineIcon);
learn_more->SetTooltipText(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
learn_more->set_tag(kLearnMoreButton);
return learn_more;
}
class InvertBubbleView : public views::BubbleDialogDelegateView, class InvertBubbleView : public views::BubbleDialogDelegateView,
public views::LinkListener, public views::LinkListener,
public views::ButtonListener { public views::ButtonListener {
...@@ -56,7 +65,6 @@ class InvertBubbleView : public views::BubbleDialogDelegateView, ...@@ -56,7 +65,6 @@ class InvertBubbleView : public views::BubbleDialogDelegateView,
private: private:
// Overridden from views::BubbleDialogDelegateView: // Overridden from views::BubbleDialogDelegateView:
std::unique_ptr<views::View> CreateExtraView() override;
int GetDialogButtons() const override; int GetDialogButtons() const override;
void Init() override; void Init() override;
...@@ -87,6 +95,7 @@ InvertBubbleView::InvertBubbleView(Browser* browser, views::View* anchor_view) ...@@ -87,6 +95,7 @@ InvertBubbleView::InvertBubbleView(Browser* browser, views::View* anchor_view)
dark_theme_(nullptr) { dark_theme_(nullptr) {
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK, DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_DONE)); l10n_util::GetStringUTF16(IDS_DONE));
DialogDelegate::SetExtraView(::CreateExtraView(this));
set_margins(gfx::Insets()); set_margins(gfx::Insets());
chrome::RecordDialogCreation(chrome::DialogIdentifier::INVERT); chrome::RecordDialogCreation(chrome::DialogIdentifier::INVERT);
} }
...@@ -94,15 +103,6 @@ InvertBubbleView::InvertBubbleView(Browser* browser, views::View* anchor_view) ...@@ -94,15 +103,6 @@ InvertBubbleView::InvertBubbleView(Browser* browser, views::View* anchor_view)
InvertBubbleView::~InvertBubbleView() { InvertBubbleView::~InvertBubbleView() {
} }
std::unique_ptr<views::View> InvertBubbleView::CreateExtraView() {
auto learn_more = views::CreateVectorImageButton(this);
views::SetImageFromVectorIcon(learn_more.get(),
vector_icons::kHelpOutlineIcon);
learn_more->SetTooltipText(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
learn_more->set_tag(kLearnMoreButton);
return learn_more;
}
int InvertBubbleView::GetDialogButtons() const { int InvertBubbleView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK; return ui::DIALOG_BUTTON_OK;
} }
......
...@@ -25,6 +25,18 @@ ...@@ -25,6 +25,18 @@
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace {
std::unique_ptr<views::View> CreateExtraView(views::ButtonListener* listener) {
auto help_button = CreateVectorImageButton(listener);
help_button->SetFocusForPlatform();
help_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
SetImageFromVectorIcon(help_button.get(), vector_icons::kHelpOutlineIcon);
return help_button;
}
} // namespace
ConfirmBubbleViews::ConfirmBubbleViews( ConfirmBubbleViews::ConfirmBubbleViews(
std::unique_ptr<ConfirmBubbleModel> model) std::unique_ptr<ConfirmBubbleModel> model)
: model_(std::move(model)), help_button_(nullptr) { : model_(std::move(model)), help_button_(nullptr) {
...@@ -34,6 +46,7 @@ ConfirmBubbleViews::ConfirmBubbleViews( ...@@ -34,6 +46,7 @@ ConfirmBubbleViews::ConfirmBubbleViews(
DialogDelegate::set_button_label( DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL, ui::DIALOG_BUTTON_CANCEL,
model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL)); model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL));
help_button_ = DialogDelegate::SetExtraView(::CreateExtraView(this));
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType( set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT)); views::TEXT, views::TEXT));
...@@ -76,15 +89,6 @@ bool ConfirmBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { ...@@ -76,15 +89,6 @@ bool ConfirmBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const {
} }
} }
std::unique_ptr<views::View> ConfirmBubbleViews::CreateExtraView() {
auto help_button = CreateVectorImageButton(this);
help_button->SetFocusForPlatform();
help_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
help_button_ = help_button.get();
SetImageFromVectorIcon(help_button_, vector_icons::kHelpOutlineIcon);
return help_button;
}
bool ConfirmBubbleViews::Cancel() { bool ConfirmBubbleViews::Cancel() {
model_->Cancel(); model_->Cancel();
return true; return true;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
class ConfirmBubbleModel; class ConfirmBubbleModel;
namespace views { namespace views {
class ImageButton;
class Label; class Label;
} // namespace views } // namespace views
...@@ -38,7 +37,6 @@ class ConfirmBubbleViews : public views::DialogDelegateView, ...@@ -38,7 +37,6 @@ class ConfirmBubbleViews : public views::DialogDelegateView,
// views::DialogDelegate implementation. // views::DialogDelegate implementation.
bool IsDialogButtonEnabled(ui::DialogButton button) const override; bool IsDialogButtonEnabled(ui::DialogButton button) const override;
std::unique_ptr<views::View> CreateExtraView() override;
bool Cancel() override; bool Cancel() override;
bool Accept() override; bool Accept() override;
...@@ -59,7 +57,7 @@ class ConfirmBubbleViews : public views::DialogDelegateView, ...@@ -59,7 +57,7 @@ class ConfirmBubbleViews : public views::DialogDelegateView,
std::unique_ptr<ConfirmBubbleModel> model_; std::unique_ptr<ConfirmBubbleModel> model_;
views::Label* label_; views::Label* label_;
views::ImageButton* help_button_; views::View* help_button_;
DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleViews); DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleViews);
}; };
......
...@@ -54,6 +54,9 @@ ChooserDialogView::ChooserDialogView( ...@@ -54,6 +54,9 @@ ChooserDialogView::ChooserDialogView(
device_chooser_content_view_->SetBorder(views::CreateEmptyBorder( device_chooser_content_view_->SetBorder(views::CreateEmptyBorder(
ChromeLayoutProvider::Get()->GetDialogInsetsForContentType( ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::CONTROL, views::CONTROL))); views::CONTROL, views::CONTROL)));
DialogDelegate::SetExtraView(device_chooser_content_view_->CreateExtraView());
chrome::RecordDialogCreation(chrome::DialogIdentifier::CHOOSER); chrome::RecordDialogCreation(chrome::DialogIdentifier::CHOOSER);
} }
...@@ -80,10 +83,6 @@ views::View* ChooserDialogView::GetInitiallyFocusedView() { ...@@ -80,10 +83,6 @@ views::View* ChooserDialogView::GetInitiallyFocusedView() {
return dcv ? dcv->cancel_button() : nullptr; return dcv ? dcv->cancel_button() : nullptr;
} }
std::unique_ptr<views::View> ChooserDialogView::CreateExtraView() {
return device_chooser_content_view_->CreateExtraView();
}
bool ChooserDialogView::Accept() { bool ChooserDialogView::Accept() {
device_chooser_content_view_->Accept(); device_chooser_content_view_->Accept();
return true; return true;
......
...@@ -31,7 +31,6 @@ class ChooserDialogView : public views::DialogDelegateView, ...@@ -31,7 +31,6 @@ class ChooserDialogView : public views::DialogDelegateView,
// views::DialogDelegate: // views::DialogDelegate:
bool IsDialogButtonEnabled(ui::DialogButton button) const override; bool IsDialogButtonEnabled(ui::DialogButton button) const override;
views::View* GetInitiallyFocusedView() override; views::View* GetInitiallyFocusedView() override;
std::unique_ptr<views::View> CreateExtraView() override;
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
bool Close() override; bool Close() override;
......
...@@ -50,6 +50,16 @@ namespace { ...@@ -50,6 +50,16 @@ namespace {
// This value is negative so that it doesn't overlap with a sink index. // This value is negative so that it doesn't overlap with a sink index.
constexpr int kAlternativeSourceButtonId = -1; constexpr int kAlternativeSourceButtonId = -1;
std::unique_ptr<views::Button> CreateSourcesButton(
views::ButtonListener* listener) {
auto sources_button = std::make_unique<views::MdTextButtonWithDownArrow>(
listener,
l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_ALTERNATIVE_SOURCES_BUTTON));
sources_button->SetID(kAlternativeSourceButtonId);
sources_button->SetEnabled(false);
return sources_button;
}
} // namespace } // namespace
// static // static
...@@ -134,16 +144,6 @@ int CastDialogView::GetDialogButtons() const { ...@@ -134,16 +144,6 @@ int CastDialogView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE; return ui::DIALOG_BUTTON_NONE;
} }
std::unique_ptr<views::View> CastDialogView::CreateExtraView() {
auto sources_button = std::make_unique<views::MdTextButtonWithDownArrow>(
this,
l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_ALTERNATIVE_SOURCES_BUTTON));
sources_button->SetID(kAlternativeSourceButtonId);
sources_button->SetEnabled(false);
sources_button_ = sources_button.get();
return sources_button;
}
bool CastDialogView::Close() { bool CastDialogView::Close() {
return Cancel(); return Cancel();
} }
...@@ -267,6 +267,7 @@ CastDialogView::CastDialogView(views::View* anchor_view, ...@@ -267,6 +267,7 @@ CastDialogView::CastDialogView(views::View* anchor_view,
controller_(controller), controller_(controller),
profile_(profile), profile_(profile),
metrics_(start_time) { metrics_(start_time) {
sources_button_ = DialogDelegate::SetExtraView(CreateSourcesButton(this));
ShowNoSinksView(); ShowNoSinksView();
} }
......
...@@ -85,7 +85,6 @@ class CastDialogView : public views::BubbleDialogDelegateView, ...@@ -85,7 +85,6 @@ class CastDialogView : public views::BubbleDialogDelegateView,
// views::DialogDelegate: // views::DialogDelegate:
int GetDialogButtons() const override; int GetDialogButtons() const override;
std::unique_ptr<views::View> CreateExtraView() override;
bool Close() override; bool Close() override;
// CastDialogController::Observer: // CastDialogController::Observer:
......
...@@ -103,6 +103,13 @@ std::unique_ptr<views::LabelButton> CreateUndoButton( ...@@ -103,6 +103,13 @@ std::unique_ptr<views::LabelButton> CreateUndoButton(
return undo_button; return undo_button;
} }
std::unique_ptr<views::View> CreateManageButton(
views::ButtonListener* listener) {
return views::MdTextButton::CreateSecondaryUiButton(
listener,
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_MANAGE_PASSWORDS_BUTTON));
}
} // namespace } // namespace
std::unique_ptr<views::Label> CreateUsernameLabel( std::unique_ptr<views::Label> CreateUsernameLabel(
...@@ -240,6 +247,7 @@ PasswordItemsView::PasswordItemsView(content::WebContents* web_contents, ...@@ -240,6 +247,7 @@ PasswordItemsView::PasswordItemsView(content::WebContents* web_contents,
anchor_view, anchor_view,
reason, reason,
/*easily_dismissable=*/true) { /*easily_dismissable=*/true) {
DialogDelegate::SetExtraView(CreateManageButton(this));
DCHECK_EQ(password_manager::ui::MANAGE_STATE, model()->state()); DCHECK_EQ(password_manager::ui::MANAGE_STATE, model()->state());
if (model()->local_credentials().empty()) { if (model()->local_credentials().empty()) {
...@@ -294,13 +302,6 @@ void PasswordItemsView::NotifyPasswordFormAction( ...@@ -294,13 +302,6 @@ void PasswordItemsView::NotifyPasswordFormAction(
model()->OnPasswordAction(password_form, action); model()->OnPasswordAction(password_form, action);
} }
std::unique_ptr<views::View> PasswordItemsView::CreateExtraView() {
auto view = views::MdTextButton::CreateSecondaryUiButton(
this,
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_MANAGE_PASSWORDS_BUTTON));
return view;
}
int PasswordItemsView::GetDialogButtons() const { int PasswordItemsView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK; return ui::DIALOG_BUTTON_OK;
} }
......
...@@ -50,7 +50,6 @@ class PasswordItemsView : public PasswordBubbleViewBase, ...@@ -50,7 +50,6 @@ class PasswordItemsView : public PasswordBubbleViewBase,
void RecreateLayout(); void RecreateLayout();
// LocationBarBubbleDelegateView: // LocationBarBubbleDelegateView:
std::unique_ptr<views::View> CreateExtraView() override;
int GetDialogButtons() const override; int GetDialogButtons() const override;
bool ShouldShowCloseButton() const override; bool ShouldShowCloseButton() const override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
......
...@@ -66,12 +66,35 @@ std::unique_ptr<views::Label> CreateText(const base::string16& message) { ...@@ -66,12 +66,35 @@ std::unique_ptr<views::Label> CreateText(const base::string16& message) {
return text; return text;
} }
std::unique_ptr<views::View> CreateLogoView() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Show Google Chrome Enterprise logo only for official build.
auto logo_image = std::make_unique<views::ImageView>();
logo_image->SetImage(
ui::ResourceBundle::GetSharedInstance()
.GetImageNamed((logo_image->GetNativeTheme()->ShouldUseDarkColors())
? IDR_PRODUCT_LOGO_ENTERPRISE_WHITE
: IDR_PRODUCT_LOGO_ENTERPRISE)
.AsImageSkia());
logo_image->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_PRODUCT_LOGO_ENTERPRISE_ALT_TEXT));
gfx::Rect logo_bounds = logo_image->GetImageBounds();
logo_image->SetImageSize(gfx::Size(
logo_bounds.width() * kLogoHeight / logo_bounds.height(), kLogoHeight));
logo_image->SetVerticalAlignment(views::ImageView::Alignment::kCenter);
return logo_image;
#else
return nullptr;
#endif
}
} // namespace } // namespace
EnterpriseStartupDialogView::EnterpriseStartupDialogView( EnterpriseStartupDialogView::EnterpriseStartupDialogView(
EnterpriseStartupDialog::DialogResultCallback callback) EnterpriseStartupDialog::DialogResultCallback callback)
: callback_(std::move(callback)) { : callback_(std::move(callback)) {
DialogDelegate::set_draggable(true); DialogDelegate::set_draggable(true);
DialogDelegate::SetExtraView(CreateLogoView());
SetBorder(views::CreateEmptyBorder(GetDialogInsets())); SetBorder(views::CreateEmptyBorder(GetDialogInsets()));
CreateDialogWidget(this, nullptr, nullptr)->Show(); CreateDialogWidget(this, nullptr, nullptr)->Show();
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -171,28 +194,6 @@ ui::ModalType EnterpriseStartupDialogView::GetModalType() const { ...@@ -171,28 +194,6 @@ ui::ModalType EnterpriseStartupDialogView::GetModalType() const {
return ui::MODAL_TYPE_NONE; return ui::MODAL_TYPE_NONE;
} }
std::unique_ptr<views::View> EnterpriseStartupDialogView::CreateExtraView() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Show Google Chrome Enterprise logo only for official build.
auto logo_image = std::make_unique<views::ImageView>();
logo_image->SetImage(
ui::ResourceBundle::GetSharedInstance()
.GetImageNamed((logo_image->GetNativeTheme()->ShouldUseDarkColors())
? IDR_PRODUCT_LOGO_ENTERPRISE_WHITE
: IDR_PRODUCT_LOGO_ENTERPRISE)
.AsImageSkia());
logo_image->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_PRODUCT_LOGO_ENTERPRISE_ALT_TEXT));
gfx::Rect logo_bounds = logo_image->GetImageBounds();
logo_image->SetImageSize(gfx::Size(
logo_bounds.width() * kLogoHeight / logo_bounds.height(), kLogoHeight));
logo_image->SetVerticalAlignment(views::ImageView::Alignment::kCenter);
return logo_image;
#else
return nullptr;
#endif
}
int EnterpriseStartupDialogView::GetDialogButtons() const { int EnterpriseStartupDialogView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK; return ui::DIALOG_BUTTON_OK;
} }
......
...@@ -47,7 +47,6 @@ class EnterpriseStartupDialogView : public views::DialogDelegateView { ...@@ -47,7 +47,6 @@ class EnterpriseStartupDialogView : public views::DialogDelegateView {
bool Close() override; bool Close() override;
bool ShouldShowWindowTitle() const override; bool ShouldShowWindowTitle() const override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
std::unique_ptr<views::View> CreateExtraView() override;
// override ui::DialogModal // override ui::DialogModal
int GetDialogButtons() const override; int GetDialogButtons() const override;
......
...@@ -33,6 +33,15 @@ namespace { ...@@ -33,6 +33,15 @@ namespace {
// Minimum width for the multi-line label. // Minimum width for the multi-line label.
const int kMinimumDialogLabelWidth = 400; const int kMinimumDialogLabelWidth = 400;
std::unique_ptr<views::Link> CreateExtraView(views::LinkListener* listener) {
auto advanced_link = std::make_unique<views::Link>(
l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED));
advanced_link->set_listener(listener);
advanced_link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
return advanced_link;
}
} // namespace } // namespace
// static // static
...@@ -80,6 +89,7 @@ OneClickSigninDialogView::OneClickSigninDialogView( ...@@ -80,6 +89,7 @@ OneClickSigninDialogView::OneClickSigninDialogView(
DialogDelegate::set_button_label( DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL, ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON)); l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON));
advanced_link_ = DialogDelegate::SetExtraView(::CreateExtraView(this));
DCHECK(!confirmed_callback_.is_null()); DCHECK(!confirmed_callback_.is_null());
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType( set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
...@@ -137,16 +147,6 @@ void OneClickSigninDialogView::WindowClosing() { ...@@ -137,16 +147,6 @@ void OneClickSigninDialogView::WindowClosing() {
dialog_view_ = NULL; dialog_view_ = NULL;
} }
std::unique_ptr<views::View> OneClickSigninDialogView::CreateExtraView() {
auto advanced_link = std::make_unique<views::Link>(
l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED));
advanced_link->set_listener(this);
advanced_link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
advanced_link_ = advanced_link.get();
return advanced_link;
}
void OneClickSigninDialogView::LinkClicked(views::Link* source, void OneClickSigninDialogView::LinkClicked(views::Link* source,
int event_flags) { int event_flags) {
if (source == learn_more_link_) { if (source == learn_more_link_) {
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
#include "ui/views/controls/link_listener.h" #include "ui/views/controls/link_listener.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
namespace views {
class View;
}
// This class allows users to confirm sync signin in cases where signin is // This class allows users to confirm sync signin in cases where signin is
// untrusted. // untrusted.
class OneClickSigninDialogView : public views::DialogDelegateView, class OneClickSigninDialogView : public views::DialogDelegateView,
...@@ -62,7 +58,6 @@ class OneClickSigninDialogView : public views::DialogDelegateView, ...@@ -62,7 +58,6 @@ class OneClickSigninDialogView : public views::DialogDelegateView,
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
void WindowClosing() override; void WindowClosing() override;
std::unique_ptr<views::View> CreateExtraView() override;
bool Accept() override; bool Accept() override;
// Overridden from views::LinkListener: // Overridden from views::LinkListener:
......
...@@ -87,6 +87,10 @@ void ProfileSigninConfirmationDialogViews::ShowDialog( ...@@ -87,6 +87,10 @@ void ProfileSigninConfirmationDialogViews::ShowDialog(
void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) { void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) {
prompt_for_new_profile_ = prompt_for_new_profile; prompt_for_new_profile_ = prompt_for_new_profile;
if (prompt_for_new_profile) {
DialogDelegate::SetExtraView(views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE)));
}
constrained_window::CreateBrowserModalDialogViews( constrained_window::CreateBrowserModalDialogViews(
this, browser_->window()->GetNativeWindow())->Show(); this, browser_->window()->GetNativeWindow())->Show();
} }
...@@ -109,15 +113,6 @@ base::string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel( ...@@ -109,15 +113,6 @@ base::string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel(
return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL); return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL);
} }
std::unique_ptr<views::View>
ProfileSigninConfirmationDialogViews::CreateExtraView() {
if (!prompt_for_new_profile_)
return nullptr;
return views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE));
}
bool ProfileSigninConfirmationDialogViews::Accept() { bool ProfileSigninConfirmationDialogViews::Accept() {
if (delegate_) { if (delegate_) {
if (prompt_for_new_profile_) if (prompt_for_new_profile_)
......
...@@ -41,7 +41,6 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView, ...@@ -41,7 +41,6 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
// views::DialogDelegateView: // views::DialogDelegateView:
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
std::unique_ptr<views::View> CreateExtraView() override;
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
......
...@@ -26,6 +26,19 @@ ...@@ -26,6 +26,19 @@
#include "ui/views/vector_icons.h" #include "ui/views/vector_icons.h"
#include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_client_view.h"
namespace {
std::unique_ptr<views::View> CreateOtherTransportsButton(
views::ButtonListener* listener) {
auto other_transports_button =
std::make_unique<views::MdTextButtonWithDownArrow>(
listener,
l10n_util::GetStringUTF16(IDS_WEBAUTHN_TRANSPORT_POPUP_LABEL));
return other_transports_button;
}
} // namespace
// static // static
void ShowAuthenticatorRequestDialog( void ShowAuthenticatorRequestDialog(
content::WebContents* web_contents, content::WebContents* web_contents,
...@@ -54,6 +67,8 @@ AuthenticatorRequestDialogView::AuthenticatorRequestDialogView( ...@@ -54,6 +67,8 @@ AuthenticatorRequestDialogView::AuthenticatorRequestDialogView(
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
model_(std::move(model)), model_(std::move(model)),
sheet_(nullptr), sheet_(nullptr),
other_transports_button_(
DialogDelegate::SetExtraView(CreateOtherTransportsButton(this))),
web_contents_hidden_(web_contents->GetVisibility() == web_contents_hidden_(web_contents->GetVisibility() ==
content::Visibility::HIDDEN) { content::Visibility::HIDDEN) {
DCHECK(!model_->should_dialog_be_closed()); DCHECK(!model_->should_dialog_be_closed());
...@@ -89,15 +104,6 @@ gfx::Size AuthenticatorRequestDialogView::CalculatePreferredSize() const { ...@@ -89,15 +104,6 @@ gfx::Size AuthenticatorRequestDialogView::CalculatePreferredSize() const {
return gfx::Size(width, GetHeightForWidth(width)); return gfx::Size(width, GetHeightForWidth(width));
} }
std::unique_ptr<views::View> AuthenticatorRequestDialogView::CreateExtraView() {
auto other_transports_button =
std::make_unique<views::MdTextButtonWithDownArrow>(
this, l10n_util::GetStringUTF16(IDS_WEBAUTHN_TRANSPORT_POPUP_LABEL));
other_transports_button_ = other_transports_button.get();
ToggleOtherTransportsButtonVisibility();
return other_transports_button;
}
bool AuthenticatorRequestDialogView::Accept() { bool AuthenticatorRequestDialogView::Accept() {
sheet()->model()->OnAccept(); sheet()->model()->OnAccept();
return false; return false;
...@@ -371,10 +377,6 @@ void AuthenticatorRequestDialogView::UpdateUIForCurrentSheet() { ...@@ -371,10 +377,6 @@ void AuthenticatorRequestDialogView::UpdateUIForCurrentSheet() {
} }
void AuthenticatorRequestDialogView::ToggleOtherTransportsButtonVisibility() { void AuthenticatorRequestDialogView::ToggleOtherTransportsButtonVisibility() {
// The button is not yet created when this is called for the first time.
if (!other_transports_button_)
return;
other_transports_button_->SetVisible(ShouldOtherTransportsButtonBeVisible()); other_transports_button_->SetVisible(ShouldOtherTransportsButtonBeVisible());
} }
......
...@@ -66,7 +66,6 @@ class AuthenticatorRequestDialogView ...@@ -66,7 +66,6 @@ class AuthenticatorRequestDialogView
// views::DialogDelegateView: // views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
std::unique_ptr<views::View> CreateExtraView() override;
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
bool Close() override; bool Close() override;
...@@ -106,7 +105,7 @@ class AuthenticatorRequestDialogView ...@@ -106,7 +105,7 @@ class AuthenticatorRequestDialogView
std::unique_ptr<AuthenticatorRequestDialogModel> model_; std::unique_ptr<AuthenticatorRequestDialogModel> model_;
AuthenticatorRequestSheetView* sheet_ = nullptr; AuthenticatorRequestSheetView* sheet_ = nullptr;
views::Button* other_transports_button_ = nullptr; views::View* other_transports_button_ = nullptr;
std::unique_ptr<views::MenuRunner> other_transports_menu_runner_; std::unique_ptr<views::MenuRunner> other_transports_menu_runner_;
bool first_shown_ = false; bool first_shown_ = false;
......
...@@ -140,7 +140,7 @@ bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const { ...@@ -140,7 +140,7 @@ bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const {
} }
std::unique_ptr<View> DialogDelegate::CreateExtraView() { std::unique_ptr<View> DialogDelegate::CreateExtraView() {
return nullptr; return std::move(extra_view_);
} }
std::unique_ptr<View> DialogDelegate::CreateFootnoteView() { std::unique_ptr<View> DialogDelegate::CreateFootnoteView() {
......
...@@ -103,6 +103,8 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { ...@@ -103,6 +103,8 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
// Override this function to display an extra view adjacent to the buttons. // Override this function to display an extra view adjacent to the buttons.
// Overrides may construct the view; this will only be called once per dialog. // Overrides may construct the view; this will only be called once per dialog.
// DEPRECATED: Prefer to use SetExtraView() below; this method is being
// removed. See https://crbug.com/1011446.
virtual std::unique_ptr<View> CreateExtraView(); virtual std::unique_ptr<View> CreateExtraView();
// Override this function to display a footnote view below the buttons. // Override this function to display a footnote view below the buttons.
...@@ -141,6 +143,13 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { ...@@ -141,6 +143,13 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
const gfx::Insets& margins() const { return margins_; } const gfx::Insets& margins() const { return margins_; }
void set_margins(const gfx::Insets& margins) { margins_ = margins; } void set_margins(const gfx::Insets& margins) { margins_ = margins; }
template <typename T>
T* SetExtraView(std::unique_ptr<T> extra_view) {
T* view = extra_view.get();
extra_view_ = std::move(extra_view);
return view;
}
// A helper for accessing the DialogClientView object contained by this // A helper for accessing the DialogClientView object contained by this
// delegate's Window. // delegate's Window.
const DialogClientView* GetDialogClientView() const; const DialogClientView* GetDialogClientView() const;
...@@ -194,6 +203,9 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { ...@@ -194,6 +203,9 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
// Dialog parameters for this dialog. // Dialog parameters for this dialog.
Params params_; Params params_;
// The extra view for this dialog, if there is one.
std::unique_ptr<View> extra_view_ = nullptr;
// Observers for DialogModel changes. // Observers for DialogModel changes.
base::ObserverList<DialogObserver>::Unchecked observer_list_; base::ObserverList<DialogObserver>::Unchecked observer_list_;
......
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