<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[167519] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/167519">167519</a></dd>
<dt>Author</dt> <dd>alice.barraclough@webkit.org</dd>
<dt>Date</dt> <dd>2014-04-18 16:45:33 -0700 (Fri, 18 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Find on page - extend API by providing highlighted match index
https://bugs.webkit.org/show_bug.cgi?id=131776

Patch by Alice Barraclough &lt;alice.barraclough@webkit.org&gt; on 2014-04-18
Reviewed by Tim Horton.

* Shared/WebFindOptions.h: Add an option for determining match index.

Plumb through the API layers the addition of a parameter for match index.
* UIProcess/API/APIFindClient.h:
(API::FindClient::didFindString):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageFindClient):
* UIProcess/API/Cocoa/WKWebView.mm:
(toFindOptions):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
(NS_OPTIONS):
* UIProcess/API/Cocoa/_WKFindDelegate.h:
* UIProcess/Cocoa/FindClient.h:
* UIProcess/Cocoa/FindClient.mm:
(WebKit::FindClient::setDelegate):
(WebKit::FindClient::didFindString):
* UIProcess/WebFindClient.cpp:
(WebKit::WebFindClient::didFindString):
* UIProcess/WebFindClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didFindString):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

The actual tracking of the match index is contained in FindController class.
* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::FindController): Start out as -1, understood to be an undefined index in this context.
(WebKit::FindController::updateFindUIAfterPageScroll): 
    Perform the calculation of matchCount if the flag for DetermineMatchIndex is on.
If matchCount exceeds max, keep the match index undefined because otherwise the finding could advance
to a point where the index exceeds the match count, legitimately. If matchCount doesn't exceed the max, then make
sure the match index, which had been being incremented or decremented blindly back in findString(), is normalized
to be less than match count.
(WebKit::FindController::findString): 
    If there is a user selection existing on the page, the next occurence of the string will be found after that
