tor-browser

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

DOMSVGAnimatedNumberList.h (5051B)


      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_DOMSVGANIMATEDNUMBERLIST_H_
      8 #define DOM_SVG_DOMSVGANIMATEDNUMBERLIST_H_
      9 
     10 #include "SVGElement.h"
     11 #include "mozilla/RefPtr.h"
     12 #include "nsCycleCollectionParticipant.h"
     13 #include "nsWrapperCache.h"
     14 
     15 namespace mozilla {
     16 
     17 class SVGAnimatedNumberList;
     18 class SVGNumberList;
     19 
     20 namespace dom {
     21 
     22 class DOMSVGNumberList;
     23 
     24 /**
     25 * Class DOMSVGAnimatedNumberList
     26 *
     27 * This class is used to create the DOM tearoff objects that wrap internal
     28 * SVGAnimatedNumberList objects.
     29 *
     30 * See the architecture comment in DOMSVGAnimatedLengthList.h (that's
     31 * LENGTH list). The comment for that class largly applies to this one too
     32 * and will go a long way to helping you understand the architecture here.
     33 *
     34 * This class is strongly intertwined with DOMSVGNumberList and DOMSVGNumber.
     35 * Our DOMSVGNumberList base and anim vals are friends and take care of nulling
     36 * out our pointers to them when they die (making our pointers to them true
     37 * weak refs).
     38 */
     39 class DOMSVGAnimatedNumberList final : public nsWrapperCache {
     40  friend class DOMSVGNumberList;
     41 
     42 public:
     43  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGAnimatedNumberList)
     44  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMSVGAnimatedNumberList)
     45 
     46  /**
     47   * Factory method to create and return a DOMSVGAnimatedNumberList wrapper
     48   * for a given internal SVGAnimatedNumberList object. The factory takes care
     49   * of caching the object that it returns so that the same object can be
     50   * returned for the given SVGAnimatedNumberList each time it is requested.
     51   * The cached object is only removed from the cache when it is destroyed due
     52   * to there being no more references to it or to any of its descendant
     53   * objects. If that happens, any subsequent call requesting the DOM wrapper
     54   * for the SVGAnimatedNumberList will naturally result in a new
     55   * DOMSVGAnimatedNumberList being returned.
     56   */
     57  static already_AddRefed<DOMSVGAnimatedNumberList> GetDOMWrapper(
     58      SVGAnimatedNumberList* aList, dom::SVGElement* aElement,
     59      uint8_t aAttrEnum);
     60 
     61  /**
     62   * This method returns the DOMSVGAnimatedNumberList wrapper for an internal
     63   * SVGAnimatedNumberList object if it currently has a wrapper. If it does
     64   * not, then nullptr is returned.
     65   */
     66  static DOMSVGAnimatedNumberList* GetDOMWrapperIfExists(
     67      SVGAnimatedNumberList* aList);
     68 
     69  /**
     70   * Called by internal code to notify us when we need to sync the length of
     71   * our baseVal DOM list with its internal list. This is called just prior to
     72   * the length of the internal baseVal list being changed so that any DOM list
     73   * items that need to be removed from the DOM list can first get their values
     74   * from their internal counterpart.
     75   *
     76   * The only time this method could fail is on OOM when trying to increase the
     77   * length of the DOM list. If that happens then this method simply clears the
     78   * list and returns. Callers just proceed as normal, and we simply accept
     79   * that the DOM list will be empty (until successfully set to a new value).
     80   */
     81  void InternalBaseValListWillChangeTo(const SVGNumberList& aNewValue);
     82  void InternalAnimValListWillChangeTo(const SVGNumberList& aNewValue);
     83 
     84  /**
     85   * Returns true if our attribute is animating (in which case our animVal is
     86   * not simply a mirror of our baseVal).
     87   */
     88  bool IsAnimating() const;
     89 
     90  // WebIDL
     91  dom::SVGElement* GetParentObject() const { return mElement; }
     92  JSObject* WrapObject(JSContext* aCx,
     93                       JS::Handle<JSObject*> aGivenProto) override;
     94  // These aren't weak refs because mBaseVal and mAnimVal are weak
     95  already_AddRefed<DOMSVGNumberList> BaseVal();
     96  already_AddRefed<DOMSVGNumberList> AnimVal();
     97 
     98 private:
     99  /**
    100   * Only our static GetDOMWrapper() factory method may create objects of our
    101   * type.
    102   */
    103  DOMSVGAnimatedNumberList(dom::SVGElement* aElement, uint8_t aAttrEnum)
    104      : mBaseVal(nullptr),
    105        mAnimVal(nullptr),
    106        mElement(aElement),
    107        mAttrEnum(aAttrEnum) {}
    108 
    109  ~DOMSVGAnimatedNumberList();
    110 
    111  /// Get a reference to this DOM wrapper object's internal counterpart.
    112  SVGAnimatedNumberList& InternalAList();
    113  const SVGAnimatedNumberList& InternalAList() const;
    114 
    115  // Weak refs to our DOMSVGNumberList baseVal/animVal objects. These objects
    116  // are friends and take care of clearing these pointers when they die, making
    117  // these true weak references.
    118  DOMSVGNumberList* mBaseVal;
    119  DOMSVGNumberList* mAnimVal;
    120 
    121  // Strong ref to our element to keep it alive. We hold this not only for
    122  // ourself, but also for our base/animVal and all of their items.
    123  RefPtr<dom::SVGElement> mElement;
    124 
    125  uint8_t mAttrEnum;
    126 };
    127 
    128 }  // namespace dom
    129 }  // namespace mozilla
    130 
    131 #endif  // DOM_SVG_DOMSVGANIMATEDNUMBERLIST_H_