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