00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "nsSVGPathGeometryFrame.h"
00040 #include "nsIDOMSVGAnimatedPoints.h"
00041 #include "nsIDOMSVGPointList.h"
00042 #include "nsIDOMSVGPoint.h"
00043
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
00057 NS_IMETHOD DidModifySVGObservable(nsISVGValue* observable);
00058
00059
00060 NS_IMETHOD ConstructPath(nsISVGRendererPathBuilder *pathBuilder);
00061
00062
00063
00064 nsCOMPtr<nsIDOMSVGPointList> mPoints;
00065 };
00066
00067
00068
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
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
00124 return nsSVGPathGeometryFrame::DidModifySVGObservable(observable);
00125 }
00126
00127
00128
00129
00130
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 }