Bug 567848 - Split content methods from nsSVGUtils into SVGContentUtils. r=dholbert
authorRobert Longson <longsonr@gmail.com>
Sat, 22 Sep 2012 20:26:05 +0100
changeset 107820 8d077e0638d4
parent 107819 18971061c844
child 107821 2afbf5440fc8
push id15227
push userlongsonr@gmail.com
push dateSat, 22 Sep 2012 19:26:21 +0000
treeherdermozilla-inbound@8d077e0638d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs567848
milestone18.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 567848 - Split content methods from nsSVGUtils into SVGContentUtils. r=dholbert
content/svg/content/src/DOMSVGMatrix.cpp
content/svg/content/src/DOMSVGTests.cpp
content/svg/content/src/Makefile.in
content/svg/content/src/SVGAnimatedTransformList.cpp
content/svg/content/src/SVGContentUtils.cpp
content/svg/content/src/SVGContentUtils.h
content/svg/content/src/SVGLength.cpp
content/svg/content/src/SVGLengthList.cpp
content/svg/content/src/SVGLengthListSMILType.cpp
content/svg/content/src/SVGMotionSMILPathUtils.cpp
content/svg/content/src/SVGNumberList.cpp
content/svg/content/src/SVGNumberListSMILType.cpp
content/svg/content/src/SVGPathData.cpp
content/svg/content/src/SVGPathSegListSMILType.cpp
content/svg/content/src/SVGPointList.cpp
content/svg/content/src/SVGPointListSMILType.cpp
content/svg/content/src/SVGStringList.cpp
content/svg/content/src/SVGTransform.cpp
content/svg/content/src/nsSVGAngle.cpp
content/svg/content/src/nsSVGAnimationElement.cpp
content/svg/content/src/nsSVGCircleElement.cpp
content/svg/content/src/nsSVGDataParser.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGEllipseElement.cpp
content/svg/content/src/nsSVGFilterElement.cpp
content/svg/content/src/nsSVGFilters.cpp
content/svg/content/src/nsSVGForeignObjectElement.cpp
content/svg/content/src/nsSVGGradientElement.cpp
content/svg/content/src/nsSVGGraphicElement.cpp
content/svg/content/src/nsSVGImageElement.cpp
content/svg/content/src/nsSVGIntegerPair.cpp
content/svg/content/src/nsSVGLength2.cpp
content/svg/content/src/nsSVGLength2.h
content/svg/content/src/nsSVGLineElement.cpp
content/svg/content/src/nsSVGMarkerElement.cpp
content/svg/content/src/nsSVGMaskElement.cpp
content/svg/content/src/nsSVGNumber2.cpp
content/svg/content/src/nsSVGNumberPair.cpp
content/svg/content/src/nsSVGPathDataParser.cpp
content/svg/content/src/nsSVGPathElement.cpp
content/svg/content/src/nsSVGPatternElement.cpp
content/svg/content/src/nsSVGPolyElement.cpp
content/svg/content/src/nsSVGPolygonElement.cpp
content/svg/content/src/nsSVGRectElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGStopElement.cpp
content/svg/content/src/nsSVGTextElement.cpp
content/svg/content/src/nsSVGTextPathElement.cpp
content/svg/content/src/nsSVGTextPositioningElement.cpp
content/svg/content/src/nsSVGUseElement.cpp
content/svg/content/src/nsSVGViewBox.cpp
layout/base/nsPresShell.cpp
layout/svg/base/src/Makefile.in
layout/svg/base/src/nsSVGFilterInstance.cpp
layout/svg/base/src/nsSVGGlyphFrame.cpp
layout/svg/base/src/nsSVGImageFrame.cpp
layout/svg/base/src/nsSVGPatternFrame.cpp
layout/svg/base/src/nsSVGUtils.cpp
layout/svg/base/src/nsSVGUtils.h
--- a/content/svg/content/src/DOMSVGMatrix.cpp
+++ b/content/svg/content/src/DOMSVGMatrix.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DOMSVGMatrix.h"
 #include "nsError.h"
 #include <math.h>
 #include "nsContentUtils.h"
 
-const double radPerDegree = 2.0*3.1415926535 / 360.0;
+const double radPerDegree = 2.0 * M_PI / 360.0;
 
 namespace mozilla {
 
 //----------------------------------------------------------------------
 // nsISupports methods:
 
 // Make sure we clear the weak ref in the owning transform (if there is one)
 // upon unlink.
--- a/content/svg/content/src/DOMSVGTests.cpp
+++ b/content/svg/content/src/DOMSVGTests.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DOMSVGTests.h"
 #include "DOMSVGStringList.h"
 #include "nsSVGFeatures.h"
 #include "nsSVGSwitchElement.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsStyleUtil.h"
-#include "nsSVGUtils.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS1(DOMSVGTests, nsIDOMSVGTests)
 
 nsIAtom** DOMSVGTests::sStringListNames[3] =
 {
--- a/content/svg/content/src/Makefile.in
+++ b/content/svg/content/src/Makefile.in
@@ -111,16 +111,17 @@ CPPSRCS		= \
 		SVGTransformListParser.cpp \
 		nsSVGAnimateElement.cpp \
 		nsSVGAnimateTransformElement.cpp \
 		nsSVGAnimateMotionElement.cpp \
 		nsSVGAnimationElement.cpp \
 		nsSVGMpathElement.cpp \
 		nsSVGSetElement.cpp \
 		SVGAttrValueWrapper.cpp \
+		SVGContentUtils.cpp \
 		SVGIntegerPairSMILType.cpp \
 		SVGLengthListSMILType.cpp \
 		SVGMotionSMILType.cpp \
 		SVGMotionSMILAttr.cpp \
 		SVGMotionSMILAnimationFunction.cpp \
 		SVGMotionSMILPathUtils.cpp \
 		SVGNumberListSMILType.cpp \
 		SVGNumberPairSMILType.cpp \
--- a/content/svg/content/src/SVGAnimatedTransformList.cpp
+++ b/content/svg/content/src/SVGAnimatedTransformList.cpp
@@ -3,20 +3,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SVGAnimatedTransformList.h"
 #include "DOMSVGAnimatedTransformList.h"
 
 #include "nsISMILAnimationElement.h"
 #include "nsSMILValue.h"
+#include "prdtoa.h"
+#include "SVGContentUtils.h"
 #include "SVGTransform.h"
 #include "SVGTransformListSMILType.h"
-#include "nsSVGUtils.h"
-#include "prdtoa.h"
 
 namespace mozilla {
 
 nsresult
 SVGAnimatedTransformList::SetBaseValueString(const nsAString& aValue)
 {
   SVGTransformList newBaseValue;
   nsresult rv = newBaseValue.SetValueFromString(aValue);
copy from layout/svg/base/src/nsSVGUtils.cpp
copy to content/svg/content/src/SVGContentUtils.cpp
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/content/svg/content/src/SVGContentUtils.cpp
@@ -1,245 +1,35 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Main header first:
 // This is also necessary to ensure our definition of M_SQRT1_2 is picked up
-#include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 
 // Keep others in (case-insensitive) order:
-#include "gfxContext.h"
-#include "gfxImageSurface.h"
 #include "gfxMatrix.h"
-#include "gfxPlatform.h"
-#include "gfxRect.h"
-#include "gfxUtils.h"
-#include "mozilla/gfx/2D.h"
 #include "mozilla/Preferences.h"
-#include "nsCSSFrameConstructor.h"
 #include "nsComputedDOMStyle.h"
-#include "nsContentUtils.h"
-#include "nsDisplayList.h"
-#include "nsFrameList.h"
-#include "nsGkAtoms.h"
-#include "nsIContent.h"
-#include "nsIDocument.h"
+#include "nsFontMetrics.h"
 #include "nsIDOMSVGElement.h"
-#include "nsIDOMSVGUnitTypes.h"
 #include "nsIFrame.h"
-#include "nsINameSpaceManager.h"
-#include "nsIPresShell.h"
 #include "nsIScriptError.h"
-#include "nsISVGChildFrame.h"
-#include "nsPresContext.h"
-#include "nsRenderingContext.h"
-#include "nsStyleCoord.h"
-#include "nsStyleStruct.h"
+#include "nsLayoutUtils.h"
 #include "nsSVGAnimationElement.h"
-#include "nsSVGClipPathFrame.h"
-#include "nsSVGContainerFrame.h"
-#include "nsSVGEffects.h"
-#include "nsSVGFilterFrame.h"
-#include "nsSVGFilterPaintCallback.h"
-#include "nsSVGForeignObjectFrame.h"
-#include "nsSVGGeometryFrame.h"
-#include "nsSVGGlyphFrame.h"
-#include "nsSVGInnerSVGFrame.h"
-#include "nsSVGIntegrationUtils.h"
-#include "nsSVGLength2.h"
-#include "nsSVGMaskFrame.h"
-#include "nsSVGOuterSVGFrame.h"
-#include "nsSVGPathElement.h"
-#include "nsSVGPathGeometryElement.h"
-#include "nsSVGPathGeometryFrame.h"
-#include "nsSVGPaintServerFrame.h"
 #include "nsSVGSVGElement.h"
-#include "nsSVGTextContainerFrame.h"
-#include "nsTextFrame.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
-#include "mozilla/unused.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
-using namespace mozilla::gfx;
-
-// c = n / 255
-// (c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055) * 255 + 0.5
-static const uint8_t glinearRGBTosRGBMap[256] = {
-  0,  13,  22,  28,  34,  38,  42,  46,
- 50,  53,  56,  59,  61,  64,  66,  69,
- 71,  73,  75,  77,  79,  81,  83,  85,
- 86,  88,  90,  92,  93,  95,  96,  98,
- 99, 101, 102, 104, 105, 106, 108, 109,
-110, 112, 113, 114, 115, 117, 118, 119,
-120, 121, 122, 124, 125, 126, 127, 128,
-129, 130, 131, 132, 133, 134, 135, 136,
-137, 138, 139, 140, 141, 142, 143, 144,
-145, 146, 147, 148, 148, 149, 150, 151,
-152, 153, 154, 155, 155, 156, 157, 158,
-159, 159, 160, 161, 162, 163, 163, 164,
-165, 166, 167, 167, 168, 169, 170, 170,
-171, 172, 173, 173, 174, 175, 175, 176,
-177, 178, 178, 179, 180, 180, 181, 182,
-182, 183, 184, 185, 185, 186, 187, 187,
-188, 189, 189, 190, 190, 191, 192, 192,
-193, 194, 194, 195, 196, 196, 197, 197,
-198, 199, 199, 200, 200, 201, 202, 202,
-203, 203, 204, 205, 205, 206, 206, 207,
-208, 208, 209, 209, 210, 210, 211, 212,
-212, 213, 213, 214, 214, 215, 215, 216,
-216, 217, 218, 218, 219, 219, 220, 220,
-221, 221, 222, 222, 223, 223, 224, 224,
-225, 226, 226, 227, 227, 228, 228, 229,
-229, 230, 230, 231, 231, 232, 232, 233,
-233, 234, 234, 235, 235, 236, 236, 237,
-237, 238, 238, 238, 239, 239, 240, 240,
-241, 241, 242, 242, 243, 243, 244, 244,
-245, 245, 246, 246, 246, 247, 247, 248,
-248, 249, 249, 250, 250, 251, 251, 251,
-252, 252, 253, 253, 254, 254, 255, 255
-};
-
-// c = n / 255
-// c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4)) * 255 + 0.5
-static const uint8_t gsRGBToLinearRGBMap[256] = {
-  0,   0,   0,   0,   0,   0,   0,   1,
-  1,   1,   1,   1,   1,   1,   1,   1,
-  1,   1,   2,   2,   2,   2,   2,   2,
-  2,   2,   3,   3,   3,   3,   3,   3,
-  4,   4,   4,   4,   4,   5,   5,   5,
-  5,   6,   6,   6,   6,   7,   7,   7,
-  8,   8,   8,   8,   9,   9,   9,  10,
- 10,  10,  11,  11,  12,  12,  12,  13,
- 13,  13,  14,  14,  15,  15,  16,  16,
- 17,  17,  17,  18,  18,  19,  19,  20,
- 20,  21,  22,  22,  23,  23,  24,  24,
- 25,  25,  26,  27,  27,  28,  29,  29,
- 30,  30,  31,  32,  32,  33,  34,  35,
- 35,  36,  37,  37,  38,  39,  40,  41,
- 41,  42,  43,  44,  45,  45,  46,  47,
- 48,  49,  50,  51,  51,  52,  53,  54,
- 55,  56,  57,  58,  59,  60,  61,  62,
- 63,  64,  65,  66,  67,  68,  69,  70,
- 71,  72,  73,  74,  76,  77,  78,  79,
- 80,  81,  82,  84,  85,  86,  87,  88,
- 90,  91,  92,  93,  95,  96,  97,  99,
-100, 101, 103, 104, 105, 107, 108, 109,
-111, 112, 114, 115, 116, 118, 119, 121,
-122, 124, 125, 127, 128, 130, 131, 133,
-134, 136, 138, 139, 141, 142, 144, 146,
-147, 149, 151, 152, 154, 156, 157, 159,
-161, 163, 164, 166, 168, 170, 171, 173,
-175, 177, 179, 181, 183, 184, 186, 188,
-190, 192, 194, 196, 198, 200, 202, 204,
-206, 208, 210, 212, 214, 216, 218, 220,
-222, 224, 226, 229, 231, 233, 235, 237,
-239, 242, 244, 246, 248, 250, 253, 255
-};
-
-static bool sSMILEnabled;
-static bool sSVGDisplayListHitTestingEnabled;
-static bool sSVGDisplayListPaintingEnabled;
-static bool sSVGTextCSSFramesEnabled;
-
-bool
-NS_SMILEnabled()
-{
-  return sSMILEnabled;
-}
-
-bool
-NS_SVGDisplayListHitTestingEnabled()
-{
-  return sSVGDisplayListHitTestingEnabled;
-}
-
-bool
-NS_SVGDisplayListPaintingEnabled()
-{
-  return sSVGDisplayListPaintingEnabled;
-}
-
-bool
-NS_SVGTextCSSFramesEnabled()
-{
-  return sSVGTextCSSFramesEnabled;
-}
-
-// we only take the address of this:
-static mozilla::gfx::UserDataKey sSVGAutoRenderStateKey;
-
-SVGAutoRenderState::SVGAutoRenderState(nsRenderingContext *aContext,
-                                       RenderMode aMode)
-  : mContext(aContext)
-  , mOriginalRenderState(nullptr)
-  , mMode(aMode)
-  , mPaintingToWindow(false)
-{
-  mOriginalRenderState = aContext->RemoveUserData(&sSVGAutoRenderStateKey);
-  // We always remove ourselves from aContext before it dies, so
-  // passing nullptr as the destroy function is okay.
-  aContext->AddUserData(&sSVGAutoRenderStateKey, this, nullptr);
-}
-
-SVGAutoRenderState::~SVGAutoRenderState()
-{
-  mContext->RemoveUserData(&sSVGAutoRenderStateKey);
-  if (mOriginalRenderState) {
-    mContext->AddUserData(&sSVGAutoRenderStateKey, mOriginalRenderState, nullptr);
-  }
-}
-
-void
-SVGAutoRenderState::SetPaintingToWindow(bool aPaintingToWindow)
-{
-  mPaintingToWindow = aPaintingToWindow;
-}
-
-/* static */ SVGAutoRenderState::RenderMode
-SVGAutoRenderState::GetRenderMode(nsRenderingContext *aContext)
-{
-  void *state = aContext->GetUserData(&sSVGAutoRenderStateKey);
-  if (state) {
-    return static_cast<SVGAutoRenderState*>(state)->mMode;
-  }
-  return NORMAL;
-}
-
-/* static */ bool
-SVGAutoRenderState::IsPaintingToWindow(nsRenderingContext *aContext)
-{
-  void *state = aContext->GetUserData(&sSVGAutoRenderStateKey);
-  if (state) {
-    return static_cast<SVGAutoRenderState*>(state)->mPaintingToWindow;
-  }
-  return false;
-}
-
-void
-nsSVGUtils::Init()
-{
-  Preferences::AddBoolVarCache(&sSMILEnabled,
-                               "svg.smil.enabled",
-                               true);
-
-  Preferences::AddBoolVarCache(&sSVGDisplayListHitTestingEnabled,
-                               "svg.display-lists.hit-testing.enabled");
-
-  Preferences::AddBoolVarCache(&sSVGDisplayListPaintingEnabled,
-                               "svg.display-lists.painting.enabled");
-
-  Preferences::AddBoolVarCache(&sSVGTextCSSFramesEnabled,
-                               "svg.text.css-frames.enabled");
-}
 
 nsSVGSVGElement*
-nsSVGUtils::GetOuterSVGElement(nsSVGElement *aSVGElement)
+SVGContentUtils::GetOuterSVGElement(nsSVGElement *aSVGElement)
 {
   nsIContent *element = nullptr;
   nsIContent *ancestor = aSVGElement->GetFlattenedTreeParent();
 
   while (ancestor && ancestor->IsSVG() &&
                      ancestor->Tag() != nsGkAtoms::foreignObject) {
     element = ancestor;
     ancestor = element->GetFlattenedTreeParent();
@@ -247,26 +37,26 @@ nsSVGUtils::GetOuterSVGElement(nsSVGElem
 
   if (element && element->Tag() == nsGkAtoms::svg) {
     return static_cast<nsSVGSVGElement*>(element);
   }
   return nullptr;
 }
 
 void
-nsSVGUtils::ActivateByHyperlink(nsIContent *aContent)
+SVGContentUtils::ActivateByHyperlink(nsIContent *aContent)
 {
   NS_ABORT_IF_FALSE(aContent->IsNodeOfType(nsINode::eANIMATION),
                     "Expecting an animation element");
 
   static_cast<nsSVGAnimationElement*>(aContent)->ActivateByHyperlink();
 }
 
 float
-nsSVGUtils::GetFontSize(Element *aElement)
+SVGContentUtils::GetFontSize(Element *aElement)
 {
   if (!aElement)
     return 1.0f;
 
   nsRefPtr<nsStyleContext> styleContext = 
     nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
                                                          nullptr, nullptr);
   if (!styleContext) {
@@ -274,37 +64,37 @@ nsSVGUtils::GetFontSize(Element *aElemen
     NS_WARNING("Couldn't get style context for content in GetFontStyle");
     return 1.0f;
   }
 
   return GetFontSize(styleContext);
 }
 
 float
-nsSVGUtils::GetFontSize(nsIFrame *aFrame)
+SVGContentUtils::GetFontSize(nsIFrame *aFrame)
 {
   NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontSize");
   return GetFontSize(aFrame->GetStyleContext());
 }
 
 float
-nsSVGUtils::GetFontSize(nsStyleContext *aStyleContext)
+SVGContentUtils::GetFontSize(nsStyleContext *aStyleContext)
 {
   NS_ABORT_IF_FALSE(aStyleContext, "NULL style context in GetFontSize");
 
   nsPresContext *presContext = aStyleContext->PresContext();
   NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontSize");
 
   nscoord fontSize = aStyleContext->GetStyleFont()->mSize;
   return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) / 
          presContext->TextZoom();
 }
 
 float
-nsSVGUtils::GetFontXHeight(Element *aElement)
+SVGContentUtils::GetFontXHeight(Element *aElement)
 {
   if (!aElement)
     return 1.0f;
 
   nsRefPtr<nsStyleContext> styleContext = 
     nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
                                                          nullptr, nullptr);
   if (!styleContext) {
@@ -312,24 +102,24 @@ nsSVGUtils::GetFontXHeight(Element *aEle
     NS_WARNING("Couldn't get style context for content in GetFontStyle");
     return 1.0f;
   }
 
   return GetFontXHeight(styleContext);
 }
   
 float
-nsSVGUtils::GetFontXHeight(nsIFrame *aFrame)
+SVGContentUtils::GetFontXHeight(nsIFrame *aFrame)
 {
   NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontXHeight");
   return GetFontXHeight(aFrame->GetStyleContext());
 }
 
 float
-nsSVGUtils::GetFontXHeight(nsStyleContext *aStyleContext)
+SVGContentUtils::GetFontXHeight(nsStyleContext *aStyleContext)
 {
   NS_ABORT_IF_FALSE(aStyleContext, "NULL style context in GetFontXHeight");
 
   nsPresContext *presContext = aStyleContext->PresContext();
   NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontXHeight");
 
   nsRefPtr<nsFontMetrics> fontMetrics;
   nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
@@ -340,153 +130,43 @@ nsSVGUtils::GetFontXHeight(nsStyleContex
     NS_WARNING("no FontMetrics in GetFontXHeight()");
     return 1.0f;
   }
 
   nscoord xHeight = fontMetrics->XHeight();
   return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) /
          presContext->TextZoom();
 }
-
-void
-nsSVGUtils::UnPremultiplyImageDataAlpha(uint8_t *data, 
-                                        int32_t stride,
-                                        const nsIntRect &rect)
-{
-  for (int32_t y = rect.y; y < rect.YMost(); y++) {
-    for (int32_t x = rect.x; x < rect.XMost(); x++) {
-      uint8_t *pixel = data + stride * y + 4 * x;
-
-      uint8_t a = pixel[GFX_ARGB32_OFFSET_A];
-      if (a == 255)
-        continue;
-
-      if (a) {
-        pixel[GFX_ARGB32_OFFSET_B] = (255 * pixel[GFX_ARGB32_OFFSET_B]) / a;
-        pixel[GFX_ARGB32_OFFSET_G] = (255 * pixel[GFX_ARGB32_OFFSET_G]) / a;
-        pixel[GFX_ARGB32_OFFSET_R] = (255 * pixel[GFX_ARGB32_OFFSET_R]) / a;
-      } else {
-        pixel[GFX_ARGB32_OFFSET_B] = 0;
-        pixel[GFX_ARGB32_OFFSET_G] = 0;
-        pixel[GFX_ARGB32_OFFSET_R] = 0;
-      }
-    }
-  }
-}
-
-void
-nsSVGUtils::PremultiplyImageDataAlpha(uint8_t *data, 
-                                      int32_t stride,
-                                      const nsIntRect &rect)
-{
-  for (int32_t y = rect.y; y < rect.YMost(); y++) {
-    for (int32_t x = rect.x; x < rect.XMost(); x++) {
-      uint8_t *pixel = data + stride * y + 4 * x;
-
-      uint8_t a = pixel[GFX_ARGB32_OFFSET_A];
-      if (a == 255)
-        continue;
-
-      FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_B],
-                         pixel[GFX_ARGB32_OFFSET_B] * a);
-      FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_G],
-                         pixel[GFX_ARGB32_OFFSET_G] * a);
-      FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_R],
-                         pixel[GFX_ARGB32_OFFSET_R] * a);
-    }
-  }
-}
-
-void
-nsSVGUtils::ConvertImageDataToLinearRGB(uint8_t *data, 
-                                        int32_t stride,
-                                        const nsIntRect &rect)
-{
-  for (int32_t y = rect.y; y < rect.YMost(); y++) {
-    for (int32_t x = rect.x; x < rect.XMost(); x++) {
-      uint8_t *pixel = data + stride * y + 4 * x;
-
-      pixel[GFX_ARGB32_OFFSET_B] =
-        gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_B]];
-      pixel[GFX_ARGB32_OFFSET_G] =
-        gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
-      pixel[GFX_ARGB32_OFFSET_R] =
-        gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
-    }
-  }
-}
-
-void
-nsSVGUtils::ConvertImageDataFromLinearRGB(uint8_t *data, 
-                                          int32_t stride,
-                                          const nsIntRect &rect)
-{
-  for (int32_t y = rect.y; y < rect.YMost(); y++) {
-    for (int32_t x = rect.x; x < rect.XMost(); x++) {
-      uint8_t *pixel = data + stride * y + 4 * x;
-
-      pixel[GFX_ARGB32_OFFSET_B] =
-        glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_B]];
-      pixel[GFX_ARGB32_OFFSET_G] =
-        glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
-      pixel[GFX_ARGB32_OFFSET_R] =
-        glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
-    }
-  }
-}
-
 nsresult
-nsSVGUtils::ReportToConsole(nsIDocument* doc,
-                            const char* aWarning,
-                            const PRUnichar **aParams,
-                            uint32_t aParamsLength)
+SVGContentUtils::ReportToConsole(nsIDocument* doc,
+                                 const char* aWarning,
+                                 const PRUnichar **aParams,
+                                 uint32_t aParamsLength)
 {
   return nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                          "SVG", doc,
                                          nsContentUtils::eSVG_PROPERTIES,
                                          aWarning,
                                          aParams, aParamsLength);
 }
 
-float
-nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
-                         nsSVGElement *aContent,
-                         const nsStyleCoord &aCoord)
-{
-  switch (aCoord.GetUnit()) {
-  case eStyleUnit_Factor:
-    // user units
-    return aCoord.GetFactorValue();
-
-  case eStyleUnit_Coord:
-    return nsPresContext::AppUnitsToFloatCSSPixels(aCoord.GetCoordValue());
-
-  case eStyleUnit_Percent: {
-      nsSVGSVGElement* ctx = aContent->GetCtx();
-      return ctx ? aCoord.GetPercentValue() * ctx->GetLength(nsSVGUtils::XY) : 0.0f;
-    }
-  default:
-    return 0.0f;
-  }
-}
-
 bool
-nsSVGUtils::EstablishesViewport(nsIContent *aContent)
+SVGContentUtils::EstablishesViewport(nsIContent *aContent)
 {
   // Although SVG 1.1 states that <image> is an element that establishes a
   // viewport, this is really only for the document it references, not
   // for any child content, which is what this function is used for.
   return aContent && aContent->IsSVG() &&
            (aContent->Tag() == nsGkAtoms::svg ||
             aContent->Tag() == nsGkAtoms::foreignObject ||
             aContent->Tag() == nsGkAtoms::symbol);
 }
 
 already_AddRefed<nsIDOMSVGElement>
