1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/nsSVGPatternFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,144 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __NS_SVGPATTERNFRAME_H__ 1.10 +#define __NS_SVGPATTERNFRAME_H__ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "gfxMatrix.h" 1.14 +#include "mozilla/gfx/2D.h" 1.15 +#include "nsSVGPaintServerFrame.h" 1.16 + 1.17 +class gfxASurface; 1.18 +class gfxContext; 1.19 +class nsIFrame; 1.20 +class nsSVGElement; 1.21 +class nsSVGLength2; 1.22 +class nsSVGPathGeometryFrame; 1.23 +class nsSVGViewBox; 1.24 + 1.25 +namespace mozilla { 1.26 +class SVGAnimatedPreserveAspectRatio; 1.27 +class nsSVGAnimatedTransformList; 1.28 +} // namespace mozilla 1.29 + 1.30 +typedef nsSVGPaintServerFrame nsSVGPatternFrameBase; 1.31 + 1.32 +/** 1.33 + * Patterns can refer to other patterns. We create an nsSVGPaintingProperty 1.34 + * with property type nsGkAtoms::href to track the referenced pattern. 1.35 + */ 1.36 +class nsSVGPatternFrame : public nsSVGPatternFrameBase 1.37 +{ 1.38 +public: 1.39 + NS_DECL_FRAMEARENA_HELPERS 1.40 + 1.41 + friend nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell, 1.42 + nsStyleContext* aContext); 1.43 + 1.44 + nsSVGPatternFrame(nsStyleContext* aContext); 1.45 + 1.46 + // nsSVGPaintServerFrame methods: 1.47 + virtual already_AddRefed<gfxPattern> 1.48 + GetPaintServerPattern(nsIFrame *aSource, 1.49 + const gfxMatrix& aContextMatrix, 1.50 + nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, 1.51 + float aOpacity, 1.52 + const gfxRect *aOverrideBounds) MOZ_OVERRIDE; 1.53 + 1.54 +public: 1.55 + typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio; 1.56 + 1.57 + // nsSVGContainerFrame methods: 1.58 + virtual gfxMatrix GetCanvasTM(uint32_t aFor, 1.59 + nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; 1.60 + 1.61 + // nsIFrame interface: 1.62 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.63 + nsIAtom* aAttribute, 1.64 + int32_t aModType) MOZ_OVERRIDE; 1.65 + 1.66 +#ifdef DEBUG 1.67 + virtual void Init(nsIContent* aContent, 1.68 + nsIFrame* aParent, 1.69 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.70 +#endif 1.71 + 1.72 + /** 1.73 + * Get the "type" of the frame 1.74 + * 1.75 + * @see nsGkAtoms::svgPatternFrame 1.76 + */ 1.77 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.78 + 1.79 +#ifdef DEBUG_FRAME_DUMP 1.80 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE 1.81 + { 1.82 + return MakeFrameName(NS_LITERAL_STRING("SVGPattern"), aResult); 1.83 + } 1.84 +#endif // DEBUG 1.85 + 1.86 +protected: 1.87 + // Internal methods for handling referenced patterns 1.88 + class AutoPatternReferencer; 1.89 + nsSVGPatternFrame* GetReferencedPattern(); 1.90 + nsSVGPatternFrame* GetReferencedPatternIfNotInUse(); 1.91 + 1.92 + // Accessors to lookup pattern attributes 1.93 + uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault); 1.94 + uint16_t GetEnumValue(uint32_t aIndex) 1.95 + { 1.96 + return GetEnumValue(aIndex, mContent); 1.97 + } 1.98 + mozilla::nsSVGAnimatedTransformList* GetPatternTransformList( 1.99 + nsIContent* aDefault); 1.100 + gfxMatrix GetPatternTransform(); 1.101 + const nsSVGViewBox &GetViewBox(nsIContent *aDefault); 1.102 + const nsSVGViewBox &GetViewBox() { return GetViewBox(mContent); } 1.103 + const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio( 1.104 + nsIContent *aDefault); 1.105 + const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio() 1.106 + { 1.107 + return GetPreserveAspectRatio(mContent); 1.108 + } 1.109 + const nsSVGLength2 *GetLengthValue(uint32_t aIndex, nsIContent *aDefault); 1.110 + const nsSVGLength2 *GetLengthValue(uint32_t aIndex) 1.111 + { 1.112 + return GetLengthValue(aIndex, mContent); 1.113 + } 1.114 + 1.115 + nsresult PaintPattern(gfxASurface **surface, 1.116 + gfxMatrix *patternMatrix, 1.117 + const gfxMatrix &aContextMatrix, 1.118 + nsIFrame *aSource, 1.119 + nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, 1.120 + float aGraphicOpacity, 1.121 + const gfxRect *aOverrideBounds); 1.122 + nsIFrame* GetPatternFirstChild(); 1.123 + gfxRect GetPatternRect(uint16_t aPatternUnits, 1.124 + const gfxRect &bbox, 1.125 + const Matrix &callerCTM, 1.126 + nsIFrame *aTarget); 1.127 + gfxMatrix ConstructCTM(const nsSVGViewBox& aViewBox, 1.128 + uint16_t aPatternContentUnits, 1.129 + uint16_t aPatternUnits, 1.130 + const gfxRect &callerBBox, 1.131 + const Matrix &callerCTM, 1.132 + nsIFrame *aTarget); 1.133 + 1.134 +private: 1.135 + // this is a *temporary* reference to the frame of the element currently 1.136 + // referencing our pattern. This must be temporary because different 1.137 + // referencing frames will all reference this one frame 1.138 + nsSVGPathGeometryFrame *mSource; 1.139 + nsAutoPtr<gfxMatrix> mCTM; 1.140 + 1.141 +protected: 1.142 + // This flag is used to detect loops in xlink:href processing 1.143 + bool mLoopFlag; 1.144 + bool mNoHRefURI; 1.145 +}; 1.146 + 1.147 +#endif