| Index: chrome/browser/ui/find_bar/find_bar_controller.cc
|
| ===================================================================
|
| --- chrome/browser/ui/find_bar/find_bar_controller.cc (revision 71618)
|
| +++ chrome/browser/ui/find_bar/find_bar_controller.cc (working copy)
|
| @@ -7,7 +7,9 @@
|
| #include <algorithm>
|
|
|
| #include "base/i18n/rtl.h"
|
| +#include "base/utf_string_conversions.h"
|
| #include "build/build_config.h"
|
| +#include "chrome/browser/renderer_host/render_view_host.h"
|
| #include "chrome/browser/tab_contents/navigation_entry.h"
|
| #include "chrome/browser/ui/find_bar/find_bar.h"
|
| #include "chrome/browser/ui/find_bar/find_bar_state.h"
|
| @@ -37,6 +39,8 @@
|
|
|
| tab_contents_->set_find_ui_active(true);
|
| find_bar_->Show(true);
|
| + } else {
|
| + MaybeOverrideText();
|
| }
|
| find_bar_->SetFocusAndSelection();
|
| }
|
| @@ -204,11 +208,14 @@
|
|
|
| void FindBarController::MaybeSetPrepopulateText() {
|
| #if !defined(OS_MACOSX)
|
| - // Find out what we should show in the find text box. Usually, this will be
|
| - // the last search in this tab, but if no search has been issued in this tab
|
| - // we use the last search string (from any tab).
|
| - string16 find_string = tab_contents_->find_text();
|
| + // Find out what we should show in the find text box. If this tab contains any
|
| + // selected text, we use that text. Otherwise, we use the last search in this
|
| + // tab. If no search has been issued in this tab we use the last search string
|
| + // (from any tab).
|
| + string16 find_string = GetSelectedText();
|
| if (find_string.empty())
|
| + find_string = tab_contents_->find_text();
|
| + if (find_string.empty())
|
| find_string = tab_contents_->previous_find_text();
|
| if (find_string.empty()) {
|
| find_string =
|
| @@ -227,3 +234,19 @@
|
| // the find pasteboard mechanism, so don't set the text here.
|
| #endif
|
| }
|
| +
|
| +void FindBarController::MaybeOverrideText() {
|
| +#if !defined(OS_MACOSX)
|
| + string16 selected_text = GetSelectedText();
|
| + if (!selected_text.empty())
|
| + find_bar_->SetFindText(selected_text);
|
| +#else
|
| + // Having a per-tab find_string is not compatible with OS X's find pasteboard,
|
| + // so we always have the same find text in all find bars. This is done through
|
| + // the find pasteboard mechanism, so don't set the text here.
|
| +#endif
|
| +}
|
| +
|
| +string16 FindBarController::GetSelectedText() {
|
| + return UTF8ToUTF16(tab_contents_->render_view_host()->selected_text());
|
| +}
|
|
|