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 "mozilla/dom/SVGViewElement.h"
8 #include "mozilla/dom/SVGViewElementBinding.h"
9 #include "DOMSVGStringList.h"
10
11 NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(View)
12
13 namespace mozilla {
14 namespace dom {
15
16 using namespace SVGViewElementBinding;
17
WrapNode(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)18 JSObject* SVGViewElement::WrapNode(JSContext* aCx,
19 JS::Handle<JSObject*> aGivenProto) {
20 return SVGViewElementBinding::Wrap(aCx, this, aGivenProto);
21 }
22
23 nsSVGElement::StringListInfo SVGViewElement::sStringListInfo[1] = {
24 {&nsGkAtoms::viewTarget}};
25
26 nsSVGEnumMapping SVGViewElement::sZoomAndPanMap[] = {
27 {&nsGkAtoms::disable, SVG_ZOOMANDPAN_DISABLE},
28 {&nsGkAtoms::magnify, SVG_ZOOMANDPAN_MAGNIFY},
29 {nullptr, 0}};
30
31 nsSVGElement::EnumInfo SVGViewElement::sEnumInfo[1] = {
32 {&nsGkAtoms::zoomAndPan, sZoomAndPanMap, SVG_ZOOMANDPAN_MAGNIFY}};
33
34 //----------------------------------------------------------------------
35 // Implementation
36
SVGViewElement(already_AddRefed<mozilla::dom::NodeInfo> & aNodeInfo)37 SVGViewElement::SVGViewElement(
38 already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
39 : SVGViewElementBase(aNodeInfo) {}
40
41 //----------------------------------------------------------------------
42 // nsIDOMNode methods
43
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGViewElement)44 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGViewElement)
45
46 void SVGViewElement::SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv) {
47 if (aZoomAndPan == SVG_ZOOMANDPAN_DISABLE ||
48 aZoomAndPan == SVG_ZOOMANDPAN_MAGNIFY) {
49 mEnumAttributes[ZOOMANDPAN].SetBaseValue(aZoomAndPan, this);
50 return;
51 }
52
53 rv.ThrowRangeError<MSG_INVALID_ZOOMANDPAN_VALUE_ERROR>();
54 }
55
56 //----------------------------------------------------------------------
57
ViewBox()58 already_AddRefed<SVGAnimatedRect> SVGViewElement::ViewBox() {
59 return mViewBox.ToSVGAnimatedRect(this);
60 }
61
62 already_AddRefed<DOMSVGAnimatedPreserveAspectRatio>
PreserveAspectRatio()63 SVGViewElement::PreserveAspectRatio() {
64 return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
65 }
66
67 //----------------------------------------------------------------------
68
ViewTarget()69 already_AddRefed<DOMSVGStringList> SVGViewElement::ViewTarget() {
70 return DOMSVGStringList::GetDOMWrapper(&mStringListAttributes[VIEW_TARGET],
71 this, false, VIEW_TARGET);
72 }
73
74 //----------------------------------------------------------------------
75 // nsSVGElement methods
76
GetEnumInfo()77 nsSVGElement::EnumAttributesInfo SVGViewElement::GetEnumInfo() {
78 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
79 }
80
GetViewBox()81 nsSVGViewBox* SVGViewElement::GetViewBox() { return &mViewBox; }
82
GetPreserveAspectRatio()83 SVGAnimatedPreserveAspectRatio* SVGViewElement::GetPreserveAspectRatio() {
84 return &mPreserveAspectRatio;
85 }
86
GetStringListInfo()87 nsSVGElement::StringListAttributesInfo SVGViewElement::GetStringListInfo() {
88 return StringListAttributesInfo(mStringListAttributes, sStringListInfo,
89 ArrayLength(sStringListInfo));
90 }
91
92 } // namespace dom
93 } // namespace mozilla
94