Bug 388411 - Improve frame construction: make trivial constructors inline and check that content is what we expect. r+sr=tor

This commit is contained in:
longsonr%gmail.com 2007-07-25 09:16:02 +00:00
Родитель 93efbef047
Коммит 55d27d8ba0
12 изменённых файлов: 67 добавлений и 65 удалений

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

@ -53,9 +53,7 @@ NS_NewSVGGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext*
{ {
nsCOMPtr<nsIDOMSVGTransformable> transformable = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGTransformable> transformable = do_QueryInterface(aContent);
if (!transformable) { if (!transformable) {
#ifdef DEBUG NS_ERROR("Can't create frame. The element doesn't support the right interface\n");
printf("warning: trying to construct an SVGGFrame for a content element that doesn't support the right interfaces\n");
#endif
return nsnull; return nsnull;
} }

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

@ -45,10 +45,13 @@ typedef nsSVGDisplayContainerFrame nsSVGGFrameBase;
class nsSVGGFrame : public nsSVGGFrameBase class nsSVGGFrame : public nsSVGGFrameBase
{ {
public: friend nsIFrame*
NS_NewSVGGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext);
protected:
nsSVGGFrame(nsStyleContext* aContext) : nsSVGGFrame(nsStyleContext* aContext) :
nsSVGGFrameBase(aContext), mPropagateTransform(PR_TRUE) {} nsSVGGFrameBase(aContext), mPropagateTransform(PR_TRUE) {}
public:
/** /**
* Get the "type" of the frame * Get the "type" of the frame
* *
@ -63,10 +66,6 @@ public:
} }
#endif #endif
protected:
friend nsIFrame*
NS_NewSVGGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext);
// nsIFrame interface: // nsIFrame interface:
NS_IMETHOD DidSetStyleContext(); NS_IMETHOD DidSetStyleContext();
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID, NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,

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

@ -735,9 +735,10 @@ NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext) nsStyleContext* aContext)
{ {
nsCOMPtr<nsIDOMSVGLinearGradientElement> grad = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGLinearGradientElement> grad = do_QueryInterface(aContent);
NS_ASSERTION(grad, "NS_NewSVGLinearGradientFrame -- Content doesn't support nsIDOMSVGLinearGradient"); if (!grad) {
if (!grad) NS_ERROR("Can't create frame! Content is not an SVG linearGradient");
return nsnull; return nsnull;
}
nsCOMPtr<nsIDOMSVGURIReference> aRef = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGURIReference> aRef = do_QueryInterface(aContent);
NS_ASSERTION(aRef, "NS_NewSVGLinearGradientFrame -- Content doesn't support nsIDOMSVGURIReference"); NS_ASSERTION(aRef, "NS_NewSVGLinearGradientFrame -- Content doesn't support nsIDOMSVGURIReference");
@ -751,9 +752,10 @@ NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext) nsStyleContext* aContext)
{ {
nsCOMPtr<nsIDOMSVGRadialGradientElement> grad = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGRadialGradientElement> grad = do_QueryInterface(aContent);
NS_ASSERTION(grad, "NS_NewSVGRadialGradientFrame -- Content doesn't support nsIDOMSVGRadialGradient"); if (!grad) {
if (!grad) NS_ERROR("Can't create frame! Content is not an SVG radialGradient");
return nsnull; return nsnull;
}
nsCOMPtr<nsIDOMSVGURIReference> aRef = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGURIReference> aRef = do_QueryInterface(aContent);
NS_ASSERTION(aRef, "NS_NewSVGRadialGradientFrame -- Content doesn't support nsIDOMSVGURIReference"); NS_ASSERTION(aRef, "NS_NewSVGRadialGradientFrame -- Content doesn't support nsIDOMSVGURIReference");

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

@ -53,6 +53,12 @@ typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
class nsSVGGradientFrame : public nsSVGGradientFrameBase, class nsSVGGradientFrame : public nsSVGGradientFrameBase,
public nsISVGValueObserver public nsISVGValueObserver
{ {
protected:
nsSVGGradientFrame(nsStyleContext* aContext,
nsIDOMSVGURIReference *aRef);
virtual ~nsSVGGradientFrame();
public: public:
// nsSVGPaintServerFrame methods: // nsSVGPaintServerFrame methods:
virtual PRBool SetupPaintServer(gfxContext *aContext, virtual PRBool SetupPaintServer(gfxContext *aContext,
@ -128,7 +134,6 @@ private:
gfxMatrix GetGradientTransform(nsSVGGeometryFrame *aSource); gfxMatrix GetGradientTransform(nsSVGGeometryFrame *aSource);
protected: protected:
virtual already_AddRefed<gfxPattern> CreateGradient() = 0; virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
// Use these inline methods instead of GetGradientWithAttr(..., aGradType) // Use these inline methods instead of GetGradientWithAttr(..., aGradType)
@ -159,16 +164,10 @@ protected:
// Get the value of our gradientUnits attribute // Get the value of our gradientUnits attribute
PRUint16 GetGradientUnits(); PRUint16 GetGradientUnits();
nsSVGGradientFrame(nsStyleContext* aContext,
nsIDOMSVGURIReference *aRef);
virtual ~nsSVGGradientFrame();
// The graphic element our gradient is (currently) being applied to // The graphic element our gradient is (currently) being applied to
nsRefPtr<nsSVGElement> mSourceContent; nsRefPtr<nsSVGElement> mSourceContent;
private: private:
// href of the other gradient we reference (if any) // href of the other gradient we reference (if any)
nsCOMPtr<nsIDOMSVGAnimatedString> mHref; nsCOMPtr<nsIDOMSVGAnimatedString> mHref;
@ -197,11 +196,15 @@ typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
{ {
public:
friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell, friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
nsIContent* aContent, nsIContent* aContent,
nsStyleContext* aContext); nsStyleContext* aContext);
protected:
nsSVGLinearGradientFrame(nsStyleContext* aContext,
nsIDOMSVGURIReference *aRef) :
nsSVGLinearGradientFrameBase(aContext, aRef) {}
public:
// nsIFrame interface: // nsIFrame interface:
virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgLinearGradientFrame virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgLinearGradientFrame
@ -218,10 +221,6 @@ public:
#endif // DEBUG #endif // DEBUG
protected: protected:
nsSVGLinearGradientFrame(nsStyleContext* aContext,
nsIDOMSVGURIReference *aRef) :
nsSVGLinearGradientFrameBase(aContext, aRef) {}
float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName); float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName);
virtual already_AddRefed<gfxPattern> CreateGradient(); virtual already_AddRefed<gfxPattern> CreateGradient();
}; };
@ -234,11 +233,15 @@ typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
{ {
public:
friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell, friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
nsIContent* aContent, nsIContent* aContent,
nsStyleContext* aContext); nsStyleContext* aContext);
protected:
nsSVGRadialGradientFrame(nsStyleContext* aContext,
nsIDOMSVGURIReference *aRef) :
nsSVGRadialGradientFrameBase(aContext, aRef) {}
public:
// nsIFrame interface: // nsIFrame interface:
virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgRadialGradientFrame virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgRadialGradientFrame
@ -255,10 +258,6 @@ public:
#endif // DEBUG #endif // DEBUG
protected: protected:
nsSVGRadialGradientFrame(nsStyleContext* aContext,
nsIDOMSVGURIReference *aRef) :
nsSVGRadialGradientFrameBase(aContext, aRef) {}
float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName, float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName,
nsIContent *aElement = nsnull); nsIContent *aElement = nsnull);
virtual already_AddRefed<gfxPattern> CreateGradient(); virtual already_AddRefed<gfxPattern> CreateGradient();

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

@ -54,7 +54,8 @@ class nsSVGInnerSVGFrame : public nsSVGInnerSVGFrameBase,
friend nsIFrame* friend nsIFrame*
NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext); NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext);
protected: protected:
nsSVGInnerSVGFrame(nsStyleContext* aContext); nsSVGInnerSVGFrame(nsStyleContext* aContext) :
nsSVGInnerSVGFrameBase(aContext), mPropagateTransform(PR_TRUE) {}
// nsISupports interface: // nsISupports interface:
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
@ -122,15 +123,13 @@ protected:
nsIFrame* nsIFrame*
NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext) NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
{ {
return new (aPresShell) nsSVGInnerSVGFrame(aContext); nsCOMPtr<nsIDOMSVGSVGElement> svg = do_QueryInterface(aContent);
} if (!svg) {
NS_ERROR("Can't create frame! Content is not an SVG 'svg' element!");
return nsnull;
}
nsSVGInnerSVGFrame::nsSVGInnerSVGFrame(nsStyleContext* aContext) : return new (aPresShell) nsSVGInnerSVGFrame(aContext);
nsSVGInnerSVGFrameBase(aContext), mPropagateTransform(PR_TRUE)
{
#ifdef DEBUG
// printf("nsSVGInnerSVGFrame CTOR\n");
#endif
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

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

@ -38,6 +38,12 @@
class nsSVGLeafFrame : public nsFrame class nsSVGLeafFrame : public nsFrame
{ {
friend nsIFrame*
NS_NewSVGLeafFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
protected:
nsSVGLeafFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
public:
virtual PRBool IsFrameOfType(PRUint32 aFlags) const virtual PRBool IsFrameOfType(PRUint32 aFlags) const
{ {
return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG)); return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
@ -50,8 +56,6 @@ class nsSVGLeafFrame : public nsFrame
} }
#endif #endif
public:
nsSVGLeafFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
}; };
nsIFrame* nsIFrame*

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

@ -871,10 +871,10 @@ nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext) nsStyleContext* aContext)
{ {
nsCOMPtr<nsIDOMSVGPatternElement> patternElement = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGPatternElement> patternElement = do_QueryInterface(aContent);
NS_ASSERTION(patternElement, if (!patternElement) {
"NS_NewSVGPatternFrame -- Content doesn't support nsIDOMSVGPattern"); NS_ERROR("Can't create frame! Content is not an SVG pattern");
if (!patternElement)
return nsnull; return nsnull;
}
nsCOMPtr<nsIDOMSVGURIReference> ref = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGURIReference> ref = do_QueryInterface(aContent);
NS_ASSERTION(ref, NS_ASSERTION(ref,

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

@ -50,9 +50,13 @@ typedef nsFrame nsSVGStopFrameBase;
class nsSVGStopFrame : public nsSVGStopFrameBase class nsSVGStopFrame : public nsSVGStopFrameBase
{ {
public: friend nsIFrame*
NS_NewSVGStopFrame(nsIPresShell* aPresShell, nsIContent* aContent,
nsIFrame* aParentFrame, nsStyleContext* aContext);
protected:
nsSVGStopFrame(nsStyleContext* aContext) : nsSVGStopFrameBase(aContext) {} nsSVGStopFrame(nsStyleContext* aContext) : nsSVGStopFrameBase(aContext) {}
public:
// nsIFrame interface: // nsIFrame interface:
NS_IMETHOD DidSetStyleContext(); NS_IMETHOD DidSetStyleContext();
@ -79,11 +83,6 @@ public:
return MakeFrameName(NS_LITERAL_STRING("SVGStop"), aResult); return MakeFrameName(NS_LITERAL_STRING("SVGStop"), aResult);
} }
#endif #endif
friend nsIFrame* NS_NewSVGStopFrame(nsIPresShell* aPresShell,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsStyleContext* aContext);
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------

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

@ -58,10 +58,9 @@ NS_NewSVGTSpanFrame(nsIPresShell* aPresShell, nsIContent* aContent,
return nsnull; return nsnull;
} }
nsCOMPtr<nsIDOMSVGTSpanElement> tspan_elem = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGTSpanElement> tspan = do_QueryInterface(aContent);
if (!tspan_elem) { if (!tspan) {
NS_ERROR("Trying to construct an SVGTSpanFrame for a " NS_ERROR("Can't create frame! Content is not an SVG tspan");
"content element that doesn't support the right interfaces");
return nsnull; return nsnull;
} }

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

@ -87,10 +87,9 @@ NS_NewSVGTextPathFrame(nsIPresShell* aPresShell, nsIContent* aContent,
return nsnull; return nsnull;
} }
nsCOMPtr<nsIDOMSVGTextPathElement> tpath_elem = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGTextPathElement> textPath = do_QueryInterface(aContent);
if (!tpath_elem) { if (!textPath) {
NS_ERROR("Trying to construct an SVGTextPathFrame for a " NS_ERROR("Can't create frame! Content is not an SVG textPath");
"content element that doesn't support the right interfaces");
return nsnull; return nsnull;
} }
@ -186,7 +185,8 @@ nsSVGTextPathFrame::GetDy()
// nsSVGTextPathFrame methods: // nsSVGTextPathFrame methods:
nsIFrame * nsIFrame *
nsSVGTextPathFrame::GetPathFrame() { nsSVGTextPathFrame::GetPathFrame()
{
nsIFrame *path = nsnull; nsIFrame *path = nsnull;
nsAutoString str; nsAutoString str;
@ -205,7 +205,8 @@ nsSVGTextPathFrame::GetPathFrame() {
} }
already_AddRefed<gfxFlattenedPath> already_AddRefed<gfxFlattenedPath>
nsSVGTextPathFrame::GetFlattenedPath() { nsSVGTextPathFrame::GetFlattenedPath()
{
nsIFrame *path = GetPathFrame(); nsIFrame *path = GetPathFrame();
if (!path) if (!path)
return nsnull; return nsnull;

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

@ -67,9 +67,13 @@ typedef nsSVGTSpanFrame nsSVGTextPathFrameBase;
class nsSVGTextPathFrame : public nsSVGTextPathFrameBase class nsSVGTextPathFrame : public nsSVGTextPathFrameBase
{ {
public: friend nsIFrame*
NS_NewSVGTextPathFrame(nsIPresShell* aPresShell, nsIContent* aContent,
nsIFrame* parentFrame, nsStyleContext* aContext);
protected:
nsSVGTextPathFrame(nsStyleContext* aContext) : nsSVGTextPathFrameBase(aContext) {} nsSVGTextPathFrame(nsStyleContext* aContext) : nsSVGTextPathFrameBase(aContext) {}
public:
// nsIFrame: // nsIFrame:
NS_IMETHOD Init(nsIContent* aContent, NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent, nsIFrame* aParent,

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

@ -94,11 +94,9 @@ public:
nsIFrame* nsIFrame*
NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext) NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
{ {
nsCOMPtr<nsIDOMSVGTransformable> transformable = do_QueryInterface(aContent); nsCOMPtr<nsIDOMSVGUseElement> use = do_QueryInterface(aContent);
if (!transformable) { if (!use) {
#ifdef DEBUG NS_ERROR("Can't create frame! Content is not an SVG use!");
printf("warning: trying to construct an SVGUseFrame for a content element that doesn't support the right interfaces\n");
#endif
return nsnull; return nsnull;
} }