Commit 270f6dd6 authored by Keren Zhu's avatar Keren Zhu Committed by Commit Bot

Change some ButtonPressed overrides to callbacks: ui/views/examples

Bug: 772945
Change-Id: I972c061fcc008f3c37308c5186e6432d766de1bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2470237
Commit-Queue: Keren Zhu <kerenzhu@chromium.org>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817292}
parent c5056f82
...@@ -29,13 +29,14 @@ void AxExample::CreateExampleView(View* container) { ...@@ -29,13 +29,14 @@ void AxExample::CreateExampleView(View* container) {
layout->SetMainAxisAlignment(LayoutAlignment::kStart); layout->SetMainAxisAlignment(LayoutAlignment::kStart);
layout->SetCrossAxisAlignment(LayoutAlignment::kStart); layout->SetCrossAxisAlignment(LayoutAlignment::kStart);
announce_button_ = container->AddChildView( auto announce_text = [](AxExample* example) {
std::make_unique<MdTextButton>(this, base::ASCIIToUTF16("AnnounceText"))); example->announce_button_->GetViewAccessibility().AnnounceText(
} base::ASCIIToUTF16("Button pressed."));
};
void AxExample::ButtonPressed(Button* sender, const ui::Event& event) {
sender->GetViewAccessibility().AnnounceText( announce_button_ = container->AddChildView(std::make_unique<MdTextButton>(
base::ASCIIToUTF16("Button pressed.")); base::BindRepeating(announce_text, base::Unretained(this)),
base::ASCIIToUTF16("AnnounceText")));
} }
} // namespace examples } // namespace examples
......
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
#define UI_VIEWS_EXAMPLES_AX_EXAMPLE_H_ #define UI_VIEWS_EXAMPLES_AX_EXAMPLE_H_
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/examples/example_base.h" #include "ui/views/examples/example_base.h"
namespace views { namespace views {
class Button;
namespace examples { namespace examples {
// ButtonExample simply counts the number of clicks. // ButtonExample simply counts the number of clicks.
class VIEWS_EXAMPLES_EXPORT AxExample : public ExampleBase, class VIEWS_EXAMPLES_EXPORT AxExample : public ExampleBase {
public ButtonListener {
public: public:
AxExample(); AxExample();
~AxExample() override; ~AxExample() override;
...@@ -24,9 +24,6 @@ class VIEWS_EXAMPLES_EXPORT AxExample : public ExampleBase, ...@@ -24,9 +24,6 @@ class VIEWS_EXAMPLES_EXPORT AxExample : public ExampleBase,
void CreateExampleView(View* container) override; void CreateExampleView(View* container) override;
private: private:
// ButtonListener:
void ButtonPressed(Button* sender, const ui::Event& event) override;
Button* announce_button_ = nullptr; Button* announce_button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AxExample); DISALLOW_COPY_AND_ASSIGN(AxExample);
......
...@@ -76,16 +76,17 @@ void AddLabeledRowToGridLayout(GridLayout* layout, ...@@ -76,16 +76,17 @@ void AddLabeledRowToGridLayout(GridLayout* layout,
// button in |*primary| is a call-to-action button, and the button in // button in |*primary| is a call-to-action button, and the button in
// |*secondary| is a regular button. // |*secondary| is a regular button.
std::vector<std::unique_ptr<MdTextButton>> MakeButtonsInState( std::vector<std::unique_ptr<MdTextButton>> MakeButtonsInState(
ButtonListener* listener,
Button::ButtonState state) { Button::ButtonState state) {
std::vector<std::unique_ptr<MdTextButton>> buttons; std::vector<std::unique_ptr<MdTextButton>> buttons;
const base::string16 button_text = base::ASCIIToUTF16("Button"); const base::string16 button_text = base::ASCIIToUTF16("Button");
auto primary = std::make_unique<views::MdTextButton>(listener, button_text); auto primary = std::make_unique<views::MdTextButton>(
Button::PressedCallback(), button_text);
primary->SetProminent(true); primary->SetProminent(true);
primary->SetState(state); primary->SetState(state);
buttons.push_back(std::move(primary)); buttons.push_back(std::move(primary));
auto secondary = std::make_unique<views::MdTextButton>(listener, button_text); auto secondary = std::make_unique<views::MdTextButton>(
Button::PressedCallback(), button_text);
secondary->SetState(state); secondary->SetState(state);
buttons.push_back(std::move(secondary)); buttons.push_back(std::move(secondary));
return buttons; return buttons;
...@@ -108,19 +109,15 @@ void ButtonStickerSheet::CreateExampleView(View* container) { ...@@ -108,19 +109,15 @@ void ButtonStickerSheet::CreateExampleView(View* container) {
AddLabeledRowToGridLayout(layout, std::string(), std::move(plainLabel)); AddLabeledRowToGridLayout(layout, std::string(), std::move(plainLabel));
AddLabeledRowToGridLayout(layout, "Default", AddLabeledRowToGridLayout(layout, "Default",
MakeButtonsInState(this, Button::STATE_NORMAL)); MakeButtonsInState(Button::STATE_NORMAL));
AddLabeledRowToGridLayout(layout, "Normal", AddLabeledRowToGridLayout(layout, "Normal",
MakeButtonsInState(this, Button::STATE_NORMAL)); MakeButtonsInState(Button::STATE_NORMAL));
AddLabeledRowToGridLayout(layout, "Hovered", AddLabeledRowToGridLayout(layout, "Hovered",
MakeButtonsInState(this, Button::STATE_HOVERED)); MakeButtonsInState(Button::STATE_HOVERED));
AddLabeledRowToGridLayout(layout, "Pressed", AddLabeledRowToGridLayout(layout, "Pressed",
MakeButtonsInState(this, Button::STATE_PRESSED)); MakeButtonsInState(Button::STATE_PRESSED));
AddLabeledRowToGridLayout(layout, "Disabled", AddLabeledRowToGridLayout(layout, "Disabled",
MakeButtonsInState(this, Button::STATE_DISABLED)); MakeButtonsInState(Button::STATE_DISABLED));
}
void ButtonStickerSheet::ButtonPressed(Button* button, const ui::Event& event) {
// Ignore button presses.
} }
} // namespace examples } // namespace examples
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define UI_VIEWS_EXAMPLES_BUTTON_STICKER_SHEET_H_ #define UI_VIEWS_EXAMPLES_BUTTON_STICKER_SHEET_H_
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/examples/example_base.h" #include "ui/views/examples/example_base.h"
namespace views { namespace views {
...@@ -16,8 +15,7 @@ namespace examples { ...@@ -16,8 +15,7 @@ namespace examples {
// design button styles. This example only looks right with `--secondary-ui-md`. // design button styles. This example only looks right with `--secondary-ui-md`.
// It is designed to be as visually similar to the UI Harmony spec's sticker // It is designed to be as visually similar to the UI Harmony spec's sticker
// sheet for buttons as possible. // sheet for buttons as possible.
class VIEWS_EXAMPLES_EXPORT ButtonStickerSheet : public ExampleBase, class VIEWS_EXAMPLES_EXPORT ButtonStickerSheet : public ExampleBase {
public ButtonListener {
public: public:
ButtonStickerSheet(); ButtonStickerSheet();
~ButtonStickerSheet() override; ~ButtonStickerSheet() override;
...@@ -25,9 +23,6 @@ class VIEWS_EXAMPLES_EXPORT ButtonStickerSheet : public ExampleBase, ...@@ -25,9 +23,6 @@ class VIEWS_EXAMPLES_EXPORT ButtonStickerSheet : public ExampleBase,
// ExampleBase: // ExampleBase:
void CreateExampleView(View* container) override; void CreateExampleView(View* container) override;
// ButtonListener:
void ButtonPressed(Button* sender, const ui::Event& event) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ButtonStickerSheet); DISALLOW_COPY_AND_ASSIGN(ButtonStickerSheet);
}; };
......
...@@ -27,11 +27,12 @@ ...@@ -27,11 +27,12 @@
namespace views { namespace views {
namespace examples { namespace examples {
class ThemeTrackingCheckbox : public views::Checkbox, class ThemeTrackingCheckbox : public views::Checkbox {
public views::ButtonListener {
public: public:
explicit ThemeTrackingCheckbox(const base::string16& label) explicit ThemeTrackingCheckbox(const base::string16& label)
: Checkbox(label, this) {} : Checkbox(label,
base::BindRepeating(&ThemeTrackingCheckbox::ButtonPressed,
base::Unretained(this))) {}
ThemeTrackingCheckbox(const ThemeTrackingCheckbox&) = delete; ThemeTrackingCheckbox(const ThemeTrackingCheckbox&) = delete;
ThemeTrackingCheckbox& operator=(const ThemeTrackingCheckbox&) = delete; ThemeTrackingCheckbox& operator=(const ThemeTrackingCheckbox&) = delete;
~ThemeTrackingCheckbox() override = default; ~ThemeTrackingCheckbox() override = default;
...@@ -39,12 +40,10 @@ class ThemeTrackingCheckbox : public views::Checkbox, ...@@ -39,12 +40,10 @@ class ThemeTrackingCheckbox : public views::Checkbox,
// views::Checkbox // views::Checkbox
void OnThemeChanged() override { void OnThemeChanged() override {
views::Checkbox::OnThemeChanged(); views::Checkbox::OnThemeChanged();
SetChecked(GetNativeTheme()->ShouldUseDarkColors()); SetChecked(GetNativeTheme()->ShouldUseDarkColors());
} }
// ButtonListener void ButtonPressed() {
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
GetNativeTheme()->set_use_dark_colors(GetChecked()); GetNativeTheme()->set_use_dark_colors(GetChecked());
GetWidget()->ThemeChanged(); GetWidget()->ThemeChanged();
} }
...@@ -52,10 +51,10 @@ class ThemeTrackingCheckbox : public views::Checkbox, ...@@ -52,10 +51,10 @@ class ThemeTrackingCheckbox : public views::Checkbox,
class TextVectorImageButton : public views::MdTextButton { class TextVectorImageButton : public views::MdTextButton {
public: public:
TextVectorImageButton(ButtonListener* listener, TextVectorImageButton(PressedCallback callback,
const base::string16& text, const base::string16& text,
const gfx::VectorIcon& icon) const gfx::VectorIcon& icon)
: MdTextButton(listener, text), icon_(icon) {} : MdTextButton(callback, text), icon_(icon) {}
TextVectorImageButton(const TextVectorImageButton&) = delete; TextVectorImageButton(const TextVectorImageButton&) = delete;
TextVectorImageButton& operator=(const TextVectorImageButton&) = delete; TextVectorImageButton& operator=(const TextVectorImageButton&) = delete;
~TextVectorImageButton() override = default; ~TextVectorImageButton() override = default;
...@@ -125,7 +124,9 @@ ColoredDialogChooser::ColoredDialogChooser() { ...@@ -125,7 +124,9 @@ ColoredDialogChooser::ColoredDialogChooser() {
l10n_util::GetStringUTF16(IDS_COLORED_DIALOG_CHOOSER_CHECKBOX))); l10n_util::GetStringUTF16(IDS_COLORED_DIALOG_CHOOSER_CHECKBOX)));
AddChildView(std::make_unique<TextVectorImageButton>( AddChildView(std::make_unique<TextVectorImageButton>(
this, l10n_util::GetStringUTF16(IDS_COLORED_DIALOG_CHOOSER_BUTTON), base::BindRepeating(&ColoredDialogChooser::ButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_COLORED_DIALOG_CHOOSER_BUTTON),
views::kInfoIcon)); views::kInfoIcon));
confirmation_label_ = AddChildView( confirmation_label_ = AddChildView(
...@@ -135,8 +136,7 @@ ColoredDialogChooser::ColoredDialogChooser() { ...@@ -135,8 +136,7 @@ ColoredDialogChooser::ColoredDialogChooser() {
ColoredDialogChooser::~ColoredDialogChooser() = default; ColoredDialogChooser::~ColoredDialogChooser() = default;
void ColoredDialogChooser::ButtonPressed(Button* sender, void ColoredDialogChooser::ButtonPressed() {
const ui::Event& event) {
// Create the colored dialog. // Create the colored dialog.
views::Widget* widget = DialogDelegate::CreateDialogWidget( views::Widget* widget = DialogDelegate::CreateDialogWidget(
new ColoredDialog(base::BindOnce(&ColoredDialogChooser::OnFeedbackSubmit, new ColoredDialog(base::BindOnce(&ColoredDialogChooser::OnFeedbackSubmit,
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define UI_VIEWS_EXAMPLES_COLORED_DIALOG_EXAMPLE_H_ #define UI_VIEWS_EXAMPLES_COLORED_DIALOG_EXAMPLE_H_
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/examples/example_base.h" #include "ui/views/examples/example_base.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -14,7 +13,6 @@ ...@@ -14,7 +13,6 @@
namespace views { namespace views {
class Button;
class Label; class Label;
namespace examples { namespace examples {
...@@ -41,15 +39,14 @@ class ColoredDialog : public views::DialogDelegateView, ...@@ -41,15 +39,14 @@ class ColoredDialog : public views::DialogDelegateView,
views::Textfield* textfield_; views::Textfield* textfield_;
}; };
class ColoredDialogChooser : public views::View, public views::ButtonListener { class ColoredDialogChooser : public views::View {
public: public:
ColoredDialogChooser(); ColoredDialogChooser();
ColoredDialogChooser(const ColoredDialogChooser&) = delete; ColoredDialogChooser(const ColoredDialogChooser&) = delete;
ColoredDialogChooser& operator=(const ColoredDialogChooser&) = delete; ColoredDialogChooser& operator=(const ColoredDialogChooser&) = delete;
~ColoredDialogChooser() override; ~ColoredDialogChooser() override;
// ButtonListener void ButtonPressed();
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
void OnFeedbackSubmit(base::string16 text); void OnFeedbackSubmit(base::string16 text);
......
...@@ -169,8 +169,10 @@ void DialogExample::CreateExampleView(View* container) { ...@@ -169,8 +169,10 @@ void DialogExample::CreateExampleView(View* container) {
kFixed, kButtonsColumnId, kFixed, kFixed, kButtonsColumnId, kFixed,
provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL)); provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL));
show_ = layout->AddView( show_ = layout->AddView(std::make_unique<views::MdTextButton>(
std::make_unique<views::MdTextButton>(this, base::ASCIIToUTF16("Show"))); base::BindRepeating(&DialogExample::ShowButtonPressed,
base::Unretained(this)),
base::ASCIIToUTF16("Show")));
} }
void DialogExample::StartRowWithLabel(GridLayout* layout, const char* label) { void DialogExample::StartRowWithLabel(GridLayout* layout, const char* label) {
...@@ -194,7 +196,10 @@ void DialogExample::StartTextfieldRow(GridLayout* layout, ...@@ -194,7 +196,10 @@ void DialogExample::StartTextfieldRow(GridLayout* layout,
} }
void DialogExample::AddCheckbox(GridLayout* layout, Checkbox** member) { void DialogExample::AddCheckbox(GridLayout* layout, Checkbox** member) {
auto checkbox = std::make_unique<Checkbox>(base::string16(), this); auto callback = member == &bubble_ ? &DialogExample::BubbleCheckboxPressed
: &DialogExample::OtherCheckboxPressed;
auto checkbox = std::make_unique<Checkbox>(
base::string16(), base::BindRepeating(callback, base::Unretained(this)));
checkbox->SetChecked(true); checkbox->SetChecked(true);
*member = layout->AddView(std::move(checkbox)); *member = layout->AddView(std::move(checkbox));
} }
...@@ -243,49 +248,48 @@ void DialogExample::ResizeDialog() { ...@@ -243,49 +248,48 @@ void DialogExample::ResizeDialog() {
widget->OnSizeConstraintsChanged(); widget->OnSizeConstraintsChanged();
} }
void DialogExample::ButtonPressed(Button* sender, const ui::Event& event) { void DialogExample::ShowButtonPressed() {
if (sender == show_) { if (bubble_->GetChecked()) {
if (bubble_->GetChecked()) { // |bubble| will be destroyed by its widget when the widget is destroyed.
// |bubble| will be destroyed by its widget when the widget is destroyed. Bubble* bubble = new Bubble(this, show_);
Bubble* bubble = new Bubble(this, sender); last_dialog_ = bubble;
last_dialog_ = bubble; BubbleDialogDelegateView::CreateBubble(bubble);
BubbleDialogDelegateView::CreateBubble(bubble); } else {
} else { // |dialog| will be destroyed by its widget when the widget is destroyed.
// |dialog| will be destroyed by its widget when the widget is destroyed. Dialog* dialog = new Dialog(this);
Dialog* dialog = new Dialog(this); last_dialog_ = dialog;
last_dialog_ = dialog; dialog->InitDelegate();
dialog->InitDelegate();
// constrained_window::CreateBrowserModalDialogViews() allows dialogs to
// constrained_window::CreateBrowserModalDialogViews() allows dialogs to // be created as MODAL_TYPE_WINDOW without specifying a parent.
// be created as MODAL_TYPE_WINDOW without specifying a parent. gfx::NativeView parent = nullptr;
gfx::NativeView parent = nullptr; if (mode_->GetSelectedIndex() != kFakeModeless)
if (mode_->GetSelectedIndex() != kFakeModeless) parent = example_view()->GetWidget()->GetNativeView();
parent = example_view()->GetWidget()->GetNativeView();
DialogDelegate::CreateDialogWidget(
DialogDelegate::CreateDialogWidget( dialog, example_view()->GetWidget()->GetNativeWindow(), parent);
dialog, example_view()->GetWidget()->GetNativeWindow(), parent);
}
last_dialog_->GetWidget()->Show();
return;
} }
last_dialog_->GetWidget()->Show();
}
if (sender == bubble_) { void DialogExample::BubbleCheckboxPressed() {
if (bubble_->GetChecked() && GetModalType() != ui::MODAL_TYPE_CHILD) { if (bubble_->GetChecked() && GetModalType() != ui::MODAL_TYPE_CHILD) {
mode_->SetSelectedIndex(ui::MODAL_TYPE_CHILD); mode_->SetSelectedIndex(ui::MODAL_TYPE_CHILD);
LogStatus("You nearly always want Child Modal for bubbles."); LogStatus("You nearly always want Child Modal for bubbles.");
} }
persistent_bubble_->SetEnabled(bubble_->GetChecked()); persistent_bubble_->SetEnabled(bubble_->GetChecked());
OnPerformAction(); // Validate the modal type. OnPerformAction(); // Validate the modal type.
if (!bubble_->GetChecked() && GetModalType() == ui::MODAL_TYPE_CHILD) { if (!bubble_->GetChecked() && GetModalType() == ui::MODAL_TYPE_CHILD) {
// Do something reasonable when simply unchecking bubble and re-enable. // Do something reasonable when simply unchecking bubble and re-enable.
mode_->SetSelectedIndex(ui::MODAL_TYPE_WINDOW); mode_->SetSelectedIndex(ui::MODAL_TYPE_WINDOW);
OnPerformAction(); OnPerformAction();
}
return;
} }
}
// Other buttons are all checkboxes. Update the dialog if there is one. void DialogExample::OtherCheckboxPressed() {
// Buttons other than show and bubble are pressed. They are all checkboxes.
// Update the dialog if there is one.
if (last_dialog_) { if (last_dialog_) {
last_dialog_->DialogModelChanged(); last_dialog_->DialogModelChanged();
ResizeDialog(); ResizeDialog();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/base/models/simple_combobox_model.h" #include "ui/base/models/simple_combobox_model.h"
#include "ui/views/controls/button/button.h" #include "ui/base/ui_base_types.h"
#include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/examples/example_base.h" #include "ui/views/examples/example_base.h"
...@@ -25,7 +25,6 @@ namespace examples { ...@@ -25,7 +25,6 @@ namespace examples {
// An example that exercises BubbleDialogDelegateView or DialogDelegateView. // An example that exercises BubbleDialogDelegateView or DialogDelegateView.
class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase, class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase,
public ButtonListener,
public TextfieldController { public TextfieldController {
public: public:
DialogExample(); DialogExample();
...@@ -61,8 +60,9 @@ class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase, ...@@ -61,8 +60,9 @@ class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase,
// Resize the dialog Widget to match the preferred size. Triggers Layout(). // Resize the dialog Widget to match the preferred size. Triggers Layout().
void ResizeDialog(); void ResizeDialog();
// ButtonListener: void ShowButtonPressed();
void ButtonPressed(Button* sender, const ui::Event& event) override; void BubbleCheckboxPressed();
void OtherCheckboxPressed();
// TextfieldController: // TextfieldController:
void ContentsChanged(Textfield* sender, void ContentsChanged(Textfield* sender,
......
...@@ -125,21 +125,21 @@ void LabelExample::CreateExampleView(View* container) { ...@@ -125,21 +125,21 @@ void LabelExample::CreateExampleView(View* container) {
AddCustomLabel(container); AddCustomLabel(container);
} }
void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { void LabelExample::MultilineCheckboxPressed() {
if (button == multiline_) { custom_label_->SetMultiLine(multiline_->GetChecked());
custom_label_->SetMultiLine(multiline_->GetChecked()); }
} else if (button == shadows_) {
gfx::ShadowValues shadows; void LabelExample::ShadowsCheckboxPressed() {
if (shadows_->GetChecked()) { gfx::ShadowValues shadows;
shadows.push_back(gfx::ShadowValue(gfx::Vector2d(), 1, SK_ColorRED)); if (shadows_->GetChecked()) {
shadows.push_back(gfx::ShadowValue(gfx::Vector2d(2, 2), 0, SK_ColorGRAY)); shadows.push_back(gfx::ShadowValue(gfx::Vector2d(), 1, SK_ColorRED));
} shadows.push_back(gfx::ShadowValue(gfx::Vector2d(2, 2), 0, SK_ColorGRAY));
custom_label_->SetShadows(shadows);
} else if (button == selectable_) {
custom_label_->SetSelectable(selectable_->GetChecked());
} }
custom_label_->parent()->parent()->InvalidateLayout(); custom_label_->SetShadows(shadows);
custom_label_->SchedulePaint(); }
void LabelExample::SelectableCheckboxPressed() {
custom_label_->SetSelectable(selectable_->GetChecked());
} }
void LabelExample::ContentsChanged(Textfield* sender, void LabelExample::ContentsChanged(Textfield* sender,
...@@ -187,12 +187,18 @@ void LabelExample::AddCustomLabel(View* container) { ...@@ -187,12 +187,18 @@ void LabelExample::AddCustomLabel(View* container) {
column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
GridLayout::ColumnSize::kUsePreferred, 0, 0); GridLayout::ColumnSize::kUsePreferred, 0, 0);
layout->StartRow(0, 1); layout->StartRow(0, 1);
multiline_ = layout->AddView( multiline_ = layout->AddView(std::make_unique<Checkbox>(
std::make_unique<Checkbox>(base::ASCIIToUTF16("Multiline"), this)); base::ASCIIToUTF16("Multiline"),
shadows_ = layout->AddView( base::BindRepeating(&LabelExample::MultilineCheckboxPressed,
std::make_unique<Checkbox>(base::ASCIIToUTF16("Shadows"), this)); base::Unretained(this))));
selectable_ = layout->AddView( shadows_ = layout->AddView(std::make_unique<Checkbox>(
std::make_unique<Checkbox>(base::ASCIIToUTF16("Selectable"), this)); base::ASCIIToUTF16("Shadows"),
base::BindRepeating(&LabelExample::ShadowsCheckboxPressed,
base::Unretained(this))));
selectable_ = layout->AddView(std::make_unique<Checkbox>(
base::ASCIIToUTF16("Selectable"),
base::BindRepeating(&LabelExample::SelectableCheckboxPressed,
base::Unretained(this))));
layout->AddPaddingRow(0, 8); layout->AddPaddingRow(0, 8);
column_set = layout->AddColumnSet(2); column_set = layout->AddColumnSet(2);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define UI_VIEWS_EXAMPLES_LABEL_EXAMPLE_H_ #define UI_VIEWS_EXAMPLES_LABEL_EXAMPLE_H_
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/examples/example_base.h" #include "ui/views/examples/example_base.h"
...@@ -20,7 +19,6 @@ class Label; ...@@ -20,7 +19,6 @@ class Label;
namespace examples { namespace examples {
class VIEWS_EXAMPLES_EXPORT LabelExample : public ExampleBase, class VIEWS_EXAMPLES_EXPORT LabelExample : public ExampleBase,
public ButtonListener,
public TextfieldController { public TextfieldController {
public: public:
LabelExample(); LabelExample();
...@@ -29,8 +27,9 @@ class VIEWS_EXAMPLES_EXPORT LabelExample : public ExampleBase, ...@@ -29,8 +27,9 @@ class VIEWS_EXAMPLES_EXPORT LabelExample : public ExampleBase,
// ExampleBase: // ExampleBase:
void CreateExampleView(View* container) override; void CreateExampleView(View* container) override;
// ButtonListener: void MultilineCheckboxPressed();
void ButtonPressed(Button* button, const ui::Event& event) override; void ShadowsCheckboxPressed();
void SelectableCheckboxPressed();
// TextfieldController: // TextfieldController:
void ContentsChanged(Textfield* sender, void ContentsChanged(Textfield* sender,
......
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