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_SVGMARKERFRAME_H__ michael@0: #define __NS_SVGMARKERFRAME_H__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "gfxMatrix.h" michael@0: #include "gfxRect.h" michael@0: #include "nsFrame.h" michael@0: #include "nsLiteralString.h" michael@0: #include "nsQueryFrame.h" michael@0: #include "nsSVGContainerFrame.h" michael@0: #include "nsSVGUtils.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIContent; michael@0: class nsIFrame; michael@0: class nsIPresShell; michael@0: class nsRenderingContext; michael@0: class nsStyleContext; michael@0: class nsSVGPathGeometryFrame; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class SVGSVGElement; michael@0: } michael@0: } michael@0: michael@0: struct nsSVGMark; michael@0: michael@0: typedef nsSVGContainerFrame nsSVGMarkerFrameBase; michael@0: michael@0: class nsSVGMarkerFrame : public nsSVGMarkerFrameBase michael@0: { michael@0: friend class nsSVGMarkerAnonChildFrame; michael@0: friend nsIFrame* michael@0: NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: nsSVGMarkerFrame(nsStyleContext* aContext) michael@0: : nsSVGMarkerFrameBase(aContext) michael@0: , mMarkedFrame(nullptr) michael@0: , mInUse(false) michael@0: , mInUse2(false) michael@0: { michael@0: AddStateBits(NS_FRAME_IS_NONDISPLAY); michael@0: } michael@0: michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: // nsIFrame interface: 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: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE {} 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: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgMarkerFrame 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("SVGMarker"), aResult); michael@0: } michael@0: #endif 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::svgMarkerAnonChildFrame, michael@0: "Where is our anonymous child?"); michael@0: return GetFirstPrincipalChild()->GetContentInsertionFrame(); michael@0: } michael@0: michael@0: // nsSVGMarkerFrame methods: michael@0: nsresult PaintMark(nsRenderingContext *aContext, michael@0: nsSVGPathGeometryFrame *aMarkedFrame, michael@0: nsSVGMark *aMark, michael@0: float aStrokeWidth); michael@0: michael@0: SVGBBox GetMarkBBoxContribution(const Matrix &aToBBoxUserspace, michael@0: uint32_t aFlags, michael@0: nsSVGPathGeometryFrame *aMarkedFrame, michael@0: const nsSVGMark *aMark, michael@0: float aStrokeWidth); michael@0: michael@0: private: michael@0: // stuff needed for callback michael@0: nsSVGPathGeometryFrame *mMarkedFrame; michael@0: float mStrokeWidth, mX, mY, mAutoAngle; michael@0: bool mIsStart; // whether the callback is for a marker-start marker 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: // A helper class to allow us to paint markers safely. The helper michael@0: // automatically sets and clears the mInUse flag on the marker frame (to michael@0: // prevent nasty reference loops) as well as the reference to the marked michael@0: // frame and its coordinate context. It's easy to mess this up michael@0: // and break things, so this helper makes the code far more robust. michael@0: class MOZ_STACK_CLASS AutoMarkerReferencer michael@0: { michael@0: public: michael@0: AutoMarkerReferencer(nsSVGMarkerFrame *aFrame, michael@0: nsSVGPathGeometryFrame *aMarkedFrame michael@0: MOZ_GUARD_OBJECT_NOTIFIER_PARAM); michael@0: ~AutoMarkerReferencer(); michael@0: private: michael@0: nsSVGMarkerFrame *mFrame; michael@0: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER michael@0: }; michael@0: michael@0: // nsSVGMarkerFrame methods: michael@0: void SetParentCoordCtxProvider(mozilla::dom::SVGSVGElement *aContext); michael@0: michael@0: // recursion prevention flag michael@0: bool mInUse; michael@0: michael@0: // second recursion prevention flag, for GetCanvasTM() michael@0: bool mInUse2; michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////// michael@0: // nsMarkerAnonChildFrame class michael@0: michael@0: typedef nsSVGDisplayContainerFrame nsSVGMarkerAnonChildFrameBase; michael@0: michael@0: /** michael@0: */ michael@0: class nsSVGMarkerAnonChildFrame michael@0: : public nsSVGMarkerAnonChildFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGMarkerAnonChildFrame(nsIPresShell* aPresShell, michael@0: nsStyleContext* aContext); michael@0: michael@0: nsSVGMarkerAnonChildFrame(nsStyleContext* aContext) michael@0: : nsSVGMarkerAnonChildFrameBase(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("SVGMarkerAnonChild"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgMarkerAnonChildFrame 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 = nullptr) MOZ_OVERRIDE michael@0: { michael@0: nsSVGMarkerFrame* marker = static_cast(mParent); michael@0: return marker->GetCanvasTM(aFor, aTransformRoot); michael@0: } michael@0: }; michael@0: #endif