2004-07-01 08:10:34 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-07-01 08:10:34 +00:00
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2010-12-20 00:45:29 +00:00
|
|
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
2013-09-17 12:52:39 +00:00
|
|
|
#include "mozilla/dom/SVGAnimatedPreserveAspectRatioBinding.h"
|
2010-02-08 02:28:01 +00:00
|
|
|
#include "nsSMILValue.h"
|
2012-12-21 09:18:58 +00:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2013-09-17 12:52:39 +00:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2010-02-08 02:28:01 +00:00
|
|
|
#include "SMILEnumType.h"
|
2013-09-17 12:52:39 +00:00
|
|
|
#include "SVGContentUtils.h"
|
2010-02-08 02:28:01 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-12-23 04:54:20 +00:00
|
|
|
using namespace mozilla::dom;
|
2004-07-01 08:10:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2010-12-20 00:45:29 +00:00
|
|
|
// SVGAnimatedPreserveAspectRatio class
|
2012-12-23 04:54:22 +00:00
|
|
|
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAnimatedPreserveAspectRatio, mSVGElement)
|
2009-01-05 01:19:38 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedPreserveAspectRatio)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedPreserveAspectRatio)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedPreserveAspectRatio)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2009-01-05 01:19:38 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
DOMSVGAnimatedPreserveAspectRatio::WrapObject(JSContext* aCx)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return SVGAnimatedPreserveAspectRatioBinding::Wrap(aCx, this);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
/* Implementation */
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
static const char *sAlignStrings[] =
|
|
|
|
{ "none", "xMinYMin", "xMidYMin", "xMaxYMin", "xMinYMid", "xMidYMid",
|
|
|
|
"xMaxYMid", "xMinYMax", "xMidYMax", "xMaxYMax" };
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
static const char *sMeetOrSliceStrings[] = { "meet", "slice" };
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGAnimatedPreserveAspectRatio>
|
2012-12-21 09:18:58 +00:00
|
|
|
sSVGAnimatedPAspectRatioTearoffTable;
|
2012-12-23 04:54:20 +00:00
|
|
|
static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGPreserveAspectRatio>
|
2012-12-21 09:18:58 +00:00
|
|
|
sBaseSVGPAspectRatioTearoffTable;
|
2012-12-23 04:54:20 +00:00
|
|
|
static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGPreserveAspectRatio>
|
2012-12-21 09:18:58 +00:00
|
|
|
sAnimSVGPAspectRatioTearoffTable;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint16_t
|
2009-01-05 01:19:38 +00:00
|
|
|
GetAlignForString(const nsAString &aAlignString)
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0 ; i < ArrayLength(sAlignStrings) ; i++) {
|
2009-01-05 01:19:38 +00:00
|
|
|
if (aAlignString.EqualsASCII(sAlignStrings[i])) {
|
2013-01-10 14:37:30 +00:00
|
|
|
return (i + SVG_ALIGN_MIN_VALID);
|
2009-01-05 01:19:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-23 04:54:21 +00:00
|
|
|
return SVG_PRESERVEASPECTRATIO_UNKNOWN;
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
static void
|
2012-08-22 15:56:38 +00:00
|
|
|
GetAlignString(nsAString& aAlignString, uint16_t aAlign)
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2009-01-05 01:19:38 +00:00
|
|
|
NS_ASSERTION(
|
2013-01-10 14:37:30 +00:00
|
|
|
aAlign >= SVG_ALIGN_MIN_VALID && aAlign <= SVG_ALIGN_MAX_VALID,
|
2009-01-05 01:19:38 +00:00
|
|
|
"Unknown align");
|
|
|
|
|
|
|
|
aAlignString.AssignASCII(
|
2013-01-10 14:37:30 +00:00
|
|
|
sAlignStrings[aAlign - SVG_ALIGN_MIN_VALID]);
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint16_t
|
2009-01-05 01:19:38 +00:00
|
|
|
GetMeetOrSliceForString(const nsAString &aMeetOrSlice)
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0 ; i < ArrayLength(sMeetOrSliceStrings) ; i++) {
|
2009-01-05 01:19:38 +00:00
|
|
|
if (aMeetOrSlice.EqualsASCII(sMeetOrSliceStrings[i])) {
|
2013-01-10 14:37:30 +00:00
|
|
|
return (i + SVG_MEETORSLICE_MIN_VALID);
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-23 04:54:21 +00:00
|
|
|
return SVG_MEETORSLICE_UNKNOWN;
|
2009-01-05 01:19:38 +00:00
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
static void
|
2012-08-22 15:56:38 +00:00
|
|
|
GetMeetOrSliceString(nsAString& aMeetOrSliceString, uint16_t aMeetOrSlice)
|
2009-01-05 01:19:38 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(
|
2013-01-10 14:37:30 +00:00
|
|
|
aMeetOrSlice >= SVG_MEETORSLICE_MIN_VALID &&
|
|
|
|
aMeetOrSlice <= SVG_MEETORSLICE_MAX_VALID,
|
2009-01-05 01:19:38 +00:00
|
|
|
"Unknown meetOrSlice");
|
|
|
|
|
|
|
|
aMeetOrSliceString.AssignASCII(
|
2013-01-10 14:37:30 +00:00
|
|
|
sMeetOrSliceStrings[aMeetOrSlice - SVG_MEETORSLICE_MIN_VALID]);
|
2009-01-05 01:19:38 +00:00
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
already_AddRefed<DOMSVGPreserveAspectRatio>
|
|
|
|
DOMSVGAnimatedPreserveAspectRatio::BaseVal()
|
2009-01-05 01:19:38 +00:00
|
|
|
{
|
2012-12-23 04:54:20 +00:00
|
|
|
nsRefPtr<DOMSVGPreserveAspectRatio> domBaseVal =
|
2012-12-23 04:54:20 +00:00
|
|
|
sBaseSVGPAspectRatioTearoffTable.GetTearoff(mVal);
|
2012-12-21 09:18:58 +00:00
|
|
|
if (!domBaseVal) {
|
2012-12-23 04:54:20 +00:00
|
|
|
domBaseVal = new DOMSVGPreserveAspectRatio(mVal, mSVGElement, true);
|
|
|
|
sBaseSVGPAspectRatioTearoffTable.AddTearoff(mVal, domBaseVal);
|
2012-12-21 09:18:58 +00:00
|
|
|
}
|
2009-01-05 01:19:38 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
return domBaseVal.forget();
|
2009-01-05 01:19:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
DOMSVGPreserveAspectRatio::~DOMSVGPreserveAspectRatio()
|
2012-12-21 09:18:58 +00:00
|
|
|
{
|
2012-12-23 04:54:20 +00:00
|
|
|
if (mIsBaseValue) {
|
|
|
|
sBaseSVGPAspectRatioTearoffTable.RemoveTearoff(mVal);
|
|
|
|
} else {
|
|
|
|
sAnimSVGPAspectRatioTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
2012-12-21 09:18:58 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
already_AddRefed<DOMSVGPreserveAspectRatio>
|
|
|
|
DOMSVGAnimatedPreserveAspectRatio::AnimVal()
|
2009-01-05 01:19:38 +00:00
|
|
|
{
|
2012-12-23 04:54:20 +00:00
|
|
|
nsRefPtr<DOMSVGPreserveAspectRatio> domAnimVal =
|
2012-12-23 04:54:20 +00:00
|
|
|
sAnimSVGPAspectRatioTearoffTable.GetTearoff(mVal);
|
2012-12-21 09:18:58 +00:00
|
|
|
if (!domAnimVal) {
|
2012-12-23 04:54:20 +00:00
|
|
|
domAnimVal = new DOMSVGPreserveAspectRatio(mVal, mSVGElement, false);
|
|
|
|
sAnimSVGPAspectRatioTearoffTable.AddTearoff(mVal, domAnimVal);
|
2012-12-21 09:18:58 +00:00
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
return domAnimVal.forget();
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
static nsresult
|
|
|
|
ToPreserveAspectRatio(const nsAString &aString,
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGPreserveAspectRatio *aValue)
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2013-09-17 12:52:39 +00:00
|
|
|
nsWhitespaceTokenizerTemplate<IsSVGWhitespace> tokenizer(aString);
|
|
|
|
if (tokenizer.whitespaceBeforeFirstToken() ||
|
|
|
|
!tokenizer.hasMoreTokens()) {
|
2010-01-20 19:58:58 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
2009-01-05 01:19:38 +00:00
|
|
|
const nsAString &token = tokenizer.nextToken();
|
|
|
|
|
|
|
|
nsresult rv;
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGPreserveAspectRatio val;
|
2009-01-05 01:19:38 +00:00
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
val.SetDefer(token.EqualsLiteral("defer"));
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
if (val.GetDefer()) {
|
2009-01-05 01:19:38 +00:00
|
|
|
if (!tokenizer.hasMoreTokens()) {
|
2010-01-20 19:58:58 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
2009-01-05 01:19:38 +00:00
|
|
|
rv = val.SetAlign(GetAlignForString(tokenizer.nextToken()));
|
|
|
|
} else {
|
|
|
|
rv = val.SetAlign(GetAlignForString(token));
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-20 19:58:58 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
if (tokenizer.hasMoreTokens()) {
|
|
|
|
rv = val.SetMeetOrSlice(GetMeetOrSliceForString(tokenizer.nextToken()));
|
2010-01-20 19:58:58 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
2009-01-05 01:19:38 +00:00
|
|
|
} else {
|
2012-12-23 04:54:21 +00:00
|
|
|
val.SetMeetOrSlice(SVG_MEETORSLICE_MEET);
|
2009-01-05 01:19:38 +00:00
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2013-09-17 12:52:39 +00:00
|
|
|
if (tokenizer.whitespaceAfterCurrentToken()) {
|
2010-01-20 19:58:58 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2009-01-05 01:19:38 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
*aValue = val;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGAnimatedPreserveAspectRatio::SetBaseValueString(
|
2012-08-25 17:02:34 +00:00
|
|
|
const nsAString &aValueAsString, nsSVGElement *aSVGElement, bool aDoSetAttr)
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGPreserveAspectRatio val;
|
2010-02-08 02:28:01 +00:00
|
|
|
nsresult res = ToPreserveAspectRatio(aValueAsString, &val);
|
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-08-25 17:02:34 +00:00
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangePreserveAspectRatio();
|
|
|
|
}
|
|
|
|
|
2010-02-11 19:41:48 +00:00
|
|
|
mBaseVal = val;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2012-08-25 17:02:34 +00:00
|
|
|
|
2010-02-11 19:41:48 +00:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
2012-08-25 17:02:34 +00:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangePreserveAspectRatio(emptyOrOldValue);
|
|
|
|
}
|
|
|
|
if (mIsAnimated) {
|
2010-02-08 02:28:01 +00:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-01-05 01:19:38 +00:00
|
|
|
|
|
|
|
void
|
2012-02-15 23:40:46 +00:00
|
|
|
SVGAnimatedPreserveAspectRatio::GetBaseValueString(
|
|
|
|
nsAString& aValueAsString) const
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2009-01-05 01:19:38 +00:00
|
|
|
nsAutoString tmpString;
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
aValueAsString.Truncate();
|
2004-07-01 08:10:34 +00:00
|
|
|
|
2009-01-05 01:19:38 +00:00
|
|
|
if (mBaseVal.mDefer) {
|
|
|
|
aValueAsString.AppendLiteral("defer ");
|
|
|
|
}
|
|
|
|
|
|
|
|
GetAlignString(tmpString, mBaseVal.mAlign);
|
|
|
|
aValueAsString.Append(tmpString);
|
|
|
|
|
2013-01-10 14:37:30 +00:00
|
|
|
if (mBaseVal.mAlign != uint8_t(SVG_PRESERVEASPECTRATIO_NONE)) {
|
2009-01-05 01:19:38 +00:00
|
|
|
|
2014-05-22 03:48:51 +00:00
|
|
|
aValueAsString.Append(' ');
|
2009-01-05 01:19:38 +00:00
|
|
|
GetMeetOrSliceString(tmpString, mBaseVal.mMeetOrSlice);
|
|
|
|
aValueAsString.Append(tmpString);
|
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 10:02:41 +00:00
|
|
|
void
|
|
|
|
SVGAnimatedPreserveAspectRatio::SetBaseValue(const SVGPreserveAspectRatio &aValue,
|
2010-12-20 00:45:29 +00:00
|
|
|
nsSVGElement *aSVGElement)
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2012-05-17 10:02:41 +00:00
|
|
|
if (mIsBaseSet && mBaseVal == aValue) {
|
|
|
|
return;
|
2012-02-15 23:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangePreserveAspectRatio();
|
2012-05-17 10:02:41 +00:00
|
|
|
mBaseVal = aValue;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2009-01-05 01:19:38 +00:00
|
|
|
|
2012-05-17 10:02:41 +00:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
2012-02-15 23:40:46 +00:00
|
|
|
}
|
|
|
|
aSVGElement->DidChangePreserveAspectRatio(emptyOrOldValue);
|
2010-02-08 02:28:01 +00:00
|
|
|
if (mIsAnimated) {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2004-07-01 08:10:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint64_t
|
2012-06-01 23:53:06 +00:00
|
|
|
PackPreserveAspectRatio(const SVGPreserveAspectRatio& par)
|
|
|
|
{
|
|
|
|
// All preserveAspectRatio values are enum values (do not interpolate), so we
|
|
|
|
// can safely collate them and treat them as a single enum as for SMIL.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t packed = 0;
|
|
|
|
packed |= uint64_t(par.GetDefer() ? 1 : 0) << 16;
|
|
|
|
packed |= uint64_t(par.GetAlign()) << 8;
|
|
|
|
packed |= uint64_t(par.GetMeetOrSlice());
|
2012-06-01 23:53:06 +00:00
|
|
|
return packed;
|
|
|
|
}
|
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
SVGAnimatedPreserveAspectRatio::SetAnimValue(uint64_t aPackedValue,
|
2010-12-20 00:45:29 +00:00
|
|
|
nsSVGElement *aSVGElement)
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
2012-06-01 23:53:06 +00:00
|
|
|
if (mIsAnimated && PackPreserveAspectRatio(mAnimVal) == aPackedValue) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mAnimVal.SetDefer(((aPackedValue & 0xff0000) >> 16) ? true : false);
|
2012-08-22 15:56:38 +00:00
|
|
|
mAnimVal.SetAlign(uint16_t((aPackedValue & 0xff00) >> 8));
|
|
|
|
mAnimVal.SetMeetOrSlice(uint16_t(aPackedValue & 0xff));
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsAnimated = true;
|
2010-02-08 02:28:01 +00:00
|
|
|
aSVGElement->DidAnimatePreserveAspectRatio();
|
|
|
|
}
|
|
|
|
|
2004-07-01 08:10:34 +00:00
|
|
|
nsresult
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGAnimatedPreserveAspectRatio::ToDOMAnimatedPreserveAspectRatio(
|
2013-01-06 09:32:01 +00:00
|
|
|
DOMSVGAnimatedPreserveAspectRatio **aResult,
|
2009-01-05 01:19:38 +00:00
|
|
|
nsSVGElement *aSVGElement)
|
2004-07-01 08:10:34 +00:00
|
|
|
{
|
2012-12-23 04:54:20 +00:00
|
|
|
nsRefPtr<DOMSVGAnimatedPreserveAspectRatio> domAnimatedPAspectRatio =
|
2012-12-21 09:18:58 +00:00
|
|
|
sSVGAnimatedPAspectRatioTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedPAspectRatio) {
|
2012-12-23 04:54:20 +00:00
|
|
|
domAnimatedPAspectRatio = new DOMSVGAnimatedPreserveAspectRatio(this, aSVGElement);
|
2012-12-21 09:18:58 +00:00
|
|
|
sSVGAnimatedPAspectRatioTearoffTable.AddTearoff(this, domAnimatedPAspectRatio);
|
|
|
|
}
|
|
|
|
domAnimatedPAspectRatio.forget(aResult);
|
2004-07-01 08:10:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-08 02:28:01 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
DOMSVGAnimatedPreserveAspectRatio::~DOMSVGAnimatedPreserveAspectRatio()
|
2012-12-21 09:18:58 +00:00
|
|
|
{
|
|
|
|
sSVGAnimatedPAspectRatioTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
nsISMILAttr*
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGAnimatedPreserveAspectRatio::ToSMILAttr(nsSVGElement *aSVGElement)
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
|
|
|
return new SMILPreserveAspectRatio(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
2010-12-20 00:45:29 +00:00
|
|
|
// typedef for inner class, to make function signatures shorter below:
|
|
|
|
typedef SVGAnimatedPreserveAspectRatio::SMILPreserveAspectRatio
|
|
|
|
SMILPreserveAspectRatio;
|
|
|
|
|
2010-02-08 02:28:01 +00:00
|
|
|
nsresult
|
2010-12-20 00:45:29 +00:00
|
|
|
SMILPreserveAspectRatio::ValueFromString(const nsAString& aStr,
|
2013-03-19 03:18:45 +00:00
|
|
|
const SVGAnimationElement* /*aSrcElement*/,
|
2010-12-20 00:45:29 +00:00
|
|
|
nsSMILValue& aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
2010-12-20 00:45:29 +00:00
|
|
|
SVGPreserveAspectRatio par;
|
2010-02-08 02:28:01 +00:00
|
|
|
nsresult res = ToPreserveAspectRatio(aStr, &par);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
|
2013-05-30 22:34:53 +00:00
|
|
|
nsSMILValue val(SMILEnumType::Singleton());
|
2010-02-08 02:28:01 +00:00
|
|
|
val.mU.mUint = PackPreserveAspectRatio(par);
|
|
|
|
aValue = val;
|
2011-10-17 14:59:28 +00:00
|
|
|
aPreventCachingOfSandwich = false;
|
2010-02-08 02:28:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
2010-12-20 00:45:29 +00:00
|
|
|
SMILPreserveAspectRatio::GetBaseValue() const
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
2013-05-30 22:34:53 +00:00
|
|
|
nsSMILValue val(SMILEnumType::Singleton());
|
2010-02-08 02:28:01 +00:00
|
|
|
val.mU.mUint = PackPreserveAspectRatio(mVal->GetBaseValue());
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-20 00:45:29 +00:00
|
|
|
SMILPreserveAspectRatio::ClearAnimValue()
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
|
|
|
if (mVal->mIsAnimated) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mVal->mIsAnimated = false;
|
2012-03-03 09:21:09 +00:00
|
|
|
mVal->mAnimVal = mVal->mBaseVal;
|
|
|
|
mSVGElement->DidAnimatePreserveAspectRatio();
|
2010-02-08 02:28:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-12-20 00:45:29 +00:00
|
|
|
SMILPreserveAspectRatio::SetAnimValue(const nsSMILValue& aValue)
|
2010-02-08 02:28:01 +00:00
|
|
|
{
|
2013-05-30 22:34:53 +00:00
|
|
|
NS_ASSERTION(aValue.mType == SMILEnumType::Singleton(),
|
2010-02-08 02:28:01 +00:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 22:34:53 +00:00
|
|
|
if (aValue.mType == SMILEnumType::Singleton()) {
|
2010-02-08 02:28:01 +00:00
|
|
|
mVal->SetAnimValue(aValue.mU.mUint, mSVGElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|