Title: [151607] trunk
Revision
151607
Author
[email protected]
Date
2013-06-14 15:21:13 -0700 (Fri, 14 Jun 2013)

Log Message

WKPageFindStringMatches ignores the kWKFindOptionsBackwards option.
https://bugs.webkit.org/show_bug.cgi?id=117647
<rdar://problem/13881024>

Source/WebCore: 

Reviewed by Darin Adler.
        
The API returns the matched ranges in the DOM order regardless of the
find direction, but the index of the first match after the user selection
should take the find direction into account.

Extended existing test in TestWebKitAPI.

* page/Page.cpp:
(WebCore::Page::findStringMatchingRanges): Added handling of the Backwards case.
* page/Page.h: Fixed incorrect name of the enum.

Source/WebKit2: 

Reviewed by Darin Adler.
        
The API returns the matched ranges in the DOM order regardless of the
find direction, but the index of the first match after the user selection
should take the find direction into account.

Extended existing test in TestWebKitAPI.

* Shared/API/c/WKFindOptions.h: Added enum for the case where there are
no matches after the user selection in the direction of the find.

Tools: 

Reviewed by Darin Adler.
        
The test now uses content with a selection and tests both
forwards and backward find as well as the case of a find
that has no matches after the user selection.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/FindMatches.mm:
(TestWebKitAPI::didFindStringMatches):
* TestWebKitAPI/Tests/WebKit2/findRanges.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (151606 => 151607)


--- trunk/Source/WebCore/ChangeLog	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Source/WebCore/ChangeLog	2013-06-14 22:21:13 UTC (rev 151607)
@@ -1,3 +1,21 @@
+2013-06-14  Enrica Casucci  <[email protected]>
+
+        WKPageFindStringMatches ignores the kWKFindOptionsBackwards option.
+        https://bugs.webkit.org/show_bug.cgi?id=117647
+        <rdar://problem/13881024>
+
+        Reviewed by Darin Adler.
+        
+        The API returns the matched ranges in the DOM order regardless of the
+        find direction, but the index of the first match after the user selection
+        should take the find direction into account.
+
+        Extended existing test in TestWebKitAPI.
+
+        * page/Page.cpp:
+        (WebCore::Page::findStringMatchingRanges): Added handling of the Backwards case.
+        * page/Page.h: Fixed incorrect name of the enum.
+
 2013-06-14  Jer Noble  <[email protected]>
 
         REGRESSION (r150651): Web Audio doesn't work at all (silence or squawks) on Mountain Lion

Modified: trunk/Source/WebCore/page/Page.cpp (151606 => 151607)


--- trunk/Source/WebCore/page/Page.cpp	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Source/WebCore/page/Page.cpp	2013-06-14 22:21:13 UTC (rev 151607)
@@ -609,13 +609,22 @@
         return;
 
     if (frameWithSelection) {
-        indexForSelection = NoMatchBeforeUserSelection;
+        indexForSelection = NoMatchAfterUserSelection;
         RefPtr<Range> selectedRange = frameWithSelection->selection()->selection().firstRange();
-        for (size_t i = 0; i < matchRanges->size(); ++i) {
-            if (selectedRange->compareBoundaryPoints(Range::START_TO_END, matchRanges->at(i).get(), IGNORE_EXCEPTION) < 0) {
-                indexForSelection = i;
-                break;
+        if (options & Backwards) {
+            for (size_t i = matchRanges->size(); i > 0; --i) {
+                if (selectedRange->compareBoundaryPoints(Range::START_TO_END, matchRanges->at(i - 1).get(), IGNORE_EXCEPTION) > 0) {
+                    indexForSelection = i - 1;
+                    break;
+                }
             }
+        } else {
+            for (size_t i = 0; i < matchRanges->size(); ++i) {
+                if (selectedRange->compareBoundaryPoints(Range::START_TO_END, matchRanges->at(i).get(), IGNORE_EXCEPTION) < 0) {
+                    indexForSelection = i;
+                    break;
+                }
+            }
         }
     }
 }

Modified: trunk/Source/WebCore/page/Page.h (151606 => 151607)


--- trunk/Source/WebCore/page/Page.h	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Source/WebCore/page/Page.h	2013-06-14 22:21:13 UTC (rev 151607)
@@ -246,8 +246,8 @@
     // Upon return, indexForSelection will be one of the following:
     // 0 if there is no user selection
     // the index of the first range after the user selection
-    // NoMatchBeforeUserSelection if there is no matching text after the user selection.
-    enum { NoMatchBeforeUserSelection = -1 };
+    // NoMatchAfterUserSelection if there is no matching text after the user selection.
+    enum { NoMatchAfterUserSelection = -1 };
     void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range> >*, int& indexForSelection);
 #if PLATFORM(MAC)
     void addSchedulePair(PassRefPtr<SchedulePair>);

