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_SVGMASKFRAME_H__ michael@0: #define __NS_SVGMASKFRAME_H__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "gfxPattern.h" michael@0: #include "gfxMatrix.h" michael@0: #include "nsSVGContainerFrame.h" michael@0: #include "nsSVGUtils.h" michael@0: michael@0: class gfxContext; michael@0: class nsRenderingContext; michael@0: michael@0: typedef nsSVGContainerFrame nsSVGMaskFrameBase; michael@0: michael@0: class nsSVGMaskFrame : public nsSVGMaskFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGMaskFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: nsSVGMaskFrame(nsStyleContext* aContext) michael@0: : nsSVGMaskFrameBase(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: // nsSVGMaskFrame method: michael@0: already_AddRefed ComputeMaskAlpha(nsRenderingContext *aContext, michael@0: nsIFrame* aParent, michael@0: const gfxMatrix &aMatrix, michael@0: float aOpacity = 1.0f); 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: #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: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgMaskFrame 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("SVGMask"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: private: michael@0: // A helper class to allow us to paint masks safely. The helper michael@0: // automatically sets and clears the mInUse flag on the mask 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 AutoMaskReferencer michael@0: { michael@0: public: michael@0: AutoMaskReferencer(nsSVGMaskFrame *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: ~AutoMaskReferencer() { michael@0: mFrame->mInUse = false; michael@0: } michael@0: private: michael@0: nsSVGMaskFrame *mFrame; michael@0: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER michael@0: }; michael@0: michael@0: nsIFrame *mMaskParent; michael@0: nsAutoPtr mMaskParentMatrix; 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