Bug 567848 - Split content methods from nsSVGUtils into SVGContentUtils. r=dholbert

--HG--
rename : layout/svg/base/src/nsSVGUtils.cpp => content/svg/content/src/SVGContentUtils.cpp
rename : layout/svg/base/src/nsSVGUtils.h => content/svg/content/src/SVGContentUtils.h
This commit is contained in:
Robert Longson 2012-09-22 20:26:05 +01:00
parent 6a917948b4
commit 3e3a71ce0c
59 changed files with 770 additions and 742 deletions

View File

@ -9,7 +9,7 @@
#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 {

View File

@ -9,7 +9,6 @@
#include "nsSVGSwitchElement.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsStyleUtil.h"
#include "nsSVGUtils.h"
#include "mozilla/Preferences.h"
using namespace mozilla;

View File

@ -116,6 +116,7 @@ CPPSRCS = \
nsSVGMpathElement.cpp \
nsSVGSetElement.cpp \
SVGAttrValueWrapper.cpp \
SVGContentUtils.cpp \
SVGIntegerPairSMILType.cpp \
SVGLengthListSMILType.cpp \
SVGMotionSMILType.cpp \

View File

@ -8,10 +8,10 @@
#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 {

View File

@ -0,0 +1,379 @@
/* -*- 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 "SVGContentUtils.h"
// Keep others in (case-insensitive) order:
#include "gfxMatrix.h"
#include "mozilla/Preferences.h"
#include "nsComputedDOMStyle.h"
#include "nsFontMetrics.h"
#include "nsIDOMSVGElement.h"
#include "nsIFrame.h"
#include "nsIScriptError.h"
#include "nsLayoutUtils.h"
#include "nsSVGAnimationElement.h"
#include "nsSVGSVGElement.h"
#include "SVGAnimatedPreserveAspectRatio.h"
using namespace mozilla;
using namespace mozilla::dom;
nsSVGSVGElement*
SVGContentUtils::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
SVGContentUtils::ActivateByHyperlink(nsIContent *aContent)
{
NS_ABORT_IF_FALSE(aContent->IsNodeOfType(nsINode::eANIMATION),
"Expecting an animation element");
static_cast<nsSVGAnimationElement*>(aContent)->ActivateByHyperlink();
}
float
SVGContentUtils::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
SVGContentUtils::GetFontSize(nsIFrame *aFrame)
{
NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontSize");
return GetFontSize(aFrame->GetStyleContext());
}
float
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
SVGContentUtils::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
SVGContentUtils::GetFontXHeight(nsIFrame *aFrame)
{
NS_ABORT_IF_FALSE(aFrame, "NULL frame in GetFontXHeight");
return GetFontXHeight(aFrame->GetStyleContext());
}
float
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,
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();
}
nsresult
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);
}
bool
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>
SVGContentUtils::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 && 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;
}
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
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);
}
double
SVGContentUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
{
return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
}
float
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;
}
gfxMatrix
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
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();
// 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);
}

View File

@ -0,0 +1,142 @@
/* -*- 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 MOZILLA_SVGCONTENTUTILS_H
#define MOZILLA_SVGCONTENTUTILS_H
// 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 "nsCOMPtr.h"
class nsIContent;
class nsIDocument;
class nsIDOMSVGElement;
class nsIFrame;
class nsStyleContext;
class nsSVGElement;
class nsSVGLength2;
class nsSVGSVGElement;
namespace mozilla {
class SVGAnimatedPreserveAspectRatio;
class SVGPreserveAspectRatio;
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
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');
}
/**
* Functions generally used by SVG Content classes. Functions here
* should not generally depend on layout methods/classes e.g. nsSVGUtils
*/
class SVGContentUtils
{
public:
typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
typedef mozilla::SVGPreserveAspectRatio SVGPreserveAspectRatio;
/*
* 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);
/*
* Report a localized error message to the error console.
*/
static nsresult ReportToConsole(nsIDocument* doc,
const char* aWarning,
const PRUnichar **aParams,
uint32_t aParamsLength);
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);
/* 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);
/* Returns the angle halfway between the two specified angles */
static float
AngleBisect(float a1, float a2);
/* 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);
};
#endif

View File

@ -9,10 +9,10 @@
#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 {
@ -57,7 +57,7 @@ SVGLength::SetValueFromString(const nsAString &aValue)
tmpUnit = GetUnitTypeForString(
Substring(aValue, unit - str, theRest - unit));
if (tmpUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN) {
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return false;
}
while (*theRest && IsSVGWhitespace(*theRest)) {
@ -178,9 +178,9 @@ SVGLength::GetUserUnitsPerUnit(const nsSVGElement *aElement, uint8_t aAxis) cons
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();

View File

@ -4,14 +4,14 @@
* 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 {

View File

@ -124,7 +124,7 @@ SVGLengthListSMILType::Add(nsSMILValue& aDest,
// Zero-pad our |dest| list, if necessary.
if (dest.Length() < valueToAdd.Length()) {
if (!dest.CanZeroPadList()) {
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return NS_ERROR_FAILURE;
}
@ -188,7 +188,7 @@ SVGLengthListSMILType::ComputeDistance(const nsSMILValue& aFrom,
if ((from.Length() < to.Length() && !from.CanZeroPadList()) ||
(to.Length() < from.Length() && !to.CanZeroPadList())) {
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return NS_ERROR_FAILURE;
}
@ -263,7 +263,7 @@ SVGLengthListSMILType::Interpolate(const nsSMILValue& aStartVal,
if ((start.Length() < end.Length() && !start.CanZeroPadList()) ||
(end.Length() < start.Length() && !end.CanZeroPadList())) {
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return NS_ERROR_FAILURE;
}

View File

@ -4,12 +4,11 @@
* 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 {
@ -113,8 +112,8 @@ SVGMotionSMILPathUtils::PathGenerator::
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);

View File

@ -6,16 +6,16 @@
#include "mozilla/Util.h"
#include "SVGNumberList.h"
#include "SVGAnimatedNumberList.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 "nsError.h"
#include "nsMathUtils.h"
#include "nsString.h"
#include "nsSVGElement.h"
#include "nsTextFormatter.h"
#include "prdtoa.h"
#include "string.h"
#include "SVGAnimatedNumberList.h"
#include "SVGContentUtils.h"
namespace mozilla {

View File

@ -116,7 +116,7 @@ SVGNumberListSMILType::Add(nsSMILValue& aDest,
"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) {
@ -141,7 +141,7 @@ SVGNumberListSMILType::ComputeDistance(const nsSMILValue& aFrom,
if (from.Length() != to.Length()) {
// Lists in the 'values' attribute must have the same length.
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return NS_ERROR_FAILURE;
}
@ -189,7 +189,7 @@ SVGNumberListSMILType::Interpolate(const nsSMILValue& aStartVal,
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())) {

View File

@ -4,16 +4,16 @@
* 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;
@ -813,7 +813,7 @@ SVGPathData::GetMarkerPositioningData(nsTArray<nsSVGMark> *aMarks) const
} else {
if (!(segType == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH &&
prevSegType == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH))
mark.angle = nsSVGUtils::AngleBisect(prevSegEndAngle, segStartAngle);
mark.angle = SVGContentUtils::AngleBisect(prevSegEndAngle, segStartAngle);
}
}
@ -828,7 +828,7 @@ SVGPathData::GetMarkerPositioningData(nsTArray<nsSVGMark> *aMarks) const
prevSegType != nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH) {
aMarks->ElementAt(aMarks->Length() - 1).angle =
//aMarks->ElementAt(pathStartIndex).angle =
nsSVGUtils::AngleBisect(segEndAngle, pathStartAngle);
SVGContentUtils::AngleBisect(segEndAngle, pathStartAngle);
}
prevSegType = segType;

View File

@ -418,7 +418,7 @@ SVGPathSegListSMILType::Add(nsSMILValue& aDest,
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;
@ -446,7 +446,7 @@ SVGPathSegListSMILType::ComputeDistance(const nsSMILValue& aFrom,
// See https://bugzilla.mozilla.org/show_bug.cgi?id=522306#c18
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -474,7 +474,7 @@ SVGPathSegListSMILType::Interpolate(const nsSMILValue& aStartVal,
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;

View File

@ -6,16 +6,16 @@
#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 {

View File

@ -99,7 +99,7 @@ SVGPointListSMILType::Add(nsSMILValue& aDest,
"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) {
@ -124,7 +124,7 @@ SVGPointListSMILType::ComputeDistance(const nsSMILValue& aFrom,
if (from.Length() != to.Length()) {
// Lists in the 'values' attribute must have the same length.
// nsSVGUtils::ReportToConsole
// SVGContentUtils::ReportToConsole
return NS_ERROR_FAILURE;
}
@ -173,7 +173,7 @@ SVGPointListSMILType::Interpolate(const nsSMILValue& aStartVal,
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())) {

View File

@ -6,14 +6,14 @@
#include "mozilla/Util.h"
#include "SVGStringList.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 "nsString.h"
#include "nsSVGElement.h"
#include "nsTextFormatter.h"
#include "nsWhitespaceTokenizer.h"
#include "SVGContentUtils.h"
namespace mozilla {

View File

@ -10,7 +10,7 @@
#include "nsTextFormatter.h"
namespace {
const double radPerDegree = 2.0*3.1415926535 / 360.0;
const double radPerDegree = 2.0 * M_PI / 360.0;
}
namespace mozilla {

View File

@ -8,7 +8,6 @@
#include "nsSVGAngle.h"
#include "prdtoa.h"
#include "nsTextFormatter.h"
#include "nsSVGUtils.h"
#include "nsSVGMarkerElement.h"
#include "nsMathUtils.h"
#include "nsContentUtils.h" // NS_ENSURE_FINITE

View File

@ -423,7 +423,7 @@ nsSVGAnimationElement::ActivateByHyperlink()
nsSMILTimeContainer*
nsSVGAnimationElement::GetTimeContainer()
{
nsSVGSVGElement *element = nsSVGUtils::GetOuterSVGElement(this);
nsSVGSVGElement *element = SVGContentUtils::GetOuterSVGElement(this);
if (element) {
return element->GetTimedDocumentRoot();

View File

@ -9,7 +9,6 @@
#include "nsIDOMSVGCircleElement.h"
#include "nsSVGLength2.h"
#include "nsGkAtoms.h"
#include "nsSVGUtils.h"
#include "gfxContext.h"
using namespace mozilla;
@ -56,9 +55,9 @@ protected:
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)

View File

@ -18,7 +18,6 @@
#include "nsSVGDataParser.h"
#include "prdtoa.h"
#include "nsSVGUtils.h"
#include "nsMathUtils.h"
#include "nsMemory.h"
#include "nsReadableUtils.h"

View File

@ -31,7 +31,6 @@
#include "nsNodeInfoManager.h"
#include "nsIScriptGlobalObject.h"
#include "nsEventListenerManager.h"
#include "nsSVGUtils.h"
#include "nsSVGLength2.h"
#include "nsSVGNumber2.h"
#include "nsSVGNumberPair.h"
@ -47,6 +46,7 @@
#include "SVGAnimatedPointList.h"
#include "SVGAnimatedPathSegList.h"
#include "SVGAnimatedTransformList.h"
#include "SVGContentUtils.h"
#include "DOMSVGTests.h"
#include "nsIDOMSVGUnitTypes.h"
#include "nsSVGRect.h"
@ -1058,7 +1058,7 @@ nsSVGElement::GetOwnerSVGElement(nsIDOMSVGSVGElement * *aOwnerSVGElement)
NS_IMETHODIMP
nsSVGElement::GetViewportElement(nsIDOMSVGElement * *aViewportElement)
{
*aViewportElement = nsSVGUtils::GetNearestViewportElement(this).get();
*aViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
return NS_OK;
}
@ -2419,9 +2419,9 @@ nsSVGElement::ReportAttributeParseFailure(nsIDocument* aDocument,
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

View File

@ -9,7 +9,6 @@
#include "nsIDOMSVGEllipseElement.h"
#include "nsSVGLength2.h"
#include "nsGkAtoms.h"
#include "nsSVGUtils.h"
#include "gfxContext.h"
using namespace mozilla;
@ -56,10 +55,10 @@ protected:
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)

View File

@ -14,10 +14,10 @@ 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] =

View File

@ -35,6 +35,7 @@
#include "nsSVGString.h"
#include "nsSVGEffects.h"
#include "gfxUtils.h"
#include "SVGContentUtils.h"
#if defined(XP_WIN)
// Prevent Windows redefining LoadImage
@ -83,10 +84,10 @@ CopyAndScaleDeviceOffset(const gfxImageSurface *aImage, gfxImageSurface *aResult
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 }
};
//----------------------------------------------------------------------
@ -123,10 +124,10 @@ nsSVGFE::SetupScalingFilter(nsSVGFilterInstance *aInstance,
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)
@ -590,10 +591,10 @@ 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)
@ -2616,9 +2617,9 @@ 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
@ -3791,11 +3792,11 @@ nsSVGFEMorphologyElement::GetRXY(int32_t *aRX, int32_t *aRY,
// 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);
@ -3811,7 +3812,7 @@ nsSVGFEMorphologyElement::Filter(nsSVGFilterInstance *instance,
GetRXY(&rx, &ry, *instance);
if (rx < 0 || ry < 0) {
// XXX nsSVGUtils::ReportToConsole()
// XXX SVGContentUtils::ReportToConsole()
return NS_OK;
}
if (rx == 0 && ry == 0) {
@ -5701,10 +5702,10 @@ nsSVGFEImageElement::Filter(nsSVGFilterInstance *instance,
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()));
@ -5985,7 +5986,7 @@ nsSVGFEDisplacementMapElement::Filter(nsSVGFilterInstance *instance,
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);

View File

@ -12,10 +12,10 @@ 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)

View File

@ -133,10 +133,10 @@ nsSVGGradientElement::IsAttributeMapped(const nsIAtom* name) const
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)
@ -222,11 +222,11 @@ nsSVGLinearGradientElement::GetLengthInfo()
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)

View File

@ -47,14 +47,14 @@ nsSVGGraphicElement::nsSVGGraphicElement(already_AddRefed<nsINodeInfo> aNodeInfo
/* 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;
}
@ -78,7 +78,7 @@ NS_IMETHODIMP nsSVGGraphicElement::GetBBox(nsIDOMSVGRect **_retval)
/* 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;
@ -87,7 +87,7 @@ NS_IMETHODIMP nsSVGGraphicElement::GetCTM(nsIDOMSVGMatrix * *aCTM)
/* 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;

View File

@ -17,10 +17,10 @@ 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] =

View File

@ -4,11 +4,11 @@
* 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;

View File

@ -183,10 +183,14 @@ nsSVGLength2::GetAxisLength(nsIFrame *aNonSVGFrame) const
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");

View File

@ -15,7 +15,7 @@
#include "nsISMILAttr.h"
#include "nsMathUtils.h"
#include "nsSVGElement.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
class nsIFrame;
class nsISMILAnimationElement;
@ -26,7 +26,7 @@ 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) {
@ -101,17 +101,17 @@ private:
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;

View File

@ -57,10 +57,10 @@ protected:
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)

View File

@ -9,19 +9,19 @@
#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[] = {
@ -363,11 +363,11 @@ nsSVGMarkerElement::GetViewBoxTransform()
"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);

View File

@ -15,10 +15,10 @@ using namespace mozilla;
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] =

View File

@ -5,7 +5,6 @@
#include "nsError.h"
#include "nsSVGNumber2.h"
#include "nsSVGUtils.h"
#include "nsTextFormatter.h"
#include "prdtoa.h"
#include "nsMathUtils.h"

View File

@ -4,12 +4,12 @@
* 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;

View File

@ -7,7 +7,6 @@
#include "nsSVGDataParser.h"
#include "nsSVGPathElement.h"
#include "prdtoa.h"
#include "nsSVGUtils.h"
#include "nsIDOMSVGPathSeg.h"
#include <stdlib.h>
#include <math.h>

View File

@ -12,7 +12,6 @@
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsSVGPathElement.h"
#include "nsSVGUtils.h"
#include "DOMSVGPoint.h"
#include "gfxContext.h"

View File

@ -17,10 +17,10 @@ using namespace mozilla;
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] =

View File

@ -8,7 +8,7 @@
#include "nsSVGPolyElement.h"
#include "DOMSVGPointList.h"
#include "gfxContext.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
using namespace mozilla;
@ -96,7 +96,7 @@ nsSVGPolyElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
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));

View File

@ -6,7 +6,7 @@
#include "nsSVGPolyElement.h"
#include "nsIDOMSVGPolygonElement.h"
#include "gfxContext.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
typedef nsSVGPolyElement nsSVGPolygonElementBase;
@ -83,8 +83,8 @@ nsSVGPolygonElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
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

View File

@ -55,12 +55,12 @@ protected:
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)

View File

@ -25,10 +25,11 @@
#include "nsError.h"
#include "nsISVGChildFrame.h"
#include "nsGUIEvent.h"
#include "nsSVGUtils.h"
#include "nsSVGSVGElement.h"
#include "nsSVGUtils.h"
#include "nsSVGViewElement.h"
#include "nsStyleUtil.h"
#include "SVGContentUtils.h"
#include "nsEventDispatcher.h"
#include "nsSMILTimeContainer.h"
@ -101,10 +102,10 @@ nsSVGTranslatePoint::DOMVal::MatrixTransform(nsIDOMSVGMatrix *matrix,
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[] = {
@ -636,7 +637,7 @@ nsSVGSVGElement::GetPreserveAspectRatio(nsIDOMSVGAnimatedPreserveAspectRatio
NS_IMETHODIMP
nsSVGSVGElement::GetNearestViewportElement(nsIDOMSVGElement * *aNearestViewportElement)
{
*aNearestViewportElement = nsSVGUtils::GetNearestViewportElement(this).get();
*aNearestViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
return NS_OK;
}
@ -644,7 +645,7 @@ nsSVGSVGElement::GetNearestViewportElement(nsIDOMSVGElement * *aNearestViewportE
NS_IMETHODIMP
nsSVGSVGElement::GetFarthestViewportElement(nsIDOMSVGElement * *aFarthestViewportElement)
{
NS_IF_ADDREF(*aFarthestViewportElement = nsSVGUtils::GetOuterSVGElement(this));
NS_IF_ADDREF(*aFarthestViewportElement = SVGContentUtils::GetOuterSVGElement(this));
return NS_OK;
}
@ -670,7 +671,7 @@ nsSVGSVGElement::GetBBox(nsIDOMSVGRect **_retval)
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;
@ -680,7 +681,7 @@ nsSVGSVGElement::GetCTM(nsIDOMSVGMatrix * *aCTM)
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;
@ -806,7 +807,7 @@ nsSVGSVGElement::GetTimedDocumentRoot()
// 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();
@ -933,11 +934,11 @@ nsSVGSVGElement::GetViewBoxTransform() const
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
@ -1190,12 +1191,12 @@ nsSVGSVGElement::GetLength(uint8_t aCtxType)
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;
}

View File

@ -8,7 +8,6 @@
#include "nsSVGStylableElement.h"
#include "nsIDOMSVGStopElement.h"
#include "nsSVGNumber2.h"
#include "nsSVGUtils.h"
#include "nsGenericHTMLElement.h"
using namespace mozilla;

View File

@ -138,7 +138,7 @@ NS_IMETHODIMP
nsSVGTextElement::GetX(nsIDOMSVGAnimatedLengthList * *aX)
{
*aX = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[X],
this, X, nsSVGUtils::X).get();
this, X, SVGContentUtils::X).get();
return NS_OK;
}
@ -147,7 +147,7 @@ NS_IMETHODIMP
nsSVGTextElement::GetY(nsIDOMSVGAnimatedLengthList * *aY)
{
*aY = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[Y],
this, Y, nsSVGUtils::Y).get();
this, Y, SVGContentUtils::Y).get();
return NS_OK;
}
@ -156,7 +156,7 @@ NS_IMETHODIMP
nsSVGTextElement::GetDx(nsIDOMSVGAnimatedLengthList * *aDx)
{
*aDx = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DX],
this, DX, nsSVGUtils::X).get();
this, DX, SVGContentUtils::X).get();
return NS_OK;
}
@ -165,7 +165,7 @@ NS_IMETHODIMP
nsSVGTextElement::GetDy(nsIDOMSVGAnimatedLengthList * *aDy)
{
*aDy = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DY],
this, DY, nsSVGUtils::Y).get();
this, DY, SVGContentUtils::Y).get();
return NS_OK;
}
@ -339,10 +339,10 @@ nsSVGTextElement::IsAttributeMapped(const nsIAtom* name) const
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

View File

@ -18,7 +18,7 @@ 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[] = {

View File

@ -6,21 +6,21 @@
#include "mozilla/Util.h"
#include "nsSVGTextPositioningElement.h"
#include "nsSVGUtils.h"
#include "SVGAnimatedLengthList.h"
#include "DOMSVGAnimatedLengthList.h"
#include "SVGLengthList.h"
#include "DOMSVGAnimatedNumberList.h"
#include "SVGContentUtils.h"
#include "SVGLengthList.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
@ -50,7 +50,7 @@ nsSVGTextPositioningElement::GetNumberListInfo()
NS_IMETHODIMP nsSVGTextPositioningElement::GetX(nsIDOMSVGAnimatedLengthList * *aX)
{
*aX = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[X],
this, X, nsSVGUtils::X).get();
this, X, SVGContentUtils::X).get();
return NS_OK;
}
@ -58,7 +58,7 @@ NS_IMETHODIMP nsSVGTextPositioningElement::GetX(nsIDOMSVGAnimatedLengthList * *a
NS_IMETHODIMP nsSVGTextPositioningElement::GetY(nsIDOMSVGAnimatedLengthList * *aY)
{
*aY = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[Y],
this, Y, nsSVGUtils::Y).get();
this, Y, SVGContentUtils::Y).get();
return NS_OK;
}
@ -66,7 +66,7 @@ NS_IMETHODIMP nsSVGTextPositioningElement::GetY(nsIDOMSVGAnimatedLengthList * *a
NS_IMETHODIMP nsSVGTextPositioningElement::GetDx(nsIDOMSVGAnimatedLengthList * *aDx)
{
*aDx = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DX],
this, DX, nsSVGUtils::X).get();
this, DX, SVGContentUtils::X).get();
return NS_OK;
}
@ -74,7 +74,7 @@ NS_IMETHODIMP nsSVGTextPositioningElement::GetDx(nsIDOMSVGAnimatedLengthList * *
NS_IMETHODIMP nsSVGTextPositioningElement::GetDy(nsIDOMSVGAnimatedLengthList * *aDy)
{
*aDy = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DY],
this, DY, nsSVGUtils::Y).get();
this, DY, SVGContentUtils::Y).get();
return NS_OK;
}

View File

@ -23,10 +23,10 @@ using namespace mozilla::dom;
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] =
@ -414,7 +414,7 @@ nsSVGUseElement::SyncWidthOrHeight(nsIAtom* aName)
// 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;

View File

@ -4,12 +4,12 @@
* 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

View File

@ -118,7 +118,7 @@
#include "nsHTMLMediaElement.h"
#endif
#include "nsSMILAnimationController.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
#include "SVGFragmentIdentifier.h"
#include "nsRefreshDriver.h"
@ -2882,7 +2882,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll)
// 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;

View File

@ -75,7 +75,6 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../../../xul/base/src \
-I$(srcdir)/../../../../content/svg/content/src \
-I$(srcdir)/../../../../content/base/src \
-I$(srcdir)/../../../../content/smil \
$(NULL)
libs::

View File

@ -15,6 +15,7 @@
#include "nsSVGFilterElement.h"
#include "nsSVGFilterPaintCallback.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
float
nsSVGFilterInstance::GetPrimitiveNumber(uint8_t aCtxType, float aValue) const
@ -31,13 +32,13 @@ nsSVGFilterInstance::GetPrimitiveNumber(uint8_t aCtxType, float aValue) const
}
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());
}
@ -47,21 +48,21 @@ 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>

View File

@ -24,6 +24,7 @@
#include "nsSVGTextPathFrame.h"
#include "nsSVGUtils.h"
#include "nsTextFragment.h"
#include "SVGContentUtils.h"
#include "SVGLengthList.h"
using namespace mozilla;
@ -1816,7 +1817,7 @@ nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale,
// 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) {

View File

@ -17,6 +17,7 @@
#include "nsSVGPathGeometryFrame.h"
#include "nsSVGSVGElement.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
using namespace mozilla;
@ -231,10 +232,10 @@ nsSVGImageFrame::GetRasterImageTransform(int32_t aNativeWidth,
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);
}

View File

@ -21,6 +21,7 @@
#include "nsSVGPatternElement.h"
#include "nsSVGUtils.h"
#include "SVGAnimatedTransformList.h"
#include "SVGContentUtils.h"
using namespace mozilla;
@ -661,7 +662,7 @@ nsSVGPatternFrame::ConstructCTM(const nsSVGViewBox& aViewBox,
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,

View File

@ -17,25 +17,20 @@
#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"
@ -56,7 +51,7 @@
#include "nsSVGSVGElement.h"
#include "nsSVGTextContainerFrame.h"
#include "nsTextFrame.h"
#include "SVGAnimatedPreserveAspectRatio.h"
#include "SVGContentUtils.h"
#include "mozilla/unused.h"
using namespace mozilla;
@ -233,119 +228,6 @@ nsSVGUtils::Init()
"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,
@ -433,19 +315,6 @@ nsSVGUtils::ConvertImageDataFromLinearRGB(uint8_t *data,
}
}
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,
@ -461,120 +330,13 @@ nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
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)
{
@ -611,7 +373,7 @@ nsSVGUtils::GetPostFilterVisualOverflowRect(nsIFrame *aFrame,
bool
nsSVGUtils::OuterSVGIsCallingReflowSVG(nsIFrame *aFrame)
{
return nsSVGUtils::GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
return GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
}
void
@ -835,26 +597,21 @@ nsSVGUtils::NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame)
}
}
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");
@ -880,22 +637,6 @@ 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)
{
@ -920,107 +661,6 @@ nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect)
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)
{
@ -1186,7 +826,7 @@ nsSVGUtils::PaintFrameWithEffects(nsRenderingContext *aContext,
tm = childrenOnlyTM.Invert() * tm;
}
}
nsIntRect bounds = nsSVGUtils::TransformFrameRectToOuterSVG(overflowRect,
nsIntRect bounds = TransformFrameRectToOuterSVG(overflowRect,
tm, aFrame->PresContext()).
ToOutsidePixels(appUnitsPerDevPx);
if (!aDirtyRect->Intersects(bounds)) {
@ -1722,29 +1362,6 @@ nsSVGUtils::GetFirstNonAAncestorFrame(nsIFrame* aStartFrame)
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)
{
@ -1762,7 +1379,7 @@ nsSVGUtils::GetStrokeTransform(nsIFrame *aFrame)
// 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();
@ -2044,8 +1661,8 @@ nsSVGUtils::GetStrokeWidth(nsIFrame* aFrame, gfxTextObjectPaint *aObjectPaint)
nsSVGElement *ctx = static_cast<nsSVGElement*>(content);
return nsSVGUtils::CoordToFloat(aFrame->PresContext(), ctx,
style->mStrokeWidth);
return CoordToFloat(aFrame->PresContext(), ctx,
style->mStrokeWidth);
}
void

View File

@ -6,7 +6,7 @@
#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>
@ -32,7 +32,6 @@ class gfxPattern;
class nsFrameList;
class nsIContent;
class nsIDocument;
class nsIDOMSVGElement;
class nsIFrame;
class nsPresContext;
class nsRenderingContext;
@ -45,7 +44,6 @@ class nsSVGGeometryFrame;
class nsSVGLength2;
class nsSVGOuterSVGFrame;
class nsSVGPathGeometryFrame;
class nsSVGSVGElement;
class nsTextFrame;
class gfxTextObjectPaint;
@ -90,30 +88,12 @@ class Element;
// 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();
@ -215,55 +195,17 @@ public:
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
*/
@ -289,14 +231,6 @@ public:
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
@ -306,17 +240,6 @@ public:
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,
@ -395,14 +318,6 @@ public:
*/
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
@ -421,10 +336,6 @@ public:
*/
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);
@ -437,22 +348,6 @@ public:
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
@ -630,11 +525,6 @@ public:
*/
static nsIFrame* GetFirstNonAAncestorFrame(nsIFrame* aStartFrame);
#ifdef DEBUG
static void
WritePPM(const char *fname, gfxImageSurface *aSurface);
#endif
static bool OuterSVGIsCallingReflowSVG(nsIFrame *aFrame);
/*