summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 16:38:19 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 16:38:19 +0000
commite6347c2a131b2c66febcb8f1a3f0fd33d915115b (patch)
tree4077a9b7d1010150875de5c87658740cdca1404d /webkit
parentdb7286d3355528b36de6f0d7fa7f8d9929566511 (diff)
downloadchromium_src-e6347c2a131b2c66febcb8f1a3f0fd33d915115b.zip
chromium_src-e6347c2a131b2c66febcb8f1a3f0fd33d915115b.tar.gz
chromium_src-e6347c2a131b2c66febcb8f1a3f0fd33d915115b.tar.bz2
Let WebKit draw the active highlight for FindInPage,
instead of using the SelectionController. This fixes a couple of bugs, such as: Active match highlighting disappears when mouse selection is made within the page and selection color is orange (6145). and Selection color becomes orange in some cases on tabs that don't have a Find box open. and Gmail jumping to the first match if on FindNext if Find box is closed and reopened (9795). NOTE: This patch depends on my patch to WebKit that just got accepted. See: https://bugs.webkit.org/show_bug.cgi?id=25102 BUG=6145, 9795 TEST=Find something on a page that results in multiple matches being found. Highlight another word that is not currently highlighted. You should see both active and inactive highlights (orange and yellow) and a blue colored selection highlight. Review URL: http://codereview.chromium.org/66016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13510 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webframe_impl.cc38
-rw-r--r--webkit/glue/webframe_impl.h5
2 files changed, 31 insertions, 12 deletions
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 1c498cf..885b928 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -970,18 +970,26 @@ bool WebFrameImpl::Find(int request_id,
if (!options.findNext)
frame()->page()->unmarkAllTextMatches();
+ else
+ SetMarkerActive(active_match_.get(), false); // Active match is changing.
// Starts the search from the current selection.
bool start_in_selection = true;
+ // If the user has selected something since the last Find operation we want
+ // to start from there. Otherwise, we start searching from where the last Find
+ // operation left off (either a Find or a FindNext operation).
+ VisibleSelection selection(frame()->selection()->selection());
+ if (selection.isNone() && active_match_) {
+ selection = VisibleSelection(active_match_.get());
+ frame()->selection()->setSelection(selection);
+ }
+
DCHECK(frame() && frame()->view());
bool found = frame()->findString(webcore_string, options.forward,
options.matchCase, wrap_within_frame,
start_in_selection);
if (found) {
-#if defined(OS_WIN)
- WebCore::RenderThemeChromiumWin::setFindInPageMode(true);
-#endif
// Store which frame was active. This will come in handy later when we
// change the active match ordinal below.
WebFrameImpl* old_active_frame = main_frame_impl->active_match_frame_;
@@ -1003,6 +1011,8 @@ bool WebFrameImpl::Find(int request_id,
} else {
active_match_ = new_selection.toNormalizedRange();
curr_selection_rect = active_match_->boundingBox();
+ SetMarkerActive(active_match_.get(), true); // Active.
+ ClearSelection(); // WebKit draws the highlighting for all matches.
}
if (!options.findNext) {
@@ -1113,7 +1123,7 @@ void WebFrameImpl::InvalidateIfNecessary() {
}
}
-void WebFrameImpl::AddMarker(WebCore::Range* range) {
+void WebFrameImpl::AddMarker(WebCore::Range* range, bool active_match) {
// Use a TextIterator to visit the potentially multiple nodes the range
// covers.
TextIterator markedText(range);
@@ -1125,7 +1135,8 @@ void WebFrameImpl::AddMarker(WebCore::Range* range) {
WebCore::DocumentMarker::TextMatch,
textPiece->startOffset(exception),
textPiece->endOffset(exception),
- "" };
+ "",
+ active_match };
if (marker.endOffset > marker.startOffset) {
// Find the node to add a marker to and add it.
@@ -1146,6 +1157,13 @@ void WebFrameImpl::AddMarker(WebCore::Range* range) {
}
}
+void WebFrameImpl::SetMarkerActive(WebCore::Range* range, bool active) {
+ if (!range)
+ return;
+
+ frame()->document()->setMarkersActive(range, active);
+}
+
void WebFrameImpl::ScopeStringMatches(int request_id,
const string16& search_text,
const WebFindOptions& options,
@@ -1242,8 +1260,6 @@ void WebFrameImpl::ScopeStringMatches(int request_id,
if (frame()->editor()->insideVisibleArea(result_range.get())) {
++match_count;
- AddMarker(result_range.get());
-
setStart(search_range.get(), new_start);
Node* shadow_tree_root = search_range->shadowTreeRootNode();
if (search_range->collapsed(ec) && shadow_tree_root)
@@ -1264,9 +1280,11 @@ void WebFrameImpl::ScopeStringMatches(int request_id,
// match was found in active_selection_rect_ on the current frame. If we
// find this rect during scoping it means we have found the active
// tickmark.
+ bool found_active_match = false;
if (locating_active_rect_ && (active_selection_rect == result_bounds)) {
// We have found the active tickmark frame.
main_frame_impl->active_match_frame_ = this;
+ found_active_match = true;
// We also know which tickmark is active now.
active_match_index_ = match_count - 1;
// To stop looking for the active tickmark, we set this flag.
@@ -1284,6 +1302,8 @@ void WebFrameImpl::ScopeStringMatches(int request_id,
request_id);
#endif
}
+
+ AddMarker(result_range.get(), found_active_match);
}
resume_scoping_from_range_ = result_range;
@@ -1389,10 +1409,6 @@ void WebFrameImpl::StopFinding(bool clear_selection) {
SetFindEndstateFocusAndSelection();
CancelPendingScopingEffort();
-#if defined(OS_WIN)
- WebCore::RenderThemeChromiumWin::setFindInPageMode(false);
-#endif
-
// Remove all markers for matches found and turn off the highlighting.
if (this == static_cast<WebFrameImpl*>(GetView()->GetMainFrame()))
frame()->document()->removeMarkers(WebCore::DocumentMarker::TextMatch);
diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h
index 0d8b876..a80ee91 100644
--- a/webkit/glue/webframe_impl.h
+++ b/webkit/glue/webframe_impl.h
@@ -387,7 +387,10 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> {
void InvalidateArea(AreaToInvalidate area);
// Add a WebKit TextMatch-highlight marker to nodes in a range.
- void AddMarker(WebCore::Range* range);
+ void AddMarker(WebCore::Range* range, bool active_match);
+
+ // Sets the markers within a range as active or inactive.
+ void SetMarkerActive(WebCore::Range* range, bool active);
// Returns the ordinal of the first match in the frame specified. This
// function enumerates the frames, starting with the main frame and up to (but