-nsSVGUtils::GetNearestViewportElement(nsIContent *aContent)
+SVGContentUtils::GetNearestViewportElement(nsIContent *aContent)
 {
   nsIContent *element = aContent->GetFlattenedTreeParent();
 
   while (element && element->IsSVG()) {
     if (EstablishesViewport(element)) {
       if (element->Tag() == nsGkAtoms::foreignObject) {
         return nullptr;
       }
@@ -504,17 +184,17 @@ GetCTMInternal(nsSVGElement *aElement, b
     aHaveRecursed ? nsSVGElement::eAllTransforms : nsSVGElement::eUserSpaceToParent);
   nsSVGElement *element = aElement;
   nsIContent *ancestor = aElement->GetFlattenedTreeParent();
 
   while (ancestor && ancestor->IsSVG() &&
                      ancestor->Tag() != nsGkAtoms::foreignObject) {
     element = static_cast<nsSVGElement*>(ancestor);
     matrix *= element->PrependLocalTransformsTo(gfxMatrix()); // i.e. *A*ppend
-    if (!aScreenCTM && nsSVGUtils::EstablishesViewport(element)) {
+    if (!aScreenCTM && SVGContentUtils::EstablishesViewport(element)) {
       if (!element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG) &&
           !element->NodeInfo()->Equals(nsGkAtoms::symbol, kNameSpaceID_SVG)) {
         NS_ERROR("New (SVG > 1.1) SVG viewport establishing element?");
         return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
       }
       // XXX spec seems to say x,y translation should be undone for IsInnerSVG
       return matrix;
     }
@@ -560,391 +240,68 @@ GetCTMInternal(nsSVGElement *aElement, b
         y = nsPresContext::AppUnitsToFloatCSSPixels(point.y);
       }
     }
   }
   return matrix * gfxMatrix().Translate(gfxPoint(x, y));
 }
 
 gfxMatrix
-nsSVGUtils::GetCTM(nsSVGElement *aElement, bool aScreenCTM)
+SVGContentUtils::GetCTM(nsSVGElement *aElement, bool aScreenCTM)
 {
   nsIDocument* currentDoc = aElement->GetCurrentDoc();
   if (currentDoc) {
     // Flush all pending notifications so that our frames are up to date
     currentDoc->FlushPendingNotifications(Flush_Layout);
   }
   return GetCTMInternal(aElement, aScreenCTM, false);
 }
 
-nsSVGDisplayContainerFrame*
-nsSVGUtils::GetNearestSVGViewport(nsIFrame *aFrame)
-{
-  NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
-  if (aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
-    return nullptr;
-  }
-  while ((aFrame = aFrame->GetParent())) {
-    NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
-    if (aFrame->GetType() == nsGkAtoms::svgInnerSVGFrame ||
-        aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
-      return do_QueryFrame(aFrame);
-    }
-  }
-  NS_NOTREACHED("This is not reached. It's only needed to compile.");
-  return nullptr;
-}
-
-nsRect
-nsSVGUtils::GetPostFilterVisualOverflowRect(nsIFrame *aFrame,
-                                            const nsRect &aPreFilterRect)
-{
-  NS_ABORT_IF_FALSE(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT,
-                    "Called on invalid frame type");
-
-  nsSVGFilterFrame *filter = nsSVGEffects::GetFilterFrame(aFrame);
-  if (!filter) {
-    return aPreFilterRect;
-  }
-
-  return filter->GetPostFilterBounds(aFrame, nullptr, &aPreFilterRect);
-}
-
-bool
-nsSVGUtils::OuterSVGIsCallingReflowSVG(nsIFrame *aFrame)
-{
-  return nsSVGUtils::GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
-}
-
-void
-nsSVGUtils::InvalidateBounds(nsIFrame *aFrame, bool aDuringUpdate,
-                             const nsRect *aBoundsSubArea, uint32_t aFlags)
-{
-  NS_ABORT_IF_FALSE(aFrame->IsFrameOfType(nsIFrame::eSVG) &&
-                    !(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG),
-                    "Passed bad frame!");
-
-  NS_ASSERTION(aDuringUpdate == OuterSVGIsCallingReflowSVG(aFrame),
-               "aDuringUpdate lies!");
-
-  // Rendering observers must be notified about changes to the frames that they
-  // are observing _before_ ReflowSVG is called on the SVG frame tree, so we
-  // only need to notify observers if we're not under an ReflowSVG call.
-  // In fact, it would actually be wrong to notify observers while under
-  // ReflowSVG because the observers will try to mark themselves as dirty
-  // and, since ReflowSVG would be in the process of _removeing_ dirty bits
-  // from frames, that would mess things up.
-  if (!aDuringUpdate) {
-    NS_ASSERTION(!OuterSVGIsCallingReflowSVG(aFrame),
-                 "Must not InvalidateRenderingObservers() under "
-                 "nsISVGChildFrame::ReflowSVG!");
-
-    nsSVGEffects::InvalidateRenderingObservers(aFrame);
-  }
-
-  // Must come after InvalidateRenderingObservers
-  if (aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) {
-    return;
-  }
-
-  // XXXjwatt: can this come before InvalidateRenderingObservers?
-  if (aFrame->GetStateBits() &
-      (NS_FRAME_IS_DIRTY | NS_FRAME_FIRST_REFLOW)) {
-    // Nothing to do if we're already dirty, or if the outer-<svg>
-    // hasn't yet had its initial reflow.
-    return;
-  }
-
-  // Okay, so now we pass the area that needs to be invalidated up our parent
-  // chain, accounting for filter effects and transforms as we go, until we
-  // reach our nsSVGOuterSVGFrame where we can invalidate:
-
-  nsRect invalidArea;
-  if (aBoundsSubArea) {
-    invalidArea = *aBoundsSubArea;
-  } else {
-    invalidArea = aFrame->GetVisualOverflowRect();
-    // GetVisualOverflowRect() already includes filter effects and transforms,
-    // so advance to our parent before the loop below:
-    invalidArea += aFrame->GetPosition();
-    aFrame = aFrame->GetParent();
-  }
-
-  int32_t appUnitsPerCSSPx = aFrame->PresContext()->AppUnitsPerCSSPixel();
-
-  while (aFrame) {
-    if ((aFrame->GetStateBits() & NS_FRAME_IS_DIRTY)) {
-      // This ancestor frame has already been invalidated, so nothing to do.
-      return;
-    }
-    if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
-      break;
-    }
-    if (aFrame->GetType() == nsGkAtoms::svgInnerSVGFrame &&
-        aFrame->GetStyleDisplay()->IsScrollableOverflow()) {
-      // Clip rect to the viewport established by this inner-<svg>:
-      float x, y, width, height;
-      static_cast<nsSVGSVGElement*>(aFrame->GetContent())->
-        GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
-      if (width <= 0.0f || height <= 0.0f) {
-        return; // Nothing to invalidate
-      }
-      nsRect viewportRect =
-        nsLayoutUtils::RoundGfxRectToAppRect(gfxRect(0.0, 0.0, width, height),
-                                             appUnitsPerCSSPx);
-      invalidArea = invalidArea.Intersect(viewportRect);
-      if (invalidArea.IsEmpty()) {
-        return; // Nothing to invalidate
-      }
-    }
-    nsSVGFilterFrame *filterFrame = nsSVGEffects::GetFilterFrame(aFrame);
-    if (filterFrame) {
-      invalidArea =
-        filterFrame->GetPostFilterDirtyArea(aFrame, invalidArea);
-    }
-    if (aFrame->IsTransformed()) {
-      invalidArea =
-        nsDisplayTransform::TransformRect(invalidArea, aFrame, nsPoint(0, 0));
-    }
-    invalidArea += aFrame->GetPosition();
-    aFrame = aFrame->GetParent();
-  }
-
-  if (!aFrame) {
-    // We seem to be able to get here, even though SVG frames are never created
-    // without an ancestor nsSVGOuterSVGFrame. See bug 767996.
-    return;
-  }
-
-  NS_ASSERTION(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG,
-               "SVG frames must always have an nsSVGOuterSVGFrame ancestor!");
-
-  static_cast<nsSVGOuterSVGFrame*>(aFrame)->InvalidateWithFlags(invalidArea,
-                                                                aFlags);
-}
-
-void
-nsSVGUtils::ScheduleReflowSVG(nsIFrame *aFrame)
-{
-  NS_ABORT_IF_FALSE(aFrame->IsFrameOfType(nsIFrame::eSVG),
-                    "Passed bad frame!");
-
-  // If this is triggered, the callers should be fixed to call us before
-  // ReflowSVG is called. If we try to mark dirty bits on frames while we're
-  // in the process of removing them, things will get messed up.
-  NS_ASSERTION(!OuterSVGIsCallingReflowSVG(aFrame),
-               "Do not call under nsISVGChildFrame::ReflowSVG!");
-
-  // We don't call nsSVGEffects::InvalidateRenderingObservers here because
-  // we should only be called under InvalidateAndScheduleReflowSVG (which
-  // calls InvalidateBounds) or nsSVGDisplayContainerFrame::InsertFrames
-  // (at which point the frame has no observers).
-
-  if (aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) {
-    return;
-  }
-
-  if (aFrame->GetStateBits() &
-      (NS_FRAME_IS_DIRTY | NS_FRAME_FIRST_REFLOW)) {
-    // Nothing to do if we're already dirty, or if the outer-<svg>
-    // hasn't yet had its initial reflow.
-    return;
-  }
-
-  nsSVGOuterSVGFrame *outerSVGFrame = nullptr;
-
-  // We must not add dirty bits to the nsSVGOuterSVGFrame or else
-  // PresShell::FrameNeedsReflow won't work when we pass it in below.
-  if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
-    outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(aFrame);
-  } else {
-    aFrame->AddStateBits(NS_FRAME_IS_DIRTY);
-
-    nsIFrame *f = aFrame->GetParent();
-    while (f && !(f->GetStateBits() & NS_STATE_IS_OUTER_SVG)) {
-      if (f->GetStateBits() &
-          (NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN)) {
-        return;
-      }
-      f->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
-      f = f->GetParent();
-      NS_ABORT_IF_FALSE(f->IsFrameOfType(nsIFrame::eSVG),
-                        "NS_STATE_IS_OUTER_SVG check above not valid!");
-    }
-
-    outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(f);
-
-    NS_ABORT_IF_FALSE(outerSVGFrame &&
-                      outerSVGFrame->GetType() == nsGkAtoms::svgOuterSVGFrame,
-                      "Did not find nsSVGOuterSVGFrame!");
-  }
-
-  if (outerSVGFrame->GetStateBits() & NS_FRAME_IN_REFLOW) {
-    // We're currently under an nsSVGOuterSVGFrame::Reflow call so there is no
-    // need to call PresShell::FrameNeedsReflow, since we have an
-    // nsSVGOuterSVGFrame::DidReflow call pending.
-    return;
-  }
-
-  nsFrameState dirtyBit =
-    (outerSVGFrame == aFrame ? NS_FRAME_IS_DIRTY : NS_FRAME_HAS_DIRTY_CHILDREN);
-
-  aFrame->PresContext()->PresShell()->FrameNeedsReflow(
-    outerSVGFrame, nsIPresShell::eResize, dirtyBit);
-}
-
-void
-nsSVGUtils::InvalidateAndScheduleReflowSVG(nsIFrame *aFrame)
-{
-  // If this is triggered, the callers should be fixed to call us much
-  // earlier. If we try to mark dirty bits on frames while we're in the
-  // process of removing them, things will get messed up.
-  NS_ASSERTION(!OuterSVGIsCallingReflowSVG(aFrame),
-               "Must not call under nsISVGChildFrame::ReflowSVG!");
-
-  InvalidateBounds(aFrame, false);
-  ScheduleReflowSVG(aFrame);
-}
-
-bool
-nsSVGUtils::NeedsReflowSVG(nsIFrame *aFrame)
-{
-  NS_ABORT_IF_FALSE(aFrame->IsFrameOfType(nsIFrame::eSVG),
-                    "SVG uses bits differently!");
-
-  // The flags we test here may change, hence why we have this separate
-  // function.
-  return NS_SUBTREE_DIRTY(aFrame);
-}
-
-void
-nsSVGUtils::NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame)
-{
-  NS_ABORT_IF_FALSE(!(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG),
-                    "Not expecting to be called on the outer SVG Frame");
-
-  aFrame = aFrame->GetParent();
-
-  while (aFrame) {
-    if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG)
-      return;
-
-    nsSVGFilterProperty *property = nsSVGEffects::GetFilterProperty(aFrame);
-    if (property) {
-      property->Invalidate();
-    }
-    aFrame = aFrame->GetParent();
-  }
-}
-
 double
-nsSVGUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
+SVGContentUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
 {
   return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
 }
 
 float
-nsSVGUtils::ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength)
-{
-  float axis;
-
-  switch (aLength->GetCtxType()) {
-  case X:
-    axis = aRect.Width();
-    break;
-  case Y:
-    axis = aRect.Height();
-    break;
-  case XY:
-    axis = float(ComputeNormalizedHypotenuse(aRect.Width(), aRect.Height()));
-    break;
-  default:
-    NS_NOTREACHED("unexpected ctx type");
-    axis = 0.0f;
-    break;
-  }
-  if (aLength->IsPercentage()) {
-    // Multiply first to avoid precision errors:
-    return axis * aLength->GetAnimValInSpecifiedUnits() / 100;
-  }
-  return aLength->GetAnimValue(static_cast<nsSVGSVGElement*>(nullptr)) * axis;
-}
-
-float
-nsSVGUtils::UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength)
-{
-  return aLength->GetAnimValue(aSVGElement);
-}
-
-float
-nsSVGUtils::UserSpace(nsIFrame *aNonSVGContext, const nsSVGLength2 *aLength)
-{
-  return aLength->GetAnimValue(aNonSVGContext);
-}
-
-float
-nsSVGUtils::AngleBisect(float a1, float a2)
+SVGContentUtils::AngleBisect(float a1, float a2)
 {
   float delta = fmod(a2 - a1, static_cast<float>(2*M_PI));
   if (delta < 0) {
     delta += 2*M_PI;
   }
   /* delta is now the angle from a1 around to a2, in the range [0, 2*M_PI) */
   float r = a1 + delta/2;
   if (delta >= M_PI) {
     /* the arc from a2 to a1 is smaller, so use the ray on that side */
     r += M_PI;
   }
   return r;
 }
 
-nsSVGOuterSVGFrame *
-nsSVGUtils::GetOuterSVGFrame(nsIFrame *aFrame)
-{
-  while (aFrame) {
-    if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
-      return static_cast<nsSVGOuterSVGFrame*>(aFrame);
-    }
-    aFrame = aFrame->GetParent();
-  }
-
-  return nullptr;
-}
-
-nsIFrame*
-nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect)
-{
-  nsISVGChildFrame* svg = do_QueryFrame(aFrame);
-  if (!svg)
-    return nullptr;
-  *aRect = (aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) ?
-             nsRect(0, 0, 0, 0) : svg->GetCoveredRegion();
-  return GetOuterSVGFrame(aFrame);
-}
-
 gfxMatrix
-nsSVGUtils::GetViewBoxTransform(const nsSVGElement* aElement,
-                                float aViewportWidth, float aViewportHeight,
-                                float aViewboxX, float aViewboxY,
-                                float aViewboxWidth, float aViewboxHeight,
-                                const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio)
+SVGContentUtils::GetViewBoxTransform(const nsSVGElement* aElement,
+                                     float aViewportWidth, float aViewportHeight,
+                                     float aViewboxX, float aViewboxY,
+                                     float aViewboxWidth, float aViewboxHeight,
+                                     const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio)
 {
   return GetViewBoxTransform(aElement,
                              aViewportWidth, aViewportHeight,
                              aViewboxX, aViewboxY,
                              aViewboxWidth, aViewboxHeight,
                              aPreserveAspectRatio.GetAnimValue());
 }
 
 gfxMatrix
-nsSVGUtils::GetViewBoxTransform(const nsSVGElement* aElement,
-                                float aViewportWidth, float aViewportHeight,
-                                float aViewboxX, float aViewboxY,
-                                float aViewboxWidth, float aViewboxHeight,
-                                const SVGPreserveAspectRatio &aPreserveAspectRatio)
+SVGContentUtils::GetViewBoxTransform(const nsSVGElement* aElement,
+                                     float aViewportWidth, float aViewportHeight,
+                                     float aViewboxX, float aViewboxY,
+                                     float aViewboxWidth, float aViewboxHeight,
+                                     const SVGPreserveAspectRatio &aPreserveAspectRatio)
 {
   NS_ASSERTION(aViewportWidth  >= 0, "viewport width must be nonnegative!");
   NS_ASSERTION(aViewportHeight >= 0, "viewport height must be nonnegative!");
   NS_ASSERTION(aViewboxWidth  > 0, "viewBox width must be greater than zero!");
   NS_ASSERTION(aViewboxHeight > 0, "viewBox height must be greater than zero!");
 
   uint16_t align = aPreserveAspectRatio.GetAlign();
   uint16_t meetOrSlice = aPreserveAspectRatio.GetMeetOrSlice();
@@ -1015,1228 +372,8 @@ nsSVGUtils::GetViewBoxTransform(const ns
     else NS_NOTREACHED("Unknown value for meetOrSlice");
   }
   
   if (aViewboxX) e += -a * aViewboxX;
   if (aViewboxY) f += -d * aViewboxY;
   
   return gfxMatrix(a, 0.0f, 0.0f, d, e, f);
 }
