Back to index

lightning-sunbird  0.9+nobinonly
nsSVGPoint.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Mozilla SVG project.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Crocodile Clips Ltd..
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
00024  *   Jonathan Watt <jonathan.watt@strath.ac.uk>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsSVGPoint.h"
00041 #include "nsIDOMSVGMatrix.h"
00042 #include "nsSVGValue.h"
00043 #include "nsContentUtils.h"
00044 #include "nsDOMError.h"
00045 
00046 class nsSVGPoint : public nsIDOMSVGPoint,
00047                    public nsSVGValue
00048 {
00049 public:
00050   nsSVGPoint(float x, float y);
00051 
00052   // nsISupports interface:
00053   NS_DECL_ISUPPORTS
00054 
00055   // nsIDOMSVGPoint interface:
00056   NS_DECL_NSIDOMSVGPOINT
00057 
00058   // nsISVGValue interface:
00059   NS_IMETHOD SetValueString(const nsAString& aValue);
00060   NS_IMETHOD GetValueString(nsAString& aValue);
00061   
00062 protected:
00063   float mX;
00064   float mY;
00065 };
00066 
00067 
00068 //----------------------------------------------------------------------
00069 // Implementation
00070 
00071 nsresult
00072 NS_NewSVGPoint(nsIDOMSVGPoint** result, float x, float y)
00073 {
00074   *result = new nsSVGPoint(x, y);
00075   if (!*result)
00076     return NS_ERROR_OUT_OF_MEMORY;
00077   NS_ADDREF(*result);
00078   return NS_OK;
00079 }
00080 
00081 nsSVGPoint::nsSVGPoint(float x, float y)
00082     : mX(x), mY(y)
00083 {
00084 }
00085 
00086 //----------------------------------------------------------------------
00087 // nsISupports methods:
00088 
00089 NS_IMPL_ADDREF(nsSVGPoint)
00090 NS_IMPL_RELEASE(nsSVGPoint)
00091 
00092 NS_INTERFACE_MAP_BEGIN(nsSVGPoint)
00093   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00094   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGPoint)
00095   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGPoint)
00096   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00097 NS_INTERFACE_MAP_END
00098 
00099 //----------------------------------------------------------------------
00100 // nsIDOMSVGPoint methods:
00101 
00102 /* attribute float x; */
00103 NS_IMETHODIMP nsSVGPoint::GetX(float *aX)
00104 {
00105   *aX = mX;
00106   return NS_OK;
00107 }
00108 NS_IMETHODIMP nsSVGPoint::SetX(float aX)
00109 {
00110   WillModify();
00111   mX = aX;
00112   DidModify();
00113   
00114   return NS_OK;
00115 }
00116 
00117 /* attribute float y; */
00118 NS_IMETHODIMP nsSVGPoint::GetY(float *aY)
00119 {
00120   *aY = mY;
00121   return NS_OK;
00122 }
00123 NS_IMETHODIMP nsSVGPoint::SetY(float aY)
00124 {
00125   WillModify();
00126   mY = aY;
00127   DidModify();
00128   
00129   return NS_OK;
00130 }
00131 
00132 /* nsIDOMSVGPoint matrixTransform (in nsIDOMSVGMatrix matrix); */
00133 NS_IMETHODIMP nsSVGPoint::MatrixTransform(nsIDOMSVGMatrix *matrix,
00134                                           nsIDOMSVGPoint **_retval)
00135 {
00136   if (!matrix)
00137     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
00138 
00139   float a, b, c, d, e, f;
00140   matrix->GetA(&a);
00141   matrix->GetB(&b);
00142   matrix->GetC(&c);
00143   matrix->GetD(&d);
00144   matrix->GetE(&e);
00145   matrix->GetF(&f);
00146   
00147   return NS_NewSVGPoint(_retval, a*mX + c*mY + e, b*mX + d*mY + f);
00148 }
00149 
00150 //----------------------------------------------------------------------
00151 // nsISVGValue methods:
00152 NS_IMETHODIMP
00153 nsSVGPoint::SetValueString(const nsAString& aValue)
00154 {
00155   NS_NOTYETIMPLEMENTED("nsSVGPoint::SetValueString");
00156   return NS_ERROR_NOT_IMPLEMENTED;
00157 }
00158 
00159 NS_IMETHODIMP
00160 nsSVGPoint::GetValueString(nsAString& aValue)
00161 {
00162   NS_NOTYETIMPLEMENTED("nsSVGPoint::GetValueString");
00163   return NS_ERROR_NOT_IMPLEMENTED;
00164 }
00165 
00166 
00167 
00169 // Implement a readonly version of SVGPoint
00170 //
00171 // We need this because attributes of some SVG interfaces *and* the objects the
00172 // attributes refer to (including SVGPoints) are supposed to be readonly
00173 
00174 class nsSVGReadonlyPoint : public nsSVGPoint
00175 {
00176 public:
00177   nsSVGReadonlyPoint(float x, float y)
00178     : nsSVGPoint(x, y)
00179   {
00180   };
00181 
00182   // override setters to make the whole object readonly
00183   NS_IMETHODIMP SetX(float) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
00184   NS_IMETHODIMP SetY(float) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
00185   NS_IMETHODIMP SetValueString(const nsAString&) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
00186 };
00187 
00188 nsresult
00189 NS_NewSVGReadonlyPoint(nsIDOMSVGPoint** result, float x, float y)
00190 {
00191   *result = new nsSVGReadonlyPoint(x, y);
00192   if (!*result)
00193     return NS_ERROR_OUT_OF_MEMORY;
00194   NS_ADDREF(*result);
00195   return NS_OK;
00196 }