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_SVGPATTERNFRAME_H__ michael@0: #define __NS_SVGPATTERNFRAME_H__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "gfxMatrix.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "nsSVGPaintServerFrame.h" michael@0: michael@0: class gfxASurface; michael@0: class gfxContext; michael@0: class nsIFrame; michael@0: class nsSVGElement; michael@0: class nsSVGLength2; michael@0: class nsSVGPathGeometryFrame; michael@0: class nsSVGViewBox; michael@0: michael@0: namespace mozilla { michael@0: class SVGAnimatedPreserveAspectRatio; michael@0: class nsSVGAnimatedTransformList; michael@0: } // namespace mozilla michael@0: michael@0: typedef nsSVGPaintServerFrame nsSVGPatternFrameBase; michael@0: michael@0: /** michael@0: * Patterns can refer to other patterns. We create an nsSVGPaintingProperty michael@0: * with property type nsGkAtoms::href to track the referenced pattern. michael@0: */ michael@0: class nsSVGPatternFrame : public nsSVGPatternFrameBase michael@0: { michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: friend nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell, michael@0: nsStyleContext* aContext); michael@0: michael@0: nsSVGPatternFrame(nsStyleContext* aContext); michael@0: michael@0: // nsSVGPaintServerFrame methods: michael@0: virtual already_AddRefed michael@0: GetPaintServerPattern(nsIFrame *aSource, michael@0: const gfxMatrix& aContextMatrix, michael@0: nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, michael@0: float aOpacity, michael@0: const gfxRect *aOverrideBounds) MOZ_OVERRIDE; michael@0: michael@0: public: michael@0: typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio; 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: // 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: #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: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgPatternFrame 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("SVGPattern"), aResult); michael@0: } michael@0: #endif // DEBUG michael@0: michael@0: protected: michael@0: // Internal methods for handling referenced patterns michael@0: class AutoPatternReferencer; michael@0: nsSVGPatternFrame* GetReferencedPattern(); michael@0: nsSVGPatternFrame* GetReferencedPatternIfNotInUse(); michael@0: michael@0: // Accessors to lookup pattern attributes michael@0: uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault); michael@0: uint16_t GetEnumValue(uint32_t aIndex) michael@0: { michael@0: return GetEnumValue(aIndex, mContent); michael@0: } michael@0: mozilla::nsSVGAnimatedTransformList* GetPatternTransformList( michael@0: nsIContent* aDefault); michael@0: gfxMatrix GetPatternTransform(); michael@0: const nsSVGViewBox &GetViewBox(nsIContent *aDefault); michael@0: const nsSVGViewBox &GetViewBox() { return GetViewBox(mContent); } michael@0: const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio( michael@0: nsIContent *aDefault); michael@0: const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio() michael@0: { michael@0: return GetPreserveAspectRatio(mContent); michael@0: } michael@0: const nsSVGLength2 *GetLengthValue(uint32_t aIndex, nsIContent *aDefault); michael@0: const nsSVGLength2 *GetLengthValue(uint32_t aIndex) michael@0: { michael@0: return GetLengthValue(aIndex, mContent); michael@0: } michael@0: michael@0: nsresult PaintPattern(gfxASurface **surface, michael@0: gfxMatrix *patternMatrix, michael@0: const gfxMatrix &aContextMatrix, michael@0: nsIFrame *aSource, michael@0: nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, michael@0: float aGraphicOpacity, michael@0: const gfxRect *aOverrideBounds); michael@0: nsIFrame* GetPatternFirstChild(); michael@0: gfxRect GetPatternRect(uint16_t aPatternUnits, michael@0: const gfxRect &bbox, michael@0: const Matrix &callerCTM, michael@0: nsIFrame *aTarget); michael@0: gfxMatrix ConstructCTM(const nsSVGViewBox& aViewBox, michael@0: uint16_t aPatternContentUnits, michael@0: uint16_t aPatternUnits, michael@0: const gfxRect &callerBBox, michael@0: const Matrix &callerCTM, michael@0: nsIFrame *aTarget); michael@0: michael@0: private: michael@0: // this is a *temporary* reference to the frame of the element currently michael@0: // referencing our pattern. This must be temporary because different michael@0: // referencing frames will all reference this one frame michael@0: nsSVGPathGeometryFrame *mSource; michael@0: nsAutoPtr mCTM; michael@0: michael@0: protected: michael@0: // This flag is used to detect loops in xlink:href processing michael@0: bool mLoopFlag; michael@0: bool mNoHRefURI; michael@0: }; michael@0: michael@0: #endif