2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGLength2.h"
|
|
|
|
#include "prdtoa.h"
|
|
|
|
#include "nsTextFormatter.h"
|
2013-01-09 15:02:45 -08:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2009-08-26 21:30:51 -07:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h" // NS_ENSURE_FINITE
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "nsSMILFloatType.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2013-01-19 12:56:00 -08:00
|
|
|
#include "mozilla/dom/SVGAnimatedLength.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
2013-01-09 15:02:45 -08:00
|
|
|
using namespace mozilla::dom;
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2008-12-30 08:32:22 -08:00
|
|
|
NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGLength2::DOMBaseVal, mSVGElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-30 08:32:22 -08:00
|
|
|
NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGLength2::DOMAnimVal, mSVGElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-30 08:32:22 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGLength2::DOMBaseVal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGLength2::DOMBaseVal)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGLength2::DOMAnimVal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGLength2::DOMAnimVal)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGLength2::DOMBaseVal)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLength)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2008-12-30 08:32:22 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGLength2::DOMAnimVal)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLength)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2007-10-03 02:02:19 -07:00
|
|
|
static nsIAtom** const unitMap[] =
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
|
|
|
|
nullptr, /* SVG_LENGTHTYPE_NUMBER */
|
2007-10-03 02:02:19 -07:00
|
|
|
&nsGkAtoms::percentage,
|
|
|
|
&nsGkAtoms::em,
|
|
|
|
&nsGkAtoms::ex,
|
|
|
|
&nsGkAtoms::px,
|
|
|
|
&nsGkAtoms::cm,
|
|
|
|
&nsGkAtoms::mm,
|
|
|
|
&nsGkAtoms::in,
|
|
|
|
&nsGkAtoms::pt,
|
|
|
|
&nsGkAtoms::pc
|
|
|
|
};
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGLength2, SVGAnimatedLength>
|
2009-08-26 21:30:51 -07:00
|
|
|
sSVGAnimatedLengthTearoffTable;
|
2012-08-22 23:24:43 -07:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGLength2, nsSVGLength2::DOMBaseVal>
|
2009-08-26 21:30:51 -07:00
|
|
|
sBaseSVGLengthTearoffTable;
|
2012-08-22 23:24:43 -07:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGLength2, nsSVGLength2::DOMAnimVal>
|
2009-08-26 21:30:51 -07:00
|
|
|
sAnimSVGLengthTearoffTable;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Helper functions */
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-22 08:56:38 -07:00
|
|
|
IsValidUnitType(uint16_t unit)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (unit > nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN &&
|
|
|
|
unit <= nsIDOMSVGLength::SVG_LENGTHTYPE_PC)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
GetUnitString(nsAString& unit, uint16_t unitType)
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
|
|
|
if (IsValidUnitType(unitType)) {
|
|
|
|
if (unitMap[unitType]) {
|
|
|
|
(*unitMap[unitType])->ToString(unit);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint16_t
|
2012-08-24 00:29:09 -07:00
|
|
|
GetUnitTypeForString(const nsAString& unitStr)
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
2012-08-24 00:29:09 -07:00
|
|
|
if (unitStr.IsEmpty())
|
2007-10-03 02:02:19 -07:00
|
|
|
return nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
|
|
|
|
|
2012-08-24 00:29:09 -07:00
|
|
|
nsIAtom *unitAtom = NS_GetStaticAtom(unitStr);
|
|
|
|
if (unitAtom) {
|
|
|
|
for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
|
|
|
|
if (unitMap[i] && *unitMap[i] == unitAtom) {
|
|
|
|
return i;
|
|
|
|
}
|
2007-10-03 02:02:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-03 02:02:19 -07:00
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRUnichar buf[24];
|
|
|
|
nsTextFormatter::snprintf(buf, sizeof(buf)/sizeof(PRUnichar),
|
|
|
|
NS_LITERAL_STRING("%g").get(),
|
|
|
|
(double)aValue);
|
|
|
|
aValueAsString.Assign(buf);
|
|
|
|
|
|
|
|
nsAutoString unitString;
|
2007-10-03 02:02:19 -07:00
|
|
|
GetUnitString(unitString, aUnitType);
|
2007-03-22 10:30:00 -07:00
|
|
|
aValueAsString.Append(unitString);
|
|
|
|
}
|
|
|
|
|
2007-10-03 02:02:19 -07:00
|
|
|
static nsresult
|
|
|
|
GetValueFromString(const nsAString &aValueAsString,
|
|
|
|
float *aValue,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t *aUnitType)
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
2007-10-19 01:54:21 -07:00
|
|
|
NS_ConvertUTF16toUTF8 value(aValueAsString);
|
|
|
|
const char *str = value.get();
|
2007-10-03 02:02:19 -07:00
|
|
|
|
2007-10-19 01:54:21 -07:00
|
|
|
if (NS_IsAsciiWhitespace(*str))
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2007-10-03 02:02:19 -07:00
|
|
|
|
2007-10-19 01:54:21 -07:00
|
|
|
char *rest;
|
|
|
|
*aValue = float(PR_strtod(str, &rest));
|
2011-08-01 10:43:23 -07:00
|
|
|
if (rest != str && NS_finite(*aValue)) {
|
2012-08-24 00:29:09 -07:00
|
|
|
*aUnitType = GetUnitTypeForString(
|
|
|
|
Substring(aValueAsString, rest - str));
|
2007-10-19 01:54:21 -07:00
|
|
|
if (IsValidUnitType(*aUnitType)) {
|
|
|
|
return NS_OK;
|
2007-10-03 02:02:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2007-10-03 02:02:19 -07:00
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
static float
|
|
|
|
FixAxisLength(float aLength)
|
|
|
|
{
|
|
|
|
if (aLength == 0.0f) {
|
|
|
|
NS_WARNING("zero axis length");
|
|
|
|
return 1e-20f;
|
|
|
|
}
|
|
|
|
return aLength;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
float
|
2013-01-09 15:02:45 -08:00
|
|
|
nsSVGLength2::GetAxisLength(SVGSVGElement *aCtx) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aCtx)
|
|
|
|
return 1;
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
return FixAxisLength(aCtx->GetLength(mCtxType));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
float
|
|
|
|
nsSVGLength2::GetAxisLength(nsIFrame *aNonSVGFrame) const
|
|
|
|
{
|
2012-06-19 08:28:04 -07:00
|
|
|
gfxSize size =
|
|
|
|
nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(aNonSVGFrame);
|
2008-09-10 17:24:16 -07:00
|
|
|
float length;
|
|
|
|
switch (mCtxType) {
|
2012-09-22 12:26:05 -07:00
|
|
|
case SVGContentUtils::X:
|
|
|
|
length = size.width;
|
|
|
|
break;
|
|
|
|
case SVGContentUtils::Y:
|
|
|
|
length = size.height;
|
|
|
|
break;
|
|
|
|
case SVGContentUtils::XY:
|
|
|
|
length = SVGContentUtils::ComputeNormalizedHypotenuse(size.width, size.height);
|
2008-09-10 17:24:16 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown axis type");
|
|
|
|
length = 1;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
return FixAxisLength(length);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2009-01-21 17:00:27 -08:00
|
|
|
nsSVGLength2::GetUnitScaleFactor(nsSVGElement *aSVGElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aUnitType) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-21 17:00:27 -08:00
|
|
|
switch (aUnitType) {
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER:
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PX:
|
|
|
|
return 1;
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
|
|
|
|
return 1 / GetEmLength(aSVGElement);
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
|
|
|
|
return 1 / GetExLength(aSVGElement);
|
2007-06-25 09:12:35 -07:00
|
|
|
}
|
2007-10-03 02:02:19 -07:00
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
return GetUnitScaleFactor(aSVGElement->GetCtx(), aUnitType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2013-01-09 15:02:45 -08:00
|
|
|
nsSVGLength2::GetUnitScaleFactor(SVGSVGElement *aCtx, uint8_t aUnitType) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-21 17:00:27 -08:00
|
|
|
switch (aUnitType) {
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER:
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PX:
|
|
|
|
return 1;
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_MM:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel();
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() / 10.0f;
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() / MM_PER_INCH_FLOAT;
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT;
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT / 12.0f;
|
2007-10-03 02:02:19 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
|
|
|
|
return 100.0f / GetAxisLength(aCtx);
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
|
|
|
|
return 1 / GetEmLength(aCtx);
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
|
|
|
|
return 1 / GetExLength(aCtx);
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
float
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGLength2::GetUnitScaleFactor(nsIFrame *aFrame, uint8_t aUnitType) const
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2009-08-24 13:02:07 -07:00
|
|
|
if (content->IsSVG())
|
2009-01-21 17:00:27 -08:00
|
|
|
return GetUnitScaleFactor(static_cast<nsSVGElement*>(content), aUnitType);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
switch (aUnitType) {
|
2008-09-10 17:24:16 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER:
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PX:
|
|
|
|
return 1;
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_MM:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel();
|
2008-09-10 17:24:16 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() / 10.0f;
|
2008-09-10 17:24:16 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() / MM_PER_INCH_FLOAT;
|
2008-09-10 17:24:16 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT;
|
2008-09-10 17:24:16 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
|
2010-08-13 02:58:04 -07:00
|
|
|
return GetMMPerPixel() * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT / 12.0f;
|
2008-09-10 17:24:16 -07:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
|
|
|
|
return 100.0f / GetAxisLength(aFrame);
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
|
|
|
|
return 1 / GetEmLength(aFrame);
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
|
|
|
|
return 1 / GetExLength(aFrame);
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsSVGLength2::SetBaseValueInSpecifiedUnits(float aValue,
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-15 15:40:45 -08:00
|
|
|
if (mIsBaseSet && mBaseVal == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
|
|
|
}
|
2010-02-11 11:41:48 -08:00
|
|
|
mBaseVal = aValue;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsBaseSet = true;
|
2010-02-11 11:41:48 -08:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 17:00:27 -08:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-20 11:58:58 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGLength2::ConvertToSpecifiedUnits(uint16_t unitType,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
if (!IsValidUnitType(unitType))
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
if (mIsBaseSet && mSpecifiedUnitType == uint8_t(unitType))
|
2012-02-15 15:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Even though we're not changing the visual effect this length will have
|
|
|
|
// on the document, we still need to send out notifications in case we have
|
|
|
|
// mutation listeners, since the actual string value of the attribute will
|
|
|
|
// change.
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
|
|
|
|
|
|
|
float valueInUserUnits =
|
2009-01-21 17:00:27 -08:00
|
|
|
mBaseVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType);
|
2012-08-22 08:56:38 -07:00
|
|
|
mSpecifiedUnitType = uint8_t(unitType);
|
2012-02-15 15:40:45 -08:00
|
|
|
// Setting aDoSetAttr to false here will ensure we don't call
|
|
|
|
// Will/DidChangeAngle a second time (and dispatch duplicate notifications).
|
|
|
|
SetBaseValue(valueInUserUnits, aSVGElement, false);
|
|
|
|
|
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
2010-01-20 11:58:58 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-20 11:58:58 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGLength2::NewValueSpecifiedUnits(uint16_t unitType,
|
2007-03-22 10:30:00 -07:00
|
|
|
float valueInSpecifiedUnits,
|
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
{
|
2010-01-20 11:58:58 -08:00
|
|
|
NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!IsValidUnitType(unitType))
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
if (mIsBaseSet && mBaseVal == valueInSpecifiedUnits &&
|
2012-08-22 08:56:38 -07:00
|
|
|
mSpecifiedUnitType == uint8_t(unitType)) {
|
2012-02-15 15:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
2010-02-11 11:41:48 -08:00
|
|
|
mBaseVal = valueInSpecifiedUnits;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsBaseSet = true;
|
2012-08-22 08:56:38 -07:00
|
|
|
mSpecifiedUnitType = uint8_t(unitType);
|
2010-02-11 11:41:48 -08:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 17:00:27 -08:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGLength2::ToDOMBaseVal(nsIDOMSVGLength **aResult, nsSVGElement *aSVGElement)
|
|
|
|
{
|
2012-08-22 23:24:43 -07:00
|
|
|
nsRefPtr<DOMBaseVal> domBaseVal =
|
|
|
|
sBaseSVGLengthTearoffTable.GetTearoff(this);
|
|
|
|
if (!domBaseVal) {
|
|
|
|
domBaseVal = new DOMBaseVal(this, aSVGElement);
|
|
|
|
sBaseSVGLengthTearoffTable.AddTearoff(this, domBaseVal);
|
2009-08-26 21:30:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 23:24:43 -07:00
|
|
|
domBaseVal.forget(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-26 21:30:51 -07:00
|
|
|
nsSVGLength2::DOMBaseVal::~DOMBaseVal()
|
|
|
|
{
|
|
|
|
sBaseSVGLengthTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsSVGLength2::ToDOMAnimVal(nsIDOMSVGLength **aResult, nsSVGElement *aSVGElement)
|
|
|
|
{
|
2012-08-22 23:24:43 -07:00
|
|
|
nsRefPtr<DOMAnimVal> domAnimVal =
|
|
|
|
sAnimSVGLengthTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimVal) {
|
|
|
|
domAnimVal = new DOMAnimVal(this, aSVGElement);
|
|
|
|
sAnimSVGLengthTearoffTable.AddTearoff(this, domAnimVal);
|
2009-08-26 21:30:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 23:24:43 -07:00
|
|
|
domAnimVal.forget(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-26 21:30:51 -07:00
|
|
|
nsSVGLength2::DOMAnimVal::~DOMAnimVal()
|
|
|
|
{
|
|
|
|
sAnimSVGLengthTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2007-10-03 02:02:19 -07:00
|
|
|
/* Implementation */
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGLength2::SetBaseValueString(const nsAString &aValueAsString,
|
|
|
|
nsSVGElement *aSVGElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoSetAttr)
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
|
|
|
float value;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t unitType;
|
2012-02-15 15:40:45 -08:00
|
|
|
|
2007-10-03 02:02:19 -07:00
|
|
|
nsresult rv = GetValueFromString(aValueAsString, &value, &unitType);
|
2007-10-15 05:06:42 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
|
|
|
|
if (mIsBaseSet && mBaseVal == value &&
|
2012-08-22 08:56:38 -07:00
|
|
|
mSpecifiedUnitType == uint8_t(unitType)) {
|
2012-02-15 15:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
|
|
|
}
|
2010-02-11 11:41:48 -08:00
|
|
|
mBaseVal = value;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsBaseSet = true;
|
2012-08-22 08:56:38 -07:00
|
|
|
mSpecifiedUnitType = uint8_t(unitType);
|
2010-02-11 11:41:48 -08:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 17:00:27 -08:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
|
|
|
}
|
2007-10-03 02:02:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGLength2::GetBaseValueString(nsAString & aValueAsString) const
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
|
|
|
GetValueString(aValueAsString, mBaseVal, mSpecifiedUnitType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGLength2::GetAnimValueString(nsAString & aValueAsString) const
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
|
|
|
GetValueString(aValueAsString, mAnimVal, mSpecifiedUnitType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGLength2::SetBaseValue(float aValue, nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr)
|
2007-10-03 02:02:19 -07:00
|
|
|
{
|
2011-03-31 12:29:44 -07:00
|
|
|
SetBaseValueInSpecifiedUnits(aValue * GetUnitScaleFactor(aSVGElement,
|
|
|
|
mSpecifiedUnitType),
|
2012-02-15 15:40:45 -08:00
|
|
|
aSVGElement, aDoSetAttr);
|
2007-10-03 02:02:19 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
void
|
2011-03-31 12:29:44 -07:00
|
|
|
nsSVGLength2::SetAnimValueInSpecifiedUnits(float aValue,
|
|
|
|
nsSVGElement* aSVGElement)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2012-06-01 16:52:15 -07:00
|
|
|
if (mAnimVal == aValue && mIsAnimated) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-31 12:29:44 -07:00
|
|
|
mAnimVal = aValue;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAnimated = true;
|
2009-01-14 20:38:07 -08:00
|
|
|
aSVGElement->DidAnimateLength(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
2011-03-31 12:29:44 -07:00
|
|
|
void
|
|
|
|
nsSVGLength2::SetAnimValue(float aValue, nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
SetAnimValueInSpecifiedUnits(aValue * GetUnitScaleFactor(aSVGElement,
|
|
|
|
mSpecifiedUnitType),
|
|
|
|
aSVGElement);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsSVGLength2::ToDOMAnimatedLength(nsIDOMSVGAnimatedLength **aResult,
|
|
|
|
nsSVGElement *aSVGElement)
|
2013-01-06 01:32:02 -08:00
|
|
|
{
|
|
|
|
*aResult = ToDOMAnimatedLength(aSVGElement).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
nsSVGLength2::ToDOMAnimatedLength(nsSVGElement* aSVGElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-19 12:56:00 -08:00
|
|
|
nsRefPtr<SVGAnimatedLength> svgAnimatedLength =
|
2012-08-22 23:24:43 -07:00
|
|
|
sSVGAnimatedLengthTearoffTable.GetTearoff(this);
|
2013-01-19 12:56:00 -08:00
|
|
|
if (!svgAnimatedLength) {
|
|
|
|
svgAnimatedLength = new SVGAnimatedLength(this, aSVGElement);
|
|
|
|
sSVGAnimatedLengthTearoffTable.AddTearoff(this, svgAnimatedLength);
|
2009-08-26 21:30:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
return svgAnimatedLength.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
SVGAnimatedLength::~SVGAnimatedLength()
|
2009-08-26 21:30:51 -07:00
|
|
|
{
|
|
|
|
sSVGAnimatedLengthTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGLength2::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILLength(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGLength2::SMILLength::ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const SVGAnimationElement* /*aSrcElement*/,
|
2010-02-20 13:13:11 -08:00
|
|
|
nsSMILValue& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2009-01-21 17:00:27 -08:00
|
|
|
float value;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t unitType;
|
2009-01-21 17:00:27 -08:00
|
|
|
|
|
|
|
nsresult rv = GetValueFromString(aStr, &value, &unitType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
nsSMILValue val(&nsSMILFloatType::sSingleton);
|
2009-01-21 17:00:27 -08:00
|
|
|
val.mU.mDouble = value / mVal->GetUnitScaleFactor(mSVGElement, unitType);
|
2009-01-14 20:38:07 -08:00
|
|
|
aValue = val;
|
2010-06-23 17:30:55 -07:00
|
|
|
aPreventCachingOfSandwich =
|
|
|
|
(unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE ||
|
|
|
|
unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_EMS ||
|
|
|
|
unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_EXS);
|
2010-02-20 13:13:11 -08:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGLength2::SMILLength::GetBaseValue() const
|
|
|
|
{
|
|
|
|
nsSMILValue val(&nsSMILFloatType::sSingleton);
|
|
|
|
val.mU.mDouble = mVal->GetBaseValue(mSVGElement);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-07-14 12:33:29 -07:00
|
|
|
void
|
|
|
|
nsSVGLength2::SMILLength::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mVal->mIsAnimated) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mVal->mIsAnimated = false;
|
2012-03-03 01:21:09 -08:00
|
|
|
mVal->mAnimVal = mVal->mBaseVal;
|
|
|
|
mSVGElement->DidAnimateLength(mVal->mAttrEnum);
|
2009-07-14 12:33:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
nsresult
|
|
|
|
nsSVGLength2::SMILLength::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aValue.mType == &nsSMILFloatType::sSingleton,
|
|
|
|
"Unexpected type to assign animated value");
|
|
|
|
if (aValue.mType == &nsSMILFloatType::sSingleton) {
|
2009-01-21 17:00:27 -08:00
|
|
|
mVal->SetAnimValue(float(aValue.mU.mDouble), mSVGElement);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|