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

views: de-virtualize DialogDelegate::GetDialogButtonLabel

Bug: 1011446
Change-Id: I35b19fa40c105738b286e5bf669049643b45681a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993900
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729919}
parent d8b8781d
...@@ -36,7 +36,13 @@ constexpr int kFakeModeless = ui::MODAL_TYPE_SYSTEM + 1; ...@@ -36,7 +36,13 @@ constexpr int kFakeModeless = ui::MODAL_TYPE_SYSTEM + 1;
template <class DialogType> template <class DialogType>
class DialogExample::Delegate : public virtual DialogType { class DialogExample::Delegate : public virtual DialogType {
public: public:
explicit Delegate(DialogExample* parent) : parent_(parent) {} explicit Delegate(DialogExample* parent) : parent_(parent) {
DialogDelegate::set_buttons(parent_->GetDialogButtons());
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK,
parent_->ok_button_label_->GetText());
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_CANCEL,
parent_->cancel_button_label_->GetText());
}
void InitDelegate() { void InitDelegate() {
this->SetLayoutManager(std::make_unique<FillLayout>()); this->SetLayoutManager(std::make_unique<FillLayout>());
...@@ -67,14 +73,6 @@ class DialogExample::Delegate : public virtual DialogType { ...@@ -67,14 +73,6 @@ class DialogExample::Delegate : public virtual DialogType {
bool Cancel() override { return parent_->AllowDialogClose(false); } bool Cancel() override { return parent_->AllowDialogClose(false); }
bool Accept() override { return parent_->AllowDialogClose(true); } bool Accept() override { return parent_->AllowDialogClose(true); }
int GetDialogButtons() const override { return parent_->GetDialogButtons(); }
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override {
if (button == ui::DIALOG_BUTTON_OK)
return parent_->ok_button_label_->GetText();
if (button == ui::DIALOG_BUTTON_CANCEL)
return parent_->cancel_button_label_->GetText();
return base::string16();
}
private: private:
DialogExample* parent_; DialogExample* parent_;
......
...@@ -40,6 +40,7 @@ class DialogClientViewTest : public test::WidgetTest, ...@@ -40,6 +40,7 @@ class DialogClientViewTest : public test::WidgetTest,
WidgetTest::SetUp(); WidgetTest::SetUp();
DialogDelegate::set_use_custom_frame(false); DialogDelegate::set_use_custom_frame(false);
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_NONE);
// Note: not using DialogDelegate::CreateDialogWidget(..), since that can // Note: not using DialogDelegate::CreateDialogWidget(..), since that can
// alter the frame type according to the platform. // alter the frame type according to the platform.
...@@ -64,13 +65,6 @@ class DialogClientViewTest : public test::WidgetTest, ...@@ -64,13 +65,6 @@ class DialogClientViewTest : public test::WidgetTest,
// DialogDelegateView would delete this, but |this| is owned by the test. // DialogDelegateView would delete this, but |this| is owned by the test.
} }
int GetDialogButtons() const override { return dialog_buttons_; }
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override {
return button == ui::DIALOG_BUTTON_CANCEL && !cancel_label_.empty()
? cancel_label_
: DialogDelegate::GetDialogButtonLabel(button);
}
protected: protected:
gfx::Rect GetUpdatedClientBounds() { gfx::Rect GetUpdatedClientBounds() {
client_view()->SizeToPreferredSize(); client_view()->SizeToPreferredSize();
...@@ -91,7 +85,7 @@ class DialogClientViewTest : public test::WidgetTest, ...@@ -91,7 +85,7 @@ class DialogClientViewTest : public test::WidgetTest,
// Sets the buttons to show in the dialog and refreshes the dialog. // Sets the buttons to show in the dialog and refreshes the dialog.
void SetDialogButtons(int dialog_buttons) { void SetDialogButtons(int dialog_buttons) {
dialog_buttons_ = dialog_buttons; DialogDelegate::set_buttons(dialog_buttons);
DialogModelChanged(); DialogModelChanged();
} }
...@@ -124,7 +118,9 @@ class DialogClientViewTest : public test::WidgetTest, ...@@ -124,7 +118,9 @@ class DialogClientViewTest : public test::WidgetTest,
// exceeded. The resulting width is around 160 pixels, but depends on system // exceeded. The resulting width is around 160 pixels, but depends on system
// fonts. // fonts.
void SetLongCancelLabel() { void SetLongCancelLabel() {
cancel_label_ = base::ASCIIToUTF16("Cancel Cancel Cancel"); DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL, base::ASCIIToUTF16("Cancel Cancel Cancel"));
DialogModelChanged();
} }
DialogClientView* client_view() { DialogClientView* client_view() {
...@@ -137,15 +133,10 @@ class DialogClientViewTest : public test::WidgetTest, ...@@ -137,15 +133,10 @@ class DialogClientViewTest : public test::WidgetTest,
// The dialog Widget. // The dialog Widget.
Widget* widget_ = nullptr; Widget* widget_ = nullptr;
// The bitmask of buttons to show in the dialog.
int dialog_buttons_ = ui::DIALOG_BUTTON_NONE;
gfx::Size preferred_size_; gfx::Size preferred_size_;
gfx::Size min_size_; gfx::Size min_size_;
gfx::Size max_size_; gfx::Size max_size_;
base::string16 cancel_label_; // If set, the label for the Cancel button.
DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest); DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest);
}; };
......
...@@ -103,7 +103,7 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { ...@@ -103,7 +103,7 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
int GetDefaultDialogButton() const; int GetDefaultDialogButton() const;
// Returns the label of the specified dialog button. // Returns the label of the specified dialog button.
virtual base::string16 GetDialogButtonLabel(ui::DialogButton button) const; base::string16 GetDialogButtonLabel(ui::DialogButton button) const;
// Returns whether the specified dialog button is enabled. // Returns whether the specified dialog button is enabled.
virtual bool IsDialogButtonEnabled(ui::DialogButton button) const; virtual bool IsDialogButtonEnabled(ui::DialogButton button) const;
......
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