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 69182002081b52a9bbe88e10a6d9ba8b0f531c7a..6c603c26f32ca5d9fe2ad81331dbc19b8e8323ef 100644 |
--- a/chrome/browser/ui/views/find_bar_view.cc |
+++ b/chrome/browser/ui/views/find_bar_view.cc |
@@ -395,8 +395,34 @@ void FindBarView::ButtonPressed( |
//////////////////////////////////////////////////////////////////////////////// |
// FindBarView, views::TextfieldController implementation: |
-void FindBarView::ContentsChanged(views::Textfield* sender, |
- const string16& 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) { |
FindBarController* controller = find_bar_host()->GetFindBarController(); |
DCHECK(controller); |
content::WebContents* web_contents = controller->web_contents(); |
@@ -407,12 +433,21 @@ void FindBarView::ContentsChanged(views::Textfield* sender, |
return; |
FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); |
+ // 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_) |
Peter Kasting
2013/05/30 22:00:14
Why check for the same text?
Right now, if you co
Yuki
2013/05/31 08:58:25
1. The original code used overriding TextfieldCont
|
+ return; |
+ |
+ const string16& search_text = sender->text(); |
+ 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()); |
@@ -430,33 +465,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::OnAfterCutOrCopy() { |
Profile* profile = host()->browser_view()->browser()->profile(); |
ui::SourceTag source_tag = |