Commit 2d956c00 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Allow Button::set_callback() to take a RepeatingClosure.

This will be convenient for various callers.

Bug: 772945
Change-Id: I044f791aafe079d0728aabea20e0e287bbf045ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425142
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809681}
parent bb0a6230
...@@ -117,6 +117,16 @@ class VIEWS_EXPORT Button : public InkDropHostView, ...@@ -117,6 +117,16 @@ class VIEWS_EXPORT Button : public InkDropHostView,
set_callback(ListenerToPressedCallback(this, listener)); set_callback(ListenerToPressedCallback(this, listener));
} }
// Allow providing callbacks that expect either zero or one args, since many
// callers don't care about the argument and can avoid adapter functions this
// way.
void set_callback(base::RepeatingClosure callback) {
// Adapt this closure to a PressedCallback by discarding the extra arg.
callback_ =
base::BindRepeating([](base::RepeatingClosure closure,
const ui::Event& event) { closure.Run(); },
std::move(callback));
}
void set_callback(PressedCallback callback) { void set_callback(PressedCallback callback) {
callback_ = std::move(callback); callback_ = std::move(callback);
} }
......
...@@ -39,8 +39,8 @@ class VIEWS_EXPORT Link : public Label { ...@@ -39,8 +39,8 @@ class VIEWS_EXPORT Link : public Label {
int text_style = style::STYLE_LINK); int text_style = style::STYLE_LINK);
~Link() override; ~Link() override;
// Allow providing callbacks that expect either zero or two args, since many // Allow providing callbacks that expect either zero or one args, since many
// callers don't care about the arguments and can avoid adapter functions this // callers don't care about the argument and can avoid adapter functions this
// way. // way.
void set_callback(base::RepeatingClosure callback) { void set_callback(base::RepeatingClosure callback) {
// Adapt this closure to a ClickedCallback by discarding the extra arg. // Adapt this closure to a ClickedCallback by discarding the extra arg.
......
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