more fixes for getting the path work started

This commit is contained in:
rods%netscape.com 2000-05-15 21:38:47 +00:00
Родитель d4ebed6269
Коммит 4d9e613c83
3 изменённых файлов: 310 добавлений и 8 удалений

Просмотреть файл

@ -57,9 +57,246 @@ NS_NewSVGPathFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
return NS_OK;
}
NS_METHOD nsSVGPathFrame::RenderPoints(nsIRenderingContext& aRenderingContext,
const nsPoint aPoints[], PRInt32 aNumPoints)
// static NS_DEFINE_IID(kDefSVGPathCID, NS_DEFCOLORPICKER_CID);
//
// nsSVGPathFrame cntr
//
nsSVGPathFrame::nsSVGPathFrame() :
mPath(nsnull),
mX(0),
mY(0)
{
// draw path here
}
nsSVGPathFrame::~nsSVGPathFrame()
{
if (mPath) {
delete mPath;
}
}
NS_IMETHODIMP
nsSVGPathFrame::Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
nsAutoString type;
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, type);
if (type.EqualsIgnoreCase(NS_ConvertASCIItoUCS2("swatch")) || type.IsEmpty())
{
//mSVGPath = new nsStdSVGPath();
//mSVGPath->Init(mContent);
}
return rv;
}
//--------------------------------------------------------------
// Frames are not refcounted, no need to AddRef
NS_IMETHODIMP
nsSVGPathFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(NS_GET_IID(nsISVGFrame))) {
*aInstancePtr = (void*) ((nsISVGFrame*) this);
return NS_OK;
}
return nsLeafFrame::QueryInterface(aIID, aInstancePtr);
}
//-------------------------------------------------------------------
//-- Main Reflow for the SVGPath
//-------------------------------------------------------------------
NS_IMETHODIMP
nsSVGPathFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
aStatus = NS_FRAME_COMPLETE;
nsCOMPtr<nsIDeviceContext> dx;
aPresContext->GetDeviceContext(getter_AddRefs(dx));
float p2t = 1.0;
float scale = 1.0;
if (dx) {
aPresContext->GetPixelsToTwips(&p2t);
dx->GetCanonicalPixelScale(scale);
}
nsAutoString coordStr;
nsresult res = mContent->GetAttribute(kNameSpaceID_None, nsSVGAtoms::x, coordStr);
if (NS_SUCCEEDED(res)) {
char * s = coordStr.ToNewCString();
mX = NSIntPixelsToTwips(atoi(s), p2t*scale);
delete [] s;
}
res = mContent->GetAttribute(kNameSpaceID_None, nsSVGAtoms::y, coordStr);
if (NS_SUCCEEDED(res)) {
char * s = coordStr.ToNewCString();
mY = NSIntPixelsToTwips(atoi(s), p2t*scale);
delete [] s;
}
nsAutoString pathStr;
res = mContent->GetAttribute(kNameSpaceID_None, nsSVGAtoms::d, pathStr);
if (NS_SUCCEEDED(res)) {
char * s = pathStr.ToNewCString();
// parse path commands here
delete [] s;
}
// Create Path object here;
//mPath = new nsPathObject();
//
// iterate thru path commands here and load up path
// calculate the rect the the path owns
//aDesiredSize.width = maxWidth + nscoord(p2t*scale);
//aDesiredSize.height = maxHeight + nscoord(p2t*scale);
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
if (nsnull != aDesiredSize.maxElementSize) {
aDesiredSize.maxElementSize->width = aDesiredSize.width;
aDesiredSize.maxElementSize->height = aDesiredSize.height;
}
return NS_OK;
}
NS_IMETHODIMP
nsSVGPathFrame::HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
*aEventStatus = nsEventStatus_eConsumeDoDefault;
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN)
HandleMouseDownEvent(aPresContext, aEvent, aEventStatus);
return NS_OK;
}
nsresult
nsSVGPathFrame::HandleMouseDownEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
return NS_OK;
}
NS_IMETHODIMP nsSVGPathFrame::SetProperty(nsIPresContext* aPresContext,
nsIAtom* aName,
const nsString& aValue)
{
if (aName == nsSVGAtoms::d) {
}
return NS_OK;
}
NS_IMETHODIMP
nsSVGPathFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
return nsLeafFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
//
// Paint
//
//
NS_METHOD
nsSVGPathFrame::Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
// if we aren't visible then we are done.
if (!disp->IsVisibleOrCollapsed())
return NS_OK;
// if we are visible then tell our superclass to paint
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,
aWhichLayer);
// get our border
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
nsMargin border(0,0,0,0);
spacing->CalcBorderFor(this, border);
// XXX - Color needs to comes from new style property fill
// and not mColor
const nsStyleColor* colorStyle = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
nscolor color = colorStyle->mColor;
aRenderingContext.PushState();
// set the clip region
nsRect rect;
PRBool clipState;
GetRect(rect);
// Clip so we don't render outside the inner rect
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipState);
aRenderingContext.SetColor(color);
///////////////////////////////////////////
// XXX - This is all just a quick hack
// needs to be rewritten
nsCOMPtr<nsIDeviceContext> dx;
aPresContext->GetDeviceContext(getter_AddRefs(dx));
float p2t = 1.0;
float scale = 1.0;
if (dx) {
aPresContext->GetPixelsToTwips(&p2t);
dx->GetCanonicalPixelScale(scale);
}
// render path here
aRenderingContext.PopState(clipState);
return NS_OK;
}
//
// GetDesiredSize
//
// For now, be as big as CSS wants us to be, or some small default size.
//
void
nsSVGPathFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{
NS_ASSERTION(0, "Who called this? and Why?");
} // GetDesiredSize

Просмотреть файл

@ -28,7 +28,12 @@
#define nsSVGPathFrame_h__
#include "nsPolygonFrame.h"
#include "nsLeafFrame.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
#include "nsISVGFrame.h"
class nsString;
@ -41,11 +46,69 @@ nsresult NS_NewSVGPathFrame(nsIPresShell* aPresShell, nsIFrame** aResult) ;
// we really want to create our own container class from the nsIFrame
// interface and not derive from any HTML Frames
// XXX - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
class nsSVGPathFrame : public nsPolygonFrame
class nsSVGPathFrame : public nsLeafFrame, public nsISVGFrame
{
NS_IMETHOD RenderPoints(nsIRenderingContext& aRenderingContext,
const nsPoint aPoints[], PRInt32 aNumPoints);
public:
nsSVGPathFrame();
virtual ~nsSVGPathFrame();
NS_IMETHOD Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD Reflow(nsIPresContext* aCX,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
// nsISVGFrame
NS_IMETHOD GetXY(nscoord* aX, nscoord* aY) { *aX = mX; *aY = mY; return NS_OK; }
// nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("SVGPathFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
nsresult HandleMouseDownEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
NS_IMETHOD Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue);
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize) ;
nscoord mX;
nscoord mY;
// make this a path object
void * mPath;
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
}; // class nsSVGPathFrame
#endif

Просмотреть файл

@ -41,6 +41,7 @@
******/
// tags
SVG_ATOM(path, "path")
SVG_ATOM(polygon, "polygon")
SVG_ATOM(polyline, "polyline")
SVG_ATOM(rect, "rect")
@ -55,3 +56,4 @@ SVG_ATOM(points, "points")
SVG_ATOM(x, "x")
SVG_ATOM(y, "y")
SVG_ATOM(fill, "fill")
SVG_ATOM(d, "d")