Index: /cvsroot/mozilla/content/smil/Makefile.in =================================================================== RCS file: /cvsroot/mozilla/content/smil/Makefile.in diff -N content/smil/Makefile.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/Makefile.in 16 Oct 2005 07:36:38 -0000 @@ -0,0 +1,48 @@ +# +# ***** 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 mozilla.org code. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 1999 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# 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 ***** + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public src + +include $(topsrcdir)/config/rules.mk + Index: /cvsroot/mozilla/content/smil/public/Makefile.in =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/Makefile.in diff -N content/smil/public/Makefile.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/Makefile.in 16 Oct 2005 07:36:38 -0000 @@ -0,0 +1,62 @@ +# +# ***** 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 mozilla.org code. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 1998 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# 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 ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = content + +EXPORTS = \ + nsISMILAnimAttr.h \ + nsISMILAnimElement.h \ + nsISMILAnimVal.h \ + nsISMILAnimationController.h \ + nsISMILAnimationFunction.h \ + nsISMILAnimationObserver.h \ + nsISMILAnimationRegistry.h \ + nsISMILComposable.h \ + nsISMILTimeClient.h \ + nsISMILTimeContainer.h \ + nsISMILTimedElement.h \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimAttr.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimAttr.h diff -N content/smil/public/nsISMILAnimAttr.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimAttr.h 16 Oct 2005 07:36:39 -0000 @@ -0,0 +1,104 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMATTR_H__ +#define __NS_ISMILANIMATTR_H__ + +#include "nsISupports.h" + +class nsISMILAnimVal; + +//////////////////////////////////////////////////////////////////////// +// nsISMILAnimAttr: Interfaces for data types that can have a base and animated +// value. + +// {c487920a-7d12-40ff-bf3b-c39dd4797cff} +#define NS_ISMILANIMATTR_IID \ +{ 0xc487920a, 0x7d12, 0x40ff, { 0xbf, 0x3b, 0xc3, 0x9d, 0xd4, 0x79, 0x7c, 0xff } } + +/** + * Interfaces for data types that can have a base and animated value. + * + * This interface is like a stepping stone between nsISMILAnimElement and + * nsISMILAnimVal. It should be possible to do without this interface altogether + * and I think this would produce a simpler design. However, keeping it should + * mean that nsISMILAnimVal can be implemented by a separate lightweight object, + * perhaps even implemented as a tear off from the class implementing + * nsISMILAnimAttr. + */ +class nsISMILAnimAttr : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMATTR_IID) + + /** + * Gets the underlying value of this attribute. It is the same as Create() but + * avoids allocating memory. + * + * @param aValue The value to fill. + * @return NS_OK on success or an error code if getting failed. + */ + virtual nsresult GetBaseValue(nsISMILAnimVal& aValue) = 0; + + /** + * Sets the presentation value of this attribute. + * + * @param aValue The value to set. + * @return NS_OK on success or an error code if setting failed. + */ + virtual nsresult SetAnimValue(const nsISMILAnimVal& aValue) = 0; + + /* + * Factory methods + */ + + /** + * Creates a new nsISMILAnimVal initialized to the base value of this + * attribute. + * + * @return The newly created object or null if creation failed. + */ + virtual nsISMILAnimVal* Create() const = 0; + + /** + * Creates a new nsISMILAnimVal from the given specification. + * + * @param aSpec A string representation that should be parsed to determine + * the value of the newly created object. + * @return The newly created object or null if creation failed. + */ + virtual nsISMILAnimVal* CreateFromSpec(const nsAString& aSpec) const = 0; +}; + +#endif // __NS_ISMILANIMATTR_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimElement.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimElement.h diff -N content/smil/public/nsISMILAnimElement.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimElement.h 16 Oct 2005 07:36:39 -0000 @@ -0,0 +1,74 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMELEMENT__ +#define __NS_ISMILANIMELEMENT__ + +#include "nsISupports.h" +#include "nsISMILAnimAttr.h" + +//////////////////////////////////////////////////////////////////////// +// nsISMILAnimElement: interface of elements that have attributes +// that can be animated. + +// {5DD94E10-FD8D-42FB-B054-8D29F771033A} +#define NS_ISMILANIMELEMENT_IID \ +{ 0x5dd94e10, 0xfd8d, 0x42fb, { 0xb0, 0x54, 0x8d, 0x29, 0xf7, 0x71, 0x03, 0x3a } } + +/** + * Interface for elements that have attributes that can be animated. + * + * This interface is not actually used by the SMIL module. Instead it is used by + * the host language to identify targets for animation. However, in a mixed + * namespace environment this interface might be used by several modules so it + * should probably stay here in SMIL. + */ +class nsISMILAnimElement : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMELEMENT_IID) + + /** + * Gets an animatable attribute identified by namespace and attribute name. + * + * @param aNamespaceID The namespace of the attribute + * @param aName The attribute name + * @return The attribute or NULL if this attribute does not exist or is not + * animatable. + */ + virtual nsISMILAnimAttr* + GetAnimAttribute(PRInt32 aNamespaceID, nsIAtom* aName)=0; +}; + +#endif // __NS_ISMILANIMELEMENT__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimVal.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimVal.h diff -N content/smil/public/nsISMILAnimVal.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimVal.h 16 Oct 2005 07:36:39 -0000 @@ -0,0 +1,127 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMVAL_H__ +#define __NS_ISMILANIMVAL_H__ + +#include "nsISupports.h" + +//////////////////////////////////////////////////////////////////////// +// nsISMILAnimVal + +// {01d2aae5-9de4-4e8f-a1e9-ae660ad27925} +#define NS_ISMILANIMVAL_IID \ +{ 0x01d2aae5, 0x9de4, 0x4e8f, { 0xa1, 0xe9, 0xae, 0x66, 0x0a, 0xd2, 0x79, 0x25 } } + +class nsISMILAnimVal : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMVAL_IID) + + /** + * Calculates the 'distance' between this value and another. This is the + * distance used in paced interpolation. + * + * @param aTo The end of the interval for which the distance should be + * calculated. + * @param aDistance The result of the calculation. + * @return NS_OK on success, or an appropriate code if there is no notion of + * distance for the underlying data type or the distance could not be + * calculated. + */ + virtual nsresult ComputeDistance(const nsISMILAnimVal& aTo, + PRFloat64& aDistance) const = 0; + + /** + * Calculates an interpolates value between this value and the specified end + * value using the specified proportion. + * + * @param aEndVal The value defining the end of the interval of + * interpolation. + * @param aUnitDistance A number between 0.0 and 1.0 (inclusive) defining + * the distance of the interpolated value in the + * interval. + * @param aResult The interpolated value. + * @result NS_OK on success, NS_ERROR_FAILURE if this data type cannot be + * interpolated or NS_ERROR_OUT_OF_MEMORY if insufficient memory was + * available for storing the result. + */ + virtual nsresult Interpolate(const nsISMILAnimVal& aEndVal, + float aUnitDistance, + nsISMILAnimVal& aResult) = 0; + + /** + * Add the given value to this value. This method facilitates additive and + * cumulative animation. + * + * This method will fail (return false) if the underlying datatype is not + * additive or was not specified using an additive syntax. + * + * See SVG 1.1, section 19.2.5. In particular, + * + * "If a given attribute or property can take values of keywords (which are + * not additive) or numeric values (which are additive), then additive + * animations are possible if the subsequent animation uses a numeric value + * even if the base animation uses a keyword value; however, if the subsequent + * animation uses a keyword value, additive animation is not possible." + * + * @param aAddedVal The value to add to this value. + * @return NS_OK on success, an error code on failure. + */ + virtual nsresult Add(const nsISMILAnimVal& aAddedVal) = 0; + + /** + * Assign this object the value of another. Think of this as the assignment + * operator. + * + * @param aNewVal The value to set. + * @return NS_OK on success, an error code on failure such as when the + * underlying type of the specified object differs. + */ + virtual nsresult Set(const nsISMILAnimVal& aNewVal) = 0; + + /** + * Repeats this value or the specified value a number of times. This method + * will fail (return false) if the underlying data type is not additive. + * + * @param aCount The number of times to repeat the value. + * @param aRepeatValue The value to repeat. If this parameter is null the + * current value will be repeated. + * @return NS_OK on success, an error code on failure. + */ + virtual nsresult Repeat(PRUint32 aCount, + const nsISMILAnimVal* aRepeatValue = nsnull) = 0; +}; + +#endif // __NS_ISMILANIMVAL_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimationController.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimationController.h diff -N content/smil/public/nsISMILAnimationController.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimationController.h 16 Oct 2005 07:36:39 -0000 @@ -0,0 +1,71 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMATIONCONTROLLER_H__ +#define __NS_ISMILANIMATIONCONTROLLER_H__ + +#include "nsIAnimationController.h" + +#define NS_ISMILANIMATIONCONTROLLER_IID \ +{ 0xd2c81398, 0x1f30, 0x4303, { 0xbe, 0xbe, 0xc5, 0x0c, 0x01, 0xfd, 0xd8, 0x85 } } + +class nsISMILTimeContainer; +class nsIDocument; + +//////////////////////////////////////////////////////////////////////// +// nsISMILAnimationController: Animation controller + +class nsISMILAnimationController : public nsIAnimationController +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMATIONCONTROLLER_IID) + + // nsIAnimationController methods + virtual nsresult Pause()=0; + virtual nsresult Resume()=0; + virtual nsresult Reset()=0; + + // + // Eventually, this will probably be all nsISMILTimedElements so that it is + // possible to have hierarchies of containers (which will implement + // nsISMILTimedElement), and then these methods will be replaced with + // SetRootElement. + // + virtual nsresult AddTimeContainer(nsISMILTimeContainer* aContainer)=0; + virtual nsresult RemoveTimeContainer(nsISMILTimeContainer* aContainer)=0; +}; + +nsISMILAnimationController* NS_NewSMILAnimationController(nsIDocument *doc); + +#endif // __NS_ISMILANIMATIONCONTROLLER_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimationFunction.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimationFunction.h diff -N content/smil/public/nsISMILAnimationFunction.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimationFunction.h 16 Oct 2005 07:36:40 -0000 @@ -0,0 +1,103 @@ + +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMFUNCTION_H__ +#define __NS_ISMILANIMFUNCTION_H__ + +#include "nsISupports.h" + +class nsISMILAnimAttr; + +// {14eb1aab-e4ba-4c77-be89-195ef975c90d} +#define NS_ISMILANIMFUNCTION_IID \ +{ 0x14eb1aab, 0xe4ba, 0x4c77, { 0xbe, 0x89, 0x19, 0x5e, 0xf9, 0x75, 0xc9, 0x0d } } + +/** + * Provides the animation function for an interpolating animation element. This + * includes the animation-related attributes. It is intended to be used by + * elements such as , and so on. + * + * It will likely be split into nsISMILInterpolatingAnimFunc and + * nsISMILSimpleAnimFunc when is introduced. Extra parameters or perhaps + * a subclass will probably be needed to support , + * and the like. + */ +class nsISMILAnimationFunction : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMFUNCTION_IID) + + virtual nsresult SetTargetAttribute(nsISMILAnimAttr* aAttribute)=0; + virtual nsISMILAnimAttr* GetTargetAttribute()=0; + virtual void SetDocumentPosition(PRUint16 aDocPosition)=0; + + /* + * Property setters + */ + virtual nsresult SetAccumulate(const nsAString& aAccumulate)=0; + virtual nsresult SetAdditive(const nsAString& aAdditive)=0; + virtual nsresult SetBy(const nsAString& aBy)=0; + virtual nsresult SetCalcMode(const nsAString& aCalcMode)=0; + virtual nsresult SetFrom(const nsAString& aFrom)=0; + virtual nsresult SetKeyTimes(const nsAString& aKeyTimes)=0; + virtual nsresult SetKeySplines(const nsAString& aKeySplines)=0; + virtual nsresult SetTo(const nsAString& aTo)=0; + virtual nsresult SetValues(const nsAString& aValues)=0; + + /* + * Property unsetters + * + * Unsetters are used instead of simply passing an empty string to the setters + * as in some cases an empty string is an error whereas not specifying an + * attribute is not. + * + * Unsetters are used in preference to setting a default value so that this + * object is responsible for supplying default values and not all the + * different animation elements that use it. + */ + virtual void UnsetAdditive()=0; + virtual void UnsetBy()=0; + virtual void UnsetCalcMode()=0; + virtual void UnsetAccumulate()=0; + virtual void UnsetFrom()=0; + virtual void UnsetKeyTimes()=0; + virtual void UnsetKeySplines()=0; + virtual void UnsetTo()=0; + virtual void UnsetValues()=0; +}; + +nsISMILAnimationFunction* NS_NewSMILAnimationFunction(); + +#endif //__NS_ISMILANIMFUNCTION_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimationObserver.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimationObserver.h diff -N content/smil/public/nsISMILAnimationObserver.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimationObserver.h 16 Oct 2005 07:36:40 -0000 @@ -0,0 +1,59 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMATIONOBSERVER_H__ +#define __NS_ISMILANIMATIONOBSERVER_H__ + +#include "nsISupports.h" +#include "nsWeakReference.h" + +#define NS_ISMILANIMATIONOBSERVER_IID \ +{ 0x8f96dd0c, 0x9c70, 0x4b3a, { 0xa0, 0x72, 0xce, 0x71, 0x0f, 0x47, 0xa0, 0x06 } } + +//////////////////////////////////////////////////////////////////////// +// nsISMILAnimationObserver: Interfaces for clients that want to be informed of +// stages in the animation's life cycle + +class nsISMILAnimationObserver : public nsSupportsWeakReference +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMATIONOBSERVER_IID) + + virtual void StartSample()=0; + virtual void StartCompositing()=0; + virtual void EndCompositing()=0; + virtual void EndSample()=0; +}; + +#endif // __NS_ISMILANIMATIONOBSERVER_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILAnimationRegistry.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILAnimationRegistry.h diff -N content/smil/public/nsISMILAnimationRegistry.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILAnimationRegistry.h 16 Oct 2005 07:36:40 -0000 @@ -0,0 +1,151 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILANIMATIONREGISTRY_H__ +#define __NS_ISMILANIMATIONREGISTRY_H__ + +#include "nsISupports.h" + +class nsISMILAnimationController; +class nsISMILAnimationObserver; +class nsISMILComposable; +class nsISMILAnimAttr; +class nsISMILTimedElement; + +#define NS_ISMILANIMATIONREGISTRY_IID \ +{ 0xdd3c7124, 0xcc1f, 0x447b, { 0xa1, 0x35, 0x4a, 0xd8, 0xfc, 0xd4, 0x9f, 0x31 } } + +//////////////////////////////////////////////////////////////////////// +// nsISMILAnimationRegistry: Entry point for SMIL animated documents + +class nsISMILAnimationRegistry : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILANIMATIONREGISTRY_IID) + + /** + * Sets the animation controller which is needed for registering the time + * container managed by this registry. + * + * @param aController The animation controller. May be NULL to disassociate + * this registry from any controller. + */ + virtual nsresult SetController(nsISMILAnimationController* aController)=0; + + /** + * Sets the object which will receive notifications when samples begin and end + * and when compositing takes place. Currently only one observer can be set at + * a time. + * + * @param aObserver The observer to receive notifications. May be null to + * remove the currently set observer if any. + */ + virtual void SetObserver(nsISMILAnimationObserver* aObserver)=0; + + /* + * The next five methods correspond to methods in the nsIDOMSVGSVGElement + * interface. + */ + + /** + * Starts animation. After creating the registry this method needs to be + * called before animation starts. This allows more precise control over when + * the animation starts allowing the registry to be created and set up but + * only started when the conditions are right. + */ + virtual nsresult Start()=0; + + /** + * Pauses animation. + */ + virtual void Pause()=0; + + /** + * Unpauses animation. + */ + virtual void Unpause()=0; + + /** + * @return true if the animation is in a paused state. + */ + virtual PRBool IsPaused()=0; + + /** + * Returns the current time in seconds relative to the start time of the + * animation. + */ + virtual float GetCurrentTime()=0; + + /** + * Adjusts the clock for the animation to the specified time. + * + * @param aSeconds The new current time in seconds relative to the start time + * for this animation. + */ + virtual nsresult SetCurrentTime(float aSeconds)=0; + + /** + * Registers a composable object with the compositor for the specified target + * attribute. The composable object may be registered with several target + * attributes and each target attribute may have several composable objects + * associated with it. + */ + virtual nsresult RegisterComposable(nsISMILAnimAttr* aTargetAttr, + nsISMILComposable* aComposable)=0; + + /** + * Removes the specified composable object from all compositors with which is + * it registered. + */ + virtual nsresult UnregisterComposable(nsISMILComposable* aComposable)=0; + + /** + * Registers the timed element with the time container managed by this + * registry. + */ + virtual nsresult RegisterTimedElement(nsISMILTimedElement* aElement)=0; + + /** + * Unregisters the timed element from the time container managed by this + * registry. + */ + virtual nsresult UnregisterTimedElement(nsISMILTimedElement* aElement)=0; +}; + +/** + * Creates a new animation registry object. + */ +nsISMILAnimationRegistry* NS_NewSMILAnimationRegistry(); + +#endif // __NS_ISMILANIMATIONREGISTRY_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILComposable.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILComposable.h diff -N content/smil/public/nsISMILComposable.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILComposable.h 16 Oct 2005 07:36:41 -0000 @@ -0,0 +1,141 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILCOMPOSABLE_H__ +#define __NS_ISMILCOMPOSABLE_H__ + +#include "nsISupports.h" +#include "nsWeakReference.h" + +class nsISMILAnimVal; + +//////////////////////////////////////////////////////////////////////// +// nsISMILComposable : Interface for animations that can be composited +// by the compositor + +// {4b05aa22-712e-4a9e-8452-f7c4b2e507e7} +#define NS_ISMILCOMPOSABLE_IID \ +{ 0x4b05aa22, 0x712e, 0x4a9e, { 0x84, 0x52, 0xf7, 0xc4, 0xb2, 0xe5, 0x07, 0xe7 } } + +class nsISMILComposable : public nsSupportsWeakReference +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILCOMPOSABLE_IID) + + /** + * Combines the result of this animation function for the last sample with the + * specified value. + * + * @param aResult The value to compose with. + */ + virtual void ComposeResult(nsISMILAnimVal &aResult)=0; + + /** + * Returns the relative priority of this animation to another. The priority is + * used for determining the position of the animation in the animation + * sandwich. + * + * @return -1 if this animation has lower priority or 1 if this animation has + * higher priority + * + * This method should never return 0. + */ + virtual PRInt8 CompareTo(const nsISMILComposable& composable) const=0; + + /* + * The following three methods are used in sorting. + */ + + /** + * Indicates if this animation is a 'to animation'. Such animations appear + * 'higher' in the animation sandwich than all other animations. + * + * @return True if this animation is a to animation, false otherwise. + */ + virtual PRBool IsToAnimation() const=0; + + /** + * Returns the begin time of this animation for the interval it is currently + * animating. For inactive animations this will be LL_MinInt but such + * animations should be filtered from compositing anyway. + * + * @return A 64-bit integer representing the begin time of this animation. + */ + virtual const PRInt64& GetBeginTime() const=0; + + /** + * Returns a unique (0-based) index indicating the position of this animation + * in the document. The first animation will have index 0 as so on. Positions + * are recalculated when the document structure is changed. + * + * @return An unsigned integer representing this animation's position in the + * document. + */ + virtual PRUint16 GetDocumentPosition() const=0; + + /* + * The following methods are provided so that the compositor can optimise its + * operations by only composing those animation that will affect the final + * result. + */ + + /** + * Indicates if the animation is currently active. Inactive animations will + * not contribute to the composed result. + * + * @return True if the animation active, false otherwise. + */ + virtual PRBool IsActive() const=0; + + /** + * Indicates if this animation will replace the passed in result rather than + * adding to it. Animations that replace the underlying value may be called + * without first calling lower priority animations. + * + * @return True if the animation will replace, false if it will add or + * otherwise build on the passed in value. + */ + virtual PRBool WillReplace() const=0; + + /** + * Indicates if the parameters for this animation have changed since the last + * time it was composited. This allows rendering to be performed only when + * necessary, particularly when no animations are active. + * + * @return True if the animation parameters have changed, false otherwise. + */ + virtual PRBool HasChanged() const=0; +}; + +#endif // __NS_ISMILCOMPOSABLE_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILTimeClient.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILTimeClient.h diff -N content/smil/public/nsISMILTimeClient.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILTimeClient.h 16 Oct 2005 07:36:41 -0000 @@ -0,0 +1,102 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILTIMECLIENT_H__ +#define __NS_ISMILTIMECLIENT_H__ + +#include "nsISupports.h" + +class nsSMILTimeValue; + +//////////////////////////////////////////////////////////////////////// +// nsISMILTimeClient + +// {196f66f4-e6f6-420b-a337-da42a2efccde} +#define NS_ISMILTIMECLIENT_IID \ +{ 0x196f66f4, 0xe6f6, 0x420b, { 0xa3, 0x37, 0xda, 0x42, 0xa2, 0xef, 0xcc, 0xde } } + +class nsISMILTimeClient : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILTIMECLIENT_IID) + + /** + * Indicate a new sample has occurred. + * + * @param aSimpleTime The sample time for this timed element expressed in + * simple time. + * @param aSimpleDuration The simple duration for this timed element. + * @param aRepeatIteration The repeat iteration for this sample. The first + * iteration has a value of 0. + */ + virtual void SampleAt(const PRInt64& aSimpleTime, + const nsSMILTimeValue& aSimpleDuration, + const PRUint32& aRepeatIteration)=0; + + /** + * Indicate to sample using the last value defined for the animation function. + * This value is not normally sampled due to the end-point exclusive timing + * model but only occurs when the fill mode is "freeze" and the active + * duration is an even multiple of the simple duration. + * + * @param aRepeatIteration The repeat iteration for this sample. The first + * iteration has a value of 0. + */ + virtual void SampleLastValue(const PRUint32& aRepeatIteration)=0; + + /** + * Indicate that the timed element is now active. This is used, for example, + * to instruct the animation function that it should now add its result to the + * animation sandwich. The begin time is also provided for proper + * prioritisation of animation functions and for this reason this method must + * be called before either of the Sample methods. + * + * @param aBeginTime The begin time for the newly active interval. + */ + virtual void ToActive(const PRInt64& aBeginTime)=0; + + /** + * Indicate that the timed element is no longer active. This is used, for + * example, to instruct the animation function that it should no longer add + * its result to the animation sandwich. + * + * @param aIsFrozen True if this animation should continue to contribute to + * the animation sandwich using the most recent sample + * parameters even though these parameters are unlikely to + * change between samples. + */ + virtual void ToInactive(PRBool aIsFrozen)=0; +}; + +#endif // __NS_ISMILTIMECLIENT_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILTimeContainer.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILTimeContainer.h diff -N content/smil/public/nsISMILTimeContainer.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILTimeContainer.h 16 Oct 2005 07:36:41 -0000 @@ -0,0 +1,124 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILTIMECONTAINER_H__ +#define __NS_ISMILTIMECONTAINER_H__ + +#include "nsISupports.h" +#include "nsISMILTimedElement.h" + +//////////////////////////////////////////////////////////////////////// +// nsISMILTimeContainer: Time container + +// {46b51a7b-d857-45f1-9c7d-4d0d12719238} +#define NS_ISMILTIMECONTAINER_IID \ +{ 0x46b51a7b, 0xd857, 0x45f1, { 0x9c, 0x7d, 0x4d, 0x0d, 0x12, 0x71, 0x92, 0x38 } } + +/** + * A SMIL time container. + * + * When implementing SMIL 2.0 time containers, this interface will most likely + * inherit from nsISMILTimedElement, amongst other changes + */ +class nsISMILTimeContainer : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILTIMECONTAINER_IID) + + /** + * Pause the time container. The time container is initially unpaused. + */ + virtual nsresult Pause()=0; + + /** + * Resume the time container. + */ + virtual nsresult Resume()=0; + + /** + * Returns the paused state of the time container independently of the paused + * state of the container's parent. + */ + virtual PRBool IsPaused()=0; + + /** + * Inform the time container that its parent has been paused. + * + * Currently this is necessary so that the time container will accumulate + * pause offsets correctly as these are not maintained by the parent. + * + * Re-using Pause() and maintaining pause counts can lead to unwanted + * behaviour when calls to pause and resume are unbalanced. + */ + virtual nsresult ParentPaused()=0; + + /** + * Inform the time container that its parent has been resumed. + */ + virtual nsresult ParentResumed()=0; + + /** + * Reset the time container's internal state. This is particularly useful when + * a cached time container is to be re-used. + */ + virtual nsresult Reset()=0; + + /** + * We may later change this to SampleAt and maintain separate host document + * and document fragment times. This would allow more advanced time + * manipulations for documents with several animated SVG document fragments. + */ + virtual void Sample()=0; + + /** + * Add a timed element to this container. No attempt is made to check if the + * timed element is already a child of this container--in that case the timed + * element will be added twice and will be sampled twice. + * + * @param aElement The element to add. + * @return NS_OK if the element was successfully added or an error otherwise. + */ + virtual nsresult AddTimedElement(nsISMILTimedElement* aElement)=0; + + /** + * Remove the specified timed element from this container. + * + * @param aElement The element to remove. + * @return NS_OK if the element is found and successfully removed or an error + * otherwise. + */ + virtual nsresult RemoveTimedElement(nsISMILTimedElement* aElement)=0; +}; + +#endif // __NS_ISMILTIMECONTAINER_H__ + Index: /cvsroot/mozilla/content/smil/public/nsISMILTimedElement.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/public/nsISMILTimedElement.h diff -N content/smil/public/nsISMILTimedElement.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/public/nsISMILTimedElement.h 16 Oct 2005 07:36:42 -0000 @@ -0,0 +1,143 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_ISMILTIMEDELEMENT_H__ +#define __NS_ISMILTIMEDELEMENT_H__ + +#include "nsWeakReference.h" + +class nsISMILTimeClient; +class nsSMILTimeValue; +class nsSMILInstanceTime; + +//////////////////////////////////////////////////////////////////////// +// nsISMILTimedElement + +// {c5f60446-5c1a-4f3b-8ce3-646199ac97f2} +#define NS_ISMILTIMEDELEMENT_IID \ +{ 0xc5f60446, 0x5c1a, 0x4f3b, { 0x8c, 0xe3, 0x64, 0x61, 0x99, 0xac, 0x97, 0xf2 } } + +class nsISMILTimedElement : public nsSupportsWeakReference +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISMILTIMEDELEMENT_IID) + + /** + * Adds an instance time object this this element's list of instance times. + * These instance times are used when creating intervals. + * + * This method is typically called by an nsSMILTimeValueSpec to register an + * instance time corresponding its specification. + * + * @param aInstanceTime The time to add. + * + * @param aIsBegin True if the time to be added represents a begin time + * or false if it represents an end time. + */ + virtual void AddInstanceTime(nsSMILInstanceTime* aInstanceTime, + PRBool aIsBegin)=0; + + /** + * Sets the object that will be called by this timed element each time it is + * sampled. + * + * In Schmitz's model it is possible to associate several time clients with + * a timed element but for now we only allow one. + * + * @param aClient The time client to associate. Any previous time client + * will be disassociated and no longer sampled. Setting this + * to NULL will simply disassociate the previous client, if + * any. + */ + virtual void SetTimeClient(nsISMILTimeClient* aClient)=0; + + /** + * Samples the object at the given document time. Timing intervals are updated + * and if this element is active at the given time the associated time client + * will be sampled with the appropriate simple time. + * + * @param aDocumentTime The document time at which to sample. + */ + virtual void SampleAt(const PRInt64& aDocumentTime)=0; + + /** + * Reset the element's internal state. This is useful for repeating time + * containers and so that the timing model can be cached. + * + * @param aHardReset Perform a hard reset such that all instance times are + * cleared. For a soft reset only instance times created by + * DOM calls and events are cleared. A hard reset is needed + * in the case of a cached timing model whilst for + * repeating only a soft reset is required. + */ + virtual void Reset(PRBool aHardReset = PR_FALSE)=0; + + /* + * Property setters + */ + virtual nsresult SetBeginSpec(const nsAString& aBeginSpec)=0; + virtual nsresult SetEndSpec(const nsAString& aEndSpec)=0; + virtual nsresult SetSimpleDuration(const nsAString& aDurSpec)=0; + virtual nsresult SetMin(const nsAString& aMinSpec)=0; + virtual nsresult SetMax(const nsAString& aMaxSpec)=0; + virtual nsresult SetRestart(const nsAString& aRestartSpec)=0; + virtual nsresult SetRepeatCount(const nsAString& aRepeatCountSpec)=0; + virtual nsresult SetRepeatDur(const nsAString& aRepeatDurSpec)=0; + virtual nsresult SetFillMode(const nsAString& aFillModeSpec)=0; + + /* + * Property unsetters + * + * Unsetters are used instead of simply passing an empty string to the setters + * as in some cases an empty string is an error whereas not specifying an + * attribute is not. + * + * Unsetters are used in preference to setting a default value so that this + * object is responsible for supplying default values and not all the + * different animation elements that use it. + */ + virtual void UnsetBeginSpec()=0; + virtual void UnsetEndSpec()=0; + virtual void UnsetSimpleDuration()=0; + virtual void UnsetMin()=0; + virtual void UnsetMax()=0; + virtual void UnsetRestart()=0; + virtual void UnsetRepeatCount()=0; + virtual void UnsetRepeatDur()=0; + virtual void UnsetFillMode()=0; +}; + +nsISMILTimedElement* NS_NewSMILTimedElement(); + +#endif // __NS_ISMILTIMEDELEMENT_H__ + Index: /cvsroot/mozilla/content/smil/src/Makefile.in =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/Makefile.in diff -N content/smil/src/Makefile.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/Makefile.in 16 Oct 2005 07:36:42 -0000 @@ -0,0 +1,89 @@ +# +# ***** 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 mozilla.org code. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 1998 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# 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 ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = content +LIBRARY_NAME = gkconsmil_s +LIBXUL_LIBRARY = 1 + +REQUIRES = xpcom \ + string \ + layout \ + content \ + unicharutil \ + widget \ + dom \ + $(NULL) + +CPPSRCS = \ + nsSMILAnimationController.cpp \ + nsSMILAnimationFunction.cpp \ + nsSMILAnimationRegistry.cpp \ + nsSMILAtoms.cpp \ + nsSMILCompositor.cpp \ + nsSMILEnum.cpp \ + nsSMILInstanceTime.cpp \ + nsSMILInterval.cpp \ + nsSMILTimedDocumentRoot.cpp \ + nsSMILTimedElement.cpp \ + nsSMILTimeValue.cpp \ + nsSMILTimeValueSpec.cpp \ + $(NULL) + +include $(topsrcdir)/config/config.mk + +# we don't want the shared lib, but we want to force the creation of a static lib. +FORCE_STATIC_LIB = 1 + +include $(topsrcdir)/config/rules.mk + +DEFINES += -D_IMPL_NS_LAYOUT + Index: /cvsroot/mozilla/content/smil/src/nsSMILAnimationController.cpp =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAnimationController.cpp diff -N content/smil/src/nsSMILAnimationController.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAnimationController.cpp 16 Oct 2005 07:36:43 -0000 @@ -0,0 +1,417 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 "nsISMILAnimationController.h" +#include "nsComponentManagerUtils.h" +#include "nsWeakReference.h" +#include "nsITimer.h" +#include "nsISMILTimeContainer.h" +#include "nsCOMArray.h" +#include "nsISimpleEnumerator.h" +#include "nsArrayEnumerator.h" +#include "nsAutoLock.h" +#include "nsIDocument.h" +#include "nsIDOMEventReceiver.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMPageTransitionListener.h" + +class nsSMILAnimationController : public nsISMILAnimationController, + public nsIDOMPageTransitionListener, + public nsSupportsWeakReference +{ +public: + nsSMILAnimationController(); + ~nsSMILAnimationController(); + + NS_DECL_ISUPPORTS + + // nsISMILAnimationController + virtual nsresult Pause(); + virtual nsresult Resume(); + virtual nsresult Reset(); + virtual nsresult AddTimeContainer(nsISMILTimeContainer* aContainer); + virtual nsresult RemoveTimeContainer(nsISMILTimeContainer* aContainer); + + // nsIDOMPageTransitionListener, + NS_IMETHOD HandleEvent(nsIDOMEvent *event); + NS_IMETHOD PageShow(nsIDOMEvent *event); + NS_IMETHOD PageHide(nsIDOMEvent *event); + +protected: + friend nsISMILAnimationController* + NS_NewSMILAnimationController(nsIDocument* doc); + + // nsISMILAnimationController + nsresult Init(nsIDocument* doc); + nsresult StartTimer(); + nsresult StopTimer(); + void SampleChildren(); + static void Notify(nsITimer* aTimer, void* aClosure); + + nsCOMPtr mTimer; + nsCOMArray mTimeContainers; + PRLock* mAnimationLock; + PRUint16 mPauseCount; + PRBool mHidden; +}; + +//////////////////////////////////////////////////////////////////////// +// nsSMILAnimationController implementation + +//---------------------------------------------------------------------- +// ctors, dtors, factory methods + +nsSMILAnimationController::nsSMILAnimationController() + : mPauseCount(0), + mHidden(PR_FALSE) +{ +} + +nsSMILAnimationController::~nsSMILAnimationController() +{ + if (mAnimationLock) + PR_Lock(mAnimationLock); + + if (mTimer) { + mTimer->Cancel(); + mTimer = nsnull; + } + + if (mAnimationLock) { + PR_Unlock(mAnimationLock); + PR_DestroyLock(mAnimationLock); + } +} + +nsISMILAnimationController* NS_NewSMILAnimationController(nsIDocument* doc) +{ + nsSMILAnimationController* animationController = + new nsSMILAnimationController(); + NS_ENSURE_TRUE(animationController, nsnull); + + nsresult rv = animationController->Init(doc); + if (NS_FAILED(rv)) { + delete animationController; + animationController = nsnull; + } + + return animationController; +} + +//---------------------------------------------------------------------- +// nsISupports methods: + +NS_IMPL_ISUPPORTS5(nsSMILAnimationController, + nsISMILAnimationController, + nsIAnimationController, + nsIDOMEventListener, + nsIDOMPageTransitionListener, + nsISupportsWeakReference); + +//---------------------------------------------------------------------- +// Timer callback + +// +// We use the function callback rather than implementing nsITimerCallback to +// avoid circular ownership between the timer and this object. +// + +/*static*/ void +nsSMILAnimationController::Notify(nsITimer* timer, void* aClosure) +{ + nsSMILAnimationController* controller = (nsSMILAnimationController*)aClosure; + + NS_ASSERTION(controller->mTimer == timer, + "nsSMILAnimationController::Notify called with incorrect timer"); + + controller->SampleChildren(); +} + +//---------------------------------------------------------------------- +// nsISMILAnimationController methods: + +nsresult +nsSMILAnimationController::Pause() +{ + nsAutoLock lock(mAnimationLock); + + if (++mPauseCount > 1) + return NS_OK; + + nsresult rv = NS_OK; + + rv = StopTimer(); + + // We must tell the children too so they can keep their accumulated offsets + // accurate + PRUint32 i = mTimeContainers.Count(); + while (i > 0) { + --i; + nsCOMPtr + container( do_QueryReferent(mTimeContainers[i]) ); + + // This mess means that we continue processing all the children even if an + // error occurs but that we report the first error encountered + if (container) { + if (NS_SUCCEEDED(rv)) + rv = container->ParentPaused(); + else + container->ParentPaused(); + } else { + mTimeContainers.RemoveObjectAt(i); + } + } + + return rv; +} + +nsresult +nsSMILAnimationController::Resume() +{ + nsAutoLock lock(mAnimationLock); + + nsresult rv = NS_OK; + + NS_ASSERTION(mPauseCount > 0, "Unbalanced calls to Pause() and Resume()"); + if (mPauseCount == 0) + return NS_ERROR_FAILURE; + + if (--mPauseCount > 0) + return NS_OK; + + // We must tell the children so they can keep their accumulated offsets + // accurate + PRUint32 i = mTimeContainers.Count(); + while (i > 0) { + --i; + nsCOMPtr + container( do_QueryReferent(mTimeContainers[i]) ); + + if (container) { + if (NS_SUCCEEDED(rv)) + rv = container->ParentResumed(); + else + container->ParentResumed(); + } else { + mTimeContainers.RemoveObjectAt(i); + } + } + + if (mTimeContainers.Count() > 0) + StartTimer(); + + return rv; +} + +nsresult +nsSMILAnimationController::Reset() +{ + nsresult rv = NS_OK; + + nsAutoLock lock(mAnimationLock); + + PRUint32 i = mTimeContainers.Count(); + while (i > 0) { + --i; + nsCOMPtr + container( do_QueryReferent(mTimeContainers[i]) ); + + if (container) { + if (NS_SUCCEEDED(rv)) + rv = container->Reset(); + else + container->Reset(); + } else { + mTimeContainers.RemoveObjectAt(i); + } + } + + return rv; +} + +nsresult +nsSMILAnimationController::AddTimeContainer(nsISMILTimeContainer* aContainer) +{ + NS_ENSURE_ARG_POINTER(aContainer); + + nsresult rv; + nsCOMPtr weakRef( + getter_AddRefs(do_GetWeakReference(aContainer, &rv)) ); + NS_ENSURE_SUCCESS(rv,rv); + + { + nsAutoLock lock(mAnimationLock); + rv = (mTimeContainers.AppendObject(weakRef)) ? NS_OK : NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv,rv); + + if (mPauseCount > 0) { + aContainer->ParentPaused(); + } else if (mTimeContainers.Count() == 1) { + rv = StartTimer(); + } + } + + return rv; +} + +nsresult +nsSMILAnimationController::RemoveTimeContainer(nsISMILTimeContainer* aContainer) +{ + NS_ENSURE_ARG_POINTER(aContainer); + + nsresult rv; + nsCOMPtr weakRef( + getter_AddRefs(do_GetWeakReference(aContainer, &rv)) ); + + { + nsAutoLock lock(mAnimationLock); + if (NS_SUCCEEDED(rv)) + rv = (mTimeContainers.RemoveObject(weakRef)) ? NS_OK : NS_ERROR_FAILURE; + + if (NS_SUCCEEDED(rv) && mPauseCount == 0 && mTimeContainers.Count() == 0) + rv = StopTimer(); + } + + return rv; +} + +//---------------------------------------------------------------------- +// nsIDOMPageTransitionListener methods + +nsresult +nsSMILAnimationController::HandleEvent(nsIDOMEvent * /*event*/) +{ + return NS_OK; +} + +nsresult +nsSMILAnimationController::PageShow(nsIDOMEvent * /*event*/) +{ + if (!mHidden) + return NS_OK; + + mHidden = PR_FALSE; + + nsresult rv = Reset(); + NS_ENSURE_SUCCESS(rv,rv); + + return Resume(); +} + +nsresult +nsSMILAnimationController::PageHide(nsIDOMEvent * /*event*/) +{ + mHidden = PR_TRUE; + return Pause(); +} + +//---------------------------------------------------------------------- +// Implementation helpers: + +nsresult +nsSMILAnimationController::Init(nsIDocument *doc) +{ + mTimer = do_CreateInstance("@mozilla.org/timer;1"); + mAnimationLock = PR_NewLock(); + + // SMIL should be able to be used from a wide variety of contexts so in the + // following we fail silently. It is only necessary to support the bfcache. + if (doc) { + nsCOMPtr global(doc->GetScriptGlobalObject()); + if (global) { + nsCOMPtr receiver( do_QueryInterface(global) ); + if (receiver) { + receiver->AddEventListener(NS_LITERAL_STRING("pageshow"), this, + PR_FALSE); + receiver->AddEventListener(NS_LITERAL_STRING("pagehide"), this, + PR_FALSE); + } + } + } + + return (mTimer && mAnimationLock) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; +} + +nsresult +nsSMILAnimationController::StartTimer() +{ + NS_ENSURE_TRUE(mTimer, NS_ERROR_FAILURE); + NS_ASSERTION(mPauseCount == 0, "Starting timer but controller is paused."); + + // Run the first sample manually + SampleChildren(); + + // XXXbb Remove magic number, make timer self-tuning + return mTimer->InitWithFuncCallback(nsSMILAnimationController::Notify, + this, + 28, + nsITimer::TYPE_REPEATING_PRECISE); +} + +nsresult +nsSMILAnimationController::StopTimer() +{ + NS_ENSURE_TRUE(mTimer, NS_ERROR_FAILURE); + + return mTimer->Cancel(); +} + +void +nsSMILAnimationController::SampleChildren() +{ + // Creating a new enumerator each sample provides thread-safety but I'm not + // sure what the cost is + + if (mPauseCount > 0) + return; + + nsCOMPtr enumerator; + nsresult rv = + NS_NewArrayEnumerator(getter_AddRefs(enumerator), mTimeContainers); + NS_ENSURE_SUCCESS(rv,); + + PRBool more = PR_FALSE; + nsCOMPtr container; + nsCOMPtr weakRef; + + while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) { + if (NS_FAILED(enumerator->GetNext(getter_AddRefs(weakRef))) || !weakRef) + break; + + container = do_QueryReferent(weakRef); + + if (container) + container->Sample(); + } +} + Index: /cvsroot/mozilla/content/smil/src/nsSMILAnimationFunction.cpp =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAnimationFunction.cpp diff -N content/smil/src/nsSMILAnimationFunction.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAnimationFunction.cpp 16 Oct 2005 07:36:44 -0000 @@ -0,0 +1,865 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 "nsISMILAnimationFunction.h" +#include "nsISMILComposable.h" +#include "nsISMILTimeClient.h" +#include "nsSMILTimeValue.h" +#include "nsISMILAnimVal.h" +#include "nsISMILAnimAttr.h" +#include "nsSMILEnum.h" +#include "nsSMILAtoms.h" +#include "nsCOMPtr.h" +#include "nsCOMArray.h" +#include "nsReadableUtils.h" +#include "nsString.h" +#include "nsCRT.h" +#include "nsAutoLock.h" +#include + +// XXXbb remove +#include "nsITimelineService.h" + +//---------------------------------------------------------------------- +// nsSMILAnimationFunction + +class nsSMILAnimationFunction : public nsISMILAnimationFunction, + public nsISMILComposable, + public nsISMILTimeClient +{ +public: + nsSMILAnimationFunction(); + ~nsSMILAnimationFunction(); + + NS_DECL_ISUPPORTS + + // nsISMILAnimationFunction + virtual nsresult SetTargetAttribute(nsISMILAnimAttr* aAttribute); + virtual nsISMILAnimAttr* GetTargetAttribute(); + virtual void SetDocumentPosition(PRUint16 aDocPosition); + + virtual nsresult SetAccumulate(const nsAString& aAccumulate); + virtual nsresult SetAdditive(const nsAString& aAdditive); + virtual nsresult SetBy(const nsAString& aBy); + virtual nsresult SetCalcMode(const nsAString& aCalcMode); + virtual nsresult SetFrom(const nsAString& aFrom); + virtual nsresult SetKeyTimes(const nsAString& aKeyTimes); + virtual nsresult SetKeySplines(const nsAString& aKeySplines); + virtual nsresult SetTo(const nsAString& aTo); + virtual nsresult SetValues(const nsAString& aValues); + + virtual void UnsetAdditive(); + virtual void UnsetBy(); + virtual void UnsetCalcMode(); + virtual void UnsetAccumulate(); + virtual void UnsetFrom(); + virtual void UnsetKeyTimes(); + virtual void UnsetKeySplines(); + virtual void UnsetTo(); + virtual void UnsetValues(); + + // nsISMILTimeClient methods + virtual void SampleAt(const PRInt64& aSimpleTime, + const nsSMILTimeValue& aSimpleDuration, + const PRUint32& aRepeatIteration); + virtual void SampleLastValue(const PRUint32& aRepeatIteration); + virtual void ToActive(const PRInt64& aBeginTime); + virtual void ToInactive(PRBool aIsFrozen); + + // nsISMILComposable methods + virtual void ComposeResult(nsISMILAnimVal &aResult); + virtual PRInt8 CompareTo(const nsISMILComposable& composable) const; + virtual PRBool IsToAnimation() const; + virtual const PRInt64& GetBeginTime() const; + virtual PRUint16 GetDocumentPosition() const; + virtual PRBool IsActive() const; + virtual PRBool WillReplace() const; + virtual PRBool HasChanged() const; + +protected: + // Implementation helpers + nsISMILAnimationFunction* NS_NewSMILAnimationFunction(); + virtual void FillValuesArray(); + virtual PRBool IsAdditive() const; + + // Members + + /** + * The attribute being targeted. This is needed for parsing animation function + * values and creating temporary objects. + */ + nsCOMPtr mAttribute; + + // + // Animation function values. + // + nsCOMPtr mFrom; + nsCOMPtr mTo; + nsCOMPtr mBy; + nsCOMArray mValues; + + // + // When the values attribute isn't set explicitly, the mValues array is filled + // with an equivalent set of values based on the from, to and by attributes. + // This flag indicates if the values array is filled with values from an + // actual values attribute (in which case it is true) or if it has been filled + // with the values of from, to and by (in which case it is false). + // + PRBool mValuesIsSet; + + enum nsSMILCalcMode + { + calc_linear, + calc_discrete, + calc_paced, + calc_spline + }; + static nsSMILEnumMapping sCalcModeMap[]; + nsSMILEnum mCalcMode; + + static nsSMILEnumMapping sAdditiveMap[]; + nsSMILEnum mAdditive; + + PRBool mIsActive; + PRBool mIsFrozen; + + // + // These are the parameters provided by the previous sample. Currently we + // perform lazy calculation. That is, we only calculate the result if and when + // instructed by the compositor. This allows us to apply the result directly + // to the animation value and allows the compositor to filter out functions + // that it determines will not contribute to the final result. + // + PRInt64 mSimpleTime; + nsSMILTimeValue mSimpleDuration; + PRUint32 mRepeatIteration; + PRBool mLastValue; + PRBool mHasChanged; + + PRInt64 mBeginTime; + PRUint16 mDocumentPosition; + + // + // This is for the very specific case where we have a 'to' animation that is + // frozen part way through the simple duration and there are other active + // lower-priority animations targetting the same attribute. In this case + // SMILANIM 3.3.6 says: + // + // The value for F(t) when a to-animation is frozen (at the end of the + // simple duration) is just the to value. If a to-animation is frozen + // anywhere within the simple duration (e.g., using a repeatCount of "2.5"), + // the value for F(t) when the animation is frozen is the value computed for + // the end of the active duration. Even if other, lower priority animations + // are active while a to-animation is frozen, the value for F(t) does not + // change. + // + // To implement properly this we'd need to force a resample of all the lower + // priority animations at the active end of this animation--something which + // would introduce unwanted coupling between the timing and animation model. + // Instead we just save the value calculated when this animation is frozen (in + // which case this animation will be sampled at the active end and the lower + // priority animations should be sampled at a time pretty close to this, + // provided we have a reasonable frame rate). + // + // @see + // http://www.w3.org/TR/2001/REC-smil-animation-20010904/#FromToByAndAdditive + // + nsCOMPtr mFrozenValue; + + PRLock* mCompositingLock; +}; + +//---------------------------------------------------------------------- +// Static members + +nsSMILEnumMapping nsSMILAnimationFunction::sCalcModeMap[] = { + {&nsSMILAtoms::linear, calc_linear}, + {&nsSMILAtoms::discrete, calc_discrete}, + {&nsSMILAtoms::paced, calc_paced}, + {&nsSMILAtoms::spline, calc_spline}, + {nsnull, 0} +}; + +nsSMILEnumMapping nsSMILAnimationFunction::sAdditiveMap[] = { + {&nsSMILAtoms::replace, PR_FALSE}, + {&nsSMILAtoms::sum, PR_TRUE}, + {nsnull, 0} +}; + +//---------------------------------------------------------------------- +// Constructors etc. + +nsSMILAnimationFunction::nsSMILAnimationFunction() + : mValuesIsSet(PR_FALSE), + mCalcMode(calc_linear, sCalcModeMap), + mAdditive(PR_FALSE, sAdditiveMap), + mIsActive(PR_FALSE), + mIsFrozen(PR_FALSE), + mSimpleTime(-1), + mRepeatIteration(0), + mLastValue(PR_FALSE), + mHasChanged(PR_TRUE), + mBeginTime(LL_MinInt()), + mDocumentPosition(PR_UINT16_MAX) +{ + mCompositingLock = PR_NewLock(); +} + +nsSMILAnimationFunction::~nsSMILAnimationFunction() +{ + // Wait for the lock in case we're in the middle of compositing + if (mCompositingLock) { + PR_Lock(mCompositingLock); + PR_Unlock(mCompositingLock); + PR_DestroyLock(mCompositingLock); + } +} + +nsISMILAnimationFunction* +NS_NewSMILAnimationFunction() +{ + return new nsSMILAnimationFunction(); +} + +//---------------------------------------------------------------------- +// nsISupports methods: + +NS_IMPL_ISUPPORTS4(nsSMILAnimationFunction, + nsISMILAnimationFunction, + nsISMILComposable, + nsISMILTimeClient, + nsISupportsWeakReference) + +//---------------------------------------------------------------------- +// nsISMILAnimationFunction methods: + +nsresult +nsSMILAnimationFunction::SetTargetAttribute(nsISMILAnimAttr* aAttribute) +{ + nsAutoLock lock(mCompositingLock); + mAttribute = aAttribute; + mValues.Clear(); + mValuesIsSet = PR_FALSE; + mFrom = nsnull; + mTo = nsnull; + mBy = nsnull; + mHasChanged = PR_TRUE; + + return NS_OK; +} + +nsISMILAnimAttr* +nsSMILAnimationFunction::GetTargetAttribute() +{ + return mAttribute; +} + +void +nsSMILAnimationFunction::SetDocumentPosition(PRUint16 aDocPosition) +{ + mDocumentPosition = aDocPosition; + mHasChanged = PR_TRUE; +} + +nsresult +nsSMILAnimationFunction::SetAdditive(const nsAString& aAdditive) +{ + mHasChanged = PR_TRUE; + return mAdditive.SetStringValue(aAdditive); +} + +void +nsSMILAnimationFunction::UnsetAdditive() +{ + mAdditive.SetIntegerValue((PRUint16)PR_FALSE); + mHasChanged = PR_TRUE; +} + +nsresult +nsSMILAnimationFunction::SetBy(const nsAString& aBy) +{ + NS_ENSURE_TRUE(mAttribute, NS_ERROR_FAILURE); + + nsAutoLock lock(mCompositingLock); + mBy = mAttribute->CreateFromSpec(aBy); + if (!mBy) + return NS_ERROR_FAILURE; + + FillValuesArray(); + mHasChanged = PR_TRUE; + + return NS_OK; +} + +void +nsSMILAnimationFunction::UnsetBy() +{ + nsAutoLock lock(mCompositingLock); + mBy = nsnull; + FillValuesArray(); + mHasChanged = PR_TRUE; +} + +nsresult +nsSMILAnimationFunction::SetCalcMode(const nsAString& aCalcMode) +{ + // XXXbb + (void)aCalcMode; + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::SetCalcMode"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +void +nsSMILAnimationFunction::UnsetCalcMode() +{ + // XXXbb + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::UnsetCalcMode"); +} + +nsresult +nsSMILAnimationFunction::SetAccumulate(const nsAString& aAccumulate) +{ + // XXXbb + (void)aAccumulate; + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::SetAccumulate"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +void +nsSMILAnimationFunction::UnsetAccumulate() +{ + // XXXbb + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::UnsetAccumulate"); +} + + +nsresult +nsSMILAnimationFunction::SetFrom(const nsAString& aFrom) +{ + NS_ENSURE_TRUE(mAttribute, NS_ERROR_FAILURE); + + nsAutoLock lock(mCompositingLock); + mFrom = mAttribute->CreateFromSpec(aFrom); + if (!mFrom) + return NS_ERROR_FAILURE; + + FillValuesArray(); + mHasChanged = PR_TRUE; + + return NS_OK; +} + +void +nsSMILAnimationFunction::UnsetFrom() +{ + nsAutoLock lock(mCompositingLock); + mFrom = nsnull; + FillValuesArray(); + mHasChanged = PR_TRUE; +} + +nsresult +nsSMILAnimationFunction::SetKeySplines(const nsAString& aKeySplines) +{ + // XXXbb + (void)aKeySplines; + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::SetKeySplines"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +void +nsSMILAnimationFunction::UnsetKeySplines() +{ + // XXXbb + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::UnsetKeySplines"); +} + +nsresult +nsSMILAnimationFunction::SetKeyTimes(const nsAString& aKeyTimes) +{ + // XXXbb + (void)aKeyTimes; + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::SetKeyTimes"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +void +nsSMILAnimationFunction::UnsetKeyTimes() +{ + // XXXbb + NS_NOTYETIMPLEMENTED("nsSMILAnimationFunction::UnsetKeyTimes"); +} + +nsresult +nsSMILAnimationFunction::SetTo(const nsAString& aTo) +{ + NS_ENSURE_TRUE(mAttribute, NS_ERROR_FAILURE); + + nsAutoLock lock(mCompositingLock); + mTo = mAttribute->CreateFromSpec(aTo); + if (!mTo) + return NS_ERROR_FAILURE; + + FillValuesArray(); + mHasChanged = PR_TRUE; + + return NS_OK; +} + +void +nsSMILAnimationFunction::UnsetTo() +{ + nsAutoLock lock(mCompositingLock); + mTo = nsnull; + FillValuesArray(); + mHasChanged = PR_TRUE; +} + +nsresult +nsSMILAnimationFunction::SetValues(const nsAString& aValues) +{ + NS_ENSURE_TRUE(mAttribute, NS_ERROR_FAILURE); + + nsresult rv = NS_ERROR_FAILURE; + nsAString::const_iterator start; + nsAString::const_iterator end; + nsAString::const_iterator substr_end; + nsAString::const_iterator next; + + aValues.BeginReading(start); + aValues.EndReading(end); + + nsAutoLock lock(mCompositingLock); + mValues.Clear(); + mValuesIsSet = PR_FALSE; + + while (start != end) { + rv = NS_ERROR_FAILURE; + + while (*start && NS_IS_SPACE(*start)) + ++start; + + if (*start == '\0' || *start == ';') + break; + + substr_end = start; + + while (substr_end != end && *substr_end != ';') + ++substr_end; + + next = substr_end; + if (*substr_end == ';') { + ++next; + if (next == end) + break; + } + + do --substr_end; while (start != substr_end && NS_IS_SPACE(*substr_end)); + ++substr_end; + + nsCOMPtr newValue ( + mAttribute->CreateFromSpec(Substring(start, substr_end))); + + if (!newValue) + break; + + mValues.AppendObject(newValue); + + rv = NS_OK; + start = next; + } + + if (NS_SUCCEEDED(rv)) + mValuesIsSet = PR_TRUE; + else + mValues.Clear(); + + mHasChanged = PR_TRUE; + + return rv; +} + +void +nsSMILAnimationFunction::UnsetValues() +{ + nsAutoLock lock(mCompositingLock); + mValuesIsSet = PR_FALSE; + FillValuesArray(); + mHasChanged = PR_TRUE; +} + +//---------------------------------------------------------------------- +// nsISMILTimeClient methods + +void +nsSMILAnimationFunction::SampleAt(const PRInt64& aSimpleTime, + const nsSMILTimeValue& aSimpleDuration, + const PRUint32& aRepeatIteration) +{ + if (mHasChanged || mLastValue || LL_NE(mSimpleTime, aSimpleTime) || + mSimpleDuration.CompareTo(aSimpleDuration) || + mRepeatIteration != aRepeatIteration) + mHasChanged = PR_TRUE; + + mSimpleTime = aSimpleTime; + mSimpleDuration = aSimpleDuration; + mRepeatIteration = aRepeatIteration; + mLastValue = PR_FALSE; +} + +void +nsSMILAnimationFunction::SampleLastValue(const PRUint32& aRepeatIteration) +{ + if (mHasChanged || !mLastValue || mRepeatIteration != aRepeatIteration) + mHasChanged = PR_TRUE; + + mRepeatIteration = aRepeatIteration; + mLastValue = PR_TRUE; +} + +void +nsSMILAnimationFunction::ToActive(const PRInt64& aBeginTime) +{ + mBeginTime = aBeginTime; + mIsActive = PR_TRUE; + mIsFrozen = PR_FALSE; + mFrozenValue = nsnull; +} + +void +nsSMILAnimationFunction::ToInactive(PRBool aIsFrozen) +{ + mIsActive = PR_FALSE; + mIsFrozen = aIsFrozen; + mFrozenValue = nsnull; +} + +//---------------------------------------------------------------------- +// nsISMILComposable methods + +void +nsSMILAnimationFunction::ComposeResult(nsISMILAnimVal &aResult) +{ + NS_TIMELINE_START_TIMER("nsSMILAnimationFunction::ComposeResult"); + + // This checks if mValues is empty so we don't need to check it again + if (!IsActive()) { + NS_TIMELINE_STOP_TIMER("nsSMILAnimationFunction::ComposeResult"); + return; + } + + nsAutoLock lock(mCompositingLock); + + if (!mAttribute) { + NS_TIMELINE_STOP_TIMER("nsSMILAnimationFunction::ComposeResult"); + return; + } + + NS_ENSURE_TRUE(mSimpleTime >= 0,); + NS_ENSURE_TRUE(mSimpleDuration.IsResolved() || + mSimpleDuration.IsIndefinite(), ); + + nsCOMPtr result(mAttribute->Create()); + NS_ENSURE_TRUE(result,); + + if (mSimpleDuration.IsIndefinite() || + (mValuesIsSet && mValues.Count() == 1)) { + nsISMILAnimVal* firstValue = mValues.SafeObjectAt(0); + NS_ENSURE_TRUE(firstValue,); + NS_ENSURE_SUCCESS(result->Set(*firstValue),); + } else if (mLastValue) { + nsISMILAnimVal* lastValue = mValues.SafeObjectAt(mValues.Count() - 1); + NS_ENSURE_TRUE(lastValue,); + // if accumulate == sum + // result->Repeat(mRepeatIteration + 1, lastValue); + // else + NS_ENSURE_SUCCESS(result->Set(*lastValue),); + } else if (mFrozenValue && !mHasChanged) { + NS_ENSURE_SUCCESS(result->Set(*mFrozenValue),); + } else { + const PRInt64& dur = mSimpleDuration.GetMillis(); + + if (LL_CMP(mSimpleTime, >=, dur) || !LL_GE_ZERO(mSimpleTime)) { + NS_ERROR("Animation sampled outside interval."); + return; + } + + double fTime; + double fDur; + double simpleDistance; + double intervalDistance; + PRInt32 index; + nsISMILAnimVal* from = nsnull; + nsISMILAnimVal* to = nsnull; + + LL_L2D(fTime, mSimpleTime); + LL_L2D(fDur, dur); + + NS_ASSERTION(mValues.Count() >= 2 || IsToAnimation(), + "Unexpected number of values."); + + simpleDistance = (fDur > 0.0) ? fTime / fDur : 0.0; + + if (IsToAnimation()) { + from = &aResult; + to = mValues.SafeObjectAt(0); + NS_ENSURE_TRUE(to,); + intervalDistance = simpleDistance; + } else { + index = (PRInt32) floor(simpleDistance * (mValues.Count() - 1)); + + from = mValues.SafeObjectAt(index); + NS_ENSURE_TRUE(from,); + + to = mValues.SafeObjectAt(index + 1); + NS_ENSURE_TRUE(to,); + + intervalDistance = simpleDistance * (mValues.Count() - 1) - index; + } + + nsresult rv = from->Interpolate(*to, + NS_STATIC_CAST(float, intervalDistance), + *result); + NS_ENSURE_SUCCESS(rv,); + + if (IsToAnimation() && mIsFrozen) { + mFrozenValue = mAttribute->Create(); + NS_ENSURE_TRUE(mFrozenValue,); + NS_ENSURE_SUCCESS(mFrozenValue->Set(*result),); + } + } + + // + // If additive animation isn't required or fails, just set the value. + // + if (!IsAdditive() || NS_FAILED(aResult.Add(*result))) + aResult.Set(*result); + + mHasChanged = PR_FALSE; + NS_TIMELINE_STOP_TIMER("nsSMILAnimationFunction::ComposeResult"); +} + +PRInt8 +nsSMILAnimationFunction::CompareTo(const nsISMILComposable& composable) const +{ + // + // Inactive animations sort first + // + if (!IsActive() && composable.IsActive()) + return -1; + + if (IsActive() && !composable.IsActive()) + return 1; + + // + // Sort based on begin time + // + if (LL_NE(mBeginTime, composable.GetBeginTime())) + return LL_CMP(mBeginTime, >, composable.GetBeginTime()) ? 1 : -1; + + // XXX When syncbase timing is implemented, we next need to sort based on + // dependencies + + // + // Animations that appear later in the document sort after those earlier in + // the document + // + NS_ASSERTION(mDocumentPosition != composable.GetDocumentPosition(), + "Two animations cannot have the same document position!"); + + return (mDocumentPosition > composable.GetDocumentPosition()) + ? 1 + : (mDocumentPosition == composable.GetDocumentPosition()) ? 0 : -1; +} + +PRBool +nsSMILAnimationFunction::IsToAnimation() const +{ + return (!mValuesIsSet && mTo && !mFrom); +} + +const PRInt64& +nsSMILAnimationFunction::GetBeginTime() const +{ + return mBeginTime; +} + +PRUint16 +nsSMILAnimationFunction::GetDocumentPosition() const +{ + return mDocumentPosition; +} + +PRBool +nsSMILAnimationFunction::IsActive() const +{ + // + // Even if an animation should be active, if its attributes are set + // incorrectly, it will have no effect and should be considered by the + // compositor to be inactive. + // + // Frozen animations should be considered active for the purposes of + // compositing. + // + return ((mIsActive || mIsFrozen) && mValues.Count() > 0); +} + + +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. + */ + return !(IsAdditive() || IsToAnimation()) || + (IsToAnimation() && mIsFrozen && !mHasChanged); +} + +PRBool +nsSMILAnimationFunction::HasChanged() const +{ + return mHasChanged; +} + +// XXX What we need is HasChanged. In SampleAt and SampleLastValue (what about +// ToActive and ToInactive()? -- I think not) we compare the values and set +// a flag to true if it's changed. We never set it to false in that method even +// if nothing's changed. If the flag was true when we entered the method it +// stays true--in fact we could save comparing in that case, e.g. +// +// if (mHasChanged || (mSimpleTime != aSimpleTime) || .... +// mHasChanged = PR_TRUE; +// +// Then after compositing we set it to false. +// +// That way the flag indicates if the parameters have changed since the last +// composite. +// +// In the compositor we do a first pass and if none of the composables for +// attribute have changed we don't composite. Alternatively we always composite +// and accumulate a bool indicating if any of them have changed and then if none +// have we just don't set the anim value. I think the first method will be more +// efficient as the HasChanged method will simply return a member variable. +// +// This hasChanged member could be re-used later for optimising by storing the +// last result if it wasn't additive. +// +// We can also use it in WillReplace. The condition would be something like +// +// WillReplace = (!IsAdditive && !IsToAnimation) || (IsToAnimation && mIsFrozen +// && !mHasChanged) +// +// likewise in the compositing loop we should only use the frozen value if +// mHasChanged is false, otherwise we should re-composite anyway---this sort of +// situation might arise when seeking backwards and although we may get the +// right quite wrong, it won't be _as_ wrong as if we just used the frozen value + +//---------------------------------------------------------------------- +// Implementation helpers + +/* + * 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. + */ +void +nsSMILAnimationFunction::FillValuesArray() +{ + if (!mValuesIsSet) { + mValues.Clear(); + + if (mTo) { + if (mFrom) { + mValues.AppendObject(mFrom); + mValues.AppendObject(mTo); + } else { + mValues.AppendObject(mTo); + } + } else if (mBy) { + if (mFrom) { + // + // Set values to 'from; from + to' + // + mValues.AppendObject(mFrom); + nsCOMPtr to (mAttribute->Create()); + if (to && + NS_SUCCEEDED(to->Set(*mFrom)) && + NS_SUCCEEDED(to->Add(*mBy))) { + mValues.AppendObject(to); + } else { + mValues.Clear(); + } + } else { + // + // Set values to '0; by' + // + nsCOMPtr from (mAttribute->Create()); + if (from) { + mValues.AppendObject(from); + mValues.AppendObject(mBy); + } else { + mValues.Clear(); + } + } + } + // else, do nothing, mValues has been cleared already. + } +} + +inline PRBool +nsSMILAnimationFunction::IsAdditive() const +{ + /* + * Animation is additive if: + * + * (1) additive = "sum" (mAdditive == true), or + * (2) it is 'by animation' (by is set, from and values are not) + * + * Although animation is not additive if it is 'to animation' + */ + return (!IsToAnimation() && + (mAdditive.GetIntegerValue() || (!mValuesIsSet && mBy && !mFrom))); +} + Index: /cvsroot/mozilla/content/smil/src/nsSMILAnimationRegistry.cpp =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAnimationRegistry.cpp diff -N content/smil/src/nsSMILAnimationRegistry.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAnimationRegistry.cpp 16 Oct 2005 07:36:45 -0000 @@ -0,0 +1,338 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 "nsSMILAnimationRegistry.h" +#include "nsISMILAnimationObserver.h" +#include "nsISMILAnimAttr.h" +#include "nsISMILComposable.h" +#include "nsSMILTimedDocumentRoot.h" +#include "nsSMILCompositor.h" +#include "nsAutoLock.h" + +// XXXbb Remove +#include "nsITimelineService.h" + +//////////////////////////////////////////////////////////////////////// +// nsSMILAnimationRegistry implementation + +struct CompositorEntry +{ + nsISMILAnimAttr* key; + nsSMILCompositor compositor; +}; + +//---------------------------------------------------------------------- +// ctors, dtors, factory methods + +nsSMILAnimationRegistry::~nsSMILAnimationRegistry() +{ + if (mController && mTimedDocumentRoot) + mController->RemoveTimeContainer(mTimedDocumentRoot); + + CompositorEntry* entry; + PRInt32 count = mCompositors.Count(); + + PR_Lock(mAnimationLock); + + for (PRInt32 i = 0; i < count; ++i) { + entry = NS_STATIC_CAST(CompositorEntry*, mCompositors[i]); + mCompositors.ReplaceElementAt(nsnull, i); + delete entry; + } + + mCompositors.Clear(); + + PR_Unlock(mAnimationLock); + PR_DestroyLock(mAnimationLock); +} + +nsISMILAnimationRegistry* +NS_NewSMILAnimationRegistry() +{ + nsSMILAnimationRegistry* animationRegistry = new nsSMILAnimationRegistry(); + + if (!animationRegistry) + return nsnull; + + nsresult rv = animationRegistry->Init(); + if (NS_FAILED(rv)) { + delete animationRegistry; + animationRegistry = nsnull; + } + + return animationRegistry; +} + +nsresult +nsSMILAnimationRegistry::Init() +{ + mTimedDocumentRoot = new nsSMILTimedDocumentRoot(this); + NS_ENSURE_TRUE(mTimedDocumentRoot, NS_ERROR_OUT_OF_MEMORY); + + mTimedDocumentRoot->Pause(); + + mAnimationLock = PR_NewLock(); + NS_ENSURE_TRUE(mAnimationLock, NS_ERROR_OUT_OF_MEMORY); + + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports methods: + +NS_IMPL_ISUPPORTS1(nsSMILAnimationRegistry, + nsISMILAnimationRegistry); + +//---------------------------------------------------------------------- +// nsISMILAnimationRegistry methods: + +nsresult +nsSMILAnimationRegistry::SetController(nsISMILAnimationController* aController) +{ + nsresult rv = NS_OK; + + NS_ENSURE_TRUE(mTimedDocumentRoot, NS_ERROR_FAILURE); + + if (mController) { + rv = mController->RemoveTimeContainer(mTimedDocumentRoot); + NS_ENSURE_SUCCESS(rv,rv); + } + + mController = aController; + + if (mController) + rv = mController->AddTimeContainer(mTimedDocumentRoot); + + return rv; +} + +void +nsSMILAnimationRegistry::SetObserver(nsISMILAnimationObserver* aObserver) +{ + if (aObserver) { + mObserver = do_GetWeakReference(aObserver); + } else { + mObserver = nsnull; + } +} + +nsresult +nsSMILAnimationRegistry::Start() +{ + NS_ENSURE_TRUE(mTimedDocumentRoot,NS_ERROR_FAILURE); + if (!mStarted) { + mTimedDocumentRoot->Resume(); + mStarted = PR_TRUE; + } +} + +void +nsSMILAnimationRegistry::Pause() +{ + NS_ENSURE_TRUE(mTimedDocumentRoot,); + NS_ENSURE_TRUE(mStarted,); + mTimedDocumentRoot->Pause(); +} + +void +nsSMILAnimationRegistry::Unpause() +{ + NS_ENSURE_TRUE(mTimedDocumentRoot,); + NS_ENSURE_TRUE(mStarted,); + mTimedDocumentRoot->Resume(); +} + +PRBool +nsSMILAnimationRegistry::IsPaused() +{ + if (!mStarted) + return PR_TRUE; + + NS_ENSURE_TRUE(mTimedDocumentRoot,PR_FALSE); + + return mTimedDocumentRoot->IsPaused(); +} + +float +nsSMILAnimationRegistry::GetCurrentTime() +{ + // XXXbb + NS_NOTYETIMPLEMENTED("nsSMILAnimationRegistry::GetCurrentTime"); + return 0.0f; +} + +nsresult +nsSMILAnimationRegistry::SetCurrentTime(float aSeconds) +{ + // XXXbb + (void)aSeconds; + NS_NOTYETIMPLEMENTED("nsSMILAnimationRegistry::SetCurrentTime"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult +nsSMILAnimationRegistry::RegisterComposable(nsISMILAnimAttr* aTargetAttr, + nsISMILComposable* aComposable) +{ + NS_ENSURE_ARG_POINTER(aTargetAttr); + NS_ENSURE_ARG_POINTER(aComposable); + + nsSMILCompositor* compositor = nsnull; + CompositorEntry* entry; + + nsAutoLock lock(mAnimationLock); + + // + // Iterate in reverse as if a compositor already exists for this attribute it + // is most likely to be the most recently added entry. + // + for (PRInt32 i = mCompositors.Count() - 1; i >= 0 && !compositor; --i) { + entry = (CompositorEntry*)mCompositors[i]; + if (entry && entry->key == aTargetAttr) + compositor = &entry->compositor; + } + + if (!compositor) { + entry = new CompositorEntry(); + NS_ENSURE_TRUE(entry,NS_ERROR_OUT_OF_MEMORY); + + nsresult rv = entry->compositor.Init(aTargetAttr); + NS_ENSURE_SUCCESS(rv,rv); + + entry->key = aTargetAttr; + if (!mCompositors.AppendElement(entry)) { + delete entry; + return NS_ERROR_FAILURE; + } + + compositor = &entry->compositor; + } + + return compositor->AddComposable(aComposable); +} + +nsresult +nsSMILAnimationRegistry::UnregisterComposable(nsISMILComposable* aComposable) +{ + NS_ENSURE_ARG_POINTER(aComposable); + + PRBool found = PR_FALSE; + nsresult result = NS_OK; + nsresult rv = NS_ERROR_FAILURE; + CompositorEntry* entry; + PRInt32 count = mCompositors.Count(); + + nsAutoLock lock(mAnimationLock); + + for (PRInt32 i = 0; i < count; ++i) { + entry = (CompositorEntry*)mCompositors[i]; + if (entry) { + rv = entry->compositor.RemoveComposable(aComposable); + + // This rather complicated error handling just ensures that we report the + // first error that occurs, or a generic error if the item wasn't found. + if (NS_SUCCEEDED(result)) + result = rv; + found = PR_TRUE; + } + + // Even if the entry now no longer has any compositors we don't bother + // deleting it as it may be re-used again later. + } + + return (found) ? rv : NS_ERROR_FAILURE; +} + +nsresult +nsSMILAnimationRegistry::RegisterTimedElement(nsISMILTimedElement *aElement) +{ + return (mTimedDocumentRoot) ? mTimedDocumentRoot->AddTimedElement(aElement) + : NS_ERROR_FAILURE; +} + +nsresult +nsSMILAnimationRegistry::UnregisterTimedElement(nsISMILTimedElement *aElement) +{ + return (mTimedDocumentRoot) ? mTimedDocumentRoot->RemoveTimedElement(aElement) + : NS_ERROR_FAILURE; +} + +void +nsSMILAnimationRegistry::StartSample() +{ + if (mObserver) { + nsCOMPtr observer = do_QueryReferent(mObserver); + if (observer) + observer->StartSample(); + } + + // Do any pre-animation actions here, e.g. acquiring locks, blocking scripts + // etc. +} + +void +nsSMILAnimationRegistry::EndSample() +{ + NS_TIMELINE_START_TIMER("nsSMILAnimationRegistry::EndSample"); + CompositorEntry* entry; + PRInt32 count = mCompositors.Count(); + nsCOMPtr observer; + + if (mObserver) + observer = do_QueryReferent(mObserver); + + if (observer) + observer->StartCompositing(); + + PR_Lock(mAnimationLock); + + for (PRInt32 i = 0; i < count; ++i) { + entry = NS_STATIC_CAST(CompositorEntry*, mCompositors[i]); + if (entry) + entry->compositor.ComposeSample(); + } + + PR_Unlock(mAnimationLock); + + NS_TIMELINE_START_TIMER("nsSVGSVGElement::EndCompositing"); + if (observer) + observer->EndCompositing(); + NS_TIMELINE_STOP_TIMER("nsSVGSVGElement::EndCompositing"); + + // Release any locks etc. + + if (observer) + observer->EndSample(); + NS_TIMELINE_STOP_TIMER("nsSMILAnimationRegistry::EndSample"); +} + Index: /cvsroot/mozilla/content/smil/src/nsSMILAnimationRegistry.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAnimationRegistry.h diff -N content/smil/src/nsSMILAnimationRegistry.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAnimationRegistry.h 16 Oct 2005 07:36:45 -0000 @@ -0,0 +1,92 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_SMILANIMATIONREGISTRY_H__ +#define __NS_SMILANIMATIONREGISTRY_H__ + +#include "nsISMILAnimationRegistry.h" +#include "nsISMILAnimationController.h" +#include "nsVoidArray.h" +#include "nsAutoPtr.h" +#include "nsWeakPtr.h" + +class nsSMILTimedDocumentRoot; + +class nsSMILAnimationRegistry : public nsISMILAnimationRegistry +{ +public: + ~nsSMILAnimationRegistry(); + + NS_DECL_ISUPPORTS + + virtual void StartSample(); + virtual void EndSample(); + + // nsISMILAnimationRegistry + virtual nsresult SetController(nsISMILAnimationController* aController); + virtual void SetObserver(nsISMILAnimationObserver* aObserver); + virtual nsresult Start(); + virtual void Pause(); + virtual void Unpause(); + virtual PRBool IsPaused(); + virtual float GetCurrentTime(); + virtual nsresult SetCurrentTime(float aSeconds); + virtual nsresult RegisterComposable(nsISMILAnimAttr *aTargetAttr, + nsISMILComposable *aComposable); + virtual nsresult UnregisterComposable(nsISMILComposable *aComposable); + virtual nsresult RegisterTimedElement(nsISMILTimedElement *aElement); + virtual nsresult UnregisterTimedElement(nsISMILTimedElement *aElement); + +protected: + friend nsISMILAnimationRegistry* NS_NewSMILAnimationRegistry(); + + nsresult Init(); + + nsVoidArray mCompositors; + nsRefPtr mTimedDocumentRoot; + nsCOMPtr mController; + nsWeakPtr mObserver; + PRBool mStarted; + PRLock* mAnimationLock; + +private: + // This class should only be created by the factory method + nsSMILAnimationRegistry() : mStarted(PR_FALSE) {} + + // Pass by value and assignment should not be used + nsSMILAnimationRegistry(const nsSMILAnimationRegistry& other); + nsSMILAnimationRegistry& operator=(const nsSMILAnimationRegistry& right); +}; + +#endif // __NS_SMILANIMATIONREGISTRY_H__ + Index: /cvsroot/mozilla/content/smil/src/nsSMILAtomList.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAtomList.h diff -N content/smil/src/nsSMILAtomList.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAtomList.h 16 Oct 2005 07:36:46 -0000 @@ -0,0 +1,70 @@ +/* -*- 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1999 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 ***** */ + +/****** + + This file contains the list of all SMIL nsIAtoms and their values + + It is designed to be used as inline input to nsSMILAtoms.cpp *only* + through the magic of C preprocessing. + + All entires must be enclosed in the macro SMIL_ATOM which will have cruel + and unusual things done to it + + It is recommended (but not strictly necessary) to keep all entries + in alphabetical order + + The first argument to SMIL_ATOM is the C++ identifier of the atom + The second argument is the string value of the atom + + ******/ + +// calc modes +SMIL_ATOM(discrete, "discrete") +SMIL_ATOM(linear, "linear") +SMIL_ATOM(paced, "paced") +SMIL_ATOM(spline, "spline") + +// fill modes +SMIL_ATOM(freeze, "freeze") +SMIL_ATOM(remove, "remove") + +// additive +SMIL_ATOM(replace, "replace") +SMIL_ATOM(sum, "sum") + Index: /cvsroot/mozilla/content/smil/src/nsSMILAtoms.cpp =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAtoms.cpp diff -N content/smil/src/nsSMILAtoms.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAtoms.cpp 16 Oct 2005 07:36:46 -0000 @@ -0,0 +1,63 @@ +/* -*- 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 "nsSMILAtoms.h" +#include "nsStaticAtom.h" +#include "nsMemory.h" + +// define storage for all atoms +#define SMIL_ATOM(_name, _value) nsIAtom* nsSMILAtoms::_name; +#include "nsSMILAtomList.h" +#undef SMIL_ATOM + +static const nsStaticAtom SMILAtoms_info[] = { +#define SMIL_ATOM(name_, value_) { value_, &nsSMILAtoms::name_ }, +#include "nsSMILAtomList.h" +#undef SMIL_ATOM +}; + +void nsSMILAtoms::AddRefAtoms() +{ + static bool atomsRegistered = PR_FALSE; + + if (!atomsRegistered) { + NS_RegisterStaticAtoms(SMILAtoms_info, NS_ARRAY_LENGTH(SMILAtoms_info)); + atomsRegistered = PR_TRUE; + } +} + Index: /cvsroot/mozilla/content/smil/src/nsSMILAtoms.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILAtoms.h diff -N content/smil/src/nsSMILAtoms.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILAtoms.h 16 Oct 2005 07:36:46 -0000 @@ -0,0 +1,66 @@ +/* -*- 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 ***** */ + +#ifndef __NS_SMILATOMS_H__ +#define __NS_SMILATOMS_H__ + +#include "prtypes.h" +#include "nsIAtom.h" + +class nsSMILAtoms +{ +public: + static void AddRefAtoms(); + + /* + * Declare all atoms + * + * The atom names and values are stored in nsSMILAtomList.h and are brought to + * you by the magic of C preprocessing + * + * Add new atoms to nsSMILAtomList and all support logic will be + * auto-generated + */ +#define SMIL_ATOM(_name, _value) static nsIAtom* _name; +#include "nsSMILAtomList.h" +#undef SMIL_ATOM + +}; + +#endif /* __NS_SMILATOMS_H__ */ + Index: /cvsroot/mozilla/content/smil/src/nsSMILCompositor.cpp =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILCompositor.cpp diff -N content/smil/src/nsSMILCompositor.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILCompositor.cpp 16 Oct 2005 07:36:46 -0000 @@ -0,0 +1,192 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 "nsSMILCompositor.h" +#include "nsISMILComposable.h" +#include "nsISimpleEnumerator.h" +#include "nsArrayEnumerator.h" +#include "nsISMILAnimAttr.h" +#include "nsISMILAnimVal.h" +#include "nsAutoLock.h" + +// XXXbb Remove +#include "nsITimelineService.h" + +//////////////////////////////////////////////////////////////////////// +// nsSMILCompositor implementation + +nsSMILCompositor::~nsSMILCompositor() +{ + if (mLock) { + PR_Lock(mLock); + PR_Unlock(mLock); + PR_DestroyLock(mLock); + } +} + +nsresult +nsSMILCompositor::Init(nsISMILAnimAttr* aTargetAttribute) +{ + NS_ENSURE_ARG_POINTER(aTargetAttribute); + + nsresult rv; + mTargetAttribute = do_GetWeakReference(aTargetAttribute, &rv); + if (NS_FAILED(rv)) { + mTargetAttribute = nsnull; + return rv; + } + + mResult = aTargetAttribute->Create(); + NS_ENSURE_TRUE(mResult, NS_ERROR_OUT_OF_MEMORY); + + mLock = PR_NewLock(); + NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY); + + return NS_OK; +} + +nsresult +nsSMILCompositor::AddComposable(nsISMILComposable* aComposable) +{ + NS_ENSURE_ARG_POINTER(aComposable); + + nsresult rv; + nsCOMPtr weakRef( + getter_AddRefs(do_GetWeakReference(aComposable, &rv)) ); + + nsAutoLock lock(mLock); + if (NS_SUCCEEDED(rv)) + rv = (mChildren.AppendObject(weakRef)) ? NS_OK : NS_ERROR_FAILURE; + + return rv; +} + +nsresult +nsSMILCompositor::RemoveComposable(nsISMILComposable* aComposable) +{ + NS_ENSURE_ARG_POINTER(aComposable); + + nsresult rv; + nsCOMPtr weakRef( + getter_AddRefs(do_GetWeakReference(aComposable, &rv)) ); + + nsAutoLock lock(mLock); + if (NS_SUCCEEDED(rv)) + rv = (mChildren.RemoveObject(weakRef)) ? NS_OK : NS_ERROR_FAILURE; + + return rv; +} + +void +nsSMILCompositor::ComposeSample() +{ + NS_TIMELINE_START_TIMER("nsSMILCompositor::ComposeSample"); + + NS_TIMELINE_START_TIMER("nsSMILCompositor::Initialisation"); + NS_ENSURE_TRUE(mTargetAttribute,); + NS_ENSURE_TRUE(mResult,); + nsresult rv; + + nsCOMPtr targetAttribute( + do_QueryReferent(mTargetAttribute) ); + NS_ENSURE_TRUE(targetAttribute,); + + rv = targetAttribute->GetBaseValue(*mResult); + NS_ENSURE_SUCCESS(rv,); + + PR_Lock(mLock); + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::Initialisation"); + + NS_TIMELINE_START_TIMER("nsSMILCompositor::SortCompositors"); + mChildren.Sort(SortCompositors, nsnull); + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::SortCompositors"); + + NS_TIMELINE_START_TIMER("nsSMILCompositor::Preparing for compositing"); + + PRBool changed = PR_FALSE; + nsCOMPtr composable; + PRUint32 length = mChildren.Count(); + PRUint32 i; + + for (i = length; i > 0; --i) { + composable = do_QueryReferent(mChildren[i-1]); + if (composable) { + changed |= composable->HasChanged(); + if (composable->WillReplace()) { + --i; + break; + } + } + } + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::Preparing for compositing"); + + if (!changed) { + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::ComposeSample"); + PR_Unlock(mLock); + return; + } + + NS_TIMELINE_START_TIMER("nsSMILCompositor::Composing loop"); + + for (; i < length; ++i) + { + composable = do_QueryReferent(mChildren[i]); + if (composable) + composable->ComposeResult(*mResult); + } + + PR_Unlock(mLock); + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::Composing loop"); + + // We can't just call Set on the animated value itself, because the observers + // of the animated object as a whole need to be updated too. + NS_TIMELINE_START_TIMER("nsSMILCompositor::Set value"); + targetAttribute->SetAnimValue(*mResult); + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::Set value"); + NS_TIMELINE_STOP_TIMER("nsSMILCompositor::ComposeSample"); +} + +//---------------------------------------------------------------------- +// Implementation helpers + +PR_CALLBACK int +nsSMILCompositor::SortCompositors(nsIWeakReference* aRef1, + nsIWeakReference* aRef2, + void* /*aData*/) +{ + nsCOMPtr a = do_QueryReferent(aRef1); + nsCOMPtr b = do_QueryReferent(aRef2); + + return (a && b) ? a->CompareTo(*b) : (a) ? 1 : (b) ? -1 : 0; +} + Index: /cvsroot/mozilla/content/smil/src/nsSMILCompositor.h =================================================================== RCS file: /cvsroot/mozilla/content/smil/src/nsSMILCompositor.h diff -N content/smil/src/nsSMILCompositor.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ /cvsroot/mozilla/content/smil/src/nsSMILCompositor.h 16 Oct 2005 07:36:46 -0000 @@ -0,0 +1,77 @@ +/* -*- 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 SVG project. + * + * Contributor(s): + * Brian Birtles + * + * 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 ***** */ + +#ifndef __NS_SMILCOMPOSITOR_H__ +#define __NS_SMILCOMPOSITOR_H__ + +#include "nsCOMArray.h" +#include "nsWeakReference.h" +#include "nsISMILAnimVal.h" +#include "prlock.h" + +//////////////////////////////////////////////////////////////////////// +// nsSMILCompositor: Collection of nsISMILComposable animations + +class nsISMILComposable; +class nsISMILAnimAttr; + +class nsSMILCompositor +{ +public: + nsSMILCompositor() {} + ~nsSMILCompositor(); + + nsresult Init(nsISMILAnimAttr* aTargetAttribute); + + nsresult AddComposable(nsISMILComposable* aComposable); + nsresult RemoveComposable(nsISMILComposable* aComposable); + void ComposeSample(); + +protected: + PR_STATIC_CALLBACK(int) SortCompositors(nsIWeakReference* aRef1, + nsIWeakReference* aRef2, + void* aData); + + nsCOMArray mChildren; + nsCOMPtr mResult; + nsWeakPtr mTargetAttribute; + PRLock* mLock; + +private: + // Pass by value and assignment should not be used + nsSMILCompositor(const nsSMILCompositor& other); + nsSMILCompositor& operator=(const nsSM