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

Unified Diff: chrome/browser/ui/find_bar/find_bar_controller.cc

Issue 6356004: If the user selects text in the current tab, and types CTRL-F,... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 11 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/find_bar/find_bar_controller.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « chrome/browser/ui/find_bar/find_bar_controller.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698