summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-26 21:47:20 +0000
committerfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-26 21:47:20 +0000
commit65134c43c3c181b874ea1c19a9f7bbcd82f51c6f (patch)
treef69374cec217dafb46b70cf68cef2cd8c4cc0ad4
parent1bbe184ba49c0ac30d193777a16331b6baa4f104 (diff)
downloadchromium_src-65134c43c3c181b874ea1c19a9f7bbcd82f51c6f.zip
chromium_src-65134c43c3c181b874ea1c19a9f7bbcd82f51c6f.tar.gz
chromium_src-65134c43c3c181b874ea1c19a9f7bbcd82f51c6f.tar.bz2
Fix bug 455: Active match in Find is not selected and links are not focused after you close the Find box.
Review URL: http://codereview.chromium.org/4283 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2645 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/render_view.cc2
-rw-r--r--webkit/glue/webframe.h16
-rw-r--r--webkit/glue/webframe_impl.cc45
-rw-r--r--webkit/glue/webframe_impl.h10
4 files changed, 63 insertions, 10 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index f9d6b33..9bfed29 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -835,7 +835,7 @@ void RenderView::OnStopFinding(bool clear_selection) {
WebFrame* frame = view->GetMainFrame();
while (frame) {
- frame->StopFinding();
+ frame->StopFinding(clear_selection);
frame = view->GetNextFrameAfter(frame, false);
}
}
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h
index 9e6f9c9..a63158a 100644
--- a/webkit/glue/webframe.h
+++ b/webkit/glue/webframe.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WEBKIT_GLUE_WEBFRAME_H__
-#define WEBKIT_GLUE_WEBFRAME_H__
+#ifndef WEBKIT_GLUE_WEBFRAME_H_
+#define WEBKIT_GLUE_WEBFRAME_H_
#include <string>
@@ -203,8 +203,11 @@ class WebFrame : public base::RefCounted<WebFrame> {
// Notifies the frame that we are no longer interested in searching. This will
// abort any asynchronous scoping effort already under way (see the function
// ScopeStringMatches for details) and erase all tick-marks and highlighting
- // from the previous search.
- virtual void StopFinding() = 0;
+ // from the previous search. If |clear_selection| is true, it will also make
+ // sure the end state for the Find operation does not leave a selection.
+ // This can occur when the user clears the search string but does not close
+ // the find box.
+ virtual void StopFinding(bool clear_selection) = 0;
// Counts how many times a particular string occurs within the frame. It
// also retrieves the location of the string and updates a vector in the frame
@@ -352,8 +355,7 @@ class WebFrame : public base::RefCounted<WebFrame> {
virtual bool IsReloadAllowingStaleData() const = 0;
private:
- DISALLOW_EVIL_CONSTRUCTORS(WebFrame);
+ DISALLOW_COPY_AND_ASSIGN(WebFrame);
};
-#endif // WEBKIT_GLUE_WEBFRAME_H__
-
+#endif // WEBKIT_GLUE_WEBFRAME_H_
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 17cc4cd..f65bf9e 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -1225,7 +1225,50 @@ void WebFrameImpl::CancelPendingScopingEffort() {
active_tickmark_ = WidgetClientWin::kNoTickmark;
}
-void WebFrameImpl::StopFinding() {
+void WebFrameImpl::SetFindEndstateFocusAndSelection() {
+ WebFrameImpl* main_frame_impl =
+ static_cast<WebFrameImpl*>(GetView()->GetMainFrame());
+
+ if (this == main_frame_impl->active_tickmark_frame() &&
+ active_tickmark_ != WidgetClientWin::kNoTickmark) {
+ RefPtr<Range> range = tickmarks_[active_tickmark_];
+
+ // Set the selection to what the active match is.
+ frame()->selectionController()->setSelectedRange(
+ range.get(), WebCore::DOWNSTREAM, false);
+
+ // We will be setting focus ourselves, so we want the view to forget its
+ // stored focus node so that it won't change it after we are done.
+ static_cast<WebViewImpl*>(GetView())->ReleaseFocusReferences();
+
+ // Try to find the first focusable node up the chain, which will, for
+ // example, focus links if we have found text within the link.
+ Node* node = range->startNode();
+ while (node && !node->isFocusable() && node != frame()->document())
+ node = node->parent();
+
+ if (node && node != frame()->document()) {
+ // Found a focusable parent node. Set focus to it.
+ frame()->document()->setFocusedNode(node);
+ } else {
+ // Iterate over all the nodes in the range until we find a focusable node.
+ // This, for example, sets focus to the first link if you search for
+ // text and text that is within one or more links.
+ node = range->startNode();
+ while (node && node != range->pastEndNode()) {
+ if (node->isFocusable()) {
+ frame()->document()->setFocusedNode(node);
+ break;
+ }
+ node = node->traverseNextNode();
+ }
+ }
+ }
+}
+
+void WebFrameImpl::StopFinding(bool clear_selection) {
+ if (!clear_selection)
+ SetFindEndstateFocusAndSelection();
CancelPendingScopingEffort();
// Let the frame know that we don't want tickmarks or highlighting anymore.
diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h
index a9d1fc4..dfca6e3 100644
--- a/webkit/glue/webframe_impl.h
+++ b/webkit/glue/webframe_impl.h
@@ -124,7 +124,7 @@ class WebFrameImpl : public WebFrame {
gfx::Rect* selection_rect);
virtual bool FindNext(const FindInPageRequest& request,
bool wrap_within_frame);
- virtual void StopFinding();
+ virtual void StopFinding(bool clear_selection);
virtual void ScopeStringMatches(FindInPageRequest request, bool reset);
virtual void CancelPendingScopingEffort();
virtual void ResetMatchCount();
@@ -251,6 +251,14 @@ class WebFrameImpl : public WebFrame {
return active_tickmark_;
}
+ // When a Find operation ends, we want to set the selection to what was active
+ // and set focus to the first focusable node we find (starting with the first
+ // node in the matched range and going up the inheritance chain). If we find
+ // nothing to focus we focus the first focusable node in the range. This
+ // allows us to set focus to a link (when we find text inside a link), which
+ // allows us to navigate by pressing Enter after closing the Find box.
+ void SetFindEndstateFocusAndSelection();
+
// Sets whether the WebFrameImpl allows its document to be scrolled.
// If the parameter is true, allow the document to be scrolled.
// Otherwise, disallow scrolling