Bug 825834 - Convert SVGViewElement to webidl r=bz

This commit is contained in:
David Zbarsky 2013-01-07 22:22:41 -05:00
parent 6ce48d9fe8
commit d6949d0115
6 changed files with 122 additions and 8 deletions

View File

@ -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<nsIDOMSVGAnimatedRect>
SVGViewElement::ViewBox()
{
nsCOMPtr<nsIDOMSVGAnimatedRect> 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<DOMSVGAnimatedPreserveAspectRatio>
SVGViewElement::PreserveAspectRatio()
{
nsRefPtr<DOMSVGAnimatedPreserveAspectRatio> 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<nsIDOMSVGStringList>
SVGViewElement::ViewTarget()
{
return DOMSVGStringList::GetDOMWrapper(
&mStringListAttributes[VIEW_TARGET], this, false, VIEW_TARGET);
}
//----------------------------------------------------------------------
// nsSVGElement methods

View File

@ -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<nsINodeInfo> aNodeInfo);
friend nsresult (::NS_NewSVGViewElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> 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<nsIDOMSVGAnimatedRect> ViewBox();
already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
already_AddRefed<nsIDOMSVGStringList> ViewTarget();
private:
// nsSVGElement overrides

View File

@ -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;
};

View File

@ -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;

View File

@ -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;
};

View File

@ -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 \