diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/svg/SVGLengthListSMILType.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/svg/SVGLengthListSMILType.h')
-rw-r--r-- | dom/svg/SVGLengthListSMILType.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/dom/svg/SVGLengthListSMILType.h b/dom/svg/SVGLengthListSMILType.h new file mode 100644 index 0000000000..ebfccdb85f --- /dev/null +++ b/dom/svg/SVGLengthListSMILType.h @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_SVG_SVGLENGTHLISTSMILTYPE_H_ +#define DOM_SVG_SVGLENGTHLISTSMILTYPE_H_ + +#include "mozilla/Attributes.h" +#include "mozilla/SMILType.h" + +namespace mozilla { + +class SMILValue; + +//////////////////////////////////////////////////////////////////////// +// SVGLengthListSMILType +// +// Operations for animating an SVGLengthList. +// +class SVGLengthListSMILType : public SMILType { + public: + // Singleton for SMILValue objects to hold onto. + static SVGLengthListSMILType sSingleton; + + protected: + // SMILType Methods + // ------------------- + + /** + * When this method initializes the SVGLengthListAndInfo for its SMILValue + * argument, it has to blindly set its mCanZeroPadList to true despite + * the fact that some attributes can't be zero-padded. (See the explaination + * that follows.) SVGAnimatedLengthList::SMILAnimatedLengthList's + * GetBaseValue() and ValueFromString() methods then override this for the + * SMILValue objects that they create to set this flag to the appropriate + * value for the attribute in question. + * + * The reason that we default to setting the mCanZeroPadList to true is + * because the SMIL engine creates "zero" valued SMILValue objects for + * intermediary calculations, and may pass such a SMILValue (along with a + * SMILValue from an animation element - that is a SMILValue created by + * SVGAnimatedLengthList::SMILAnimatedLengthList's GetBaseValue() or + * ValueFromString() methods) into the Add(), ComputeDistance() or + * Interpolate() methods below. Even in the case of animation of list + * attributes that may *not* be padded with zeros (such as 'x' and 'y' on the + * <text> element), we need to allow zero-padding of these "zero" valued + * SMILValue's lists. One reason for this is illustrated by the following + * example: + * + * <text x="2 4">foo + * <animate by="2 2" .../> + * </text> + * + * In this example there are two SMIL animation layers to be sandwiched: the + * base layer, and the layer created for the <animate> element. The SMIL + * engine calculates the result of each layer *independently*, before + * compositing the results together. Thus for the <animate> sandwich layer + * the SMIL engine interpolates between a "zero" SMILValue that it creates + * (since there is no explicit "from") and the "2 2", before the result of + * that interpolation is added to the "2 4" from the base layer. Clearly for + * the interpolation between the "zero" SMILValue and "2 2" to work, the + * "zero" SMILValue's SVGLengthListAndInfo must be zero paddable - hence + * why this method always sets mCanZeroPadList to true. + * + * (Since the Add(), ComputeDistance() and Interpolate() methods may be + * passed two input SMILValue objects for which CanZeroPadList() returns + * opposite values, these methods must be careful what they set the flag to + * on the SMILValue that they output. If *either* of the input SMILValues + * has an SVGLengthListAndInfo for which CanZeroPadList() returns false, + * then they must set the flag to false on the output SMILValue too. If + * the methods failed to do that, then when the result SMILValue objects + * from each sandwich layer are composited together, we could end up allowing + * animation between lists of different length when we should not!) + */ + void Init(SMILValue& aValue) const override; + + void Destroy(SMILValue& aValue) const override; + nsresult Assign(SMILValue& aDest, const SMILValue& aSrc) const override; + bool IsEqual(const SMILValue& aLeft, const SMILValue& aRight) const override; + nsresult Add(SMILValue& aDest, const SMILValue& aValueToAdd, + uint32_t aCount) const override; + nsresult ComputeDistance(const SMILValue& aFrom, const SMILValue& aTo, + double& aDistance) const override; + nsresult Interpolate(const SMILValue& aStartVal, const SMILValue& aEndVal, + double aUnitDistance, SMILValue& aResult) const override; + + private: + // Private constructor: prevent instances beyond my singleton. + constexpr SVGLengthListSMILType() = default; +}; + +} // namespace mozilla + +#endif // DOM_SVG_SVGLENGTHLISTSMILTYPE_H_ |