-
-gfxMatrix
-nsSVGUtils::GetCanvasTM(nsIFrame *aFrame, uint32_t aFor)
-{
-  // XXX yuck, we really need a common interface for GetCanvasTM
-
-  if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
-    return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
-  }
-
-  if (!(aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
-    if ((aFor == nsISVGChildFrame::FOR_PAINTING &&
-         NS_SVGDisplayListPaintingEnabled()) ||
-        (aFor == nsISVGChildFrame::FOR_HIT_TESTING &&
-         NS_SVGDisplayListHitTestingEnabled())) {
-      return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
-    }
-  }
-
-  nsIAtom* type = aFrame->GetType();
-  if (type == nsGkAtoms::svgForeignObjectFrame) {
-    return static_cast<nsSVGForeignObjectFrame*>(aFrame)->GetCanvasTM(aFor);
-  }
-  if (type == nsGkAtoms::svgOuterSVGFrame) {
-    return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
-  }
-
-  nsSVGContainerFrame *containerFrame = do_QueryFrame(aFrame);
-  if (containerFrame) {
-    return containerFrame->GetCanvasTM(aFor);
-  }
-
-  return static_cast<nsSVGGeometryFrame*>(aFrame)->GetCanvasTM(aFor);
-}
-
-gfxMatrix
-nsSVGUtils::GetUserToCanvasTM(nsIFrame *aFrame, uint32_t aFor)
-{
-  NS_ASSERTION(aFor == nsISVGChildFrame::FOR_OUTERSVG_TM,
-               "Unexpected aFor?");
-
-  nsISVGChildFrame* svgFrame = do_QueryFrame(aFrame);
-  NS_ASSERTION(svgFrame, "bad frame");
-
-  gfxMatrix tm;
-  if (svgFrame) {
-    nsSVGElement *content = static_cast<nsSVGElement*>(aFrame->GetContent());
-    tm = content->PrependLocalTransformsTo(
-                    GetCanvasTM(aFrame->GetParent(), aFor),
-                    nsSVGElement::eUserSpaceToParent);
-  }
-  return tm;
-}
-
-void 
-nsSVGUtils::NotifyChildrenOfSVGChange(nsIFrame *aFrame, uint32_t aFlags)
-{
-  nsIFrame *kid = aFrame->GetFirstPrincipalChild();
-
-  while (kid) {
-    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
-    if (SVGFrame) {
-      SVGFrame->NotifySVGChanged(aFlags); 
-    } else {
-      NS_ASSERTION(kid->IsFrameOfType(nsIFrame::eSVG) || kid->IsSVGText(),
-                   "SVG frame expected");
-      // recurse into the children of container frames e.g. <clipPath>, <mask>
-      // in case they have child frames with transformation matrices
-      if (kid->IsFrameOfType(nsIFrame::eSVG)) {
-        NotifyChildrenOfSVGChange(kid, aFlags);
-      }
-    }
-    kid = kid->GetNextSibling();
-  }
-}
-
-// ************************************************************
-
-class SVGPaintCallback : public nsSVGFilterPaintCallback
-{
-public:
-  virtual void Paint(nsRenderingContext *aContext, nsIFrame *aTarget,
-                     const nsIntRect* aDirtyRect)
-  {
-    nsISVGChildFrame *svgChildFrame = do_QueryFrame(aTarget);
-    NS_ASSERTION(svgChildFrame, "Expected SVG frame here");
-
-    nsIntRect* dirtyRect = nullptr;
-    nsIntRect tmpDirtyRect;
-
-    // aDirtyRect is in user-space pixels, we need to convert to
-    // outer-SVG-frame-relative device pixels.
-    if (aDirtyRect) {
-      gfxMatrix userToDeviceSpace =
-        nsSVGUtils::GetCanvasTM(aTarget, nsISVGChildFrame::FOR_PAINTING);
-      if (userToDeviceSpace.IsSingular()) {
-        return;
-      }
-      gfxRect dirtyBounds = userToDeviceSpace.TransformBounds(
-        gfxRect(aDirtyRect->x, aDirtyRect->y, aDirtyRect->width, aDirtyRect->height));
-      dirtyBounds.RoundOut();
-      if (gfxUtils::GfxRectToIntRect(dirtyBounds, &tmpDirtyRect)) {
-        dirtyRect = &tmpDirtyRect;
-      }
-    }
-
-    svgChildFrame->PaintSVG(aContext, dirtyRect);
-  }
-};
-
-void
-nsSVGUtils::PaintFrameWithEffects(nsRenderingContext *aContext,
-                                  const nsIntRect *aDirtyRect,
-                                  nsIFrame *aFrame)
-{
-  NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
-               (aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) ||
-               aFrame->PresContext()->IsGlyph(),
-               "If display lists are enabled, only painting of non-display "
-               "SVG should take this code path");
-
-  nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
-  if (!svgChildFrame)
-    return;
-
-  float opacity = aFrame->GetStyleDisplay()->mOpacity;
-  if (opacity == 0.0f)
-    return;
-
-  const nsIContent* content = aFrame->GetContent();
-  if (content->IsSVG() &&
-      !static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
-    return;
-  }
-
-  /* Properties are added lazily and may have been removed by a restyle,
-     so make sure all applicable ones are set again. */
-
-  nsSVGEffects::EffectProperties effectProperties =
-    nsSVGEffects::GetEffectProperties(aFrame);
-
-  bool isOK = true;
-  nsSVGFilterFrame *filterFrame = effectProperties.GetFilterFrame(&isOK);
-
-  if (aDirtyRect &&
-      !(aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
-    // Here we convert aFrame's paint bounds to outer-<svg> device space,
-    // compare it to aDirtyRect, and return early if they don't intersect.
-    // We don't do this optimization for nondisplay SVG since nondisplay
-    // SVG doesn't maintain bounds/overflow rects.
-    nsRect overflowRect = aFrame->GetVisualOverflowRectRelativeToSelf();
-    if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry)) {
-      // Unlike containers, leaf frames do not include GetPosition() in
-      // GetCanvasTM().
-      overflowRect = overflowRect + aFrame->GetPosition();
-    }
-    uint32_t appUnitsPerDevPx = aFrame->PresContext()->AppUnitsPerDevPixel();
-    gfxMatrix tm = GetCanvasTM(aFrame, nsISVGChildFrame::FOR_PAINTING);
-    if (aFrame->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer)) {
-      gfxMatrix childrenOnlyTM;
-      if (static_cast<nsSVGContainerFrame*>(aFrame)->
-            HasChildrenOnlyTransform(&childrenOnlyTM)) {
-        // Undo the children-only transform:
-        tm = childrenOnlyTM.Invert() * tm;
-      }
-    }
-    nsIntRect bounds = nsSVGUtils::TransformFrameRectToOuterSVG(overflowRect,
-                         tm, aFrame->PresContext()).
-                           ToOutsidePixels(appUnitsPerDevPx);
-    if (!aDirtyRect->Intersects(bounds)) {
-      return;
-    }
-  }
-
-  /* SVG defines the following rendering model:
-   *
-   *  1. Render fill
-   *  2. Render stroke
-   *  3. Render markers
-   *  4. Apply filter
-   *  5. Apply clipping, masking, group opacity
-   *
-   * We follow this, but perform a couple of optimizations:
-   *
-   * + Use cairo's clipPath when representable natively (single object
-   *   clip region).
-   *
-   * + Merge opacity and masking if both used together.
-   */
-
-  if (opacity != 1.0f && CanOptimizeOpacity(aFrame))
-    opacity = 1.0f;
-
-  gfxContext *gfx = aContext->ThebesContext();
-  bool complexEffects = false;
-
-  nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
-  nsSVGMaskFrame *maskFrame = effectProperties.GetMaskFrame(&isOK);
-
-  bool isTrivialClip = clipPathFrame ? clipPathFrame->IsTrivial() : true;
-
-  if (!isOK) {
-    // Some resource is invalid. We shouldn't paint anything.
-    return;
-  }
-  
-  gfxMatrix matrix;
-  if (clipPathFrame || maskFrame)
-    matrix = GetCanvasTM(aFrame, nsISVGChildFrame::FOR_PAINTING);
-
-  /* Check if we need to do additional operations on this child's
-   * rendering, which necessitates rendering into another surface. */
-  if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)) {
-    complexEffects = true;
-    gfx->Save();
-    if (!(aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
-      // aFrame has a valid visual overflow rect, so clip to it before calling
-      // PushGroup() to minimize the size of the surfaces we'll composite:
-      gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(gfx);
-      gfx->Multiply(GetCanvasTM(aFrame, nsISVGChildFrame::FOR_PAINTING));
-      nsRect overflowRect = aFrame->GetVisualOverflowRectRelativeToSelf();
-      if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry)) {
-        // Unlike containers, leaf frames do not include GetPosition() in
-        // GetCanvasTM().
-        overflowRect = overflowRect + aFrame->GetPosition();
-      }
-      aContext->IntersectClip(overflowRect);
-    }
-    gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
-  }
-
-  /* If this frame has only a trivial clipPath, set up cairo's clipping now so
-   * we can just do normal painting and get it clipped appropriately.
-   */
-  if (clipPathFrame && isTrivialClip) {
-    gfx->Save();
-    clipPathFrame->ClipPaint(aContext, aFrame, matrix);
-  }
-
-  /* Paint the child */
-  if (filterFrame) {
-    nsRect* dirtyRect = nullptr;
-    nsRect tmpDirtyRect;
-    if (aDirtyRect) {
-      // aDirtyRect is in outer-<svg> device pixels, but the filter code needs
-      // it in frame space.
-      gfxMatrix userToDeviceSpace =
-        GetUserToCanvasTM(aFrame, nsISVGChildFrame::FOR_OUTERSVG_TM);
-      if (userToDeviceSpace.IsSingular()) {
-        return;
-      }
-      gfxMatrix deviceToUserSpace = userToDeviceSpace;
-      deviceToUserSpace.Invert();
-      gfxRect dirtyBounds = deviceToUserSpace.TransformBounds(
-                              gfxRect(aDirtyRect->x, aDirtyRect->y,
-                                      aDirtyRect->width, aDirtyRect->height));
-      tmpDirtyRect =
-        nsLayoutUtils::RoundGfxRectToAppRect(
-          dirtyBounds, aFrame->PresContext()->AppUnitsPerCSSPixel()) -
-        aFrame->GetPosition();
-      dirtyRect = &tmpDirtyRect;
-    }
-    SVGPaintCallback paintCallback;
-    filterFrame->PaintFilteredFrame(aContext, aFrame, &paintCallback, dirtyRect);
-  } else {
-    svgChildFrame->PaintSVG(aContext, aDirtyRect);
-  }
-
-  if (clipPathFrame && isTrivialClip) {
-    gfx->Restore();
-  }
-
-  /* No more effects, we're done. */
-  if (!complexEffects)
-    return;
-
-  gfx->PopGroupToSource();
-
-  nsRefPtr<gfxPattern> maskSurface =
-    maskFrame ? maskFrame->ComputeMaskAlpha(aContext, aFrame,
-                                            matrix, opacity) : nullptr;
-
-  nsRefPtr<gfxPattern> clipMaskSurface;
-  if (clipPathFrame && !isTrivialClip) {
-    gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
-
-    nsresult rv = clipPathFrame->ClipPaint(aContext, aFrame, matrix);
-    clipMaskSurface = gfx->PopGroup();
-
-    if (NS_SUCCEEDED(rv) && clipMaskSurface) {
-      // Still more set after clipping, so clip to another surface
-      if (maskSurface || opacity != 1.0f) {
-        gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
-        gfx->Mask(clipMaskSurface);
-        gfx->PopGroupToSource();
-      } else {
-        gfx->Mask(clipMaskSurface);
-      }
-    }
-  }
-
-  if (maskSurface) {
-    gfx->Mask(maskSurface);
-  } else if (opacity != 1.0f) {
-    gfx->Paint(opacity);
-  }
-
-  gfx->Restore();
-}
-
-bool
-nsSVGUtils::HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint)
-{
-  nsSVGEffects::EffectProperties props =
-    nsSVGEffects::GetEffectProperties(aFrame);
-  if (!props.mClipPath)
-    return true;
-
-  bool isOK = true;
-  nsSVGClipPathFrame *clipPathFrame = props.GetClipPathFrame(&isOK);
-  if (!clipPathFrame || !isOK) {
-    // clipPath is not a valid resource, so nothing gets painted, so
-    // hit-testing must fail.
-    return false;
-  }
-
-  return clipPathFrame->ClipHitTest(aFrame, GetCanvasTM(aFrame,
-                                    nsISVGChildFrame::FOR_HIT_TESTING), aPoint);
-}
-
-nsIFrame *
-nsSVGUtils::HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint)
-{
-  // Traverse the list in reverse order, so that if we get a hit we know that's
-  // the topmost frame that intersects the point; then we can just return it.
-  nsIFrame* result = nullptr;
-  for (nsIFrame* current = aFrame->PrincipalChildList().LastChild();
-       current;
-       current = current->GetPrevSibling()) {
-    nsISVGChildFrame* SVGFrame = do_QueryFrame(current);
-    if (SVGFrame) {
-      const nsIContent* content = current->GetContent();
-      if (content->IsSVG() &&
-          !static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
-        continue;
-      }
-      result = SVGFrame->GetFrameForPoint(aPoint);
-      if (result)
-        break;
-    }
-  }
-
-  if (result && !HitTestClip(aFrame, aPoint))
-    result = nullptr;
-
-  return result;
-}
-
-nsRect
-nsSVGUtils::GetCoveredRegion(const nsFrameList &aFrames)
-{
-  nsRect rect;
-
-  for (nsIFrame* kid = aFrames.FirstChild();
-       kid;
-       kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* child = do_QueryFrame(kid);
-    if (child) {
-      nsRect childRect = child->GetCoveredRegion();
-      rect.UnionRect(rect, childRect);
-    }
-  }
-
-  return rect;
-}
-
-nsPoint
-nsSVGUtils::TransformOuterSVGPointToChildFrame(nsPoint aPoint,
-                                               const gfxMatrix& aFrameToCanvasTM,
-                                               nsPresContext* aPresContext)
-{
-  NS_ABORT_IF_FALSE(!aFrameToCanvasTM.IsSingular(),
-                    "Callers must not pass a singular matrix");
-  gfxMatrix canvasDevToFrameUserSpace = aFrameToCanvasTM;
-  canvasDevToFrameUserSpace.Invert();
-  gfxPoint devPt = gfxPoint(aPoint.x, aPoint.y) /
-    aPresContext->AppUnitsPerDevPixel();
-  gfxPoint userPt = canvasDevToFrameUserSpace.Transform(devPt);
-  gfxPoint appPt = (userPt * aPresContext->AppUnitsPerCSSPixel()).Round();
-  userPt.x = clamped(appPt.x, gfxFloat(nscoord_MIN), gfxFloat(nscoord_MAX));
-  userPt.y = clamped(appPt.y, gfxFloat(nscoord_MIN), gfxFloat(nscoord_MAX));
-  // now guaranteed to be safe:
-  return nsPoint(nscoord(userPt.x), nscoord(userPt.y));
-}
-
-nsRect
-nsSVGUtils::TransformFrameRectToOuterSVG(const nsRect& aRect,
-                                         const gfxMatrix& aMatrix,
-                                         nsPresContext* aPresContext)
-{
-  gfxRect r(aRect.x, aRect.y, aRect.width, aRect.height);
-  r.Scale(1.0 / nsPresContext::AppUnitsPerCSSPixel());
-  return nsLayoutUtils::RoundGfxRectToAppRect(
-    aMatrix.TransformBounds(r), aPresContext->AppUnitsPerDevPixel());
-}
-
-gfxIntSize
-nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize,
-                                 bool *aResultOverflows)
-{
-  gfxIntSize surfaceSize(ClampToInt(ceil(aSize.width)), ClampToInt(ceil(aSize.height)));
-
-  *aResultOverflows = surfaceSize.width != ceil(aSize.width) ||
-    surfaceSize.height != ceil(aSize.height);
-
-  if (!gfxASurface::CheckSurfaceSize(surfaceSize)) {
-    surfaceSize.width = NS_MIN(NS_SVG_OFFSCREEN_MAX_DIMENSION,
-                               surfaceSize.width);
-    surfaceSize.height = NS_MIN(NS_SVG_OFFSCREEN_MAX_DIMENSION,
-                                surfaceSize.height);
-    *aResultOverflows = true;
-  }
-
-  return surfaceSize;
-}
-
-bool
-nsSVGUtils::HitTestRect(const gfxMatrix &aMatrix,
-                        float aRX, float aRY, float aRWidth, float aRHeight,
-                        float aX, float aY)
-{
-  gfxRect rect(aRX, aRY, aRWidth, aRHeight);
-  if (rect.IsEmpty() || aMatrix.IsSingular()) {
-    return false;
-  }
-  gfxMatrix toRectSpace = aMatrix;
-  toRectSpace.Invert();
-  gfxPoint p = toRectSpace.Transform(gfxPoint(aX, aY));
-  return rect.x <= p.x && p.x <= rect.XMost() &&
-         rect.y <= p.y && p.y <= rect.YMost();
-}
-
-gfxRect
-nsSVGUtils::GetClipRectForFrame(nsIFrame *aFrame,
-                                float aX, float aY, float aWidth, float aHeight)
-{
-  const nsStyleDisplay* disp = aFrame->GetStyleDisplay();
-
-  if (!(disp->mClipFlags & NS_STYLE_CLIP_RECT)) {
-    NS_ASSERTION(disp->mClipFlags == NS_STYLE_CLIP_AUTO,
-                 "We don't know about this type of clip.");
-    return gfxRect(aX, aY, aWidth, aHeight);
-  }
-
-  if (disp->mOverflowX == NS_STYLE_OVERFLOW_HIDDEN ||
-      disp->mOverflowY == NS_STYLE_OVERFLOW_HIDDEN) {
-
-    nsIntRect clipPxRect =
-      disp->mClip.ToOutsidePixels(aFrame->PresContext()->AppUnitsPerDevPixel());
-    gfxRect clipRect =
-      gfxRect(clipPxRect.x, clipPxRect.y, clipPxRect.width, clipPxRect.height);
-
-    if (NS_STYLE_CLIP_RIGHT_AUTO & disp->mClipFlags) {
-      clipRect.width = aWidth - clipRect.X();
-    }
-    if (NS_STYLE_CLIP_BOTTOM_AUTO & disp->mClipFlags) {
-      clipRect.height = aHeight - clipRect.Y();
-    }
-
-    if (disp->mOverflowX != NS_STYLE_OVERFLOW_HIDDEN) {
-      clipRect.x = aX;
-      clipRect.width = aWidth;
-    }
-    if (disp->mOverflowY != NS_STYLE_OVERFLOW_HIDDEN) {
-      clipRect.y = aY;
-      clipRect.height = aHeight;
-    }
-     
-    return clipRect;
-  }
-  return gfxRect(aX, aY, aWidth, aHeight);
-}
-
-void
-nsSVGUtils::CompositeSurfaceMatrix(gfxContext *aContext,
-                                   gfxASurface *aSurface,
-                                   const gfxMatrix &aCTM, float aOpacity)
-{
-  if (aCTM.IsSingular())
-    return;
-  
-  if (aContext->IsCairo()) {
-    aContext->Save();
-    aContext->Multiply(aCTM);
-    aContext->SetSource(aSurface);
-    aContext->Paint(aOpacity);
-    aContext->Restore();
-  } else {
-    DrawTarget *dt = aContext->GetDrawTarget();
-    Matrix oldMat = dt->GetTransform();
-    RefPtr<SourceSurface> surf =
-      gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, aSurface);
-    dt->SetTransform(ToMatrix(aCTM) * oldMat);
-
-    gfxSize size = aSurface->GetSize();
-    NS_ASSERTION(size.width >= 0 && size.height >= 0, "Failure to get size for aSurface.");
-
-    gfxPoint pt = aSurface->GetDeviceOffset();
-
-    dt->FillRect(Rect(-pt.x, -pt.y, size.width, size.height),
-                 SurfacePattern(surf, EXTEND_CLAMP,
-                                Matrix(1.0f, 0, 0, 1.0f, -pt.x, -pt.y)),
-                 DrawOptions(aOpacity));
-
-    dt->SetTransform(oldMat);
-  }
-}
-
-void
-nsSVGUtils::CompositePatternMatrix(gfxContext *aContext,
-                                   gfxPattern *aPattern,
-                                   const gfxMatrix &aCTM, float aWidth, float aHeight, float aOpacity)
-{
-  if (aCTM.IsSingular())
-    return;
-
-  aContext->Save();
-  SetClipRect(aContext, aCTM, gfxRect(0, 0, aWidth, aHeight));
-  aContext->Multiply(aCTM);
-  aContext->SetPattern(aPattern);
-  aContext->Paint(aOpacity);
-  aContext->Restore();
-}
-
-void
-nsSVGUtils::SetClipRect(gfxContext *aContext,
-                        const gfxMatrix &aCTM,
-                        const gfxRect &aRect)
-{
-  if (aCTM.IsSingular())
-    return;
-
-  gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(aContext);
-  aContext->Multiply(aCTM);
-  aContext->Clip(aRect);
-}
-
-void
-nsSVGUtils::ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect)
-{
-  gfxRect r = aGfxRect;
-  r.RoundOut();
-  gfxRect r2(aRect->x, aRect->y, aRect->width, aRect->height);
-  r = r.Intersect(r2);
-  *aRect = nsIntRect(int32_t(r.X()), int32_t(r.Y()),
-                     int32_t(r.Width()), int32_t(r.Height()));
-}
-
-gfxRect
-nsSVGUtils::GetBBox(nsIFrame *aFrame, uint32_t aFlags)
-{
-  if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
-    aFrame = aFrame->GetParent();
-  }
-  gfxRect bbox;
-  nsISVGChildFrame *svg = do_QueryFrame(aFrame);
-  if (svg || aFrame->IsSVGText()) {
-    // It is possible to apply a gradient, pattern, clipping path, mask or
-    // filter to text. When one of these facilities is applied to text
-    // the bounding box is the entire text element in all
-    // cases.
-    if (NS_SVGTextCSSFramesEnabled()) {
-      nsIFrame* ancestor = GetFirstNonAAncestorFrame(aFrame);
-      if (ancestor && ancestor->IsSVGText()) {
-        while (ancestor->GetType() != nsGkAtoms::svgTextFrame2) {
-          ancestor = ancestor->GetParent();
-        }
-      }
-      svg = do_QueryFrame(ancestor);
-    } else {
-      nsSVGTextContainerFrame* metrics = do_QueryFrame(
-        GetFirstNonAAncestorFrame(aFrame));
-      if (metrics) {
-        while (aFrame->GetType() != nsGkAtoms::svgTextFrame) {
-          aFrame = aFrame->GetParent();
-        }
-        svg = do_QueryFrame(aFrame);
-      }
-    }
-    nsIContent* content = aFrame->GetContent();
-    if (content->IsSVG() &&
-        !static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
-      return bbox;
-    }
-    gfxMatrix matrix;
-    if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame) {
-      // The spec says getBBox "Returns the tight bounding box in *current user
-      // space*". So we should really be doing this for all elements, but that
-      // needs investigation to check that we won't break too much content.
-      NS_ABORT_IF_FALSE(content->IsSVG(), "bad cast");
-      nsSVGElement *element = static_cast<nsSVGElement*>(content);
-      matrix = element->PrependLocalTransformsTo(matrix,
-                          nsSVGElement::eChildToUserSpace);
-    }
-    return svg->GetBBoxContribution(matrix, aFlags);
-  }
-  return nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(aFrame);
-}
-
-gfxRect
-nsSVGUtils::GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH,
-                            const gfxRect &aBBox, nsIFrame *aFrame)
-{
-  float x, y, width, height;
-  if (aUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
-    x = aBBox.X() + ObjectSpace(aBBox, &aXYWH[0]);
-    y = aBBox.Y() + ObjectSpace(aBBox, &aXYWH[1]);
-    width = ObjectSpace(aBBox, &aXYWH[2]);
-    height = ObjectSpace(aBBox, &aXYWH[3]);
-  } else {
-    x = UserSpace(aFrame, &aXYWH[0]);
-    y = UserSpace(aFrame, &aXYWH[1]);
-    width = UserSpace(aFrame, &aXYWH[2]);
-    height = UserSpace(aFrame, &aXYWH[3]);
-  }
-  return gfxRect(x, y, width, height);
-}
-
-bool
-nsSVGUtils::CanOptimizeOpacity(nsIFrame *aFrame)
-{
-  if (!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
-    return false;
-  }
-  nsIAtom *type = aFrame->GetType();
-  if (type != nsGkAtoms::svgImageFrame &&
-      type != nsGkAtoms::svgPathGeometryFrame) {
-    return false;
-  }
-  if (aFrame->GetStyleSVGReset()->mFilter) {
-    return false;
-  }
-  // XXX The SVG WG is intending to allow fill, stroke and markers on <image>
-  if (type == nsGkAtoms::svgImageFrame) {
-    return true;
-  }
-  const nsStyleSVG *style = aFrame->GetStyleSVG();
-  if (style->mMarkerStart || style->mMarkerMid || style->mMarkerEnd) {
-    return false;
-  }
-  if (style->mFill.mType == eStyleSVGPaintType_None ||
-      style->mFillOpacity <= 0 ||
-      !HasStroke(aFrame)) {
-    return true;
-  }
-  return false;
-}
-
-float
-nsSVGUtils::MaxExpansion(const gfxMatrix &aMatrix)
-{
-  // maximum expansion derivation from
-  // http://lists.cairographics.org/archives/cairo/2004-October/001980.html
-  // and also implemented in cairo_matrix_transformed_circle_major_axis
-  double a = aMatrix.xx;
-  double b = aMatrix.yx;
-  double c = aMatrix.xy;
-  double d = aMatrix.yy;
-  double f = (a * a + b * b + c * c + d * d) / 2;
-  double g = (a * a + b * b - c * c - d * d) / 2;
-  double h = a * c + b * d;
-  return sqrt(f + sqrt(g * g + h * h));
-}
-
-gfxMatrix
-nsSVGUtils::AdjustMatrixForUnits(const gfxMatrix &aMatrix,
-                                 nsSVGEnum *aUnits,
-                                 nsIFrame *aFrame)
-{
-  if (aFrame &&
-      aUnits->GetAnimValue() ==
-      nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
-    gfxRect bbox = GetBBox(aFrame);
-    return gfxMatrix().Scale(bbox.Width(), bbox.Height()) *
-           gfxMatrix().Translate(gfxPoint(bbox.X(), bbox.Y())) *
-           aMatrix;
-  }
-  return aMatrix;
-}
-
-nsIFrame*
-nsSVGUtils::GetFirstNonAAncestorFrame(nsIFrame* aStartFrame)
-{
-  for (nsIFrame *ancestorFrame = aStartFrame; ancestorFrame;
-       ancestorFrame = ancestorFrame->GetParent()) {
-    if (ancestorFrame->GetType() != nsGkAtoms::svgAFrame) {
-      return ancestorFrame;
-    }
-  }
-  return nullptr;
-}
-
-#ifdef DEBUG
-void
-nsSVGUtils::WritePPM(const char *fname, gfxImageSurface *aSurface)
-{
-  FILE *f = fopen(fname, "wb");
-  if (!f)
-    return;
-
-  gfxIntSize size = aSurface->GetSize();
-  fprintf(f, "P6\n%d %d\n255\n", size.width, size.height);
-  unsigned char *data = aSurface->Data();
-  int32_t stride = aSurface->Stride();
-  for (int y=0; y<size.height; y++) {
-    for (int x=0; x<size.width; x++) {
-      unused << fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_R, 1, 1, f);
-      unused << fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_G, 1, 1, f);
-      unused << fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_B, 1, 1, f);
-    }
-  }
-  fclose(f);
-}
-#endif
-
-gfxMatrix
-nsSVGUtils::GetStrokeTransform(nsIFrame *aFrame)
-{
-  if (aFrame->GetStyleSVGReset()->mVectorEffect ==
-      NS_STYLE_VECTOR_EFFECT_NON_SCALING_STROKE) {
- 
-    if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
-      aFrame = aFrame->GetParent();
-    }
-
-    nsIContent *content = aFrame->GetContent();
-    NS_ABORT_IF_FALSE(content->IsSVG(), "bad cast");
-
-    // a non-scaling stroke is in the screen co-ordinate
-    // space rather so we need to invert the transform
-    // to the screen co-ordinate space to get there.
-    // See http://www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke
-    gfxMatrix transform = nsSVGUtils::GetCTM(
-                            static_cast<nsSVGElement*>(content), true);
-    if (!transform.IsSingular()) {
-      return transform.Invert();
-    }
-  }
-  return gfxMatrix();
-}
-
-// The logic here comes from _cairo_stroke_style_max_distance_from_path
-static gfxRect
-PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                              nsIFrame* aFrame,
-                              double aStyleExpansionFactor,
-                              const gfxMatrix& aMatrix)
-{
-  double style_expansion =
-    aStyleExpansionFactor * nsSVGUtils::GetStrokeWidth(aFrame);
-
-  gfxMatrix matrix = aMatrix;
-  matrix.Multiply(nsSVGUtils::GetStrokeTransform(aFrame));
-
-  double dx = style_expansion * (fabs(matrix.xx) + fabs(matrix.xy));
-  double dy = style_expansion * (fabs(matrix.yy) + fabs(matrix.yx));
-
-  gfxRect strokeExtents = aPathExtents;
-  strokeExtents.Inflate(dx, dy);
-  return strokeExtents;
-}
-
-/*static*/ gfxRect
-nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                                          nsSVGGeometryFrame* aFrame,
-                                          const gfxMatrix& aMatrix)
-{
-  return ::PathExtentsToMaxStrokeExtents(aPathExtents, aFrame, 0.5, aMatrix);
-}
-
-/*static*/ gfxRect
-nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                                          nsTextFrame* aFrame,
-                                          const gfxMatrix& aMatrix)
-{
-  NS_ASSERTION(aFrame->IsSVGText(), "expected an nsTextFrame for SVG text");
-  return ::PathExtentsToMaxStrokeExtents(aPathExtents, aFrame, 0.5, aMatrix);
-}
-
-/*static*/ gfxRect
-nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                                          nsSVGPathGeometryFrame* aFrame,
-                                          const gfxMatrix& aMatrix)
-{
-  double styleExpansionFactor = 0.5;
-
-  if (static_cast<nsSVGPathGeometryElement*>(aFrame->GetContent())->IsMarkable()) {
-    const nsStyleSVG* style = aFrame->GetStyleSVG();
-
-    if (style->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_SQUARE) {
-      styleExpansionFactor = M_SQRT1_2;
-    }
-
-    if (style->mStrokeLinejoin == NS_STYLE_STROKE_LINEJOIN_MITER &&
-        styleExpansionFactor < style->mStrokeMiterlimit &&
-        aFrame->GetContent()->Tag() != nsGkAtoms::line) {
-      styleExpansionFactor = style->mStrokeMiterlimit;
-    }
-  }
-
-  return ::PathExtentsToMaxStrokeExtents(aPathExtents,
-                                         aFrame,
-                                         styleExpansionFactor,
-                                         aMatrix);
-}
-
-// ----------------------------------------------------------------------
-
-/* static */ nscolor
-nsSVGUtils::GetFallbackOrPaintColor(gfxContext *aContext, nsStyleContext *aStyleContext,
-                                    nsStyleSVGPaint nsStyleSVG::*aFillOrStroke)
-{
-  const nsStyleSVGPaint &paint = aStyleContext->GetStyleSVG()->*aFillOrStroke;
-  nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited();
-  bool isServer = paint.mType == eStyleSVGPaintType_Server ||
-                  paint.mType == eStyleSVGPaintType_ObjectFill ||
-                  paint.mType == eStyleSVGPaintType_ObjectStroke;
-  nscolor color = isServer ? paint.mFallbackColor : paint.mPaint.mColor;
-  if (styleIfVisited) {
-    const nsStyleSVGPaint &paintIfVisited =
-      styleIfVisited->GetStyleSVG()->*aFillOrStroke;
-    // To prevent Web content from detecting if a user has visited a URL
-    // (via URL loading triggered by paint servers or performance
-    // differences between paint servers or between a paint server and a
-    // color), we do not allow whether links are visited to change which
-    // paint server is used or switch between paint servers and simple
-    // colors.  A :visited style may only override a simple color with
-    // another simple color.
-    if (paintIfVisited.mType == eStyleSVGPaintType_Color &&
-        paint.mType == eStyleSVGPaintType_Color) {
-      nscolor colors[2] = { color, paintIfVisited.mPaint.mColor };
-      return nsStyleContext::CombineVisitedColors(
-               colors, aStyleContext->RelevantLinkVisited());
-    }
-  }
-  return color;
-}
-
-static void
-SetupFallbackOrPaintColor(gfxContext *aContext, nsStyleContext *aStyleContext,
-                          nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
-                          float aOpacity)
-{
-  nscolor color = nsSVGUtils::GetFallbackOrPaintColor(
-    aContext, aStyleContext, aFillOrStroke);
-
-  aContext->SetColor(gfxRGBA(NS_GET_R(color)/255.0,
-                             NS_GET_G(color)/255.0,
-                             NS_GET_B(color)/255.0,
-                             NS_GET_A(color)/255.0 * aOpacity));
-}
-
-static float
-MaybeOptimizeOpacity(nsIFrame *aFrame, float aFillOrStrokeOpacity)
-{
-  float opacity = aFrame->GetStyleDisplay()->mOpacity;
-  if (opacity < 1 && nsSVGUtils::CanOptimizeOpacity(aFrame)) {
-    return aFillOrStrokeOpacity * opacity;
-  }
-  return aFillOrStrokeOpacity;
-}
-
-/* static */ bool
-nsSVGUtils::SetupObjectPaint(gfxContext *aContext,
-                             gfxTextObjectPaint *aObjectPaint,
-                             const nsStyleSVGPaint &aPaint,
-                             float aOpacity)
-{
-  nsRefPtr<gfxPattern> pattern;
-
-  if (!aObjectPaint) {
-    return false;
-  }
-
-  switch (aPaint.mType) {
-    case eStyleSVGPaintType_ObjectFill:
-      pattern = aObjectPaint->GetFillPattern(aOpacity, aContext->CurrentMatrix());
-      break;
-    case eStyleSVGPaintType_ObjectStroke:
-      pattern = aObjectPaint->GetStrokePattern(aOpacity, aContext->CurrentMatrix());
-      break;
-    default:
-      return false;
-  }
-
-  if (!pattern) {
-    return false;
-  }
-
-  aContext->SetPattern(pattern);
-
-  return true;
-}
-
-bool
-nsSVGUtils::SetupCairoFillPaint(nsIFrame *aFrame, gfxContext* aContext,
-                                gfxTextObjectPaint *aObjectPaint)
-{
-  const nsStyleSVG* style = aFrame->GetStyleSVG();
-  if (style->mFill.mType == eStyleSVGPaintType_None)
-    return false;
-
-  if (style->mFillRule == NS_STYLE_FILL_RULE_EVENODD)
-    aContext->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
-  else
-    aContext->SetFillRule(gfxContext::FILL_RULE_WINDING);
-
-  float opacity = MaybeOptimizeOpacity(aFrame,
-                                       GetOpacity(style->mFillOpacitySource,
-                                                  style->mFillOpacity,
-                                                  aObjectPaint));
-  nsSVGPaintServerFrame *ps =
-    nsSVGEffects::GetPaintServer(aFrame, &style->mFill, nsSVGEffects::FillProperty());
-  if (ps && ps->SetupPaintServer(aContext, aFrame, &nsStyleSVG::mFill, opacity))
-    return true;
-
-  if (SetupObjectPaint(aContext, aObjectPaint, style->mFill, opacity)) {
-    return true;
-  }
-
-  // On failure, use the fallback colour in case we have an
-  // objectBoundingBox where the width or height of the object is zero.
-  // See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
-  SetupFallbackOrPaintColor(aContext, aFrame->GetStyleContext(),
-                            &nsStyleSVG::mFill, opacity);
-
-  return true;
-}
-
-bool
-nsSVGUtils::SetupCairoStrokePaint(nsIFrame *aFrame, gfxContext* aContext,
-                                  gfxTextObjectPaint *aObjectPaint)
-{
-  const nsStyleSVG* style = aFrame->GetStyleSVG();
-  if (style->mStroke.mType == eStyleSVGPaintType_None)
-    return false;
-
-  float opacity = MaybeOptimizeOpacity(aFrame,
-                                       GetOpacity(style->mStrokeOpacitySource,
-                                                  style->mStrokeOpacity,
-                                                  aObjectPaint));
-
-  nsSVGPaintServerFrame *ps =
-    nsSVGEffects::GetPaintServer(aFrame, &style->mStroke, nsSVGEffects::StrokeProperty());
-  if (ps && ps->SetupPaintServer(aContext, aFrame, &nsStyleSVG::mStroke, opacity))
-    return true;
-
-  if (SetupObjectPaint(aContext, aObjectPaint, style->mStroke, opacity)) {
-    return true;
-  }
-
-  // On failure, use the fallback colour in case we have an
-  // objectBoundingBox where the width or height of the object is zero.
-  // See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
-  SetupFallbackOrPaintColor(aContext, aFrame->GetStyleContext(),
-                            &nsStyleSVG::mStroke, opacity);
-
-  return true;
-}
-
-/* static */ float
-nsSVGUtils::GetOpacity(nsStyleSVGOpacitySource aOpacityType,
-                       const float& aOpacity,
-                       gfxTextObjectPaint *aOuterObjectPaint)
-{
-  float opacity = 1.0f;
-  switch (aOpacityType) {
-  case eStyleSVGOpacitySource_Normal:
-    opacity = aOpacity;
-    break;
-  case eStyleSVGOpacitySource_ObjectFillOpacity:
-    if (aOuterObjectPaint) {
-      opacity = aOuterObjectPaint->GetFillOpacity();
-    } else {
-      NS_WARNING("objectFillOpacity used outside of an SVG glyph");
-    }
-    break;
-  case eStyleSVGOpacitySource_ObjectStrokeOpacity:
-    if (aOuterObjectPaint) {
-      opacity = aOuterObjectPaint->GetStrokeOpacity();
-    } else {
-      NS_WARNING("objectStrokeOpacity used outside of an SVG glyph");
-    }
-    break;
-  default:
-    NS_NOTREACHED("Unknown object opacity inheritance type for SVG glyph");
-  }
-  return opacity;
-}
-
-bool
-nsSVGUtils::HasStroke(nsIFrame* aFrame, gfxTextObjectPaint *aObjectPaint)
-{
-  const nsStyleSVG *style = aFrame->GetStyleSVG();
-  return style->mStroke.mType != eStyleSVGPaintType_None &&
-         style->mStrokeOpacity > 0 &&
-         GetStrokeWidth(aFrame, aObjectPaint) > 0;
-}
-
-float
-nsSVGUtils::GetStrokeWidth(nsIFrame* aFrame, gfxTextObjectPaint *aObjectPaint)
-{
-  const nsStyleSVG *style = aFrame->GetStyleSVG();
-  if (aObjectPaint && style->mStrokeWidthFromObject) {
-    return aObjectPaint->GetStrokeWidth();
-  }
-
-  nsIContent* content = aFrame->GetContent();
-  if (content->IsNodeOfType(nsINode::eTEXT)) {
-    content = content->GetParent();
-  }
-
-  nsSVGElement *ctx = static_cast<nsSVGElement*>(content);
-
-  return nsSVGUtils::CoordToFloat(aFrame->PresContext(), ctx,
-                                  style->mStrokeWidth);
-}
-
-void
-nsSVGUtils::SetupCairoStrokeGeometry(nsIFrame* aFrame, gfxContext *aContext,
-                                     gfxTextObjectPaint *aObjectPaint)
-{
-  float width = GetStrokeWidth(aFrame, aObjectPaint);
-  if (width <= 0)
-    return;
-  aContext->SetLineWidth(width);
-
-  // Apply any stroke-specific transform
-  aContext->Multiply(GetStrokeTransform(aFrame));
-
-  const nsStyleSVG* style = aFrame->GetStyleSVG();
-  
-  switch (style->mStrokeLinecap) {
-  case NS_STYLE_STROKE_LINECAP_BUTT:
-    aContext->SetLineCap(gfxContext::LINE_CAP_BUTT);
-    break;
-  case NS_STYLE_STROKE_LINECAP_ROUND:
-    aContext->SetLineCap(gfxContext::LINE_CAP_ROUND);
-    break;
-  case NS_STYLE_STROKE_LINECAP_SQUARE:
-    aContext->SetLineCap(gfxContext::LINE_CAP_SQUARE);
-    break;
-  }
-
-  aContext->SetMiterLimit(style->mStrokeMiterlimit);
-
-  switch (style->mStrokeLinejoin) {
-  case NS_STYLE_STROKE_LINEJOIN_MITER:
-    aContext->SetLineJoin(gfxContext::LINE_JOIN_MITER);
-    break;
-  case NS_STYLE_STROKE_LINEJOIN_ROUND:
-    aContext->SetLineJoin(gfxContext::LINE_JOIN_ROUND);
-    break;
-  case NS_STYLE_STROKE_LINEJOIN_BEVEL:
-    aContext->SetLineJoin(gfxContext::LINE_JOIN_BEVEL);
-    break;
-  }
-}
-
-static bool
-GetStrokeDashData(nsIFrame* aFrame,
-                  FallibleTArray<gfxFloat>& aDashes,
-                  gfxFloat* aDashOffset,
-                  gfxTextObjectPaint *aObjectPaint)
-{
-  const nsStyleSVG* style = aFrame->GetStyleSVG();
-  nsPresContext *presContext = aFrame->PresContext();
-  nsIContent *content = aFrame->GetContent();
-  nsSVGElement *ctx = static_cast<nsSVGElement*>
-    (content->IsNodeOfType(nsINode::eTEXT) ?
-     content->GetParent() : content);
-
-  gfxFloat totalLength = 0.0;
-  if (aObjectPaint && style->mStrokeDasharrayFromObject) {
-    aDashes = aObjectPaint->GetStrokeDashArray();
-
-    for (uint32_t i = 0; i < aDashes.Length(); i++) {
-      if (aDashes[i] < 0.0) {
-        return false;
-      }
-      totalLength += aDashes[i];
-    }
-
-  } else {
-    uint32_t count = style->mStrokeDasharrayLength;
-    if (!count || !aDashes.SetLength(count)) {
-      return false;
-    }
-
-    gfxFloat pathScale = 1.0;
-
-    if (content->Tag() == nsGkAtoms::path) {
-      pathScale = static_cast<nsSVGPathElement*>(content)->
-        GetPathLengthScale(nsSVGPathElement::eForStroking);
-      if (pathScale <= 0) {
-        return false;
-      }
-    }
-
-    const nsStyleCoord *dasharray = style->mStrokeDasharray;
-
-    for (uint32_t i = 0; i < count; i++) {
-      aDashes[i] = nsSVGUtils::CoordToFloat(presContext,
-                                            ctx,
-                                            dasharray[i]) * pathScale;
-      if (aDashes[i] < 0.0) {
-        return false;
-      }
-      totalLength += aDashes[i];
-    }
-  }
-
-  if (aObjectPaint && style->mStrokeDashoffsetFromObject) {
-    *aDashOffset = aObjectPaint->GetStrokeDashOffset();
-  } else {
-    *aDashOffset = nsSVGUtils::CoordToFloat(presContext,
-                                           ctx,
-                                           style->mStrokeDashoffset);
-  }
-  
-  if (content->IsNodeOfType(nsINode::eTEXT)) {
-    content = content->GetParent();
-  }
-
-  return (totalLength > 0.0);
-}
-
-void
-nsSVGUtils::SetupCairoStrokeHitGeometry(nsIFrame* aFrame, gfxContext* aContext,
-                                        gfxTextObjectPaint *aObjectPaint)
-{
-  SetupCairoStrokeGeometry(aFrame, aContext, aObjectPaint);
-
-  AutoFallibleTArray<gfxFloat, 10> dashes;
-  gfxFloat dashOffset;
-  if (GetStrokeDashData(aFrame, dashes, &dashOffset, aObjectPaint)) {
-    aContext->SetDash(dashes.Elements(), dashes.Length(), dashOffset);
-  }
-}
-
-uint16_t
-nsSVGUtils::GetGeometryHitTestFlags(nsIFrame* aFrame)
-{
-  uint16_t flags = 0;
-
-  switch(aFrame->GetStyleVisibility()->mPointerEvents) {
-  case NS_STYLE_POINTER_EVENTS_NONE:
-    break;
-  case NS_STYLE_POINTER_EVENTS_AUTO:
-  case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
-    if (aFrame->GetStyleVisibility()->IsVisible()) {
-      if (aFrame->GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None)
-        flags |= SVG_HIT_TEST_FILL;
-      if (aFrame->GetStyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
-        flags |= SVG_HIT_TEST_STROKE;
-      if (aFrame->GetStyleSVG()->mStrokeOpacity > 0)
-        flags |= SVG_HIT_TEST_CHECK_MRECT;
-    }
-    break;
-  case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
-    if (aFrame->GetStyleVisibility()->IsVisible()) {
-      flags |= SVG_HIT_TEST_FILL;
-    }
-    break;
-  case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
-    if (aFrame->GetStyleVisibility()->IsVisible()) {
-      flags |= SVG_HIT_TEST_STROKE;
-    }
-    break;
-  case NS_STYLE_POINTER_EVENTS_VISIBLE:
-    if (aFrame->GetStyleVisibility()->IsVisible()) {
-      flags |= SVG_HIT_TEST_FILL | SVG_HIT_TEST_STROKE;
-    }
-    break;
-  case NS_STYLE_POINTER_EVENTS_PAINTED:
-    if (aFrame->GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None)
-      flags |= SVG_HIT_TEST_FILL;
-    if (aFrame->GetStyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
-      flags |= SVG_HIT_TEST_STROKE;
-    if (aFrame->GetStyleSVG()->mStrokeOpacity)
-      flags |= SVG_HIT_TEST_CHECK_MRECT;
-    break;
-  case NS_STYLE_POINTER_EVENTS_FILL:
-    flags |= SVG_HIT_TEST_FILL;
-    break;
-  case NS_STYLE_POINTER_EVENTS_STROKE:
-    flags |= SVG_HIT_TEST_STROKE;
-    break;
-  case NS_STYLE_POINTER_EVENTS_ALL:
-    flags |= SVG_HIT_TEST_FILL | SVG_HIT_TEST_STROKE;
-    break;
-  default:
-    NS_ERROR("not reached");
-    break;
-  }
-
-  return flags;
-}
-
-bool
-nsSVGUtils::SetupCairoStroke(nsIFrame* aFrame, gfxContext* aContext,
-                             gfxTextObjectPaint *aObjectPaint)
-{
-  if (!HasStroke(aFrame, aObjectPaint)) {
-    return false;
-  }
-  SetupCairoStrokeHitGeometry(aFrame, aContext, aObjectPaint);
-
-  return SetupCairoStrokePaint(aFrame, aContext, aObjectPaint);
-}
copy from layout/svg/base/src/nsSVGUtils.h
copy to content/svg/content/src/SVGContentUtils.h
--- a/layout/svg/base/src/nsSVGUtils.h
+++ b/content/svg/content/src/SVGContentUtils.h
@@ -1,238 +1,64 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef NS_SVGUTILS_H
-#define NS_SVGUTILS_H
+#ifndef MOZILLA_SVGCONTENTUTILS_H
+#define MOZILLA_SVGCONTENTUTILS_H
 
-// include math.h to pick up definition of M_SQRT1_2 if the platform defines it
+// include math.h to pick up definition of M_ maths defines e.g. M_PI
 #define _USE_MATH_DEFINES
 #include <math.h>
 
 #include "gfxMatrix.h"
-#include "gfxPoint.h"
-#include "gfxRect.h"
-#include "nsAlgorithm.h"
-#include "nsChangeHint.h"
-#include "nsColor.h"
 #include "nsCOMPtr.h"
-#include "nsID.h"
-#include "nsISupportsBase.h"
-#include "nsMathUtils.h"
-#include "nsPoint.h"
-#include "nsRect.h"
-#include "nsStyleStruct.h"
-#include "mozilla/Constants.h"
 
-class gfxASurface;
-class gfxContext;
-class gfxImageSurface;
-class gfxPattern;
-class nsFrameList;
 class nsIContent;
 class nsIDocument;
 class nsIDOMSVGElement;
 class nsIFrame;
-class nsPresContext;
-class nsRenderingContext;
 class nsStyleContext;
-class nsStyleCoord;
-class nsSVGDisplayContainerFrame;
 class nsSVGElement;
-class nsSVGEnum;
-class nsSVGGeometryFrame;
 class nsSVGLength2;
-class nsSVGOuterSVGFrame;
-class nsSVGPathGeometryFrame;
 class nsSVGSVGElement;
-class nsTextFrame;
-class gfxTextObjectPaint;
-
-struct nsStyleSVG;
-struct nsStyleSVGPaint;
 
 namespace mozilla {
 class SVGAnimatedPreserveAspectRatio;
 class SVGPreserveAspectRatio;
 namespace dom {
 class Element;
 } // namespace dom
 } // namespace mozilla
 
-// SVG Frame state bits
-#define NS_STATE_IS_OUTER_SVG                    NS_FRAME_STATE_BIT(20)
-
-/* are we the child of a non-display container? */
-#define NS_STATE_SVG_NONDISPLAY_CHILD            NS_FRAME_STATE_BIT(22)
-
-// If this bit is set, we are a <clipPath> element or descendant.
-#define NS_STATE_SVG_CLIPPATH_CHILD              NS_FRAME_STATE_BIT(23)
-
-/**
- * Byte offsets of channels in a native packed gfxColor or cairo image surface.
- */
-#ifdef IS_BIG_ENDIAN
-#define GFX_ARGB32_OFFSET_A 0
-#define GFX_ARGB32_OFFSET_R 1
-#define GFX_ARGB32_OFFSET_G 2
-#define GFX_ARGB32_OFFSET_B 3
-#else
-#define GFX_ARGB32_OFFSET_A 3
-#define GFX_ARGB32_OFFSET_R 2
-#define GFX_ARGB32_OFFSET_G 1
-#define GFX_ARGB32_OFFSET_B 0
-#endif
-
-// maximum dimension of an offscreen surface - choose so that
-// the surface size doesn't overflow a 32-bit signed int using
-// 4 bytes per pixel; in line with gfxASurface::CheckSurfaceSize
-// In fact Macs can't even manage that
-#define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
-
-#define SVG_WSP_DELIM       "\x20\x9\xD\xA"
-#define SVG_COMMA_WSP_DELIM "," SVG_WSP_DELIM
-
-#define SVG_HIT_TEST_FILL        0x01
-#define SVG_HIT_TEST_STROKE      0x02
-#define SVG_HIT_TEST_CHECK_MRECT 0x04
-
 inline bool
 IsSVGWhitespace(char aChar)
 {
   return aChar == '\x20' || aChar == '\x9' ||
          aChar == '\xD'  || aChar == '\xA';
 }
 
 inline bool
 IsSVGWhitespace(PRUnichar aChar)
 {
   return aChar == PRUnichar('\x20') || aChar == PRUnichar('\x9') ||
          aChar == PRUnichar('\xD')  || aChar == PRUnichar('\xA');
 }
 
-/*
- * Checks the smil enabled preference.  Declared as a function to match
- * NS_SVGEnabled().
- */
-bool NS_SMILEnabled();
-
-bool NS_SVGDisplayListHitTestingEnabled();
-bool NS_SVGDisplayListPaintingEnabled();
-bool NS_SVGTextCSSFramesEnabled();
-
 /**
- * Sometimes we need to distinguish between an empty box and a box
- * that contains an element that has no size e.g. a point at the origin.
+ * Functions generally used by SVG Content classes. Functions here
+ * should not generally depend on layout methods/classes e.g. nsSVGUtils
  */
-class SVGBBox {
-public:
-  SVGBBox() 
-    : mIsEmpty(true) {}
-
-  SVGBBox(const gfxRect& aRect) 
-    : mBBox(aRect), mIsEmpty(false) {}
-
-  SVGBBox& operator=(const gfxRect& aRect) {
-    mBBox = aRect;
-    mIsEmpty = false;
-    return *this;
-  }
-
-  operator const gfxRect& () const {
-    return mBBox;
-  }
-
-  bool IsEmpty() const {
-    return mIsEmpty;
-  }
-
-  void UnionEdges(const SVGBBox& aSVGBBox) {
-    if (aSVGBBox.mIsEmpty) {
-      return;
-    }
-    mBBox = mIsEmpty ? aSVGBBox.mBBox : mBBox.UnionEdges(aSVGBBox.mBBox);
-    mIsEmpty = false;
-  }
-
-private:
-  gfxRect mBBox;
-  bool    mIsEmpty;
-};
-
-// GRRR WINDOWS HATE HATE HATE
-#undef CLIP_MASK
-
-class NS_STACK_CLASS SVGAutoRenderState
-{
-public:
-  enum RenderMode {
-    /**
-     * Used to inform SVG frames that they should paint as normal.
-     */
-    NORMAL, 
-    /** 
-     * Used to inform SVG frames when they are painting as the child of a
-     * simple clipPath. In this case they should only draw their basic geometry
-     * as a path. They should not fill, stroke, or paint anything else.
-     */
-    CLIP, 
-    /** 
-     * Used to inform SVG frames when they are painting as the child of a
-     * complex clipPath that requires the use of a clip mask. In this case they
-     * should only draw their basic geometry as a path and then fill it using
-     * fully opaque white. They should not stroke, or paint anything else.
-     */
-    CLIP_MASK 
-  };
-
-  SVGAutoRenderState(nsRenderingContext *aContext, RenderMode aMode);
-  ~SVGAutoRenderState();
-
-  void SetPaintingToWindow(bool aPaintingToWindow);
-
-  static RenderMode GetRenderMode(nsRenderingContext *aContext);
-  static bool IsPaintingToWindow(nsRenderingContext *aContext);
-
-private:
-  nsRenderingContext *mContext;
-  void *mOriginalRenderState;
-  RenderMode mMode;
-  bool mPaintingToWindow;
-};
-
-
-#define NS_ISVGFILTERPROPERTY_IID \
-{ 0x9744ee20, 0x1bcf, 0x4c62, \
- { 0x86, 0x7d, 0xd3, 0x7a, 0x91, 0x60, 0x3e, 0xef } }
-
-class nsISVGFilterProperty : public nsISupports
-{
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGFILTERPROPERTY_IID)
-  virtual void Invalidate() = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterProperty, NS_ISVGFILTERPROPERTY_IID)
-
-class nsSVGUtils
+class SVGContentUtils
 {
 public:
   typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
   typedef mozilla::SVGPreserveAspectRatio SVGPreserveAspectRatio;
 
-  static void Init();
-
-  /*
-   * Get the parent element of an nsIContent
-   */
-  static mozilla::dom::Element *GetParentElement(nsIContent *aContent);
-
   /*
    * Get the outer SVG element of an nsIContent
    */
   static nsSVGSVGElement *GetOuterSVGElement(nsSVGElement *aSVGElement);
 
   /**
    * Activates the animation element aContent as a result of navigation to the
    * fragment identifier that identifies aContent. aContent must be an instance
@@ -260,487 +86,57 @@ public:
    * XXX document the conditions under which these may fail, and what they
    * return in those cases.
    */
   static float GetFontXHeight(mozilla::dom::Element *aElement);
   static float GetFontXHeight(nsIFrame *aFrame);
   static float GetFontXHeight(nsStyleContext *aStyleContext);
 
   /*
-   * Converts image data from premultipled to unpremultiplied alpha
-   */
-  static void UnPremultiplyImageDataAlpha(uint8_t *data, 
-                                          int32_t stride, 
-                                          const nsIntRect &rect);
-  /*
-   * Converts image data from unpremultipled to premultiplied alpha
-   */
-  static void PremultiplyImageDataAlpha(uint8_t *data, 
-                                        int32_t stride, 
-                                        const nsIntRect &rect);
-  /*
-   * Converts image data from premultiplied sRGB to Linear RGB
-   */
-  static void ConvertImageDataToLinearRGB(uint8_t *data, 
-                                          int32_t stride, 
-                                          const nsIntRect &rect);
-  /*
-   * Converts image data from LinearRGB to premultiplied sRGB
-   */
-  static void ConvertImageDataFromLinearRGB(uint8_t *data, 
-                                            int32_t stride, 
-                                            const nsIntRect &rect);
-
-  /*
    * Report a localized error message to the error console.
    */
   static nsresult ReportToConsole(nsIDocument* doc,
                                   const char* aWarning,
                                   const PRUnichar **aParams,
                                   uint32_t aParamsLength);
 
-  /*
-   * Converts a nsStyleCoord into a userspace value.  Handles units
-   * Factor (straight userspace), Coord (dimensioned), and Percent (of
-   * the current SVG viewport)
-   */
-  static float CoordToFloat(nsPresContext *aPresContext,
-                            nsSVGElement *aContent,
-                            const nsStyleCoord &aCoord);
-
   static gfxMatrix GetCTM(nsSVGElement *aElement, bool aScreenCTM);
 
   /**
    * Check if this is one of the SVG elements that SVG 1.1 Full says
    * establishes a viewport: svg, symbol, image or foreignObject.
    */
   static bool EstablishesViewport(nsIContent *aContent);
 
   static already_AddRefed<nsIDOMSVGElement>
   GetNearestViewportElement(nsIContent *aContent);
 
-  /**
-   * Gets the nearest nsSVGInnerSVGFrame or nsSVGOuterSVGFrame frame. aFrame
-   * must be an SVG frame. If aFrame is of type nsGkAtoms::svgOuterSVGFrame,
-   * returns nullptr.
-   */
-  static nsSVGDisplayContainerFrame* GetNearestSVGViewport(nsIFrame *aFrame);
-
-  /**
-   * Returns the frame's post-filter visual overflow rect when passed the
-   * frame's pre-filter visual overflow rect. If the frame is not currently
-   * being filtered, this function simply returns aUnfilteredRect.
-   */
-  static nsRect GetPostFilterVisualOverflowRect(nsIFrame *aFrame,
-                                                const nsRect &aUnfilteredRect);
-
-  /**
-   * Invalidates the area that is painted by the frame without updating its
-   * bounds.
-   *
-   * This is similar to InvalidateOverflowRect(). It will go away when we
-   * support display list based invalidation of SVG.
-   *
-   * @param aBoundsSubArea If non-null, a sub-area of aFrame's pre-filter
-   *   visual overflow rect that should be invalidated instead of aFrame's
-   *   entire visual overflow rect.
-   */
-  static void InvalidateBounds(nsIFrame *aFrame, bool aDuringUpdate = false,
-                               const nsRect *aBoundsSubArea = nullptr,
-                               uint32_t aFlags = 0);
-
-  /**
-   * Schedules an update of the frame's bounds (which will in turn invalidate
-   * the new area that the frame should paint to).
-   *
-   * This does nothing when passed an NS_STATE_SVG_NONDISPLAY_CHILD frame.
-   * In future we may want to allow ReflowSVG to be called on such frames,
-   * but that would be better implemented as a ForceReflowSVG function to
-   * be called synchronously while painting them without marking or paying
-   * attention to dirty bits like this function.
-   *
-   * This is very similar to PresShell::FrameNeedsReflow. The main reason that
-   * we have this function instead of using FrameNeedsReflow is because we need
-   * to be able to call it under nsSVGOuterSVGFrame::NotifyViewportChange when
-   * that function is called by nsSVGOuterSVGFrame::Reflow. FrameNeedsReflow
-   * is not suitable for calling during reflow though, and it asserts as much.
-   * The reason that we want to be callable under NotifyViewportChange is
-   * because we want to synchronously notify and dirty the nsSVGOuterSVGFrame's
-   * children so that when nsSVGOuterSVGFrame::DidReflow is called its children
-   * will be updated for the new size as appropriate. Otherwise we'd have to
-   * post an event to the event loop to mark dirty flags and request an update.
-   *
-   * Another reason that we don't currently want to call
-   * PresShell::FrameNeedsReflow is because passing eRestyle to it to get it to
-   * mark descendants dirty would cause it to descend through
-   * nsSVGForeignObjectFrame frames to mark their children dirty, but we want to
-   * handle nsSVGForeignObjectFrame specially. It would also do unnecessary work
-   * descending into NS_STATE_SVG_NONDISPLAY_CHILD frames.
-   */
-  static void ScheduleReflowSVG(nsIFrame *aFrame);
-
-  /**
-   * Invalidates the area that the frame last painted to, then schedules an
-   * update of the frame's bounds (which will in turn invalidate the new area
-   * that the frame should paint to).
-   */
-  static void InvalidateAndScheduleReflowSVG(nsIFrame *aFrame);
-
-  /**
-   * Returns true if the frame or any of its children need ReflowSVG
-   * to be called on them.
-   */
-  static bool NeedsReflowSVG(nsIFrame *aFrame);
-
-  /*
-   * Update the filter invalidation region for ancestor frames, if relevant.
-   */
-  static void NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame);
-
   /* enum for specifying coordinate direction for ObjectSpace/UserSpace */
   enum ctxDirection { X, Y, XY };
 
   /**
    * Computes sqrt((aWidth^2 + aHeight^2)/2);
    */
   static double ComputeNormalizedHypotenuse(double aWidth, double aHeight);
 
-  /* Computes the input length in terms of object space coordinates.
-     Input: rect - bounding box
-            length - length to be converted
-  */
-  static float ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength);
-
-  /* Computes the input length in terms of user space coordinates.
-     Input: content - object to be used for determining user space
-     Input: length - length to be converted
-  */
-  static float UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength);
-
-  /* Computes the input length in terms of user space coordinates.
-     Input: aFrame - object to be used for determining user space
-            length - length to be converted
-  */
-  static float UserSpace(nsIFrame *aFrame, const nsSVGLength2 *aLength);
-
   /* Returns the angle halfway between the two specified angles */
   static float
   AngleBisect(float a1, float a2);
 
