2009-01-15 07:38:07 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SMIL module.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Brian Birtles.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Birtles <birtles@gmail.com>
|
|
|
|
* Chris Double <chris.double@double.co.nz>
|
|
|
|
* Daniel Holbert <dholbert@cs.stanford.edu>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsSMILAnimationFunction.h"
|
|
|
|
#include "nsISMILAttr.h"
|
|
|
|
#include "nsSMILParserUtils.h"
|
|
|
|
#include "nsSMILNullType.h"
|
|
|
|
#include "nsISMILAnimationElement.h"
|
2010-01-12 23:00:49 +03:00
|
|
|
#include "nsSMILTimedElement.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Static members
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILAnimationFunction::sAccumulateTable[] = {
|
|
|
|
{"none", PR_FALSE},
|
|
|
|
{"sum", PR_TRUE},
|
|
|
|
{nsnull, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILAnimationFunction::sAdditiveTable[] = {
|
|
|
|
{"replace", PR_FALSE},
|
|
|
|
{"sum", PR_TRUE},
|
|
|
|
{nsnull, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILAnimationFunction::sCalcModeTable[] = {
|
|
|
|
{"linear", CALC_LINEAR},
|
|
|
|
{"discrete", CALC_DISCRETE},
|
|
|
|
{"paced", CALC_PACED},
|
|
|
|
{"spline", CALC_SPLINE},
|
|
|
|
{nsnull, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Any negative number should be fine as a sentinel here,
|
|
|
|
// because valid distances are non-negative.
|
|
|
|
#define COMPUTE_DISTANCE_ERROR (-1)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Constructors etc.
|
|
|
|
|
|
|
|
nsSMILAnimationFunction::nsSMILAnimationFunction()
|
2010-12-10 21:33:13 +03:00
|
|
|
: mSampleTime(-1),
|
2009-01-15 07:38:07 +03:00
|
|
|
mRepeatIteration(0),
|
2010-12-10 21:33:13 +03:00
|
|
|
mBeginTime(LL_MININT),
|
|
|
|
mAnimationElement(nsnull),
|
|
|
|
mErrorFlags(0),
|
|
|
|
mIsActive(PR_FALSE),
|
|
|
|
mIsFrozen(PR_FALSE),
|
2009-01-15 07:38:07 +03:00
|
|
|
mLastValue(PR_FALSE),
|
|
|
|
mHasChanged(PR_TRUE),
|
2010-02-21 00:13:11 +03:00
|
|
|
mValueNeedsReparsingEverySample(PR_FALSE),
|
2010-12-10 21:33:13 +03:00
|
|
|
mPrevSampleWasSingleValueAnimation(PR_FALSE)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::SetAnimationElement(
|
|
|
|
nsISMILAnimationElement* aAnimationElement)
|
|
|
|
{
|
|
|
|
mAnimationElement = aAnimationElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::SetAttr(nsIAtom* aAttribute, const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult, nsresult* aParseResult)
|
|
|
|
{
|
|
|
|
PRBool foundMatch = PR_TRUE;
|
|
|
|
nsresult parseResult = NS_OK;
|
|
|
|
|
|
|
|
// The attributes 'by', 'from', 'to', and 'values' may be parsed differently
|
|
|
|
// depending on the element & attribute we're animating. So instead of
|
|
|
|
// parsing them now we re-parse them at every sample.
|
|
|
|
if (aAttribute == nsGkAtoms::by ||
|
|
|
|
aAttribute == nsGkAtoms::from ||
|
|
|
|
aAttribute == nsGkAtoms::to ||
|
|
|
|
aAttribute == nsGkAtoms::values) {
|
|
|
|
// We parse to, from, by, values at sample time.
|
|
|
|
// XXX Need to flag which attribute has changed and then when we parse it at
|
|
|
|
// sample time, report any errors and reset the flag
|
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
aResult.SetTo(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::accumulate) {
|
|
|
|
parseResult = SetAccumulate(aValue, aResult);
|
|
|
|
} else if (aAttribute == nsGkAtoms::additive) {
|
|
|
|
parseResult = SetAdditive(aValue, aResult);
|
|
|
|
} else if (aAttribute == nsGkAtoms::calcMode) {
|
|
|
|
parseResult = SetCalcMode(aValue, aResult);
|
|
|
|
} else if (aAttribute == nsGkAtoms::keyTimes) {
|
|
|
|
parseResult = SetKeyTimes(aValue, aResult);
|
|
|
|
} else if (aAttribute == nsGkAtoms::keySplines) {
|
|
|
|
parseResult = SetKeySplines(aValue, aResult);
|
|
|
|
} else {
|
|
|
|
foundMatch = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundMatch && aParseResult) {
|
|
|
|
*aParseResult = parseResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::UnsetAttr(nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
PRBool foundMatch = PR_TRUE;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::by ||
|
|
|
|
aAttribute == nsGkAtoms::from ||
|
|
|
|
aAttribute == nsGkAtoms::to ||
|
|
|
|
aAttribute == nsGkAtoms::values) {
|
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
} else if (aAttribute == nsGkAtoms::accumulate) {
|
|
|
|
UnsetAccumulate();
|
|
|
|
} else if (aAttribute == nsGkAtoms::additive) {
|
|
|
|
UnsetAdditive();
|
|
|
|
} else if (aAttribute == nsGkAtoms::calcMode) {
|
|
|
|
UnsetCalcMode();
|
|
|
|
} else if (aAttribute == nsGkAtoms::keyTimes) {
|
|
|
|
UnsetKeyTimes();
|
|
|
|
} else if (aAttribute == nsGkAtoms::keySplines) {
|
|
|
|
UnsetKeySplines();
|
|
|
|
} else {
|
|
|
|
foundMatch = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::SampleAt(nsSMILTime aSampleTime,
|
|
|
|
const nsSMILTimeValue& aSimpleDuration,
|
|
|
|
PRUint32 aRepeatIteration)
|
|
|
|
{
|
2010-12-10 21:33:13 +03:00
|
|
|
// * Update mHasChanged ("Might this sample be different from prev one?")
|
|
|
|
// Were we previously sampling a fill="freeze" final val? (We're not anymore.)
|
|
|
|
mHasChanged |= mLastValue;
|
|
|
|
|
|
|
|
// Are we sampling at a new point in simple duration? And does that matter?
|
|
|
|
mHasChanged |=
|
|
|
|
(mSampleTime != aSampleTime || mSimpleDuration != aSimpleDuration) &&
|
|
|
|
!IsValueFixedForSimpleDuration();
|
|
|
|
|
|
|
|
// Are we on a new repeat and accumulating across repeats?
|
|
|
|
mHasChanged |= (mRepeatIteration != aRepeatIteration) && GetAccumulate();
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
mSampleTime = aSampleTime;
|
|
|
|
mSimpleDuration = aSimpleDuration;
|
|
|
|
mRepeatIteration = aRepeatIteration;
|
|
|
|
mLastValue = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::SampleLastValue(PRUint32 aRepeatIteration)
|
|
|
|
{
|
|
|
|
if (mHasChanged || !mLastValue || mRepeatIteration != aRepeatIteration) {
|
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRepeatIteration = aRepeatIteration;
|
|
|
|
mLastValue = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::Activate(nsSMILTime aBeginTime)
|
|
|
|
{
|
|
|
|
mBeginTime = aBeginTime;
|
|
|
|
mIsActive = PR_TRUE;
|
|
|
|
mIsFrozen = PR_FALSE;
|
|
|
|
mFrozenValue = nsSMILValue();
|
2010-02-21 00:13:11 +03:00
|
|
|
mHasChanged = PR_TRUE;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::Inactivate(PRBool aIsFrozen)
|
|
|
|
{
|
|
|
|
mIsActive = PR_FALSE;
|
|
|
|
mIsFrozen = aIsFrozen;
|
|
|
|
mFrozenValue = nsSMILValue();
|
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::ComposeResult(const nsISMILAttr& aSMILAttr,
|
|
|
|
nsSMILValue& aResult)
|
|
|
|
{
|
|
|
|
mHasChanged = PR_FALSE;
|
2010-12-10 21:33:13 +03:00
|
|
|
mPrevSampleWasSingleValueAnimation = PR_FALSE;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Skip animations that are inactive or in error
|
2009-08-25 23:02:28 +04:00
|
|
|
if (!IsActiveOrFrozen() || mErrorFlags != 0)
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Get the animation values
|
|
|
|
nsSMILValueArray values;
|
|
|
|
nsresult rv = GetValues(aSMILAttr, values);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
// Check that we have the right number of keySplines and keyTimes
|
|
|
|
CheckValueListDependentAttrs(values.Length());
|
2009-08-24 23:34:34 +04:00
|
|
|
if (mErrorFlags != 0)
|
|
|
|
return;
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// If this interval is active, we must have a non-negative mSampleTime
|
|
|
|
NS_ABORT_IF_FALSE(mSampleTime >= 0 || !mIsActive,
|
|
|
|
"Negative sample time for active animation");
|
|
|
|
NS_ABORT_IF_FALSE(mSimpleDuration.IsResolved() ||
|
|
|
|
mSimpleDuration.IsIndefinite() || mLastValue,
|
|
|
|
"Unresolved simple duration for active or frozen animation");
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-11-24 02:31:17 +03:00
|
|
|
// If we want to add but don't have a base value then just fail outright.
|
|
|
|
// This can happen when we skipped getting the base value because there's an
|
|
|
|
// animation function in the sandwich that should replace it but that function
|
|
|
|
// failed unexpectedly.
|
|
|
|
PRBool isAdditive = IsAdditive();
|
|
|
|
if (isAdditive && aResult.IsNull())
|
|
|
|
return;
|
|
|
|
|
2010-11-10 02:21:04 +03:00
|
|
|
nsSMILValue result;
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2010-12-05 16:13:31 +03:00
|
|
|
if (values.Length() == 1 && !IsToAnimation()) {
|
|
|
|
|
|
|
|
// Single-valued animation
|
2009-01-15 07:38:07 +03:00
|
|
|
result = values[0];
|
2010-12-10 21:33:13 +03:00
|
|
|
mPrevSampleWasSingleValueAnimation = PR_TRUE;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
} else if (mLastValue) {
|
|
|
|
|
|
|
|
// Sampling last value
|
2010-04-29 03:00:54 +04:00
|
|
|
const nsSMILValue& last = values[values.Length() - 1];
|
2009-01-15 07:38:07 +03:00
|
|
|
result = last;
|
|
|
|
|
|
|
|
// See comment in AccumulateResult: to-animation does not accumulate
|
|
|
|
if (!IsToAnimation() && GetAccumulate() && mRepeatIteration) {
|
|
|
|
// If the target attribute type doesn't support addition Add will
|
|
|
|
// fail leaving result = last
|
|
|
|
result.Add(last, mRepeatIteration);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!mFrozenValue.IsNull() && !mHasChanged) {
|
|
|
|
|
|
|
|
// Frozen to animation
|
|
|
|
result = mFrozenValue;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Interpolation
|
2010-02-22 20:41:21 +03:00
|
|
|
if (NS_FAILED(InterpolateResult(values, result, aResult)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (NS_FAILED(AccumulateResult(values, result)))
|
|
|
|
return;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (IsToAnimation() && mIsFrozen) {
|
|
|
|
mFrozenValue = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If additive animation isn't required or isn't supported, set the value.
|
2010-11-24 02:31:17 +03:00
|
|
|
if (!isAdditive || NS_FAILED(aResult.SandwichAdd(result))) {
|
2010-03-26 22:24:07 +03:00
|
|
|
aResult.Swap(result);
|
|
|
|
// Note: The old value of aResult is now in |result|, and it will get
|
|
|
|
// cleaned up when |result| goes out of scope, when this function returns.
|
2009-01-19 12:14:16 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt8
|
|
|
|
nsSMILAnimationFunction::CompareTo(const nsSMILAnimationFunction* aOther) const
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aOther, 0);
|
|
|
|
|
2010-01-28 12:50:30 +03:00
|
|
|
NS_ASSERTION(aOther != this, "Trying to compare to self");
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Inactive animations sort first
|
2009-08-25 23:02:28 +04:00
|
|
|
if (!IsActiveOrFrozen() && aOther->IsActiveOrFrozen())
|
2009-01-15 07:38:07 +03:00
|
|
|
return -1;
|
|
|
|
|
2009-08-25 23:02:28 +04:00
|
|
|
if (IsActiveOrFrozen() && !aOther->IsActiveOrFrozen())
|
2009-01-15 07:38:07 +03:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
// Sort based on begin time
|
|
|
|
if (mBeginTime != aOther->GetBeginTime())
|
|
|
|
return mBeginTime > aOther->GetBeginTime() ? 1 : -1;
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// Next sort based on syncbase dependencies: the dependent element sorts after
|
|
|
|
// its syncbase
|
|
|
|
const nsSMILTimedElement& thisTimedElement =
|
|
|
|
mAnimationElement->TimedElement();
|
|
|
|
const nsSMILTimedElement& otherTimedElement =
|
|
|
|
aOther->mAnimationElement->TimedElement();
|
|
|
|
if (thisTimedElement.IsTimeDependent(otherTimedElement))
|
|
|
|
return 1;
|
|
|
|
if (otherTimedElement.IsTimeDependent(thisTimedElement))
|
|
|
|
return -1;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Animations that appear later in the document sort after those earlier in
|
|
|
|
// the document
|
2010-08-18 14:20:24 +04:00
|
|
|
nsIContent& thisContent = mAnimationElement->AsElement();
|
|
|
|
nsIContent& otherContent = aOther->mAnimationElement->AsElement();
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
NS_ABORT_IF_FALSE(&thisContent != &otherContent,
|
|
|
|
"Two animations cannot have the same animation content element!");
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
return (nsContentUtils::PositionIsBefore(&thisContent, &otherContent))
|
2009-01-15 07:38:07 +03:00
|
|
|
? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::WillReplace() const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* In IsAdditive() we don't consider to-animation to be additive as it is
|
|
|
|
* a special case that is dealt with differently in the compositing method but
|
|
|
|
* here we return false for to animation as it builds on the underlying value
|
|
|
|
* unless its a frozen to animation.
|
|
|
|
*/
|
2010-02-21 00:13:11 +03:00
|
|
|
return !mErrorFlags && (!(IsAdditive() || IsToAnimation()) ||
|
|
|
|
(IsToAnimation() && mIsFrozen && !mHasChanged));
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::HasChanged() const
|
|
|
|
{
|
2010-02-21 00:13:11 +03:00
|
|
|
return mHasChanged || mValueNeedsReparsingEverySample;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2010-02-21 00:13:11 +03:00
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::UpdateCachedTarget(const nsSMILTargetIdentifier& aNewTarget)
|
|
|
|
{
|
|
|
|
if (!mLastTarget.Equals(aNewTarget)) {
|
|
|
|
mLastTarget = aNewTarget;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::InterpolateResult(const nsSMILValueArray& aValues,
|
|
|
|
nsSMILValue& aResult,
|
|
|
|
nsSMILValue& aBaseValue)
|
|
|
|
{
|
2010-12-05 16:13:31 +03:00
|
|
|
// Sanity check animation values
|
2009-07-15 22:33:31 +04:00
|
|
|
if ((!IsToAnimation() && aValues.Length() < 2) ||
|
2009-01-15 07:38:07 +03:00
|
|
|
(IsToAnimation() && aValues.Length() != 1)) {
|
2010-01-28 12:50:30 +03:00
|
|
|
NS_ERROR("Unexpected number of values");
|
2009-01-15 07:38:07 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-12-05 16:13:31 +03:00
|
|
|
// Get the normalised progress through the simple duration.
|
|
|
|
//
|
|
|
|
// If we have an indefinite simple duration, just set the progress to be
|
|
|
|
// 0 which will give us the expected behaviour of the animation being fixed at
|
|
|
|
// its starting point.
|
|
|
|
double simpleProgress = 0.0;
|
|
|
|
|
|
|
|
if (mSimpleDuration.IsResolved()) {
|
|
|
|
nsSMILTime dur = mSimpleDuration.GetMillis();
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(dur >= 0, "Simple duration should not be negative");
|
|
|
|
NS_ABORT_IF_FALSE(mSampleTime >= 0, "Sample time should not be negative");
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-12-05 16:13:31 +03:00
|
|
|
if (mSampleTime >= dur || mSampleTime < 0) {
|
|
|
|
NS_ERROR("Animation sampled outside interval");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dur > 0) {
|
|
|
|
simpleProgress = (double)mSampleTime / dur;
|
|
|
|
} // else leave simpleProgress at 0.0 (e.g. if mSampleTime == dur == 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2010-09-18 07:46:48 +04:00
|
|
|
nsSMILCalcMode calcMode = GetCalcMode();
|
|
|
|
if (calcMode != CALC_DISCRETE) {
|
2009-10-03 01:37:25 +04:00
|
|
|
// Get the normalised progress between adjacent values
|
|
|
|
const nsSMILValue* from = nsnull;
|
|
|
|
const nsSMILValue* to = nsnull;
|
2010-09-18 07:46:48 +04:00
|
|
|
// Init to -1 to make sure that if we ever forget to set this, the
|
|
|
|
// NS_ABORT_IF_FALSE that tests that intervalProgress is in range will fail.
|
|
|
|
double intervalProgress = -1.f;
|
2009-10-03 01:37:25 +04:00
|
|
|
if (IsToAnimation()) {
|
2010-11-10 02:21:04 +03:00
|
|
|
if (aBaseValue.IsNull()) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2010-04-07 01:39:29 +04:00
|
|
|
} else {
|
2010-11-10 02:21:04 +03:00
|
|
|
from = &aBaseValue;
|
|
|
|
to = &aValues[0];
|
|
|
|
if (calcMode == CALC_PACED) {
|
|
|
|
// Note: key[Times/Splines/Points] are ignored for calcMode="paced"
|
|
|
|
intervalProgress = simpleProgress;
|
|
|
|
} else {
|
|
|
|
double scaledSimpleProgress =
|
|
|
|
ScaleSimpleProgress(simpleProgress, calcMode);
|
|
|
|
intervalProgress = ScaleIntervalProgress(scaledSimpleProgress, 0);
|
|
|
|
}
|
2010-04-07 01:39:29 +04:00
|
|
|
}
|
2010-12-05 16:13:31 +03:00
|
|
|
} else if (calcMode == CALC_PACED) {
|
|
|
|
rv = ComputePacedPosition(aValues, simpleProgress,
|
|
|
|
intervalProgress, from, to);
|
|
|
|
// Note: If the above call fails, we'll skip the "from->Interpolate"
|
|
|
|
// call below, and we'll drop into the CALC_DISCRETE section
|
|
|
|
// instead. (as the spec says we should, because our failure was
|
|
|
|
// presumably due to the values being non-additive)
|
|
|
|
} else { // calcMode == CALC_LINEAR or calcMode == CALC_SPLINE
|
|
|
|
double scaledSimpleProgress =
|
|
|
|
ScaleSimpleProgress(simpleProgress, calcMode);
|
|
|
|
PRUint32 index = (PRUint32)floor(scaledSimpleProgress *
|
|
|
|
(aValues.Length() - 1));
|
|
|
|
from = &aValues[index];
|
|
|
|
to = &aValues[index + 1];
|
|
|
|
intervalProgress =
|
|
|
|
scaledSimpleProgress * (aValues.Length() - 1) - index;
|
|
|
|
intervalProgress = ScaleIntervalProgress(intervalProgress, index);
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
2010-12-05 16:13:31 +03:00
|
|
|
|
2009-10-03 01:37:25 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2010-01-28 12:50:30 +03:00
|
|
|
NS_ABORT_IF_FALSE(from, "NULL from-value during interpolation");
|
|
|
|
NS_ABORT_IF_FALSE(to, "NULL to-value during interpolation");
|
2009-10-03 01:37:25 +04:00
|
|
|
NS_ABORT_IF_FALSE(0.0f <= intervalProgress && intervalProgress < 1.0f,
|
|
|
|
"Interval progress should be in the range [0, 1)");
|
|
|
|
rv = from->Interpolate(*to, intervalProgress, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Discrete-CalcMode case
|
|
|
|
// Note: If interpolation failed (isn't supported for this type), the SVG
|
|
|
|
// spec says to force discrete mode.
|
2010-09-18 07:46:48 +04:00
|
|
|
if (calcMode == CALC_DISCRETE || NS_FAILED(rv)) {
|
2009-07-28 00:52:19 +04:00
|
|
|
if (IsToAnimation()) {
|
2010-08-18 14:20:24 +04:00
|
|
|
// SMIL 3, 12.6.4: Since a to animation has only 1 value, a discrete to
|
|
|
|
// animation will simply set the to value for the simple duration.
|
|
|
|
aResult = aValues[0];
|
2009-07-28 00:52:19 +04:00
|
|
|
} else {
|
2010-09-18 07:46:48 +04:00
|
|
|
double scaledSimpleProgress =
|
|
|
|
ScaleSimpleProgress(simpleProgress, CALC_DISCRETE);
|
|
|
|
PRUint32 index = (PRUint32)floor(scaledSimpleProgress * aValues.Length());
|
2009-07-28 00:52:19 +04:00
|
|
|
aResult = aValues[index];
|
|
|
|
}
|
2009-10-03 01:37:25 +04:00
|
|
|
rv = NS_OK;
|
2009-07-15 22:33:31 +04:00
|
|
|
}
|
2009-10-03 01:37:25 +04:00
|
|
|
return rv;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::AccumulateResult(const nsSMILValueArray& aValues,
|
|
|
|
nsSMILValue& aResult)
|
|
|
|
{
|
|
|
|
if (!IsToAnimation() && GetAccumulate() && mRepeatIteration)
|
|
|
|
{
|
2010-02-11 22:40:50 +03:00
|
|
|
const nsSMILValue& lastValue = aValues[aValues.Length() - 1];
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// If the target attribute type doesn't support addition, Add will
|
|
|
|
// fail and we leave aResult untouched.
|
|
|
|
aResult.Add(lastValue, mRepeatIteration);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given the simple progress for a paced animation, this method:
|
|
|
|
* - determines which two elements of the values array we're in between
|
|
|
|
* (returned as aFrom and aTo)
|
|
|
|
* - determines where we are between them
|
|
|
|
* (returned as aIntervalProgress)
|
|
|
|
*
|
2009-10-03 01:37:25 +04:00
|
|
|
* Returns NS_OK, or NS_ERROR_FAILURE if our values don't support distance
|
|
|
|
* computation.
|
2009-01-15 07:38:07 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::ComputePacedPosition(const nsSMILValueArray& aValues,
|
|
|
|
double aSimpleProgress,
|
|
|
|
double& aIntervalProgress,
|
|
|
|
const nsSMILValue*& aFrom,
|
|
|
|
const nsSMILValue*& aTo)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0.0f <= aSimpleProgress && aSimpleProgress < 1.0f,
|
2010-01-28 12:50:30 +03:00
|
|
|
"aSimpleProgress is out of bounds");
|
2009-01-15 07:38:07 +03:00
|
|
|
NS_ASSERTION(GetCalcMode() == CALC_PACED,
|
|
|
|
"Calling paced-specific function, but not in paced mode");
|
2010-04-05 20:59:42 +04:00
|
|
|
NS_ABORT_IF_FALSE(aValues.Length() >= 2, "Unexpected number of values");
|
|
|
|
|
|
|
|
// Trivial case: If we have just 2 values, then there's only one interval
|
|
|
|
// for us to traverse, and our progress across that interval is the exact
|
|
|
|
// same as our overall progress.
|
|
|
|
if (aValues.Length() == 2) {
|
|
|
|
aIntervalProgress = aSimpleProgress;
|
|
|
|
aFrom = &aValues[0];
|
|
|
|
aTo = &aValues[1];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
double totalDistance = ComputePacedTotalDistance(aValues);
|
|
|
|
if (totalDistance == COMPUTE_DISTANCE_ERROR)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// total distance we should have moved at this point in time.
|
|
|
|
// (called 'remainingDist' due to how it's used in loop below)
|
|
|
|
double remainingDist = aSimpleProgress * totalDistance;
|
|
|
|
|
|
|
|
// Must be satisfied, because totalDistance is a sum of (non-negative)
|
|
|
|
// distances, and aSimpleProgress is non-negative
|
|
|
|
NS_ASSERTION(remainingDist >= 0, "distance values must be non-negative");
|
|
|
|
|
|
|
|
// Find where remainingDist puts us in the list of values
|
|
|
|
// Note: We could optimize this next loop by caching the
|
|
|
|
// interval-distances in an array, but maybe that's excessive.
|
|
|
|
for (PRUint32 i = 0; i < aValues.Length() - 1; i++) {
|
|
|
|
// Note: The following assertion is valid because remainingDist should
|
|
|
|
// start out non-negative, and this loop never shaves off more than its
|
|
|
|
// current value.
|
|
|
|
NS_ASSERTION(remainingDist >= 0, "distance values must be non-negative");
|
|
|
|
|
|
|
|
double curIntervalDist;
|
2010-07-11 16:30:35 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
aValues[i].ComputeDistance(aValues[i+1], curIntervalDist);
|
2009-10-03 01:37:25 +04:00
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"If we got through ComputePacedTotalDistance, we should "
|
|
|
|
"be able to recompute each sub-distance without errors");
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
NS_ASSERTION(curIntervalDist >= 0, "distance values must be non-negative");
|
|
|
|
// Clamp distance value at 0, just in case ComputeDistance is evil.
|
2009-12-31 02:25:44 +03:00
|
|
|
curIntervalDist = NS_MAX(curIntervalDist, 0.0);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (remainingDist >= curIntervalDist) {
|
|
|
|
remainingDist -= curIntervalDist;
|
|
|
|
} else {
|
|
|
|
// NOTE: If we get here, then curIntervalDist necessarily is not 0. Why?
|
|
|
|
// Because this clause is only hit when remainingDist < curIntervalDist,
|
|
|
|
// and if curIntervalDist were 0, that would mean remainingDist would
|
|
|
|
// have to be < 0. But that can't happen, because remainingDist (as
|
|
|
|
// a distance) is non-negative by definition.
|
|
|
|
NS_ASSERTION(curIntervalDist != 0,
|
|
|
|
"We should never get here with this set to 0...");
|
|
|
|
|
|
|
|
// We found the right spot -- an interpolated position between
|
|
|
|
// values i and i+1.
|
|
|
|
aFrom = &aValues[i];
|
|
|
|
aTo = &aValues[i+1];
|
|
|
|
aIntervalProgress = remainingDist / curIntervalDist;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("shouldn't complete loop & get here -- if we do, "
|
2010-01-28 12:50:30 +03:00
|
|
|
"then aSimpleProgress was probably out of bounds");
|
2009-01-15 07:38:07 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-10-03 01:37:25 +04:00
|
|
|
* Computes the total distance to be travelled by a paced animation.
|
2009-01-15 07:38:07 +03:00
|
|
|
*
|
2009-10-03 01:37:25 +04:00
|
|
|
* Returns the total distance, or returns COMPUTE_DISTANCE_ERROR if
|
|
|
|
* our values don't support distance computation.
|
2009-01-15 07:38:07 +03:00
|
|
|
*/
|
|
|
|
double
|
|
|
|
nsSMILAnimationFunction::ComputePacedTotalDistance(
|
|
|
|
const nsSMILValueArray& aValues) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(GetCalcMode() == CALC_PACED,
|
|
|
|
"Calling paced-specific function, but not in paced mode");
|
|
|
|
|
|
|
|
double totalDistance = 0.0;
|
|
|
|
for (PRUint32 i = 0; i < aValues.Length() - 1; i++) {
|
|
|
|
double tmpDist;
|
|
|
|
nsresult rv = aValues[i].ComputeDistance(aValues[i+1], tmpDist);
|
2009-10-03 01:37:25 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2009-01-15 07:38:07 +03:00
|
|
|
return COMPUTE_DISTANCE_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-10-03 01:37:25 +04:00
|
|
|
// Clamp distance value to 0, just in case we have an evil ComputeDistance
|
|
|
|
// implementation somewhere
|
|
|
|
NS_ABORT_IF_FALSE(tmpDist >= 0.0f, "distance values must be non-negative");
|
2009-12-31 02:25:44 +03:00
|
|
|
tmpDist = NS_MAX(tmpDist, 0.0);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
totalDistance += tmpDist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return totalDistance;
|
|
|
|
}
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
double
|
|
|
|
nsSMILAnimationFunction::ScaleSimpleProgress(double aProgress,
|
|
|
|
nsSMILCalcMode aCalcMode)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
if (!HasAttr(nsGkAtoms::keyTimes))
|
2010-09-18 07:46:48 +04:00
|
|
|
return aProgress;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
PRUint32 numTimes = mKeyTimes.Length();
|
|
|
|
|
|
|
|
if (numTimes < 2)
|
2010-09-18 07:46:48 +04:00
|
|
|
return aProgress;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
PRUint32 i = 0;
|
|
|
|
for (; i < numTimes - 2 && aProgress >= mKeyTimes[i+1]; ++i);
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
if (aCalcMode == CALC_DISCRETE) {
|
|
|
|
// discrete calcMode behaviour differs in that each keyTime defines the time
|
|
|
|
// from when the corresponding value is set, and therefore the last value
|
|
|
|
// needn't be 1. So check if we're in the last 'interval', that is, the
|
|
|
|
// space between the final value and 1.0.
|
|
|
|
if (aProgress >= mKeyTimes[i+1]) {
|
|
|
|
NS_ABORT_IF_FALSE(i == numTimes - 2,
|
|
|
|
"aProgress is not in range of the current interval, yet the current"
|
|
|
|
" interval is not the last bounded interval either.");
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return (double)i / numTimes;
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
double& intervalStart = mKeyTimes[i];
|
|
|
|
double& intervalEnd = mKeyTimes[i+1];
|
|
|
|
|
|
|
|
double intervalLength = intervalEnd - intervalStart;
|
2010-09-18 07:46:48 +04:00
|
|
|
if (intervalLength <= 0.0)
|
|
|
|
return intervalStart;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
return (i + (aProgress - intervalStart) / intervalLength) /
|
|
|
|
double(numTimes - 1);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
double
|
|
|
|
nsSMILAnimationFunction::ScaleIntervalProgress(double aProgress,
|
|
|
|
PRUint32 aIntervalIndex)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
if (GetCalcMode() != CALC_SPLINE)
|
2010-09-18 07:46:48 +04:00
|
|
|
return aProgress;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (!HasAttr(nsGkAtoms::keySplines))
|
2010-09-18 07:46:48 +04:00
|
|
|
return aProgress;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
NS_ABORT_IF_FALSE(aIntervalIndex < mKeySplines.Length(),
|
|
|
|
"Invalid interval index");
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
nsSMILKeySpline const &spline = mKeySplines[aIntervalIndex];
|
2010-09-18 07:46:48 +04:00
|
|
|
return spline.GetSplineValue(aProgress);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::HasAttr(nsIAtom* aAttName) const
|
|
|
|
{
|
|
|
|
return mAnimationElement->HasAnimAttr(aAttName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrValue*
|
|
|
|
nsSMILAnimationFunction::GetAttr(nsIAtom* aAttName) const
|
|
|
|
{
|
|
|
|
return mAnimationElement->GetAnimAttr(aAttName);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::GetAttr(nsIAtom* aAttName, nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return mAnimationElement->GetAnimAttr(aAttName, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A utility function to make querying an attribute that corresponds to an
|
|
|
|
* nsSMILValue a little neater.
|
|
|
|
*
|
2010-02-21 00:13:11 +03:00
|
|
|
* @param aAttName The attribute name (in the global namespace).
|
|
|
|
* @param aSMILAttr The SMIL attribute to perform the parsing.
|
|
|
|
* @param[out] aResult The resulting nsSMILValue.
|
2010-06-24 04:30:55 +04:00
|
|
|
* @param[out] aPreventCachingOfSandwich
|
|
|
|
* If |aResult| contains dependencies on its context that
|
|
|
|
* should prevent the result of the animation sandwich from
|
|
|
|
* being cached and reused in future samples (as reported
|
|
|
|
* by nsISMILAttr::ValueFromString), then this outparam
|
|
|
|
* will be set to PR_TRUE. Otherwise it is left unmodified.
|
2009-01-15 07:38:07 +03:00
|
|
|
*
|
|
|
|
* Returns PR_FALSE if a parse error occurred, otherwise returns PR_TRUE.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::ParseAttr(nsIAtom* aAttName,
|
|
|
|
const nsISMILAttr& aSMILAttr,
|
2010-02-21 00:13:11 +03:00
|
|
|
nsSMILValue& aResult,
|
2010-06-24 04:30:55 +04:00
|
|
|
PRBool& aPreventCachingOfSandwich) const
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
nsAutoString attValue;
|
|
|
|
if (GetAttr(aAttName, attValue)) {
|
2010-06-24 04:30:55 +04:00
|
|
|
PRBool preventCachingOfSandwich;
|
2010-02-21 00:13:11 +03:00
|
|
|
nsresult rv = aSMILAttr.ValueFromString(attValue, mAnimationElement,
|
2010-06-24 04:30:55 +04:00
|
|
|
aResult, preventCachingOfSandwich);
|
2009-01-15 07:38:07 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
2010-02-21 00:13:11 +03:00
|
|
|
|
2010-06-24 04:30:55 +04:00
|
|
|
if (preventCachingOfSandwich) {
|
|
|
|
aPreventCachingOfSandwich = PR_TRUE;
|
2010-02-21 00:13:11 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SMILANIM specifies the following rules for animation function values:
|
|
|
|
*
|
|
|
|
* (1) if values is set, it overrides everything
|
|
|
|
* (2) for from/to/by animation at least to or by must be specified, from on its
|
|
|
|
* own (or nothing) is an error--which we will ignore
|
|
|
|
* (3) if both by and to are specified only to will be used, by will be ignored
|
|
|
|
* (4) if by is specified without from (by animation), forces additive behaviour
|
|
|
|
* (5) if to is specified without from (to animation), special care needs to be
|
|
|
|
* taken when compositing animation as such animations are composited last.
|
|
|
|
*
|
|
|
|
* This helper method applies these rules to fill in the values list and to set
|
|
|
|
* some internal state.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::GetValues(const nsISMILAttr& aSMILAttr,
|
|
|
|
nsSMILValueArray& aResult)
|
|
|
|
{
|
|
|
|
if (!mAnimationElement)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-02-21 00:13:11 +03:00
|
|
|
mValueNeedsReparsingEverySample = PR_FALSE;
|
2009-01-15 07:38:07 +03:00
|
|
|
nsSMILValueArray result;
|
|
|
|
|
|
|
|
// If "values" is set, use it
|
|
|
|
if (HasAttr(nsGkAtoms::values)) {
|
|
|
|
nsAutoString attValue;
|
|
|
|
GetAttr(nsGkAtoms::values, attValue);
|
2010-06-24 04:30:55 +04:00
|
|
|
PRBool preventCachingOfSandwich;
|
2009-01-15 07:38:07 +03:00
|
|
|
nsresult rv = nsSMILParserUtils::ParseValues(attValue, mAnimationElement,
|
2010-06-24 04:30:55 +04:00
|
|
|
aSMILAttr, result,
|
|
|
|
preventCachingOfSandwich);
|
2009-01-15 07:38:07 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-06-24 04:30:55 +04:00
|
|
|
if (preventCachingOfSandwich) {
|
2010-02-21 00:13:11 +03:00
|
|
|
mValueNeedsReparsingEverySample = PR_TRUE;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
// Else try to/from/by
|
|
|
|
} else {
|
2010-06-24 04:30:55 +04:00
|
|
|
PRBool preventCachingOfSandwich = PR_FALSE;
|
2009-01-15 07:38:07 +03:00
|
|
|
PRBool parseOk = PR_TRUE;
|
|
|
|
nsSMILValue to, from, by;
|
2010-06-24 04:30:55 +04:00
|
|
|
parseOk &= ParseAttr(nsGkAtoms::to, aSMILAttr, to,
|
|
|
|
preventCachingOfSandwich);
|
|
|
|
parseOk &= ParseAttr(nsGkAtoms::from, aSMILAttr, from,
|
|
|
|
preventCachingOfSandwich);
|
|
|
|
parseOk &= ParseAttr(nsGkAtoms::by, aSMILAttr, by,
|
|
|
|
preventCachingOfSandwich);
|
2010-02-21 00:13:11 +03:00
|
|
|
|
2010-06-24 04:30:55 +04:00
|
|
|
if (preventCachingOfSandwich) {
|
2010-02-21 00:13:11 +03:00
|
|
|
mValueNeedsReparsingEverySample = PR_TRUE;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (!parseOk)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
result.SetCapacity(2);
|
|
|
|
if (!to.IsNull()) {
|
|
|
|
if (!from.IsNull()) {
|
|
|
|
result.AppendElement(from);
|
|
|
|
result.AppendElement(to);
|
|
|
|
} else {
|
|
|
|
result.AppendElement(to);
|
|
|
|
}
|
|
|
|
} else if (!by.IsNull()) {
|
|
|
|
nsSMILValue effectiveFrom(by.mType);
|
|
|
|
if (!from.IsNull())
|
|
|
|
effectiveFrom = from;
|
|
|
|
// Set values to 'from; from + by'
|
|
|
|
result.AppendElement(effectiveFrom);
|
|
|
|
nsSMILValue effectiveTo(effectiveFrom);
|
|
|
|
if (!effectiveTo.IsNull() && NS_SUCCEEDED(effectiveTo.Add(by))) {
|
|
|
|
result.AppendElement(effectiveTo);
|
|
|
|
} else {
|
|
|
|
// Using by-animation with non-additive type or bad base-value
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No values, no to, no by -- call it a day
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.SwapElements(aResult);
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::CheckValueListDependentAttrs(PRUint32 aNumValues)
|
|
|
|
{
|
|
|
|
CheckKeyTimes(aNumValues);
|
|
|
|
CheckKeySplines(aNumValues);
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
/**
|
|
|
|
* Performs checks for the keyTimes attribute required by the SMIL spec but
|
|
|
|
* which depend on other attributes and therefore needs to be updated as
|
|
|
|
* dependent attributes are set.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::CheckKeyTimes(PRUint32 aNumValues)
|
|
|
|
{
|
|
|
|
if (!HasAttr(nsGkAtoms::keyTimes))
|
|
|
|
return;
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
nsSMILCalcMode calcMode = GetCalcMode();
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// attribute is ignored for calcMode = paced
|
2010-09-18 07:46:48 +04:00
|
|
|
if (calcMode == CALC_PACED) {
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeyTimesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
PRUint32 numKeyTimes = mKeyTimes.Length();
|
|
|
|
if (numKeyTimes < 1) {
|
2009-01-15 07:38:07 +03:00
|
|
|
// keyTimes isn't set or failed preliminary checks
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeyTimesErrorFlag(PR_TRUE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no. keyTimes == no. values
|
2010-09-18 07:46:48 +04:00
|
|
|
// For to-animation the number of values is considered to be 2 unless it's
|
|
|
|
// discrete to-animation in which case either 1 or 2 is acceptable.
|
|
|
|
PRBool matchingNumOfValues = IsToAnimation() ?
|
|
|
|
calcMode == CALC_DISCRETE ? numKeyTimes <= 2 : numKeyTimes == 2 :
|
|
|
|
numKeyTimes == aNumValues;
|
|
|
|
if (!matchingNumOfValues) {
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeyTimesErrorFlag(PR_TRUE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
// first value must be 0
|
|
|
|
if (mKeyTimes[0] != 0.0) {
|
|
|
|
SetKeyTimesErrorFlag(PR_TRUE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-18 07:46:48 +04:00
|
|
|
// last value must be 1 for linear or spline calcModes
|
|
|
|
if (calcMode != CALC_DISCRETE && numKeyTimes > 1 &&
|
|
|
|
mKeyTimes[numKeyTimes - 1] != 1.0) {
|
|
|
|
SetKeyTimesErrorFlag(PR_TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeyTimesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::CheckKeySplines(PRUint32 aNumValues)
|
|
|
|
{
|
|
|
|
// attribute is ignored if calc mode is not spline
|
|
|
|
if (GetCalcMode() != CALC_SPLINE) {
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calc mode is spline but the attribute is not set
|
|
|
|
if (!HasAttr(nsGkAtoms::keySplines)) {
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mKeySplines.Length() < 1) {
|
|
|
|
// keyTimes isn't set or failed preliminary checks
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_TRUE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore splines if there's only one value
|
|
|
|
if (aNumValues == 1 && !IsToAnimation()) {
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no. keySpline specs == no. values - 1
|
|
|
|
PRUint32 splineSpecs = mKeySplines.Length();
|
|
|
|
if ((splineSpecs != aNumValues - 1 && !IsToAnimation()) ||
|
|
|
|
(IsToAnimation() && splineSpecs != 1)) {
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_TRUE);
|
2009-01-15 07:38:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2010-12-10 21:33:13 +03:00
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::IsValueFixedForSimpleDuration() const
|
|
|
|
{
|
|
|
|
return mSimpleDuration.IsIndefinite() ||
|
|
|
|
(!mHasChanged && mPrevSampleWasSingleValueAnimation);
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Property getters
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::GetAccumulate() const
|
|
|
|
{
|
|
|
|
const nsAttrValue* value = GetAttr(nsGkAtoms::accumulate);
|
|
|
|
if (!value)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-02-07 18:52:43 +03:00
|
|
|
return value->GetEnumValue();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILAnimationFunction::GetAdditive() const
|
|
|
|
{
|
|
|
|
const nsAttrValue* value = GetAttr(nsGkAtoms::additive);
|
|
|
|
if (!value)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-02-07 18:52:43 +03:00
|
|
|
return value->GetEnumValue();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILAnimationFunction::nsSMILCalcMode
|
|
|
|
nsSMILAnimationFunction::GetCalcMode() const
|
|
|
|
{
|
|
|
|
const nsAttrValue* value = GetAttr(nsGkAtoms::calcMode);
|
|
|
|
if (!value)
|
|
|
|
return CALC_LINEAR;
|
|
|
|
|
|
|
|
return nsSMILCalcMode(value->GetEnumValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Property setters / un-setters:
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::SetAccumulate(const nsAString& aAccumulate,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
mHasChanged = PR_TRUE;
|
2009-07-15 22:33:31 +04:00
|
|
|
PRBool parseResult =
|
2009-01-15 07:38:07 +03:00
|
|
|
aResult.ParseEnumValue(aAccumulate, sAccumulateTable, PR_TRUE);
|
2010-04-29 03:00:53 +04:00
|
|
|
SetAccumulateErrorFlag(!parseResult);
|
2009-01-15 07:38:07 +03:00
|
|
|
return parseResult ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::UnsetAccumulate()
|
|
|
|
{
|
2010-04-29 03:00:53 +04:00
|
|
|
SetAccumulateErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::SetAdditive(const nsAString& aAdditive,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
mHasChanged = PR_TRUE;
|
2009-07-15 22:33:31 +04:00
|
|
|
PRBool parseResult
|
2009-01-15 07:38:07 +03:00
|
|
|
= aResult.ParseEnumValue(aAdditive, sAdditiveTable, PR_TRUE);
|
2010-04-29 03:00:53 +04:00
|
|
|
SetAdditiveErrorFlag(!parseResult);
|
2009-01-15 07:38:07 +03:00
|
|
|
return parseResult ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::UnsetAdditive()
|
|
|
|
{
|
2010-04-29 03:00:53 +04:00
|
|
|
SetAdditiveErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::SetCalcMode(const nsAString& aCalcMode,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
mHasChanged = PR_TRUE;
|
2009-07-15 22:33:31 +04:00
|
|
|
PRBool parseResult
|
2009-01-15 07:38:07 +03:00
|
|
|
= aResult.ParseEnumValue(aCalcMode, sCalcModeTable, PR_TRUE);
|
2010-04-29 03:00:53 +04:00
|
|
|
SetCalcModeErrorFlag(!parseResult);
|
2009-01-15 07:38:07 +03:00
|
|
|
return parseResult ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::UnsetCalcMode()
|
|
|
|
{
|
2010-04-29 03:00:53 +04:00
|
|
|
SetCalcModeErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::SetKeySplines(const nsAString& aKeySplines,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
mKeySplines.Clear();
|
|
|
|
aResult.SetTo(aKeySplines);
|
|
|
|
|
|
|
|
nsTArray<double> keySplines;
|
|
|
|
nsresult rv = nsSMILParserUtils::ParseKeySplines(aKeySplines, keySplines);
|
|
|
|
|
|
|
|
if (keySplines.Length() < 1 || keySplines.Length() % 4)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
mKeySplines.SetCapacity(keySplines.Length() % 4);
|
|
|
|
for (PRUint32 i = 0; i < keySplines.Length() && NS_SUCCEEDED(rv); i += 4)
|
|
|
|
{
|
|
|
|
if (!mKeySplines.AppendElement(nsSMILKeySpline(keySplines[i],
|
|
|
|
keySplines[i+1],
|
|
|
|
keySplines[i+2],
|
|
|
|
keySplines[i+3]))) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::UnsetKeySplines()
|
|
|
|
{
|
|
|
|
mKeySplines.Clear();
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeySplinesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationFunction::SetKeyTimes(const nsAString& aKeyTimes,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
mKeyTimes.Clear();
|
|
|
|
aResult.SetTo(aKeyTimes);
|
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsSMILParserUtils::ParseSemicolonDelimitedProgressList(aKeyTimes, PR_TRUE,
|
|
|
|
mKeyTimes);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && mKeyTimes.Length() < 1)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
mKeyTimes.Clear();
|
|
|
|
|
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationFunction::UnsetKeyTimes()
|
|
|
|
{
|
|
|
|
mKeyTimes.Clear();
|
2010-04-29 03:00:53 +04:00
|
|
|
SetKeyTimesErrorFlag(PR_FALSE);
|
2009-01-15 07:38:07 +03:00
|
|
|
mHasChanged = PR_TRUE;
|
|
|
|
}
|