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

Side by Side 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: Synced. Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/find_bar_view.h" 5 #include "chrome/browser/ui/views/find_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 NOTREACHED() << L"Unknown button"; 389 NOTREACHED() << L"Unknown button";
390 break; 390 break;
391 } 391 }
392 } 392 }
393 393
394 //////////////////////////////////////////////////////////////////////////////// 394 ////////////////////////////////////////////////////////////////////////////////
395 // FindBarView, views::TextfieldController implementation: 395 // FindBarView, views::TextfieldController implementation:
396 396
397 void FindBarView::ContentsChanged(views::Textfield* sender, 397 void FindBarView::ContentsChanged(views::Textfield* sender,
398 const string16& new_contents) { 398 const string16& new_contents) {
399 // TextfieldController::OnAfterUserAction() is supported only by Views
400 // implementation, and NativeTextfieldWin doesn't call OnAfterUserAction().
401 // Call Find() here.
402 // TODO(yukishiino): Remove this code after the migration to Views.
403 if (!views::Textfield::IsViewsTextfieldEnabled())
404 Find(new_contents);
405 }
406
407 bool FindBarView::HandleKeyEvent(views::Textfield* sender,
408 const ui::KeyEvent& key_event) {
409 // If the dialog is not visible, there is no reason to process keyboard input.
410 if (!host()->IsVisible())
411 return false;
412
413 if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
414 return true; // Handled, we are done!
415
416 if (key_event.key_code() == ui::VKEY_RETURN) {
417 // Pressing Return/Enter starts the search (unless text box is empty).
418 string16 find_string = find_text_->text();
419 if (!find_string.empty()) {
420 FindBarController* controller = find_bar_host()->GetFindBarController();
421 FindTabHelper* find_tab_helper =
422 FindTabHelper::FromWebContents(controller->web_contents());
423 // Search forwards for enter, backwards for shift-enter.
424 find_tab_helper->StartFinding(find_string,
425 !key_event.IsShiftDown(),
426 false); // Not case sensitive.
427 }
428 return true;
429 }
430
431 return false;
432 }
433
434 void FindBarView::OnAfterUserAction(views::Textfield* sender) {
435 // The composition text wouldn't be what the user is really looking for.
436 // We delay the search until the user commits the composition text.
437 if (sender->IsIMEComposing() || sender->text() == last_searched_text_)
438 return;
439
440 // TODO(yukishiino): Remove this condition check after the migration to Views.
441 if (views::Textfield::IsViewsTextfieldEnabled())
442 Find(sender->text());
443 }
444
445 void FindBarView::OnAfterPaste() {
446 // Clear the last search text so we always search for the user input after
447 // a paste operation, even if the pasted text is the same as before.
448 // See http://crbug.com/79002
449 last_searched_text_.clear();
450 }
451
452 void FindBarView::Find(const string16& search_text) {
399 FindBarController* controller = find_bar_host()->GetFindBarController(); 453 FindBarController* controller = find_bar_host()->GetFindBarController();
400 DCHECK(controller); 454 DCHECK(controller);
401 content::WebContents* web_contents = controller->web_contents(); 455 content::WebContents* web_contents = controller->web_contents();
402 // We must guard against a NULL web_contents, which can happen if the text 456 // We must guard against a NULL web_contents, which can happen if the text
403 // in the Find box is changed right after the tab is destroyed. Otherwise, it 457 // in the Find box is changed right after the tab is destroyed. Otherwise, it
404 // can lead to crashes, as exposed by automation testing in issue 8048. 458 // can lead to crashes, as exposed by automation testing in issue 8048.
405 if (!web_contents) 459 if (!web_contents)
406 return; 460 return;
407 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); 461 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
408 462
463 last_searched_text_ = search_text;
464
409 // When the user changes something in the text box we check the contents and 465 // When the user changes something in the text box we check the contents and
410 // if the textbox contains something we set it as the new search string and 466 // if the textbox contains something we set it as the new search string and
411 // initiate search (even though old searches might be in progress). 467 // initiate search (even though old searches might be in progress).
412 if (!new_contents.empty()) { 468 if (!search_text.empty()) {
413 // The last two params here are forward (true) and case sensitive (false). 469 // The last two params here are forward (true) and case sensitive (false).
414 find_tab_helper->StartFinding(new_contents, true, false); 470 find_tab_helper->StartFinding(search_text, true, false);
415 } else { 471 } else {
416 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage); 472 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
417 UpdateForResult(find_tab_helper->find_result(), string16()); 473 UpdateForResult(find_tab_helper->find_result(), string16());
418 find_bar_host()->MoveWindowIfNecessary(gfx::Rect(), false); 474 find_bar_host()->MoveWindowIfNecessary(gfx::Rect(), false);
419 475
420 // Clearing the text box should clear the prepopulate state so that when 476 // Clearing the text box should clear the prepopulate state so that when
421 // we close and reopen the Find box it doesn't show the search we just 477 // we close and reopen the Find box it doesn't show the search we just
422 // deleted. We can't do this on ChromeOS yet because we get ContentsChanged 478 // deleted. We can't do this on ChromeOS yet because we get ContentsChanged
423 // sent for a lot more things than just the user nulling out the search 479 // sent for a lot more things than just the user nulling out the search
424 // terms. See http://crbug.com/45372. 480 // terms. See http://crbug.com/45372.
425 Profile* profile = 481 Profile* profile =
426 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 482 Profile::FromBrowserContext(web_contents->GetBrowserContext());
427 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile); 483 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile);
428 find_bar_state->set_last_prepopulate_text(string16()); 484 find_bar_state->set_last_prepopulate_text(string16());
429 } 485 }
430 } 486 }
431 487
432 bool FindBarView::HandleKeyEvent(views::Textfield* sender,
433 const ui::KeyEvent& key_event) {
434 // If the dialog is not visible, there is no reason to process keyboard input.
435 if (!host()->IsVisible())
436 return false;
437
438 if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
439 return true; // Handled, we are done!
440
441 if (key_event.key_code() == ui::VKEY_RETURN) {
442 // Pressing Return/Enter starts the search (unless text box is empty).
443 string16 find_string = find_text_->text();
444 if (!find_string.empty()) {
445 FindBarController* controller = find_bar_host()->GetFindBarController();
446 FindTabHelper* find_tab_helper =
447 FindTabHelper::FromWebContents(controller->web_contents());
448 // Search forwards for enter, backwards for shift-enter.
449 find_tab_helper->StartFinding(find_string,
450 !key_event.IsShiftDown(),
451 false); // Not case sensitive.
452 }
453 return true;
454 }
455
456 return false;
457 }
458
459 void FindBarView::UpdateMatchCountAppearance(bool no_match) { 488 void FindBarView::UpdateMatchCountAppearance(bool no_match) {
460 if (no_match) { 489 if (no_match) {
461 match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch); 490 match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch);
462 match_count_text_->SetEnabledColor(kTextColorNoMatch); 491 match_count_text_->SetEnabledColor(kTextColorNoMatch);
463 } else { 492 } else {
464 match_count_text_->SetBackgroundColor(kBackgroundColorMatch); 493 match_count_text_->SetBackgroundColor(kBackgroundColorMatch);
465 match_count_text_->SetEnabledColor(kTextColorMatchCount); 494 match_count_text_->SetEnabledColor(kTextColorMatchCount);
466 } 495 }
467 } 496 }
468 497
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 533
505 void FindBarView::OnThemeChanged() { 534 void FindBarView::OnThemeChanged() {
506 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 535 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
507 if (GetThemeProvider()) { 536 if (GetThemeProvider()) {
508 close_button_->SetBackground( 537 close_button_->SetBackground(
509 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), 538 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT),
510 rb.GetImageSkiaNamed(IDR_CLOSE_1), 539 rb.GetImageSkiaNamed(IDR_CLOSE_1),
511 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); 540 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK));
512 } 541 }
513 } 542 }
OLDNEW
« 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