Commit e905386a authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: ash/quick_answers/

Bug: 772945
Change-Id: I44ef7ea9c2e4e7f770860016fc5f1e205e2d1212
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2516882
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823563}
parent 368bcee3
......@@ -132,7 +132,8 @@ View* AddHorizontalUiElements(
QuickAnswersView::QuickAnswersView(const gfx::Rect& anchor_view_bounds,
const std::string& title,
QuickAnswersUiController* controller)
: Button(this),
: Button(base::BindRepeating(&QuickAnswersView::SendQuickAnswersQuery,
base::Unretained(this))),
anchor_view_bounds_(anchor_view_bounds),
controller_(controller),
title_(title),
......@@ -221,22 +222,6 @@ void QuickAnswersView::StateChanged(views::Button::ButtonState old_state) {
SetBackgroundState(hovered);
}
void QuickAnswersView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == dogfood_button_) {
controller_->OnDogfoodButtonPressed();
return;
}
if (sender == retry_label_) {
controller_->OnRetryLabelPressed();
return;
}
if (sender == this) {
SendQuickAnswersQuery();
return;
}
}
void QuickAnswersView::SetButtonNotifyActionToOnPress(views::Button* button) {
DCHECK(button);
button->button_controller()->set_notify_action(
......@@ -283,7 +268,9 @@ void QuickAnswersView::ShowRetryView() {
// Add retry label.
retry_label_ =
description_container->AddChildView(std::make_unique<views::LabelButton>(
/*listener=*/this, base::UTF8ToUTF16(kDefaultRetryStr)));
base::BindRepeating(&QuickAnswersUiController::OnRetryLabelPressed,
base::Unretained(controller_)),
base::UTF8ToUTF16(kDefaultRetryStr)));
retry_label_->SetEnabledTextColors(gfx::kGoogleBlue600);
retry_label_->SetRequestFocusOnPress(true);
SetButtonNotifyActionToOnPress(retry_label_);
......@@ -308,7 +295,9 @@ void QuickAnswersView::AddDogfoodButton() {
views::BoxLayout::Orientation::kVertical,
gfx::Insets(kDogfoodButtonMarginDip)));
layout->set_cross_axis_alignment(views::BoxLayout::CrossAxisAlignment::kEnd);
auto dogfood_button = std::make_unique<views::ImageButton>(/*listener=*/this);
auto dogfood_button = std::make_unique<views::ImageButton>(
base::BindRepeating(&QuickAnswersUiController::OnDogfoodButtonPressed,
base::Unretained(controller_)));
dogfood_button->SetImage(
views::Button::ButtonState::STATE_NORMAL,
gfx::CreateVectorIcon(kDogfoodIcon, kDogfoodButtonSizeDip,
......
......@@ -31,8 +31,7 @@ class QuickAnswersUiController;
class QuickAnswersPreTargetHandler;
// A bubble style view to show QuickAnswer.
class ASH_EXPORT QuickAnswersView : public views::Button,
public views::ButtonListener {
class ASH_EXPORT QuickAnswersView : public views::Button {
public:
QuickAnswersView(const gfx::Rect& anchor_view_bounds,
const std::string& title,
......@@ -52,9 +51,6 @@ class ASH_EXPORT QuickAnswersView : public views::Button,
// views::Button:
void StateChanged(views::Button::ButtonState old_state) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Called when a click happens to trigger Assistant Query.
void SendQuickAnswersQuery();
......
......@@ -89,10 +89,10 @@ std::unique_ptr<views::Label> CreateLabel(const base::string16& text,
// underlying label.
class CustomizedLabelButton : public views::MdTextButton {
public:
CustomizedLabelButton(views::ButtonListener* listener,
CustomizedLabelButton(PressedCallback callback,
const base::string16& text,
const SkColor color)
: MdTextButton(listener, text) {
: MdTextButton(std::move(callback), text) {
SetCustomPadding(kButtonInsets);
SetEnabledTextColors(color);
label()->SetLineHeight(kLineHeightDip);
......@@ -205,25 +205,6 @@ std::vector<views::View*> UserNoticeView::GetFocusableViews() {
return focusable_views;
}
void UserNoticeView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == accept_button_) {
// When user notice is acknowledged, QuickAnswersView will be
// displayed instead of dismissing the menu.
event_handler_->set_dismiss_anchor_menu_on_view_closed(false);
ui_controller_->OnAcceptButtonPressed();
return;
}
if (sender == settings_button_) {
ui_controller_->OnManageSettingsButtonPressed();
return;
}
if (sender == dogfood_button_) {
ui_controller_->OnDogfoodButtonPressed();
return;
}
}
void UserNoticeView::UpdateAnchorViewBounds(
const gfx::Rect& anchor_view_bounds) {
anchor_view_bounds_ = anchor_view_bounds;
......@@ -300,7 +281,9 @@ void UserNoticeView::InitButtonBar() {
// Manage-Settings button.
auto settings_button = std::make_unique<CustomizedLabelButton>(
this,
base::BindRepeating(
&QuickAnswersUiController::OnManageSettingsButtonPressed,
base::Unretained(ui_controller_)),
l10n_util::GetStringUTF16(
IDS_ASH_QUICK_ANSWERS_USER_NOTICE_VIEW_MANAGE_SETTINGS_BUTTON),
kSettingsButtonTextColor);
......@@ -310,7 +293,15 @@ void UserNoticeView::InitButtonBar() {
settings_button_ = button_bar->AddChildView(std::move(settings_button));
auto accept_button = std::make_unique<CustomizedLabelButton>(
this,
base::BindRepeating(
[](QuickAnswersPreTargetHandler* handler,
QuickAnswersUiController* controller) {
// When user notice is acknowledged, QuickAnswersView will be
// displayed instead of dismissing the menu.
handler->set_dismiss_anchor_menu_on_view_closed(false);
controller->OnAcceptButtonPressed();
},
event_handler_.get(), ui_controller_),
l10n_util::GetStringUTF16(
IDS_ASH_QUICK_ANSWERS_USER_NOTICE_VIEW_ACCEPT_BUTTON),
kAcceptButtonTextColor);
......@@ -351,7 +342,9 @@ void UserNoticeView::AddDogfoodButton() {
views::BoxLayout::Orientation::kVertical,
gfx::Insets(kDogfoodButtonMarginDip)));
layout->set_cross_axis_alignment(views::BoxLayout::CrossAxisAlignment::kEnd);
auto dogfood_button = std::make_unique<views::ImageButton>(/*listener=*/this);
auto dogfood_button = std::make_unique<views::ImageButton>(
base::BindRepeating(&QuickAnswersUiController::OnDogfoodButtonPressed,
base::Unretained(ui_controller_)));
dogfood_button->SetImage(
views::Button::ButtonState::STATE_NORMAL,
gfx::CreateVectorIcon(kDogfoodIcon, kDogfoodButtonSizeDip,
......
......@@ -8,7 +8,6 @@
#include <memory>
#include "ash/quick_answers/ui/quick_answers_focus_search.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace views {
......@@ -28,7 +27,7 @@ namespace quick_answers {
// |intent_type| and |intent_text| are used to generate the notice title
// including predicted intent information. Fallback to title without intent
// information if any of these two strings are empty.
class UserNoticeView : public views::View, public views::ButtonListener {
class UserNoticeView : public views::View {
public:
UserNoticeView(const gfx::Rect& anchor_view_bounds,
const base::string16& intent_type,
......@@ -48,9 +47,6 @@ class UserNoticeView : public views::View, public views::ButtonListener {
views::FocusTraversable* GetPaneFocusTraversable() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void UpdateAnchorViewBounds(const gfx::Rect& anchor_view_bounds);
private:
......
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