tor-browser

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

SVGMotionSMILType.h (2717B)


      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 /* implementation of SMILType for use by <animateMotion> element */
      8 
      9 #ifndef DOM_SVG_SVGMOTIONSMILTYPE_H_
     10 #define DOM_SVG_SVGMOTIONSMILTYPE_H_
     11 
     12 #include "mozilla/SMILType.h"
     13 #include "mozilla/gfx/2D.h"
     14 
     15 namespace mozilla {
     16 
     17 class SMILValue;
     18 
     19 /**
     20 * MotionRotateType: Enum to indicate the type of our "rotate" attribute.
     21 */
     22 enum RotateType {
     23  eRotateType_Explicit,    // for e.g. rotate="45"/"45deg"/"0.785rad"
     24  eRotateType_Auto,        // for rotate="auto"
     25  eRotateType_AutoReverse  // for rotate="auto-reverse"
     26 };
     27 
     28 /**
     29 * SVGMotionSMILType: Implements the SMILType interface for SMIL animations
     30 * from <animateMotion>.
     31 *
     32 * NOTE: Even though there's technically no "motion" attribute, we behave in
     33 * many ways as if there were, for simplicity.
     34 */
     35 class SVGMotionSMILType : public SMILType {
     36  using Path = mozilla::gfx::Path;
     37 
     38 public:
     39  // Singleton for SMILValue objects to hold onto.
     40  static SVGMotionSMILType sSingleton;
     41 
     42 protected:
     43  // SMILType Methods
     44  // -------------------
     45  void InitValue(SMILValue& aValue) const override;
     46  void DestroyValue(SMILValue& aValue) const override;
     47  nsresult Assign(SMILValue& aDest, const SMILValue& aSrc) const override;
     48  bool IsEqual(const SMILValue& aLeft, const SMILValue& aRight) const override;
     49  nsresult Add(SMILValue& aDest, const SMILValue& aValueToAdd,
     50               uint32_t aCount) const override;
     51  nsresult SandwichAdd(SMILValue& aDest,
     52                       const SMILValue& aValueToAdd) const override;
     53  nsresult ComputeDistance(const SMILValue& aFrom, const SMILValue& aTo,
     54                           double& aDistance) const override;
     55  nsresult Interpolate(const SMILValue& aStartVal, const SMILValue& aEndVal,
     56                       double aUnitDistance, SMILValue& aResult) const override;
     57 
     58 public:
     59  // Used to generate a transform matrix from an <animateMotion> SMILValue.
     60  static gfx::Matrix CreateMatrix(const SMILValue& aSMILVal);
     61 
     62  // Used to generate a SMILValue for the point at the given distance along
     63  // the given path.
     64  static SMILValue ConstructSMILValue(Path* aPath, float aDist,
     65                                      RotateType aRotateType,
     66                                      float aRotateAngle);
     67 
     68 private:
     69  // Private constructor: prevent instances beyond my singleton.
     70  constexpr SVGMotionSMILType() = default;
     71 };
     72 
     73 }  // namespace mozilla
     74 
     75 #endif  // DOM_SVG_SVGMOTIONSMILTYPE_H_