tor-browser

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

SVGMotionSMILAnimationFunction.h (3699B)


      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_SVGMOTIONSMILANIMATIONFUNCTION_H_
      8 #define DOM_SVG_SVGMOTIONSMILANIMATIONFUNCTION_H_
      9 
     10 #include "SVGMotionSMILType.h"
     11 #include "mozilla/RefPtr.h"
     12 #include "mozilla/SMILAnimationFunction.h"
     13 #include "mozilla/gfx/2D.h"
     14 #include "nsTArray.h"
     15 
     16 class nsAttrValue;
     17 class nsAtom;
     18 class nsIContent;
     19 
     20 namespace mozilla {
     21 
     22 class SMILAttr;
     23 class SMILValue;
     24 
     25 namespace dom {
     26 class SVGMPathElement;
     27 }  // namespace dom
     28 
     29 //----------------------------------------------------------------------
     30 // SVGMotionSMILAnimationFunction
     31 //
     32 // Subclass of SMILAnimationFunction to support a few extra features offered
     33 // by the <animateMotion> element.
     34 //
     35 class SVGMotionSMILAnimationFunction final : public SMILAnimationFunction {
     36  using Path = mozilla::gfx::Path;
     37 
     38 public:
     39  SVGMotionSMILAnimationFunction();
     40  bool SetAttr(nsAtom* aAttribute, const nsAString& aValue,
     41               nsAttrValue& aResult, nsresult* aParseResult = nullptr) override;
     42  bool UnsetAttr(nsAtom* aAttribute) override;
     43 
     44  // Method to allow our owner-element to signal us when our <mpath>
     45  // has changed or been added/removed.  When that happens, we need to
     46  // mark ourselves as changed so we'll get recomposed, and mark our path data
     47  // as stale so it'll get regenerated (regardless of mPathSourceType, since
     48  // <mpath> trumps all the other sources of path data)
     49  void MpathChanged() { mIsPathStale = mHasChanged = true; }
     50 
     51 protected:
     52  enum PathSourceType {
     53    // NOTE: Ordering matters here. Higher-priority path-descriptors should
     54    // have higher enumerated values
     55    ePathSourceType_None,    // uninitialized or not applicable
     56    ePathSourceType_ByAttr,  // by or from-by animation
     57    ePathSourceType_ToAttr,  // to or from-to animation
     58    ePathSourceType_ValuesAttr,
     59    ePathSourceType_PathAttr,
     60    ePathSourceType_Mpath
     61  };
     62 
     63  SMILCalcMode GetCalcMode() const override;
     64  virtual nsresult GetValues(const SMILAttr& aSMILAttr,
     65                             SMILValueArray& aResult) override;
     66  void CheckValueListDependentAttrs(uint32_t aNumValues) override;
     67 
     68  bool IsToAnimation() const override;
     69 
     70  void CheckKeyPoints();
     71  nsresult SetKeyPoints(const nsAString& aKeyPoints, nsAttrValue& aResult);
     72  void UnsetKeyPoints();
     73  nsresult SetRotate(const nsAString& aRotate, nsAttrValue& aResult);
     74  void UnsetRotate();
     75 
     76  // Helpers for GetValues
     77  void MarkStaleIfAttributeAffectsPath(nsAtom* aAttribute);
     78  void RebuildPathAndVertices(const nsIContent* aTargetElement);
     79  void RebuildPathAndVerticesFromMpathElem(dom::SVGMPathElement* aMpathElem);
     80  void RebuildPathAndVerticesFromPathAttr();
     81  void RebuildPathAndVerticesFromBasicAttrs(const nsIContent* aContextElem);
     82  nsresult GenerateValuesForPathAndPoints(
     83      Path* aPath, bool aIsKeyPoints, FallibleTArray<double>& aPointDistances,
     84      SMILValueArray& aResult);
     85 
     86  // Members
     87  // -------
     88  FallibleTArray<double> mKeyPoints;  // parsed from "keyPoints" attribute.
     89 
     90  RotateType mRotateType;  // auto, auto-reverse, or explicit.
     91  float mRotateAngle;      // the angle value, if explicit.
     92 
     93  PathSourceType mPathSourceType;        // source of our Path.
     94  RefPtr<Path> mPath;                    // representation of motion path.
     95  FallibleTArray<double> mPathVertices;  // distances of vertices along path.
     96 
     97  bool mIsPathStale;
     98 };
     99 
    100 }  // namespace mozilla
    101 
    102 #endif  // DOM_SVG_SVGMOTIONSMILANIMATIONFUNCTION_H_