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 Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * 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 : * Jonathan Watt <jonathan.watt@strath.ac.uk>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsSVGRect.h"
41 : #include "prdtoa.h"
42 : #include "nsTextFormatter.h"
43 : #include "nsCRT.h"
44 : #include "nsIDOMSVGLength.h"
45 : #include "nsContentUtils.h"
46 : #include "nsDOMError.h"
47 :
48 : //----------------------------------------------------------------------
49 : // implementation:
50 :
51 0 : nsSVGRect::nsSVGRect(float x, float y, float w, float h)
52 0 : : mX(x), mY(y), mWidth(w), mHeight(h)
53 : {
54 0 : }
55 :
56 : //----------------------------------------------------------------------
57 : // nsISupports methods:
58 :
59 0 : NS_IMPL_ADDREF(nsSVGRect)
60 0 : NS_IMPL_RELEASE(nsSVGRect)
61 :
62 : DOMCI_DATA(SVGRect, nsSVGRect)
63 :
64 0 : NS_INTERFACE_MAP_BEGIN(nsSVGRect)
65 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMSVGRect)
66 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGRect)
67 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
68 0 : NS_INTERFACE_MAP_END
69 :
70 : //----------------------------------------------------------------------
71 : // nsIDOMSVGRect methods:
72 :
73 : /* attribute float x; */
74 0 : NS_IMETHODIMP nsSVGRect::GetX(float *aX)
75 : {
76 0 : *aX = mX;
77 0 : return NS_OK;
78 : }
79 0 : NS_IMETHODIMP nsSVGRect::SetX(float aX)
80 : {
81 0 : NS_ENSURE_FINITE(aX, NS_ERROR_ILLEGAL_VALUE);
82 0 : mX = aX;
83 0 : return NS_OK;
84 : }
85 :
86 : /* attribute float y; */
87 0 : NS_IMETHODIMP nsSVGRect::GetY(float *aY)
88 : {
89 0 : *aY = mY;
90 0 : return NS_OK;
91 : }
92 0 : NS_IMETHODIMP nsSVGRect::SetY(float aY)
93 : {
94 0 : NS_ENSURE_FINITE(aY, NS_ERROR_ILLEGAL_VALUE);
95 0 : mY = aY;
96 0 : return NS_OK;
97 : }
98 :
99 : /* attribute float width; */
100 0 : NS_IMETHODIMP nsSVGRect::GetWidth(float *aWidth)
101 : {
102 0 : *aWidth = mWidth;
103 0 : return NS_OK;
104 : }
105 0 : NS_IMETHODIMP nsSVGRect::SetWidth(float aWidth)
106 : {
107 0 : NS_ENSURE_FINITE(aWidth, NS_ERROR_ILLEGAL_VALUE);
108 0 : mWidth = aWidth;
109 0 : return NS_OK;
110 : }
111 :
112 : /* attribute float height; */
113 0 : NS_IMETHODIMP nsSVGRect::GetHeight(float *aHeight)
114 : {
115 0 : *aHeight = mHeight;
116 0 : return NS_OK;
117 : }
118 0 : NS_IMETHODIMP nsSVGRect::SetHeight(float aHeight)
119 : {
120 0 : NS_ENSURE_FINITE(aHeight, NS_ERROR_ILLEGAL_VALUE);
121 0 : mHeight = aHeight;
122 0 : return NS_OK;
123 : }
124 :
125 :
126 :
127 : ////////////////////////////////////////////////////////////////////////
128 : // Exported creation functions:
129 :
130 : nsresult
131 0 : NS_NewSVGRect(nsIDOMSVGRect** result, float x, float y,
132 : float width, float height)
133 : {
134 0 : *result = new nsSVGRect(x, y, width, height);
135 0 : if (!*result) return NS_ERROR_OUT_OF_MEMORY;
136 0 : NS_ADDREF(*result);
137 0 : return NS_OK;
138 : }
139 :
140 : nsresult
141 0 : NS_NewSVGRect(nsIDOMSVGRect** result, const gfxRect& rect)
142 : {
143 : return NS_NewSVGRect(result,
144 0 : rect.X(), rect.Y(),
145 0 : rect.Width(), rect.Height());
146 : }
147 :
|