| Index: chrome/browser/ui/views/find_bar_view.cc
|
| diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc
|
| index a3598acc4ea9761d22a69f28721be696627f03be..0649358f5132f6e1014f6c582eba93c6a9c5d0aa 100644
|
| --- a/chrome/browser/ui/views/find_bar_view.cc
|
| +++ b/chrome/browser/ui/views/find_bar_view.cc
|
| @@ -396,6 +396,60 @@ void FindBarView::ButtonPressed(
|
|
|
| void FindBarView::ContentsChanged(views::Textfield* sender,
|
| const string16& new_contents) {
|
| + // TextfieldController::OnAfterUserAction() is supported only by Views
|
| + // implementation, and NativeTextfieldWin doesn't call OnAfterUserAction().
|
| + // Call Find() here.
|
| + // TODO(yukishiino): Remove this code after the migration to Views.
|
| + if (!views::Textfield::IsViewsTextfieldEnabled())
|
| + Find(new_contents);
|
| +}
|
| +
|
| +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 (!host()->IsVisible())
|
| + return false;
|
| +
|
| + if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
|
| + return true; // Handled, we are done!
|
| +
|
| + if (key_event.key_code() == ui::VKEY_RETURN) {
|
| + // Pressing Return/Enter starts the search (unless text box is empty).
|
| + string16 find_string = find_text_->text();
|
| + if (!find_string.empty()) {
|
| + FindBarController* controller = find_bar_host()->GetFindBarController();
|
| + FindTabHelper* find_tab_helper =
|
| + FindTabHelper::FromWebContents(controller->web_contents());
|
| + // Search forwards for enter, backwards for shift-enter.
|
| + find_tab_helper->StartFinding(find_string,
|
| + !key_event.IsShiftDown(),
|
| + false); // Not case sensitive.
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +void FindBarView::OnAfterUserAction(views::Textfield* sender) {
|
| + // The composition text wouldn't be what the user is really looking for.
|
| + // We delay the search until the user commits the composition text.
|
| + if (sender->IsIMEComposing() || sender->text() == last_searched_text_)
|
| + return;
|
| +
|
| + // TODO(yukishiino): Remove this condition check after the migration to Views.
|
| + if (views::Textfield::IsViewsTextfieldEnabled())
|
| + Find(sender->text());
|
| +}
|
| +
|
| +void FindBarView::OnAfterPaste() {
|
| + // Clear the last search text so we always search for the user input after
|
| + // a paste operation, even if the pasted text is the same as before.
|
| + // See http://crbug.com/79002
|
| + last_searched_text_.clear();
|
| +}
|
| +
|
| +void FindBarView::Find(const string16& search_text) {
|
| FindBarController* controller = find_bar_host()->GetFindBarController();
|
| DCHECK(controller);
|
| content::WebContents* web_contents = controller->web_contents();
|
| @@ -406,12 +460,14 @@ void FindBarView::ContentsChanged(views::Textfield* sender,
|
| return;
|
| FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
|
|
|
| + last_searched_text_ = search_text;
|
| +
|
| // When the user changes something in the text box we check the contents and
|
| // if the textbox contains something we set it as the new search string and
|
| // initiate search (even though old searches might be in progress).
|
| - if (!new_contents.empty()) {
|
| + if (!search_text.empty()) {
|
| // The last two params here are forward (true) and case sensitive (false).
|
| - find_tab_helper->StartFinding(new_contents, true, false);
|
| + find_tab_helper->StartFinding(search_text, true, false);
|
| } else {
|
| find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
|
| UpdateForResult(find_tab_helper->find_result(), string16());
|
| @@ -429,33 +485,6 @@ void FindBarView::ContentsChanged(views::Textfield* sender,
|
| }
|
| }
|
|
|
| -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 (!host()->IsVisible())
|
| - return false;
|
| -
|
| - if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
|
| - return true; // Handled, we are done!
|
| -
|
| - if (key_event.key_code() == ui::VKEY_RETURN) {
|
| - // Pressing Return/Enter starts the search (unless text box is empty).
|
| - string16 find_string = find_text_->text();
|
| - if (!find_string.empty()) {
|
| - FindBarController* controller = find_bar_host()->GetFindBarController();
|
| - FindTabHelper* find_tab_helper =
|
| - FindTabHelper::FromWebContents(controller->web_contents());
|
| - // Search forwards for enter, backwards for shift-enter.
|
| - find_tab_helper->StartFinding(find_string,
|
| - !key_event.IsShiftDown(),
|
| - false); // Not case sensitive.
|
| - }
|
| - return true;
|
| - }
|
| -
|
| - return false;
|
| -}
|
| -
|
| void FindBarView::UpdateMatchCountAppearance(bool no_match) {
|
| if (no_match) {
|
| match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch);
|
|
|