Bug 1073207 - getScreenCTM should account for padding and border for outer svg r=longsonr
authorviolet <violet.bugreport@gmail.com>
Tue, 23 Apr 2019 18:15:57 +0000
changeset 470580 0ebd471a1242aa288662526da42ab6ada428e45b
parent 470579 358171d00f9a1251fff6269ca343fbe9e8ece858
child 470581 01c3e1ae707de16d3e72bf5a9cfa8bf26d85fec3
push id35908
push useraciure@mozilla.com
push dateWed, 24 Apr 2019 04:28:40 +0000
treeherdermozilla-central@c9f0730a57a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1073207
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1073207 - getScreenCTM should account for padding and border for outer svg r=longsonr Differential Revision: https://phabricator.services.mozilla.com/D28488
dom/svg/SVGContentUtils.cpp
dom/svg/test/test_getCTM.html
--- a/dom/svg/SVGContentUtils.cpp
+++ b/dom/svg/SVGContentUtils.cpp
@@ -498,16 +498,26 @@ static gfx::Matrix GetCTMInternal(SVGEle
     // We get here when getScreenCTM() is called on an outer-<svg>.
     // Consistency with other elements would have us include only the
     // eFromUserSpace transforms, but we include the eAllTransforms
     // transforms in this case since that's what we've been doing for
     // a while, and it keeps us consistent with WebKit and Opera (if not
     // really with the ambiguous spec).
     matrix = aElement->PrependLocalTransformsTo(gfxMatrix());
   }
+
+  if (auto* f = element->GetPrimaryFrame()) {
+    if (f->IsSVGOuterSVGFrame()) {
+      nsMargin bp = f->GetUsedBorderAndPadding();
+      matrix.PostTranslate(
+          NSAppUnitsToFloatPixels(bp.left, AppUnitsPerCSSPixel()),
+          NSAppUnitsToFloatPixels(bp.top, AppUnitsPerCSSPixel()));
+    }
+  }
+
   if (!ancestor || !ancestor->IsElement()) {
     return gfx::ToMatrix(matrix);
   }
   if (ancestor->IsSVGElement()) {
     return gfx::ToMatrix(matrix) *
            GetCTMInternal(static_cast<SVGElement*>(ancestor), true, true);
   }
 
--- a/dom/svg/test/test_getCTM.html
+++ b/dom/svg/test/test_getCTM.html
@@ -2,36 +2,47 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=366697
 -->
 <head>
   <title>Test for Bug 366697</title>
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <style>
+    #padsvg1 { padding-left: 27px; padding-top: 43px; }
+  </style>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=366697">Mozilla Bug 366697</a>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 
 <iframe id="svg" src="getCTM-helper.svg"></iframe>
 
+<svg id="padsvg1" width="100" height="100">
+  <rect width="10" height="10" />
+</svg>
+
 <pre id="test">
 <script class="testbody" type="application/javascript">
 SimpleTest.waitForExplicitFinish();
 
 function runTest() {
   var doc = $("svg").contentWindow.document;
 
   /* Minimal */
   var buggy = doc.getElementById("buggy");
   is(buggy.getCTM().e, 30, "buggy.getCTM().e");
   is(buggy.getCTM().f, 40, "buggy.getCTM().f");
 
+  var padsvg1 = document.getElementById("padsvg1");
+  is(padsvg1.getScreenCTM().e - padsvg1.getBoundingClientRect().x, 27, "padsvg1.getScreenCTM().e");
+  is(padsvg1.getScreenCTM().f - padsvg1.getBoundingClientRect().y, 43, "padsvg1.getScreenCTM().f");
+
   var root = doc.documentElement;
   var inner = doc.getElementById("inner");
   var g1 = doc.getElementById("g1");
   var outer = doc.getElementById("outer");
   var outer2 = doc.getElementById("outer2");
   var g2 = doc.getElementById("g2");
   var g3 = doc.getElementById("g3");
   var g4 = doc.getElementById("g4");