tor-browser

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

SVGAnimatedLengthList.h (4313B)


      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_SVGANIMATEDLENGTHLIST_H_
      8 #define DOM_SVG_SVGANIMATEDLENGTHLIST_H_
      9 
     10 #include "SVGLengthList.h"
     11 #include "mozilla/SMILAttr.h"
     12 #include "mozilla/UniquePtr.h"
     13 
     14 namespace mozilla {
     15 
     16 class SMILValue;
     17 
     18 namespace dom {
     19 class SVGAnimationElement;
     20 class SVGElement;
     21 }  // namespace dom
     22 
     23 /**
     24 * Class SVGAnimatedLengthList
     25 *
     26 * This class is very different to the SVG DOM interface of the same name found
     27 * in the SVG specification. This is a lightweight internal class - see
     28 * DOMSVGAnimatedLengthList for the heavier DOM class that wraps instances of
     29 * this class and implements the SVG specification's SVGAnimatedLengthList DOM
     30 * interface.
     31 *
     32 * Except where noted otherwise, this class' methods take care of keeping the
     33 * appropriate DOM wrappers in sync (see the comment in
     34 * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo) so that their
     35 * consumers don't need to concern themselves with that.
     36 */
     37 class SVGAnimatedLengthList {
     38  // friends so that they can get write access to mBaseVal
     39  friend class dom::DOMSVGLength;
     40  friend class dom::DOMSVGLengthList;
     41 
     42 public:
     43  SVGAnimatedLengthList() = default;
     44 
     45  SVGAnimatedLengthList& operator=(const SVGAnimatedLengthList& aOther) {
     46    mBaseVal = aOther.mBaseVal;
     47    if (aOther.mAnimVal) {
     48      mAnimVal = MakeUnique<SVGLengthList>(*aOther.mAnimVal);
     49    }
     50    return *this;
     51  }
     52 
     53  /**
     54   * Because it's so important that mBaseVal and its DOMSVGLengthList wrapper
     55   * (if any) be kept in sync (see the comment in
     56   * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo), this method
     57   * returns a const reference. Only our friend classes may get mutable
     58   * references to mBaseVal.
     59   */
     60  const SVGLengthList& GetBaseValue() const { return mBaseVal; }
     61 
     62  nsresult SetBaseValueString(const nsAString& aValue);
     63 
     64  void ClearBaseValue(uint32_t aAttrEnum);
     65 
     66  const SVGLengthList& GetAnimValue() const {
     67    return mAnimVal ? *mAnimVal : mBaseVal;
     68  }
     69 
     70  nsresult SetAnimValue(const SVGLengthList& aNewAnimValue,
     71                        dom::SVGElement* aElement, uint32_t aAttrEnum);
     72 
     73  void ClearAnimValue(dom::SVGElement* aElement, uint32_t aAttrEnum);
     74 
     75  bool IsAnimating() const { return !!mAnimVal; }
     76 
     77  UniquePtr<SMILAttr> ToSMILAttr(dom::SVGElement* aSVGElement,
     78                                 uint8_t aAttrEnum, uint8_t aAxis,
     79                                 bool aCanZeroPadList);
     80 
     81 private:
     82  // mAnimVal is a pointer to allow us to determine if we're being animated or
     83  // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
     84  // if we're animating is not an option, since that would break animation *to*
     85  // the empty string (<set to="">).
     86 
     87  SVGLengthList mBaseVal;
     88  UniquePtr<SVGLengthList> mAnimVal;
     89 
     90  struct SMILAnimatedLengthList : public SMILAttr {
     91   public:
     92    SMILAnimatedLengthList(SVGAnimatedLengthList* aVal,
     93                           dom::SVGElement* aSVGElement, uint8_t aAttrEnum,
     94                           uint8_t aAxis, bool aCanZeroPadList)
     95        : mVal(aVal),
     96          mElement(aSVGElement),
     97          mAttrEnum(aAttrEnum),
     98          mAxis(aAxis),
     99          mCanZeroPadList(aCanZeroPadList) {}
    100 
    101    // These will stay alive because a SMILAttr only lives as long
    102    // as the Compositing step, and DOM elements don't get a chance to
    103    // die during that.
    104    SVGAnimatedLengthList* mVal;
    105    dom::SVGElement* mElement;
    106    uint8_t mAttrEnum;
    107    uint8_t mAxis;
    108    bool mCanZeroPadList;  // See SVGLengthListAndInfo::CanZeroPadList
    109 
    110    // SMILAttr methods
    111    nsresult ValueFromString(const nsAString& aStr,
    112                             const dom::SVGAnimationElement* aSrcElement,
    113                             SMILValue& aValue,
    114                             bool& aPreventCachingOfSandwich) const override;
    115    SMILValue GetBaseValue() const override;
    116    void ClearAnimValue() override;
    117    nsresult SetAnimValue(const SMILValue& aValue) override;
    118  };
    119 };
    120 
    121 }  // namespace mozilla
    122 
    123 #endif  // DOM_SVG_SVGANIMATEDLENGTHLIST_H_