Bug 1941128 - Turn off network.dns.native_https_query on Mac again
[gecko.git] / dom / svg / SVGPatternElement.cpp
blob073dba5940871028c35695e70681099bdf4555a3
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/. */
7 #include "mozilla/dom/SVGPatternElement.h"
9 #include "mozilla/AlreadyAddRefed.h"
10 #include "mozilla/ArrayUtils.h"
11 #include "mozilla/dom/SVGLengthBinding.h"
12 #include "mozilla/dom/SVGPatternElementBinding.h"
13 #include "mozilla/dom/SVGUnitTypesBinding.h"
14 #include "DOMSVGAnimatedTransformList.h"
15 #include "nsGkAtoms.h"
17 NS_IMPL_NS_NEW_SVG_ELEMENT(Pattern)
19 namespace mozilla::dom {
21 using namespace SVGUnitTypes_Binding;
23 JSObject* SVGPatternElement::WrapNode(JSContext* aCx,
24 JS::Handle<JSObject*> aGivenProto) {
25 return SVGPatternElement_Binding::Wrap(aCx, this, aGivenProto);
28 //--------------------- Patterns ------------------------
30 SVGElement::LengthInfo SVGPatternElement::sLengthInfo[4] = {
31 {nsGkAtoms::x, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
32 SVGContentUtils::X},
33 {nsGkAtoms::y, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
34 SVGContentUtils::Y},
35 {nsGkAtoms::width, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
36 SVGContentUtils::X},
37 {nsGkAtoms::height, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
38 SVGContentUtils::Y},
41 SVGElement::EnumInfo SVGPatternElement::sEnumInfo[2] = {
42 {nsGkAtoms::patternUnits, sSVGUnitTypesMap,
43 SVG_UNIT_TYPE_OBJECTBOUNDINGBOX},
44 {nsGkAtoms::patternContentUnits, sSVGUnitTypesMap,
45 SVG_UNIT_TYPE_USERSPACEONUSE}};
47 SVGElement::StringInfo SVGPatternElement::sStringInfo[2] = {
48 {nsGkAtoms::href, kNameSpaceID_None, true},
49 {nsGkAtoms::href, kNameSpaceID_XLink, true}};
51 //----------------------------------------------------------------------
52 // Implementation
54 SVGPatternElement::SVGPatternElement(
55 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
56 : SVGPatternElementBase(std::move(aNodeInfo)) {}
58 //----------------------------------------------------------------------
59 // nsINode method
61 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPatternElement)
63 //----------------------------------------------------------------------
65 already_AddRefed<SVGAnimatedRect> SVGPatternElement::ViewBox() {
66 return mViewBox.ToSVGAnimatedRect(this);
69 bool SVGPatternElement::IsAttributeMapped(const nsAtom* aAttribute) const {
70 return aAttribute == nsGkAtoms::patternTransform ||
71 SVGPatternElementBase::IsAttributeMapped(aAttribute);
74 already_AddRefed<DOMSVGAnimatedPreserveAspectRatio>
75 SVGPatternElement::PreserveAspectRatio() {
76 return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
79 //----------------------------------------------------------------------
81 already_AddRefed<DOMSVGAnimatedEnumeration> SVGPatternElement::PatternUnits() {
82 return mEnumAttributes[PATTERNUNITS].ToDOMAnimatedEnum(this);
85 already_AddRefed<DOMSVGAnimatedEnumeration>
86 SVGPatternElement::PatternContentUnits() {
87 return mEnumAttributes[PATTERNCONTENTUNITS].ToDOMAnimatedEnum(this);
90 already_AddRefed<DOMSVGAnimatedTransformList>
91 SVGPatternElement::PatternTransform() {
92 // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
93 // to allocate the DOMSVGAnimatedTransformList if it hasn't already done so:
94 return DOMSVGAnimatedTransformList::GetDOMWrapper(
95 GetAnimatedTransformList(DO_ALLOCATE), this);
98 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::X() {
99 return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
102 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::Y() {
103 return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
106 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::Width() {
107 return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
110 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::Height() {
111 return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
114 already_AddRefed<DOMSVGAnimatedString> SVGPatternElement::Href() {
115 return mStringAttributes[HREF].IsExplicitlySet()
116 ? mStringAttributes[HREF].ToDOMAnimatedString(this)
117 : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
120 //----------------------------------------------------------------------
121 // SVGElement methods
123 SVGAnimatedTransformList* SVGPatternElement::GetAnimatedTransformList(
124 uint32_t aFlags) {
125 if (!mPatternTransform && (aFlags & DO_ALLOCATE)) {
126 mPatternTransform = MakeUnique<SVGAnimatedTransformList>();
128 return mPatternTransform.get();
131 /* virtual */
132 bool SVGPatternElement::HasValidDimensions() const {
133 return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() &&
134 mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
135 mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() &&
136 mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0;
139 SVGElement::LengthAttributesInfo SVGPatternElement::GetLengthInfo() {
140 return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
141 std::size(sLengthInfo));
144 SVGElement::EnumAttributesInfo SVGPatternElement::GetEnumInfo() {
145 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, std::size(sEnumInfo));
148 SVGAnimatedViewBox* SVGPatternElement::GetAnimatedViewBox() {
149 return &mViewBox;
152 SVGAnimatedPreserveAspectRatio*
153 SVGPatternElement::GetAnimatedPreserveAspectRatio() {
154 return &mPreserveAspectRatio;
157 SVGElement::StringAttributesInfo SVGPatternElement::GetStringInfo() {
158 return StringAttributesInfo(mStringAttributes, sStringInfo,
159 std::size(sStringInfo));
162 } // namespace mozilla::dom