Commit 790598d9 authored by Keren Zhu's avatar Keren Zhu Committed by Commit Bot

Use builder in FindBarView

Also replace ButtonListener with callbacks in this CL.

Bug: 1130078, 772945
Change-Id: Idabf368ddd6e4e48cce78b7b03a88a69028da2d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466568
Commit-Queue: Keren Zhu <kerenzhu@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816709}
parent b62c9cb2
...@@ -127,50 +127,67 @@ END_METADATA ...@@ -127,50 +127,67 @@ END_METADATA
// FindBarView, public: // FindBarView, public:
FindBarView::FindBarView(FindBarHost* host) { FindBarView::FindBarView(FindBarHost* host) {
auto find_text = std::make_unique<views::Textfield>(); auto find_text =
find_text->SetID(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); views::Builder<views::Textfield>()
find_text->SetDefaultWidthInChars(30); .SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND))
find_text->SetMinimumWidthInChars(1); .SetBorder(views::NullBorder())
.SetDefaultWidthInChars(30)
.SetID(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)
.SetMinimumWidthInChars(1)
.SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF)
.Build();
// TODO(kerenzhu): set_controller() should be supported in Builder<TextField>.
find_text->set_controller(this); find_text->set_controller(this);
find_text->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
find_text->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
find_text_ = AddChildView(std::move(find_text)); find_text_ = AddChildView(std::move(find_text));
SetHost(host); SetHost(host);
auto match_count_text = std::make_unique<FindBarMatchCountLabel>(); auto match_count_text = views::Builder<FindBarMatchCountLabel>()
match_count_text->SetCanProcessEventsWithinSubtree(false); .SetCanProcessEventsWithinSubtree(false)
.Build();
match_count_text_ = AddChildView(std::move(match_count_text)); match_count_text_ = AddChildView(std::move(match_count_text));
auto separator = std::make_unique<views::Separator>(); auto separator = views::Builder<views::Separator>()
separator->SetCanProcessEventsWithinSubtree(false); .SetCanProcessEventsWithinSubtree(false)
.Build();
separator_ = AddChildView(std::move(separator)); separator_ = AddChildView(std::move(separator));
auto find_previous_button = std::make_unique<views::ImageButton>(this); auto find_previous_button =
SetCommonButtonAttributes(find_previous_button.get()); views::Builder<views::ImageButton>()
find_previous_button->SetID(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); .SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS))
find_previous_button->SetTooltipText( .SetID(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON)
l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); .SetTooltipText(
find_previous_button->SetAccessibleName( l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP))
l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); .Build();
find_previous_button->set_callback(base::BindRepeating(
&FindBarView::FindNext, base::Unretained(this), true));
find_previous_button_ = AddChildView(std::move(find_previous_button)); find_previous_button_ = AddChildView(std::move(find_previous_button));
SetCommonButtonAttributes(find_previous_button_);
auto find_next_button = std::make_unique<views::ImageButton>(this);
SetCommonButtonAttributes(find_next_button.get()); auto find_next_button =
find_next_button->SetID(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); views::Builder<views::ImageButton>()
find_next_button->SetTooltipText( .SetID(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON)
l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); .SetTooltipText(
find_next_button->SetAccessibleName( l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP))
l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); .SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT))
.Build();
find_next_button->set_callback(base::BindRepeating(
&FindBarView::FindNext, base::Unretained(this), false));
find_next_button_ = AddChildView(std::move(find_next_button)); find_next_button_ = AddChildView(std::move(find_next_button));
SetCommonButtonAttributes(find_next_button_);
auto close_button = std::make_unique<views::ImageButton>(this);
SetCommonButtonAttributes(close_button.get()); auto close_button = views::Builder<views::ImageButton>()
close_button->SetID(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON); .SetID(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON)
close_button->SetTooltipText( .SetTooltipText(l10n_util::GetStringUTF16(
l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); IDS_FIND_IN_PAGE_CLOSE_TOOLTIP))
close_button->SetAnimationDuration(base::TimeDelta()); .SetAnimationDuration(base::TimeDelta())
.Build();
close_button->set_callback(base::BindRepeating(&FindBarView::EndFindSession,
base::Unretained(this)));
close_button_ = AddChildView(std::move(close_button)); close_button_ = AddChildView(std::move(close_button));
SetCommonButtonAttributes(close_button_);
EnableCanvasFlippingForRTLUI(true); EnableCanvasFlippingForRTLUI(true);
...@@ -214,8 +231,6 @@ FindBarView::FindBarView(FindBarHost* host) { ...@@ -214,8 +231,6 @@ FindBarView::FindBarView(FindBarHost* host) {
views::kMarginsKey, views::kMarginsKey,
gfx::Insets(toast_label_vertical_margin + horizontal_margin)); gfx::Insets(toast_label_vertical_margin + horizontal_margin));
find_text_->SetBorder(views::NullBorder());
auto* manager = SetLayoutManager(std::make_unique<views::BoxLayout>( auto* manager = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(provider->GetInsetsMetric(INSETS_TOAST) - horizontal_margin), gfx::Insets(provider->GetInsetsMetric(INSETS_TOAST) - horizontal_margin),
...@@ -343,40 +358,6 @@ void FindBarView::FocusAndSelectAll() { ...@@ -343,40 +358,6 @@ void FindBarView::FocusAndSelectAll() {
find_text_->SelectAll(true); find_text_->SelectAll(true);
} }
////////////////////////////////////////////////////////////////////////////////
// FindBarView, views::ButtonListener implementation:
void FindBarView::ButtonPressed(
views::Button* sender, const ui::Event& event) {
if (!find_bar_host_)
return;
switch (sender->GetID()) {
case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON:
case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON:
if (!find_text_->GetText().empty()) {
find_in_page::FindTabHelper* find_tab_helper =
find_in_page::FindTabHelper::FromWebContents(
find_bar_host_->GetFindBarController()->web_contents());
find_tab_helper->StartFinding(
find_text_->GetText(),
sender->GetID() ==
VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON, /* forward_direction */
false /* case_sensitive */,
true /* find_match */);
}
break;
case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON:
find_bar_host_->GetFindBarController()->EndFindSession(
find_in_page::SelectionAction::kKeep,
find_in_page::ResultAction::kKeep);
break;
default:
NOTREACHED() << "Unknown button";
break;
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FindBarView, views::TextfieldController implementation: // FindBarView, views::TextfieldController implementation:
...@@ -464,6 +445,27 @@ void FindBarView::Find(const base::string16& search_text) { ...@@ -464,6 +445,27 @@ void FindBarView::Find(const base::string16& search_text) {
} }
} }
void FindBarView::FindNext(bool reverse) {
if (!find_bar_host_)
return;
if (!find_text_->GetText().empty()) {
find_in_page::FindTabHelper* find_tab_helper =
find_in_page::FindTabHelper::FromWebContents(
find_bar_host_->GetFindBarController()->web_contents());
find_tab_helper->StartFinding(find_text_->GetText(),
!reverse, /* forward_direction */
false, /* case_sensitive */
true /* find_match */);
}
}
void FindBarView::EndFindSession() {
if (!find_bar_host_)
return;
find_bar_host_->GetFindBarController()->EndFindSession(
find_in_page::SelectionAction::kKeep, find_in_page::ResultAction::kKeep);
}
void FindBarView::UpdateMatchCountAppearance(bool no_match) { void FindBarView::UpdateMatchCountAppearance(bool no_match) {
bool enable_buttons = !find_text_->GetText().empty() && !no_match; bool enable_buttons = !find_text_->GetText().empty() && !no_match;
find_previous_button_->SetEnabled(enable_buttons); find_previous_button_->SetEnabled(enable_buttons);
......
...@@ -43,7 +43,6 @@ class Textfield; ...@@ -43,7 +43,6 @@ class Textfield;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class FindBarView : public views::View, class FindBarView : public views::View,
public DropdownBarHostDelegate, public DropdownBarHostDelegate,
public views::ButtonListener,
public views::TextfieldController { public views::TextfieldController {
public: public:
METADATA_HEADER(FindBarView); METADATA_HEADER(FindBarView);
...@@ -81,9 +80,6 @@ class FindBarView : public views::View, ...@@ -81,9 +80,6 @@ class FindBarView : public views::View,
// DropdownBarHostDelegate: // DropdownBarHostDelegate:
void FocusAndSelectAll() override; void FocusAndSelectAll() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::TextfieldController: // views::TextfieldController:
bool HandleKeyEvent(views::Textfield* sender, bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) override; const ui::KeyEvent& key_event) override;
...@@ -94,6 +90,12 @@ class FindBarView : public views::View, ...@@ -94,6 +90,12 @@ class FindBarView : public views::View,
// Starts finding |search_text|. If the text is empty, stops finding. // Starts finding |search_text|. If the text is empty, stops finding.
void Find(const base::string16& search_text); void Find(const base::string16& search_text);
// Find the next/previous occurrence of search text when clicking the
// next/previous button.
void FindNext(bool reverse = false);
// End the current find session and close the find bubble.
void EndFindSession();
// Updates the appearance for the match count label. // Updates the appearance for the match count label.
void UpdateMatchCountAppearance(bool no_match); void UpdateMatchCountAppearance(bool no_match);
......
...@@ -381,6 +381,7 @@ class VIEWS_EXPORT Button : public InkDropHostView, ...@@ -381,6 +381,7 @@ class VIEWS_EXPORT Button : public InkDropHostView,
}; };
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, Button, InkDropHostView) BEGIN_VIEW_BUILDER(VIEWS_EXPORT, Button, InkDropHostView)
VIEW_BUILDER_PROPERTY(base::string16, AccessibleName)
VIEW_BUILDER_PROPERTY(base::TimeDelta, AnimationDuration) VIEW_BUILDER_PROPERTY(base::TimeDelta, AnimationDuration)
VIEW_BUILDER_PROPERTY(bool, AnimateOnStateChange) VIEW_BUILDER_PROPERTY(bool, AnimateOnStateChange)
VIEW_BUILDER_PROPERTY(bool, HasInkDropActionOnClick) VIEW_BUILDER_PROPERTY(bool, HasInkDropActionOnClick)
......
...@@ -739,20 +739,22 @@ class VIEWS_EXPORT Textfield : public View, ...@@ -739,20 +739,22 @@ class VIEWS_EXPORT Textfield : public View,
}; };
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, Textfield, View) BEGIN_VIEW_BUILDER(VIEWS_EXPORT, Textfield, View)
VIEW_BUILDER_PROPERTY(bool, ReadOnly) VIEW_BUILDER_PROPERTY(base::string16, AccessibleName)
VIEW_BUILDER_PROPERTY(base::string16, Text)
VIEW_BUILDER_PROPERTY(ui::TextInputType, TextInputType)
VIEW_BUILDER_PROPERTY(int, TextInputFlags)
VIEW_BUILDER_PROPERTY(SkColor, TextColor)
VIEW_BUILDER_PROPERTY(SkColor, SelectionTextColor)
VIEW_BUILDER_PROPERTY(SkColor, BackgroundColor) VIEW_BUILDER_PROPERTY(SkColor, BackgroundColor)
VIEW_BUILDER_PROPERTY(SkColor, SelectionBackgroundColor)
VIEW_BUILDER_PROPERTY(bool, CursorEnabled) VIEW_BUILDER_PROPERTY(bool, CursorEnabled)
VIEW_BUILDER_PROPERTY(base::string16, PlaceholderText) VIEW_BUILDER_PROPERTY(int, DefaultWidthInChars)
VIEW_BUILDER_PROPERTY(bool, Invalid)
VIEW_BUILDER_PROPERTY(gfx::HorizontalAlignment, HorizontalAlignment) VIEW_BUILDER_PROPERTY(gfx::HorizontalAlignment, HorizontalAlignment)
VIEW_BUILDER_PROPERTY(bool, Invalid)
VIEW_BUILDER_PROPERTY(int, MinimumWidthInChars)
VIEW_BUILDER_PROPERTY(base::string16, PlaceholderText)
VIEW_BUILDER_PROPERTY(bool, ReadOnly)
VIEW_BUILDER_PROPERTY(gfx::Range, SelectedRange) VIEW_BUILDER_PROPERTY(gfx::Range, SelectedRange)
VIEW_BUILDER_PROPERTY(base::string16, AccessibleName) VIEW_BUILDER_PROPERTY(SkColor, SelectionBackgroundColor)
VIEW_BUILDER_PROPERTY(SkColor, SelectionTextColor)
VIEW_BUILDER_PROPERTY(base::string16, Text)
VIEW_BUILDER_PROPERTY(SkColor, TextColor)
VIEW_BUILDER_PROPERTY(int, TextInputFlags)
VIEW_BUILDER_PROPERTY(ui::TextInputType, TextInputType)
END_VIEW_BUILDER(VIEWS_EXPORT, Textfield) END_VIEW_BUILDER(VIEWS_EXPORT, Textfield)
} // namespace views } // namespace views
......
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