getScreenCTM returns different values depending on zoom
authorfmalita@chromium.org <fmalita@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2012 14:36:26 +0000 (14:36 +0000)
committerfmalita@chromium.org <fmalita@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2012 14:36:26 +0000 (14:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=96361

Reviewed by Dirk Schulze.

Source/WebCore:

SVGSVGElement::localCoordinateSpaceTransform() needs to adjust for the
zoom level (which is already factored into CSS coordinates) at the
SVG/HTML boundary.

Test: svg/zoom/page/zoom-get-screen-ctm.html

* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::localCoordinateSpaceTransform):

LayoutTests:

* svg/zoom/page/zoom-get-screen-ctm-expected.txt: Added.
* svg/zoom/page/zoom-get-screen-ctm.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/svg/zoom/page/zoom-get-screen-ctm-expected.txt [new file with mode: 0644]
LayoutTests/svg/zoom/page/zoom-get-screen-ctm.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/svg/SVGSVGElement.cpp

index 711921f..11408a8 100644 (file)
@@ -1,3 +1,13 @@
+2012-09-12  Florin Malita  <fmalita@chromium.org>
+
+        getScreenCTM returns different values depending on zoom
+        https://bugs.webkit.org/show_bug.cgi?id=96361
+
+        Reviewed by Dirk Schulze.
+
+        * svg/zoom/page/zoom-get-screen-ctm-expected.txt: Added.
+        * svg/zoom/page/zoom-get-screen-ctm.html: Added.
+
 2012-09-12  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
 
         Unreviewed gardening. These tests should have been unskipped when fixed.
diff --git a/LayoutTests/svg/zoom/page/zoom-get-screen-ctm-expected.txt b/LayoutTests/svg/zoom/page/zoom-get-screen-ctm-expected.txt
new file mode 100644 (file)
index 0000000..8529076
--- /dev/null
@@ -0,0 +1,14 @@
+This test checks getScreenCTM() on zoomed pages.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS CTM1 is "1, 0, 0, 1, 0, 100"
+PASS CTM2 is "1, 0, 0, 1, 100, 200"
+PASS CTM3 is "1, 0, 0, 1, 200, 300"
+PASS CTM4 is "1, 0, 0, 1, 300, 400"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/zoom/page/zoom-get-screen-ctm.html b/LayoutTests/svg/zoom/page/zoom-get-screen-ctm.html
new file mode 100644 (file)
index 0000000..f24e2cb
--- /dev/null
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<body style="margin: 0px; padding: 0px;" onload="runRepaintTest()">
+  <div style="width: 100px; height: 100px;"></div>
+  <svg id="svg1" xmlns="http://www.w3.org/2000/svg" width="400" height="400">
+    <rect width="100" height="100" fill="green"/>
+    <svg id="svg2" x="100" y="100" width="300" height="300">
+      <rect width="100" height="100" fill="green"/>
+      <svg id="svg3" x="100" y="100" width="200" height="200">
+        <rect width="100" height="100" fill="green"/>
+        <svg id="svg4" x="100" y="100" width="100" height="100">
+          <rect width="100" height="100" fill="green"/>
+        </svg>
+      </svg>
+    </svg>
+  </svg>
+
+<script>
+  var zoomCount = 2;
+
+  if (window.testRunner) {
+    testRunner.waitUntilDone();
+    window.postZoomCallback = executeTest;
+  }
+
+  function ctmToString(ctm) {
+    return [ ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f ].join(', ');
+  }
+
+  function executeTest() {
+    CTM1 = ctmToString(document.getElementById('svg1').getScreenCTM());
+    CTM2 = ctmToString(document.getElementById('svg2').getScreenCTM());
+    CTM3 = ctmToString(document.getElementById('svg3').getScreenCTM());
+    CTM4 = ctmToString(document.getElementById('svg4').getScreenCTM());
+
+    description("This test checks getScreenCTM() on zoomed pages.");
+
+    shouldBeEqualToString('CTM1', '1, 0, 0, 1, 0, 100');
+    shouldBeEqualToString('CTM2', '1, 0, 0, 1, 100, 200');
+    shouldBeEqualToString('CTM3', '1, 0, 0, 1, 200, 300');
+    shouldBeEqualToString('CTM4', '1, 0, 0, 1, 300, 400');
+    debug('');
+  }
+
+</script>
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../../fast/repaint/resources/repaint.js"></script>
+<script src="../resources/testPageZoom.js"></script>
+
+</body>
+</html>
index d4617a9..393ab4f 100644 (file)
@@ -1,3 +1,19 @@
+2012-09-12  Florin Malita  <fmalita@chromium.org>
+
+        getScreenCTM returns different values depending on zoom
+        https://bugs.webkit.org/show_bug.cgi?id=96361
+
+        Reviewed by Dirk Schulze.
+
+        SVGSVGElement::localCoordinateSpaceTransform() needs to adjust for the
+        zoom level (which is already factored into CSS coordinates) at the
+        SVG/HTML boundary.
+
+        Test: svg/zoom/page/zoom-get-screen-ctm.html
+
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::localCoordinateSpaceTransform):
+
 2012-09-12  Simon Hausmann  <simon.hausmann@nokia.com>
 
         [Qt] Drastically shorten length of commandline needed for JS bindings generator
index ef8e29c..3014794 100644 (file)
@@ -438,16 +438,21 @@ AffineTransform SVGSVGElement::localCoordinateSpaceTransform(SVGLocatable::CTMSc
     } else if (mode == SVGLocatable::ScreenScope) {
         if (RenderObject* renderer = this->renderer()) {
             FloatPoint location;
-            
+            float zoomFactor = 1;
+
             // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localToBorderBoxTransform 
             // to map an element from SVG viewport coordinates to CSS box coordinates.
             // RenderSVGRoot's localToAbsolute method expects CSS box coordinates.
-            if (renderer->isSVGRoot())
+            // We also need to adjust for the zoom level factored into CSS coordinates (bug #96361).
+            if (renderer->isSVGRoot()) {
                 location = toRenderSVGRoot(renderer)->localToBorderBoxTransform().mapPoint(location);
-            
+                zoomFactor = 1 / renderer->style()->effectiveZoom();
+            }
+
             // Translate in our CSS parent coordinate space
             // FIXME: This doesn't work correctly with CSS transforms.
             location = renderer->localToAbsolute(location, false, true);
+            location.scale(zoomFactor, zoomFactor);
 
             // Be careful here! localToBorderBoxTransform() included the x/y offset coming from the viewBoxToViewTransform(),
             // so we have to subtract it here (original cause of bug #27183)
@@ -456,6 +461,7 @@ AffineTransform SVGSVGElement::localCoordinateSpaceTransform(SVGLocatable::CTMSc
             // Respect scroll offset.
             if (FrameView* view = document()->view()) {
                 LayoutSize scrollOffset = view->scrollOffset();
+                scrollOffset.scale(zoomFactor);
                 transform.translate(-scrollOffset.width(), -scrollOffset.height());
             }
         }