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