Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / svg / SVGPatternElement.cpp
blob5a0a9a46f2928099c68442cf08281f290d100484
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 already_AddRefed<DOMSVGAnimatedPreserveAspectRatio>
70 SVGPatternElement::PreserveAspectRatio() {
71 return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
74 //----------------------------------------------------------------------
76 already_AddRefed<DOMSVGAnimatedEnumeration> SVGPatternElement::PatternUnits() {
77 return mEnumAttributes[PATTERNUNITS].ToDOMAnimatedEnum(this);
80 already_AddRefed<DOMSVGAnimatedEnumeration>
81 SVGPatternElement::PatternContentUnits() {
82 return mEnumAttributes[PATTERNCONTENTUNITS].ToDOMAnimatedEnum(this);
85 already_AddRefed<DOMSVGAnimatedTransformList>
86 SVGPatternElement::PatternTransform() {
87 // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
88 // to allocate the DOMSVGAnimatedTransformList if it hasn't already done so:
89 return DOMSVGAnimatedTransformList::GetDOMWrapper(
90 GetAnimatedTransformList(DO_ALLOCATE), this);
93 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::X() {
94 return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
97 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::Y() {
98 return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
101 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::Width() {
102 return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
105 already_AddRefed<DOMSVGAnimatedLength> SVGPatternElement::Height() {
106 return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
109 already_AddRefed<DOMSVGAnimatedString> SVGPatternElement::Href() {
110 return mStringAttributes[HREF].IsExplicitlySet()
111 ? mStringAttributes[HREF].ToDOMAnimatedString(this)
112 : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
115 //----------------------------------------------------------------------
116 // SVGElement methods
118 SVGAnimatedTransformList* SVGPatternElement::GetAnimatedTransformList(
119 uint32_t aFlags) {
120 if (!mPatternTransform && (aFlags & DO_ALLOCATE)) {
121 mPatternTransform = MakeUnique<SVGAnimatedTransformList>();
123 return mPatternTransform.get();
126 /* virtual */
127 bool SVGPatternElement::HasValidDimensions() const {
128 return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() &&
129 mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
130 mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() &&
131 mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0;
134 SVGElement::LengthAttributesInfo SVGPatternElement::GetLengthInfo() {
135 return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
136 ArrayLength(sLengthInfo));
139 SVGElement::EnumAttributesInfo SVGPatternElement::GetEnumInfo() {
140 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
143 SVGAnimatedViewBox* SVGPatternElement::GetAnimatedViewBox() {
144 return &mViewBox;
147 SVGAnimatedPreserveAspectRatio*
148 SVGPatternElement::GetAnimatedPreserveAspectRatio() {
149 return &mPreserveAspectRatio;
152 SVGElement::StringAttributesInfo SVGPatternElement::GetStringInfo() {
153 return StringAttributesInfo(mStringAttributes, sStringInfo,
154 ArrayLength(sStringInfo));
157 } // namespace mozilla::dom