OLD | NEW |
---|---|
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 Loading... | |
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_) | |
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
| |
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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 | 530 |
523 void FindBarView::OnThemeChanged() { | 531 void FindBarView::OnThemeChanged() { |
524 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 532 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
525 if (GetThemeProvider()) { | 533 if (GetThemeProvider()) { |
526 close_button_->SetBackground( | 534 close_button_->SetBackground( |
527 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | 535 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), |
528 rb.GetImageSkiaNamed(IDR_CLOSE_1), | 536 rb.GetImageSkiaNamed(IDR_CLOSE_1), |
529 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | 537 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |
530 } | 538 } |
531 } | 539 } |
OLD | NEW |