2019-02-15 11:41: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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedOrient.h"
|
2019-02-15 11:41:37 +03:00
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "DOMSVGAngle.h"
|
|
|
|
#include "DOMSVGAnimatedAngle.h"
|
|
|
|
#include "SVGAttrTearoffTable.h"
|
|
|
|
#include "SVGOrientSMILType.h"
|
2019-02-15 11:41:37 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2020-01-17 13:00:28 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2019-02-15 11:41:37 +03:00
|
|
|
#include "mozilla/SMILValue.h"
|
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2020-01-17 13:00:28 +03:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2019-02-15 11:41:37 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-03-19 03:01:03 +03:00
|
|
|
#include "nsTextFormatter.h"
|
2020-02-20 01:06:09 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2019-02-15 11:41:37 +03:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::SVGAngle_Binding;
|
|
|
|
using namespace mozilla::dom::SVGMarkerElement_Binding;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
static const nsStaticAtom* const angleUnitMap[] = {
|
|
|
|
nullptr, /* SVG_ANGLETYPE_UNKNOWN */
|
|
|
|
nullptr, /* SVG_ANGLETYPE_UNSPECIFIED */
|
|
|
|
nsGkAtoms::deg, nsGkAtoms::rad, nsGkAtoms::grad};
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedOrient, DOMSVGAnimatedEnumeration>
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedEnumTearoffTable;
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedOrient, DOMSVGAnimatedAngle>
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedAngleTearoffTable;
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedOrient, DOMSVGAngle>
|
|
|
|
sBaseSVGAngleTearoffTable;
|
|
|
|
static SVGAttrTearoffTable<SVGAnimatedOrient, DOMSVGAngle>
|
|
|
|
sAnimSVGAngleTearoffTable;
|
2019-02-15 11:41:37 +03:00
|
|
|
|
|
|
|
/* Helper functions */
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeOrientNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeOrient and
|
2020-01-17 13:00:28 +03:00
|
|
|
// DidChangeOrient with mozAutoDocUpdate.
|
2019-02-15 11:41:37 +03:00
|
|
|
class MOZ_RAII AutoChangeOrientNotifier {
|
|
|
|
public:
|
|
|
|
explicit AutoChangeOrientNotifier(
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedOrient* aOrient, SVGElement* aSVGElement,
|
2019-02-15 11:41:37 +03:00
|
|
|
bool aDoSetAttr = true MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mOrient(aOrient), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
MOZ_ASSERT(mOrient, "Expecting non-null orient");
|
|
|
|
if (mSVGElement && mDoSetAttr) {
|
2020-01-17 13:00:28 +03:00
|
|
|
mUpdateBatch.emplace(mSVGElement->GetComposedDoc(), true);
|
|
|
|
mEmptyOrOldValue = mSVGElement->WillChangeOrient(mUpdateBatch.ref());
|
2019-02-15 11:41:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeOrientNotifier() {
|
|
|
|
if (mSVGElement) {
|
|
|
|
if (mDoSetAttr) {
|
2020-01-17 13:00:28 +03:00
|
|
|
mSVGElement->DidChangeOrient(mEmptyOrOldValue, mUpdateBatch.ref());
|
2019-02-15 11:41:37 +03:00
|
|
|
}
|
|
|
|
if (mOrient->mIsAnimated) {
|
|
|
|
mSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-01-17 13:00:28 +03:00
|
|
|
Maybe<mozAutoDocUpdate> mUpdateBatch;
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedOrient* const mOrient;
|
2019-02-15 11:41:37 +03:00
|
|
|
SVGElement* const mSVGElement;
|
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
bool mDoSetAttr;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool IsValidAngleUnitType(uint16_t unit) {
|
2019-04-20 13:29:32 +03:00
|
|
|
return unit > SVG_ANGLETYPE_UNKNOWN && unit <= SVG_ANGLETYPE_GRAD;
|
2019-02-15 11:41:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void GetAngleUnitString(nsAString& unit, uint16_t unitType) {
|
|
|
|
if (IsValidAngleUnitType(unitType)) {
|
|
|
|
if (angleUnitMap[unitType]) {
|
|
|
|
angleUnitMap[unitType]->ToString(unit);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown unit type");
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t GetAngleUnitTypeForString(const nsAString& unitStr) {
|
|
|
|
if (unitStr.IsEmpty()) return SVG_ANGLETYPE_UNSPECIFIED;
|
|
|
|
|
|
|
|
nsStaticAtom* unitAtom = NS_GetStaticAtom(unitStr);
|
|
|
|
|
|
|
|
if (unitAtom) {
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(angleUnitMap); i++) {
|
|
|
|
if (angleUnitMap[i] == unitAtom) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SVG_ANGLETYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GetAngleValueString(nsAString& aValueAsString, float aValue,
|
|
|
|
uint16_t aUnitType) {
|
|
|
|
nsTextFormatter::ssprintf(aValueAsString, u"%g", (double)aValue);
|
|
|
|
|
|
|
|
nsAutoString unitString;
|
|
|
|
GetAngleUnitString(unitString, aUnitType);
|
|
|
|
aValueAsString.Append(unitString);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
2019-04-04 20:40:56 +03:00
|
|
|
bool SVGAnimatedOrient::GetValueFromString(const nsAString& aString,
|
|
|
|
float& aValue, uint16_t* aUnitType) {
|
2019-03-27 11:52:33 +03:00
|
|
|
bool success;
|
|
|
|
auto token = SVGContentUtils::GetAndEnsureOneToken(aString, success);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RangedPtr<const char16_t> iter = SVGContentUtils::GetStartRangedPtr(token);
|
|
|
|
const RangedPtr<const char16_t> end = SVGContentUtils::GetEndRangedPtr(token);
|
2019-02-15 11:41:37 +03:00
|
|
|
|
|
|
|
if (!SVGContentUtils::ParseNumber(iter, end, aValue)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& units = Substring(iter.get(), end.get());
|
|
|
|
*aUnitType = GetAngleUnitTypeForString(units);
|
|
|
|
return IsValidAngleUnitType(*aUnitType);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
2019-04-04 20:40:56 +03:00
|
|
|
float SVGAnimatedOrient::GetDegreesPerUnit(uint8_t aUnit) {
|
2019-02-15 11:41:37 +03:00
|
|
|
switch (aUnit) {
|
|
|
|
case SVG_ANGLETYPE_UNSPECIFIED:
|
|
|
|
case SVG_ANGLETYPE_DEG:
|
|
|
|
return 1;
|
|
|
|
case SVG_ANGLETYPE_RAD:
|
|
|
|
return static_cast<float>(180.0 / M_PI);
|
|
|
|
case SVG_ANGLETYPE_GRAD:
|
|
|
|
return 90.0f / 100.0f;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown unit type");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::SetBaseValueInSpecifiedUnits(float aValue,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (mBaseVal == aValue && mBaseType == SVG_MARKER_ORIENT_ANGLE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoChangeOrientNotifier notifier(this, aSVGElement);
|
|
|
|
|
|
|
|
mBaseVal = aValue;
|
|
|
|
mBaseType = SVG_MARKER_ORIENT_ANGLE;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimType = mBaseType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedOrient::ConvertToSpecifiedUnits(uint16_t unitType,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (!IsValidAngleUnitType(unitType)) return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
|
|
|
|
if (mBaseValUnit == uint8_t(unitType) &&
|
|
|
|
mBaseType == SVG_MARKER_ORIENT_ANGLE) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
float valueInUserUnits = mBaseVal * GetDegreesPerUnit(mBaseValUnit);
|
|
|
|
SetBaseValue(valueInUserUnits, unitType, aSVGElement, true);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-27 10:57:50 +03:00
|
|
|
nsresult SVGAnimatedOrient::NewValueSpecifiedUnits(uint16_t aUnitType,
|
|
|
|
float aValueInSpecifiedUnits,
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGElement* aSVGElement) {
|
2019-04-27 10:57:50 +03:00
|
|
|
NS_ENSURE_FINITE(aValueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
|
2019-02-15 11:41:37 +03:00
|
|
|
|
2019-04-27 10:57:50 +03:00
|
|
|
if (!IsValidAngleUnitType(aUnitType)) return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2019-02-15 11:41:37 +03:00
|
|
|
|
2019-04-27 10:57:50 +03:00
|
|
|
if (mBaseVal == aValueInSpecifiedUnits &&
|
|
|
|
mBaseValUnit == uint8_t(aUnitType) &&
|
2019-02-15 11:41:37 +03:00
|
|
|
mBaseType == SVG_MARKER_ORIENT_ANGLE)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
AutoChangeOrientNotifier notifier(this, aSVGElement);
|
|
|
|
|
2019-04-27 10:57:50 +03:00
|
|
|
mBaseVal = aValueInSpecifiedUnits;
|
|
|
|
mBaseValUnit = uint8_t(aUnitType);
|
2019-02-15 11:41:37 +03:00
|
|
|
mBaseType = SVG_MARKER_ORIENT_ANGLE;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimValUnit = mBaseValUnit;
|
|
|
|
mAnimType = mBaseType;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAngle> SVGAnimatedOrient::ToDOMBaseVal(
|
|
|
|
SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
RefPtr<DOMSVGAngle> domBaseVal = sBaseSVGAngleTearoffTable.GetTearoff(this);
|
|
|
|
if (!domBaseVal) {
|
|
|
|
domBaseVal = new DOMSVGAngle(this, aSVGElement, DOMSVGAngle::BaseValue);
|
|
|
|
sBaseSVGAngleTearoffTable.AddTearoff(this, domBaseVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
return domBaseVal.forget();
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAngle> SVGAnimatedOrient::ToDOMAnimVal(
|
|
|
|
SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
RefPtr<DOMSVGAngle> domAnimVal = sAnimSVGAngleTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimVal) {
|
|
|
|
domAnimVal = new DOMSVGAngle(this, aSVGElement, DOMSVGAngle::AnimValue);
|
|
|
|
sAnimSVGAngleTearoffTable.AddTearoff(this, domAnimVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
return domAnimVal.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGAngle::~DOMSVGAngle() {
|
|
|
|
if (mType == BaseValue) {
|
|
|
|
sBaseSVGAngleTearoffTable.RemoveTearoff(mVal);
|
|
|
|
} else if (mType == AnimValue) {
|
|
|
|
sAnimSVGAngleTearoffTable.RemoveTearoff(mVal);
|
|
|
|
} else {
|
|
|
|
delete mVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implementation */
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedOrient::SetBaseValueString(const nsAString& aValueAsString,
|
|
|
|
SVGElement* aSVGElement,
|
|
|
|
bool aDoSetAttr) {
|
2019-02-15 11:41:37 +03:00
|
|
|
uint8_t type;
|
|
|
|
float value;
|
|
|
|
uint16_t unitType;
|
|
|
|
bool valueChanged = false;
|
|
|
|
|
|
|
|
if (aValueAsString.EqualsLiteral("auto")) {
|
|
|
|
type = SVG_MARKER_ORIENT_AUTO;
|
|
|
|
if (type == mBaseType) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else if (aValueAsString.EqualsLiteral("auto-start-reverse")) {
|
|
|
|
type = SVG_MARKER_ORIENT_AUTO_START_REVERSE;
|
|
|
|
if (type == mBaseType) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!GetValueFromString(aValueAsString, value, &unitType)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
if (mBaseVal == value && mBaseValUnit == uint8_t(unitType) &&
|
|
|
|
mBaseType == SVG_MARKER_ORIENT_ANGLE) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
valueChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoChangeOrientNotifier notifier(this, aSVGElement, aDoSetAttr);
|
|
|
|
|
|
|
|
if (valueChanged) {
|
|
|
|
mBaseVal = value;
|
|
|
|
mBaseValUnit = uint8_t(unitType);
|
|
|
|
mBaseType = SVG_MARKER_ORIENT_ANGLE;
|
|
|
|
} else {
|
|
|
|
mBaseVal = .0f;
|
|
|
|
mBaseValUnit = SVG_ANGLETYPE_UNSPECIFIED;
|
|
|
|
mBaseType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimValUnit = mBaseValUnit;
|
|
|
|
mAnimType = mBaseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::GetBaseValueString(nsAString& aValueAsString) const {
|
2019-02-15 11:41:37 +03:00
|
|
|
switch (mBaseType) {
|
|
|
|
case SVG_MARKER_ORIENT_AUTO:
|
|
|
|
aValueAsString.AssignLiteral("auto");
|
|
|
|
return;
|
|
|
|
case SVG_MARKER_ORIENT_AUTO_START_REVERSE:
|
|
|
|
aValueAsString.AssignLiteral("auto-start-reverse");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetAngleValueString(aValueAsString, mBaseVal, mBaseValUnit);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::GetBaseAngleValueString(
|
|
|
|
nsAString& aValueAsString) const {
|
2019-02-15 11:41:37 +03:00
|
|
|
GetAngleValueString(aValueAsString, mBaseVal, mBaseValUnit);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::GetAnimAngleValueString(
|
|
|
|
nsAString& aValueAsString) const {
|
2019-02-15 11:41:37 +03:00
|
|
|
GetAngleValueString(aValueAsString, mAnimVal, mAnimValUnit);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::SetBaseValue(float aValue, uint8_t aUnit,
|
|
|
|
SVGElement* aSVGElement, bool aDoSetAttr) {
|
2019-02-15 11:41:37 +03:00
|
|
|
float valueInSpecifiedUnits = aValue / GetDegreesPerUnit(aUnit);
|
|
|
|
if (aUnit == mBaseValUnit && mBaseVal == valueInSpecifiedUnits &&
|
|
|
|
mBaseType == SVG_MARKER_ORIENT_ANGLE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoChangeOrientNotifier notifier(this, aSVGElement, aDoSetAttr);
|
|
|
|
|
|
|
|
mBaseValUnit = aUnit;
|
|
|
|
mBaseVal = valueInSpecifiedUnits;
|
|
|
|
mBaseType = SVG_MARKER_ORIENT_ANGLE;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimValUnit = mBaseValUnit;
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimType = mBaseType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 01:06:09 +03:00
|
|
|
void SVGAnimatedOrient::SetBaseType(SVGEnumValue aValue,
|
|
|
|
SVGElement* aSVGElement, ErrorResult& aRv) {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (mBaseType == aValue) {
|
2020-02-20 01:06:09 +03:00
|
|
|
return;
|
2019-02-15 11:41:37 +03:00
|
|
|
}
|
2020-02-20 01:06:09 +03:00
|
|
|
if (aValue == SVG_MARKER_ORIENT_AUTO || aValue == SVG_MARKER_ORIENT_ANGLE) {
|
2019-02-15 11:41:37 +03:00
|
|
|
AutoChangeOrientNotifier notifier(this, aSVGElement);
|
|
|
|
|
|
|
|
mBaseVal = .0f;
|
|
|
|
mBaseValUnit = SVG_ANGLETYPE_UNSPECIFIED;
|
|
|
|
mBaseType = aValue;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
mAnimValUnit = mBaseValUnit;
|
|
|
|
mAnimType = mBaseType;
|
|
|
|
}
|
2020-02-20 01:06:09 +03:00
|
|
|
return;
|
2019-02-15 11:41:37 +03:00
|
|
|
}
|
2020-02-20 01:06:09 +03:00
|
|
|
nsPrintfCString err("Invalid base value %u for marker orient", aValue);
|
|
|
|
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
|
2019-02-15 11:41:37 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::SetAnimValue(float aValue, uint8_t aUnit,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (mIsAnimated && mAnimVal == aValue && mAnimValUnit == aUnit &&
|
|
|
|
mAnimType == SVG_MARKER_ORIENT_ANGLE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAnimVal = aValue;
|
|
|
|
mAnimValUnit = aUnit;
|
|
|
|
mAnimType = SVG_MARKER_ORIENT_ANGLE;
|
|
|
|
mIsAnimated = true;
|
|
|
|
aSVGElement->DidAnimateOrient();
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::SetAnimType(SVGEnumValue aValue,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (mIsAnimated && mAnimType == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAnimVal = .0f;
|
|
|
|
mAnimValUnit = SVG_ANGLETYPE_UNSPECIFIED;
|
|
|
|
mAnimType = aValue;
|
|
|
|
mIsAnimated = true;
|
|
|
|
aSVGElement->DidAnimateOrient();
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedAngle> SVGAnimatedOrient::ToDOMAnimatedAngle(
|
2019-02-15 11:41:37 +03:00
|
|
|
SVGElement* aSVGElement) {
|
2019-03-19 03:01:03 +03:00
|
|
|
RefPtr<DOMSVGAnimatedAngle> domAnimatedAngle =
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedAngleTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedAngle) {
|
2019-03-19 03:01:03 +03:00
|
|
|
domAnimatedAngle = new DOMSVGAnimatedAngle(this, aSVGElement);
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedAngleTearoffTable.AddTearoff(this, domAnimatedAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return domAnimatedAngle.forget();
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration>
|
|
|
|
SVGAnimatedOrient::ToDOMAnimatedEnum(SVGElement* aSVGElement) {
|
2019-03-19 03:01:03 +03:00
|
|
|
RefPtr<DOMSVGAnimatedEnumeration> domAnimatedEnum =
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedEnumTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedEnum) {
|
|
|
|
domAnimatedEnum = new DOMAnimatedEnum(this, aSVGElement);
|
|
|
|
sSVGAnimatedEnumTearoffTable.AddTearoff(this, domAnimatedEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return domAnimatedEnum.forget();
|
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
DOMSVGAnimatedAngle::~DOMSVGAnimatedAngle() {
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedAngleTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedOrient::DOMAnimatedEnum::~DOMAnimatedEnum() {
|
2019-02-15 11:41:37 +03:00
|
|
|
sSVGAnimatedEnumTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we want to avoid exposing SVG_MARKER_ORIENT_AUTO_START_REVERSE to
|
|
|
|
// Web content
|
2019-04-04 20:40:56 +03:00
|
|
|
uint16_t SVGAnimatedOrient::DOMAnimatedEnum::Sanitize(uint16_t aValue) {
|
2019-02-15 11:41:37 +03:00
|
|
|
return aValue == dom::SVG_MARKER_ORIENT_AUTO_START_REVERSE
|
|
|
|
? dom::SVGMarkerElement_Binding::SVG_MARKER_ORIENT_UNKNOWN
|
|
|
|
: aValue;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
UniquePtr<SMILAttr> SVGAnimatedOrient::ToSMILAttr(SVGElement* aSVGElement) {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (aSVGElement->NodeInfo()->Equals(nsGkAtoms::marker, kNameSpaceID_SVG)) {
|
|
|
|
return MakeUnique<SMILOrient>(this, aSVGElement);
|
|
|
|
}
|
|
|
|
// SMILOrient would not be useful for general angle attributes (also,
|
|
|
|
// "orient" is the only animatable <angle>-valued attribute in SVG 1.1).
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Trying to animate unknown angle attribute.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedOrient::SMILOrient::ValueFromString(
|
2019-02-15 11:41:37 +03:00
|
|
|
const nsAString& aStr, const SVGAnimationElement* /*aSrcElement*/,
|
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
|
|
|
|
SMILValue val(&SVGOrientSMILType::sSingleton);
|
|
|
|
if (aStr.EqualsLiteral("auto")) {
|
|
|
|
val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_AUTO;
|
|
|
|
val.mU.mOrient.mAngle = .0f;
|
|
|
|
val.mU.mOrient.mUnit = SVG_ANGLETYPE_UNSPECIFIED;
|
|
|
|
} else if (aStr.EqualsLiteral("auto-start-reverse")) {
|
|
|
|
val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_AUTO_START_REVERSE;
|
|
|
|
val.mU.mOrient.mAngle = .0f;
|
|
|
|
val.mU.mOrient.mUnit = SVG_ANGLETYPE_UNSPECIFIED;
|
|
|
|
} else {
|
|
|
|
float value;
|
|
|
|
uint16_t unitType;
|
|
|
|
if (!GetValueFromString(aStr, value, &unitType)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
val.mU.mOrient.mAngle = value;
|
|
|
|
val.mU.mOrient.mUnit = unitType;
|
|
|
|
val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_ANGLE;
|
|
|
|
}
|
|
|
|
aValue = std::move(val);
|
|
|
|
aPreventCachingOfSandwich = false;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SMILValue SVGAnimatedOrient::SMILOrient::GetBaseValue() const {
|
2019-02-15 11:41:37 +03:00
|
|
|
SMILValue val(&SVGOrientSMILType::sSingleton);
|
|
|
|
val.mU.mOrient.mAngle = mOrient->GetBaseValInSpecifiedUnits();
|
|
|
|
val.mU.mOrient.mUnit = mOrient->GetBaseValueUnit();
|
|
|
|
val.mU.mOrient.mOrientType = mOrient->mBaseType;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedOrient::SMILOrient::ClearAnimValue() {
|
2019-02-15 11:41:37 +03:00
|
|
|
if (mOrient->mIsAnimated) {
|
|
|
|
mOrient->mIsAnimated = false;
|
|
|
|
mOrient->mAnimVal = mOrient->mBaseVal;
|
|
|
|
mOrient->mAnimValUnit = mOrient->mBaseValUnit;
|
|
|
|
mOrient->mAnimType = mOrient->mBaseType;
|
|
|
|
mSVGElement->DidAnimateOrient();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedOrient::SMILOrient::SetAnimValue(const SMILValue& aValue) {
|
2019-02-15 11:41:37 +03:00
|
|
|
NS_ASSERTION(aValue.mType == &SVGOrientSMILType::sSingleton,
|
|
|
|
"Unexpected type to assign animated value");
|
|
|
|
|
|
|
|
if (aValue.mType == &SVGOrientSMILType::sSingleton) {
|
|
|
|
if (aValue.mU.mOrient.mOrientType == SVG_MARKER_ORIENT_AUTO ||
|
|
|
|
aValue.mU.mOrient.mOrientType == SVG_MARKER_ORIENT_AUTO_START_REVERSE) {
|
|
|
|
mOrient->SetAnimType(aValue.mU.mOrient.mOrientType, mSVGElement);
|
|
|
|
} else {
|
|
|
|
mOrient->SetAnimValue(aValue.mU.mOrient.mAngle, aValue.mU.mOrient.mUnit,
|
|
|
|
mSVGElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|