Modified: trunk/Source/WebKit2/ChangeLog (151606 => 151607)


--- trunk/Source/WebKit2/ChangeLog	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Source/WebKit2/ChangeLog	2013-06-14 22:21:13 UTC (rev 151607)
@@ -1,3 +1,20 @@
+2013-06-14  Enrica Casucci  <[email protected]>
+
+        WKPageFindStringMatches ignores the kWKFindOptionsBackwards option.
+        https://bugs.webkit.org/show_bug.cgi?id=117647
+        <rdar://problem/13881024>
+
+        Reviewed by Darin Adler.
+        
+        The API returns the matched ranges in the DOM order regardless of the
+        find direction, but the index of the first match after the user selection
+        should take the find direction into account.
+
+        Extended existing test in TestWebKitAPI.
+
+        * Shared/API/c/WKFindOptions.h: Added enum for the case where there are
+        no matches after the user selection in the direction of the find.
+
 2013-06-14  Andres Gomez  <[email protected]>
 
         [GTK] Compilation problems - hb.h not found

Modified: trunk/Source/WebKit2/Shared/API/c/WKFindOptions.h (151606 => 151607)


--- trunk/Source/WebKit2/Shared/API/c/WKFindOptions.h	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Source/WebKit2/Shared/API/c/WKFindOptions.h	2013-06-14 22:21:13 UTC (rev 151607)
@@ -42,6 +42,8 @@
 };
 typedef uint32_t WKFindOptions;
 
+enum { kWKFindResultNoMatchAfterUserSelection = -1 };
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Tools/ChangeLog (151606 => 151607)


--- trunk/Tools/ChangeLog	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Tools/ChangeLog	2013-06-14 22:21:13 UTC (rev 151607)
@@ -1,3 +1,20 @@
+2013-06-14  Enrica Casucci  <[email protected]>
+
+        WKPageFindStringMatches ignores the kWKFindOptionsBackwards option.
+        https://bugs.webkit.org/show_bug.cgi?id=117647
+        <rdar://problem/13881024>
+
+        Reviewed by Darin Adler.
+        
+        The test now uses content with a selection and tests both
+        forwards and backward find as well as the case of a find
+        that has no matches after the user selection.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/FindMatches.mm:
+        (TestWebKitAPI::didFindStringMatches):
+        * TestWebKitAPI/Tests/WebKit2/findRanges.html: Added.
+
 2013-06-14  Tor Arne Vestbø  <[email protected]>
 
         Remove myself from Qt build system watchlist

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (151606 => 151607)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2013-06-14 22:21:13 UTC (rev 151607)
@@ -195,6 +195,7 @@
 		C2CF975B16CEC71B0054E99D /* JSContextBackForwardCache1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C2CF975816CEC69E0054E99D /* JSContextBackForwardCache1.html */; };
 		C2EB2DD316CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2EB2DD116CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm */; };
 		C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */ = {isa = PBXBuildFile; fileRef = C507E8A614C6545B005D6B3B /* InspectorBar.mm */; };
