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_SVGCLIPPATHFRAME_H__ michael@0: #define __NS_SVGCLIPPATHFRAME_H__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "gfxMatrix.h" michael@0: #include "nsSVGContainerFrame.h" michael@0: #include "nsSVGUtils.h" michael@0: michael@0: class nsRenderingContext; michael@0: class nsISVGChildFrame; michael@0: michael@0: typedef nsSVGContainerFrame nsSVGClipPathFrameBase; michael@0: michael@0: class nsSVGClipPathFrame : public nsSVGClipPathFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: nsSVGClipPathFrame(nsStyleContext* aContext) michael@0: : nsSVGClipPathFrameBase(aContext) michael@0: , mInUse(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 methods: michael@0: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE {} michael@0: michael@0: // nsSVGClipPathFrame methods: michael@0: nsresult ClipPaint(nsRenderingContext* aContext, michael@0: nsIFrame* aParent, michael@0: const gfxMatrix &aMatrix); michael@0: michael@0: bool ClipHitTest(nsIFrame* aParent, michael@0: const gfxMatrix &aMatrix, michael@0: const nsPoint &aPoint); michael@0: michael@0: // Check if this clipPath is made up of more than one geometry object. michael@0: // If so, the clipping API in cairo isn't enough and we need to use michael@0: // mask based clipping. michael@0: bool IsTrivial(nsISVGChildFrame **aSingleChild = nullptr); michael@0: michael@0: bool IsValid(); michael@0: michael@0: // nsIFrame interface: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) 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: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgClipPathFrame 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("SVGClipPath"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: private: michael@0: // A helper class to allow us to paint clip paths safely. The helper michael@0: // automatically sets and clears the mInUse flag on the clip path frame michael@0: // (to prevent nasty reference loops). 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 AutoClipPathReferencer michael@0: { michael@0: public: michael@0: AutoClipPathReferencer(nsSVGClipPathFrame *aFrame michael@0: MOZ_GUARD_OBJECT_NOTIFIER_PARAM) michael@0: : mFrame(aFrame) { michael@0: MOZ_GUARD_OBJECT_NOTIFIER_INIT; michael@0: NS_ASSERTION(!mFrame->mInUse, "reference loop!"); michael@0: mFrame->mInUse = true; michael@0: } michael@0: ~AutoClipPathReferencer() { michael@0: mFrame->mInUse = false; michael@0: } michael@0: private: michael@0: nsSVGClipPathFrame *mFrame; michael@0: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER michael@0: }; michael@0: michael@0: nsIFrame *mClipParent; michael@0: nsAutoPtr mClipParentMatrix; michael@0: // recursion prevention flag michael@0: bool mInUse; 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: michael@0: #endif