From 80a8cf92b68adc7b99297559583094902983db64 Mon Sep 17 00:00:00 2001 From: "cvshook%sicking.cc" Date: Wed, 25 Jan 2006 21:16:12 +0000 Subject: [PATCH] Bug 310436: Implement IsFrameOfType and use that to disable non-svg frames from being children of svg frames. r=bz sr=dbaron --- layout/base/nsCSSFrameConstructor.cpp | 13 +++++++++++++ layout/generic/nsIFrame.h | 19 +++++++++++++++++++ .../base/src/nsMathMLContainerFrame.cpp | 6 ++++++ .../mathml/base/src/nsMathMLContainerFrame.h | 1 + .../mathml/base/src/nsMathMLmtableFrame.cpp | 19 +++++++++++++++++++ layout/mathml/base/src/nsMathMLmtableFrame.h | 4 ++++ layout/svg/base/src/nsSVGDefsFrame.cpp | 6 ++++++ layout/svg/base/src/nsSVGDefsFrame.h | 1 + .../svg/base/src/nsSVGForeignObjectFrame.cpp | 7 +++++++ .../base/src/nsSVGGenericContainerFrame.cpp | 5 +++++ .../svg/base/src/nsSVGGenericContainerFrame.h | 1 + layout/svg/base/src/nsSVGGlyphFrame.cpp | 7 +++++++ layout/svg/base/src/nsSVGInnerSVGFrame.cpp | 7 +++++++ layout/svg/base/src/nsSVGOuterSVGFrame.cpp | 7 +++++++ .../svg/base/src/nsSVGPathGeometryFrame.cpp | 6 ++++++ layout/svg/base/src/nsSVGPathGeometryFrame.h | 1 + layout/svg/base/src/nsSVGPatternFrame.cpp | 7 +++++++ layout/svg/base/src/nsSVGStopFrame.cpp | 7 +++++++ layout/svg/base/src/nsSVGTSpanFrame.cpp | 6 ++++++ layout/svg/base/src/nsSVGTSpanFrame.h | 1 + layout/svg/base/src/nsSVGTextFrame.cpp | 7 +++++++ 21 files changed, 138 insertions(+) diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 944f98509dc..e5e2601a58a 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -8050,6 +8050,19 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsFrameConstructorState& aState, return NS_OK; } +#ifdef MOZ_SVG + // Don't create frames for non-SVG children of SVG elements + if (aNameSpaceID != kNameSpaceID_SVG && + aParentFrame && + aParentFrame->IsFrameOfType(nsIFrame::eSVG) +#ifdef MOZ_SVG_FOREIGNOBJECT + && !aParentFrame->IsFrameOfType(nsIFrame::eSVGForeignObject) +#endif + ) { + return NS_OK; + } +#endif + nsIFrame* adjParentFrame = aParentFrame; nsFrameItems* frameItems = &aFrameItems; PRBool pseudoParent = PR_FALSE; diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index d137e45132d..5f139492221 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -1057,6 +1057,25 @@ public: */ virtual nsIAtom* GetType() const = 0; + + /** + * Bit-flags to pass to IsFrameOfType() + */ + enum { + eMathML = 1 << 0, + eSVG = 1 << 1, + eSVGForeignObject = 1 << 2 + }; + + /** + * API for doing a quick check if a frame is of a given + * type. Returns true if the frame matches ALL flags passed in. + */ + virtual PRBool IsFrameOfType(PRUint32 aFlags) const + { + return !aFlags; + } + /** * Is this frame a containing block for non-positioned elements? */ diff --git a/layout/mathml/base/src/nsMathMLContainerFrame.cpp b/layout/mathml/base/src/nsMathMLContainerFrame.cpp index a6312ea8b63..ed4cca1f57d 100644 --- a/layout/mathml/base/src/nsMathMLContainerFrame.cpp +++ b/layout/mathml/base/src/nsMathMLContainerFrame.cpp @@ -1177,6 +1177,12 @@ nsMathMLContainerFrame::GetType() const return nsMathMLAtoms::ordinaryMathMLFrame; } +PRBool +nsMathMLContainerFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eMathML); +} + enum eMathMLFrameType { eMathMLFrameType_UNKNOWN = -1, eMathMLFrameType_Ordinary, diff --git a/layout/mathml/base/src/nsMathMLContainerFrame.h b/layout/mathml/base/src/nsMathMLContainerFrame.h index bbc2f3950a0..0ae43e15306 100644 --- a/layout/mathml/base/src/nsMathMLContainerFrame.h +++ b/layout/mathml/base/src/nsMathMLContainerFrame.h @@ -116,6 +116,7 @@ public: // Overloaded nsHTMLContainerFrame methods -- see documentation in nsIFrame.h virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; NS_IMETHOD Init(nsPresContext* aPresContext, diff --git a/layout/mathml/base/src/nsMathMLmtableFrame.cpp b/layout/mathml/base/src/nsMathMLmtableFrame.cpp index 9e922640d98..00019de3f28 100644 --- a/layout/mathml/base/src/nsMathMLmtableFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmtableFrame.cpp @@ -571,6 +571,12 @@ nsMathMLmtableOuterFrame::Reflow(nsPresContext* aPresContext, return rv; } +PRBool +nsMathMLmtableOuterFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eMathML); +} + // -------- // implementation of nsMathMLmtdFrame @@ -622,6 +628,12 @@ nsMathMLmtdFrame::GetColSpan() return colspan; } +PRBool +nsMathMLmtdFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eMathML); +} + // -------- // implementation of nsMathMLmtdInnerFrame @@ -676,3 +688,10 @@ nsMathMLmtdInnerFrame::Reflow(nsPresContext* aPresContext, // ... return rv; } + +PRBool +nsMathMLmtdInnerFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eMathML); +} + diff --git a/layout/mathml/base/src/nsMathMLmtableFrame.h b/layout/mathml/base/src/nsMathMLmtableFrame.h index 73bfd29da78..ee182adaa40 100644 --- a/layout/mathml/base/src/nsMathMLmtableFrame.h +++ b/layout/mathml/base/src/nsMathMLmtableFrame.h @@ -92,6 +92,8 @@ public: const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus); + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; + protected: nsMathMLmtableOuterFrame(); virtual ~nsMathMLmtableOuterFrame(); @@ -116,6 +118,7 @@ public: // overloaded nsTableCellFrame methods virtual PRInt32 GetRowSpan(); virtual PRInt32 GetColSpan(); + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; protected: nsMathMLmtdFrame(); @@ -166,6 +169,7 @@ public: nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus); + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; protected: nsMathMLmtdInnerFrame(); diff --git a/layout/svg/base/src/nsSVGDefsFrame.cpp b/layout/svg/base/src/nsSVGDefsFrame.cpp index aa7913b9af7..6daf6c94c1f 100644 --- a/layout/svg/base/src/nsSVGDefsFrame.cpp +++ b/layout/svg/base/src/nsSVGDefsFrame.cpp @@ -188,6 +188,12 @@ nsSVGDefsFrame::GetType() const return nsLayoutAtoms::svgDefsFrame; } +PRBool +nsSVGDefsFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISVGValueObserver methods: diff --git a/layout/svg/base/src/nsSVGDefsFrame.h b/layout/svg/base/src/nsSVGDefsFrame.h index 16d7be024d5..b883f177e27 100644 --- a/layout/svg/base/src/nsSVGDefsFrame.h +++ b/layout/svg/base/src/nsSVGDefsFrame.h @@ -87,6 +87,7 @@ public: * @see nsLayoutAtoms::svgDefsFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const diff --git a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp index 1b50c5a44da..83c5bb32fe7 100644 --- a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp +++ b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp @@ -116,6 +116,7 @@ public: // frametypes, particularly code looking at block and area // also handles foreignObject before we return our own frametype // virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -419,6 +420,12 @@ nsSVGForeignObjectFrame::RemoveFrame(nsIAtom* aListName, // return nsLayoutAtoms::svgForeignObjectFrame; // } +PRBool +nsSVGForeignObjectFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~(nsIFrame::eSVG | nsIFrame::eSVGForeignObject)); +} + //---------------------------------------------------------------------- // nsISVGValueObserver methods: diff --git a/layout/svg/base/src/nsSVGGenericContainerFrame.cpp b/layout/svg/base/src/nsSVGGenericContainerFrame.cpp index 53ca1e3cd4e..69c12aebe05 100644 --- a/layout/svg/base/src/nsSVGGenericContainerFrame.cpp +++ b/layout/svg/base/src/nsSVGGenericContainerFrame.cpp @@ -176,6 +176,11 @@ nsSVGGenericContainerFrame::GetType() const return nsLayoutAtoms::svgGenericContainerFrame; } +PRBool +nsSVGGenericContainerFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} //---------------------------------------------------------------------- // nsISVGChildFrame methods diff --git a/layout/svg/base/src/nsSVGGenericContainerFrame.h b/layout/svg/base/src/nsSVGGenericContainerFrame.h index d2b41a4d8ed..81975edeb52 100644 --- a/layout/svg/base/src/nsSVGGenericContainerFrame.h +++ b/layout/svg/base/src/nsSVGGenericContainerFrame.h @@ -91,6 +91,7 @@ public: * @see nsLayoutAtoms::svgGenericContainerFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index 5065c01d4a5..abf58db41fe 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -117,6 +117,7 @@ public: * @see nsLayoutAtoms::svgGlyphFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -417,6 +418,12 @@ nsSVGGlyphFrame::GetType() const return nsLayoutAtoms::svgGlyphFrame; } +PRBool +nsSVGGlyphFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISVGValueObserver methods: diff --git a/layout/svg/base/src/nsSVGInnerSVGFrame.cpp b/layout/svg/base/src/nsSVGInnerSVGFrame.cpp index ae31a2c840e..b868cf65901 100644 --- a/layout/svg/base/src/nsSVGInnerSVGFrame.cpp +++ b/layout/svg/base/src/nsSVGInnerSVGFrame.cpp @@ -107,6 +107,7 @@ public: * @see nsLayoutAtoms::svgInnerSVGFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -350,6 +351,12 @@ nsSVGInnerSVGFrame::GetType() const return nsLayoutAtoms::svgInnerSVGFrame; } +PRBool +nsSVGInnerSVGFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISVGChildFrame methods diff --git a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp index a4cc9d44232..d54ec50ea5d 100644 --- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp +++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp @@ -217,6 +217,7 @@ public: * @see nsLayoutAtoms::svgOuterSVGFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -843,6 +844,12 @@ nsSVGOuterSVGFrame::GetType() const return nsLayoutAtoms::svgOuterSVGFrame; } +PRBool +nsSVGOuterSVGFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISVGValueObserver methods: diff --git a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp index 5b2bb57d495..47625f53286 100644 --- a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp +++ b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp @@ -205,6 +205,12 @@ nsSVGPathGeometryFrame::GetType() const return nsLayoutAtoms::svgPathGeometryFrame; } +PRBool +nsSVGPathGeometryFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISVGChildFrame methods diff --git a/layout/svg/base/src/nsSVGPathGeometryFrame.h b/layout/svg/base/src/nsSVGPathGeometryFrame.h index 33eeac3923e..fc341a38959 100644 --- a/layout/svg/base/src/nsSVGPathGeometryFrame.h +++ b/layout/svg/base/src/nsSVGPathGeometryFrame.h @@ -95,6 +95,7 @@ public: * @see nsLayoutAtoms::svgPathGeometryFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const diff --git a/layout/svg/base/src/nsSVGPatternFrame.cpp b/layout/svg/base/src/nsSVGPatternFrame.cpp index 8d96d07e3a8..7a365cc4192 100644 --- a/layout/svg/base/src/nsSVGPatternFrame.cpp +++ b/layout/svg/base/src/nsSVGPatternFrame.cpp @@ -141,6 +141,7 @@ public: * @see nsLayoutAtoms::svgPatternFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -274,6 +275,12 @@ nsSVGPatternFrame::GetType() const return nsLayoutAtoms::svgPatternFrame; } +PRBool +nsSVGPatternFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISVGContainerFrame interface: nsISVGOuterSVGFrame* diff --git a/layout/svg/base/src/nsSVGStopFrame.cpp b/layout/svg/base/src/nsSVGStopFrame.cpp index 81c7ee10b64..f75ff977116 100644 --- a/layout/svg/base/src/nsSVGStopFrame.cpp +++ b/layout/svg/base/src/nsSVGStopFrame.cpp @@ -68,6 +68,7 @@ class nsSVGStopFrame : public nsSVGStopFrameBase, * @see nsLayoutAtoms::svgStopFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -133,6 +134,12 @@ nsSVGStopFrame::GetType() const return nsLayoutAtoms::svgStopFrame; } +PRBool +nsSVGStopFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + NS_IMETHODIMP nsSVGStopFrame::Init(nsPresContext* aPresContext, nsIContent* aContent, diff --git a/layout/svg/base/src/nsSVGTSpanFrame.cpp b/layout/svg/base/src/nsSVGTSpanFrame.cpp index 93758e096a5..99c3d34d546 100644 --- a/layout/svg/base/src/nsSVGTSpanFrame.cpp +++ b/layout/svg/base/src/nsSVGTSpanFrame.cpp @@ -159,6 +159,12 @@ nsSVGTSpanFrame::GetType() const return nsLayoutAtoms::svgTSpanFrame; } +PRBool +nsSVGTSpanFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + //---------------------------------------------------------------------- // nsISupports methods diff --git a/layout/svg/base/src/nsSVGTSpanFrame.h b/layout/svg/base/src/nsSVGTSpanFrame.h index 2582a7992af..159d9adcf4e 100644 --- a/layout/svg/base/src/nsSVGTSpanFrame.h +++ b/layout/svg/base/src/nsSVGTSpanFrame.h @@ -112,6 +112,7 @@ public: * @see nsLayoutAtoms::svgTSpanFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const diff --git a/layout/svg/base/src/nsSVGTextFrame.cpp b/layout/svg/base/src/nsSVGTextFrame.cpp index d0487b41d4f..2142caa16ee 100644 --- a/layout/svg/base/src/nsSVGTextFrame.cpp +++ b/layout/svg/base/src/nsSVGTextFrame.cpp @@ -124,6 +124,7 @@ public: * @see nsLayoutAtoms::svgTextFrame */ virtual nsIAtom* GetType() const; + virtual PRBool IsFrameOfType(PRUint32 aFlags) const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -368,6 +369,12 @@ nsSVGTextFrame::GetType() const return nsLayoutAtoms::svgTextFrame; } +PRBool +nsSVGTextFrame::IsFrameOfType(PRUint32 aFlags) const +{ + return !(aFlags & ~nsIFrame::eSVG); +} + NS_IMETHODIMP nsSVGTextFrame::AppendFrames(nsIAtom* aListName, nsIFrame* aFrameList)