selection. In that case we still want the index to properly reflect its ordinal  position within the entire document.
Use findStringMatchingRanges to provide the match index, and set a flag that prevents the match index from being
blindly incremented or decremented later. After findString() is actually called on the page, increment or decrement
the find index under specific conditions. 
(WebKit::FindController::hideFindIndicator): Reset match index when find UI goes away.
* WebProcess/WebPage/FindController.h: Add m_foundStringMatchIndex to private variables.
* WebProcess/WebPage/ios/FindControllerIOS.mm:
(WebKit::FindController::hideFindIndicator): Reset match index when find UI goes away.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedWebFindOptionsh">trunk/Source/WebKit2/Shared/WebFindOptions.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIAPIFindClienth">trunk/Source/WebKit2/UIProcess/API/APIFindClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagecpp">trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKFindDelegateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFindDelegate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaFindClienth">trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaFindClientmm">trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebFindClientcpp">trunk/Source/WebKit2/UIProcess/WebFindClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebFindClienth">trunk/Source/WebKit2/UIProcess/WebFindClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageFindControllercpp">trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageFindControllerh">trunk/Source/WebKit2/WebProcess/WebPage/FindController.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosFindControllerIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/FindControllerIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/ChangeLog        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -1,3 +1,54 @@
</span><ins>+2014-04-18  Alice Barraclough  &lt;alice.barraclough@webkit.org&gt;
+
+        Find on page - extend API by providing highlighted match index
+        https://bugs.webkit.org/show_bug.cgi?id=131776
+
+        Reviewed by Tim Horton.
+
+        * Shared/WebFindOptions.h: Add an option for determining match index.
+
+        Plumb through the API layers the addition of a parameter for match index.
+        * UIProcess/API/APIFindClient.h:
+        (API::FindClient::didFindString):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageFindClient):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (toFindOptions):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        (NS_OPTIONS):
+        * UIProcess/API/Cocoa/_WKFindDelegate.h:
+        * UIProcess/Cocoa/FindClient.h:
+        * UIProcess/Cocoa/FindClient.mm:
+        (WebKit::FindClient::setDelegate):
+        (WebKit::FindClient::didFindString):
+        * UIProcess/WebFindClient.cpp:
+        (WebKit::WebFindClient::didFindString):
+        * UIProcess/WebFindClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didFindString):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        The actual tracking of the match index is contained in FindController class.
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::FindController::FindController): Start out as -1, understood to be an undefined index in this context.
+        (WebKit::FindController::updateFindUIAfterPageScroll): 
+            Perform the calculation of matchCount if the flag for DetermineMatchIndex is on.
+        If matchCount exceeds max, keep the match index undefined because otherwise the finding could advance
+        to a point where the index exceeds the match count, legitimately. If matchCount doesn't exceed the max, then make
+        sure the match index, which had been being incremented or decremented blindly back in findString(), is normalized
+        to be less than match count.
+        (WebKit::FindController::findString): 
+            If there is a user selection existing on the page, the next occurence of the string will be found after that
+        selection. In that case we still want the index to properly reflect its ordinal  position within the entire document.
+        Use findStringMatchingRanges to provide the match index, and set a flag that prevents the match index from being
+        blindly incremented or decremented later. After findString() is actually called on the page, increment or decrement
+        the find index under specific conditions. 
+        (WebKit::FindController::hideFindIndicator): Reset match index when find UI goes away.
+        * WebProcess/WebPage/FindController.h: Add m_foundStringMatchIndex to private variables.
+        * WebProcess/WebPage/ios/FindControllerIOS.mm:
+        (WebKit::FindController::hideFindIndicator): Reset match index when find UI goes away.
+
</ins><span class="cx"> 2014-04-18  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Correct some issues small issues in WK2 file upload InjectedBundle APIs
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedWebFindOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/WebFindOptions.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/WebFindOptions.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/Shared/WebFindOptions.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -36,7 +36,8 @@
</span><span class="cx">     FindOptionsWrapAround = 1 &lt;&lt; 4,
</span><span class="cx">     FindOptionsShowOverlay = 1 &lt;&lt; 5,
</span><span class="cx">     FindOptionsShowFindIndicator = 1 &lt;&lt; 6,
</span><del>-    FindOptionsShowHighlight = 1 &lt;&lt; 7
</del><ins>+    FindOptionsShowHighlight = 1 &lt;&lt; 7,
+    FindOptionsDetermineMatchIndex = 1 &lt;&lt; 8,
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIAPIFindClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/APIFindClient.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/APIFindClient.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/API/APIFindClient.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx">     virtual ~FindClient() { }
</span><span class="cx"> 
</span><span class="cx">     virtual void didCountStringMatches(WebKit::WebPageProxy*, const WTF::String&amp;, uint32_t) { }
</span><del>-    virtual void didFindString(WebKit::WebPageProxy*, const WTF::String&amp;, uint32_t) { }
</del><ins>+    virtual void didFindString(WebKit::WebPageProxy*, const WTF::String&amp;, uint32_t, int32_t) { }
</ins><span class="cx">     virtual void didFailToFindString(WebKit::WebPageProxy*, const WTF::String&amp;) { }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -706,7 +706,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">     private:
</span><del>-        virtual void didFindString(WebPageProxy* page, const String&amp; string, uint32_t matchCount) override
</del><ins>+        virtual void didFindString(WebPageProxy* page, const String&amp; string, uint32_t matchCount, int32_t matchIndex) override
</ins><span class="cx">         {
</span><span class="cx">             if (!m_client.didFindString)
</span><span class="cx">                 return;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -1167,6 +1167,8 @@
</span><span class="cx">         findOptions |= WebKit::FindOptionsShowFindIndicator;
</span><span class="cx">     if (wkFindOptions &amp; _WKFindOptionsShowHighlight)
</span><span class="cx">         findOptions |= WebKit::FindOptionsShowHighlight;
</span><ins>+    if (wkFindOptions &amp; _WKFindOptionsDetermineMatchIndex)
+        findOptions |= WebKit::FindOptionsDetermineMatchIndex;
</ins><span class="cx"> 
</span><span class="cx">     return static_cast&lt;WebKit::FindOptions&gt;(findOptions);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx">     _WKFindOptionsShowOverlay = 1 &lt;&lt; 5,
</span><span class="cx">     _WKFindOptionsShowFindIndicator = 1 &lt;&lt; 6,
</span><span class="cx">     _WKFindOptionsShowHighlight = 1 &lt;&lt; 7,
</span><ins>+    _WKFindOptionsDetermineMatchIndex = 1 &lt;&lt; 8,
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> @class WKBrowsingContextHandle;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKFindDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFindDelegate.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFindDelegate.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFindDelegate.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -34,7 +34,7 @@
</span><span class="cx"> @optional
</span><span class="cx"> 
</span><span class="cx"> - (void)_webView:(WKWebView *)webView didCountMatches:(NSUInteger)matches forString:(NSString *)string;
</span><del>-- (void)_webView:(WKWebView *)webView didFindMatches:(NSUInteger)matches forString:(NSString *)string;
</del><ins>+- (void)_webView:(WKWebView *)webView didFindMatches:(NSUInteger)matches forString:(NSString *)string withMatchIndex:(NSInteger)matchIndex;
</ins><span class="cx"> - (void)_webView:(WKWebView *)webView didFailToFindString:(NSString *)string;
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaFindClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx"> private:
</span><span class="cx">     // From API::FindClient
</span><span class="cx">     virtual void didCountStringMatches(WebPageProxy*, const String&amp;, uint32_t matchCount);
</span><del>-    virtual void didFindString(WebPageProxy*, const String&amp;, uint32_t matchCount);
</del><ins>+    virtual void didFindString(WebPageProxy*, const String&amp;, uint32_t matchCount, int32_t matchIndex);
</ins><span class="cx">     virtual void didFailToFindString(WebPageProxy*, const String&amp;);
</span><span class="cx">     
</span><span class="cx">     WKWebView *m_webView;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaFindClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">     m_delegate = delegate;
</span><span class="cx"> 
</span><span class="cx">     m_delegateMethods.webviewDidCountStringMatches = [delegate respondsToSelector:@selector(_webView:didCountMatches:forString:)];
</span><del>-    m_delegateMethods.webviewDidFindString = [delegate respondsToSelector:@selector(_webView:didFindMatches:forString:)];
</del><ins>+    m_delegateMethods.webviewDidFindString = [delegate respondsToSelector:@selector(_webView:didFindMatches:forString:withMatchIndex:)];
</ins><span class="cx">     m_delegateMethods.webviewDidFailToFindString = [delegate respondsToSelector:@selector(_webView:didFailToFindString:)];
</span><span class="cx"> }
</span><span class="cx">     
</span><span class="lines">@@ -57,10 +57,10 @@
</span><span class="cx">         [m_delegate.get() _webView:m_webView didCountMatches:matchCount forString:string];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FindClient::didFindString(WebPageProxy*, const String&amp; string, uint32_t matchCount)
</del><ins>+void FindClient::didFindString(WebPageProxy*, const String&amp; string, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx"> {
</span><span class="cx">     if (m_delegateMethods.webviewDidFindString)
</span><del>-        [m_delegate.get() _webView:m_webView didFindMatches:matchCount forString:string];
</del><ins>+        [m_delegate.get() _webView:m_webView didFindMatches:matchCount forString:string withMatchIndex:matchIndex];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FindClient::didFailToFindString(WebPageProxy*, const String&amp; string)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebFindClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebFindClient.cpp (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebFindClient.cpp        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/WebFindClient.cpp        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -30,13 +30,12 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-void WebFindClient::didFindString(WebPageProxy* page, const String&amp; string, uint32_t matchCount)
</del><ins>+void WebFindClient::didFindString(WebPageProxy* page, const String&amp; string, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx"> {
</span><span class="cx">     if (!m_client.didFindString)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
</span><del>-
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebFindClient::didFailToFindString(WebPageProxy* page, const String&amp; string)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebFindClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebFindClient.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebFindClient.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/WebFindClient.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -49,7 +49,7 @@
</span><span class="cx"> 
</span><span class="cx"> class WebFindClient : public API::Client&lt;WKPageFindClientBase&gt; {
</span><span class="cx"> public:
</span><del>-    void didFindString(WebPageProxy*, const String&amp;, uint32_t matchCount);
</del><ins>+    void didFindString(WebPageProxy*, const String&amp;, uint32_t matchCount, int32_t matchIndex);
</ins><span class="cx">     void didFailToFindString(WebPageProxy*, const String&amp;);
</span><span class="cx">     void didCountStringMatches(WebPageProxy*, const String&amp;, uint32_t matchCount);
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -3276,9 +3276,9 @@
</span><span class="cx">     m_pageClient.setFindIndicator(findIndicator.release(), fadeOut, animate);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPageProxy::didFindString(const String&amp; string, uint32_t matchCount)
</del><ins>+void WebPageProxy::didFindString(const String&amp; string, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx"> {
</span><del>-    m_findClient-&gt;didFindString(this, string, matchCount);
</del><ins>+    m_findClient-&gt;didFindString(this, string, matchCount, matchIndex);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::didFindStringMatches(const String&amp; string, Vector&lt;Vector&lt;WebCore::IntRect&gt;&gt; matchRects, int32_t firstIndexAfterSelection)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -819,7 +819,7 @@
</span><span class="cx">     void countStringMatches(const String&amp;, FindOptions, unsigned maxMatchCount);
</span><span class="cx">     void didCountStringMatches(const String&amp;, uint32_t matchCount);
</span><span class="cx">     void setFindIndicator(const WebCore::FloatRect&amp; selectionRectInWindowCoordinates, const Vector&lt;WebCore::FloatRect&gt;&amp; textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle&amp; contentImageHandle, bool fadeOut, bool animate);
</span><del>-    void didFindString(const String&amp;, uint32_t matchCount);
</del><ins>+    void didFindString(const String&amp;, uint32_t matchCount, int32_t matchIndex);
</ins><span class="cx">     void didFailToFindString(const String&amp;);
</span><span class="cx">     void didFindStringMatches(const String&amp;, Vector&lt;Vector&lt;WebCore::IntRect&gt;&gt; matchRects, int32_t firstIndexAfterSelection);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -209,7 +209,7 @@
</span><span class="cx">     # Find messages
</span><span class="cx">     DidCountStringMatches(String string, uint32_t matchCount)
</span><span class="cx">     SetFindIndicator(WebCore::FloatRect selectionRect, Vector&lt;WebCore::FloatRect&gt; textRects, float contentImageScaleFactor, WebKit::ShareableBitmap::Handle contentImageHandle, bool fadeOut, bool animate)
</span><del>-    DidFindString(String string, uint32_t matchCount)
</del><ins>+    DidFindString(String string, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx">     DidFailToFindString(String string)
</span><span class="cx">     DidFindStringMatches(String string, Vector&lt;Vector&lt;WebCore::IntRect&gt;&gt; matches, int32_t firstIndexAfterSelection)
</span><span class="cx">     DidGetImageForFindMatch(WebKit::ShareableBitmap::Handle contentImageHandle, uint32_t matchIndex)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageFindControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">     : m_webPage(webPage)
</span><span class="cx">     , m_findPageOverlay(0)
</span><span class="cx">     , m_isShowingFindIndicator(false)
</span><ins>+    , m_foundStringMatchIndex(-1)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -129,14 +130,23 @@
</span><span class="cx">     } else {
</span><span class="cx">         shouldShowOverlay = options &amp; FindOptionsShowOverlay;
</span><span class="cx">         bool shouldShowHighlight = options &amp; FindOptionsShowHighlight;
</span><ins>+        bool shouldDetermineMatchIndex = options &amp; FindOptionsDetermineMatchIndex;
</ins><span class="cx">         unsigned matchCount = 1;
</span><span class="cx"> 
</span><ins>+        if (shouldDetermineMatchIndex) {
+            if (pluginView)
+                matchCount = pluginView-&gt;countFindMatches(string, core(options), maxMatchCount + 1);
+            else
+                matchCount = m_webPage-&gt;corePage()-&gt;countFindMatches(string, core(options), maxMatchCount + 1);
+        }
+
</ins><span class="cx">         if (shouldShowOverlay || shouldShowHighlight) {
</span><span class="cx">             if (maxMatchCount == std::numeric_limits&lt;unsigned&gt;::max())
</span><span class="cx">                 --maxMatchCount;
</span><span class="cx"> 
</span><span class="cx">             if (pluginView) {
</span><del>-                matchCount = pluginView-&gt;countFindMatches(string, core(options), maxMatchCount + 1);
</del><ins>+                if (!shouldDetermineMatchIndex)
+                    matchCount = pluginView-&gt;countFindMatches(string, core(options), maxMatchCount + 1);
</ins><span class="cx">                 shouldShowOverlay = false;
</span><span class="cx">             } else {
</span><span class="cx">                 m_webPage-&gt;corePage()-&gt;unmarkAllTextMatches();
</span><span class="lines">@@ -149,8 +159,16 @@
</span><span class="cx">                 matchCount = static_cast&lt;unsigned&gt;(kWKMoreThanMaximumMatchCount);
</span><span class="cx">             }
</span><span class="cx">         }
</span><ins>+        if (matchCount == static_cast&lt;unsigned&gt;(kWKMoreThanMaximumMatchCount))
+            m_foundStringMatchIndex = -1;
+        else {
+            if (m_foundStringMatchIndex &lt; 0)
+                m_foundStringMatchIndex += matchCount;
+            if (m_foundStringMatchIndex &gt;= (int) matchCount)
+                m_foundStringMatchIndex -= matchCount;
+        }
</ins><span class="cx"> 
</span><del>-        m_webPage-&gt;send(Messages::WebPageProxy::DidFindString(string, matchCount));
</del><ins>+        m_webPage-&gt;send(Messages::WebPageProxy::DidFindString(string, matchCount, m_foundStringMatchIndex));
</ins><span class="cx"> 
</span><span class="cx">         if (!(options &amp; FindOptionsShowFindIndicator) || !selectedFrame || !updateFindIndicator(*selectedFrame, shouldShowOverlay))
</span><span class="cx">             hideFindIndicator();
</span><span class="lines">@@ -184,12 +202,33 @@
</span><span class="cx"> 
</span><span class="cx">     willFindString();
</span><span class="cx"> 
</span><ins>+    bool foundStringStartsAfterSelection = false;
+    if (!pluginView) {
+        if (Frame* selectedFrame = frameWithSelection(m_webPage-&gt;corePage())) {
+            FrameSelection&amp; fs = selectedFrame-&gt;selection();
+            if (fs.selectionBounds().isEmpty()) {
+                m_findMatches.clear();
+                int indexForSelection;
+                m_webPage-&gt;corePage()-&gt;findStringMatchingRanges(string, core(options), maxMatchCount, &amp;m_findMatches, indexForSelection);
+                m_foundStringMatchIndex = indexForSelection;
+                foundStringStartsAfterSelection = true;
+            }
+        }
+    }
+
</ins><span class="cx">     bool found;
</span><span class="cx">     if (pluginView)
</span><span class="cx">         found = pluginView-&gt;findString(string, coreOptions, maxMatchCount);
</span><span class="cx">     else
</span><span class="cx">         found = m_webPage-&gt;corePage()-&gt;findString(string, coreOptions);
</span><span class="cx"> 
</span><ins>+    if (found &amp;&amp; !foundStringStartsAfterSelection) {
+        if (options &amp; FindOptionsBackwards)
+            m_foundStringMatchIndex--;
+        else
+            m_foundStringMatchIndex++;
+    }
+
</ins><span class="cx">     m_webPage-&gt;drawingArea()-&gt;dispatchAfterEnsuringUpdatedScrollPosition(WTF::bind(&amp;FindController::updateFindUIAfterPageScroll, this, found, string, options, maxMatchCount));
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -334,6 +373,7 @@
</span><span class="cx">     ShareableBitmap::Handle handle;
</span><span class="cx">     m_webPage-&gt;send(Messages::WebPageProxy::SetFindIndicator(FloatRect(), Vector&lt;FloatRect&gt;(), m_webPage-&gt;corePage()-&gt;deviceScaleFactor(), handle, false, true));
</span><span class="cx">     m_isShowingFindIndicator = false;
</span><ins>+    m_foundStringMatchIndex = -1;
</ins><span class="cx">     didHideFindIndicator();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageFindControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.h (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.h        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.h        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -95,6 +95,8 @@
</span><span class="cx">     bool m_isShowingFindIndicator;
</span><span class="cx">     WebCore::IntRect m_findIndicatorRect;
</span><span class="cx">     Vector&lt;RefPtr&lt;WebCore::Range&gt;&gt; m_findMatches;
</span><ins>+    // Index value is -1 if not found or if number of matches exceeds provided maximum.
+    int m_foundStringMatchIndex;
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     RefPtr&lt;PageOverlay&gt; m_findIndicatorOverlay;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosFindControllerIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/FindControllerIOS.mm (167518 => 167519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/FindControllerIOS.mm        2014-04-18 23:30:58 UTC (rev 167518)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/FindControllerIOS.mm        2014-04-18 23:45:33 UTC (rev 167519)
</span><span class="lines">@@ -109,7 +109,7 @@
</span><span class="cx">     m_webPage-&gt;uninstallPageOverlay(m_findIndicatorOverlay.get());
</span><span class="cx">     m_findIndicatorOverlay = nullptr;
</span><span class="cx">     m_isShowingFindIndicator = false;
</span><del>-
</del><ins>+    m_foundStringMatchIndex = -1;
</ins><span class="cx">     didHideFindIndicator();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>