Incorrect foreignObject hit test results when overlapping other SVG elements
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Mar 2012 21:00:37 +0000 (21:00 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Mar 2012 21:00:37 +0000 (21:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82059

Patch by Florin Malita <fmalita@google.com> on 2012-03-28
Reviewed by Nikolas Zimmermann.

Source/WebCore:

Test: svg/hittest/foreign-object-background.svg

Foreign content needs to be hit-tested atomically due to the (pseudo)
stacking context established by FOs.

* rendering/svg/RenderSVGForeignObject.cpp:
(WebCore::RenderSVGForeignObject::nodeAtFloatPoint):
Hit test all phases on FO HitTestForeground.

LayoutTests:

* svg/hittest/foreign-object-background-expected.txt: Added.
* svg/hittest/foreign-object-background.svg: Added.

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

LayoutTests/ChangeLog
LayoutTests/svg/hittest/foreign-object-background-expected.txt [new file with mode: 0644]
LayoutTests/svg/hittest/foreign-object-background.svg [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/svg/RenderSVGForeignObject.cpp

index a74aa75..ed16a3b 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-28  Florin Malita  <fmalita@google.com>
+
+        Incorrect foreignObject hit test results when overlapping other SVG elements
+        https://bugs.webkit.org/show_bug.cgi?id=82059
+
+        Reviewed by Nikolas Zimmermann.
+
+        * svg/hittest/foreign-object-background-expected.txt: Added.
+        * svg/hittest/foreign-object-background.svg: Added.
+
 2012-03-26  Shawn Singh  <shawnsingh@chromium.org>
 
         [chromium] layer->clipRect() is not initialized for layers that create a renderSurface.
diff --git a/LayoutTests/svg/hittest/foreign-object-background-expected.txt b/LayoutTests/svg/hittest/foreign-object-background-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/svg/hittest/foreign-object-background.svg b/LayoutTests/svg/hittest/foreign-object-background.svg
new file mode 100644 (file)
index 0000000..80ce9ee
--- /dev/null
@@ -0,0 +1,23 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+  <rect width="100" height="100" fill="red" onclick="window.alert('FAIL: click not sent to FO content.');"/>
+  <foreignObject width="100" height="100">
+    <body xmlns="http://www.w3.org/1999/xhtml" style="margin: 0; padding: 0;">
+      <!-- Clicking on the green div (background) should be dispatched to the div element and not to the red SVG rect underneath. -->
+      <div id="target" style="width: 100px; height: 100px; background-color:green;" onclick="window.alert('PASS: click sent to FO content.');"></div>
+    </body>
+  </foreignObject>
+
+  <script><![CDATA[
+
+    if (window.layoutTestController) {
+      layoutTestController.dumpAsText();
+
+      var hitElement = document.elementFromPoint(50, 50);
+      var hitSuccess = hitElement && hitElement == document.getElementById("target");
+      document.getElementById('target').innerHTML = hitSuccess ? 'PASS' : 'FAIL';
+    } else {
+      document.getElementById('target').innerHTML = 'Click me.';
+    }
+  ]]></script>
+</svg>
+
index 7662d82..b44d978 100644 (file)
@@ -1,3 +1,19 @@
+2012-03-28  Florin Malita  <fmalita@google.com>
+
+        Incorrect foreignObject hit test results when overlapping other SVG elements
+        https://bugs.webkit.org/show_bug.cgi?id=82059
+
+        Reviewed by Nikolas Zimmermann.
+
+        Test: svg/hittest/foreign-object-background.svg
+
+        Foreign content needs to be hit-tested atomically due to the (pseudo)
+        stacking context established by FOs.
+
+        * rendering/svg/RenderSVGForeignObject.cpp:
+        (WebCore::RenderSVGForeignObject::nodeAtFloatPoint):
+        Hit test all phases on FO HitTestForeground.
+
 2012-03-26  Shawn Singh  <shawnsingh@chromium.org>
 
         [chromium] layer->clipRect() is not initialized for layers that create a renderSurface.
index 676e8f4..8693b13 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "GraphicsContext.h"
 #include "LayoutRepainter.h"
+#include "RenderObject.h"
 #include "RenderSVGResource.h"
 #include "RenderView.h"
 #include "SVGForeignObjectElement.h"
@@ -165,13 +166,20 @@ void RenderSVGForeignObject::layout()
 
 bool RenderSVGForeignObject::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
 {
+    // Embedded content is drawn in the foreground phase.
+    if (hitTestAction != HitTestForeground)
+        return false;
+
     FloatPoint localPoint = localTransform().inverse().mapPoint(pointInParent);
 
     // Early exit if local point is not contained in clipped viewport area
     if (SVGRenderSupport::isOverflowHidden(this) && !m_viewport.contains(localPoint))
         return false;
 
-    return RenderBlock::nodeAtPoint(request, result, roundedLayoutPoint(localPoint), LayoutPoint(), hitTestAction);
+    // FOs establish a stacking context, so we need to hit-test all layers.
+    return RenderBlock::nodeAtPoint(request, result, roundedLayoutPoint(localPoint), LayoutPoint(), HitTestForeground)
+        || RenderBlock::nodeAtPoint(request, result, roundedLayoutPoint(localPoint), LayoutPoint(), HitTestFloat)
+        || RenderBlock::nodeAtPoint(request, result, roundedLayoutPoint(localPoint), LayoutPoint(), HitTestChildBlockBackgrounds);
 }
 
 bool RenderSVGForeignObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint&, const LayoutPoint&, HitTestAction)