/layout/svg/base/src/nsSVGPolylineFrame.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
00006  * Version 1.1 (the "License"); you may not use this file except in
00007  * compliance with 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  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or 
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the NPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ----- END LICENSE BLOCK ----- */
00038 
00039 #include "nsSVGPathGeometryFrame.h"
00040 #include "nsIDOMSVGAnimatedPoints.h"
00041 #include "nsIDOMSVGPointList.h"
00042 #include "nsIDOMSVGPoint.h"
00043 //#include "nsASVGPathBuilder.h"
00044 #include "nsISVGRendererPathBuilder.h"
00045 
00046 class nsSVGPolylineFrame : public nsSVGPathGeometryFrame
00047 {
00048 protected:
00049   friend nsresult
00050   NS_NewSVGPolylineFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame);
00051 
00052   virtual ~nsSVGPolylineFrame();
00053   virtual nsresult Init();
00054 
00055 public:
00056   // nsISVGValueObserver interface:
00057   NS_IMETHOD DidModifySVGObservable(nsISVGValue* observable);
00058 
00059   // nsISVGPathGeometrySource interface:
00060   NS_IMETHOD ConstructPath(nsISVGRendererPathBuilder *pathBuilder);
00061 
00062 //  virtual void ConstructPath(nsASVGPathBuilder* pathBuilder);
00063 
00064   nsCOMPtr<nsIDOMSVGPointList> mPoints;
00065 };
00066 
00067 //----------------------------------------------------------------------
00068 // Implementation
00069 
00070 nsresult
00071 NS_NewSVGPolylineFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame)
00072 {
00073   nsCOMPtr<nsIDOMSVGAnimatedPoints> anim_points = do_QueryInterface(aContent);
00074   if (!anim_points) {
00075 #ifdef DEBUG
00076     printf("warning: trying to construct an SVGPolylineFrame for a content element that doesn't support the right interfaces\n");
00077 #endif
00078     return NS_ERROR_FAILURE;
00079   }
00080   
00081   nsSVGPolylineFrame* it = new (aPresShell) nsSVGPolylineFrame;
00082   if (nsnull == it)
00083     return NS_ERROR_OUT_OF_MEMORY;
00084 
00085   *aNewFrame = it;
00086   return NS_OK;
00087 }
00088 
00089 nsSVGPolylineFrame::~nsSVGPolylineFrame()
00090 {
00091   nsCOMPtr<nsISVGValue> value;
00092   if (mPoints && (value = do_QueryInterface(mPoints)))
00093       value->RemoveObserver(this);
00094 }
00095 
00096 nsresult nsSVGPolylineFrame::Init()
00097 {
00098   nsresult rv = nsSVGPathGeometryFrame::Init();
00099   if (NS_FAILED(rv)) return rv;
00100   
00101   nsCOMPtr<nsIDOMSVGAnimatedPoints> anim_points = do_QueryInterface(mContent);
00102   NS_ASSERTION(anim_points,"wrong content element");
00103   anim_points->GetPoints(getter_AddRefs(mPoints));
00104   NS_ASSERTION(mPoints, "no points");
00105   if (!mPoints) return NS_ERROR_FAILURE;
00106   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mPoints);
00107   if (value)
00108     value->AddObserver(this);
00109   return NS_OK; 
00110 }  
00111 
00112 //----------------------------------------------------------------------
00113 // nsISVGValueObserver methods:
00114 
00115 NS_IMETHODIMP
00116 nsSVGPolylineFrame::DidModifySVGObservable(nsISVGValue* observable)
00117 {
00118   nsCOMPtr<nsIDOMSVGPointList> l = do_QueryInterface(observable);
00119   if (l && mPoints==l) {
00120     UpdateGraphic(nsISVGPathGeometrySource::UPDATEMASK_PATH);
00121     return NS_OK;
00122   }
00123   // else
00124   return nsSVGPathGeometryFrame::DidModifySVGObservable(observable);
00125 }
00126 
00127 //----------------------------------------------------------------------
00128 // nsISVGPathGeometrySource methods:
00129 
00130 /* void constructPath (in nsISVGRendererPathBuilder pathBuilder); */
00131 NS_IMETHODIMP nsSVGPolylineFrame::ConstructPath(nsISVGRendererPathBuilder* pathBuilder)
00132 {
00133   if (!mPoints) return NS_OK;
00134 
00135   PRUint32 count;
00136   mPoints->GetNumberOfItems(&count);
00137   if (count == 0) return NS_OK;
00138   
00139   PRUint32 i;
00140   for (i = 0; i < count; ++i) {
00141     nsCOMPtr<nsIDOMSVGPoint> point;
00142     mPoints->GetItem(i, getter_AddRefs(point));
00143 
00144     float x, y;
00145     point->GetX(&x);
00146     point->GetY(&y);
00147     if (i == 0)
00148       pathBuilder->Moveto(x, y);
00149     else
00150       pathBuilder->Lineto(x, y);
00151   }
00152 
00153   return NS_OK;
00154 }

Generated on Wed Sep 10 22:25:23 2003 for Mozilla SVG Project Rendering Backend by doxygen1.3