SVGPatternFrame.h (5167B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef LAYOUT_SVG_SVGPATTERNFRAME_H_ 8 #define LAYOUT_SVG_SVGPATTERNFRAME_H_ 9 10 #include "gfxMatrix.h" 11 #include "mozilla/AlreadyAddRefed.h" 12 #include "mozilla/SVGPaintServerFrame.h" 13 #include "mozilla/UniquePtr.h" 14 #include "mozilla/gfx/2D.h" 15 16 class nsIFrame; 17 18 namespace mozilla { 19 class PresShell; 20 class SVGAnimatedLength; 21 class SVGAnimatedPreserveAspectRatio; 22 class SVGAnimatedTransformList; 23 class SVGAnimatedViewBox; 24 class SVGGeometryFrame; 25 } // namespace mozilla 26 27 nsIFrame* NS_NewSVGPatternFrame(mozilla::PresShell* aPresShell, 28 mozilla::ComputedStyle* aStyle); 29 30 namespace mozilla { 31 32 class SVGPatternFrame final : public SVGPaintServerFrame { 33 using SourceSurface = gfx::SourceSurface; 34 35 public: 36 NS_DECL_FRAMEARENA_HELPERS(SVGPatternFrame) 37 NS_DECL_QUERYFRAME 38 39 friend nsIFrame* ::NS_NewSVGPatternFrame(mozilla::PresShell* aPresShell, 40 ComputedStyle* aStyle); 41 42 explicit SVGPatternFrame(ComputedStyle* aStyle, nsPresContext* aPresContext); 43 44 // SVGPaintServerFrame methods: 45 already_AddRefed<gfxPattern> GetPaintServerPattern( 46 nsIFrame* aSource, const DrawTarget* aDrawTarget, 47 const gfxMatrix& aContextMatrix, 48 StyleSVGPaint nsStyleSVG::* aFillOrStroke, float aGraphicOpacity, 49 imgDrawingParams& aImgParams, const gfxRect* aOverrideBounds) override; 50 51 public: 52 // SVGContainerFrame methods: 53 gfxMatrix GetCanvasTM() override; 54 55 // nsIFrame interface: 56 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 57 AttrModType aModType) override; 58 59 #ifdef DEBUG 60 void Init(nsIContent* aContent, nsContainerFrame* aParent, 61 nsIFrame* aPrevInFlow) override; 62 #endif 63 64 #ifdef DEBUG_FRAME_DUMP 65 nsresult GetFrameName(nsAString& aResult) const override { 66 return MakeFrameName(u"SVGPattern"_ns, aResult); 67 } 68 #endif // DEBUG 69 70 protected: 71 /** 72 * Parses this frame's href and - if it references another pattern - returns 73 * it. It also makes this frame a rendering observer of the specified ID. 74 */ 75 SVGPatternFrame* GetReferencedPattern(); 76 77 // Accessors to lookup pattern attributes 78 uint16_t GetEnumValue(uint32_t aIndex, nsIContent* aDefault); 79 uint16_t GetEnumValue(uint32_t aIndex) { 80 return GetEnumValue(aIndex, mContent); 81 } 82 SVGPatternFrame* GetPatternTransformFrame(SVGPatternFrame* aDefault); 83 gfxMatrix GetPatternTransform(); 84 const SVGAnimatedViewBox& GetViewBox(nsIContent* aDefault); 85 const SVGAnimatedViewBox& GetViewBox() { return GetViewBox(mContent); } 86 const SVGAnimatedPreserveAspectRatio& GetPreserveAspectRatio( 87 nsIContent* aDefault); 88 const SVGAnimatedPreserveAspectRatio& GetPreserveAspectRatio() { 89 return GetPreserveAspectRatio(mContent); 90 } 91 const SVGAnimatedLength* GetLengthValue(uint32_t aIndex, 92 nsIContent* aDefault); 93 const SVGAnimatedLength* GetLengthValue(uint32_t aIndex) { 94 return GetLengthValue(aIndex, mContent); 95 } 96 97 void PaintChildren(DrawTarget* aDrawTarget, 98 SVGPatternFrame* aPatternWithChildren, nsIFrame* aSource, 99 float aGraphicOpacity, imgDrawingParams& aImgParams); 100 101 already_AddRefed<SourceSurface> PaintPattern( 102 const DrawTarget* aDrawTarget, Matrix* patternMatrix, 103 const Matrix& aContextMatrix, nsIFrame* aSource, 104 StyleSVGPaint nsStyleSVG::* aFillOrStroke, float aGraphicOpacity, 105 const gfxRect* aOverrideBounds, imgDrawingParams& aImgParams); 106 107 /** 108 * A <pattern> element may reference another <pattern> element using 109 * xlink:href and, if it doesn't have any child content of its own, then it 110 * will "inherit" the children of the referenced pattern (which may itself be 111 * inheriting its children if it references another <pattern>). This 112 * function returns this SVGPatternFrame or the first pattern along the 113 * reference chain (if there is one) to have children. 114 */ 115 SVGPatternFrame* GetPatternWithChildren(); 116 117 gfxRect GetPatternRect(uint16_t aPatternUnits, const gfxRect& bbox, 118 const Matrix& aTargetCTM, nsIFrame* aTarget); 119 gfxMatrix ConstructCTM(const SVGAnimatedViewBox& aViewBox, 120 uint16_t aPatternContentUnits, uint16_t aPatternUnits, 121 const gfxRect& callerBBox, const Matrix& callerCTM, 122 nsIFrame* aTarget); 123 124 private: 125 // this is a *temporary* reference to the frame of the element currently 126 // referencing our pattern. This must be temporary because different 127 // referencing frames will all reference this one frame 128 SVGGeometryFrame* mSource; 129 UniquePtr<gfxMatrix> mCTM; 130 131 protected: 132 // This flag is used to detect loops in xlink:href processing 133 bool mLoopFlag; 134 bool mNoHRefURI; 135 }; 136 137 } // namespace mozilla 138 139 #endif // LAYOUT_SVG_SVGPATTERNFRAME_H_