tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGLengthListSMILType.h (4478B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_SVG_SVGLENGTHLISTSMILTYPE_H_
      8 #define DOM_SVG_SVGLENGTHLISTSMILTYPE_H_
      9 
     10 #include "mozilla/SMILType.h"
     11 
     12 namespace mozilla {
     13 
     14 class SMILValue;
     15 
     16 ////////////////////////////////////////////////////////////////////////
     17 // SVGLengthListSMILType
     18 //
     19 // Operations for animating an SVGLengthList.
     20 //
     21 class SVGLengthListSMILType : public SMILType {
     22 public:
     23  // Singleton for SMILValue objects to hold onto.
     24  static SVGLengthListSMILType sSingleton;
     25 
     26 protected:
     27  // SMILType Methods
     28  // -------------------
     29 
     30  /**
     31   * When this method initializes the SVGLengthListAndInfo for its SMILValue
     32   * argument, it has to blindly set its mCanZeroPadList to true despite
     33   * the fact that some attributes can't be zero-padded. (See the explaination
     34   * that follows.) SVGAnimatedLengthList::SMILAnimatedLengthList's
     35   * GetBaseValue() and ValueFromString() methods then override this for the
     36   * SMILValue objects that they create to set this flag to the appropriate
     37   * value for the attribute in question.
     38   *
     39   * The reason that we default to setting the mCanZeroPadList to true is
     40   * because the SMIL engine creates "zero" valued SMILValue objects for
     41   * intermediary calculations, and may pass such a SMILValue (along with a
     42   * SMILValue from an animation element - that is a SMILValue created by
     43   * SVGAnimatedLengthList::SMILAnimatedLengthList's GetBaseValue() or
     44   * ValueFromString() methods) into the Add(), ComputeDistance() or
     45   * Interpolate() methods below. Even in the case of animation of list
     46   * attributes that may *not* be padded with zeros (such as 'x' and 'y' on the
     47   * <text> element), we need to allow zero-padding of these "zero" valued
     48   * SMILValue's lists. One reason for this is illustrated by the following
     49   * example:
     50   *
     51   *   <text x="2 4">foo
     52   *      <animate by="2 2" .../>
     53   *   </text>
     54   *
     55   * In this example there are two SMIL animation layers to be sandwiched: the
     56   * base layer, and the layer created for the <animate> element. The SMIL
     57   * engine calculates the result of each layer *independently*, before
     58   * compositing the results together. Thus for the <animate> sandwich layer
     59   * the SMIL engine interpolates between a "zero" SMILValue that it creates
     60   * (since there is no explicit "from") and the "2 2", before the result of
     61   * that interpolation is added to the "2 4" from the base layer. Clearly for
     62   * the interpolation between the "zero" SMILValue and "2 2" to work, the
     63   * "zero" SMILValue's SVGLengthListAndInfo must be zero paddable - hence
     64   * why this method always sets mCanZeroPadList to true.
     65   *
     66   * (Since the Add(), ComputeDistance() and Interpolate() methods may be
     67   * passed two input SMILValue objects for which CanZeroPadList() returns
     68   * opposite values, these methods must be careful what they set the flag to
     69   * on the SMILValue that they output. If *either* of the input SMILValues
     70   * has an SVGLengthListAndInfo for which CanZeroPadList() returns false,
     71   * then they must set the flag to false on the output SMILValue too. If
     72   * the methods failed to do that, then when the result SMILValue objects
     73   * from each sandwich layer are composited together, we could end up allowing
     74   * animation between lists of different length when we should not!)
     75   */
     76  void InitValue(SMILValue& aValue) const override;
     77 
     78  void DestroyValue(SMILValue& aValue) const override;
     79  nsresult Assign(SMILValue& aDest, const SMILValue& aSrc) const override;
     80  bool IsEqual(const SMILValue& aLeft, const SMILValue& aRight) const override;
     81  nsresult Add(SMILValue& aDest, const SMILValue& aValueToAdd,
     82               uint32_t aCount) const override;
     83  nsresult ComputeDistance(const SMILValue& aFrom, const SMILValue& aTo,
     84                           double& aDistance) const override;
     85  nsresult Interpolate(const SMILValue& aStartVal, const SMILValue& aEndVal,
     86                       double aUnitDistance, SMILValue& aResult) const override;
     87 
     88 private:
     89  // Private constructor: prevent instances beyond my singleton.
     90  constexpr SVGLengthListSMILType() = default;
     91 };
     92 
     93 }  // namespace mozilla
     94 
     95 #endif  // DOM_SVG_SVGLENGTHLISTSMILTYPE_H_