-  /* Find the outermost SVG frame of the passed frame */
-  static nsSVGOuterSVGFrame *
-  GetOuterSVGFrame(nsIFrame *aFrame);
-
-  /**
-   * Get the covered region for a frame. Return null if it's not an SVG frame.
-   * @param aRect gets a rectangle in app units
-   * @return the outer SVG frame which aRect is relative to
-   */
-  static nsIFrame*
-  GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect);
-
   /* Generate a viewbox to viewport tranformation matrix */
 
   static gfxMatrix
   GetViewBoxTransform(const nsSVGElement* aElement,
                       float aViewportWidth, float aViewportHeight,
                       float aViewboxX, float aViewboxY,
                       float aViewboxWidth, float aViewboxHeight,
                       const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio);
 
   static gfxMatrix
   GetViewBoxTransform(const nsSVGElement* aElement,
                       float aViewportWidth, float aViewportHeight,
                       float aViewboxX, float aViewboxY,
                       float aViewboxWidth, float aViewboxHeight,
                       const SVGPreserveAspectRatio &aPreserveAspectRatio);
 
-  /* Paint SVG frame with SVG effects - aDirtyRect is the area being
-   * redrawn, in device pixel coordinates relative to the outer svg */
-  static void
-  PaintFrameWithEffects(nsRenderingContext *aContext,
-                        const nsIntRect *aDirtyRect,
-                        nsIFrame *aFrame);
-
-  /* Hit testing - check if point hits the clipPath of indicated
-   * frame.  Returns true if no clipPath set. */
-  static bool
-  HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint);
-  
-  /* Hit testing - check if point hits any children of frame. */
-
-  static nsIFrame *
-  HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint);
-
-  /*
-   * Returns the CanvasTM of the indicated frame, whether it's a
-   * child SVG frame, container SVG frame, or a regular frame.
-   * For regular frames, we just return an identity matrix.
-   */
-  static gfxMatrix GetCanvasTM(nsIFrame* aFrame, uint32_t aFor);
-
-  /**
-   * Returns the transform from aFrame's user space to canvas space. Only call
-   * with SVG frames. This is like GetCanvasTM, except that it only includes
-   * the transforms from aFrame's user space (i.e. the coordinate context
-   * established by its 'transform' attribute, or else the coordinate context
-   * that its _parent_ establishes for its children) to outer-<svg> device
-   * space. Specifically, it does not include any other transforms introduced
-   * by the frame such as x/y offsets and viewBox attributes.
-   */
-  static gfxMatrix GetUserToCanvasTM(nsIFrame* aFrame, uint32_t aFor);
-
-  /**
-   * Notify the descendants of aFrame of a change to one of their ancestors
-   * that might affect them.
-   *
-   * If the changed ancestor renders and needs to be invalidated, it should
-   * call nsSVGUtils::InvalidateAndScheduleBoundsUpdate or
-   * nsSVGUtils::InvalidateBounds _before_ calling this method. That makes it
-   * cheaper when descendants schedule their own bounds update because the code
-   * that walks up the parent chain marking dirty bits can stop earlier.
-   */
-  static void
-  NotifyChildrenOfSVGChange(nsIFrame *aFrame, uint32_t aFlags);
-
-  /*
-   * Get frame's covered region by walking the children and doing union.
-   */
-  static nsRect
-  GetCoveredRegion(const nsFrameList &aFrames);
-
-  // Converts aPoint from an app unit point in outer-<svg> content rect space
-  // to an app unit point in a frame's SVG userspace. 
-  // This is a temporary helper we should no longer need after bug 614732 is
-  // fixed.
-  static nsPoint
-  TransformOuterSVGPointToChildFrame(nsPoint aPoint,
-                                     const gfxMatrix& aFrameToCanvasTM,
-                                     nsPresContext* aPresContext);
-
-  static nsRect
-  TransformFrameRectToOuterSVG(const nsRect& aRect,
-                               const gfxMatrix& aMatrix,
-                               nsPresContext* aPresContext);
-
-  /*
-   * Convert a surface size to an integer for use by thebes
-   * possibly making it smaller in the process so the surface does not
-   * use excessive memory.
-   *
-   * @param aSize the desired surface size
-   * @param aResultOverflows true if the desired surface size is too big
-   * @return the surface size to use
-   */
-  static gfxIntSize ConvertToSurfaceSize(const gfxSize& aSize,
-                                         bool *aResultOverflows);
-
-  /*
-   * Hit test a given rectangle/matrix.
-   */
-  static bool
-  HitTestRect(const gfxMatrix &aMatrix,
-              float aRX, float aRY, float aRWidth, float aRHeight,
-              float aX, float aY);
-
-
-  /**
-   * Get the clip rect for the given frame, taking into account the CSS 'clip'
-   * property. See:
-   * http://www.w3.org/TR/SVG11/masking.html#OverflowAndClipProperties
-   * The arguments for aX, aY, aWidth and aHeight should be the dimensions of
-   * the viewport established by aFrame.
-   */
-  static gfxRect
-  GetClipRectForFrame(nsIFrame *aFrame,
-                      float aX, float aY, float aWidth, float aHeight);
-
-  static void CompositeSurfaceMatrix(gfxContext *aContext,
-                                     gfxASurface *aSurface,
-                                     const gfxMatrix &aCTM, float aOpacity);
-
-  static void CompositePatternMatrix(gfxContext *aContext,
-                                     gfxPattern *aPattern,
-                                     const gfxMatrix &aCTM, float aWidth, float aHeight, float aOpacity);
-
-  static void SetClipRect(gfxContext *aContext,
-                          const gfxMatrix &aCTM,
-                          const gfxRect &aRect);
-
-  /**
-   * Restricts aRect to pixels that intersect aGfxRect.
-   */
-  static void ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect);
-
-  /* Using group opacity instead of fill or stroke opacity on a
-   * geometry object seems to be a common authoring mistake.  If we're
-   * not applying filters and not both stroking and filling, we can
-   * generate the same result without going through the overhead of a
-   * push/pop group. */
-  static bool
-  CanOptimizeOpacity(nsIFrame *aFrame);
-
-  /* Calculate the maximum expansion of a matrix */
-  static float
-  MaxExpansion(const gfxMatrix &aMatrix);
-
-  /**
-   * Take the CTM to userspace for an element, and adjust it to a CTM to its
-   * object bounding box space if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX.
-   * (I.e. so that [0,0] is at the top left of its bbox, and [1,1] is at the
-   * bottom right of its bbox).
-   *
-   * If the bbox is empty, this will return a singular matrix.
-   */
-  static gfxMatrix
-  AdjustMatrixForUnits(const gfxMatrix &aMatrix,
-                       nsSVGEnum *aUnits,
-                       nsIFrame *aFrame);
-
-  enum BBoxFlags {
-    eBBoxIncludeFill           = 1 << 0,
-    eBBoxIncludeFillGeometry   = 1 << 1,
-    eBBoxIncludeStroke         = 1 << 2,
-    eBBoxIncludeStrokeGeometry = 1 << 3,
-    eBBoxIncludeMarkers        = 1 << 4
-  };
-  /**
-   * Get the SVG bbox (the SVG spec's simplified idea of bounds) of aFrame in
-   * aFrame's userspace.
-   */
-  static gfxRect GetBBox(nsIFrame *aFrame,
-                         uint32_t aFlags = eBBoxIncludeFillGeometry);
-
-  /**
-   * Convert a userSpaceOnUse/objectBoundingBoxUnits rectangle that's specified
-   * using four nsSVGLength2 values into a user unit rectangle in user space.
-   *
-   * @param aXYWH pointer to 4 consecutive nsSVGLength2 objects containing
-   * the x, y, width and height values in that order
-   * @param aBBox the bounding box of the object the rect is relative to;
-   * may be null if aUnits is not SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
-   * @param aFrame the object in which to interpret user-space units;
-   * may be null if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
-   */
-  static gfxRect
-  GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH,
-                  const gfxRect &aBBox, nsIFrame *aFrame);
-
-  /**
-   * Find the first frame, starting with aStartFrame and going up its
-   * parent chain, that is not an svgAFrame.
-   */
-  static nsIFrame* GetFirstNonAAncestorFrame(nsIFrame* aStartFrame);
-
-#ifdef DEBUG
-  static void
-  WritePPM(const char *fname, gfxImageSurface *aSurface);
-#endif
-
-  static bool OuterSVGIsCallingReflowSVG(nsIFrame *aFrame);
-
-  /*
-   * Get any additional transforms that apply only to stroking
-   * e.g. non-scaling-stroke
-   */
-  static gfxMatrix GetStrokeTransform(nsIFrame *aFrame);
-
-  /**
-   * Compute the maximum possible device space stroke extents of a path given
-   * the path's device space path extents, its stroke style and its ctm.
-   *
-   * This is a workaround for the lack of suitable cairo API for getting the
-   * tight device space stroke extents of a path. This basically gives us the
-   * tightest extents that we can guarantee fully enclose the inked stroke
-   * without doing the calculations for the actual tight extents. We exploit
-   * the fact that cairo does have an API for getting the tight device space
-   * fill/path extents.
-   *
-   * This should die once bug 478152 is fixed.
-   */
-  static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                                               nsSVGGeometryFrame* aFrame,
-                                               const gfxMatrix& aMatrix);
-  static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                                               nsTextFrame* aFrame,
-                                               const gfxMatrix& aMatrix);
-  static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
-                                               nsSVGPathGeometryFrame* aFrame,
-                                               const gfxMatrix& aMatrix);
-
-  /**
-   * Convert a floating-point value to a 32-bit integer value, clamping to
-   * the range of valid integers.
-   */
-  static int32_t ClampToInt(double aVal)
-  {
-    return NS_lround(NS_MAX(double(PR_INT32_MIN),
-                            NS_MIN(double(PR_INT32_MAX), aVal)));
-  }
-
-  static nscolor GetFallbackOrPaintColor(gfxContext *aContext,
-                                         nsStyleContext *aStyleContext,
-                                         nsStyleSVGPaint nsStyleSVG::*aFillOrStroke);
-
-  /**
-   * Set up cairo context with an object pattern
-   */
-  static bool SetupObjectPaint(gfxContext *aContext,
-                               gfxTextObjectPaint *aObjectPaint,
-                               const nsStyleSVGPaint& aPaint,
-                               float aOpacity);
-
-  /**
-   * Sets the current paint on the specified gfxContent to be the SVG 'fill'
-   * for the given frame.
-   */
-  static bool SetupCairoFillPaint(nsIFrame* aFrame, gfxContext* aContext,
-                                  gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  /**
-   * Sets the current paint on the specified gfxContent to be the SVG 'stroke'
-   * for the given frame.
-   */
-  static bool SetupCairoStrokePaint(nsIFrame* aFrame, gfxContext* aContext,
-                                    gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  static float GetOpacity(nsStyleSVGOpacitySource aOpacityType,
-                          const float& aOpacity,
-                          gfxTextObjectPaint *aOuterObjectPaint);
-
-  /*
-   * @return false if there is no stroke
-   */
-  static bool HasStroke(nsIFrame* aFrame,
-                        gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  static float GetStrokeWidth(nsIFrame* aFrame,
-                              gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  /*
-   * Set up a cairo context for measuring a stroked path
-   */
-  static void SetupCairoStrokeGeometry(nsIFrame* aFrame, gfxContext *aContext,
-                                       gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  /*
-   * Set up a cairo context for hit testing a stroked path
-   */
-  static void SetupCairoStrokeHitGeometry(nsIFrame* aFrame, gfxContext *aContext,
-                                          gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  /*
-   * Set up a cairo context for stroking, including setting up any stroke-related
-   * properties such as dashing and setting the current paint on the gfxContext.
-   */
-  static bool SetupCairoStroke(nsIFrame* aFrame, gfxContext *aContext,
-                               gfxTextObjectPaint *aObjectPaint = nullptr);
-
-  /**
-   * This function returns a set of bit flags indicating which parts of the
-   * element (fill, stroke, bounds) should intercept pointer events. It takes
-   * into account the type of element and the value of the 'pointer-events'
-   * property on the element.
-   */
-  static uint16_t GetGeometryHitTestFlags(nsIFrame* aFrame);
 };
 
 #endif
--- a/content/svg/content/src/SVGLength.cpp
+++ b/content/svg/content/src/SVGLength.cpp
@@ -4,20 +4,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "SVGLength.h"
 #include "nsSVGElement.h"
 #include "nsSVGSVGElement.h"
 #include "nsString.h"
-#include "nsSVGUtils.h"
 #include "nsTextFormatter.h"
 #include "prdtoa.h"
 #include "nsMathUtils.h"
+#include "SVGContentUtils.h"
 #include <limits>
 
 namespace mozilla {
 
 // Declare some helpers defined below:
 static void GetUnitString(nsAString& unit, uint16_t unitType);
 static uint16_t GetUnitTypeForString(const nsAString& unitStr);
 
@@ -52,17 +52,17 @@ SVGLength::SetValueFromString(const nsAS
   if (unit != str && NS_finite(tmpValue)) {
     char *theRest = unit;
     while (*theRest != '\0' && !IsSVGWhitespace(*theRest)) {
       ++theRest;
     }
     tmpUnit = GetUnitTypeForString(
                 Substring(aValue, unit - str, theRest - unit));
     if (tmpUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN) {
-      // nsSVGUtils::ReportToConsole
+      // SVGContentUtils::ReportToConsole
       return false;
     }
     while (*theRest && IsSVGWhitespace(*theRest)) {
       ++theRest;
     }
     if (!*theRest) {
       mValue = tmpValue;
       mUnit = tmpUnit;
@@ -173,19 +173,19 @@ SVGLength::GetUserUnitsPerUnit(const nsS
       return GetUserUnitsPerInch();
     case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
       return (1.0f/POINTS_PER_INCH_FLOAT) * GetUserUnitsPerInch();
     case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
       return (12.0f/POINTS_PER_INCH_FLOAT) * GetUserUnitsPerInch();
     case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
       return GetUserUnitsPerPercent(aElement, aAxis);
     case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
-      return nsSVGUtils::GetFontSize(const_cast<nsSVGElement*>(aElement));
+      return SVGContentUtils::GetFontSize(const_cast<nsSVGElement*>(aElement));
     case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
-      return nsSVGUtils::GetFontXHeight(const_cast<nsSVGElement*>(aElement));
+      return SVGContentUtils::GetFontXHeight(const_cast<nsSVGElement*>(aElement));
     default:
       NS_NOTREACHED("Unknown unit type");
       return std::numeric_limits<float>::quiet_NaN();
   }
 }
 
 /* static */ float
 SVGLength::GetUserUnitsPerPercent(const nsSVGElement *aElement, uint8_t aAxis)
--- a/content/svg/content/src/SVGLengthList.cpp
+++ b/content/svg/content/src/SVGLengthList.cpp
@@ -1,22 +1,22 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SVGLengthList.h"
-#include "SVGAnimatedLengthList.h"
-#include "SVGLength.h"
-#include "nsSVGElement.h"
+#include "nsCharSeparatedTokenizer.h"
 #include "nsError.h"
 #include "nsString.h"
-#include "nsSVGUtils.h"
-#include "nsCharSeparatedTokenizer.h"
+#include "nsSVGElement.h"
 #include "string.h"
+#include "SVGAnimatedLengthList.h"
+#include "SVGContentUtils.h"
+#include "SVGLength.h"
 
 namespace mozilla {
 
 nsresult
 SVGLengthList::CopyFrom(const SVGLengthList& rhs)
 {
   if (!mLengths.SetCapacity(rhs.Length())) {
     // Yes, we do want fallible alloc here
--- a/content/svg/content/src/SVGLengthListSMILType.cpp
+++ b/content/svg/content/src/SVGLengthListSMILType.cpp
@@ -119,17 +119,17 @@ SVGLengthListSMILType::Add(nsSMILValue& 
     return NS_OK;
   }
   NS_ABORT_IF_FALSE(dest.Element() == valueToAdd.Element(),
                     "adding values from different elements...?");
 
   // Zero-pad our |dest| list, if necessary.
   if (dest.Length() < valueToAdd.Length()) {
     if (!dest.CanZeroPadList()) {
-      // nsSVGUtils::ReportToConsole
+      // SVGContentUtils::ReportToConsole
       return NS_ERROR_FAILURE;
     }
 
     NS_ABORT_IF_FALSE(valueToAdd.CanZeroPadList(),
                       "values disagree about attribute's zero-paddibility");
 
     uint32_t i = dest.Length();
     if (!dest.SetLength(valueToAdd.Length())) {
@@ -183,17 +183,17 @@ SVGLengthListSMILType::ComputeDistance(c
                (from.CanZeroPadList() && from.IsEmpty()) ||
                (to.CanZeroPadList() && to.IsEmpty()),
                "Only \"zero\" nsSMILValues from the SMIL engine should "
                "return true for CanZeroPadList() when the attribute "
                "being animated can't be zero padded");
 
   if ((from.Length() < to.Length() && !from.CanZeroPadList()) ||
       (to.Length() < from.Length() && !to.CanZeroPadList())) {
-    // nsSVGUtils::ReportToConsole
+    // SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
 
   // We return the root of the sum of the squares of the deltas between the
   // user unit values of the lengths at each correspanding index. In the
   // general case, paced animation is probably not useful, but this strategy at
   // least does the right thing for paced animation in the face of simple
   // 'values' lists such as:
@@ -258,17 +258,17 @@ SVGLengthListSMILType::Interpolate(const
                (start.CanZeroPadList() && start.IsEmpty()) ||
                (end.CanZeroPadList() && end.IsEmpty()),
                "Only \"zero\" nsSMILValues from the SMIL engine should "
                "return true for CanZeroPadList() when the attribute "
                "being animated can't be zero padded");
 
   if ((start.Length() < end.Length() && !start.CanZeroPadList()) ||
       (end.Length() < start.Length() && !end.CanZeroPadList())) {
-    // nsSVGUtils::ReportToConsole
+    // SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
 
   if (!result.SetLength(NS_MAX(start.Length(), end.Length()))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   uint32_t i = 0;
--- a/content/svg/content/src/SVGMotionSMILPathUtils.cpp
+++ b/content/svg/content/src/SVGMotionSMILPathUtils.cpp
@@ -1,20 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SVGMotionSMILPathUtils.h"
-#include "nsSVGElement.h"
-#include "SVGLength.h"
-#include "nsContentCreatorFunctions.h" // For NS_NewSVGElement
 #include "nsCharSeparatedTokenizer.h"
 #include "nsContentUtils.h"
-#include "nsSVGUtils.h"
+#include "nsSVGElement.h"
+#include "SVGContentUtils.h"
+#include "SVGLength.h"
 
 namespace mozilla {
 
 //----------------------------------------------------------------------
 // PathGenerator methods
 
 // For the dummy 'from' value used in pure by-animation & to-animation
 void
@@ -108,18 +107,18 @@ SVGMotionSMILPathUtils::PathGenerator::
     return false;
   }
 
   if (tokenizer.lastTokenEndedWithSeparator() || // Trailing comma.
       tokenizer.hasMoreTokens()) {               // More text remains
     return false;
   }
 
-  float xRes = x.GetValueInUserUnits(mSVGElement, nsSVGUtils::X);
-  float yRes = y.GetValueInUserUnits(mSVGElement, nsSVGUtils::Y);
+  float xRes = x.GetValueInUserUnits(mSVGElement, SVGContentUtils::X);
+  float yRes = y.GetValueInUserUnits(mSVGElement, SVGContentUtils::Y);
 
   NS_ENSURE_FINITE2(xRes, yRes, false);
 
   aXVal = xRes;
   aYVal = yRes;
   return true;
 }
 
--- a/content/svg/content/src/SVGNumberList.cpp
+++ b/content/svg/content/src/SVGNumberList.cpp
@@ -1,26 +1,26 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "SVGNumberList.h"
-#include "SVGAnimatedNumberList.h"
-#include "nsSVGElement.h"
+#include "nsCharSeparatedTokenizer.h"
 #include "nsError.h"
+#include "nsMathUtils.h"
 #include "nsString.h"
-#include "nsSVGUtils.h"
-#include "string.h"
+#include "nsSVGElement.h"
+#include "nsTextFormatter.h"
 #include "prdtoa.h"
-#include "nsTextFormatter.h"
-#include "nsCharSeparatedTokenizer.h"
-#include "nsMathUtils.h"
+#include "string.h"
+#include "SVGAnimatedNumberList.h"
+#include "SVGContentUtils.h"
 
 namespace mozilla {
 
 nsresult
 SVGNumberList::CopyFrom(const SVGNumberList& rhs)
 {
   if (!mNumbers.SetCapacity(rhs.Length())) {
     // Yes, we do want fallible alloc here
--- a/content/svg/content/src/SVGNumberListSMILType.cpp
+++ b/content/svg/content/src/SVGNumberListSMILType.cpp
@@ -111,17 +111,17 @@ SVGNumberListSMILType::Add(nsSMILValue& 
     }
     dest.SetInfo(valueToAdd.Element()); // propagate target element info!
     return NS_OK;
   }
   NS_ABORT_IF_FALSE(dest.Element() == valueToAdd.Element(),
                     "adding values from different elements...?");
   if (dest.Length() != valueToAdd.Length()) {
     // For now we only support animation between lists with the same number of
-    // items. nsSVGUtils::ReportToConsole
+    // items. SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
   for (uint32_t i = 0; i < dest.Length(); ++i) {
     dest[i] += aCount * valueToAdd[i];
   }
   dest.SetInfo(valueToAdd.Element()); // propagate target element info!
   return NS_OK;
 }
@@ -136,17 +136,17 @@ SVGNumberListSMILType::ComputeDistance(c
 
   const SVGNumberListAndInfo& from =
     *static_cast<const SVGNumberListAndInfo*>(aFrom.mU.mPtr);
   const SVGNumberListAndInfo& to =
     *static_cast<const SVGNumberListAndInfo*>(aTo.mU.mPtr);
 
   if (from.Length() != to.Length()) {
     // Lists in the 'values' attribute must have the same length.
-    // nsSVGUtils::ReportToConsole
+    // SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
 
   // We return the root of the sum of the squares of the delta between the
   // numbers at each correspanding index.
 
   double total = 0.0;
 
@@ -184,17 +184,17 @@ SVGNumberListSMILType::Interpolate(const
 
   NS_ABORT_IF_FALSE(end.Element(), "Can't propagate target element");
   NS_ABORT_IF_FALSE(start.Element() == end.Element() || !start.Element(),
                     "Different target elements");
 
   if (start.Element() && // 'start' is not an "identity" value
       start.Length() != end.Length()) {
     // For now we only support animation between lists of the same length.
-    // nsSVGUtils::ReportToConsole
+    // SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
   if (!result.SetLength(end.Length())) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   result.SetInfo(end.Element()); // propagate target element info!
 
--- a/content/svg/content/src/SVGPathData.cpp
+++ b/content/svg/content/src/SVGPathData.cpp
@@ -1,24 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SVGPathData.h"
-#include "SVGPathSegUtils.h"
-#include "nsSVGElement.h"
+#include "gfxPlatform.h"
 #include "nsError.h"
 #include "nsString.h"
-#include "nsSVGUtils.h"
-#include "string.h"
+#include "nsSVGElement.h"
 #include "nsSVGPathDataParser.h"
 #include "nsSVGPathGeometryElement.h" // for nsSVGMark
-#include "gfxPlatform.h"
 #include <stdarg.h>
+#include "string.h"
+#include "SVGContentUtils.h"
+#include "SVGPathSegUtils.h"
 
 using namespace mozilla;
 
 static bool IsMoveto(uint16_t aSegType)
 {
   return aSegType == nsIDOMSVGPathSeg::PATHSEG_MOVETO_ABS ||
          aSegType == nsIDOMSVGPathSeg::PATHSEG_MOVETO_REL;
 }
@@ -808,32 +808,32 @@ SVGPathData::GetMarkerPositioningData(ns
         pathStartAngle = mark.angle = segStartAngle;
       } else if (IsMoveto(segType) && !IsMoveto(prevSegType)) {
         // end of a subpath
         if (prevSegType != nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH)
           mark.angle = prevSegEndAngle;
       } else {
         if (!(segType == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH &&
               prevSegType == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH))
-          mark.angle = nsSVGUtils::AngleBisect(prevSegEndAngle, segStartAngle);
+          mark.angle = SVGContentUtils::AngleBisect(prevSegEndAngle, segStartAngle);
       }
     }
 
     // Add the mark at the end of this segment, and set its position:
     if (!aMarks->AppendElement(nsSVGMark(static_cast<float>(segEnd.x),
                                          static_cast<float>(segEnd.y), 0))) {
       aMarks->Clear(); // OOM, so try to free some
       return;
     }
 
     if (segType == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH &&
         prevSegType != nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH) {
       aMarks->ElementAt(aMarks->Length() - 1).angle =
         //aMarks->ElementAt(pathStartIndex).angle =
-        nsSVGUtils::AngleBisect(segEndAngle, pathStartAngle);
+        SVGContentUtils::AngleBisect(segEndAngle, pathStartAngle);
     }
 
     prevSegType = segType;
     prevSegEnd = segEnd;
     prevSegEndAngle = segEndAngle;
   }
 
   NS_ABORT_IF_FALSE(i == mData.Length(), "Very, very bad - mData corrupt");
--- a/content/svg/content/src/SVGPathSegListSMILType.cpp
+++ b/content/svg/content/src/SVGPathSegListSMILType.cpp
@@ -413,17 +413,17 @@ SVGPathSegListSMILType::Add(nsSMILValue&
 
   if (!dest.IsIdentity()) {
     // Neither value is identity; make sure they're compatible.
     NS_ABORT_IF_FALSE(dest.Element() == valueToAdd.Element(),
                       "adding values from different elements...?");
 
     PathInterpolationResult check = CanInterpolate(dest, valueToAdd);
     if (check == eCannotInterpolate) {
-      // nsSVGUtils::ReportToConsole - can't add path segment lists with
+      // SVGContentUtils::ReportToConsole - can't add path segment lists with
       // different numbers of segments, with arcs that have different flag
       // values, or with incompatible segment types.
       return NS_ERROR_FAILURE;
     }
     if (check == eRequiresConversion) {
       // Convert dest, in-place, to match the types in valueToAdd:
       ConvertAllPathSegmentData(dest.begin(), dest.end(),
                                 valueToAdd.begin(), valueToAdd.end(),
@@ -441,17 +441,17 @@ SVGPathSegListSMILType::ComputeDistance(
                                         const nsSMILValue& aTo,
                                         double& aDistance) const
 {
   NS_PRECONDITION(aFrom.mType == this, "Unexpected SMIL type");
   NS_PRECONDITION(aTo.mType == this, "Incompatible SMIL type");
 
   // See https://bugzilla.mozilla.org/show_bug.cgi?id=522306#c18
 
-  // nsSVGUtils::ReportToConsole
+  // SVGContentUtils::ReportToConsole
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
 SVGPathSegListSMILType::Interpolate(const nsSMILValue& aStartVal,
                                     const nsSMILValue& aEndVal,
                                     double aUnitDistance,
                                     nsSMILValue& aResult) const
@@ -469,17 +469,17 @@ SVGPathSegListSMILType::Interpolate(cons
   SVGPathDataAndOwner& result =
     *static_cast<SVGPathDataAndOwner*>(aResult.mU.mPtr);
   NS_ABORT_IF_FALSE(result.IsIdentity(),
                     "expecting outparam to start out as identity");
 
   PathInterpolationResult check = CanInterpolate(start, end); 
 
   if (check == eCannotInterpolate) {
-    // nsSVGUtils::ReportToConsole - can't interpolate path segment lists with
+    // SVGContentUtils::ReportToConsole - can't interpolate path segment lists with
     // different numbers of segments, with arcs with different flag values, or
     // with incompatible segment types.
     return NS_ERROR_FAILURE;
   }
 
   const SVGPathDataAndOwner* startListToUse = &start;
   if (check == eRequiresConversion) {
     // Can't convert |start| in-place, since it's const. Instead, we copy it
--- a/content/svg/content/src/SVGPointList.cpp
+++ b/content/svg/content/src/SVGPointList.cpp
@@ -1,26 +1,26 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "SVGPointList.h"
-#include "SVGAnimatedPointList.h"
-#include "nsSVGElement.h"
 #include "nsError.h"
-#include "nsString.h"
-#include "nsSVGUtils.h"
-#include "string.h"
-#include "prdtoa.h"
-#include "nsTextFormatter.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsMathUtils.h"
+#include "nsString.h"
+#include "nsSVGElement.h"
+#include "nsTextFormatter.h"
+#include "prdtoa.h"
+#include "string.h"
+#include "SVGAnimatedPointList.h"
+#include "SVGContentUtils.h"
 
 namespace mozilla {
 
 nsresult
 SVGPointList::CopyFrom(const SVGPointList& rhs)
 {
   if (!SetCapacity(rhs.Length())) {
     // Yes, we do want fallible alloc here
--- a/content/svg/content/src/SVGPointListSMILType.cpp
+++ b/content/svg/content/src/SVGPointListSMILType.cpp
@@ -94,17 +94,17 @@ SVGPointListSMILType::Add(nsSMILValue& a
     }
     dest.SetInfo(valueToAdd.Element()); // propagate target element info!
     return NS_OK;
   }
   NS_ABORT_IF_FALSE(dest.Element() == valueToAdd.Element(),
                     "adding values from different elements...?");
   if (dest.Length() != valueToAdd.Length()) {
     // For now we only support animation between lists with the same number of
-    // items. nsSVGUtils::ReportToConsole
+    // items. SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
   for (uint32_t i = 0; i < dest.Length(); ++i) {
     dest[i] += aCount * valueToAdd[i];
   }
   dest.SetInfo(valueToAdd.Element()); // propagate target element info!
   return NS_OK;
 }
@@ -119,17 +119,17 @@ SVGPointListSMILType::ComputeDistance(co
 
   const SVGPointListAndInfo& from =
     *static_cast<const SVGPointListAndInfo*>(aFrom.mU.mPtr);
   const SVGPointListAndInfo& to =
     *static_cast<const SVGPointListAndInfo*>(aTo.mU.mPtr);
 
   if (from.Length() != to.Length()) {
     // Lists in the 'values' attribute must have the same length.
-    // nsSVGUtils::ReportToConsole
+    // SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
 
   // We return the root of the sum of the squares of the distances between the
   // points at each corresponding index.
 
   double total = 0.0;
 
@@ -168,17 +168,17 @@ SVGPointListSMILType::Interpolate(const 
 
   NS_ABORT_IF_FALSE(end.Element(), "Can't propagate target element");
   NS_ABORT_IF_FALSE(start.Element() == end.Element() || !start.Element(),
                     "Different target elements");
 
   if (start.Element() && // 'start' is not an "identity" value
       start.Length() != end.Length()) {
     // For now we only support animation between lists of the same length.
-    // nsSVGUtils::ReportToConsole
+    // SVGContentUtils::ReportToConsole
     return NS_ERROR_FAILURE;
   }
   if (!result.SetLength(end.Length())) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   result.SetInfo(end.Element()); // propagate target element info!
 
--- a/content/svg/content/src/SVGStringList.cpp
+++ b/content/svg/content/src/SVGStringList.cpp
@@ -1,24 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "SVGStringList.h"
+#include "nsError.h"
+#include "nsCharSeparatedTokenizer.h"
+#include "nsMathUtils.h"
+#include "nsString.h"
 #include "nsSVGElement.h"
-#include "nsError.h"
-#include "nsString.h"
-#include "nsSVGUtils.h"
 #include "nsTextFormatter.h"
 #include "nsWhitespaceTokenizer.h"
-#include "nsCharSeparatedTokenizer.h"
-#include "nsMathUtils.h"
+#include "SVGContentUtils.h"
 
 namespace mozilla {
 
 nsresult
 SVGStringList::CopyFrom(const SVGStringList& rhs)
 {
   if (!mStrings.SetCapacity(rhs.Length())) {
     // Yes, we do want fallible alloc here
--- a/content/svg/content/src/SVGTransform.cpp
+++ b/content/svg/content/src/SVGTransform.cpp
@@ -5,17 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsError.h"
 #include "SVGTransform.h"
 #include "nsContentUtils.h"
 #include "nsTextFormatter.h"
 
 namespace {
-  const double radPerDegree = 2.0*3.1415926535 / 360.0;
+  const double radPerDegree = 2.0 * M_PI / 360.0;
 }
 
 namespace mozilla {
 
 void
 SVGTransform::GetValueAsString(nsAString& aValue) const
 {
   PRUnichar buf[256];
--- a/content/svg/content/src/nsSVGAngle.cpp
+++ b/content/svg/content/src/nsSVGAngle.cpp
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsSVGAngle.h"
 #include "prdtoa.h"
 #include "nsTextFormatter.h"
-#include "nsSVGUtils.h"
 #include "nsSVGMarkerElement.h"
 #include "nsMathUtils.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
 #include "nsSMILValue.h"
 #include "SVGOrientSMILType.h"
 #include "mozilla/Attributes.h"
 
 using namespace mozilla;
--- a/content/svg/content/src/nsSVGAnimationElement.cpp
+++ b/content/svg/content/src/nsSVGAnimationElement.cpp
@@ -418,17 +418,17 @@ nsSVGAnimationElement::ActivateByHyperli
 }
 
 //----------------------------------------------------------------------
 // Implementation helpers
 
 nsSMILTimeContainer*
 nsSVGAnimationElement::GetTimeContainer()
 {
-  nsSVGSVGElement *element = nsSVGUtils::GetOuterSVGElement(this);
+  nsSVGSVGElement *element = SVGContentUtils::GetOuterSVGElement(this);
 
   if (element) {
     return element->GetTimedDocumentRoot();
   }
 
   return nullptr;
 }
 
--- a/content/svg/content/src/nsSVGCircleElement.cpp
+++ b/content/svg/content/src/nsSVGCircleElement.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsSVGPathGeometryElement.h"
 #include "nsIDOMSVGCircleElement.h"
 #include "nsSVGLength2.h"
 #include "nsGkAtoms.h"
-#include "nsSVGUtils.h"
 #include "gfxContext.h"
 
 using namespace mozilla;
 
 typedef nsSVGPathGeometryElement nsSVGCircleElementBase;
 
 class nsSVGCircleElement : public nsSVGCircleElementBase,
                            public nsIDOMSVGCircleElement
@@ -51,19 +50,19 @@ protected:
 
   enum { CX, CY, R };
   nsSVGLength2 mLengthAttributes[3];
   static LengthInfo sLengthInfo[3];
 };
 
 nsSVGElement::LengthInfo nsSVGCircleElement::sLengthInfo[3] =
 {
-  { &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::r, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::XY }
+  { &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::r, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::XY }
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Circle)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGCircleElement,nsSVGCircleElementBase)
--- a/content/svg/content/src/nsSVGDataParser.cpp
+++ b/content/svg/content/src/nsSVGDataParser.cpp
@@ -13,17 +13,16 @@
   *   A subclass should implement a Match method which gets invoked from the
   *   Parse method.  The Parse method can be overridden, as required.
   *
   */
 
 
 #include "nsSVGDataParser.h"
 #include "prdtoa.h"
-#include "nsSVGUtils.h"
 #include "nsMathUtils.h"
 #include "nsMemory.h"
 #include "nsReadableUtils.h"
 #include <stdlib.h>
 #include <math.h>
 
 //----------------------------------------------------------------------
 // public interface
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -26,32 +26,32 @@
 #include "nsRuleWalker.h"
 #include "mozilla/css/Declaration.h"
 #include "nsCSSProps.h"
 #include "nsCSSParser.h"
 #include "nsGenericHTMLElement.h"
 #include "nsNodeInfoManager.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsEventListenerManager.h"
-#include "nsSVGUtils.h"
 #include "nsSVGLength2.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGNumberPair.h"
 #include "nsSVGInteger.h"
 #include "nsSVGIntegerPair.h"
 #include "nsSVGAngle.h"
 #include "nsSVGBoolean.h"
 #include "nsSVGEnum.h"
 #include "nsSVGViewBox.h"
 #include "nsSVGString.h"
 #include "SVGAnimatedNumberList.h"
 #include "SVGAnimatedLengthList.h"
 #include "SVGAnimatedPointList.h"
 #include "SVGAnimatedPathSegList.h"
 #include "SVGAnimatedTransformList.h"
+#include "SVGContentUtils.h"
 #include "DOMSVGTests.h"
 #include "nsIDOMSVGUnitTypes.h"
 #include "nsSVGRect.h"
 #include "nsIFrame.h"
 #include "prdtoa.h"
 #include <stdarg.h>
 #include "nsSMILMappedAttribute.h"
 #include "SVGMotionSMILAttr.h"
@@ -1053,17 +1053,17 @@ nsSVGElement::GetOwnerSVGElement(nsIDOMS
   // Otherwise, we've got an invalid structure
   return NS_ERROR_FAILURE;
 }
 
 /* readonly attribute nsIDOMSVGElement viewportElement; */
 NS_IMETHODIMP
 nsSVGElement::GetViewportElement(nsIDOMSVGElement * *aViewportElement)
 {
-  *aViewportElement = nsSVGUtils::GetNearestViewportElement(this).get();
+  *aViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
   return NS_OK;
 }
 
 //------------------------------------------------------------------------
 // Helper class: MappedAttrParser, for parsing values of mapped attributes
 
 namespace {
 
@@ -2414,19 +2414,19 @@ nsSVGElement::StringListAttributesInfo::
 nsresult
 nsSVGElement::ReportAttributeParseFailure(nsIDocument* aDocument,
                                           nsIAtom* aAttribute,
                                           const nsAString& aValue)
 {
   const nsAFlatString& attributeValue = PromiseFlatString(aValue);
   const PRUnichar *strings[] = { aAttribute->GetUTF16String(),
                                  attributeValue.get() };
-  return nsSVGUtils::ReportToConsole(aDocument,
-                                     "AttributeParseWarning",
-                                     strings, ArrayLength(strings));
+  return SVGContentUtils::ReportToConsole(aDocument,
+                                          "AttributeParseWarning",
+                                          strings, ArrayLength(strings));
 }
 
 void
 nsSVGElement::RecompileScriptEventListeners()
 {
   int32_t i, count = mAttrsAndChildren.AttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
--- a/content/svg/content/src/nsSVGEllipseElement.cpp
+++ b/content/svg/content/src/nsSVGEllipseElement.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsSVGPathGeometryElement.h"
 #include "nsIDOMSVGEllipseElement.h"
 #include "nsSVGLength2.h"
 #include "nsGkAtoms.h"
-#include "nsSVGUtils.h"
 #include "gfxContext.h"
 
 using namespace mozilla;
 
 typedef nsSVGPathGeometryElement nsSVGEllipseElementBase;
 
 class nsSVGEllipseElement : public nsSVGEllipseElementBase,
                             public nsIDOMSVGEllipseElement
@@ -51,20 +50,20 @@ protected:
 
   enum { CX, CY, RX, RY };
   nsSVGLength2 mLengthAttributes[4];
   static LengthInfo sLengthInfo[4];
 };
 
 nsSVGElement::LengthInfo nsSVGEllipseElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
+  { &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Ellipse)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGEllipseElement,nsSVGEllipseElementBase)
--- a/content/svg/content/src/nsSVGFilterElement.cpp
+++ b/content/svg/content/src/nsSVGFilterElement.cpp
@@ -9,20 +9,20 @@
 #include "nsCOMPtr.h"
 #include "nsSVGFilterElement.h"
 #include "nsSVGEffects.h"
 
 using namespace mozilla;
 
 nsSVGElement::LengthInfo nsSVGFilterElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
+  { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 nsSVGElement::IntegerPairInfo nsSVGFilterElement::sIntegerPairInfo[1] =
 {
   { &nsGkAtoms::filterRes, 0 }
 };
 
 nsSVGElement::EnumInfo nsSVGFilterElement::sEnumInfo[2] =
--- a/content/svg/content/src/nsSVGFilters.cpp
+++ b/content/svg/content/src/nsSVGFilters.cpp
@@ -30,16 +30,17 @@
 #include "gfxMatrix.h"
 #include "imgIContainer.h"
 #include "nsNetUtil.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsSVGFilterElement.h"
 #include "nsSVGString.h"
 #include "nsSVGEffects.h"
 #include "gfxUtils.h"
+#include "SVGContentUtils.h"
 
 #if defined(XP_WIN) 
 // Prevent Windows redefining LoadImage
 #undef LoadImage
 #endif
 
 #define NUM_ENTRIES_IN_4x5_MATRIX 20
 
@@ -78,20 +79,20 @@ CopyAndScaleDeviceOffset(const gfxImageS
   deviceOffset.y /= kernelY;
   aResult->SetDeviceOffset(deviceOffset);
 }
 
 //--------------------Filter Element Base Class-----------------------
 
 nsSVGElement::LengthInfo nsSVGFE::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::height, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y }
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::height, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }
 };
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGFE,nsSVGFEBase)
 NS_IMPL_RELEASE_INHERITED(nsSVGFE,nsSVGFEBase)
 
@@ -118,20 +119,20 @@ nsSVGFE::SetupScalingFilter(nsSVGFilterI
   result.mRescaling = aKernelUnitLength->IsExplicitlySet();
   if (!result.mRescaling) {
     result.mSource = aSource->mImage;
     result.mTarget = aTarget->mImage;
     result.mDataRect = aDataRect;
     return result;
   }
 
-  gfxFloat kernelX = aInstance->GetPrimitiveNumber(nsSVGUtils::X,
+  gfxFloat kernelX = aInstance->GetPrimitiveNumber(SVGContentUtils::X,
                                                    aKernelUnitLength,
                                                    nsSVGNumberPair::eFirst);
-  gfxFloat kernelY = aInstance->GetPrimitiveNumber(nsSVGUtils::Y,
+  gfxFloat kernelY = aInstance->GetPrimitiveNumber(SVGContentUtils::Y,
                                                    aKernelUnitLength,
                                                    nsSVGNumberPair::eSecond);
   if (kernelX <= 0 || kernelY <= 0)
     return result;
 
   bool overflow = false;
   gfxIntSize scaledSize =
     nsSVGUtils::ConvertToSurfaceSize(gfxSize(aTarget->mImage->Width() / kernelX,
@@ -585,20 +586,20 @@ GetBlurBoxSize(double aStdDev)
     return max;
   return uint32_t(floor(size + 0.5));
 }
 
 nsresult
 nsSVGFEGaussianBlurElement::GetDXY(uint32_t *aDX, uint32_t *aDY,
                                    const nsSVGFilterInstance& aInstance)
 {
-  float stdX = aInstance.GetPrimitiveNumber(nsSVGUtils::X,
+  float stdX = aInstance.GetPrimitiveNumber(SVGContentUtils::X,
                                             &mNumberPairAttributes[STD_DEV],
                                             nsSVGNumberPair::eFirst);
-  float stdY = aInstance.GetPrimitiveNumber(nsSVGUtils::Y,
+  float stdY = aInstance.GetPrimitiveNumber(SVGContentUtils::Y,
                                             &mNumberPairAttributes[STD_DEV],
                                             nsSVGNumberPair::eSecond);
   if (stdX < 0 || stdY < 0)
     return NS_ERROR_FAILURE;
 
   // If the box size is greater than twice the temporary surface size
   // in an axis, then each pixel will be set to the average of all the
   // other pixel values.
@@ -2611,19 +2612,19 @@ NS_IMETHODIMP nsSVGFEOffsetElement::GetD
 {
   return mNumberAttributes[DY].ToDOMAnimatedNumber(aDy, this);
 }
 
 nsIntPoint
 nsSVGFEOffsetElement::GetOffset(const nsSVGFilterInstance& aInstance)
 {
   return nsIntPoint(int32_t(aInstance.GetPrimitiveNumber(
-                              nsSVGUtils::X, &mNumberAttributes[DX])),
+                              SVGContentUtils::X, &mNumberAttributes[DX])),
                     int32_t(aInstance.GetPrimitiveNumber(
-                              nsSVGUtils::Y, &mNumberAttributes[DY])));
+                              SVGContentUtils::Y, &mNumberAttributes[DY])));
 }
 
 nsresult
 nsSVGFEOffsetElement::Filter(nsSVGFilterInstance *instance,
                              const nsTArray<const Image*>& aSources,
                              const Image* aTarget,
                              const nsIntRect& rect)
 {
@@ -3786,37 +3787,37 @@ nsSVGFEMorphologyElement::ComputeChangeB
 void
 nsSVGFEMorphologyElement::GetRXY(int32_t *aRX, int32_t *aRY,
                                  const nsSVGFilterInstance& aInstance)
 {
   // Subtract an epsilon here because we don't want a value that's just
   // slightly larger than an integer to round up to the next integer; it's
   // probably meant to be the integer it's close to, modulo machine precision
   // issues.
-  *aRX = NSToIntCeil(aInstance.GetPrimitiveNumber(nsSVGUtils::X,
+  *aRX = NSToIntCeil(aInstance.GetPrimitiveNumber(SVGContentUtils::X,
                                                   &mNumberPairAttributes[RADIUS],
                                                   nsSVGNumberPair::eFirst) -
                      MORPHOLOGY_EPSILON);
-  *aRY = NSToIntCeil(aInstance.GetPrimitiveNumber(nsSVGUtils::Y,
+  *aRY = NSToIntCeil(aInstance.GetPrimitiveNumber(SVGContentUtils::Y,
                                                   &mNumberPairAttributes[RADIUS],
                                                   nsSVGNumberPair::eSecond) -
                      MORPHOLOGY_EPSILON);
 }
 
 nsresult
 nsSVGFEMorphologyElement::Filter(nsSVGFilterInstance *instance,
                                  const nsTArray<const Image*>& aSources,
                                  const Image* aTarget,
                                  const nsIntRect& rect)
 {
   int32_t rx, ry;
   GetRXY(&rx, &ry, *instance);
 
   if (rx < 0 || ry < 0) {
-    // XXX nsSVGUtils::ReportToConsole()
+    // XXX SVGContentUtils::ReportToConsole()
     return NS_OK;
   }
   if (rx == 0 && ry == 0) {
     return NS_OK;
   }
 
   // Clamp radii to prevent completely insane values:
   rx = NS_MIN(rx, 100000);
@@ -5696,20 +5697,20 @@ nsSVGFEImageElement::Filter(nsSVGFilterI
 
     int32_t nativeWidth, nativeHeight;
     imageContainer->GetWidth(&nativeWidth);
     imageContainer->GetHeight(&nativeHeight);
 
     const gfxRect& filterSubregion = aTarget->mFilterPrimitiveSubregion;
 
     gfxMatrix viewBoxTM =
-      nsSVGUtils::GetViewBoxTransform(this,
-                                      filterSubregion.Width(), filterSubregion.Height(),
-                                      0,0, nativeWidth, nativeHeight,
-                                      mPreserveAspectRatio);
+      SVGContentUtils::GetViewBoxTransform(this,
+                                           filterSubregion.Width(), filterSubregion.Height(),
+                                           0,0, nativeWidth, nativeHeight,
+                                           mPreserveAspectRatio);
 
     gfxMatrix xyTM = gfxMatrix().Translate(gfxPoint(filterSubregion.X(), filterSubregion.Y()));
 
     gfxMatrix TM = viewBoxTM * xyTM;
     
     nsRefPtr<gfxContext> ctx = new gfxContext(aTarget->mImage);
     nsSVGUtils::CompositePatternMatrix(ctx, thebesPattern, TM, nativeWidth, nativeHeight, 1.0);
   }
@@ -5980,17 +5981,17 @@ NS_IMETHODIMP nsSVGFEDisplacementMapElem
 }
 
 nsresult
 nsSVGFEDisplacementMapElement::Filter(nsSVGFilterInstance *instance,
                                       const nsTArray<const Image*>& aSources,
                                       const Image* aTarget,
                                       const nsIntRect& rect)
 {
-  float scale = instance->GetPrimitiveNumber(nsSVGUtils::XY,
+  float scale = instance->GetPrimitiveNumber(SVGContentUtils::XY,
                                              &mNumberAttributes[SCALE]);
   if (scale == 0.0f) {
     CopyRect(aTarget, aSources[0], rect);
     return NS_OK;
   }
 
   int32_t width = instance->GetSurfaceWidth();
   int32_t height = instance->GetSurfaceHeight();
--- a/content/svg/content/src/nsSVGForeignObjectElement.cpp
+++ b/content/svg/content/src/nsSVGForeignObjectElement.cpp
@@ -7,20 +7,20 @@
 
 #include "nsCOMPtr.h"
 #include "nsSVGForeignObjectElement.h"
 
 using namespace mozilla;
 
 nsSVGElement::LengthInfo nsSVGForeignObjectElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(ForeignObject)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGForeignObjectElement,nsSVGForeignObjectElementBase)
--- a/content/svg/content/src/nsSVGGradientElement.cpp
+++ b/content/svg/content/src/nsSVGGradientElement.cpp
@@ -128,20 +128,20 @@ nsSVGGradientElement::IsAttributeMapped(
   return FindAttributeDependence(name, map) ||
     nsSVGGradientElementBase::IsAttributeMapped(name);
 }
 
 //---------------------Linear Gradients------------------------
 
 nsSVGElement::LengthInfo nsSVGLinearGradientElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
-  { &nsGkAtoms::x2, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
+  { &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
+  { &nsGkAtoms::x2, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(LinearGradient)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGLinearGradientElement,nsSVGLinearGradientElementBase)
@@ -217,21 +217,21 @@ nsSVGLinearGradientElement::GetLengthInf
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
                               ArrayLength(sLengthInfo));
 }
 
 //-------------------------- Radial Gradients ----------------------------
 
 nsSVGElement::LengthInfo nsSVGRadialGradientElement::sLengthInfo[5] =
 {
-  { &nsGkAtoms::cx, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::cy, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
-  { &nsGkAtoms::r, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::XY },
-  { &nsGkAtoms::fx, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::fy, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
+  { &nsGkAtoms::cx, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::cy, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
+  { &nsGkAtoms::r, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::XY },
+  { &nsGkAtoms::fx, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::fy, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(RadialGradient)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGRadialGradientElement,nsSVGRadialGradientElementBase)
--- a/content/svg/content/src/nsSVGGraphicElement.cpp
+++ b/content/svg/content/src/nsSVGGraphicElement.cpp
@@ -42,24 +42,24 @@ nsSVGGraphicElement::nsSVGGraphicElement
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGLocatable methods
 
 /* readonly attribute nsIDOMSVGElement nearestViewportElement; */
 NS_IMETHODIMP nsSVGGraphicElement::GetNearestViewportElement(nsIDOMSVGElement * *aNearestViewportElement)
 {
-  *aNearestViewportElement = nsSVGUtils::GetNearestViewportElement(this).get();
+  *aNearestViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGElement farthestViewportElement; */
 NS_IMETHODIMP nsSVGGraphicElement::GetFarthestViewportElement(nsIDOMSVGElement * *aFarthestViewportElement)
 {
-  NS_IF_ADDREF(*aFarthestViewportElement = nsSVGUtils::GetOuterSVGElement(this));
+  NS_IF_ADDREF(*aFarthestViewportElement = SVGContentUtils::GetOuterSVGElement(this));
   return NS_OK;
 }
 
 /* nsIDOMSVGRect getBBox (); */
 NS_IMETHODIMP nsSVGGraphicElement::GetBBox(nsIDOMSVGRect **_retval)
 {
   *_retval = nullptr;
 
@@ -73,26 +73,26 @@ NS_IMETHODIMP nsSVGGraphicElement::GetBB
     return NS_NewSVGRect(_retval, nsSVGUtils::GetBBox(frame));
   }
   return NS_ERROR_FAILURE;
 }
 
 /* nsIDOMSVGMatrix getCTM (); */
 NS_IMETHODIMP nsSVGGraphicElement::GetCTM(nsIDOMSVGMatrix * *aCTM)
 {
-  gfxMatrix m = nsSVGUtils::GetCTM(this, false);
+  gfxMatrix m = SVGContentUtils::GetCTM(this, false);
   *aCTM = m.IsSingular() ? nullptr : new DOMSVGMatrix(m);
   NS_IF_ADDREF(*aCTM);
   return NS_OK;
 }
 
 /* nsIDOMSVGMatrix getScreenCTM (); */
 NS_IMETHODIMP nsSVGGraphicElement::GetScreenCTM(nsIDOMSVGMatrix * *aCTM)
 {
-  gfxMatrix m = nsSVGUtils::GetCTM(this, true);
+  gfxMatrix m = SVGContentUtils::GetCTM(this, true);
   *aCTM = m.IsSingular() ? nullptr : new DOMSVGMatrix(m);
   NS_IF_ADDREF(*aCTM);
   return NS_OK;
 }
 
 /* nsIDOMSVGMatrix getTransformToElement (in nsIDOMSVGElement element); */
 NS_IMETHODIMP nsSVGGraphicElement::GetTransformToElement(nsIDOMSVGElement *element, nsIDOMSVGMatrix **_retval)
 {
--- a/content/svg/content/src/nsSVGImageElement.cpp
+++ b/content/svg/content/src/nsSVGImageElement.cpp
@@ -12,20 +12,20 @@
 #include "imgIContainer.h"
 #include "imgIDecoderObserver.h"
 #include "gfxContext.h"
 
 using namespace mozilla;
 
 nsSVGElement::LengthInfo nsSVGImageElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 nsSVGElement::StringInfo nsSVGImageElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Image)
--- a/content/svg/content/src/nsSVGIntegerPair.cpp
+++ b/content/svg/content/src/nsSVGIntegerPair.cpp
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSVGIntegerPair.h"
-#include "nsSVGUtils.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsError.h"
 #include "nsMathUtils.h"
 #include "nsSMILValue.h"
+#include "SVGContentUtils.h"
 #include "SVGIntegerPairSMILType.h"
 
 using namespace mozilla;
 
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGIntegerPair::DOMAnimatedInteger, mSVGElement)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGIntegerPair::DOMAnimatedInteger)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGIntegerPair::DOMAnimatedInteger)
--- a/content/svg/content/src/nsSVGLength2.cpp
+++ b/content/svg/content/src/nsSVGLength2.cpp
@@ -178,20 +178,24 @@ nsSVGLength2::GetAxisLength(nsSVGSVGElem
 
 float
 nsSVGLength2::GetAxisLength(nsIFrame *aNonSVGFrame) const
 {
   gfxSize size =
     nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(aNonSVGFrame);
   float length;
   switch (mCtxType) {
-  case nsSVGUtils::X: length = size.width; break;
-  case nsSVGUtils::Y: length = size.height; break;
-  case nsSVGUtils::XY:
-    length = nsSVGUtils::ComputeNormalizedHypotenuse(size.width, size.height);
+  case SVGContentUtils::X:
+    length = size.width;
+    break;
+  case SVGContentUtils::Y:
+    length = size.height;
+    break;
+  case SVGContentUtils::XY:
+    length = SVGContentUtils::ComputeNormalizedHypotenuse(size.width, size.height);
     break;
   default:
     NS_NOTREACHED("Unknown axis type");
     length = 1;
     break;
   }
   return FixAxisLength(length);
 }
--- a/content/svg/content/src/nsSVGLength2.h
+++ b/content/svg/content/src/nsSVGLength2.h
@@ -10,28 +10,28 @@
 #include "nsCoord.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsIDOMSVGAnimatedLength.h"
 #include "nsIDOMSVGLength.h"
 #include "nsISMILAttr.h"
 #include "nsMathUtils.h"
 #include "nsSVGElement.h"
-#include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 
 class nsIFrame;
 class nsISMILAnimationElement;
 class nsSMILValue;
 class nsSVGSVGElement;
 
 class nsSVGLength2
 {
 
 public:
-  void Init(uint8_t aCtxType = nsSVGUtils::XY,
+  void Init(uint8_t aCtxType = SVGContentUtils::XY,
             uint8_t aAttrEnum = 0xff,
             float aValue = 0,
             uint8_t aUnitType = nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER) {
     mAnimVal = mBaseVal = aValue;
     mSpecifiedUnitType = aUnitType;
     mAttrEnum = aAttrEnum;
     mCtxType = aCtxType;
     mIsAnimated = false;
@@ -96,27 +96,27 @@ private:
   uint8_t mAttrEnum; // element specified tracking for attribute
   uint8_t mCtxType; // X, Y or Unspecified
   bool mIsAnimated:1;
   bool mIsBaseSet:1;
   
   static float GetMMPerPixel() { return MM_PER_INCH_FLOAT / 96; }
   float GetAxisLength(nsIFrame *aNonSVGFrame) const;
   static float GetEmLength(nsIFrame *aFrame)
-    { return nsSVGUtils::GetFontSize(aFrame); }
+    { return SVGContentUtils::GetFontSize(aFrame); }
   static float GetExLength(nsIFrame *aFrame)
-    { return nsSVGUtils::GetFontXHeight(aFrame); }
+    { return SVGContentUtils::GetFontXHeight(aFrame); }
   float GetUnitScaleFactor(nsIFrame *aFrame, uint8_t aUnitType) const;
 
   float GetMMPerPixel(nsSVGSVGElement *aCtx) const;
   float GetAxisLength(nsSVGSVGElement *aCtx) const;
   static float GetEmLength(nsSVGElement *aSVGElement)
-    { return nsSVGUtils::GetFontSize(aSVGElement); }
+    { return SVGContentUtils::GetFontSize(aSVGElement); }
   static float GetExLength(nsSVGElement *aSVGElement)
-    { return nsSVGUtils::GetFontXHeight(aSVGElement); }
+    { return SVGContentUtils::GetFontXHeight(aSVGElement); }
   float GetUnitScaleFactor(nsSVGElement *aSVGElement, uint8_t aUnitType) const;
   float GetUnitScaleFactor(nsSVGSVGElement *aCtx, uint8_t aUnitType) const;
 
   // SetBaseValue and SetAnimValue set the value in user units
   void SetBaseValue(float aValue, nsSVGElement *aSVGElement, bool aDoSetAttr);
   void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement,
                                     bool aDoSetAttr);
   void SetAnimValue(float aValue, nsSVGElement *aSVGElement);
--- a/content/svg/content/src/nsSVGLineElement.cpp
+++ b/content/svg/content/src/nsSVGLineElement.cpp
@@ -52,20 +52,20 @@ protected:
 
   enum { X1, Y1, X2, Y2 };
   nsSVGLength2 mLengthAttributes[4];
   static LengthInfo sLengthInfo[4];
 };
 
 nsSVGElement::LengthInfo nsSVGLineElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
+  { &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Line)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
--- a/content/svg/content/src/nsSVGMarkerElement.cpp
+++ b/content/svg/content/src/nsSVGMarkerElement.cpp
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsGkAtoms.h"
 #include "nsCOMPtr.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsError.h"
-#include "nsSVGUtils.h"
 #include "nsSVGMarkerElement.h"
 #include "gfxMatrix.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
+#include "SVGContentUtils.h"
 
 using namespace mozilla;
 
 nsSVGElement::LengthInfo nsSVGMarkerElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::refX, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::refY, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::markerWidth, 3, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::markerHeight, 3, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
+  { &nsGkAtoms::refX, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::refY, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::markerWidth, 3, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::markerHeight, 3, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 nsSVGEnumMapping nsSVGMarkerElement::sUnitsMap[] = {
   {&nsGkAtoms::strokeWidth, nsIDOMSVGMarkerElement::SVG_MARKERUNITS_STROKEWIDTH},
   {&nsGkAtoms::userSpaceOnUse, nsIDOMSVGMarkerElement::SVG_MARKERUNITS_USERSPACEONUSE},
   {nullptr, 0}
 };
 
@@ -358,21 +358,21 @@ nsSVGMarkerElement::GetViewBoxTransform(
       mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx);
    
     nsSVGViewBoxRect viewbox = GetViewBoxRect();
 
     NS_ABORT_IF_FALSE(viewbox.width > 0.0f && viewbox.height > 0.0f,
                       "Rendering should be disabled");
 
     gfxMatrix viewBoxTM =
-      nsSVGUtils::GetViewBoxTransform(this,
-                                      viewportWidth, viewportHeight,
-                                      viewbox.x, viewbox.y,
-                                      viewbox.width, viewbox.height,
-                                      mPreserveAspectRatio);
+      SVGContentUtils::GetViewBoxTransform(this,
+                                           viewportWidth, viewportHeight,
+                                           viewbox.x, viewbox.y,
+                                           viewbox.width, viewbox.height,
+                                           mPreserveAspectRatio);
 
     float refX = mLengthAttributes[REFX].GetAnimValue(mCoordCtx);
     float refY = mLengthAttributes[REFY].GetAnimValue(mCoordCtx);
 
     gfxPoint ref = viewBoxTM.Transform(gfxPoint(refX, refY));
 
     gfxMatrix TM = viewBoxTM * gfxMatrix().Translate(gfxPoint(-ref.x, -ref.y));
 
--- a/content/svg/content/src/nsSVGMaskElement.cpp
+++ b/content/svg/content/src/nsSVGMaskElement.cpp
@@ -10,20 +10,20 @@
 #include "nsSVGMaskElement.h"
 
 using namespace mozilla;
 
 //--------------------- Masks ------------------------
 
 nsSVGElement::LengthInfo nsSVGMaskElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
+  { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 nsSVGElement::EnumInfo nsSVGMaskElement::sEnumInfo[2] =
 {
   { &nsGkAtoms::maskUnits,
     sSVGUnitTypesMap,
     nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
   },
--- a/content/svg/content/src/nsSVGNumber2.cpp
+++ b/content/svg/content/src/nsSVGNumber2.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsError.h"
 #include "nsSVGNumber2.h"
-#include "nsSVGUtils.h"
 #include "nsTextFormatter.h"
 #include "prdtoa.h"
 #include "nsMathUtils.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
 #include "nsSMILValue.h"
 #include "nsSMILFloatType.h"
 #include "nsIDOMSVGNumber.h"
 #include "mozilla/Attributes.h"
--- a/content/svg/content/src/nsSVGNumberPair.cpp
+++ b/content/svg/content/src/nsSVGNumberPair.cpp
@@ -1,20 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSVGNumberPair.h"
-#include "nsSVGUtils.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "prdtoa.h"
 #include "nsError.h"
 #include "nsMathUtils.h"
 #include "nsSMILValue.h"
+#include "SVGContentUtils.h"
 #include "SVGNumberPairSMILType.h"
 
 using namespace mozilla;
 
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGNumberPair::DOMAnimatedNumber, mSVGElement)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGNumberPair::DOMAnimatedNumber)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGNumberPair::DOMAnimatedNumber)
--- a/content/svg/content/src/nsSVGPathDataParser.cpp
+++ b/content/svg/content/src/nsSVGPathDataParser.cpp
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSVGPathDataParser.h"
 #include "nsSVGDataParser.h"
 #include "nsSVGPathElement.h"
 #include "prdtoa.h"
-#include "nsSVGUtils.h"
 #include "nsIDOMSVGPathSeg.h"
 #include <stdlib.h>
 #include <math.h>
 
 using namespace mozilla;
 
 nsresult nsSVGPathDataParser::Match()
 {
--- a/content/svg/content/src/nsSVGPathElement.cpp
+++ b/content/svg/content/src/nsSVGPathElement.cpp
@@ -7,17 +7,16 @@
 
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGPathSeg.h"
 #include "DOMSVGPathSeg.h"
 #include "DOMSVGPathSegList.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nsSVGPathElement.h"
-#include "nsSVGUtils.h"
 #include "DOMSVGPoint.h"
 #include "gfxContext.h"
 
 using namespace mozilla;
 
 nsSVGElement::NumberInfo nsSVGPathElement::sNumberInfo = 
 { &nsGkAtoms::pathLength, 0, false };
 
--- a/content/svg/content/src/nsSVGPatternElement.cpp
+++ b/content/svg/content/src/nsSVGPatternElement.cpp
@@ -12,20 +12,20 @@
 #include "nsSVGPatternElement.h"
 
 using namespace mozilla;
 
 //--------------------- Patterns ------------------------
 
 nsSVGElement::LengthInfo nsSVGPatternElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 nsSVGElement::EnumInfo nsSVGPatternElement::sEnumInfo[2] =
 {
   { &nsGkAtoms::patternUnits,
     sSVGUnitTypesMap,
     nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
   },
--- a/content/svg/content/src/nsSVGPolyElement.cpp
+++ b/content/svg/content/src/nsSVGPolyElement.cpp
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsSVGPolyElement.h"
 #include "DOMSVGPointList.h"
 #include "gfxContext.h"
-#include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
 NS_IMPL_RELEASE_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
@@ -91,17 +91,17 @@ nsSVGPolyElement::GetMarkPoints(nsTArray
   for (uint32_t i = 0; i < points.Length(); ++i) {
     float x = points[i].mX;
     float y = points[i].mY;
     float angle = atan2(y-py, x-px);
     if (i == 1)
       aMarks->ElementAt(aMarks->Length() - 1).angle = angle;
     else if (i > 1)
       aMarks->ElementAt(aMarks->Length() - 1).angle =
-        nsSVGUtils::AngleBisect(prevAngle, angle);
+        SVGContentUtils::AngleBisect(prevAngle, angle);
 
     aMarks->AppendElement(nsSVGMark(x, y, 0));
 
     prevAngle = angle;
     px = x;
     py = y;
   }
 
--- a/content/svg/content/src/nsSVGPolygonElement.cpp
+++ b/content/svg/content/src/nsSVGPolygonElement.cpp
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSVGPolyElement.h"
 #include "nsIDOMSVGPolygonElement.h"
 #include "gfxContext.h"
-#include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 
 typedef nsSVGPolyElement nsSVGPolygonElementBase;
 
 class nsSVGPolygonElement : public nsSVGPolygonElementBase,
                             public nsIDOMSVGPolygonElement
 {
 protected:
   friend nsresult NS_NewSVGPolygonElement(nsIContent **aResult,
@@ -78,18 +78,18 @@ void
 nsSVGPolygonElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
 {
   nsSVGPolyElement::GetMarkPoints(aMarks);
   if (aMarks->Length() > 0) {
     nsSVGMark *endMark = &aMarks->ElementAt(aMarks->Length()-1);
     nsSVGMark *startMark = &aMarks->ElementAt(0);
     float angle = atan2(startMark->y - endMark->y, startMark->x - endMark->x);
 
-    endMark->angle = nsSVGUtils::AngleBisect(angle, endMark->angle);
-    startMark->angle = nsSVGUtils::AngleBisect(angle, startMark->angle);
+    endMark->angle = SVGContentUtils::AngleBisect(angle, endMark->angle);
+    startMark->angle = SVGContentUtils::AngleBisect(angle, startMark->angle);
     // for a polygon (as opposed to a polyline) there's an implicit extra point
     // co-located with the start point that nsSVGPolyElement::GetMarkPoints
     // doesn't return
     aMarks->AppendElement(nsSVGMark(startMark->x, startMark->y, startMark->angle));
   }
 }
 
 void
--- a/content/svg/content/src/nsSVGRectElement.cpp
+++ b/content/svg/content/src/nsSVGRectElement.cpp
@@ -50,22 +50,22 @@ protected:
  
   enum { X, Y, WIDTH, HEIGHT, RX, RY };
   nsSVGLength2 mLengthAttributes[6];
   static LengthInfo sLengthInfo[6];
 };
 
 nsSVGElement::LengthInfo nsSVGRectElement::sLengthInfo[6] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y }
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y }
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Rect)
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGRectElement,nsSVGRectElementBase)
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -20,20 +20,21 @@
 #include "DOMSVGPoint.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIFrame.h"
 #include "nsISVGSVGFrame.h" //XXX
 #include "nsSVGRect.h"
 #include "nsError.h"
 #include "nsISVGChildFrame.h"
 #include "nsGUIEvent.h"
+#include "nsSVGSVGElement.h"
 #include "nsSVGUtils.h"
-#include "nsSVGSVGElement.h"
 #include "nsSVGViewElement.h"
 #include "nsStyleUtil.h"
+#include "SVGContentUtils.h"
 
 #include "nsEventDispatcher.h"
 #include "nsSMILTimeContainer.h"
 #include "nsSMILAnimationController.h"
 #include "nsSMILTypes.h"
 #include "nsIContentIterator.h"
 
 using namespace mozilla;
@@ -96,20 +97,20 @@ nsSVGTranslatePoint::DOMVal::MatrixTrans
   float y = mVal->GetY();
 
   NS_ADDREF(*_retval = new DOMSVGPoint(a*x + c*y + e, b*x + d*y + f));
   return NS_OK;
 }
 
 nsSVGElement::LengthInfo nsSVGSVGElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
-  { &nsGkAtoms::height, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
+  { &nsGkAtoms::height, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 nsSVGEnumMapping nsSVGSVGElement::sZoomAndPanMap[] = {
   {&nsGkAtoms::disable, nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_DISABLE},
   {&nsGkAtoms::magnify, nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY},
   {nullptr, 0}
 };
 
@@ -631,25 +632,25 @@ nsSVGSVGElement::GetPreserveAspectRatio(
 
 //----------------------------------------------------------------------
 // nsIDOMSVGLocatable methods
 
 /* readonly attribute nsIDOMSVGElement nearestViewportElement; */
 NS_IMETHODIMP
 nsSVGSVGElement::GetNearestViewportElement(nsIDOMSVGElement * *aNearestViewportElement)
 {
-  *aNearestViewportElement = nsSVGUtils::GetNearestViewportElement(this).get();
+  *aNearestViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGElement farthestViewportElement; */
 NS_IMETHODIMP
 nsSVGSVGElement::GetFarthestViewportElement(nsIDOMSVGElement * *aFarthestViewportElement)
 {
-  NS_IF_ADDREF(*aFarthestViewportElement = nsSVGUtils::GetOuterSVGElement(this));
+  NS_IF_ADDREF(*aFarthestViewportElement = SVGContentUtils::GetOuterSVGElement(this));
   return NS_OK;
 }
 
 /* nsIDOMSVGRect getBBox (); */
 NS_IMETHODIMP
 nsSVGSVGElement::GetBBox(nsIDOMSVGRect **_retval)
 {
   *_retval = nullptr;
@@ -665,27 +666,27 @@ nsSVGSVGElement::GetBBox(nsIDOMSVGRect *
   }
   return NS_ERROR_NOT_IMPLEMENTED; // XXX: outer svg
 }
 
 /* nsIDOMSVGMatrix getCTM (); */
 NS_IMETHODIMP
 nsSVGSVGElement::GetCTM(nsIDOMSVGMatrix * *aCTM)
 {
-  gfxMatrix m = nsSVGUtils::GetCTM(this, false);
+  gfxMatrix m = SVGContentUtils::GetCTM(this, false);
   *aCTM = m.IsSingular() ? nullptr : new DOMSVGMatrix(m);
   NS_IF_ADDREF(*aCTM);
   return NS_OK;
 }
 
 /* nsIDOMSVGMatrix getScreenCTM (); */
 NS_IMETHODIMP
 nsSVGSVGElement::GetScreenCTM(nsIDOMSVGMatrix **aCTM)
 {
-  gfxMatrix m = nsSVGUtils::GetCTM(this, true);
+  gfxMatrix m = SVGContentUtils::GetCTM(this, true);
   *aCTM = m.IsSingular() ? nullptr : new DOMSVGMatrix(m);
   NS_IF_ADDREF(*aCTM);
   return NS_OK;
 }
 
 /* nsIDOMSVGMatrix getTransformToElement (in nsIDOMSVGElement element); */
 NS_IMETHODIMP
 nsSVGSVGElement::GetTransformToElement(nsIDOMSVGElement *element,
@@ -801,17 +802,17 @@ nsSMILTimeContainer*
 nsSVGSVGElement::GetTimedDocumentRoot()
 {
   if (mTimedDocumentRoot) {
     return mTimedDocumentRoot;
   }
 
   // We must not be the outermost <svg> element, try to find it
   nsSVGSVGElement *outerSVGElement =
-    nsSVGUtils::GetOuterSVGElement(this);
+    SVGContentUtils::GetOuterSVGElement(this);
 
   if (outerSVGElement) {
     return outerSVGElement->GetTimedDocumentRoot();
   }
   // invalid structure
   return nullptr;
 }
 
@@ -928,21 +929,21 @@ nsSVGSVGElement::GetViewBoxTransform() c
 
   nsSVGViewBoxRect viewBox =
     GetViewBoxWithSynthesis(viewportWidth, viewportHeight);
 
   if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
     return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
   }
 
-  return nsSVGUtils::GetViewBoxTransform(this,
-                                         viewportWidth, viewportHeight,
-                                         viewBox.x, viewBox.y,
-                                         viewBox.width, viewBox.height,
-                                         GetPreserveAspectRatioWithOverride());
+  return SVGContentUtils::GetViewBoxTransform(this,
+                                              viewportWidth, viewportHeight,
+                                              viewBox.x, viewBox.y,
+                                              viewBox.width, viewBox.height,
+                                              GetPreserveAspectRatioWithOverride());
 }
 
 void
 nsSVGSVGElement::ChildrenOnlyTransformChanged(uint32_t aFlags)
 {
   // Avoid wasteful calls:
   NS_ABORT_IF_FALSE(!(GetPrimaryFrame()->GetStateBits() &
                       NS_STATE_SVG_NONDISPLAY_CHILD),
@@ -1185,22 +1186,22 @@ nsSVGSVGElement::GetLength(uint8_t aCtxT
     w = mViewportWidth;
     h = mViewportHeight;
   }
 
   w = NS_MAX(w, 0.0f);
   h = NS_MAX(h, 0.0f);
 
   switch (aCtxType) {
-  case nsSVGUtils::X:
+  case SVGContentUtils::X:
     return w;
-  case nsSVGUtils::Y:
+  case SVGContentUtils::Y:
     return h;
-  case nsSVGUtils::XY:
-    return float(nsSVGUtils::ComputeNormalizedHypotenuse(w, h));
+  case SVGContentUtils::XY:
+    return float(SVGContentUtils::ComputeNormalizedHypotenuse(w, h));
   }
   return 0;
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 /* virtual */ gfxMatrix
--- a/content/svg/content/src/nsSVGStopElement.cpp
+++ b/content/svg/content/src/nsSVGStopElement.cpp
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsSVGStylableElement.h"
 #include "nsIDOMSVGStopElement.h"
 #include "nsSVGNumber2.h"
-#include "nsSVGUtils.h"
 #include "nsGenericHTMLElement.h"
 
 using namespace mozilla;
 
 typedef nsSVGStylableElement nsSVGStopElementBase;
 
 class nsSVGStopElement : public nsSVGStopElementBase,
                          public nsIDOMSVGStopElement
--- a/content/svg/content/src/nsSVGTextElement.cpp
+++ b/content/svg/content/src/nsSVGTextElement.cpp
@@ -133,44 +133,44 @@ NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGTex
 //----------------------------------------------------------------------
 // nsIDOMSVGTextPositioningElement methods
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList x; */
 NS_IMETHODIMP
 nsSVGTextElement::GetX(nsIDOMSVGAnimatedLengthList * *aX)
 {
   *aX = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[X],
-                                                this, X, nsSVGUtils::X).get();
+                                                this, X, SVGContentUtils::X).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList y; */
 NS_IMETHODIMP
 nsSVGTextElement::GetY(nsIDOMSVGAnimatedLengthList * *aY)
 {
   *aY = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[Y],
-                                                this, Y, nsSVGUtils::Y).get();
+                                                this, Y, SVGContentUtils::Y).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList dx; */
 NS_IMETHODIMP
 nsSVGTextElement::GetDx(nsIDOMSVGAnimatedLengthList * *aDx)
 {
   *aDx = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DX],
-                                                 this, DX, nsSVGUtils::X).get();
+                                                 this, DX, SVGContentUtils::X).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList dy; */
 NS_IMETHODIMP
 nsSVGTextElement::GetDy(nsIDOMSVGAnimatedLengthList * *aDy)
 {
   *aDy = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DY],
-                                                 this, DY, nsSVGUtils::Y).get();
+                                                 this, DY, SVGContentUtils::Y).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedNumberList rotate; */
 NS_IMETHODIMP
 nsSVGTextElement::GetRotate(nsIDOMSVGAnimatedNumberList * *aRotate)
 {
   *aRotate = DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[ROTATE],
@@ -334,20 +334,20 @@ nsSVGTextElement::IsAttributeMapped(cons
     nsSVGTextElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthListInfo nsSVGTextElement::sLengthListInfo[4] =
 {
-  { &nsGkAtoms::x,  nsSVGUtils::X, false },
-  { &nsGkAtoms::y,  nsSVGUtils::Y, false },
-  { &nsGkAtoms::dx, nsSVGUtils::X, true },
-  { &nsGkAtoms::dy, nsSVGUtils::Y, true }
+  { &nsGkAtoms::x,  SVGContentUtils::X, false },
+  { &nsGkAtoms::y,  SVGContentUtils::Y, false },
+  { &nsGkAtoms::dx, SVGContentUtils::X, true },
+  { &nsGkAtoms::dy, SVGContentUtils::Y, true }
 };
 
 nsSVGElement::LengthListAttributesInfo
 nsSVGTextElement::GetLengthListInfo()
 {
   return LengthListAttributesInfo(mLengthListAttributes, sLengthListInfo,
                                   ArrayLength(sLengthListInfo));
 }
--- a/content/svg/content/src/nsSVGTextPathElement.cpp
+++ b/content/svg/content/src/nsSVGTextPathElement.cpp
@@ -13,17 +13,17 @@
 #include "nsSVGTextPathElement.h"
 #include "nsError.h"
 #include "nsContentUtils.h"
 
 using namespace mozilla;
 
 nsSVGElement::LengthInfo nsSVGTextPathElement::sLengthInfo[1] =
 {
-  { &nsGkAtoms::startOffset, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
+  { &nsGkAtoms::startOffset, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
 };
 
 nsSVGEnumMapping nsSVGTextPathElement::sMethodMap[] = {
   {&nsGkAtoms::align, nsIDOMSVGTextPathElement::TEXTPATH_METHODTYPE_ALIGN},
   {&nsGkAtoms::stretch, nsIDOMSVGTextPathElement::TEXTPATH_METHODTYPE_STRETCH},
   {nullptr, 0}
 };
 
--- a/content/svg/content/src/nsSVGTextPositioningElement.cpp
+++ b/content/svg/content/src/nsSVGTextPositioningElement.cpp
@@ -1,31 +1,31 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "nsSVGTextPositioningElement.h"
-#include "nsSVGUtils.h"
 #include "SVGAnimatedLengthList.h"
 #include "DOMSVGAnimatedLengthList.h"
+#include "DOMSVGAnimatedNumberList.h"
+#include "SVGContentUtils.h"
 #include "SVGLengthList.h"
-#include "DOMSVGAnimatedNumberList.h"
 
 using namespace mozilla;
 
 
 nsSVGElement::LengthListInfo nsSVGTextPositioningElement::sLengthListInfo[4] =
 {
-  { &nsGkAtoms::x,  nsSVGUtils::X, false },
-  { &nsGkAtoms::y,  nsSVGUtils::Y, false },
-  { &nsGkAtoms::dx, nsSVGUtils::X, true },
-  { &nsGkAtoms::dy, nsSVGUtils::Y, true }
+  { &nsGkAtoms::x,  SVGContentUtils::X, false },
+  { &nsGkAtoms::y,  SVGContentUtils::Y, false },
+  { &nsGkAtoms::dx, SVGContentUtils::X, true },
+  { &nsGkAtoms::dy, SVGContentUtils::Y, true }
 };
 
 nsSVGElement::LengthListAttributesInfo
 nsSVGTextPositioningElement::GetLengthListInfo()
 {
   return LengthListAttributesInfo(mLengthListAttributes, sLengthListInfo,
                                   ArrayLength(sLengthListInfo));
 }
@@ -45,41 +45,41 @@ nsSVGTextPositioningElement::GetNumberLi
 
 //----------------------------------------------------------------------
 // nsIDOMSVGTextPositioningElement methods
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList x; */
 NS_IMETHODIMP nsSVGTextPositioningElement::GetX(nsIDOMSVGAnimatedLengthList * *aX)
 {
   *aX = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[X],
-                                                this, X, nsSVGUtils::X).get();
+                                                this, X, SVGContentUtils::X).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList y; */
 NS_IMETHODIMP nsSVGTextPositioningElement::GetY(nsIDOMSVGAnimatedLengthList * *aY)
 {
   *aY = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[Y],
-                                                this, Y, nsSVGUtils::Y).get();
+                                                this, Y, SVGContentUtils::Y).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList dx; */
 NS_IMETHODIMP nsSVGTextPositioningElement::GetDx(nsIDOMSVGAnimatedLengthList * *aDx)
 {
   *aDx = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DX],
-                                                 this, DX, nsSVGUtils::X).get();
+                                                 this, DX, SVGContentUtils::X).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList dy; */
 NS_IMETHODIMP nsSVGTextPositioningElement::GetDy(nsIDOMSVGAnimatedLengthList * *aDy)
 {
   *aDy = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DY],
-                                                 this, DY, nsSVGUtils::Y).get();
+                                                 this, DY, SVGContentUtils::Y).get();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMSVGAnimatedNumberList rotate; */
 NS_IMETHODIMP nsSVGTextPositioningElement::GetRotate(nsIDOMSVGAnimatedNumberList * *aRotate)
 {
   *aRotate = DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[ROTATE],
                                                      this, ROTATE).get();
--- a/content/svg/content/src/nsSVGUseElement.cpp
+++ b/content/svg/content/src/nsSVGUseElement.cpp
@@ -18,20 +18,20 @@
 using namespace mozilla;
 using namespace mozilla::dom;
 
 ////////////////////////////////////////////////////////////////////////
 // implementation
 
 nsSVGElement::LengthInfo nsSVGUseElement::sLengthInfo[4] =
 {
-  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
-  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
-  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
+  { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
+  { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
+  { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 nsSVGElement::StringInfo nsSVGUseElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Use)
@@ -409,17 +409,17 @@ nsSVGUseElement::SyncWidthOrHeight(nsIAt
       // need to revert the clone's width/height to the width/height of the
       // content that's being cloned.
       TriggerReclone();
       return;
     }
     // Our width/height attribute is now no longer explicitly set, so we
     // need to set the value to 100%
     nsSVGLength2 length;
-    length.Init(nsSVGUtils::XY, 0xff,
+    length.Init(SVGContentUtils::XY, 0xff,
                 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE);
     target->SetLength(aName, length);
     return;
   }
 }
 
 void
 nsSVGUseElement::LookupHref()
--- a/content/svg/content/src/nsSVGViewBox.cpp
+++ b/content/svg/content/src/nsSVGViewBox.cpp
@@ -1,20 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSVGViewBox.h"
-#include "nsSVGUtils.h"
 #include "prdtoa.h"
 #include "nsTextFormatter.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsMathUtils.h"
 #include "nsSMILValue.h"
+#include "SVGContentUtils.h"
 #include "SVGViewBoxSMILType.h"
 
 #define NUM_VIEWBOX_COMPONENTS 4
 using namespace mozilla;
 
 /* Implementation of nsSVGViewBoxRect methods */
 
 bool
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -113,17 +113,17 @@
 #include "nsThreadUtils.h"
 #include "nsStyleSheetService.h"
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
 #ifdef MOZ_MEDIA
 #include "nsHTMLMediaElement.h"
 #endif
 #include "nsSMILAnimationController.h"
-#include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 #include "SVGFragmentIdentifier.h"
 
 #include "nsRefreshDriver.h"
 
 // Drag & Drop, Clipboard
 #include "nsWidgetsCID.h"
 #include "nsIClipboard.h"
 #include "nsIClipboardHelper.h"
@@ -2877,17 +2877,17 @@ PresShell::GoToAnchor(const nsAString& a
       fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
       if (SameCOMIdentity(win, focusedWindow)) {
         fm->ClearFocus(focusedWindow);
       }
     }
 
     // If the target is an animation element, activate the animation
     if (content->IsNodeOfType(nsINode::eANIMATION)) {
-      nsSVGUtils::ActivateByHyperlink(content.get());
+      SVGContentUtils::ActivateByHyperlink(content.get());
     }
   } else {
     rv = NS_ERROR_FAILURE;
     NS_NAMED_LITERAL_STRING(top, "top");
     if (nsContentUtils::EqualsIgnoreASCIICase(aAnchorName, top)) {
       // Scroll to the top/left if aAnchorName is "top" and there is no element
       // with such a name or id.
       rv = NS_OK;
--- a/layout/svg/base/src/Makefile.in
+++ b/layout/svg/base/src/Makefile.in
@@ -70,17 +70,16 @@ include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES	= \
 		-I$(srcdir)/../../../base \
 		-I$(srcdir)/../../../generic \
 		-I$(srcdir)/../../../style \
 		-I$(srcdir)/../../../xul/base/src \
 		-I$(srcdir)/../../../../content/svg/content/src \
 		-I$(srcdir)/../../../../content/base/src \
-		-I$(srcdir)/../../../../content/smil \
 		$(NULL)
 
 libs::
 	$(INSTALL) $(srcdir)/svg.css $(DIST)/bin/res
 
 install::
 	$(SYSINSTALL) $(IFLAGS1) $(srcdir)/svg.css $(DESTDIR)$(mozappdir)/res
 
--- a/layout/svg/base/src/nsSVGFilterInstance.cpp
+++ b/layout/svg/base/src/nsSVGFilterInstance.cpp
@@ -10,63 +10,64 @@
 #include "gfxPlatform.h"
 #include "gfxUtils.h"
 #include "nsIDOMSVGUnitTypes.h"
 #include "nsISVGChildFrame.h"
 #include "nsRenderingContext.h"
 #include "nsSVGFilterElement.h"
 #include "nsSVGFilterPaintCallback.h"
 #include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 
 float
 nsSVGFilterInstance::GetPrimitiveNumber(uint8_t aCtxType, float aValue) const
 {
   nsSVGLength2 val;
   val.Init(aCtxType, 0xff, aValue,
            nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
 
   float value;
   if (mPrimitiveUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
     value = nsSVGUtils::ObjectSpace(mTargetBBox, &val);
   } else {
     value = nsSVGUtils::UserSpace(mTargetFrame, &val);
   }
 
   switch (aCtxType) {
-  case nsSVGUtils::X:
+  case SVGContentUtils::X:
     return value * mFilterSpaceSize.width / mFilterRegion.Width();
-  case nsSVGUtils::Y:
+  case SVGContentUtils::Y:
     return value * mFilterSpaceSize.height / mFilterRegion.Height();
-  case nsSVGUtils::XY:
+  case SVGContentUtils::XY:
   default:
-    return value * nsSVGUtils::ComputeNormalizedHypotenuse(
+    return value * SVGContentUtils::ComputeNormalizedHypotenuse(
                      mFilterSpaceSize.width / mFilterRegion.Width(),
                      mFilterSpaceSize.height / mFilterRegion.Height());
   }
 }
 
 void
 nsSVGFilterInstance::ConvertLocation(float aValues[3]) const
 {
   nsSVGLength2 val[4];
-  val[0].Init(nsSVGUtils::X, 0xff, aValues[0],
+  val[0].Init(SVGContentUtils::X, 0xff, aValues[0],
               nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
-  val[1].Init(nsSVGUtils::Y, 0xff, aValues[1],
+  val[1].Init(SVGContentUtils::Y, 0xff, aValues[1],
               nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
   // Dummy width/height values
-  val[2].Init(nsSVGUtils::X, 0xff, 0,
+  val[2].Init(SVGContentUtils::X, 0xff, 0,
               nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
-  val[3].Init(nsSVGUtils::Y, 0xff, 0,
+  val[3].Init(SVGContentUtils::Y, 0xff, 0,
               nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
 
   gfxRect feArea = nsSVGUtils::GetRelativeRect(mPrimitiveUnits,
     val, mTargetBBox, mTargetFrame);
   aValues[0] = feArea.X();
   aValues[1] = feArea.Y();
-  aValues[2] = GetPrimitiveNumber(nsSVGUtils::XY, aValues[2]);
+  aValues[2] = GetPrimitiveNumber(SVGContentUtils::XY, aValues[2]);
 }
 
 already_AddRefed<gfxImageSurface>
 nsSVGFilterInstance::CreateImage()
 {
   nsRefPtr<gfxImageSurface> surface =
     new gfxImageSurface(gfxIntSize(mSurfaceRect.width, mSurfaceRect.height),
                         gfxASurface::ImageFormatARGB32);
--- a/layout/svg/base/src/nsSVGGlyphFrame.cpp
+++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp
@@ -19,16 +19,17 @@
 #include "nsRenderingContext.h"
 #include "nsSVGEffects.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGPaintServerFrame.h"
 #include "nsSVGRect.h"
 #include "nsSVGTextPathFrame.h"
 #include "nsSVGUtils.h"
 #include "nsTextFragment.h"
+#include "SVGContentUtils.h"
 #include "SVGLengthList.h"
 
 using namespace mozilla;
 
 struct CharacterPosition {
   gfxPoint pos;
   gfxFloat angle;
   bool draw;
@@ -1811,17 +1812,17 @@ nsSVGGlyphFrame::EnsureTextRun(float *aD
       if (m.IsSingular())
         return false;
     }
 
     // The context scale is the ratio of the length of the transformed
     // diagonal vector (1,1) to the length of the untransformed diagonal
     // (which is sqrt(2)).
     gfxPoint p = m.Transform(gfxPoint(1, 1)) - m.Transform(gfxPoint(0, 0));
-    double contextScale = nsSVGUtils::ComputeNormalizedHypotenuse(p.x, p.y);
+    double contextScale = SVGContentUtils::ComputeNormalizedHypotenuse(p.x, p.y);
 
     if (GetStyleSVG()->mTextRendering ==
         NS_STYLE_TEXT_RENDERING_GEOMETRICPRECISION) {
       textRunSize = PRECISE_SIZE;
     } else {
       textRunSize = size*contextScale;
       textRunSize = NS_MAX(textRunSize, double(CLAMP_MIN_SIZE));
       textRunSize = NS_MIN(textRunSize, double(CLAMP_MAX_SIZE));
--- a/layout/svg/base/src/nsSVGImageFrame.cpp
+++ b/layout/svg/base/src/nsSVGImageFrame.cpp
@@ -12,16 +12,17 @@
 #include "nsLayoutUtils.h"
 #include "nsRenderingContext.h"
 #include "nsStubImageDecoderObserver.h"
 #include "nsSVGEffects.h"
 #include "nsSVGImageElement.h"
 #include "nsSVGPathGeometryFrame.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGUtils.h"
+#include "SVGContentUtils.h"
 
 using namespace mozilla;
 
 class nsSVGImageFrame;
 
 class nsSVGImageListener MOZ_FINAL : public nsStubImageDecoderObserver
 {
 public:
@@ -226,20 +227,20 @@ nsSVGImageFrame::GetRasterImageTransform
                                          int32_t aNativeHeight,
                                          uint32_t aFor)
 {
   float x, y, width, height;
   nsSVGImageElement *element = static_cast<nsSVGImageElement*>(mContent);
   element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
 
   gfxMatrix viewBoxTM =
-    nsSVGUtils::GetViewBoxTransform(element,
-                                    width, height,
-                                    0, 0, aNativeWidth, aNativeHeight,
-                                    element->mPreserveAspectRatio);
+    SVGContentUtils::GetViewBoxTransform(element,
+                                         width, height,
+                                         0, 0, aNativeWidth, aNativeHeight,
+                                         element->mPreserveAspectRatio);
 
   return viewBoxTM * gfxMatrix().Translate(gfxPoint(x, y)) * GetCanvasTM(aFor);
 }
 
 gfxMatrix
 nsSVGImageFrame::GetVectorImageTransform(uint32_t aFor)
 {
   float x, y, width, height;
--- a/layout/svg/base/src/nsSVGPatternFrame.cpp
+++ b/layout/svg/base/src/nsSVGPatternFrame.cpp
@@ -16,16 +16,17 @@
 #include "nsISVGChildFrame.h"
 #include "nsRenderingContext.h"
 #include "nsStyleContext.h"
 #include "nsSVGEffects.h"
 #include "nsSVGGeometryFrame.h"
 #include "nsSVGPatternElement.h"
 #include "nsSVGUtils.h"
 #include "SVGAnimatedTransformList.h"
+#include "SVGContentUtils.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 // Helper classes
 
 class nsSVGPatternFrame::AutoPatternReferencer
 {
@@ -656,17 +657,17 @@ nsSVGPatternFrame::ConstructCTM(const ns
     viewportHeight =
       GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(aTarget);
   }
 
   if (viewportWidth <= 0.0f || viewportHeight <= 0.0f) {
     return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
   }
 
-  gfxMatrix tm = nsSVGUtils::GetViewBoxTransform(
+  gfxMatrix tm = SVGContentUtils::GetViewBoxTransform(
     static_cast<nsSVGPatternElement*>(mContent),
     viewportWidth, viewportHeight,
     viewBoxRect.x, viewBoxRect.y,
     viewBoxRect.width, viewBoxRect.height,
     GetPreserveAspectRatio());
 
   return tm * tCTM;
 }
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -12,35 +12,30 @@
 #include "gfxImageSurface.h"
 #include "gfxMatrix.h"
 #include "gfxPlatform.h"
 #include "gfxRect.h"
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/Preferences.h"
 #include "nsCSSFrameConstructor.h"
-#include "nsComputedDOMStyle.h"
-#include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsFrameList.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
-#include "nsIDOMSVGElement.h"
 #include "nsIDOMSVGUnitTypes.h"
 #include "nsIFrame.h"
 #include "nsINameSpaceManager.h"
 #include "nsIPresShell.h"
-#include "nsIScriptError.h"
 #include "nsISVGChildFrame.h"
 #include "nsPresContext.h"
 #include "nsRenderingContext.h"
 #include "nsStyleCoord.h"
 #include "nsStyleStruct.h"
-#include "nsSVGAnimationElement.h"
 #include "nsSVGClipPathFrame.h"
 #include "nsSVGContainerFrame.h"
 #include "nsSVGEffects.h"
 #include "nsSVGFilterFrame.h"
 #include "nsSVGFilterPaintCallback.h"
 #include "nsSVGForeignObjectFrame.h"
 #include "nsSVGGeometryFrame.h"
 #include "nsSVGGlyphFrame.h"
@@ -51,17 +46,17 @@
 #include "nsSVGOuterSVGFrame.h"
 #include "nsSVGPathElement.h"
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGPathGeometryFrame.h"
 #include "nsSVGPaintServerFrame.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGTextContainerFrame.h"
 #include "nsTextFrame.h"
-#include "SVGAnimatedPreserveAspectRatio.h"
+#include "SVGContentUtils.h"
 #include "mozilla/unused.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 
 // c = n / 255
 // (c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055) * 255 + 0.5
@@ -228,129 +223,16 @@ nsSVGUtils::Init()
 
   Preferences::AddBoolVarCache(&sSVGDisplayListPaintingEnabled,
                                "svg.display-lists.painting.enabled");
 
   Preferences::AddBoolVarCache(&sSVGTextCSSFramesEnabled,
                                "svg.text.css-frames.enabled");
 }
 
-nsSVGSVGElement*
-nsSVGUtils::GetOuterSVGElement(nsSVGElement *aSVGElement)
-{
-  nsIContent *element = nullptr;
-  nsIContent *ancestor = aSVGElement->GetFlattenedTreeParent();
-
-  while (ancestor && ancestor->IsSVG() &&
-                     ancestor->Tag() != nsGkAtoms::foreignObject) {
-    element = ancestor;
-    ancestor = element->GetFlattenedTreeParent();
-  }
-
-  if (element && element->Tag() == nsGkAtoms::svg) {
-    return static_cast<nsSVGSVGElement*>(element);
-  }
-  return nullptr;
-}
-
-void
-nsSVGUtils::ActivateByHyperlink(nsIContent *aContent)
-{
-  NS_ABORT_IF_FALSE(aContent->IsNodeOfType(nsINode::eANIMATION),
-                    "Expecting an animation element");
-
-  static_cast<nsSVGAnimationElement*>(aContent)->ActivateByHyperlink();
-}
-
-float
-nsSVGUtils::GetFontSize(Element *aElement)
-{
-  if (!aElement)
-    return 1.0f;
-
-  nsRefPtr<nsStyleContext> styleContext = 
-    nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
-                                                         nullptr, nullptr);
-  if (!styleContext) {
-    // ReportToConsole
-    NS_WARNING("Couldn't get style context for content in GetFontStyle");
-    return 1.0f;
-  }
-
-  return GetFontSize(styleContext);
-}
-
-float
-nsSVGUtils::GetFontSize(nsIFrame *aFrame)
-{
-  NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontSize");
-  return GetFontSize(aFrame->GetStyleContext());
-}
-
-float
-nsSVGUtils::GetFontSize(nsStyleContext *aStyleContext)
-{
-  NS_ABORT_IF_FALSE(aStyleContext, "NULL style context in GetFontSize");
-
-  nsPresContext *presContext = aStyleContext->PresContext();
-  NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontSize");
-
-  nscoord fontSize = aStyleContext->GetStyleFont()->mSize;
-  return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) / 
-         presContext->TextZoom();
-}
-
-float
-nsSVGUtils::GetFontXHeight(Element *aElement)
-{
-  if (!aElement)
-    return 1.0f;
-
-  nsRefPtr<nsStyleContext> styleContext = 
-    nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
-                                                         nullptr, nullptr);
-  if (!styleContext) {
-    // ReportToConsole
-    NS_WARNING("Couldn't get style context for content in GetFontStyle");
-    return 1.0f;
-  }
-
-  return GetFontXHeight(styleContext);
-}
-  
-float
-nsSVGUtils::GetFontXHeight(nsIFrame *aFrame)
-{
-  NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontXHeight");
-  return GetFontXHeight(aFrame->GetStyleContext());
-}
-
-float
-nsSVGUtils::GetFontXHeight(nsStyleContext *aStyleContext)
-{
-  NS_ABORT_IF_FALSE(aStyleContext, "NULL style context in GetFontXHeight");
-
-  nsPresContext *presContext = aStyleContext->PresContext();
-  NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontXHeight");
-
-  nsRefPtr<nsFontMetrics> fontMetrics;
-  nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
-                                               getter_AddRefs(fontMetrics));
-
-  if (!fontMetrics) {
-    // ReportToConsole
-    NS_WARNING("no FontMetrics in GetFontXHeight()");
-    return 1.0f;
-  }
-
-  nscoord xHeight = fontMetrics->XHeight();
-  return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) /
-         presContext->TextZoom();
-}
-
 void
 nsSVGUtils::UnPremultiplyImageDataAlpha(uint8_t *data, 
                                         int32_t stride,
                                         const nsIntRect &rect)
 {
   for (int32_t y = rect.y; y < rect.YMost(); y++) {
     for (int32_t x = rect.x; x < rect.XMost(); x++) {
       uint8_t *pixel = data + stride * y + 4 * x;
@@ -428,158 +310,38 @@ nsSVGUtils::ConvertImageDataFromLinearRG
       pixel[GFX_ARGB32_OFFSET_G] =
         glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
       pixel[GFX_ARGB32_OFFSET_R] =
         glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
     }
   }
 }
 
-nsresult
-nsSVGUtils::ReportToConsole(nsIDocument* doc,
-                            const char* aWarning,
-                            const PRUnichar **aParams,
-                            uint32_t aParamsLength)
-{
-  return nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
-                                         "SVG", doc,
-                                         nsContentUtils::eSVG_PROPERTIES,
-                                         aWarning,
-                                         aParams, aParamsLength);
-}
-
 float
 nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
                          nsSVGElement *aContent,
                          const nsStyleCoord &aCoord)
 {
   switch (aCoord.GetUnit()) {
   case eStyleUnit_Factor:
     // user units
     return aCoord.GetFactorValue();
 
   case eStyleUnit_Coord:
     return nsPresContext::AppUnitsToFloatCSSPixels(aCoord.GetCoordValue());
 
   case eStyleUnit_Percent: {
       nsSVGSVGElement* ctx = aContent->GetCtx();
-      return ctx ? aCoord.GetPercentValue() * ctx->GetLength(nsSVGUtils::XY) : 0.0f;
+      return ctx ? aCoord.GetPercentValue() * ctx->GetLength(SVGContentUtils::XY) : 0.0f;
     }
   default:
     return 0.0f;
   }
 }
 
-bool
-nsSVGUtils::EstablishesViewport(nsIContent *aContent)
-{
-  // Although SVG 1.1 states that <image> is an element that establishes a
-  // viewport, this is really only for the document it references, not
-  // for any child content, which is what this function is used for.
-  return aContent && aContent->IsSVG() &&
-           (aContent->Tag() == nsGkAtoms::svg ||
-            aContent->Tag() == nsGkAtoms::foreignObject ||
-            aContent->Tag() == nsGkAtoms::symbol);
-}
-
-already_AddRefed<nsIDOMSVGElement>
-nsSVGUtils::GetNearestViewportElement(nsIContent *aContent)
-{
-  nsIContent *element = aContent->GetFlattenedTreeParent();
-
-  while (element && element->IsSVG()) {
-    if (EstablishesViewport(element)) {
-      if (element->Tag() == nsGkAtoms::foreignObject) {
-        return nullptr;
-      }
-      return nsCOMPtr<nsIDOMSVGElement>(do_QueryInterface(element)).forget();
-    }
-    element = element->GetFlattenedTreeParent();
-  }
-  return nullptr;
-}
-
-static gfxMatrix
-GetCTMInternal(nsSVGElement *aElement, bool aScreenCTM, bool aHaveRecursed)
-{
-  gfxMatrix matrix = aElement->PrependLocalTransformsTo(gfxMatrix(),
-    aHaveRecursed ? nsSVGElement::eAllTransforms : nsSVGElement::eUserSpaceToParent);
-  nsSVGElement *element = aElement;
-  nsIContent *ancestor = aElement->GetFlattenedTreeParent();
-
-  while (ancestor && ancestor->IsSVG() &&
-                     ancestor->Tag() != nsGkAtoms::foreignObject) {
-    element = static_cast<nsSVGElement*>(ancestor);
-    matrix *= element->PrependLocalTransformsTo(gfxMatrix()); // i.e. *A*ppend
-    if (!aScreenCTM && nsSVGUtils::EstablishesViewport(element)) {
-      if (!element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG) &&
-          !element->NodeInfo()->Equals(nsGkAtoms::symbol, kNameSpaceID_SVG)) {
-        NS_ERROR("New (SVG > 1.1) SVG viewport establishing element?");
-        return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
-      }
-      // XXX spec seems to say x,y translation should be undone for IsInnerSVG
-      return matrix;
-    }
-    ancestor = ancestor->GetFlattenedTreeParent();
-  }
-  if (!aScreenCTM) {
-    // didn't find a nearestViewportElement
-    return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
-  }
-  if (element->Tag() != nsGkAtoms::svg) {
-    // Not a valid SVG fragment
-    return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
-  }
-  if (element == aElement && !aHaveRecursed) {
-    // 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 (!ancestor || !ancestor->IsElement()) {
-    return matrix;
-  }
-  if (ancestor->IsSVG()) {
-    return
-      matrix * GetCTMInternal(static_cast<nsSVGElement*>(ancestor), true, true);
-  }
-
-  // XXX this does not take into account CSS transform, or that the non-SVG
-  // content that we've hit may itself be inside an SVG foreignObject higher up
-  nsIDocument* currentDoc = aElement->GetCurrentDoc();
-  float x = 0.0f, y = 0.0f;
-  if (currentDoc && element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG)) {
-    nsIPresShell *presShell = currentDoc->GetShell();
-    if (presShell) {
-      nsIFrame* frame = element->GetPrimaryFrame();
-      nsIFrame* ancestorFrame = presShell->GetRootFrame();
-      if (frame && ancestorFrame) {
-        nsPoint point = frame->GetOffsetTo(ancestorFrame);
-        x = nsPresContext::AppUnitsToFloatCSSPixels(point.x);
-        y = nsPresContext::AppUnitsToFloatCSSPixels(point.y);
-      }
-    }
-  }
-  return matrix * gfxMatrix().Translate(gfxPoint(x, y));
-}
-
-gfxMatrix
-nsSVGUtils::GetCTM(nsSVGElement *aElement, bool aScreenCTM)
-{
-  nsIDocument* currentDoc = aElement->GetCurrentDoc();
-  if (currentDoc) {
-    // Flush all pending notifications so that our frames are up to date
-    currentDoc->FlushPendingNotifications(Flush_Layout);
-  }
-  return GetCTMInternal(aElement, aScreenCTM, false);
-}
-
 nsSVGDisplayContainerFrame*
 nsSVGUtils::GetNearestSVGViewport(nsIFrame *aFrame)
 {
   NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
   if (aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
     return nullptr;
   }
   while ((aFrame = aFrame->GetParent())) {
@@ -606,17 +368,17 @@ nsSVGUtils::GetPostFilterVisualOverflowR
   }
 
   return filter->GetPostFilterBounds(aFrame, nullptr, &aPreFilterRect);
 }
 
 bool
 nsSVGUtils::OuterSVGIsCallingReflowSVG(nsIFrame *aFrame)
 {
-  return nsSVGUtils::GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
+  return GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
 }
 
 void
 nsSVGUtils::InvalidateBounds(nsIFrame *aFrame, bool aDuringUpdate,
                              const nsRect *aBoundsSubArea, uint32_t aFlags)
 {
   NS_ABORT_IF_FALSE(aFrame->IsFrameOfType(nsIFrame::eSVG) &&
                     !(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG),
@@ -830,36 +592,31 @@ nsSVGUtils::NotifyAncestorsOfFilterRegio
     nsSVGFilterProperty *property = nsSVGEffects::GetFilterProperty(aFrame);
     if (property) {
       property->Invalidate();
     }
     aFrame = aFrame->GetParent();
   }
 }
 
-double
-nsSVGUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
-{
-  return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
-}
-
 float
 nsSVGUtils::ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength)
 {
   float axis;
 
   switch (aLength->GetCtxType()) {
-  case X:
+  case SVGContentUtils::X:
     axis = aRect.Width();
     break;
-  case Y:
+  case SVGContentUtils::Y:
     axis = aRect.Height();
     break;
-  case XY:
-    axis = float(ComputeNormalizedHypotenuse(aRect.Width(), aRect.Height()));
+  case SVGContentUtils::XY:
+    axis = float(SVGContentUtils::ComputeNormalizedHypotenuse(
+                   aRect.Width(), aRect.Height()));
     break;
   default:
     NS_NOTREACHED("unexpected ctx type");
     axis = 0.0f;
     break;
   }
   if (aLength->IsPercentage()) {
     // Multiply first to avoid precision errors:
@@ -875,32 +632,16 @@ nsSVGUtils::UserSpace(nsSVGElement *aSVG
 }
 
 float
 nsSVGUtils::UserSpace(nsIFrame *aNonSVGContext, const nsSVGLength2 *aLength)
 {
   return aLength->GetAnimValue(aNonSVGContext);
 }
 
-float
-nsSVGUtils::AngleBisect(float a1, float a2)
-{
-  float delta = fmod(a2 - a1, static_cast<float>(2*M_PI));
-  if (delta < 0) {
-    delta += 2*M_PI;
-  }
-  /* delta is now the angle from a1 around to a2, in the range [0, 2*M_PI) */
-  float r = a1 + delta/2;
-  if (delta >= M_PI) {
-    /* the arc from a2 to a1 is smaller, so use the ray on that side */
-    r += M_PI;
-  }
-  return r;
-}
-
 nsSVGOuterSVGFrame *
 nsSVGUtils::GetOuterSVGFrame(nsIFrame *aFrame)
 {
   while (aFrame) {
     if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
       return static_cast<nsSVGOuterSVGFrame*>(aFrame);
     }
     aFrame = aFrame->GetParent();
@@ -916,117 +657,16 @@ nsSVGUtils::GetOuterSVGFrameAndCoveredRe
   if (!svg)
     return nullptr;
   *aRect = (aFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) ?
              nsRect(0, 0, 0, 0) : svg->GetCoveredRegion();
   return GetOuterSVGFrame(aFrame);
 }
 
 gfxMatrix
-nsSVGUtils::GetViewBoxTransform(const nsSVGElement* aElement,
-                                float aViewportWidth, float aViewportHeight,
-                                float aViewboxX, float aViewboxY,
-                                float aViewboxWidth, float aViewboxHeight,
-                                const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio)
-{
-  return GetViewBoxTransform(aElement,
-                             aViewportWidth, aViewportHeight,
-                             aViewboxX, aViewboxY,
-                             aViewboxWidth, aViewboxHeight,
-                             aPreserveAspectRatio.GetAnimValue());
-}
-
-gfxMatrix
-nsSVGUtils::GetViewBoxTransform(const nsSVGElement* aElement,
-                                float aViewportWidth, float aViewportHeight,
-                                float aViewboxX, float aViewboxY,
-                                float aViewboxWidth, float aViewboxHeight,
-                                const SVGPreserveAspectRatio &aPreserveAspectRatio)
-{
-  NS_ASSERTION(aViewportWidth  >= 0, "viewport width must be nonnegative!");
-  NS_ASSERTION(aViewportHeight >= 0, "viewport height must be nonnegative!");
-  NS_ASSERTION(aViewboxWidth  > 0, "viewBox width must be greater than zero!");
-  NS_ASSERTION(aViewboxHeight > 0, "viewBox height must be greater than zero!");
-
-  uint16_t align = aPreserveAspectRatio.GetAlign();
-  uint16_t meetOrSlice = aPreserveAspectRatio.GetMeetOrSlice();
-
-  // default to the defaults
-  if (align == nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_UNKNOWN)
-    align = nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID;
-  if (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_UNKNOWN)
-    meetOrSlice = nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET;
-
-  float a, d, e, f;
-  a = aViewportWidth / aViewboxWidth;
-  d = aViewportHeight / aViewboxHeight;
-  e = 0.0f;
-  f = 0.0f;
-
-  if (align != nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE &&
-      a != d) {
-    if ((meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET &&
-        a < d) ||
-        (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE &&
-        d < a)) {
-      d = a;
-      switch (align) {
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
-        break;
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
-        f = (aViewportHeight - a * aViewboxHeight) / 2.0f;
-        break;
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
-        f = aViewportHeight - a * aViewboxHeight;
-        break;
-      default:
-        NS_NOTREACHED("Unknown value for align");
-      }
-    }
-    else if (
-      (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET &&
-      d < a) ||
-      (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE &&
-      a < d)) {
-      a = d;
-      switch (align) {
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
-        break;
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
-        e = (aViewportWidth - a * aViewboxWidth) / 2.0f;
-        break;
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
-      case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
-        e = aViewportWidth - a * aViewboxWidth;
-        break;
-      default:
-        NS_NOTREACHED("Unknown value for align");
-      }
-    }
-    else NS_NOTREACHED("Unknown value for meetOrSlice");
-  }
-  
-  if (aViewboxX) e += -a * aViewboxX;
-  if (aViewboxY) f += -d * aViewboxY;
-  
-  return gfxMatrix(a, 0.0f, 0.0f, d, e, f);
-}
-
-gfxMatrix
 nsSVGUtils::GetCanvasTM(nsIFrame *aFrame, uint32_t aFor)
 {
   // XXX yuck, we really need a common interface for GetCanvasTM
 
   if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
     return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
   }
 
@@ -1181,17 +821,17 @@ nsSVGUtils::PaintFrameWithEffects(nsRend
     if (aFrame->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer)) {
       gfxMatrix childrenOnlyTM;
       if (static_cast<nsSVGContainerFrame*>(aFrame)->
             HasChildrenOnlyTransform(&childrenOnlyTM)) {
         // Undo the children-only transform:
         tm = childrenOnlyTM.Invert() * tm;
       }
     }
-    nsIntRect bounds = nsSVGUtils::TransformFrameRectToOuterSVG(overflowRect,
+    nsIntRect bounds = TransformFrameRectToOuterSVG(overflowRect,
                          tm, aFrame->PresContext()).
                            ToOutsidePixels(appUnitsPerDevPx);
     if (!aDirtyRect->Intersects(bounds)) {
       return;
     }
   }
 
   /* SVG defines the following rendering model:
@@ -1717,39 +1357,16 @@ nsSVGUtils::GetFirstNonAAncestorFrame(ns
        ancestorFrame = ancestorFrame->GetParent()) {
     if (ancestorFrame->GetType() != nsGkAtoms::svgAFrame) {
       return ancestorFrame;
     }
   }
   return nullptr;
 }
 
-#ifdef DEBUG
-void
-nsSVGUtils::WritePPM(const char *fname, gfxImageSurface *aSurface)
-{
-  FILE *f = fopen(fname, "wb");
-  if (!f)
-    return;
-
-  gfxIntSize size = aSurface->GetSize();
-  fprintf(f, "P6\n%d %d\n255\n", size.width, size.height);
-  unsigned char *data = aSurface->Data();
-  int32_t stride = aSurface->Stride();
-  for (int y=0; y<size.height; y++) {
-    for (int x=0; x<size.width; x++) {
-      unused << fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_R, 1, 1, f);
-      unused << fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_G, 1, 1, f);
-      unused << fwrite(data + y * stride + 4 * x + GFX_ARGB32_OFFSET_B, 1, 1, f);
-    }
-  }
-  fclose(f);
-}
-#endif
-
 gfxMatrix
 nsSVGUtils::GetStrokeTransform(nsIFrame *aFrame)
 {
   if (aFrame->GetStyleSVGReset()->mVectorEffect ==
       NS_STYLE_VECTOR_EFFECT_NON_SCALING_STROKE) {
  
     if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
       aFrame = aFrame->GetParent();
@@ -1757,17 +1374,17 @@ nsSVGUtils::GetStrokeTransform(nsIFrame 
 
     nsIContent *content = aFrame->GetContent();
     NS_ABORT_IF_FALSE(content->IsSVG(), "bad cast");
 
     // a non-scaling stroke is in the screen co-ordinate
     // space rather so we need to invert the transform
     // to the screen co-ordinate space to get there.
     // See http://www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke
-    gfxMatrix transform = nsSVGUtils::GetCTM(
+    gfxMatrix transform = SVGContentUtils::GetCTM(
                             static_cast<nsSVGElement*>(content), true);
     if (!transform.IsSingular()) {
       return transform.Invert();
     }
   }
   return gfxMatrix();
 }
 
@@ -2039,18 +1656,18 @@ nsSVGUtils::GetStrokeWidth(nsIFrame* aFr
 
   nsIContent* content = aFrame->GetContent();
   if (content->IsNodeOfType(nsINode::eTEXT)) {
     content = content->GetParent();
   }
 
   nsSVGElement *ctx = static_cast<nsSVGElement*>(content);
 
-  return nsSVGUtils::CoordToFloat(aFrame->PresContext(), ctx,
-                                  style->mStrokeWidth);
+  return CoordToFloat(aFrame->PresContext(), ctx,
+                      style->mStrokeWidth);
 }
 
 void
 nsSVGUtils::SetupCairoStrokeGeometry(nsIFrame* aFrame, gfxContext *aContext,
                                      gfxTextObjectPaint *aObjectPaint)
 {
   float width = GetStrokeWidth(aFrame, aObjectPaint);
   if (width <= 0)
--- a/layout/svg/base/src/nsSVGUtils.h
+++ b/layout/svg/base/src/nsSVGUtils.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NS_SVGUTILS_H
 #define NS_SVGUTILS_H
 
-// include math.h to pick up definition of M_SQRT1_2 if the platform defines it
+// include math.h to pick up definition of M_ maths defines e.g. M_PI
 #define _USE_MATH_DEFINES
 #include <math.h>
 
 #include "gfxMatrix.h"
 #include "gfxPoint.h"
 #include "gfxRect.h"
 #include "nsAlgorithm.h"
 #include "nsChangeHint.h"
@@ -27,30 +27,28 @@
 
 class gfxASurface;
 class gfxContext;
 class gfxImageSurface;
 class gfxPattern;
 class nsFrameList;
 class nsIContent;
 class nsIDocument;
-class nsIDOMSVGElement;
 class nsIFrame;
 class nsPresContext;
 class nsRenderingContext;
 class nsStyleContext;
 class nsStyleCoord;
 class nsSVGDisplayContainerFrame;
 class nsSVGElement;
 class nsSVGEnum;
 class nsSVGGeometryFrame;
 class nsSVGLength2;
 class nsSVGOuterSVGFrame;
 class nsSVGPathGeometryFrame;
-class nsSVGSVGElement;
 class nsTextFrame;
 class gfxTextObjectPaint;
 
 struct nsStyleSVG;
 struct nsStyleSVGPaint;
 
 namespace mozilla {
 class SVGAnimatedPreserveAspectRatio;
@@ -85,40 +83,22 @@ class Element;
 #endif
 
 // maximum dimension of an offscreen surface - choose so that
 // the surface size doesn't overflow a 32-bit signed int using
 // 4 bytes per pixel; in line with gfxASurface::CheckSurfaceSize
 // In fact Macs can't even manage that
 #define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
 
-#define SVG_WSP_DELIM       "\x20\x9\xD\xA"
-#define SVG_COMMA_WSP_DELIM "," SVG_WSP_DELIM
-
 #define SVG_HIT_TEST_FILL        0x01
 #define SVG_HIT_TEST_STROKE      0x02
 #define SVG_HIT_TEST_CHECK_MRECT 0x04
 
-inline bool
-IsSVGWhitespace(char aChar)
-{
-  return aChar == '\x20' || aChar == '\x9' ||
-         aChar == '\xD'  || aChar == '\xA';
-}
-
-inline bool
-IsSVGWhitespace(PRUnichar aChar)
-{
-  return aChar == PRUnichar('\x20') || aChar == PRUnichar('\x9') ||
-         aChar == PRUnichar('\xD')  || aChar == PRUnichar('\xA');
-}
-
 /*
- * Checks the smil enabled preference.  Declared as a function to match
- * NS_SVGEnabled().
+ * Checks the smil enabled preference.
  */
 bool NS_SMILEnabled();
 
 bool NS_SVGDisplayListHitTestingEnabled();
 bool NS_SVGDisplayListPaintingEnabled();
 bool NS_SVGTextCSSFramesEnabled();
 
 /**
@@ -210,66 +190,28 @@ class nsISVGFilterProperty : public nsIS
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGFILTERPROPERTY_IID)
   virtual void Invalidate() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterProperty, NS_ISVGFILTERPROPERTY_IID)
 
+/**
+ * General functions used by all of SVG layout and possibly content code.
+ * If a method is used by content and depends only on other content methods
+ * it should go in SVGContentUtils instead.
+ */
 class nsSVGUtils
 {
 public:
-  typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
-  typedef mozilla::SVGPreserveAspectRatio SVGPreserveAspectRatio;
 
   static void Init();
 
   /*
-   * Get the parent element of an nsIContent
-   */
-  static mozilla::dom::Element *GetParentElement(nsIContent *aContent);
-
-  /*
-   * Get the outer SVG element of an nsIContent
-   */
-  static nsSVGSVGElement *GetOuterSVGElement(nsSVGElement *aSVGElement);
-
-  /**
-   * Activates the animation element aContent as a result of navigation to the
-   * fragment identifier that identifies aContent. aContent must be an instance
-   * of nsSVGAnimationElement.
-   *
-   * This is just a shim to allow nsSVGAnimationElement::ActivateByHyperlink to
-   * be called from layout/base without adding to that directory's include paths.
-   */
-  static void ActivateByHyperlink(nsIContent *aContent);
-
-  /*
-   * Get the number of CSS px (user units) per em (i.e. the em-height in user
-   * units) for an nsIContent
-   *
-   * XXX document the conditions under which these may fail, and what they
-   * return in those cases.
-   */
-  static float GetFontSize(mozilla::dom::Element *aElement);
-  static float GetFontSize(nsIFrame *aFrame);
-  static float GetFontSize(nsStyleContext *aStyleContext);
-  /*
-   * Get the number of CSS px (user units) per ex (i.e. the x-height in user
-   * units) for an nsIContent
-   *
-   * XXX document the conditions under which these may fail, and what they
-   * return in those cases.
-   */
-  static float GetFontXHeight(mozilla::dom::Element *aElement);
-  static float GetFontXHeight(nsIFrame *aFrame);
-  static float GetFontXHeight(nsStyleContext *aStyleContext);
-
-  /*
    * Converts image data from premultipled to unpremultiplied alpha
    */
   static void UnPremultiplyImageDataAlpha(uint8_t *data, 
                                           int32_t stride, 
                                           const nsIntRect &rect);
   /*
    * Converts image data from unpremultipled to premultiplied alpha
    */
@@ -285,43 +227,24 @@ public:
   /*
    * Converts image data from LinearRGB to premultiplied sRGB
    */
   static void ConvertImageDataFromLinearRGB(uint8_t *data, 
                                             int32_t stride, 
                                             const nsIntRect &rect);
 
   /*
-   * Report a localized error message to the error console.
-   */
-  static nsresult ReportToConsole(nsIDocument* doc,
-                                  const char* aWarning,
-                                  const PRUnichar **aParams,
-                                  uint32_t aParamsLength);
-
-  /*
    * Converts a nsStyleCoord into a userspace value.  Handles units
    * Factor (straight userspace), Coord (dimensioned), and Percent (of
    * the current SVG viewport)
    */
   static float CoordToFloat(nsPresContext *aPresContext,
                             nsSVGElement *aContent,
                             const nsStyleCoord &aCoord);
 
-  static gfxMatrix GetCTM(nsSVGElement *aElement, bool aScreenCTM);
-
-  /**
-   * Check if this is one of the SVG elements that SVG 1.1 Full says
-   * establishes a viewport: svg, symbol, image or foreignObject.
-   */
-  static bool EstablishesViewport(nsIContent *aContent);
-
-  static already_AddRefed<nsIDOMSVGElement>
-  GetNearestViewportElement(nsIContent *aContent);
-
   /**
    * Gets the nearest nsSVGInnerSVGFrame or nsSVGOuterSVGFrame frame. aFrame
    * must be an SVG frame. If aFrame is of type nsGkAtoms::svgOuterSVGFrame,
    * returns nullptr.
    */
   static nsSVGDisplayContainerFrame* GetNearestSVGViewport(nsIFrame *aFrame);
 
   /**
@@ -390,24 +313,16 @@ public:
    */
   static bool NeedsReflowSVG(nsIFrame *aFrame);
 
   /*
    * Update the filter invalidation region for ancestor frames, if relevant.
    */
   static void NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame);
 
-  /* enum for specifying coordinate direction for ObjectSpace/UserSpace */
-  enum ctxDirection { X, Y, XY };
-
-  /**
-   * Computes sqrt((aWidth^2 + aHeight^2)/2);
-   */
-  static double ComputeNormalizedHypotenuse(double aWidth, double aHeight);
-
   /* Computes the input length in terms of object space coordinates.
      Input: rect - bounding box
             length - length to be converted
   */
   static float ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength);
 
   /* Computes the input length in terms of user space coordinates.
      Input: content - object to be used for determining user space
@@ -416,48 +331,28 @@ public:
   static float UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength);
 
   /* Computes the input length in terms of user space coordinates.
      Input: aFrame - object to be used for determining user space
             length - length to be converted
   */
   static float UserSpace(nsIFrame *aFrame, const nsSVGLength2 *aLength);
 
-  /* Returns the angle halfway between the two specified angles */
-  static float
-  AngleBisect(float a1, float a2);
-
   /* Find the outermost SVG frame of the passed frame */
   static nsSVGOuterSVGFrame *
   GetOuterSVGFrame(nsIFrame *aFrame);
 
   /**
    * Get the covered region for a frame. Return null if it's not an SVG frame.
    * @param aRect gets a rectangle in app units
    * @return the outer SVG frame which aRect is relative to
    */
   static nsIFrame*
   GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect);
 
-  /* Generate a viewbox to viewport tranformation matrix */
-
-  static gfxMatrix
-  GetViewBoxTransform(const nsSVGElement* aElement,
-                      float aViewportWidth, float aViewportHeight,
-                      float aViewboxX, float aViewboxY,
-                      float aViewboxWidth, float aViewboxHeight,
-                      const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio);
-
-  static gfxMatrix
-  GetViewBoxTransform(const nsSVGElement* aElement,
-                      float aViewportWidth, float aViewportHeight,
-                      float aViewboxX, float aViewboxY,
-                      float aViewboxWidth, float aViewboxHeight,
-                      const SVGPreserveAspectRatio &aPreserveAspectRatio);
-
   /* Paint SVG frame with SVG effects - aDirtyRect is the area being
    * redrawn, in device pixel coordinates relative to the outer svg */
   static void
   PaintFrameWithEffects(nsRenderingContext *aContext,
                         const nsIntRect *aDirtyRect,
                         nsIFrame *aFrame);
 
   /* Hit testing - check if point hits the clipPath of indicated
@@ -625,21 +520,16 @@ public:
                   const gfxRect &aBBox, nsIFrame *aFrame);
 
   /**
    * Find the first frame, starting with aStartFrame and going up its
    * parent chain, that is not an svgAFrame.
    */
   static nsIFrame* GetFirstNonAAncestorFrame(nsIFrame* aStartFrame);
 
-#ifdef DEBUG
-  static void
-  WritePPM(const char *fname, gfxImageSurface *aSurface);
-#endif
-
   static bool OuterSVGIsCallingReflowSVG(nsIFrame *aFrame);
 
   /*
    * Get any additional transforms that apply only to stroking
    * e.g. non-scaling-stroke
    */
   static gfxMatrix GetStrokeTransform(nsIFrame *aFrame);