Reviewed by eseidel.
authorrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Sep 2006 17:08:39 +0000 (17:08 +0000)
committerrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Sep 2006 17:08:39 +0000 (17:08 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=11096
        Hit testing for polylines fails

        Fix Path::contains so it handles filled, non-closed paths too.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16688 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/svg/custom/polyline-hittest-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/polyline-hittest-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/polyline-hittest-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/polyline-hittest.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/platform/cg/PathCG.cpp

index 9f32c6775119d6041263416764368f64c174a269..29f9439b4339c2d8caff942cb19c77ad8b6a9149 100644 (file)
@@ -1,3 +1,16 @@
+2006-09-30  Rob Buis  <buis@kde.org>
+
+        Reviewed by eseidel.
+
+        Testcase for:
+        http://bugs.webkit.org/show_bug.cgi?id=11096
+        Hit testing for polylines fails
+
+        * svg/custom/polyline-hittest-expected.checksum: Added.
+        * svg/custom/polyline-hittest-expected.png: Added.
+        * svg/custom/polyline-hittest-expected.txt: Added.
+        * svg/custom/polyline-hittest.svg: Added.
+
 2006-09-29  Timothy Hatcher  <timothy@apple.com>
 
         Bug 11041: fast/dom/isindex-001 needs new results
diff --git a/LayoutTests/svg/custom/polyline-hittest-expected.checksum b/LayoutTests/svg/custom/polyline-hittest-expected.checksum
new file mode 100644 (file)
index 0000000..3a4f1f7
--- /dev/null
@@ -0,0 +1 @@
+16310588467cfc20d551635abc59b784
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/polyline-hittest-expected.png b/LayoutTests/svg/custom/polyline-hittest-expected.png
new file mode 100644 (file)
index 0000000..3db2634
Binary files /dev/null and b/LayoutTests/svg/custom/polyline-hittest-expected.png differ
diff --git a/LayoutTests/svg/custom/polyline-hittest-expected.txt b/LayoutTests/svg/custom/polyline-hittest-expected.txt
new file mode 100644 (file)
index 0000000..3561f49
--- /dev/null
@@ -0,0 +1,5 @@
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:(null) affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+    KCanvasContainer {svg} at (0,0) size 100x100
+      KCanvasItem {polyline} at (0,0) size 100x100 [fill={[type=SOLID] [color=#008000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
diff --git a/LayoutTests/svg/custom/polyline-hittest.svg b/LayoutTests/svg/custom/polyline-hittest.svg
new file mode 100644 (file)
index 0000000..a1b64b8
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" onload="click()">
+  <script type="text/javascript">
+  <![CDATA[
+    
+    if (window.layoutTestController)
+        layoutTestController.waitUntilDone();
+   function changeFill(evt) { 
+       var poly = evt.target;
+       poly.setAttribute("fill", "green");
+   }
+
+   function click() { 
+        if (window.eventSender) {
+            // Fill click
+            eventSender.mouseMoveTo(25, 25);
+            eventSender.mouseDown();
+            eventSender.mouseUp();
+        }
+    }
+      
+    if (window.layoutTestController)
+      layoutTestController.notifyDone();
+  ]]>
+  </script>
+
+  <polyline onclick="changeFill(evt);" points="0 0 100 0 100 100 0 100" fill="red"/>  
+</svg>
index 904b0dea02fad9e9619cc9e83971f6170d08704f..13f401e3e1942f267ef4933c9db1df70390cf4d2 100644 (file)
@@ -1,3 +1,15 @@
+2006-09-30  Rob Buis  <buis@kde.org>
+
+        Reviewed by eseidel.
+
+        http://bugs.webkit.org/show_bug.cgi?id=11096
+        Hit testing for polylines fails
+
+        Fix Path::contains so it handles filled, non-closed paths too.
+
+        * platform/cg/PathCG.cpp:
+        (WebCore::Path::contains):
+
 2006-09-30  Dave Hyatt  <hyatt@apple.com>
 
         Refactor subframe event handling to hide more of the Mac-specific logic from the cross-platform code.
index 6f3964572ca202ab78a5a5b0df451e39a45aa3b6..f741eead81c7247898fafb1ffbe828e7cfc1c9d3 100644 (file)
 
 #if PLATFORM(CG)
 
-#include "FloatRect.h"
-#include "PlatformString.h"
 #include "AffineTransform.h"
 #include <ApplicationServices/ApplicationServices.h>
+#include "FloatRect.h"
+#include "IntRect.h"
+#include "PlatformString.h"
 
 namespace WebCore {
 
@@ -61,7 +62,15 @@ Path& Path::operator=(const Path& other)
 
 bool Path::contains(const FloatPoint &point, WindRule rule) const
 {
-    return CGPathContainsPoint(m_path, 0, point, rule == RULE_EVENODD ? true : false);
+    // CGPathContainsPoint returns false for non-closed paths, as a work-around, we copy and close the path first.  Radar 4758998 asks for a better CG API to use
+    if (!enclosingIntRect(boundingRect()).contains(point.x(), point.y()))
+        return false;
+
+    CGMutablePathRef path = CGPathCreateMutableCopy(m_path);
+    CGPathCloseSubpath(path);
+    bool ret = CGPathContainsPoint(path, 0, point, rule == RULE_EVENODD ? true : false);
+    CGPathRelease(path);
+    return ret;
 }
 
 void Path::translate(const FloatSize& size)