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

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 a Paste operation. 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
« no previous file with comments | « chrome/browser/ui/views/find_bar_view.h ('k') | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e0d3966ec76565f41ba26dbfe3a93e72efe37420 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_)
msw 2013/06/01 01:58:22 Does this actually get hit when you cancel a compo
Yuki 2013/06/03 10:07:18 Yes, this line gets hit when you cancel a composit
+ 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 =
@@ -474,6 +482,13 @@ 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::UpdateMatchCountAppearance(bool no_match) {
if (no_match) {
match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch);
« no previous file with comments | « chrome/browser/ui/views/find_bar_view.h ('k') | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698