~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/content/svg/content/src/nsSVGForeignObjectElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is the Mozilla SVG project.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *    Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
 
24
 *
 
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.
 
36
 *
 
37
 * ----- END LICENSE BLOCK ----- */
 
38
 
 
39
#include "nsSVGGraphicElement.h"
 
40
#include "nsSVGAtoms.h"
 
41
#include "nsIDOMSVGForeignObjectElem.h"
 
42
#include "nsSVGLength.h"
 
43
#include "nsSVGAnimatedLength.h"
 
44
#include "nsCOMPtr.h"
 
45
#include "nsISVGSVGElement.h"
 
46
#include "nsISVGViewportAxis.h"
 
47
#include "nsISVGViewportRect.h"
 
48
 
 
49
typedef nsSVGGraphicElement nsSVGForeignObjectElementBase;
 
50
 
 
51
class nsSVGForeignObjectElement : public nsSVGForeignObjectElementBase,
 
52
                                  public nsIDOMSVGForeignObjectElement
 
53
{
 
54
protected:
 
55
  friend nsresult NS_NewSVGForeignObjectElement(nsIContent **aResult,
 
56
                                                nsINodeInfo *aNodeInfo);
 
57
  nsSVGForeignObjectElement();
 
58
  virtual ~nsSVGForeignObjectElement();
 
59
  nsresult Init(nsINodeInfo* aNodeInfo);
 
60
  
 
61
public:
 
62
  // interfaces:
 
63
  
 
64
  NS_DECL_ISUPPORTS_INHERITED
 
65
  NS_DECL_NSIDOMSVGFOREIGNOBJECTELEMENT
 
66
 
 
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::)
 
71
 
 
72
  // nsISVGContent specializations:
 
73
  virtual void ParentChainChanged();
 
74
 
 
75
protected:
 
76
  
 
77
  nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
 
78
  nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
 
79
  nsCOMPtr<nsIDOMSVGAnimatedLength> mWidth;
 
80
  nsCOMPtr<nsIDOMSVGAnimatedLength> mHeight;
 
81
};
 
82
 
 
83
 
 
84
nsresult NS_NewSVGForeignObjectElement(nsIContent **aResult, nsINodeInfo *aNodeInfo)
 
85
{
 
86
  *aResult = nsnull;
 
87
  nsSVGForeignObjectElement* it = new nsSVGForeignObjectElement();
 
88
 
 
89
  if (!it) return NS_ERROR_OUT_OF_MEMORY;
 
90
  NS_ADDREF(it);
 
91
 
 
92
  nsresult rv = it->Init(aNodeInfo);
 
93
 
 
94
  if (NS_FAILED(rv)) {
 
95
    it->Release();
 
96
    return rv;
 
97
  }
 
98
  
 
99
  *aResult = it;
 
100
 
 
101
  return NS_OK;
 
102
}
 
103
 
 
104
//----------------------------------------------------------------------
 
105
// nsISupports methods
 
106
 
 
107
NS_IMPL_ADDREF_INHERITED(nsSVGForeignObjectElement,nsSVGForeignObjectElementBase)
 
108
NS_IMPL_RELEASE_INHERITED(nsSVGForeignObjectElement,nsSVGForeignObjectElementBase)
 
109
 
 
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)
 
117
 
 
118
//----------------------------------------------------------------------
 
119
// Implementation
 
120
 
 
121
nsSVGForeignObjectElement::nsSVGForeignObjectElement()
 
122
{
 
123
 
 
124
}
 
125
 
 
126
nsSVGForeignObjectElement::~nsSVGForeignObjectElement()
 
127
{
 
128
}
 
129
 
 
130
  
 
131
nsresult
 
132
nsSVGForeignObjectElement::Init(nsINodeInfo* aNodeInfo)
 
133
{
 
134
  nsresult rv = nsSVGForeignObjectElementBase::Init(aNodeInfo);
 
135
  NS_ENSURE_SUCCESS(rv,rv);
 
136
 
 
137
  // Create mapped properties:
 
138
  
 
139
 
 
140
  // DOM property: x ,  #IMPLIED attrib: x
 
141
  {
 
142
    nsCOMPtr<nsISVGLength> length;
 
143
    rv = NS_NewSVGLength(getter_AddRefs(length),
 
144
                         0.0f);
 
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);
 
150
  }
 
151
 
 
152
  // DOM property: y ,  #IMPLIED attrib: y
 
153
  {
 
154
    nsCOMPtr<nsISVGLength> length;
 
155
    rv = NS_NewSVGLength(getter_AddRefs(length),
 
156
                         0.0f);
 
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);
 
162
  }
 
163
 
 
164
  // DOM property: width ,  #REQUIRED  attrib: width
 
165
  // XXX: enforce requiredness
 
