diff --git a/content/svg/content/src/SVGViewElement.cpp b/content/svg/content/src/SVGViewElement.cpp index bb955142726..98a3df12ba3 100644 --- a/content/svg/content/src/SVGViewElement.cpp +++ b/content/svg/content/src/SVGViewElement.cpp @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/SVGViewElement.h" +#include "mozilla/dom/SVGViewElementBinding.h" #include "DOMSVGStringList.h" DOMCI_NODE_DATA(SVGViewElement, mozilla::dom::SVGViewElement) @@ -13,6 +14,12 @@ NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(View) namespace mozilla { namespace dom { +JSObject* +SVGViewElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap) +{ + return SVGViewElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + nsSVGElement::StringListInfo SVGViewElement::sStringListInfo[1] = { { &nsGkAtoms::viewTarget } @@ -66,20 +73,28 @@ NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGViewElement) NS_IMETHODIMP SVGViewElement::GetZoomAndPan(uint16_t *aZoomAndPan) { - *aZoomAndPan = mEnumAttributes[ZOOMANDPAN].GetAnimValue(); + *aZoomAndPan = ZoomAndPan(); return NS_OK; } NS_IMETHODIMP SVGViewElement::SetZoomAndPan(uint16_t aZoomAndPan) +{ + ErrorResult rv; + SetZoomAndPan(aZoomAndPan, rv); + return rv.ErrorCode(); +} + +void +SVGViewElement::SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv) { if (aZoomAndPan == nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_DISABLE || aZoomAndPan == nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY) { mEnumAttributes[ZOOMANDPAN].SetBaseValue(aZoomAndPan, this); - return NS_OK; + return; } - return NS_ERROR_RANGE_ERR; + rv.Throw(NS_ERROR_RANGE_ERR); } //---------------------------------------------------------------------- @@ -89,18 +104,33 @@ SVGViewElement::SetZoomAndPan(uint16_t aZoomAndPan) NS_IMETHODIMP SVGViewElement::GetViewBox(nsIDOMSVGAnimatedRect * *aViewBox) { - return mViewBox.ToDOMAnimatedRect(aViewBox, this); + *aViewBox = ViewBox().get(); + return NS_OK; +} + +already_AddRefed +SVGViewElement::ViewBox() +{ + nsCOMPtr box; + mViewBox.ToDOMAnimatedRect(getter_AddRefs(box), this); + return box.forget(); } /* readonly attribute SVGPreserveAspectRatio preserveAspectRatio; */ NS_IMETHODIMP SVGViewElement::GetPreserveAspectRatio(nsISupports **aPreserveAspectRatio) +{ + *aPreserveAspectRatio = PreserveAspectRatio().get(); + return NS_OK; +} + +already_AddRefed +SVGViewElement::PreserveAspectRatio() { nsRefPtr ratio; mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(getter_AddRefs(ratio), this); - ratio.forget(aPreserveAspectRatio); - return NS_OK; + return ratio.forget(); } //---------------------------------------------------------------------- @@ -109,11 +139,17 @@ SVGViewElement::GetPreserveAspectRatio(nsISupports /* readonly attribute nsIDOMSVGStringList viewTarget; */ NS_IMETHODIMP SVGViewElement::GetViewTarget(nsIDOMSVGStringList * *aViewTarget) { - *aViewTarget = DOMSVGStringList::GetDOMWrapper( - &mStringListAttributes[VIEW_TARGET], this, false, VIEW_TARGET).get(); + *aViewTarget = ViewTarget().get(); return NS_OK; } +already_AddRefed +SVGViewElement::ViewTarget() +{ + return DOMSVGStringList::GetDOMWrapper( + &mStringListAttributes[VIEW_TARGET], this, false, VIEW_TARGET); +} + //---------------------------------------------------------------------- // nsSVGElement methods diff --git a/content/svg/content/src/SVGViewElement.h b/content/svg/content/src/SVGViewElement.h index 7b29c1fa8eb..9bf89061bdc 100644 --- a/content/svg/content/src/SVGViewElement.h +++ b/content/svg/content/src/SVGViewElement.h @@ -33,12 +33,14 @@ class SVGViewElement : public SVGViewElementBase, public nsIDOMSVGFitToViewBox, public nsIDOMSVGZoomAndPan { +protected: friend class mozilla::SVGFragmentIdentifier; friend class ::nsSVGSVGElement; friend class ::nsSVGOuterSVGFrame; SVGViewElement(already_AddRefed aNodeInfo); friend nsresult (::NS_NewSVGViewElement(nsIContent **aResult, already_AddRefed aNodeInfo)); + virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE; public: // interfaces: @@ -59,6 +61,14 @@ public: virtual nsXPCClassInfo* GetClassInfo(); virtual nsIDOMNode* AsDOMNode() { return this; } + + // WebIDL + uint16_t ZoomAndPan() { return mEnumAttributes[ZOOMANDPAN].GetAnimValue(); } + void SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv); + already_AddRefed ViewBox(); + already_AddRefed PreserveAspectRatio(); + already_AddRefed ViewTarget(); + private: // nsSVGElement overrides diff --git a/dom/webidl/SVGFitToViewBox.webidl b/dom/webidl/SVGFitToViewBox.webidl new file mode 100644 index 00000000000..7b8450cd5ff --- /dev/null +++ b/dom/webidl/SVGFitToViewBox.webidl @@ -0,0 +1,20 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * http://www.w3.org/TR/SVG2/ + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +interface SVGAnimatedRect; + +[NoInterfaceObject] +interface SVGFitToViewBox { + readonly attribute SVGAnimatedRect viewBox; + readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; +}; + diff --git a/dom/webidl/SVGViewElement.webidl b/dom/webidl/SVGViewElement.webidl new file mode 100644 index 00000000000..b28b9b4fb5e --- /dev/null +++ b/dom/webidl/SVGViewElement.webidl @@ -0,0 +1,21 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * http://www.w3.org/TR/SVG2/ + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +interface SVGStringList; + +interface SVGViewElement : SVGElement { + readonly attribute SVGStringList viewTarget; +}; + +SVGViewElement implements SVGFitToViewBox; +SVGViewElement implements SVGZoomAndPan; + diff --git a/dom/webidl/SVGZoomAndPan.webidl b/dom/webidl/SVGZoomAndPan.webidl new file mode 100644 index 00000000000..05bc4fdeb92 --- /dev/null +++ b/dom/webidl/SVGZoomAndPan.webidl @@ -0,0 +1,24 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * http://www.w3.org/TR/SVG2/ + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +[NoInterfaceObject] +interface SVGZoomAndPan { + + // Zoom and Pan Types + const unsigned short SVG_ZOOMANDPAN_UNKNOWN = 0; + const unsigned short SVG_ZOOMANDPAN_DISABLE = 1; + const unsigned short SVG_ZOOMANDPAN_MAGNIFY = 2; + + [SetterThrows] + attribute unsigned short zoomAndPan; +}; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index e65b317f4ce..905ceb12af2 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -114,6 +114,7 @@ webidl_files = \ SVGDescElement.webidl \ SVGElement.webidl \ SVGEllipseElement.webidl \ + SVGFitToViewBox.webidl \ SVGForeignObjectElement.webidl \ SVGGElement.webidl \ SVGGraphicsElement.webidl \ @@ -149,6 +150,8 @@ webidl_files = \ SVGTransformList.webidl \ SVGTSpanElement.webidl \ SVGURIReference.webidl \ + SVGViewElement.webidl \ + SVGZoomAndPan.webidl \ Text.webidl \ TextDecoder.webidl \ TextEncoder.webidl \