Title: [122339] trunk
Revision
122339
Author
[email protected]
Date
2012-07-11 10:09:03 -0700 (Wed, 11 Jul 2012)

Log Message

NodesFromRect doesn't work on SVG root elements.
https://bugs.webkit.org/show_bug.cgi?id=89990

Reviewed by Antonio Gomes.

Source/WebCore:

Adds support for rect-based hit-testing on the SVG root element.
This means that while rect-based hit-testing is still not supported
within SVG elements, that at least it works on SVG root elements as
it would on any other replaced element.

Test: fast/dom/nodesFromRect-svg.html

* rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::nodeAtPoint):

LayoutTests:

Test nodesFromRect on SVG root elements.

* fast/dom/nodesFromRect-svg-expected.txt: Added.
* fast/dom/nodesFromRect-svg.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (122338 => 122339)


--- trunk/LayoutTests/ChangeLog	2012-07-11 16:56:18 UTC (rev 122338)
+++ trunk/LayoutTests/ChangeLog	2012-07-11 17:09:03 UTC (rev 122339)
@@ -1,3 +1,15 @@
+2012-07-11  Allan Sandfeld Jensen  <[email protected]>
+
+        NodesFromRect doesn't work on SVG root elements.
+        https://bugs.webkit.org/show_bug.cgi?id=89990
+
+        Reviewed by Antonio Gomes.
+
+        Test nodesFromRect on SVG root elements.
+
+        * fast/dom/nodesFromRect-svg-expected.txt: Added.
+        * fast/dom/nodesFromRect-svg.html: Added.
+
 2012-07-11  Csaba Osztrogonác  <[email protected]>
 
         [Qt] Unreviewed gardening.

Added: trunk/LayoutTests/fast/dom/nodesFromRect-svg-expected.txt (0 => 122339)


--- trunk/LayoutTests/fast/dom/nodesFromRect-svg-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/nodesFromRect-svg-expected.txt	2012-07-11 17:09:03 UTC (rev 122339)
@@ -0,0 +1,25 @@
+Document::nodesFromRect : Rect-based hit-testing on SVG elements - bug ?
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Some of following tests will likely FAIL and will need to be updated once rect-based
+hit tests are supported inside SVG elements:
+
+Check area hits fully inside SVG element
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+Check area hits overlapping SVG element
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+Check area hits across SVG elements
+PASS All correct nodes found for rect
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/nodesFromRect-svg.html (0 => 122339)


--- trunk/LayoutTests/fast/dom/nodesFromRect-svg.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/nodesFromRect-svg.html	2012-07-11 17:09:03 UTC (rev 122339)
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Document::nodesFromRect : Rect-based hit-testing on SVG elements - bug ?</title>
+<style type="text/css">
+    #sandbox {
+        position: absolute;
+        left: 0px;
+        top: 0px;
+        width: 600px;
+        height: 800px;
+    }
+    .svg {
+        width: 40px;
+        height: 20px;
+        margin: 10px;
+        padding: 2px;
+        box-sizing: border-box;
+    }
+</style>
+<script src=""
+<script src=""
+</head>
+
+<body>
+    <div id=sandbox>
+        <div class=svg id=div1>
+            <svg id=svg1 height=16 xmlns="http://www.w3.org/2000/svg">
+                <circle id="red" cx="8" cy="8" r="5" fill="red" />
+            </svg>
+        </div>
+        <div class=svg id=div2>
+            <svg id=svg2 height=16 xmlns="http://www.w3.org/2000/svg">
+                <circle id="yellow" cx="8" cy="8" r="5" fill="yellow" />
+            </svg>
+        </div>
+        <div class=svg id=div3>
+            <svg id=svg3 height=16 xmlns="http://www.w3.org/2000/svg">
+                <circle id="green" cx="8" cy="8" r="5" fill="green" />
+            </svg>
+        </div>
+    </div>
+
+    <script>
+        function runTest()
+        {
+            description(document.title);
+            var e = {};
+
+            // Set up shortcut access to elements
+            ['sandbox', 'div1', 'div2', 'div3', 'div4',
+             'svg1', 'svg2', 'svg3', 'svg4',
+             'red', 'yellow', 'green'].forEach(function(a) {
+                e[a] = document.getElementById(a);
+            });
+
+            window.scrollTo(0, 0);
+
+            debug('\nSome of following tests will likely FAIL and will need to be updated once rect-based')
+            debug('hit tests are supported inside SVG elements:\n');
+
+            debug('Check area hits fully inside SVG element');
+            check(20, 20, 4, 4, 4, 4, [e.red, e.svg1]);
+            check(20, 52, 4, 4, 4, 4, [e.yellow, e.svg2]);
+            check(18, 80, 4, 4, 4, 4, [e.green, e.svg3]);
+            check(14, 14, 2, 2, 2, 2, [e.svg1]);
+            check(20, 20, 9, 9, 9, 9, [e.red, e.svg1, e.div1]);
+
+            debug('Check area hits overlapping SVG element');
+            check(12, 12, 2, 2, 2, 2, [e.svg1, e.div1]);
+            check(6, 50, 5, 20, 5, 5, [e.svg2, e.div2, e.sandbox]);
+
+            debug('Check area hits across SVG elements');
+            check(20, 30, 20, 10, 30, 10, [e.svg2, e.div2, e.svg1, e.div1, e.sandbox]);
+
+            debug('');
+        }
+
+        runTest();
+    </script>
+
+    <p id='description'></p>
+    <span id="console"></span>
+    <script src=""
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (122338 => 122339)


