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

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: Fixed a Paste operation. 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 break; 388 break;
389 default: 389 default:
390 NOTREACHED() << L"Unknown button"; 390 NOTREACHED() << L"Unknown button";
391 break; 391 break;
392 } 392 }
393 } 393 }
394 394
395 //////////////////////////////////////////////////////////////////////////////// 395 ////////////////////////////////////////////////////////////////////////////////
396 // FindBarView, views::TextfieldController implementation: 396 // FindBarView, views::TextfieldController implementation:
397 397
398 void FindBarView::ContentsChanged(views::Textfield* sender, 398 bool FindBarView::HandleKeyEvent(views::Textfield* sender,
399 const string16& new_contents) { 399 const ui::KeyEvent& key_event) {
400 // If the dialog is not visible, there is no reason to process keyboard input.
401 if (!host()->IsVisible())
402 return false;
403
404 if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
405 return true; // Handled, we are done!
406
407 if (key_event.key_code() == ui::VKEY_RETURN) {
408 // Pressing Return/Enter starts the search (unless text box is empty).
409 string16 find_string = find_text_->text();
410 if (!find_string.empty()) {
411 FindBarController* controller = find_bar_host()->GetFindBarController();
412 FindTabHelper* find_tab_helper =
413 FindTabHelper::FromWebContents(controller->web_contents());
414 // Search forwards for enter, backwards for shift-enter.
415 find_tab_helper->StartFinding(find_string,
416 !key_event.IsShiftDown(),
417 false); // Not case sensitive.
418 }
419 return true;
420 }
421
422 return false;
423 }
424
425 void FindBarView::OnAfterUserAction(views::Textfield* sender) {
400 FindBarController* controller = find_bar_host()->GetFindBarController(); 426 FindBarController* controller = find_bar_host()->GetFindBarController();
401 DCHECK(controller); 427 DCHECK(controller);
402 content::WebContents* web_contents = controller->web_contents(); 428 content::WebContents* web_contents = controller->web_contents();
403 // We must guard against a NULL web_contents, which can happen if the text 429 // We must guard against a NULL web_contents, which can happen if the text
404 // in the Find box is changed right after the tab is destroyed. Otherwise, it 430 // in the Find box is changed right after the tab is destroyed. Otherwise, it
405 // can lead to crashes, as exposed by automation testing in issue 8048. 431 // can lead to crashes, as exposed by automation testing in issue 8048.
406 if (!web_contents) 432 if (!web_contents)
407 return; 433 return;
408 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); 434 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
409 435
436 // The composition text wouldn't be what the user is really looking for.
437 // We delay the search until the user commits the composition text.
438 if (sender->IsIMEComposing() ||
439 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
440 return;
441
442 const string16& search_text = sender->text();
443 last_searched_text_ = search_text;
444
410 // When the user changes something in the text box we check the contents and 445 // When the user changes something in the text box we check the contents and
411 // if the textbox contains something we set it as the new search string and 446 // if the textbox contains something we set it as the new search string and
412 // initiate search (even though old searches might be in progress). 447 // initiate search (even though old searches might be in progress).
413 if (!new_contents.empty()) { 448 if (!search_text.empty()) {
414 // The last two params here are forward (true) and case sensitive (false). 449 // The last two params here are forward (true) and case sensitive (false).
415 find_tab_helper->StartFinding(new_contents, true, false); 450 find_tab_helper->StartFinding(search_text, true, false);
416 } else { 451 } else {
417 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage); 452 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
418 UpdateForResult(find_tab_helper->find_result(), string16()); 453 UpdateForResult(find_tab_helper->find_result(), string16());
419 find_bar_host()->MoveWindowIfNecessary(gfx::Rect(), false); 454 find_bar_host()->MoveWindowIfNecessary(gfx::Rect(), false);
420 455
421 // Clearing the text box should clear the prepopulate state so that when 456 // Clearing the text box should clear the prepopulate state so that when
422 // we close and reopen the Find box it doesn't show the search we just 457 // we close and reopen the Find box it doesn't show the search we just
423 // deleted. We can't do this on ChromeOS yet because we get ContentsChanged 458 // deleted. We can't do this on ChromeOS yet because we get ContentsChanged
424 // sent for a lot more things than just the user nulling out the search 459 // sent for a lot more things than just the user nulling out the search
425 // terms. See http://crbug.com/45372. 460 // terms. See http://crbug.com/45372.
426 Profile* profile = 461 Profile* profile =
427 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 462 Profile::FromBrowserContext(web_contents->GetBrowserContext());
428 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile); 463 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile);
429 find_bar_state->set_last_prepopulate_text(string16()); 464 find_bar_state->set_last_prepopulate_text(string16());
430 } 465 }
431 } 466 }
432 467
433 bool FindBarView::HandleKeyEvent(views::Textfield* sender,
434 const ui::KeyEvent& key_event) {
435 // If the dialog is not visible, there is no reason to process keyboard input.
436 if (!host()->IsVisible())
437 return false;
438
439 if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
440 return true; // Handled, we are done!
441
442 if (key_event.key_code() == ui::VKEY_RETURN) {
443 // Pressing Return/Enter starts the search (unless text box is empty).
444 string16 find_string = find_text_->text();
445 if (!find_string.empty()) {
446 FindBarController* controller = find_bar_host()->GetFindBarController();
447 FindTabHelper* find_tab_helper =
448 FindTabHelper::FromWebContents(controller->web_contents());
449 // Search forwards for enter, backwards for shift-enter.
450 find_tab_helper->StartFinding(find_string,
451 !key_event.IsShiftDown(),
452 false); // Not case sensitive.
453 }
454 return true;
455 }
456
457 return false;
458 }
459
460 void FindBarView::OnAfterCutOrCopy() { 468 void FindBarView::OnAfterCutOrCopy() {
461 Profile* profile = host()->browser_view()->browser()->profile(); 469 Profile* profile = host()->browser_view()->browser()->profile();
462 ui::SourceTag source_tag = 470 ui::SourceTag source_tag =
463 content::BrowserContext::GetMarkerForOffTheRecordContext(profile); 471 content::BrowserContext::GetMarkerForOffTheRecordContext(profile);
464 if (source_tag != ui::SourceTag()) { 472 if (source_tag != ui::SourceTag()) {
465 // Overwrite the clipboard with the correct SourceTag 473 // Overwrite the clipboard with the correct SourceTag
466 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); 474 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
467 string16 text; 475 string16 text;
468 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 476 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
469 477
470 ui::ScopedClipboardWriter scw(clipboard, 478 ui::ScopedClipboardWriter scw(clipboard,
471 ui::Clipboard::BUFFER_STANDARD, 479 ui::Clipboard::BUFFER_STANDARD,
472 source_tag); 480 source_tag);
473 scw.WriteText(text); 481 scw.WriteText(text);
474 } 482 }
475 } 483 }
476 484
485 void FindBarView::OnAfterPaste() {
486 // Clear the last search text so we always search for the user input after
487 // a paste operation, even if the pasted text is the same as before.
488 // See http://crbug.com/79002
489 last_searched_text_.clear();
490 }
491
477 void FindBarView::UpdateMatchCountAppearance(bool no_match) { 492 void FindBarView::UpdateMatchCountAppearance(bool no_match) {
478 if (no_match) { 493 if (no_match) {
479 match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch); 494 match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch);
480 match_count_text_->SetEnabledColor(kTextColorNoMatch); 495 match_count_text_->SetEnabledColor(kTextColorNoMatch);
481 } else { 496 } else {
482 match_count_text_->SetBackgroundColor(kBackgroundColorMatch); 497 match_count_text_->SetBackgroundColor(kBackgroundColorMatch);
483 match_count_text_->SetEnabledColor(kTextColorMatchCount); 498 match_count_text_->SetEnabledColor(kTextColorMatchCount);
484 } 499 }
485 } 500 }
486 501
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 537
523 void FindBarView::OnThemeChanged() { 538 void FindBarView::OnThemeChanged() {
524 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 539 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
525 if (GetThemeProvider()) { 540 if (GetThemeProvider()) {
526 close_button_->SetBackground( 541 close_button_->SetBackground(
527 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), 542 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT),
528 rb.GetImageSkiaNamed(IDR_CLOSE_1), 543 rb.GetImageSkiaNamed(IDR_CLOSE_1),
529 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); 544 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK));
530 } 545 }
531 } 546 }
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