2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
|
|
|
#include "nsSVGAngle.h"
|
2015-05-29 13:10:41 -07:00
|
|
|
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-01-29 14:11:44 -08:00
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2015-05-29 13:10:41 -07:00
|
|
|
#include "mozilla/Move.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h" // NS_ENSURE_FINITE
|
2010-02-18 13:50:59 -08:00
|
|
|
#include "nsSMILValue.h"
|
2013-09-17 05:52:39 -07:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
|
|
|
#include "nsTextFormatter.h"
|
2012-12-22 20:54:23 -08:00
|
|
|
#include "SVGAngle.h"
|
2012-12-22 20:54:23 -08:00
|
|
|
#include "SVGAnimatedAngle.h"
|
2013-09-17 05:52:39 -07:00
|
|
|
#include "SVGOrientSMILType.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-18 13:50:59 -08:00
|
|
|
using namespace mozilla;
|
2012-12-22 20:54:23 -08:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
static nsIAtom** const unitMap[] =
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, /* SVG_ANGLETYPE_UNKNOWN */
|
|
|
|
nullptr, /* SVG_ANGLETYPE_UNSPECIFIED */
|
2007-10-10 03:07:59 -07:00
|
|
|
&nsGkAtoms::deg,
|
|
|
|
&nsGkAtoms::rad,
|
|
|
|
&nsGkAtoms::grad
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-22 20:54:23 -08:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGAngle, SVGAnimatedAngle>
|
2012-12-21 01:18:58 -08:00
|
|
|
sSVGAnimatedAngleTearoffTable;
|
2012-12-22 20:54:23 -08:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGAngle, SVGAngle>
|
2012-12-21 01:18:58 -08:00
|
|
|
sBaseSVGAngleTearoffTable;
|
2012-12-22 20:54:23 -08:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGAngle, SVGAngle>
|
2012-12-21 01:18:58 -08:00
|
|
|
sAnimSVGAngleTearoffTable;
|
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
/* Helper functions */
|
2007-10-05 02:11:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-22 08:56:38 -07:00
|
|
|
IsValidUnitType(uint16_t unit)
|
2007-10-05 10:06:47 -07:00
|
|
|
{
|
2012-12-22 20:54:23 -08:00
|
|
|
if (unit > SVG_ANGLETYPE_UNKNOWN &&
|
|
|
|
unit <= SVG_ANGLETYPE_GRAD)
|
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
|
|
|
}
|
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
GetUnitString(nsAString& unit, uint16_t unitType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-10-10 03:07:59 -07:00
|
|
|
if (IsValidUnitType(unitType)) {
|
|
|
|
if (unitMap[unitType]) {
|
|
|
|
(*unitMap[unitType])->ToString(unit);
|
|
|
|
}
|
|
|
|
return;
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
2007-10-05 10:06:47 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return;
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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-05 02:11:00 -07:00
|
|
|
{
|
2012-08-24 00:29:09 -07:00
|
|
|
if (unitStr.IsEmpty())
|
2012-12-22 20:54:23 -08:00
|
|
|
return SVG_ANGLETYPE_UNSPECIFIED;
|
2007-10-10 03:07:59 -07:00
|
|
|
|
2012-08-24 00:29:09 -07:00
|
|
|
nsIAtom *unitAtom = NS_GetStaticAtom(unitStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-24 00:29:09 -07:00
|
|
|
if (unitAtom) {
|
|
|
|
for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
|
|
|
|
if (unitMap[i] && *unitMap[i] == unitAtom) {
|
|
|
|
return i;
|
|
|
|
}
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:23 -08:00
|
|
|
return SVG_ANGLETYPE_UNKNOWN;
|
2007-10-05 10:06:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
|
2007-10-05 10:06:47 -07:00
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t buf[24];
|
|
|
|
nsTextFormatter::snprintf(buf, sizeof(buf)/sizeof(char16_t),
|
2013-12-12 17:50:01 -08:00
|
|
|
MOZ_UTF16("%g"),
|
2007-10-10 03:07:59 -07:00
|
|
|
(double)aValue);
|
2007-10-05 10:06:47 -07:00
|
|
|
aValueAsString.Assign(buf);
|
2007-10-10 03:07:59 -07:00
|
|
|
|
2007-10-05 10:06:47 -07:00
|
|
|
nsAutoString unitString;
|
2007-10-10 03:07:59 -07:00
|
|
|
GetUnitString(unitString, aUnitType);
|
2007-10-05 10:06:47 -07:00
|
|
|
aValueAsString.Append(unitString);
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-01 00:50:40 -07:00
|
|
|
static bool
|
2013-10-29 10:15:39 -07:00
|
|
|
GetValueFromString(const nsAString& aString,
|
2013-10-01 00:50:40 -07:00
|
|
|
float& aValue,
|
|
|
|
uint16_t* aUnitType)
|
2007-10-05 02:11:00 -07:00
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
RangedPtr<const char16_t> iter =
|
2013-10-29 10:15:39 -07:00
|
|
|
SVGContentUtils::GetStartRangedPtr(aString);
|
2014-01-04 07:02:17 -08:00
|
|
|
const RangedPtr<const char16_t> end =
|
2013-10-29 10:15:39 -07:00
|
|
|
SVGContentUtils::GetEndRangedPtr(aString);
|
2007-10-05 02:11:00 -07:00
|
|
|
|
2013-10-29 10:15:39 -07:00
|
|
|
if (!SVGContentUtils::ParseNumber(iter, end, aValue)) {
|
2013-10-01 00:50:40 -07:00
|
|
|
return false;
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
2013-10-01 00:50:40 -07:00
|
|
|
|
2013-10-29 10:15:39 -07:00
|
|
|
const nsAString& units = Substring(iter.get(), end.get());
|
2013-10-01 00:50:40 -07:00
|
|
|
*aUnitType = GetUnitTypeForString(units);
|
|
|
|
return IsValidUnitType(*aUnitType);
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-18 13:50:59 -08:00
|
|
|
/* static */ float
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGAngle::GetDegreesPerUnit(uint8_t aUnit)
|
2007-10-05 02:11:00 -07:00
|
|
|
{
|
2010-02-18 13:50:59 -08:00
|
|
|
switch (aUnit) {
|
2012-12-22 20:54:23 -08:00
|
|
|
case SVG_ANGLETYPE_UNSPECIFIED:
|
|
|
|
case SVG_ANGLETYPE_DEG:
|
2007-10-10 03:07:59 -07:00
|
|
|
return 1;
|
2012-12-22 20:54:23 -08:00
|
|
|
case SVG_ANGLETYPE_RAD:
|
2010-02-18 13:50:59 -08:00
|
|
|
return static_cast<float>(180.0 / M_PI);
|
2012-12-22 20:54:23 -08:00
|
|
|
case SVG_ANGLETYPE_GRAD:
|
2011-03-31 12:29:44 -07:00
|
|
|
return 90.0f / 100.0f;
|
2007-10-10 03:07:59 -07:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-05 02:11:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
void
|
|
|
|
nsSVGAngle::SetBaseValueInSpecifiedUnits(float aValue,
|
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
{
|
2012-02-15 15:40:45 -08:00
|
|
|
if (mBaseVal == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
|
2007-10-10 03:07:59 -07:00
|
|
|
mBaseVal = aValue;
|
2010-02-18 13:50:59 -08:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
aSVGElement->DidChangeAngle(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
|
|
|
nsSVGAngle::ConvertToSpecifiedUnits(uint16_t unitType,
|
2007-10-10 03:07:59 -07:00
|
|
|
nsSVGElement *aSVGElement)
|
2007-10-05 02:11:00 -07:00
|
|
|
{
|
2007-10-10 03:07:59 -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-08-22 08:56:38 -07:00
|
|
|
if (mBaseValUnit == uint8_t(unitType))
|
2012-02-15 15:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-05-04 00:41:42 -07:00
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aSVGElement) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
|
2010-02-18 13:50:59 -08:00
|
|
|
float valueInUserUnits = mBaseVal * GetDegreesPerUnit(mBaseValUnit);
|
2012-08-22 08:56:38 -07:00
|
|
|
mBaseValUnit = 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);
|
|
|
|
|
2012-05-04 00:41:42 -07:00
|
|
|
if (aSVGElement) {
|
|
|
|
aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_OK;
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
|
|
|
|
2010-01-20 11:58:58 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGAngle::NewValueSpecifiedUnits(uint16_t unitType,
|
2007-10-10 03:07:59 -07:00
|
|
|
float valueInSpecifiedUnits,
|
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
{
|
2010-01-20 11:58:58 -08:00
|
|
|
NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
if (!IsValidUnitType(unitType))
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2007-10-10 03:07:59 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
if (mBaseVal == valueInSpecifiedUnits && mBaseValUnit == uint8_t(unitType))
|
2012-02-15 15:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aSVGElement) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
|
|
|
|
}
|
2010-02-18 13:50:59 -08:00
|
|
|
mBaseVal = valueInSpecifiedUnits;
|
2012-08-22 08:56:38 -07:00
|
|
|
mBaseValUnit = uint8_t(unitType);
|
2010-02-18 13:50:59 -08:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimValUnit = mBaseValUnit;
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
2010-02-18 13:50:59 -08:00
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2010-07-18 02:51:30 -07:00
|
|
|
if (aSVGElement) {
|
2012-02-15 15:40:45 -08:00
|
|
|
aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
|
2010-07-18 02:51:30 -07:00
|
|
|
}
|
2010-01-20 11:58:58 -08:00
|
|
|
return NS_OK;
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 22:31:11 -08:00
|
|
|
already_AddRefed<SVGAngle>
|
|
|
|
nsSVGAngle::ToDOMBaseVal(nsSVGElement *aSVGElement)
|
2007-10-10 03:07:59 -07:00
|
|
|
{
|
2012-12-22 20:54:23 -08:00
|
|
|
nsRefPtr<SVGAngle> domBaseVal =
|
2012-12-21 01:18:58 -08:00
|
|
|
sBaseSVGAngleTearoffTable.GetTearoff(this);
|
|
|
|
if (!domBaseVal) {
|
2012-12-22 20:54:23 -08:00
|
|
|
domBaseVal = new SVGAngle(this, aSVGElement, SVGAngle::BaseValue);
|
2012-12-21 01:18:58 -08:00
|
|
|
sBaseSVGAngleTearoffTable.AddTearoff(this, domBaseVal);
|
|
|
|
}
|
2007-10-10 03:07:59 -07:00
|
|
|
|
2013-01-29 22:31:11 -08:00
|
|
|
return domBaseVal.forget();
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 22:31:11 -08:00
|
|
|
already_AddRefed<SVGAngle>
|
|
|
|
nsSVGAngle::ToDOMAnimVal(nsSVGElement *aSVGElement)
|
2007-10-10 03:07:59 -07:00
|
|
|
{
|
2012-12-22 20:54:23 -08:00
|
|
|
nsRefPtr<SVGAngle> domAnimVal =
|
2012-12-21 01:18:58 -08:00
|
|
|
sAnimSVGAngleTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimVal) {
|
2012-12-22 20:54:23 -08:00
|
|
|
domAnimVal = new SVGAngle(this, aSVGElement, SVGAngle::AnimValue);
|
2012-12-21 01:18:58 -08:00
|
|
|
sAnimSVGAngleTearoffTable.AddTearoff(this, domAnimVal);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 22:31:11 -08:00
|
|
|
return domAnimVal.forget();
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
2007-10-05 02:11:00 -07:00
|
|
|
|
2012-12-22 20:54:23 -08:00
|
|
|
SVGAngle::~SVGAngle()
|
2012-12-21 01:18:58 -08:00
|
|
|
{
|
2012-12-22 20:54:23 -08:00
|
|
|
if (mType == BaseValue) {
|
|
|
|
sBaseSVGAngleTearoffTable.RemoveTearoff(mVal);
|
|
|
|
} else if (mType == AnimValue) {
|
|
|
|
sAnimSVGAngleTearoffTable.RemoveTearoff(mVal);
|
|
|
|
} else {
|
|
|
|
delete mVal;
|
|
|
|
}
|
2012-12-21 01:18:58 -08:00
|
|
|
}
|
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
/* Implementation */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
nsresult
|
|
|
|
nsSVGAngle::SetBaseValueString(const nsAString &aValueAsString,
|
|
|
|
nsSVGElement *aSVGElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoSetAttr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-01 00:50:40 -07:00
|
|
|
float value;
|
|
|
|
uint16_t unitType;
|
2007-10-05 10:06:47 -07:00
|
|
|
|
2013-10-01 00:50:40 -07:00
|
|
|
if (!GetValueFromString(aValueAsString, value, &unitType)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2007-10-15 05:06:42 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
if (mBaseVal == value && mBaseValUnit == uint8_t(unitType)) {
|
2012-02-15 15:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-10-10 03:07:59 -07:00
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
|
|
|
|
}
|
2010-02-18 13:50:59 -08:00
|
|
|
mBaseVal = value;
|
2012-08-22 08:56:38 -07:00
|
|
|
mBaseValUnit = uint8_t(unitType);
|
2010-02-18 13:50:59 -08:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimValUnit = mBaseValUnit;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
|
|
|
|
}
|
2007-10-10 03:07:59 -07:00
|
|
|
return NS_OK;
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGAngle::GetBaseValueString(nsAString & aValueAsString) const
|
2007-10-05 02:11:00 -07:00
|
|
|
{
|
2010-02-18 13:50:59 -08:00
|
|
|
GetValueString(aValueAsString, mBaseVal, mBaseValUnit);
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGAngle::GetAnimValueString(nsAString & aValueAsString) const
|
2007-10-10 03:07:59 -07:00
|
|
|
{
|
2010-02-18 13:50:59 -08:00
|
|
|
GetValueString(aValueAsString, mAnimVal, mAnimValUnit);
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-10 03:07:59 -07:00
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGAngle::SetBaseValue(float aValue, nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr)
|
2007-10-10 03:07:59 -07:00
|
|
|
{
|
2012-02-15 15:40:45 -08:00
|
|
|
if (mBaseVal == aValue * GetDegreesPerUnit(mBaseValUnit)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aSVGElement && aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
2010-02-18 13:50:59 -08:00
|
|
|
mBaseVal = aValue / GetDegreesPerUnit(mBaseValUnit);
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
2010-07-18 02:51:30 -07:00
|
|
|
else {
|
2010-02-18 13:50:59 -08:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
if (aSVGElement && aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
2007-10-05 02:11:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-18 13:50:59 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGAngle::SetAnimValue(float aValue, uint8_t aUnit, nsSVGElement *aSVGElement)
|
2010-02-18 13:50:59 -08:00
|
|
|
{
|
2012-06-01 16:53:06 -07:00
|
|
|
if (mIsAnimated && mAnimVal == aValue && mAnimValUnit == aUnit) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-18 13:50:59 -08:00
|
|
|
mAnimVal = aValue;
|
|
|
|
mAnimValUnit = aUnit;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAnimated = true;
|
2010-02-18 13:50:59 -08:00
|
|
|
aSVGElement->DidAnimateAngle(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
2013-01-29 14:11:44 -08:00
|
|
|
already_AddRefed<SVGAnimatedAngle>
|
|
|
|
nsSVGAngle::ToDOMAnimatedAngle(nsSVGElement *aSVGElement)
|
2007-10-05 02:11:00 -07:00
|
|
|
{
|
2012-12-22 20:54:23 -08:00
|
|
|
nsRefPtr<SVGAnimatedAngle> domAnimatedAngle =
|
2012-12-21 01:18:58 -08:00
|
|
|
sSVGAnimatedAngleTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedAngle) {
|
2012-12-22 20:54:23 -08:00
|
|
|
domAnimatedAngle = new SVGAnimatedAngle(this, aSVGElement);
|
2012-12-21 01:18:58 -08:00
|
|
|
sSVGAnimatedAngleTearoffTable.AddTearoff(this, domAnimatedAngle);
|
|
|
|
}
|
2007-10-05 02:11:00 -07:00
|
|
|
|
2013-01-29 14:11:44 -08:00
|
|
|
return domAnimatedAngle.forget();
|
2007-10-10 03:07:59 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:23 -08:00
|
|
|
SVGAnimatedAngle::~SVGAnimatedAngle()
|
2012-12-21 01:18:58 -08:00
|
|
|
{
|
|
|
|
sSVGAnimatedAngleTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2010-02-18 13:50:59 -08:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGAngle::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
if (aSVGElement->NodeInfo()->Equals(nsGkAtoms::marker, kNameSpaceID_SVG)) {
|
2013-01-29 14:11:44 -08:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(aSVGElement);
|
2010-02-18 13:50:59 -08:00
|
|
|
return new SMILOrient(marker->GetOrientType(), this, aSVGElement);
|
|
|
|
}
|
|
|
|
// SMILOrient would not be useful for general angle attributes (also,
|
|
|
|
// "orient" is the only animatable <angle>-valued attribute in SVG 1.1).
|
|
|
|
NS_NOTREACHED("Trying to animate unknown angle attribute.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-02-18 13:50:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGAngle::SMILOrient::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
|
2010-02-18 13:50:59 -08:00
|
|
|
{
|
|
|
|
nsSMILValue val(&SVGOrientSMILType::sSingleton);
|
|
|
|
if (aStr.EqualsLiteral("auto")) {
|
2013-02-18 14:48:54 -08:00
|
|
|
val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_AUTO;
|
2013-07-11 23:39:38 -07:00
|
|
|
} else if (aStr.EqualsLiteral("auto-start-reverse")) {
|
|
|
|
val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_AUTO_START_REVERSE;
|
2010-02-18 13:50:59 -08:00
|
|
|
} else {
|
|
|
|
float value;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t unitType;
|
2013-10-01 00:50:40 -07:00
|
|
|
if (!GetValueFromString(aStr, value, &unitType)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2010-02-18 13:50:59 -08:00
|
|
|
}
|
|
|
|
val.mU.mOrient.mAngle = value;
|
|
|
|
val.mU.mOrient.mUnit = unitType;
|
2013-02-18 14:48:54 -08:00
|
|
|
val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_ANGLE;
|
2010-02-18 13:50:59 -08:00
|
|
|
}
|
2015-05-29 13:10:41 -07:00
|
|
|
aValue = Move(val);
|
2011-10-17 07:59:28 -07:00
|
|
|
aPreventCachingOfSandwich = false;
|
2010-02-18 13:50:59 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGAngle::SMILOrient::GetBaseValue() const
|
|
|
|
{
|
|
|
|
nsSMILValue val(&SVGOrientSMILType::sSingleton);
|
|
|
|
val.mU.mOrient.mAngle = mAngle->GetBaseValInSpecifiedUnits();
|
|
|
|
val.mU.mOrient.mUnit = mAngle->GetBaseValueUnit();
|
|
|
|
val.mU.mOrient.mOrientType = mOrientType->GetBaseValue();
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGAngle::SMILOrient::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mAngle->mIsAnimated) {
|
|
|
|
mOrientType->SetAnimValue(mOrientType->GetBaseValue());
|
2011-10-17 07:59:28 -07:00
|
|
|
mAngle->mIsAnimated = false;
|
2012-03-03 01:21:09 -08:00
|
|
|
mAngle->mAnimVal = mAngle->mBaseVal;
|
|
|
|
mAngle->mAnimValUnit = mAngle->mBaseValUnit;
|
|
|
|
mSVGElement->DidAnimateAngle(mAngle->mAttrEnum);
|
2010-02-18 13:50:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGAngle::SMILOrient::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aValue.mType == &SVGOrientSMILType::sSingleton,
|
|
|
|
"Unexpected type to assign animated value");
|
|
|
|
|
|
|
|
if (aValue.mType == &SVGOrientSMILType::sSingleton) {
|
|
|
|
mOrientType->SetAnimValue(aValue.mU.mOrient.mOrientType);
|
2013-07-11 23:39:38 -07:00
|
|
|
if (aValue.mU.mOrient.mOrientType == SVG_MARKER_ORIENT_AUTO ||
|
|
|
|
aValue.mU.mOrient.mOrientType == SVG_MARKER_ORIENT_AUTO_START_REVERSE) {
|
2012-12-22 20:54:23 -08:00
|
|
|
mAngle->SetAnimValue(0.0f, SVG_ANGLETYPE_UNSPECIFIED, mSVGElement);
|
2010-02-18 13:50:59 -08:00
|
|
|
} else {
|
|
|
|
mAngle->SetAnimValue(aValue.mU.mOrient.mAngle, aValue.mU.mOrient.mUnit, mSVGElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|