Commit 777ff4b2 authored by Keren Zhu's avatar Keren Zhu Committed by Commit Bot

Add builder support to FindBarView

Bug: 1130078
Change-Id: Ic5253a9024038fe204076c2c5ab744b1e5275f8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462099
Commit-Queue: Keren Zhu <kerenzhu@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815693}
parent 4a9a4963
......@@ -61,8 +61,10 @@ void SetCommonButtonAttributes(views::ImageButton* button) {
class FindBarMatchCountLabel : public views::Label {
public:
FindBarMatchCountLabel() {}
~FindBarMatchCountLabel() override {}
METADATA_HEADER(FindBarMatchCountLabel);
FindBarMatchCountLabel() = default;
~FindBarMatchCountLabel() override = default;
gfx::Size CalculatePreferredSize() const override {
// We need to return at least 1dip so that box layout adds padding on either
......@@ -118,10 +120,13 @@ class FindBarMatchCountLabel : public views::Label {
BEGIN_VIEW_BUILDER(/* No Export */, FindBarMatchCountLabel, views::Label)
END_VIEW_BUILDER(/* No Export */, FindBarMatchCountLabel)
BEGIN_METADATA(FindBarMatchCountLabel, views::Label)
END_METADATA
////////////////////////////////////////////////////////////////////////////////
// FindBarView, public:
FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) {
FindBarView::FindBarView(FindBarHost* host) {
auto find_text = std::make_unique<views::Textfield>();
find_text->SetID(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
find_text->SetDefaultWidthInChars(30);
......@@ -129,10 +134,10 @@ FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) {
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->SetShouldDoLearning(
!host->browser_view()->GetProfile()->IsOffTheRecord());
find_text_ = AddChildView(std::move(find_text));
SetHost(host);
auto match_count_text = std::make_unique<FindBarMatchCountLabel>();
match_count_text->SetCanProcessEventsWithinSubtree(false);
match_count_text_ = AddChildView(std::move(match_count_text));
......@@ -222,6 +227,12 @@ FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) {
FindBarView::~FindBarView() {
}
void FindBarView::SetHost(FindBarHost* host) {
find_bar_host_ = host;
find_text_->SetShouldDoLearning(
host && !host->browser_view()->GetProfile()->IsOffTheRecord());
}
void FindBarView::SetFindTextAndSelectedRange(
const base::string16& find_text,
const gfx::Range& selected_range) {
......@@ -260,7 +271,8 @@ void FindBarView::UpdateForResult(
// find text contents after clearing the find results as the normal
// prepopulation code does not run.
if (find_text_->GetText() != find_text && !find_text_->IsIMEComposing() &&
(!find_bar_host_->HasGlobalFindPasteboard() || !find_text.empty())) {
(!find_bar_host_ || !find_bar_host_->HasGlobalFindPasteboard() ||
!find_text.empty())) {
find_text_->SetText(find_text);
find_text_->SelectAll(true);
}
......@@ -336,6 +348,9 @@ void FindBarView::FocusAndSelectAll() {
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:
......@@ -368,7 +383,7 @@ void FindBarView::ButtonPressed(
bool FindBarView::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) {
// If the dialog is not visible, there is no reason to process keyboard input.
if (!find_bar_host_->IsVisible())
if (!find_bar_host_ || !find_bar_host_->IsVisible())
return false;
if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event))
......@@ -410,6 +425,7 @@ void FindBarView::OnAfterPaste() {
}
void FindBarView::Find(const base::string16& search_text) {
DCHECK(find_bar_host_);
FindBarController* controller = find_bar_host_->GetFindBarController();
DCHECK(controller);
content::WebContents* web_contents = controller->web_contents();
......@@ -454,10 +470,6 @@ void FindBarView::UpdateMatchCountAppearance(bool no_match) {
find_next_button_->SetEnabled(enable_buttons);
}
const char* FindBarView::GetClassName() const {
return "FindBarView";
}
void FindBarView::OnThemeChanged() {
views::View::OnThemeChanged();
ui::NativeTheme* theme = GetNativeTheme();
......@@ -494,3 +506,6 @@ void FindBarView::OnThemeChanged() {
views::SetImageFromVectorIcon(close_button_, vector_icons::kCloseRoundedIcon,
base_foreground_color);
}
BEGIN_METADATA(FindBarView, views::View)
END_METADATA
......@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/views/chrome_views_export.h"
#include "chrome/browser/ui/views/dropdown_bar_host_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h"
......@@ -45,9 +46,13 @@ class FindBarView : public views::View,
public views::ButtonListener,
public views::TextfieldController {
public:
explicit FindBarView(FindBarHost* host);
METADATA_HEADER(FindBarView);
explicit FindBarView(FindBarHost* host = nullptr);
~FindBarView() override;
void SetHost(FindBarHost* host);
// Accessors for the text and selection displayed in the text box.
void SetFindTextAndSelectedRange(const base::string16& find_text,
const gfx::Range& selected_range);
......@@ -69,7 +74,6 @@ class FindBarView : public views::View,
void ClearMatchCount();
// views::View:
const char* GetClassName() const override;
bool OnMousePressed(const ui::MouseEvent& event) override;
gfx::Size CalculatePreferredSize() const override;
void OnThemeChanged() override;
......@@ -116,4 +120,8 @@ class FindBarView : public views::View,
DISALLOW_COPY_AND_ASSIGN(FindBarView);
};
BEGIN_VIEW_BUILDER(/* no export */, FindBarView, views::View)
VIEW_BUILDER_PROPERTY(FindBarHost*, Host)
END_VIEW_BUILDER(/* no export */, FindBarView)
#endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_
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