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) { ...@@ -61,8 +61,10 @@ void SetCommonButtonAttributes(views::ImageButton* button) {
class FindBarMatchCountLabel : public views::Label { class FindBarMatchCountLabel : public views::Label {
public: public:
FindBarMatchCountLabel() {} METADATA_HEADER(FindBarMatchCountLabel);
~FindBarMatchCountLabel() override {}
FindBarMatchCountLabel() = default;
~FindBarMatchCountLabel() override = default;
gfx::Size CalculatePreferredSize() const override { gfx::Size CalculatePreferredSize() const override {
// We need to return at least 1dip so that box layout adds padding on either // We need to return at least 1dip so that box layout adds padding on either
...@@ -118,10 +120,13 @@ class FindBarMatchCountLabel : public views::Label { ...@@ -118,10 +120,13 @@ class FindBarMatchCountLabel : public views::Label {
BEGIN_VIEW_BUILDER(/* No Export */, FindBarMatchCountLabel, views::Label) BEGIN_VIEW_BUILDER(/* No Export */, FindBarMatchCountLabel, views::Label)
END_VIEW_BUILDER(/* No Export */, FindBarMatchCountLabel) END_VIEW_BUILDER(/* No Export */, FindBarMatchCountLabel)
BEGIN_METADATA(FindBarMatchCountLabel, views::Label)
END_METADATA
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FindBarView, public: // FindBarView, public:
FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) { FindBarView::FindBarView(FindBarHost* host) {
auto find_text = std::make_unique<views::Textfield>(); auto find_text = std::make_unique<views::Textfield>();
find_text->SetID(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); find_text->SetID(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
find_text->SetDefaultWidthInChars(30); find_text->SetDefaultWidthInChars(30);
...@@ -129,10 +134,10 @@ FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) { ...@@ -129,10 +134,10 @@ FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) {
find_text->set_controller(this); find_text->set_controller(this);
find_text->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); find_text->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
find_text->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); find_text->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
find_text->SetShouldDoLearning(
!host->browser_view()->GetProfile()->IsOffTheRecord());
find_text_ = AddChildView(std::move(find_text)); find_text_ = AddChildView(std::move(find_text));
SetHost(host);
auto match_count_text = std::make_unique<FindBarMatchCountLabel>(); auto match_count_text = std::make_unique<FindBarMatchCountLabel>();
match_count_text->SetCanProcessEventsWithinSubtree(false); match_count_text->SetCanProcessEventsWithinSubtree(false);
match_count_text_ = AddChildView(std::move(match_count_text)); match_count_text_ = AddChildView(std::move(match_count_text));
...@@ -222,6 +227,12 @@ FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) { ...@@ -222,6 +227,12 @@ FindBarView::FindBarView(FindBarHost* host) : find_bar_host_(host) {
FindBarView::~FindBarView() { FindBarView::~FindBarView() {
} }
void FindBarView::SetHost(FindBarHost* host) {
find_bar_host_ = host;
find_text_->SetShouldDoLearning(
host && !host->browser_view()->GetProfile()->IsOffTheRecord());
}
void FindBarView::SetFindTextAndSelectedRange( void FindBarView::SetFindTextAndSelectedRange(
const base::string16& find_text, const base::string16& find_text,
const gfx::Range& selected_range) { const gfx::Range& selected_range) {
...@@ -260,7 +271,8 @@ void FindBarView::UpdateForResult( ...@@ -260,7 +271,8 @@ void FindBarView::UpdateForResult(
// find text contents after clearing the find results as the normal // find text contents after clearing the find results as the normal
// prepopulation code does not run. // prepopulation code does not run.
if (find_text_->GetText() != find_text && !find_text_->IsIMEComposing() && 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_->SetText(find_text);
find_text_->SelectAll(true); find_text_->SelectAll(true);
} }
...@@ -336,6 +348,9 @@ void FindBarView::FocusAndSelectAll() { ...@@ -336,6 +348,9 @@ void FindBarView::FocusAndSelectAll() {
void FindBarView::ButtonPressed( void FindBarView::ButtonPressed(
views::Button* sender, const ui::Event& event) { views::Button* sender, const ui::Event& event) {
if (!find_bar_host_)
return;
switch (sender->GetID()) { switch (sender->GetID()) {
case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON: case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON:
case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON: case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON:
...@@ -368,7 +383,7 @@ void FindBarView::ButtonPressed( ...@@ -368,7 +383,7 @@ void FindBarView::ButtonPressed(
bool FindBarView::HandleKeyEvent(views::Textfield* sender, bool FindBarView::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) { const ui::KeyEvent& key_event) {
// If the dialog is not visible, there is no reason to process keyboard input. // 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; return false;
if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event))
...@@ -410,6 +425,7 @@ void FindBarView::OnAfterPaste() { ...@@ -410,6 +425,7 @@ void FindBarView::OnAfterPaste() {
} }
void FindBarView::Find(const base::string16& search_text) { void FindBarView::Find(const base::string16& search_text) {
DCHECK(find_bar_host_);
FindBarController* controller = find_bar_host_->GetFindBarController(); FindBarController* controller = find_bar_host_->GetFindBarController();
DCHECK(controller); DCHECK(controller);
content::WebContents* web_contents = controller->web_contents(); content::WebContents* web_contents = controller->web_contents();
...@@ -454,10 +470,6 @@ void FindBarView::UpdateMatchCountAppearance(bool no_match) { ...@@ -454,10 +470,6 @@ void FindBarView::UpdateMatchCountAppearance(bool no_match) {
find_next_button_->SetEnabled(enable_buttons); find_next_button_->SetEnabled(enable_buttons);
} }
const char* FindBarView::GetClassName() const {
return "FindBarView";
}
void FindBarView::OnThemeChanged() { void FindBarView::OnThemeChanged() {
views::View::OnThemeChanged(); views::View::OnThemeChanged();
ui::NativeTheme* theme = GetNativeTheme(); ui::NativeTheme* theme = GetNativeTheme();
...@@ -494,3 +506,6 @@ void FindBarView::OnThemeChanged() { ...@@ -494,3 +506,6 @@ void FindBarView::OnThemeChanged() {
views::SetImageFromVectorIcon(close_button_, vector_icons::kCloseRoundedIcon, views::SetImageFromVectorIcon(close_button_, vector_icons::kCloseRoundedIcon,
base_foreground_color); base_foreground_color);
} }
BEGIN_METADATA(FindBarView, views::View)
END_METADATA
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.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 "chrome/browser/ui/views/dropdown_bar_host_delegate.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
...@@ -45,9 +46,13 @@ class FindBarView : public views::View, ...@@ -45,9 +46,13 @@ class FindBarView : public views::View,
public views::ButtonListener, public views::ButtonListener,
public views::TextfieldController { public views::TextfieldController {
public: public:
explicit FindBarView(FindBarHost* host); METADATA_HEADER(FindBarView);
explicit FindBarView(FindBarHost* host = nullptr);
~FindBarView() override; ~FindBarView() override;
void SetHost(FindBarHost* host);
// Accessors for the text and selection displayed in the text box. // Accessors for the text and selection displayed in the text box.
void SetFindTextAndSelectedRange(const base::string16& find_text, void SetFindTextAndSelectedRange(const base::string16& find_text,
const gfx::Range& selected_range); const gfx::Range& selected_range);
...@@ -69,7 +74,6 @@ class FindBarView : public views::View, ...@@ -69,7 +74,6 @@ class FindBarView : public views::View,
void ClearMatchCount(); void ClearMatchCount();
// views::View: // views::View:
const char* GetClassName() const override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void OnThemeChanged() override; void OnThemeChanged() override;
...@@ -116,4 +120,8 @@ class FindBarView : public views::View, ...@@ -116,4 +120,8 @@ class FindBarView : public views::View,
DISALLOW_COPY_AND_ASSIGN(FindBarView); 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_ #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