Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1489)

Unified Diff: chrome/browser/ui/views/find_bar_view.cc

Issue 15841009: Delays find-in-page until IME composition is committed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed so it works with NativeTextFieldWin as it did. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 dcc61fc7cf2b9c500e9492db40dac393802e4336..6a998a320f34e93294a147838035c27f4a13f06d 100644
--- a/chrome/browser/ui/views/find_bar_view.cc
+++ b/chrome/browser/ui/views/find_bar_view.cc
@@ -397,37 +397,12 @@ void FindBarView::ButtonPressed(
void FindBarView::ContentsChanged(views::Textfield* sender,
const string16& new_contents) {
- FindBarController* controller = find_bar_host()->GetFindBarController();
- DCHECK(controller);
- content::WebContents* web_contents = controller->web_contents();
- // We must guard against a NULL web_contents, which can happen if the text
- // in the Find box is changed right after the tab is destroyed. Otherwise, it
- // can lead to crashes, as exposed by automation testing in issue 8048.
- if (!web_contents)
- return;
- FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
-
- // 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()) {
- // The last two params here are forward (true) and case sensitive (false).
- find_tab_helper->StartFinding(new_contents, true, false);
- } else {
- find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
- UpdateForResult(find_tab_helper->find_result(), string16());
- find_bar_host()->MoveWindowIfNecessary(gfx::Rect(), false);
-
- // Clearing the text box should clear the prepopulate state so that when
- // we close and reopen the Find box it doesn't show the search we just
- // deleted. We can't do this on ChromeOS yet because we get ContentsChanged
- // sent for a lot more things than just the user nulling out the search
- // terms. See http://crbug.com/45372.
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile);
- find_bar_state->set_last_prepopulate_text(string16());
- }
+ // TextfieldController::OnAfterUserAction() is supported only by Views
+ // implementation, and NativeTextfieldWin doesn't call OnAfterUserAction().
+ // Call DoFinding() here.
+ // TODO(yukishiino): Remove this code after the migration to Views.
+ if (!views::Textfield::IsViewsTextfieldEnabled())
+ DoFinding(sender);
}
bool FindBarView::HandleKeyEvent(views::Textfield* sender,
@@ -457,6 +432,16 @@ bool FindBarView::HandleKeyEvent(views::Textfield* sender,
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_)
msw 2013/06/04 01:30:23 nit: this fits on the line above; also invert the
Yuki 2013/06/04 03:35:04 Done.
+ return;
+
+ DoFinding(sender);
+}
+
void FindBarView::OnAfterCutOrCopy() {
Profile* profile = host()->browser_view()->browser()->profile();
ui::SourceTag source_tag =
@@ -474,6 +459,50 @@ void FindBarView::OnAfterCutOrCopy() {
}
}
+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::DoFinding(views::Textfield* sender) {
+ FindBarController* controller = find_bar_host()->GetFindBarController();
+ DCHECK(controller);
+ content::WebContents* web_contents = controller->web_contents();
+ // We must guard against a NULL web_contents, which can happen if the text
+ // in the Find box is changed right after the tab is destroyed. Otherwise, it
+ // can lead to crashes, as exposed by automation testing in issue 8048.
+ if (!web_contents)
+ return;
+ FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
+
+ 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 (!search_text.empty()) {
+ // The last two params here are forward (true) and case sensitive (false).
+ find_tab_helper->StartFinding(search_text, true, false);
+ } else {
+ find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
+ UpdateForResult(find_tab_helper->find_result(), string16());
+ find_bar_host()->MoveWindowIfNecessary(gfx::Rect(), false);
+
+ // Clearing the text box should clear the prepopulate state so that when
+ // we close and reopen the Find box it doesn't show the search we just
+ // deleted. We can't do this on ChromeOS yet because we get ContentsChanged
+ // sent for a lot more things than just the user nulling out the search
+ // terms. See http://crbug.com/45372.
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile);
+ find_bar_state->set_last_prepopulate_text(string16());
+ }
+}
+
void FindBarView::UpdateMatchCountAppearance(bool no_match) {
if (no_match) {
match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch);

Powered by Google App Engine
This is Rietveld 408576698