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