1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ----- BEGIN LICENSE BLOCK -----
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Mozilla SVG project.
17
* The Initial Developer of the Original Code is
18
* Crocodile Clips Ltd..
19
* Portions created by the Initial Developer are Copyright (C) 2001
20
* the Initial Developer. All Rights Reserved.
23
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
37
* ----- END LICENSE BLOCK ----- */
39
#include "nsSVGGraphicElement.h"
40
#include "nsSVGAtoms.h"
41
#include "nsIDOMSVGForeignObjectElem.h"
42
#include "nsSVGLength.h"
43
#include "nsSVGAnimatedLength.h"
45
#include "nsISVGSVGElement.h"
46
#include "nsISVGViewportAxis.h"
47
#include "nsISVGViewportRect.h"
49
typedef nsSVGGraphicElement nsSVGForeignObjectElementBase;
51
class nsSVGForeignObjectElement : public nsSVGForeignObjectElementBase,
52
public nsIDOMSVGForeignObjectElement
55
friend nsresult NS_NewSVGForeignObjectElement(nsIContent **aResult,
56
nsINodeInfo *aNodeInfo);
57
nsSVGForeignObjectElement();
58
virtual ~nsSVGForeignObjectElement();
59
nsresult Init(nsINodeInfo* aNodeInfo);
64
NS_DECL_ISUPPORTS_INHERITED
65
NS_DECL_NSIDOMSVGFOREIGNOBJECTELEMENT
67
// xxx I wish we could use virtual inheritance
68
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGForeignObjectElementBase::)
69
NS_FORWARD_NSIDOMELEMENT(nsSVGForeignObjectElementBase::)
70
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGForeignObjectElementBase::)
72
// nsISVGContent specializations:
73
virtual void ParentChainChanged();
77
nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
78
nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
79
nsCOMPtr<nsIDOMSVGAnimatedLength> mWidth;
80
nsCOMPtr<nsIDOMSVGAnimatedLength> mHeight;
84
nsresult NS_NewSVGForeignObjectElement(nsIContent **aResult, nsINodeInfo *aNodeInfo)
87
nsSVGForeignObjectElement* it = new nsSVGForeignObjectElement();
89
if (!it) return NS_ERROR_OUT_OF_MEMORY;
92
nsresult rv = it->Init(aNodeInfo);
104
//----------------------------------------------------------------------
105
// nsISupports methods
107
NS_IMPL_ADDREF_INHERITED(nsSVGForeignObjectElement,nsSVGForeignObjectElementBase)
108
NS_IMPL_RELEASE_INHERITED(nsSVGForeignObjectElement,nsSVGForeignObjectElementBase)
110
NS_INTERFACE_MAP_BEGIN(nsSVGForeignObjectElement)
111
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
112
NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
113
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
114
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGForeignObjectElement)
115
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGForeignObjectElement)
116
NS_INTERFACE_MAP_END_INHERITING(nsSVGForeignObjectElementBase)
118
//----------------------------------------------------------------------
121
nsSVGForeignObjectElement::nsSVGForeignObjectElement()
126
nsSVGForeignObjectElement::~nsSVGForeignObjectElement()
132
nsSVGForeignObjectElement::Init(nsINodeInfo* aNodeInfo)
134
nsresult rv = nsSVGForeignObjectElementBase::Init(aNodeInfo);
135
NS_ENSURE_SUCCESS(rv,rv);
137
// Create mapped properties:
140
// DOM property: x , #IMPLIED attrib: x
142
nsCOMPtr<nsISVGLength> length;
143
rv = NS_NewSVGLength(getter_AddRefs(length),
145
NS_ENSURE_SUCCESS(rv,rv);
146
rv = NS_NewSVGAnimatedLength(getter_AddRefs(mX), length);
147
NS_ENSURE_SUCCESS(rv,rv);
148
rv = AddMappedSVGValue(nsSVGAtoms::x, mX);
149
NS_ENSURE_SUCCESS(rv,rv);
152
// DOM property: y , #IMPLIED attrib: y
154
nsCOMPtr<nsISVGLength> length;
155
rv = NS_NewSVGLength(getter_AddRefs(length),
157
NS_ENSURE_SUCCESS(rv,rv);
158
rv = NS_NewSVGAnimatedLength(getter_AddRefs(mY), length);
159
NS_ENSURE_SUCCESS(rv,rv);
160
rv = AddMappedSVGValue(nsSVGAtoms::y, mY);
161
NS_ENSURE_SUCCESS(rv,rv);
164
// DOM property: width , #REQUIRED attrib: width
165
// XXX: enforce requiredness
167
nsCOMPtr<nsISVGLength> length;
168
rv = NS_NewSVGLength(getter_AddRefs(length),
170
NS_ENSURE_SUCCESS(rv,rv);
171
rv = NS_NewSVGAnimatedLength(getter_AddRefs(mWidth), length);
172
NS_ENSURE_SUCCESS(rv,rv);
173
rv = AddMappedSVGValue(nsSVGAtoms::width, mWidth);
174
NS_ENSURE_SUCCESS(rv,rv);
177
// DOM property: height , #REQUIRED attrib: height
178
// XXX: enforce requiredness
180
nsCOMPtr<nsISVGLength> length;
181
rv = NS_NewSVGLength(getter_AddRefs(length),
183
NS_ENSURE_SUCCESS(rv,rv);
184
rv = NS_NewSVGAnimatedLength(getter_AddRefs(mHeight), length);
185
NS_ENSURE_SUCCESS(rv,rv);
186
rv = AddMappedSVGValue(nsSVGAtoms::height, mHeight);
187
NS_ENSURE_SUCCESS(rv,rv);
194
//----------------------------------------------------------------------
195
// nsIDOMNode methods
198
nsSVGForeignObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
201
nsSVGForeignObjectElement* it = new nsSVGForeignObjectElement();
203
if (!it) return NS_ERROR_OUT_OF_MEMORY;
206
nsresult rv = it->Init(mNodeInfo);
213
rv = CopyNode(it, aDeep);
225
//----------------------------------------------------------------------
226
// nsIDOMSVGForeignObjectElement methods:
228
/* readonly attribute nsIDOMSVGAnimatedLength x; */
229
NS_IMETHODIMP nsSVGForeignObjectElement::GetX(nsIDOMSVGAnimatedLength * *aX)
236
/* readonly attribute nsIDOMSVGAnimatedLength y; */
237
NS_IMETHODIMP nsSVGForeignObjectElement::GetY(nsIDOMSVGAnimatedLength * *aY)
244
/* readonly attribute nsIDOMSVGAnimatedLength width; */
245
NS_IMETHODIMP nsSVGForeignObjectElement::GetWidth(nsIDOMSVGAnimatedLength * *aWidth)
248
NS_IF_ADDREF(*aWidth);
252
/* readonly attribute nsIDOMSVGAnimatedLength height; */
253
NS_IMETHODIMP nsSVGForeignObjectElement::GetHeight(nsIDOMSVGAnimatedLength * *aHeight)
256
NS_IF_ADDREF(*aHeight);
260
//----------------------------------------------------------------------
261
// nsISVGContent methods
263
void nsSVGForeignObjectElement::ParentChainChanged()
265
// set new context information on our length-properties:
267
nsCOMPtr<nsIDOMSVGSVGElement> dom_elem;
268
GetOwnerSVGElement(getter_AddRefs(dom_elem));
269
if (!dom_elem) return;
271
nsCOMPtr<nsISVGSVGElement> svg_elem = do_QueryInterface(dom_elem);
272
NS_ASSERTION(svg_elem, "<svg> element missing interface");
276
nsCOMPtr<nsIDOMSVGLength> dom_length;
277
mX->GetBaseVal(getter_AddRefs(dom_length));
278
nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
279
NS_ASSERTION(length, "svg length missing interface");
281
nsCOMPtr<nsIDOMSVGRect> vp_dom;
282
svg_elem->GetViewport(getter_AddRefs(vp_dom));
283
nsCOMPtr<nsISVGViewportRect> vp = do_QueryInterface(vp_dom);
284
nsCOMPtr<nsISVGViewportAxis> ctx;
285
vp->GetXAxis(getter_AddRefs(ctx));
287
length->SetContext(ctx);
292
nsCOMPtr<nsIDOMSVGLength> dom_length;
293
mY->GetBaseVal(getter_AddRefs(dom_length));
294
nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
295
NS_ASSERTION(length, "svg length missing interface");
297
nsCOMPtr<nsIDOMSVGRect> vp_dom;
298
svg_elem->GetViewport(getter_AddRefs(vp_dom));
299
nsCOMPtr<nsISVGViewportRect> vp = do_QueryInterface(vp_dom);
300
nsCOMPtr<nsISVGViewportAxis> ctx;
301
vp->GetYAxis(getter_AddRefs(ctx));
303
length->SetContext(ctx);
308
nsCOMPtr<nsIDOMSVGLength> dom_length;
309
mWidth->GetBaseVal(getter_AddRefs(dom_length));
310
nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
311
NS_ASSERTION(length, "svg length missing interface");
313
nsCOMPtr<nsIDOMSVGRect> vp_dom;
314
svg_elem->GetViewport(getter_AddRefs(vp_dom));
315
nsCOMPtr<nsISVGViewportRect> vp = do_QueryInterface(vp_dom);
316
nsCOMPtr<nsISVGViewportAxis> ctx;
317
vp->GetXAxis(getter_AddRefs(ctx));
319
length->SetContext(ctx);
324
nsCOMPtr<nsIDOMSVGLength> dom_length;
325
mHeight->GetBaseVal(getter_AddRefs(dom_length));
326
nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
327
NS_ASSERTION(length, "svg length missing interface");
329
nsCOMPtr<nsIDOMSVGRect> vp_dom;
330
svg_elem->GetViewport(getter_AddRefs(vp_dom));
331
nsCOMPtr<nsISVGViewportRect> vp = do_QueryInterface(vp_dom);
332
nsCOMPtr<nsISVGViewportAxis> ctx;
333
vp->GetYAxis(getter_AddRefs(ctx));
335
length->SetContext(ctx);