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

Change ButtonPressed overrides to callbacks: c/b/chromeos/

Bug: 772945
Change-Id: Ia203016d23ba52d8cb1cc33164a9a56988aaba23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2492546
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820373}
parent ff15aaac
......@@ -34,20 +34,6 @@
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
namespace {
std::unique_ptr<views::ImageButton> CreateLearnMoreButton(
views::ButtonListener* listener) {
auto learn_more_button = views::CreateVectorImageButtonWithNativeTheme(
listener, vector_icons::kHelpOutlineIcon);
learn_more_button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_CHROMEOS_ACC_LEARN_MORE));
learn_more_button->SetFocusForPlatform();
return learn_more_button;
}
} // namespace
namespace chromeos {
namespace attestation {
......@@ -97,8 +83,14 @@ PlatformVerificationDialog::PlatformVerificationDialog(
ui::DIALOG_BUTTON_OK, l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW));
DialogDelegate::SetButtonLabel(
ui::DIALOG_BUTTON_CANCEL, l10n_util::GetStringUTF16(IDS_PERMISSION_DENY));
learn_more_button_ =
DialogDelegate::SetExtraView(CreateLearnMoreButton(this));
auto* learn_more_button = DialogDelegate::SetExtraView(
views::CreateVectorImageButtonWithNativeTheme(
base::BindRepeating(&PlatformVerificationDialog::ButtonPressed,
base::Unretained(this)),
vector_icons::kHelpOutlineIcon));
learn_more_button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_CHROMEOS_ACC_LEARN_MORE));
learn_more_button->SetFocusForPlatform();
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(
views::LayoutProvider::Get()->GetDialogInsetsForContentType(
......@@ -129,11 +121,18 @@ PlatformVerificationDialog::PlatformVerificationDialog(
chrome::RecordDialogCreation(chrome::DialogIdentifier::PLATFORM_VERIFICATION);
}
void PlatformVerificationDialog::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender != learn_more_button_)
void PlatformVerificationDialog::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
if (!navigation_handle->IsInMainFrame() ||
navigation_handle->IsSameDocument())
return;
views::Widget* widget = GetWidget();
if (widget)
widget->Close();
}
void PlatformVerificationDialog::ButtonPressed() {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
const GURL learn_more_url(chrome::kEnhancedPlaybackNotificationLearnMoreURL);
......@@ -150,16 +149,5 @@ void PlatformVerificationDialog::ButtonPressed(views::Button* sender,
}
}
void PlatformVerificationDialog::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
if (!navigation_handle->IsInMainFrame() ||
navigation_handle->IsSameDocument())
return;
views::Widget* widget = GetWidget();
if (widget)
widget->Close();
}
} // namespace attestation
} // namespace chromeos
......@@ -22,7 +22,6 @@ namespace attestation {
// A tab-modal dialog UI to ask the user for PlatformVerificationFlow.
class PlatformVerificationDialog : public views::DialogDelegateView,
public views::ButtonListener,
public content::WebContentsObserver {
public:
enum ConsentResponse {
......@@ -50,16 +49,14 @@ class PlatformVerificationDialog : public views::DialogDelegateView,
const base::string16& domain,
ConsentCallback callback);
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// content::WebContentsObserver:
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void ButtonPressed();
base::string16 domain_;
ConsentCallback callback_;
views::ImageButton* learn_more_button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(PlatformVerificationDialog);
};
......
......@@ -128,9 +128,9 @@ std::unique_ptr<views::Label> CreateAnnotationLabel(
} // namespace
CandidateView::CandidateView(views::ButtonListener* listener,
CandidateView::CandidateView(PressedCallback callback,
ui::CandidateWindow::Orientation orientation)
: views::Button(listener), orientation_(orientation) {
: views::Button(std::move(callback)), orientation_(orientation) {
SetBorder(views::CreateEmptyBorder(1, 1, 1, 1));
const ui::NativeTheme& theme = *GetNativeTheme();
......
......@@ -19,7 +19,7 @@ namespace ime {
// CandidateView renderes a row of a candidate.
class UI_CHROMEOS_EXPORT CandidateView : public views::Button {
public:
CandidateView(views::ButtonListener* listener,
CandidateView(PressedCallback callback,
ui::CandidateWindow::Orientation orientation);
~CandidateView() override {}
......
......@@ -30,11 +30,10 @@ const char* const kDummyCandidates[] = {
} // namespace
class CandidateViewTest : public views::ViewsTestBase,
public views::ButtonListener {
class CandidateViewTest : public views::ViewsTestBase {
public:
CandidateViewTest() : widget_(nullptr), last_pressed_(nullptr) {}
~CandidateViewTest() override {}
CandidateViewTest() = default;
~CandidateViewTest() override = default;
void SetUp() override {
views::ViewsTestBase::SetUp();
......@@ -48,8 +47,8 @@ class CandidateViewTest : public views::ViewsTestBase,
container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
for (size_t i = 0; i < base::size(kDummyCandidates); ++i) {
CandidateView* candidate =
new CandidateView(this, ui::CandidateWindow::VERTICAL);
CandidateView* candidate = new CandidateView(
views::Button::PressedCallback(), ui::CandidateWindow::VERTICAL);
ui::CandidateWindow::Entry entry;
entry.value = base::UTF8ToUTF16(kDummyCandidates[i]);
candidate->SetEntry(entry);
......@@ -91,30 +90,12 @@ class CandidateViewTest : public views::ViewsTestBase,
return (it == children.cend()) ? -1 : std::distance(children.cbegin(), it);
}
int GetLastPressedIndexAndReset() {
const auto& children = container_->children();
const auto it =
std::find(children.cbegin(), children.cend(), last_pressed_);
if (it != children.cend()) {
last_pressed_ = nullptr;
return std::distance(children.cbegin(), it);
}
DCHECK(!last_pressed_);
return -1;
}
ui::test::EventGenerator* event_generator() { return event_generator_.get(); }
private:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
last_pressed_ = sender;
}
views::Widget* widget_;
views::View* container_;
views::Widget* widget_ = nullptr;
views::View* container_ = nullptr;
std::unique_ptr<ui::test::EventGenerator> event_generator_;
views::View* last_pressed_;
DISALLOW_COPY_AND_ASSIGN(CandidateViewTest);
};
......@@ -145,10 +126,13 @@ TEST_F(CandidateViewTest, MouseHovers) {
}
TEST_F(CandidateViewTest, MouseClick) {
event_generator()->MoveMouseTo(
GetCandidateAt(1)->GetBoundsInScreen().CenterPoint());
bool clicked = false;
CandidateView* view = GetCandidateAt(1);
view->SetCallback(
base::BindRepeating([](bool* clicked) { *clicked = true; }, &clicked));
event_generator()->MoveMouseTo(view->GetBoundsInScreen().CenterPoint());
event_generator()->ClickLeftButton();
EXPECT_EQ(1, GetLastPressedIndexAndReset());
EXPECT_TRUE(clicked);
}
TEST_F(CandidateViewTest, ClickAndMove) {
......@@ -157,6 +141,10 @@ TEST_F(CandidateViewTest, ClickAndMove) {
EXPECT_EQ(1u, GetHighlightedCount());
EXPECT_EQ(0, GetHighlightedIndex());
bool clicked = false;
CandidateView* view = GetCandidateAt(1);
view->SetCallback(
base::BindRepeating([](bool* clicked) { *clicked = true; }, &clicked));
event_generator()->MoveMouseTo(
GetCandidateAt(2)->GetBoundsInScreen().CenterPoint());
event_generator()->PressLeftButton();
......@@ -164,8 +152,7 @@ TEST_F(CandidateViewTest, ClickAndMove) {
EXPECT_EQ(2, GetHighlightedIndex());
// Highlight follows the drag.
event_generator()->MoveMouseTo(
GetCandidateAt(1)->GetBoundsInScreen().CenterPoint());
event_generator()->MoveMouseTo(view->GetBoundsInScreen().CenterPoint());
EXPECT_EQ(1u, GetHighlightedCount());
EXPECT_EQ(1, GetHighlightedIndex());
......@@ -174,13 +161,13 @@ TEST_F(CandidateViewTest, ClickAndMove) {
EXPECT_EQ(1u, GetHighlightedCount());
EXPECT_EQ(0, GetHighlightedIndex());
event_generator()->MoveMouseTo(
GetCandidateAt(1)->GetBoundsInScreen().CenterPoint());
event_generator()->MoveMouseTo(view->GetBoundsInScreen().CenterPoint());
EXPECT_EQ(1u, GetHighlightedCount());
EXPECT_EQ(1, GetHighlightedIndex());
EXPECT_FALSE(clicked);
event_generator()->ReleaseLeftButton();
EXPECT_EQ(1, GetLastPressedIndexAndReset());
EXPECT_TRUE(clicked);
}
} // namespace ime
......
......@@ -282,7 +282,7 @@ void CandidateWindowView::UpdateCandidates(
for (size_t i = 0; i < candidate_views_.size(); ++i) {
const size_t index_in_page = i;
const size_t candidate_index = start_from + index_in_page;
CandidateView* candidate_view = candidate_views_[index_in_page].get();
CandidateView* candidate_view = candidate_views_[index_in_page];
// Set the candidate text.
if (candidate_index < new_candidate_window.candidates().size()) {
const ui::CandidateWindow::Entry& entry =
......@@ -306,7 +306,7 @@ void CandidateWindowView::UpdateCandidates(
}
}
if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) {
for (const auto& view : candidate_views_)
for (auto* view : candidate_views_)
view->SetWidths(max_shortcut_width, max_candidate_width);
}
......@@ -362,17 +362,22 @@ void CandidateWindowView::MaybeInitializeCandidateViews(
const size_t page_size = candidate_window.page_size();
// Reset all candidate_views_ when orientation changes.
if (orientation != candidate_window_.orientation())
if (orientation != candidate_window_.orientation()) {
candidate_area_->RemoveAllChildViews(true);
candidate_views_.clear();
}
while (page_size < candidate_views_.size())
while (page_size < candidate_views_.size()) {
candidate_area_->RemoveChildViewT(candidate_views_.back());
candidate_views_.pop_back();
}
while (page_size > candidate_views_.size()) {
std::unique_ptr<CandidateView> new_candidate =
std::make_unique<CandidateView>(this, orientation);
candidate_area_->AddChildView(new_candidate.get());
candidate_views_.push_back(std::move(new_candidate));
for (size_t i = candidate_views_.size(); i < page_size; ++i) {
candidate_views_.push_back(
candidate_area_->AddChildView(std::make_unique<CandidateView>(
base::BindRepeating(&CandidateWindowView::CandidateViewPressed,
base::Unretained(this), int{i}),
orientation)));
}
}
......@@ -417,15 +422,9 @@ const char* CandidateWindowView::GetClassName() const {
return "CandidateWindowView";
}
void CandidateWindowView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
for (size_t i = 0; i < candidate_views_.size(); ++i) {
if (sender == candidate_views_[i].get()) {
for (Observer& observer : observers_)
observer.OnCandidateCommitted(i);
return;
}
}
void CandidateWindowView::CandidateViewPressed(int index) {
for (Observer& observer : observers_)
observer.OnCandidateCommitted(index);
}
} // namespace ime
......
......@@ -11,7 +11,6 @@
#include "ui/base/ime/candidate_window.h"
#include "ui/chromeos/ui_chromeos_export.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
namespace ui {
namespace ime {
......@@ -21,8 +20,7 @@ class InformationTextArea;
// CandidateWindowView is the main container of the candidate window UI.
class UI_CHROMEOS_EXPORT CandidateWindowView
: public views::BubbleDialogDelegateView,
public views::ButtonListener {
: public views::BubbleDialogDelegateView {
public:
// The object can be monitored by the observer.
class Observer {
......@@ -78,9 +76,6 @@ class UI_CHROMEOS_EXPORT CandidateWindowView
// views::BubbleDialogDelegateView:
const char* GetClassName() const override;
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void SelectCandidateAt(int index_in_page);
void UpdateVisibility();
......@@ -88,6 +83,8 @@ class UI_CHROMEOS_EXPORT CandidateWindowView
void MaybeInitializeCandidateViews(
const ui::CandidateWindow& candidate_window);
void CandidateViewPressed(int index);
// The candidate window data model.
ui::CandidateWindow candidate_window_;
......@@ -104,7 +101,7 @@ class UI_CHROMEOS_EXPORT CandidateWindowView
views::View* candidate_area_;
// The candidate views are used for rendering candidates.
std::vector<std::unique_ptr<CandidateView>> candidate_views_;
std::vector<CandidateView*> candidate_views_;
// Current columns size in |candidate_area_|.
gfx::Size previous_shortcut_column_size_;
......
......@@ -87,7 +87,7 @@ class CandidateWindowViewTest : public views::ViewsTestBase {
}
CandidateView* GetCandidateAt(size_t i) {
return candidate_window_view_->candidate_views_[i].get();
return candidate_window_view_->candidate_views_[i];
}
void SelectCandidateAt(int index_in_page) {
......
......@@ -95,8 +95,8 @@ std::unique_ptr<views::View> CreateKeyContainer() {
} // namespace
SuggestionView::SuggestionView(views::ButtonListener* listener)
: views::Button(listener) {
SuggestionView::SuggestionView(PressedCallback callback)
: views::Button(std::move(callback)) {
index_label_ = AddChildView(CreateIndexLabel());
index_label_->SetVisible(false);
suggestion_label_ = AddChildView(CreateSuggestionLabel());
......
......@@ -42,7 +42,7 @@ constexpr SkColor kButtonHighlightColor =
// SuggestionView renders a suggestion.
class UI_CHROMEOS_EXPORT SuggestionView : public views::Button {
public:
explicit SuggestionView(views::ButtonListener* listener);
explicit SuggestionView(PressedCallback callback);
~SuggestionView() override;
void SetView(const SuggestionDetails& details);
......
......@@ -84,22 +84,6 @@ SuggestionWindowView::CreateNonClientFrameView(views::Widget* widget) {
return frame;
}
// TODO(crbug/1099116): Add test for ButtonPressed.
void SuggestionWindowView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(sender);
AssistiveWindowButton button;
if (sender->parent() == candidate_area_) {
button.id = ui::ime::ButtonId::kSuggestion;
button.index = candidate_area_->GetIndexOf(sender);
} else {
DCHECK_EQ(learn_more_button_, sender);
button.id = ui::ime::ButtonId::kLearnMore;
button.window_type = ui::ime::AssistiveWindowType::kEmojiSuggestion;
}
delegate_->AssistiveWindowButtonClicked(button);
}
void SuggestionWindowView::Show(const SuggestionDetails& details) {
ResizeCandidateArea(1);
auto* const candidate =
......@@ -201,7 +185,13 @@ SuggestionWindowView::SuggestionWindowView(gfx::NativeView parent,
base::BindRepeating(on_setting_link_clicked, delegate_));
setting_link_->SetVisible(false);
learn_more_button_ = AddChildView(std::make_unique<views::ImageButton>(this));
learn_more_button_ =
AddChildView(std::make_unique<views::ImageButton>(base::BindRepeating(
&AssistiveDelegate::AssistiveWindowButtonClicked,
base::Unretained(delegate_),
AssistiveWindowButton{
.id = ui::ime::ButtonId::kLearnMore,
.window_type = ui::ime::AssistiveWindowType::kEmojiSuggestion})));
learn_more_button_->SetImageHorizontalAlignment(
views::ImageButton::ALIGN_CENTER);
learn_more_button_->SetImageVerticalAlignment(
......@@ -230,9 +220,13 @@ void SuggestionWindowView::ResizeCandidateArea(size_t size) {
candidate_area_->RemoveChildViewT(candidates.back()).get());
}
while (candidates.size() < size) {
auto* const candidate =
candidate_area_->AddChildView(std::make_unique<SuggestionView>(this));
for (size_t index = candidates.size(); index < size; ++index) {
auto* const candidate = candidate_area_->AddChildView(
std::make_unique<SuggestionView>(base::BindRepeating(
&AssistiveDelegate::AssistiveWindowButtonClicked,
base::Unretained(delegate_),
AssistiveWindowButton{.id = ui::ime::ButtonId::kSuggestion,
.index = index})));
auto subscription = candidate->AddStateChangedCallback(base::BindRepeating(
[](SuggestionWindowView* window, SuggestionView* button) {
window->SetCandidateHighlighted(button, ShouldHighlight(*button));
......
......@@ -13,7 +13,6 @@
#include "ui/chromeos/ui_chromeos_export.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
......@@ -36,8 +35,7 @@ class SuggestionView;
// SuggestionWindowView is the main container of the suggestion window UI.
class UI_CHROMEOS_EXPORT SuggestionWindowView
: public views::BubbleDialogDelegateView,
public views::ButtonListener {
: public views::BubbleDialogDelegateView {
public:
METADATA_HEADER(SuggestionWindowView);
......@@ -50,9 +48,6 @@ class UI_CHROMEOS_EXPORT SuggestionWindowView
std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView(
views::Widget* widget) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void Show(const SuggestionDetails& details);
void ShowMultipleCandidates(
......@@ -90,7 +85,7 @@ class UI_CHROMEOS_EXPORT SuggestionWindowView
void SetCandidateHighlighted(SuggestionView* candidate, bool highlighted);
// The delegate to handle events from this class.
AssistiveDelegate* delegate_;
AssistiveDelegate* const delegate_;
// The view containing all the suggestions.
views::View* candidate_area_;
......
......@@ -35,12 +35,11 @@ UndoWindow::UndoWindow(gfx::NativeView parent, AssistiveDelegate* delegate)
SetArrow(views::BubbleBorder::Arrow::BOTTOM_LEFT);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
AddUndoButton();
}
void UndoWindow::AddUndoButton() {
undo_button_ = AddChildView(std::make_unique<views::LabelButton>(
this, base::UTF8ToUTF16(kUndoButtonText)));
base::BindRepeating(&UndoWindow::UndoButtonPressed,
base::Unretained(this)),
base::UTF8ToUTF16(kUndoButtonText)));
undo_button_->SetImageLabelSpacing(
views::LayoutProvider::Get()->GetDistanceMetric(
views::DistanceMetric::DISTANCE_RELATED_BUTTON_HORIZONTAL));
......@@ -96,17 +95,6 @@ void UndoWindow::SetButtonHighlighted(const AssistiveWindowButton& button,
: nullptr);
}
void UndoWindow::ButtonPressed(views::Button* sender, const ui::Event& event) {
button_pressed_ = sender;
if (sender == undo_button_) {
AssistiveWindowButton button;
button.id = ButtonId::kUndo;
button.window_type = AssistiveWindowType::kUndoWindow;
SetButtonHighlighted(button, true);
delegate_->AssistiveWindowButtonClicked(button);
}
}
views::Button* UndoWindow::GetUndoButtonForTesting() {
return undo_button_;
}
......@@ -115,5 +103,12 @@ const char* UndoWindow::GetClassName() const {
return "UndoWindow";
}
void UndoWindow::UndoButtonPressed() {
const AssistiveWindowButton button = {
.id = ButtonId::kUndo, .window_type = AssistiveWindowType::kUndoWindow};
SetButtonHighlighted(button, true);
delegate_->AssistiveWindowButtonClicked(button);
}
} // namespace ime
} // namespace ui
......@@ -14,8 +14,7 @@ namespace ui {
namespace ime {
// Pop up UI for users to undo an autocorrected word.
class UI_CHROMEOS_EXPORT UndoWindow : public views::BubbleDialogDelegateView,
public views::ButtonListener {
class UI_CHROMEOS_EXPORT UndoWindow : public views::BubbleDialogDelegateView {
public:
explicit UndoWindow(gfx::NativeView parent, AssistiveDelegate* delegate);
~UndoWindow() override;
......@@ -39,14 +38,10 @@ class UI_CHROMEOS_EXPORT UndoWindow : public views::BubbleDialogDelegateView,
// views::BubbleDialogDelegateView:
const char* GetClassName() const override;
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void AddUndoButton();
void UndoButtonPressed();
AssistiveDelegate* delegate_;
views::LabelButton* undo_button_;
views::Button* button_pressed_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(UndoWindow);
};
......
......@@ -38,11 +38,6 @@ using views::Button;
namespace chromeos {
class DummyButtonListener : public views::ButtonListener {
public:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
};
class NetworkScreenTest : public InProcessBrowserTest {
public:
NetworkScreenTest() = default;
......
......@@ -167,20 +167,22 @@ void SimpleWebViewDialog::Init() {
SetBackground(views::CreateSolidBackground(kDialogColor));
// Back/Forward buttons.
auto back = std::make_unique<views::ImageButton>(this);
auto back = std::make_unique<views::ImageButton>(base::BindRepeating(
[](CommandUpdater* updater) { updater->ExecuteCommand(IDC_BACK); },
command_updater_.get()));
back->SetTriggerableEventFlags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
back->set_tag(IDC_BACK);
back->SetImageHorizontalAlignment(views::ImageButton::ALIGN_RIGHT);
back->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK));
back->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
back->SetID(VIEW_ID_BACK_BUTTON);
back_ = back.get();
auto forward = std::make_unique<views::ImageButton>(this);
auto forward = std::make_unique<views::ImageButton>(base::BindRepeating(
[](CommandUpdater* updater) { updater->ExecuteCommand(IDC_FORWARD); },
command_updater_.get()));
forward->SetTriggerableEventFlags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
forward->set_tag(IDC_FORWARD);
forward->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD));
forward->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD));
forward->SetID(VIEW_ID_FORWARD_BUTTON);
......@@ -195,7 +197,6 @@ void SimpleWebViewDialog::Init() {
auto reload = std::make_unique<ReloadButton>(command_updater_.get());
reload->SetTriggerableEventFlags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
reload->set_tag(IDC_RELOAD);
reload->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD));
reload->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD));
reload->SetID(VIEW_ID_RELOAD_BUTTON);
......@@ -247,11 +248,6 @@ void SimpleWebViewDialog::Init() {
Layout();
}
void SimpleWebViewDialog::ButtonPressed(views::Button* sender,
const ui::Event& event) {
command_updater_->ExecuteCommand(sender->tag());
}
content::WebContents* SimpleWebViewDialog::OpenURL(
const content::OpenURLParams& params) {
// As there are no Browsers right now, this could not actually ever work.
......
......@@ -37,8 +37,7 @@ class StubBubbleModelDelegate;
// bar. Location bar is shown in read only mode, because this view is designed
// to be used for sign in to captive portal on login screen (when Browser
// isn't running).
class SimpleWebViewDialog : public views::ButtonListener,
public views::View,
class SimpleWebViewDialog : public views::View,
public LocationBarView::Delegate,
public ChromeLocationBarModelDelegate,
public CommandUpdaterDelegate,
......@@ -54,9 +53,6 @@ class SimpleWebViewDialog : public views::ButtonListener,
// Inits view. Should be attached to a Widget before call.
void Init();
// Implements views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Implements content::PageNavigator:
content::WebContents* OpenURL(const content::OpenURLParams& params) override;
......
......@@ -20,28 +20,18 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
namespace {
namespace chromeos {
std::unique_ptr<views::ImageButton> CreateLearnMoreButton(
views::ButtonListener* listener) {
auto learn_more_button = views::CreateVectorImageButtonWithNativeTheme(
listener, vector_icons::kHelpOutlineIcon);
EchoDialogView::EchoDialogView(EchoDialogListener* listener,
const EchoDialogView::Params& params) {
auto* learn_more_button = DialogDelegate::SetExtraView(
views::CreateVectorImageButtonWithNativeTheme(
base::BindRepeating(&EchoDialogListener::OnMoreInfoLinkClicked,
base::Unretained(listener)),
vector_icons::kHelpOutlineIcon));
learn_more_button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_CHROMEOS_ACC_LEARN_MORE));
learn_more_button->SetFocusForPlatform();
return learn_more_button;
}
} // namespace
namespace chromeos {
EchoDialogView::EchoDialogView(EchoDialogListener* listener,
const EchoDialogView::Params& params)
: listener_(listener) {
DCHECK(listener_);
learn_more_button_ =
DialogDelegate::SetExtraView(CreateLearnMoreButton(this));
chrome::RecordDialogCreation(chrome::DialogIdentifier::ECHO);
if (params.echo_enabled) {
......@@ -63,9 +53,9 @@ EchoDialogView::EchoDialogView(EchoDialogListener* listener,
}
DialogDelegate::SetAcceptCallback(base::BindOnce(
&EchoDialogListener::OnAccept, base::Unretained(listener_)));
&EchoDialogListener::OnAccept, base::Unretained(listener)));
DialogDelegate::SetCancelCallback(base::BindOnce(
&EchoDialogListener::OnCancel, base::Unretained(listener_)));
&EchoDialogListener::OnCancel, base::Unretained(listener)));
DialogDelegate::SetShowTitle(false);
DialogDelegate::SetShowCloseButton(false);
......@@ -116,12 +106,6 @@ void EchoDialogView::InitForDisabledEcho() {
SetBorderAndLabel(std::move(label), font_list);
}
void EchoDialogView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(sender == learn_more_button_);
listener_->OnMoreInfoLinkClicked();
}
void EchoDialogView::SetBorderAndLabel(std::unique_ptr<views::View> label,
const gfx::FontList& label_font_list) {
SetLayoutManager(std::make_unique<views::FillLayout>());
......
......@@ -11,7 +11,6 @@
#include "ui/views/window/dialog_delegate.h"
namespace views {
class ImageButton;
class View;
} // namespace views
......@@ -28,8 +27,7 @@ class EchoDialogListener;
// being redeemed. The dialog is shown to get an user consent. If the echo
// extension is not allowed by policy to redeem offers, the dialog informs user
// about this.
class EchoDialogView : public views::DialogDelegateView,
public views::ButtonListener {
class EchoDialogView : public views::DialogDelegateView {
public:
struct Params {
bool echo_enabled = false;
......@@ -52,7 +50,8 @@ class EchoDialogView : public views::DialogDelegateView,
// url. Service name should be underlined in the dialog, and hovering over its
// label should display tooltip containing |origin|.
// The dialog will have both OK and Cancel buttons.
void InitForEnabledEcho(const base::string16& service_name, const base::string16& origin);
void InitForEnabledEcho(const base::string16& service_name,
const base::string16& origin);
// Initializes dialog layout that will be shown when echo extension is not
// allowed to redeem offers. The dialog will be showing a message that the
......@@ -60,16 +59,10 @@ class EchoDialogView : public views::DialogDelegateView,
// The dialog will have only Cancel button.
void InitForDisabledEcho();
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Sets the border and label view.
void SetBorderAndLabel(std::unique_ptr<views::View> label,
const gfx::FontList& label_font_list);
EchoDialogListener* listener_ = nullptr;
views::ImageButton* learn_more_button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(EchoDialogView);
};
......
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