+		C5101C4F176B8D9200EE9B15 /* findRanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C5101C4E176B8BB900EE9B15 /* findRanges.html */; };
 		C51AFB99169F49FF009CCF66 /* FindMatches.mm in Sources */ = {isa = PBXBuildFile; fileRef = C51AFB98169F49FF009CCF66 /* FindMatches.mm */; };
 		C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */ = {isa = PBXBuildFile; fileRef = C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */; };
 		C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C540F783152E5A7800A40C8C /* verboseMarkup.html */; };
@@ -265,6 +266,7 @@
 				37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */,
 				C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */,
 				BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */,
+				C5101C4F176B8D9200EE9B15 /* findRanges.html in Copy Resources */,
 				1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */,
 				9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */,
 				9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */,
@@ -502,6 +504,7 @@
 		C2CF975916CEC69E0054E99D /* JSContextBackForwardCache2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = JSContextBackForwardCache2.html; sourceTree = "<group>"; };
 		C2EB2DD116CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewDidCreateJavaScriptContext.mm; sourceTree = "<group>"; };
 		C507E8A614C6545B005D6B3B /* InspectorBar.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InspectorBar.mm; sourceTree = "<group>"; };
+		C5101C4E176B8BB900EE9B15 /* findRanges.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = findRanges.html; sourceTree = "<group>"; };
 		C51AFB98169F49FF009CCF66 /* FindMatches.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindMatches.mm; sourceTree = "<group>"; };
 		C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimplifyMarkup.mm; sourceTree = "<group>"; };
 		C540F783152E5A7800A40C8C /* verboseMarkup.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = verboseMarkup.html; sourceTree = "<group>"; };
@@ -797,6 +800,7 @@
 				C5E1AFFD16B22179006CC1F2 /* execCopy.html */,
 				BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */,
 				1A02C84B125D4A5E00E3F4BD /* find.html */,
+				C5101C4E176B8BB900EE9B15 /* findRanges.html */,
 				BCBD372E125ABBE600D2C29F /* icon.png */,
 				378E647816326FDF00B6C676 /* link-with-title.html */,
 				9361002814DC957B0061379D /* lots-of-iframes.html */,
@@ -1006,6 +1010,8 @@
 /* Begin PBXProject section */
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
+			attributes = {
+			};
 			buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "TestWebKitAPI" */;
 			compatibilityVersion = "Xcode 3.1";
 			developmentRegion = English;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/FindMatches.mm (151606 => 151607)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/FindMatches.mm	2013-06-14 21:55:48 UTC (rev 151606)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/FindMatches.mm	2013-06-14 22:21:13 UTC (rev 151607)
@@ -51,6 +51,7 @@
 static bool didFinishLoad = false;
 static bool didCallFindStringMatches = false;
 static bool didCallGetImage = false;
+static WKFindOptions findOptions = kWKFindOptionsAtWordStarts;
 
 RetainPtr<WebView> webkit1View;
 
