tor-browser

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

SVGAnimatedClassOrString.cpp (2074B)


      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 #include "SVGAnimatedClassOrString.h"
      8 
      9 #include "DOMSVGAnimatedString.h"
     10 #include "SVGAttrTearoffTable.h"
     11 #include "mozilla/dom/TrustedScriptURL.h"
     12 #include "mozilla/dom/UnionTypes.h"
     13 
     14 namespace mozilla {
     15 
     16 constinit static SVGAttrTearoffTable<SVGAnimatedClassOrString,
     17                                     dom::DOMSVGAnimatedString>
     18    sSVGAnimatedClassOrStringTearoffTable;
     19 
     20 already_AddRefed<dom::DOMSVGAnimatedString>
     21 SVGAnimatedClassOrString::ToDOMAnimatedString(SVGElement* aSVGElement) {
     22  RefPtr<dom::DOMSVGAnimatedString> domAnimatedString =
     23      sSVGAnimatedClassOrStringTearoffTable.GetTearoff(this);
     24  if (!domAnimatedString) {
     25    domAnimatedString = new dom::DOMSVGAnimatedString(this, aSVGElement);
     26    sSVGAnimatedClassOrStringTearoffTable.AddTearoff(this, domAnimatedString);
     27  }
     28 
     29  return domAnimatedString.forget();
     30 }
     31 
     32 void SVGAnimatedClassOrString::RemoveTearoff() {
     33  sSVGAnimatedClassOrStringTearoffTable.RemoveTearoff(this);
     34 }
     35 
     36 void SVGAnimatedClassOrString::SetBaseValue(
     37    const TrustedScriptURLOrString& aValue, SVGElement* aSVGElement,
     38    bool aDoSetAttr, nsIPrincipal*, ErrorResult&) {
     39  // The spec is not super explicit, but it makes sense to default to the
     40  // associated data value for TrustedScriptURL values.
     41  // https://github.com/w3c/svgwg/issues/961
     42  const nsAString& stringValue = aValue.IsString()
     43                                     ? aValue.GetAsString()
     44                                     : aValue.GetAsTrustedScriptURL().mData;
     45  SetBaseValue(stringValue, aSVGElement, aDoSetAttr);
     46 }
     47 
     48 void SVGAnimatedClassOrString::GetBaseValue(
     49    OwningTrustedScriptURLOrString& aValue,
     50    const SVGElement* aSVGElement) const {
     51  GetBaseValue(aValue.SetAsString(), aSVGElement);
     52 }
     53 
     54 }  // namespace mozilla