166
  {
 
167
    nsCOMPtr<nsISVGLength> length;
 
168
    rv = NS_NewSVGLength(getter_AddRefs(length),
 
169
                         100.0f);
 
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);
 
175
  }
 
176
 
 
177
  // DOM property: height ,  #REQUIRED  attrib: height
 
178
  // XXX: enforce requiredness
 
179
  {
 
180
    nsCOMPtr<nsISVGLength> length;
 
181
    rv = NS_NewSVGLength(getter_AddRefs(length),
 
182
                         100.0f);
 
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);
 
188
  }
 
189
  
 
190
    
 
191
  return NS_OK;
 
192
}
 
193
 
 
194
//----------------------------------------------------------------------
 
195
// nsIDOMNode methods
 
196
 
 
197
NS_IMETHODIMP
 
198
nsSVGForeignObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
 
199
{
 
200
  *aReturn = nsnull;
 
201
  nsSVGForeignObjectElement* it = new nsSVGForeignObjectElement();
 
202
 
 
203
  if (!it) return NS_ERROR_OUT_OF_MEMORY;
 
204
  NS_ADDREF(it);
 
205
 
 
206
  nsresult rv = it->Init(mNodeInfo);
 
207
 
 
208
  if (NS_FAILED(rv)) {
 
209
    it->Release();
 
210
    return rv;
 
211
  }
 
212
 
 
213
  rv = CopyNode(it, aDeep);
 
214
 
 
215
  if (NS_FAILED(rv)) {
 
216
    it->Release();
 
217
    return rv;
 
218
  }
 
219
 
 
220
  *aReturn = it;
 
221
 
 
222
  return NS_OK; 
 
223
}
 
224
 
 
225
//----------------------------------------------------------------------
 
226
// nsIDOMSVGForeignObjectElement methods:
 
227
 
 
228
/* readonly attribute nsIDOMSVGAnimatedLength x; */
 
229
NS_IMETHODIMP nsSVGForeignObjectElement::GetX(nsIDOMSVGAnimatedLength * *aX)
 
230
{
 
231
  *aX = mX;
 
232
  NS_IF_ADDREF(*aX);
 
233
  return NS_OK;
 
234
}
 
235
 
 
236
/* readonly attribute nsIDOMSVGAnimatedLength y; */
 
237
NS_IMETHODIMP nsSVGForeignObjectElement::GetY(nsIDOMSVGAnimatedLength * *aY)
 
238
{
 
239
  *aY = mY;
 
240
  NS_IF_ADDREF(*aY);
 
241
  return NS_OK;
 
242
}
 
243
 
 
244
/* readonly attribute nsIDOMSVGAnimatedLength width; */
 
245
NS_IMETHODIMP nsSVGForeignObjectElement::GetWidth(nsIDOMSVGAnimatedLength * *aWidth)
 
246
{
 
247
  *aWidth = mWidth;
 
248
  NS_IF_ADDREF(*aWidth);
 
249
  return NS_OK;
 
250
}
 
251
 
 
252
/* readonly attribute nsIDOMSVGAnimatedLength height; */
 
253
NS_IMETHODIMP nsSVGForeignObjectElement::GetHeight(nsIDOMSVGAnimatedLength * *aHeight)
 
254
{
 
255
  *aHeight = mHeight;
 
256
  NS_IF_ADDREF(*aHeight);
 
257
  return NS_OK;
 
258
}
 
259
 
 
260
//----------------------------------------------------------------------
 
261
// nsISVGContent methods
 
262
 
 
263
void nsSVGForeignObjectElement::ParentChainChanged()
 
264
{
 
265
  // set new context information on our length-properties:
 
266
  
 
267
  nsCOMPtr<nsIDOMSVGSVGElement> dom_elem;
 
268
  GetOwnerSVGElement(getter_AddRefs(dom_elem));
 
269
  if (!dom_elem) return;
 
270
 
 
271
  nsCOMPtr<nsISVGSVGElement> svg_elem = do_QueryInterface(dom_elem);
 
272
  NS_ASSERTION(svg_elem, "<svg> element missing interface");
 
273
 
 
274
  // x:
 
275
  {
 
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");
 
280
 
 
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));
 
286
    
 
287
    length->SetContext(ctx);
 
288
  }
 
289
 
 
290
  // y:
 
291
  {
 
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");
 
296
 
 
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));
 
302
    
 
303
    length->SetContext(ctx);
 
304
  }
 
305
 
 
306
  // width:
 
307
  {
 
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");
 
312
 
 
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));
 
318
    
 
319
    length->SetContext(ctx);
 
320
  }
 
321
 
 
322
  // height:
 
323
  {
 
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");
 
328
 
 
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));
 
334
    
 
335
    length->SetContext(ctx);
 
336
  }
 
337
}