--- trunk/Source/WebCore/ChangeLog	2012-07-11 16:56:18 UTC (rev 122338)
+++ trunk/Source/WebCore/ChangeLog	2012-07-11 17:09:03 UTC (rev 122339)
@@ -1,3 +1,20 @@
+2012-07-11  Allan Sandfeld Jensen  <[email protected]>
+
+        NodesFromRect doesn't work on SVG root elements.
+        https://bugs.webkit.org/show_bug.cgi?id=89990
+
+        Reviewed by Antonio Gomes.
+
+        Adds support for rect-based hit-testing on the SVG root element.
+        This means that while rect-based hit-testing is still not supported
+        within SVG elements, that at least it works on SVG root elements as
+        it would on any other replaced element.
+
+        Test: fast/dom/nodesFromRect-svg.html
+
+        * rendering/svg/RenderSVGRoot.cpp:
+        (WebCore::RenderSVGRoot::nodeAtPoint):
+
 2012-07-11  Joshua Netterfield  <[email protected]>
 
         [Qt] REGRESSION(r122250): It broke USE(3D_GRAPHICS)=1 and ENABLE(WEBGL)=0 builds

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp (122338 => 122339)


--- trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2012-07-11 16:56:18 UTC (rev 122338)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2012-07-11 17:09:03 UTC (rev 122339)
@@ -418,32 +418,35 @@
 bool RenderSVGRoot::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
 {
     LayoutPoint pointInParent = pointInContainer.point() - toLayoutSize(accumulatedOffset);
-    LayoutPoint pointInBorderBox(pointInParent.x() - x(), pointInParent.y() - y());
+    LayoutPoint pointInBorderBox = pointInParent - toLayoutSize(location());
 
-    // Note: For now, we're ignoring hits to border and padding for <svg>
-    if (!contentBoxRect().contains(pointInBorderBox))
-        return false;
+    // Only test SVG content if the point is in our content box.
+    // FIXME: This should be an intersection when rect-based hit tests are supported by nodeAtFloatPoint.
+    if (contentBoxRect().contains(pointInBorderBox)) {
+        FloatPoint localPoint = localToParentTransform().inverse().mapPoint(FloatPoint(pointInParent));
 
-    FloatPoint localPoint = localToParentTransform().inverse().mapPoint(FloatPoint(pointInParent));
-
-    for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
-        if (child->nodeAtFloatPoint(request, result, localPoint, hitTestAction)) {
-            // FIXME: CSS/HTML assumes the local point is relative to the border box, right?
-            updateHitTestResult(result, pointInBorderBox);
+        for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
             // FIXME: nodeAtFloatPoint() doesn't handle rect-based hit tests yet.
-            result.addNodeToRectBasedTestResult(child->node(), pointInContainer);
-            return true;
+            if (child->nodeAtFloatPoint(request, result, localPoint, hitTestAction)) {
+                updateHitTestResult(result, pointInBorderBox);
+                if (!result.addNodeToRectBasedTestResult(child->node(), pointInContainer))
+                    return true;
+            }
         }
     }
 
     // If we didn't early exit above, we've just hit the container <svg> element. Unlike SVG 1.1, 2nd Edition allows container elements to be hit.
-    if (hitTestAction == HitTestBlockBackground && style()->pointerEvents() != PE_NONE) {
+    if (hitTestAction == HitTestBlockBackground && visibleToHitTesting()) {
         // Only return true here, if the last hit testing phase 'BlockBackground' is executed. If we'd return true in the 'Foreground' phase,
         // hit testing would stop immediately. For SVG only trees this doesn't matter. Though when we have a <foreignObject> subtree we need
         // to be able to detect hits on the background of a <div> element. If we'd return true here in the 'Foreground' phase, we are not able 
         // to detect these hits anymore.
-        updateHitTestResult(result, roundedLayoutPoint(localPoint));
-        return true;
+        LayoutRect boundsRect(accumulatedOffset + location(), size());
+        if (pointInContainer.intersects(boundsRect)) {
+            updateHitTestResult(result, pointInBorderBox);
+            if (!result.addNodeToRectBasedTestResult(node(), pointInContainer, boundsRect))
+                return true;
+        }
     }
 
     return false;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to