summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-11 18:19:00 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-11 18:19:00 +0000
commit5bc8fe91607f20f2d43dc461ca188dd07b55d435 (patch)
treeca6551f9d816757942485ee7d3542c5aeb4d2fed
parent3148c0ae4462e01f4b830b8d2150dcd7fee2cb3b (diff)
downloadchromium_src-5bc8fe91607f20f2d43dc461ca188dd07b55d435.zip
chromium_src-5bc8fe91607f20f2d43dc461ca188dd07b55d435.tar.gz
chromium_src-5bc8fe91607f20f2d43dc461ca188dd07b55d435.tar.bz2
Allow users to close the find session and activate the current link via ctrl-enter.
this only hooks up ctrl-enter on gtk for now, but adding it on windows/mac should be trivial webkit side, which needs to land first, is here: https://bugs.webkit.org/show_bug.cgi?id=35407 This also enables the FindInPageControllerTest tests on linux/gtk. BUG=29500 TEST=FindInPageControllerTest.ActivateLinkNavigatesPage Review URL: http://codereview.chromium.org/660137 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41291 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/find_bar_cocoa_controller.mm7
-rw-r--r--chrome/browser/find_bar_controller.cc7
-rw-r--r--chrome/browser/find_bar_controller.h11
-rw-r--r--chrome/browser/find_bar_host_browsertest.cc (renamed from chrome/browser/views/find_bar_host_browsertest.cc)67
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc15
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc20
-rw-r--r--chrome/browser/renderer_host/render_view_host.h6
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc9
-rw-r--r--chrome/browser/tab_contents/tab_contents.h6
-rw-r--r--chrome/browser/views/find_bar_host.cc2
-rw-r--r--chrome/browser/views/find_bar_host_interactive_uitest.cc9
-rw-r--r--chrome/browser/views/find_bar_view.cc6
-rw-r--r--chrome/chrome_tests.gypi6
-rw-r--r--chrome/common/render_messages.h46
-rw-r--r--chrome/common/render_messages_internal.h7
-rw-r--r--chrome/renderer/render_view.cc17
-rw-r--r--chrome/renderer/render_view.h2
-rw-r--r--chrome/test/data/find_in_page/link.html8
18 files changed, 205 insertions, 46 deletions
diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.mm b/chrome/browser/cocoa/find_bar_cocoa_controller.mm
index 8c5a0ab..3d398ca 100644
--- a/chrome/browser/cocoa/find_bar_cocoa_controller.mm
+++ b/chrome/browser/cocoa/find_bar_cocoa_controller.mm
@@ -76,7 +76,8 @@ const float kFindBarCloseDuration = 0.15;
- (IBAction)close:(id)sender {
if (findBarBridge_)
- findBarBridge_->GetFindBarController()->EndFindSession();
+ findBarBridge_->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
}
- (IBAction)previousResult:(id)sender {
@@ -135,7 +136,7 @@ const float kFindBarCloseDuration = 0.15;
tab_contents->StartFinding(base::SysNSStringToUTF16(findText), true, false);
} else {
// The textbox is empty so we reset.
- tab_contents->StopFinding(true); // true = clear selection on page.
+ tab_contents->StopFinding(FindBarController::kClearSelection);
[self updateUIForFindResult:tab_contents->find_result()
withText:string16()];
}
@@ -356,7 +357,7 @@ const float kFindBarCloseDuration = 0.15;
TabContents* contents =
findBarBridge_->GetFindBarController()->tab_contents();
if (contents) {
- contents->StopFinding(true);
+ contents->StopFinding(FindBarController::kClearSelection);
findBarBridge_->ClearResults(contents->find_result());
}
}
diff --git a/chrome/browser/find_bar_controller.cc b/chrome/browser/find_bar_controller.cc
index 9b5bc7d..b7ddf69 100644
--- a/chrome/browser/find_bar_controller.cc
+++ b/chrome/browser/find_bar_controller.cc
@@ -34,7 +34,7 @@ void FindBarController::Show() {
find_bar_->SetFocusAndSelection();
}
-void FindBarController::EndFindSession() {
+void FindBarController::EndFindSession(SelectionAction action) {
find_bar_->Hide(true);
// |tab_contents_| can be NULL for a number of reasons, for example when the
@@ -43,8 +43,7 @@ void FindBarController::EndFindSession() {
// When we hide the window, we need to notify the renderer that we are done
// for now, so that we can abort the scoping effort and clear all the
// tickmarks and highlighting.
- tab_contents_->StopFinding(false); // false = don't clear selection on
- // page.
+ tab_contents_->StopFinding(action);
find_bar_->ClearResults(tab_contents_->find_result());
// When we get dismissed we restore the focus to where it belongs.
@@ -139,7 +138,7 @@ void FindBarController::Observe(NotificationType type,
if (find_bar_->IsFindBarVisible()) {
if (PageTransition::StripQualifier(transition_type) !=
PageTransition::RELOAD) {
- EndFindSession();
+ EndFindSession(kKeepSelection);
} else {
// On Reload we want to make sure FindNext is converted to a full Find
// to make sure highlights for inactive matches are repainted.
diff --git a/chrome/browser/find_bar_controller.h b/chrome/browser/find_bar_controller.h
index 93c8185..5f37a2a 100644
--- a/chrome/browser/find_bar_controller.h
+++ b/chrome/browser/find_bar_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,6 +15,13 @@ class TabContents;
class FindBarController : public NotificationObserver {
public:
+ // An enum listing the possible actions to take on a find-in-page selection.
+ enum SelectionAction {
+ kKeepSelection, // Translate the find selection into a normal selection.
+ kClearSelection, // Clear the find selection.
+ kActivateSelection // Focus and click the selected node (for links).
+ };
+
// FindBar takes ownership of |find_bar_view|.
explicit FindBarController(FindBar* find_bar);
@@ -24,7 +31,7 @@ class FindBarController : public NotificationObserver {
void Show();
// Ends the current session.
- void EndFindSession();
+ void EndFindSession(SelectionAction action);
// Accessor for the attached TabContents.
TabContents* tab_contents() const { return tab_contents_; }
diff --git a/chrome/browser/views/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc
index 21bf7b5..81f322c 100644
--- a/chrome/browser/views/find_bar_host_browsertest.cc
+++ b/chrome/browser/find_bar_host_browsertest.cc
@@ -15,7 +15,18 @@
#include "chrome/common/notification_service.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
+
+#if defined(TOOLKIT_VIEWS)
#include "views/focus/focus_manager.h"
+#endif
+
+// http://crbug.com/37809
+#if defined(OS_LINUX) && defined(TOOLKIT_GTK)
+#define FindDisappearOnNavigate DISABLED_FindDisappearOnNavigate
+#define FindDisappearOnNewTabAndHistory \
+ DISABLED_FindDisappearOnNewTabAndHistory
+#define FindMovesWhenObscuring DISABLED_FindMovesWhenObscuring
+#endif
const std::wstring kSimplePage = L"404_is_enough_for_us.html";
const std::wstring kFramePage = L"files/find_in_page/frames.html";
@@ -30,6 +41,7 @@ const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html";
const std::wstring kSelectChangesOrdinal =
L"files/find_in_page/select_changes_ordinal.html";
const std::wstring kSimple = L"files/find_in_page/simple.html";
+const std::wstring kLinkPage = L"files/find_in_page/link.html";
const bool kBack = false;
const bool kFwd = true;
@@ -53,7 +65,7 @@ class FindInPageControllerTest : public InProcessBrowserTest {
}
};
-// Platform independent FindInPage that takes |const wchat_t*|
+// Platform independent FindInPage that takes |const wchar_t*|
// as an input.
int FindInPageWchar(TabContents* tab,
const wchar_t* search_str,
@@ -178,7 +190,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
EXPECT_EQ(1, ordinal);
// End the find session, which should set focus to the link.
- tab_contents->StopFinding(false);
+ tab_contents->StopFinding(FindBarController::kKeepSelection);
// Verify that the link is focused.
EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str());
@@ -197,7 +209,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
&result);
// End the find session.
- tab_contents->StopFinding(false);
+ tab_contents->StopFinding(FindBarController::kKeepSelection);
// Verify that link2 is not focused.
EXPECT_STREQ("", FocusedOnPage(tab_contents).c_str());
@@ -278,7 +290,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
EXPECT_EQ(3, ordinal);
// End the find session.
- tab_contents->StopFinding(false);
+ tab_contents->StopFinding(FindBarController::kKeepSelection);
}
// This test loads a page with frames and makes sure the ordinal returned makes
@@ -486,8 +498,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
GURL url2 = server->TestServerPageW(kFramePage);
ui_test_utils::NavigateToURL(browser(), url);
+#if defined(TOOLKIT_VIEWS)
// Open the Find window with animations disabled.
DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
browser()->ShowFindBar();
gfx::Point position;
@@ -520,8 +534,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
+#if defined(TOOLKIT_VIEWS)
// Open the Find window with animations disabled.
DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
browser()->ShowFindBar();
gfx::Point position;
@@ -560,8 +576,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) {
GURL url = server->TestServerPageW(kMoveIfOver);
ui_test_utils::NavigateToURL(browser(), url);
+#if defined(TOOLKIT_VIEWS)
// Open the Find window with animations disabled.
DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
browser()->ShowFindBar();
gfx::Point start_position;
@@ -640,6 +658,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
EXPECT_EQ(0, ordinal);
}
+#if defined(TOOLKIT_VIEWS)
// Make sure Find box grabs the Esc accelerator and restores it again.
#if defined(OS_LINUX)
// TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and
@@ -681,8 +700,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
focus_manager->GetCurrentTargetForAccelerator(escape);
EXPECT_TRUE(old_target != NULL);
+#if defined(TOOLKIT_VIEWS)
// Open the Find window with animations disabled.
DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
browser()->ShowFindBar();
// Our Find bar should be the new target.
@@ -693,12 +714,14 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
EXPECT_NE(new_target, old_target);
// Close the Find box.
- browser()->GetFindBarController()->EndFindSession();
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
// The accelerator for Escape should be back to what it was before.
EXPECT_EQ(old_target,
focus_manager->GetCurrentTargetForAccelerator(escape));
}
+#endif // TOOLKIT_VIEWS
// Make sure Find box does not become UI-inactive when no text is in the box as
// we switch to a tab contents with an empty find string. See issue 13570.
@@ -709,8 +732,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
+#if defined(TOOLKIT_VIEWS)
// Open the Find window with animations disabled.
DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
browser()->ShowFindBar();
// Simulate a user clearing the search string. Ideally, we should be
@@ -720,7 +745,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
TabContents* tab_contents = browser()->GetSelectedTabContents();
// Stop the (non-existing) find operation, and clear the selection (which
// signals the UI is still active).
- tab_contents->StopFinding(true);
+ tab_contents->StopFinding(FindBarController::kClearSelection);
// Make sure the Find UI flag hasn't been cleared, it must be so that the UI
// still responds to browser window resizing.
ASSERT_TRUE(tab_contents->find_ui_active());
@@ -748,7 +773,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
EXPECT_EQ(1, ordinal);
// End the Find session, thereby making the next F3 start afresh.
- browser()->GetFindBarController()->EndFindSession();
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
// Simulate F3 while Find box is closed. Should have 1 match.
EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal));
@@ -764,7 +790,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
HTTPTestServer* server = StartHTTPServer();
+#if defined(TOOLKIT_VIEWS)
DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -787,8 +815,31 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
// Switch back to first tab.
browser()->SelectTabContentsAt(0, false);
- browser()->GetFindBarController()->EndFindSession();
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
// Simulate F3.
ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal);
EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default"));
}
+
+// This makes sure that dismissing the find bar with kActivateSelection works.
+IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
+ HTTPTestServer* server = StartHTTPServer();
+
+#if defined(TOOLKIT_VIEWS)
+ DropdownBarHost::disable_animations_during_testing_ = true;
+#endif
+
+ // First we navigate to our test content.
+ GURL url = server->TestServerPageW(kLinkPage);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ TabContents* tab = browser()->GetSelectedTabContents();
+ int ordinal = 0;
+ FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal);
+ EXPECT_EQ(ordinal, 1);
+
+ // End the find session, click on the link.
+ tab->StopFinding(FindBarController::kActivateSelection);
+ EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
+}
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index 300c6db..f99eb6f 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -539,7 +539,7 @@ void FindBarGtk::FindEntryTextInContents(bool forward_search) {
false); // Not case sensitive.
} else {
// The textbox is empty so we reset.
- tab_contents->StopFinding(true); // true = clear selection on page.
+ tab_contents->StopFinding(FindBarController::kClearSelection);
UpdateUIForFindResult(find_bar_controller_->tab_contents()->find_result(),
string16());
}
@@ -695,10 +695,18 @@ gboolean FindBarGtk::OnKeyPressEvent(GtkWidget* widget, GdkEventKey* event,
if (find_bar->MaybeForwardKeyEventToRenderer(event)) {
return TRUE;
} else if (GDK_Escape == event->keyval) {
- find_bar->find_bar_controller_->EndFindSession();
+ find_bar->find_bar_controller_->EndFindSession(
+ FindBarController::kKeepSelection);
return TRUE;
} else if (GDK_Return == event->keyval ||
GDK_KP_Enter == event->keyval) {
+ if ((event->state & gtk_accelerator_get_default_mod_mask()) ==
+ GDK_CONTROL_MASK) {
+ find_bar->find_bar_controller_->EndFindSession(
+ FindBarController::kActivateSelection);
+ return TRUE;
+ }
+
bool forward = (event->state & gtk_accelerator_get_default_mod_mask()) !=
GDK_SHIFT_MASK;
find_bar->FindEntryTextInContents(forward);
@@ -716,7 +724,8 @@ gboolean FindBarGtk::OnKeyReleaseEvent(GtkWidget* widget, GdkEventKey* event,
// static
void FindBarGtk::OnClicked(GtkWidget* button, FindBarGtk* find_bar) {
if (button == find_bar->close_button_->widget()) {
- find_bar->find_bar_controller_->EndFindSession();
+ find_bar->find_bar_controller_->EndFindSession(
+ FindBarController::kKeepSelection);
} else if (button == find_bar->find_previous_button_->widget() ||
button == find_bar->find_next_button_->widget()) {
find_bar->FindEntryTextInContents(
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 59ba321..da86877 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -391,8 +391,24 @@ void RenderViewHost::StartFinding(int request_id,
// The result of the search is sent as a notification message by the renderer.
}
-void RenderViewHost::StopFinding(bool clear_selection) {
- Send(new ViewMsg_StopFinding(routing_id(), clear_selection));
+void RenderViewHost::StopFinding(
+ FindBarController::SelectionAction selection_action) {
+ ViewMsg_StopFinding_Params params;
+
+ switch (selection_action) {
+ case FindBarController::kClearSelection:
+ params.action = ViewMsg_StopFinding_Params::kClearSelection;
+ break;
+ case FindBarController::kKeepSelection:
+ params.action = ViewMsg_StopFinding_Params::kKeepSelection;
+ break;
+ case FindBarController::kActivateSelection:
+ params.action = ViewMsg_StopFinding_Params::kActivateSelection;
+ break;
+ default:
+ NOTREACHED();
+ }
+ Send(new ViewMsg_StopFinding(routing_id(), params));
}
void RenderViewHost::Zoom(PageZoom::Function function) {
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index e860dc2..4059bec 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/scoped_ptr.h"
+#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/renderer_host/render_widget_host.h"
#include "chrome/common/content_settings_types.h"
#include "chrome/common/page_zoom.h"
@@ -204,9 +205,8 @@ class RenderViewHost : public RenderWidgetHost {
bool match_case,
bool find_next);
- // Cancel a pending find operation. If |clear_selection| is true, it will also
- // clear the selection on the focused frame.
- void StopFinding(bool clear_selection);
+ // Cancel a pending find operation.
+ void StopFinding(FindBarController::SelectionAction selection_action);
// Change the zoom level of a page.
void Zoom(PageZoom::Function function);
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index db8e51f..8d93d2e 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1135,16 +1135,17 @@ void TabContents::StartFinding(string16 search_string,
find_next);
}
-void TabContents::StopFinding(bool clear_selection) {
- // When |clear_selection| is true, it means the find string has been cleared
+void TabContents::StopFinding(
+ FindBarController::SelectionAction selection_action) {
+ // When the action is kClearAction, it means the find string has been cleared
// by the user, but the UI has not been dismissed.
- if (!clear_selection)
+ if (selection_action != FindBarController::kClearSelection)
find_ui_active_ = false;
previous_find_text_ = find_text_;
find_text_.clear();
find_op_aborted_ = true;
last_search_result_ = FindNotificationDetails();
- render_view_host()->StopFinding(clear_selection);
+ render_view_host()->StopFinding(selection_action);
}
void TabContents::OnSavePage() {
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index c935519..15dd13a 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -22,6 +22,7 @@
#include "chrome/browser/dom_ui/dom_ui_factory.h"
#include "chrome/browser/download/save_package.h"
#include "chrome/browser/fav_icon_helper.h"
+#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/find_notification_details.h"
#include "chrome/browser/jsmessage_box_client.h"
#include "chrome/browser/net/url_request_context_getter.h"
@@ -499,9 +500,8 @@ class TabContents : public PageNavigator,
bool forward_direction,
bool case_sensitive);
- // Stops the current Find operation. If |clear_selection| is true, it will
- // also clear the selection on the focused frame.
- void StopFinding(bool clear_selection);
+ // Stops the current Find operation.
+ void StopFinding(FindBarController::SelectionAction selection_action);
// Accessors/Setters for find_ui_active_.
bool find_ui_active() const { return find_ui_active_; }
diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc
index 4a7a553..4fb10b2 100644
--- a/chrome/browser/views/find_bar_host.cc
+++ b/chrome/browser/views/find_bar_host.cc
@@ -96,7 +96,7 @@ bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) {
// This will end the Find session and hide the window, causing it to loose
// focus and in the process unregister us as the handler for the Escape
// accelerator through the FocusWillChange event.
- find_bar_controller_->EndFindSession();
+ find_bar_controller_->EndFindSession(FindBarController::kKeepSelection);
return true;
}
diff --git a/chrome/browser/views/find_bar_host_interactive_uitest.cc b/chrome/browser/views/find_bar_host_interactive_uitest.cc
index 3e6e48a..0b66cc9 100644
--- a/chrome/browser/views/find_bar_host_interactive_uitest.cc
+++ b/chrome/browser/views/find_bar_host_interactive_uitest.cc
@@ -125,7 +125,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
// Ensure the creation of the find bar controller.
browser()->GetFindBarController()->Show();
EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
- browser()->GetFindBarController()->EndFindSession();
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
// Focus the location bar, find something on the page, close the find box,
@@ -135,7 +136,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
ui_test_utils::FindInPage(browser()->GetSelectedTabContents(),
L"a", true, false, NULL);
- browser()->GetFindBarController()->EndFindSession();
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
EXPECT_EQ(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW, GetFocusedViewID());
// Focus the location bar, open and close the find box, focus should return to
@@ -145,6 +147,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
browser()->GetFindBarController()->Show();
EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
- browser()->GetFindBarController()->EndFindSession();
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
}
diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc
index 8eb432d..a8cb944 100644
--- a/chrome/browser/views/find_bar_view.cc
+++ b/chrome/browser/views/find_bar_view.cc
@@ -406,7 +406,8 @@ void FindBarView::ButtonPressed(
}
break;
case CLOSE_TAG:
- find_bar_host()->GetFindBarController()->EndFindSession();
+ find_bar_host()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
break;
default:
NOTREACHED() << L"Unknown button";
@@ -434,8 +435,7 @@ void FindBarView::ContentsChanged(views::Textfield* sender,
// The last two params here are forward (true) and case sensitive (false).
controller->tab_contents()->StartFinding(new_contents, true, false);
} else {
- // The textbox is empty so we reset. true = clear selection on page.
- controller->tab_contents()->StopFinding(true);
+ controller->tab_contents()->StopFinding(FindBarController::kClearSelection);
UpdateForResult(controller->tab_contents()->find_result(), string16());
}
}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index d9e9a51..0387d50 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -7,7 +7,6 @@
'browser_tests_sources_views_specific': [
'browser/extensions/browser_action_test_util_views.cc',
'browser/views/browser_actions_container_unittest.cc',
- 'browser/views/find_bar_host_browsertest.cc',
],
'browser_tests_sources_win_specific': [
'browser/extensions/extension_shelf_model_unittest.cc',
@@ -1216,6 +1215,7 @@
'browser/extensions/page_action_apitest.cc',
'browser/extensions/permissions_apitest.cc',
'browser/extensions/stubs_apitest.cc',
+ 'browser/find_bar_host_browsertest.cc',
'browser/geolocation/access_token_store_browsertest.cc',
'browser/geolocation/geolocation_browsertest.cc',
'browser/gtk/bookmark_manager_browsertest.cc',
@@ -1287,6 +1287,10 @@
'sources': [
'browser/extensions/browser_action_test_util_mac.mm',
],
+ 'sources!': [
+ # TODO(estade): need to port. http://crbug.com/37808
+ 'browser/find_bar_host_browsertest.cc',
+ ],
'include_dirs': [
'../third_party/GTM',
],
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index d7c3825..0fb09e4 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -119,6 +119,19 @@ struct ViewMsg_AudioStreamState_Params {
State state;
};
+// The user has completed a find-in-page; this type defines what actions the
+// renderer should take next.
+struct ViewMsg_StopFinding_Params {
+ enum Action {
+ kClearSelection,
+ kKeepSelection,
+ kActivateSelection
+ };
+
+ // The action that should be taken when the find is completed.
+ Action action;
+};
+
// Parameters structure for ViewHostMsg_FrameNavigate, which has too many data
// parameters to be reasonably put in a predefined IPC message.
struct ViewHostMsg_FrameNavigate_Params {
@@ -1998,6 +2011,39 @@ struct ParamTraits<ViewMsg_AudioStreamState_Params> {
};
template <>
+struct ParamTraits<ViewMsg_StopFinding_Params> {
+ typedef ViewMsg_StopFinding_Params param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p.action);
+ }
+ static bool Read(const Message* m, void** iter, param_type* p) {
+ int type;
+ if (!m->ReadInt(iter, &type))
+ return false;
+ p->action = static_cast<ViewMsg_StopFinding_Params::Action>(type);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ std::wstring action;
+ switch (p.action) {
+ case ViewMsg_StopFinding_Params::kClearSelection:
+ action = L"ViewMsg_StopFinding_Params::kClearSelection";
+ break;
+ case ViewMsg_StopFinding_Params::kKeepSelection:
+ action = L"ViewMsg_StopFinding_Params::kKeepSelection";
+ break;
+ case ViewMsg_StopFinding_Params::kActivateSelection:
+ action = L"ViewMsg_StopFinding_Params::kActivateSelection";
+ break;
+ default:
+ action = L"UNKNOWN";
+ break;
+ }
+ LogParam(action, l);
+ }
+};
+
+template <>
struct ParamTraits<ViewMsg_DatabaseOpenFileResponse_Params> {
typedef ViewMsg_DatabaseOpenFileResponse_Params param_type;
static void Write(Message* m, const param_type& p) {
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 10ca2dc..6f9158a 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -201,10 +201,9 @@ IPC_BEGIN_MESSAGES(View)
std::string /* security info */)
// This message notifies the renderer that the user has closed the FindInPage
- // window (and that the selection should be cleared and the tick-marks
- // erased). If |clear_selection| is true, it will also clear the current
- // selection.
- IPC_MESSAGE_ROUTED1(ViewMsg_StopFinding, bool /* clear_selection */)
+ // window (and what action to take regarding the selection).
+ IPC_MESSAGE_ROUTED1(ViewMsg_StopFinding,
+ ViewMsg_StopFinding_Params /* action */)
// These messages are typically generated from context menus and request the
// renderer to apply the specified operation to the current selection.
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index f18d06b..12394b2 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -146,6 +146,7 @@ using WebKit::WebCString;
using WebKit::WebData;
using WebKit::WebDataSource;
using WebKit::WebDevToolsAgent;
+using WebKit::WebDocument;
using WebKit::WebDragData;
using WebKit::WebDragOperation;
using WebKit::WebDragOperationsMask;
@@ -980,11 +981,13 @@ void RenderView::OnSetupDevToolsClient() {
devtools_client_.reset(new DevToolsClient(this));
}
-void RenderView::OnStopFinding(bool clear_selection) {
+void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
WebView* view = webview();
if (!view)
return;
+ bool clear_selection =
+ params.action == ViewMsg_StopFinding_Params::kClearSelection;
if (clear_selection)
view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
@@ -993,6 +996,18 @@ void RenderView::OnStopFinding(bool clear_selection) {
frame->stopFinding(clear_selection);
frame = frame->traverseNext(false);
}
+
+ if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
+ WebFrame* focused_frame = view->focusedFrame();
+ if (focused_frame) {
+ WebDocument doc = focused_frame->document();
+ if (!doc.isNull()) {
+ WebNode node = doc.focusedNode();
+ if (!node.isNull())
+ node.simulateClick();
+ }
+ }
+ }
}
void RenderView::OnFindReplyAck() {
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index b0db68f..d32ce57 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -613,7 +613,7 @@ class RenderView : public RenderWidget,
bool new_navigation,
const GURL& display_url,
const std::string& security_info);
- void OnStopFinding(bool clear_selection);
+ void OnStopFinding(const ViewMsg_StopFinding_Params& params);
void OnFindReplyAck();
void OnUpdateTargetURLAck();
void OnUndo();
diff --git a/chrome/test/data/find_in_page/link.html b/chrome/test/data/find_in_page/link.html
new file mode 100644
index 0000000..78644ce1
--- /dev/null
+++ b/chrome/test/data/find_in_page/link.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+ <title>Find in page</title>
+</head>
+<body>
+ This is a page with some text and a <a href="simple.html">link</a> that we use in the browser tests.
+</body>
+</html>