@@ -61,22 +62,32 @@
 
 static void didFindStringMatches(WKPageRef page, WKStringRef string, WKArrayRef matches, int firstIndex, const void* clientInfo)
 {
-    EXPECT_WK_STREQ("Hello", string);
-    size_t numMatches = WKArrayGetSize(matches);
-    EXPECT_EQ(3u, numMatches);
+    if (WKStringIsEqualToUTF8CString(string, "Hello")) {
+        size_t numMatches = WKArrayGetSize(matches);
+        EXPECT_EQ(3u, numMatches);
 
-    for (size_t i = 0; i < numMatches; ++i) {
-        WKTypeRef items = WKArrayGetItemAtIndex(matches, i);
-        WKTypeID type = WKGetTypeID(items);
-        EXPECT_EQ(type, WKArrayGetTypeID());
-        WKArrayRef rects = reinterpret_cast<WKArrayRef>(items);
-        size_t numRects = WKArrayGetSize(rects);
-        EXPECT_EQ(1u, numRects);
-        items = WKArrayGetItemAtIndex(rects, 0);
-        type = WKGetTypeID(items);
-        EXPECT_EQ(type, WKRectGetTypeID());
-        WKRect rect = WKRectGetValue(reinterpret_cast<WKRectRef>(items));
-        rect = rect;
+        if (findOptions & kWKFindOptionsBackwards)
+            EXPECT_EQ(1, firstIndex);
+        else
+            EXPECT_EQ(2, firstIndex);
+
+        for (size_t i = 0; i < numMatches; ++i) {
+            WKTypeRef items = WKArrayGetItemAtIndex(matches, i);
+            WKTypeID type = WKGetTypeID(items);
+            EXPECT_EQ(type, WKArrayGetTypeID());
+            WKArrayRef rects = reinterpret_cast<WKArrayRef>(items);
+            size_t numRects = WKArrayGetSize(rects);
+            EXPECT_EQ(1u, numRects);
+            items = WKArrayGetItemAtIndex(rects, 0);
+            type = WKGetTypeID(items);
+            EXPECT_EQ(type, WKRectGetTypeID());
+            WKRect rect = WKRectGetValue(reinterpret_cast<WKRectRef>(items));
+            rect = rect;
+        }
+    } else if (WKStringIsEqualToUTF8CString(string, "crazy")) {
+        size_t numMatches = WKArrayGetSize(matches);
+        EXPECT_EQ(1u, numMatches);
+        EXPECT_EQ(kWKFindResultNoMatchAfterUserSelection, firstIndex);
     }
     didCallFindStringMatches = true;
 }
@@ -117,16 +128,23 @@
 
     WKPageSetPageFindMatchesClient(webView.page(), &findMatchesClient);
 
-    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("find", "html"));
+    // This HTML file contains 3 occurrences of the word Hello and has the second occurence of the word 'world' selected.
+    // It contains 1 occurrence of the word 'crazy' that is before the selected word.
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("findRanges", "html"));
     WKPageLoadURL(webView.page(), url.get());
 
     Util::run(&didFinishLoad);
 
     WKRetainPtr<WKStringRef> findString(AdoptWK, WKStringCreateWithUTF8CString("Hello"));
- 
-    WKPageFindStringMatches(webView.page(), findString.get(), true, 100);
+
+    WKPageFindStringMatches(webView.page(), findString.get(), findOptions, 100);
     Util::run(&didCallFindStringMatches);
 
+    didCallFindStringMatches = false;
+    findOptions |= kWKFindOptionsBackwards;
+    WKPageFindStringMatches(webView.page(), findString.get(), findOptions, 100);
+    Util::run(&didCallFindStringMatches);
+
     webkit1View = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
     RetainPtr<FindMatchesWK1FrameLoadDelegate> frameLoadDelegate = adoptNS([FindMatchesWK1FrameLoadDelegate new]);
 
@@ -138,6 +156,12 @@
     WKPageGetImageForFindMatch(webView.page(), 0);
     Util::run(&didCallGetImage);
 
+    didCallFindStringMatches = false;
+    findOptions &= ~kWKFindOptionsBackwards;
+    WKRetainPtr<WKStringRef> findOtherString(AdoptWK, WKStringCreateWithUTF8CString("crazy"));
+    WKPageFindStringMatches(webView.page(), findOtherString.get(), findOptions, 100);
+    Util::run(&didCallFindStringMatches);
+
     WKPageHideFindUI(webView.page());
 }
 

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/findRanges.html (0 => 151607)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/findRanges.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/findRanges.html	2013-06-14 22:21:13 UTC (rev 151607)
@@ -0,0 +1,11 @@
+<html>
+<body>Test search. Hello world, Hello crazy world, Hello!</body>
+<script>
+    var s = window.getSelection();
+    var r = document.createRange();
+
+    r.setStart(document.body.firstChild, 38);
+    r.setEnd(document.body.firstChild, 43);
+    s.addRange(r);
+</script>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to