michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __NS_SVGOUTERSVGFRAME_H__ michael@0: #define __NS_SVGOUTERSVGFRAME_H__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsISVGSVGFrame.h" michael@0: #include "nsSVGContainerFrame.h" michael@0: #include "nsRegion.h" michael@0: michael@0: class nsSVGForeignObjectFrame; michael@0: michael@0: //////////////////////////////////////////////////////////////////////// michael@0: // nsSVGOuterSVGFrame class michael@0: michael@0: typedef nsSVGDisplayContainerFrame nsSVGOuterSVGFrameBase; michael@0: michael@0: class nsSVGOuterSVGFrame : public nsSVGOuterSVGFrameBase, michael@0: public nsISVGSVGFrame michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: nsSVGOuterSVGFrame(nsStyleContext* aContext); michael@0: michael@0: public: michael@0: NS_DECL_QUERYFRAME michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: #ifdef DEBUG michael@0: ~nsSVGOuterSVGFrame() { michael@0: NS_ASSERTION(!mForeignObjectHash || mForeignObjectHash->Count() == 0, michael@0: "foreignObject(s) still registered!"); michael@0: } michael@0: #endif michael@0: michael@0: // nsIFrame: michael@0: virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; michael@0: virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; michael@0: michael@0: virtual mozilla::IntrinsicSize GetIntrinsicSize() MOZ_OVERRIDE; michael@0: virtual nsSize GetIntrinsicRatio() MOZ_OVERRIDE; michael@0: michael@0: virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext, michael@0: nsSize aCBSize, nscoord aAvailableWidth, michael@0: nsSize aMargin, nsSize aBorder, nsSize aPadding, michael@0: uint32_t aFlags) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult DidReflow(nsPresContext* aPresContext, michael@0: const nsHTMLReflowState* aReflowState, michael@0: nsDidReflowStatus aStatus) MOZ_OVERRIDE; michael@0: michael@0: virtual bool UpdateOverflow() MOZ_OVERRIDE; michael@0: michael@0: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: michael@0: virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgOuterSVGFrame michael@0: */ michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVG"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) MOZ_OVERRIDE; michael@0: michael@0: virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE { michael@0: // Any children must be added to our single anonymous inner frame kid. michael@0: NS_ABORT_IF_FALSE(GetFirstPrincipalChild() && michael@0: GetFirstPrincipalChild()->GetType() == michael@0: nsGkAtoms::svgOuterSVGAnonChildFrame, michael@0: "Where is our anonymous child?"); michael@0: return GetFirstPrincipalChild()->GetContentInsertionFrame(); michael@0: } michael@0: michael@0: virtual bool IsSVGTransformed(Matrix *aOwnTransform, michael@0: Matrix *aFromParentTransform) const MOZ_OVERRIDE { michael@0: // Our anonymous wrapper performs the transforms. We simply michael@0: // return whether we are transformed here but don't apply the transforms michael@0: // themselves. michael@0: return GetFirstPrincipalChild()->IsSVGTransformed(); michael@0: } michael@0: michael@0: // nsISVGSVGFrame interface: michael@0: virtual void NotifyViewportOrTransformChanged(uint32_t aFlags) MOZ_OVERRIDE; michael@0: michael@0: // nsISVGChildFrame methods: michael@0: virtual nsresult PaintSVG(nsRenderingContext* aContext, michael@0: const nsIntRect *aDirtyRect, michael@0: nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; michael@0: michael@0: virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace, michael@0: uint32_t aFlags) MOZ_OVERRIDE; michael@0: michael@0: // nsSVGContainerFrame methods: michael@0: virtual gfxMatrix GetCanvasTM(uint32_t aFor, michael@0: nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; michael@0: michael@0: /* Methods to allow descendant nsSVGForeignObjectFrame frames to register and michael@0: * unregister themselves with their nearest nsSVGOuterSVGFrame ancestor. This michael@0: * is temporary until display list based invalidation is impleented for SVG. michael@0: * Maintaining a list of our foreignObject descendants allows us to search michael@0: * them for areas that need to be invalidated, without having to also search michael@0: * the SVG frame tree for foreignObjects. This is important so that bug 539356 michael@0: * does not slow down SVG in general (only foreignObjects, until bug 614732 is michael@0: * fixed). michael@0: */ michael@0: void RegisterForeignObject(nsSVGForeignObjectFrame* aFrame); michael@0: void UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame); michael@0: michael@0: virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const MOZ_OVERRIDE { michael@0: // Our anonymous wrapper child must claim our children-only transforms as michael@0: // its own so that our real children (the frames it wraps) are transformed michael@0: // by them, and we must pretend we don't have any children-only transforms michael@0: // so that our anonymous child is _not_ transformed by them. michael@0: return false; michael@0: } michael@0: michael@0: /** michael@0: * Return true only if the height is unspecified (defaulting to 100%) or else michael@0: * the height is explicitly set to a percentage value no greater than 100%. michael@0: */ michael@0: bool VerticalScrollbarNotNeeded() const; michael@0: michael@0: bool IsCallingReflowSVG() const { michael@0: return mCallingReflowSVG; michael@0: } michael@0: michael@0: void InvalidateSVG(const nsRegion& aRegion) michael@0: { michael@0: if (!aRegion.IsEmpty()) { michael@0: mInvalidRegion.Or(mInvalidRegion, aRegion); michael@0: InvalidateFrame(); michael@0: } michael@0: } michael@0: michael@0: void ClearInvalidRegion() { mInvalidRegion.SetEmpty(); } michael@0: michael@0: const nsRegion& GetInvalidRegion() { michael@0: nsRect rect; michael@0: if (!IsInvalid(rect)) { michael@0: mInvalidRegion.SetEmpty(); michael@0: } michael@0: return mInvalidRegion; michael@0: } michael@0: michael@0: nsRegion FindInvalidatedForeignObjectFrameChildren(nsIFrame* aFrame); michael@0: michael@0: protected: michael@0: michael@0: bool mCallingReflowSVG; michael@0: michael@0: /* Returns true if our content is the document element and our document is michael@0: * embedded in an HTML 'object', 'embed' or 'applet' element. Set michael@0: * aEmbeddingFrame to obtain the nsIFrame for the embedding HTML element. michael@0: */ michael@0: bool IsRootOfReplacedElementSubDoc(nsIFrame **aEmbeddingFrame = nullptr); michael@0: michael@0: /* Returns true if our content is the document element and our document is michael@0: * being used as an image. michael@0: */ michael@0: bool IsRootOfImage(); michael@0: michael@0: // This is temporary until display list based invalidation is implemented for michael@0: // SVG. michael@0: // A hash-set containing our nsSVGForeignObjectFrame descendants. Note we use michael@0: // a hash-set to avoid the O(N^2) behavior we'd get tearing down an SVG frame michael@0: // subtree if we were to use a list (see bug 381285 comment 20). michael@0: nsAutoPtr > > mForeignObjectHash; michael@0: michael@0: nsAutoPtr mCanvasTM; michael@0: michael@0: nsRegion mInvalidRegion; michael@0: michael@0: float mFullZoom; michael@0: michael@0: bool mViewportInitialized; michael@0: bool mIsRootContent; michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////// michael@0: // nsSVGOuterSVGAnonChildFrame class michael@0: michael@0: typedef nsSVGDisplayContainerFrame nsSVGOuterSVGAnonChildFrameBase; michael@0: michael@0: /** michael@0: * nsSVGOuterSVGFrames have a single direct child that is an instance of this michael@0: * class, and which is used to wrap their real child frames. Such anonymous michael@0: * wrapper frames created from this class exist because SVG frames need their michael@0: * GetPosition() offset to be their offset relative to "user space" (in app michael@0: * units) so that they can play nicely with nsDisplayTransform. This is fine michael@0: * for all SVG frames except for direct children of an nsSVGOuterSVGFrame, michael@0: * since an nsSVGOuterSVGFrame can have CSS border and padding (unlike other michael@0: * SVG frames). The direct children can't include the offsets due to any such michael@0: * border/padding in their mRects since that would break nsDisplayTransform, michael@0: * but not including these offsets would break other parts of the Mozilla code michael@0: * that assume a frame's mRect contains its border-box-to-parent-border-box michael@0: * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on michael@0: * it. Wrapping an nsSVGOuterSVGFrame's children in an instance of this class michael@0: * with its GetPosition() set to its nsSVGOuterSVGFrame's border/padding offset michael@0: * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy. michael@0: * michael@0: * The reason that this class inherit from nsSVGDisplayContainerFrame rather michael@0: * than simply from nsContainerFrame is so that we can avoid having special michael@0: * handling for these inner wrappers in multiple parts of the SVG code. For michael@0: * example, the implementations of IsSVGTransformed and GetCanvasTM assume michael@0: * nsSVGContainerFrame instances all the way up to the nsSVGOuterSVGFrame. michael@0: */ michael@0: class nsSVGOuterSVGAnonChildFrame michael@0: : public nsSVGOuterSVGAnonChildFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGOuterSVGAnonChildFrame(nsIPresShell* aPresShell, michael@0: nsStyleContext* aContext); michael@0: michael@0: nsSVGOuterSVGAnonChildFrame(nsStyleContext* aContext) michael@0: : nsSVGOuterSVGAnonChildFrameBase(aContext) michael@0: {} michael@0: michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: #ifdef DEBUG michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { michael@0: return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVGAnonChild"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgOuterSVGAnonChildFrame michael@0: */ michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: // nsSVGContainerFrame methods: michael@0: virtual gfxMatrix GetCanvasTM(uint32_t aFor, michael@0: nsIFrame* aTransformRoot) MOZ_OVERRIDE { michael@0: // GetCanvasTM returns the transform from an SVG frame to the frame's michael@0: // nsSVGOuterSVGFrame's content box, so we do not include any x/y offset michael@0: // set on us for any CSS border or padding on our nsSVGOuterSVGFrame. michael@0: return static_cast(mParent)->GetCanvasTM(aFor, aTransformRoot); michael@0: } michael@0: michael@0: virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: #endif