/src/mozilla-central/layout/svg/nsSVGPatternFrame.h
Line | Count | Source (jump to first uncovered line) |
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 __NS_SVGPATTERNFRAME_H__ |
8 | | #define __NS_SVGPATTERNFRAME_H__ |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "gfxMatrix.h" |
12 | | #include "mozilla/gfx/2D.h" |
13 | | #include "mozilla/RefPtr.h" |
14 | | #include "nsAutoPtr.h" |
15 | | #include "nsSVGPaintServerFrame.h" |
16 | | |
17 | | class nsIFrame; |
18 | | class nsSVGLength2; |
19 | | class nsSVGViewBox; |
20 | | |
21 | | namespace mozilla { |
22 | | class SVGAnimatedPreserveAspectRatio; |
23 | | class SVGGeometryFrame; |
24 | | class nsSVGAnimatedTransformList; |
25 | | } // namespace mozilla |
26 | | |
27 | | /** |
28 | | * Patterns can refer to other patterns. We create an nsSVGPaintingProperty |
29 | | * with property type nsGkAtoms::href to track the referenced pattern. |
30 | | */ |
31 | | class nsSVGPatternFrame final : public nsSVGPaintServerFrame |
32 | | { |
33 | | typedef mozilla::gfx::SourceSurface SourceSurface; |
34 | | |
35 | | public: |
36 | | NS_DECL_FRAMEARENA_HELPERS(nsSVGPatternFrame) |
37 | | |
38 | | friend nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell, |
39 | | ComputedStyle* aStyle); |
40 | | |
41 | | explicit nsSVGPatternFrame(ComputedStyle* aStyle); |
42 | | |
43 | | // nsSVGPaintServerFrame methods: |
44 | | virtual already_AddRefed<gfxPattern> |
45 | | GetPaintServerPattern(nsIFrame *aSource, |
46 | | const DrawTarget* aDrawTarget, |
47 | | const gfxMatrix& aContextMatrix, |
48 | | nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, |
49 | | float aOpacity, |
50 | | imgDrawingParams& aImgParams, |
51 | | const gfxRect* aOverrideBounds) override; |
52 | | |
53 | | public: |
54 | | typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio; |
55 | | |
56 | | // nsSVGContainerFrame methods: |
57 | | virtual gfxMatrix GetCanvasTM() override; |
58 | | |
59 | | // nsIFrame interface: |
60 | | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
61 | | nsAtom* aAttribute, |
62 | | int32_t aModType) override; |
63 | | |
64 | | #ifdef DEBUG |
65 | | virtual void Init(nsIContent* aContent, |
66 | | nsContainerFrame* aParent, |
67 | | nsIFrame* aPrevInFlow) override; |
68 | | #endif |
69 | | |
70 | | #ifdef DEBUG_FRAME_DUMP |
71 | | virtual nsresult GetFrameName(nsAString& aResult) const override |
72 | | { |
73 | | return MakeFrameName(NS_LITERAL_STRING("SVGPattern"), aResult); |
74 | | } |
75 | | #endif // DEBUG |
76 | | |
77 | | protected: |
78 | | // Internal methods for handling referenced patterns |
79 | | nsSVGPatternFrame* GetReferencedPattern(); |
80 | | |
81 | | // Accessors to lookup pattern attributes |
82 | | uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault); |
83 | | uint16_t GetEnumValue(uint32_t aIndex) |
84 | 0 | { |
85 | 0 | return GetEnumValue(aIndex, mContent); |
86 | 0 | } |
87 | | mozilla::nsSVGAnimatedTransformList* GetPatternTransformList( |
88 | | nsIContent* aDefault); |
89 | | gfxMatrix GetPatternTransform(); |
90 | | const nsSVGViewBox &GetViewBox(nsIContent *aDefault); |
91 | 0 | const nsSVGViewBox &GetViewBox() { return GetViewBox(mContent); } |
92 | | const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio( |
93 | | nsIContent *aDefault); |
94 | | const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio() |
95 | 0 | { |
96 | 0 | return GetPreserveAspectRatio(mContent); |
97 | 0 | } |
98 | | const nsSVGLength2 *GetLengthValue(uint32_t aIndex, nsIContent *aDefault); |
99 | | const nsSVGLength2 *GetLengthValue(uint32_t aIndex) |
100 | 0 | { |
101 | 0 | return GetLengthValue(aIndex, mContent); |
102 | 0 | } |
103 | | |
104 | | already_AddRefed<SourceSurface> |
105 | | PaintPattern(const DrawTarget* aDrawTarget, |
106 | | Matrix *patternMatrix, |
107 | | const Matrix &aContextMatrix, |
108 | | nsIFrame *aSource, |
109 | | nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, |
110 | | float aGraphicOpacity, |
111 | | const gfxRect *aOverrideBounds, |
112 | | imgDrawingParams& aImgParams); |
113 | | |
114 | | /** |
115 | | * A <pattern> element may reference another <pattern> element using |
116 | | * xlink:href and, if it doesn't have any child content of its own, then it |
117 | | * will "inherit" the children of the referenced pattern (which may itself be |
118 | | * inheriting its children if it references another <pattern>). This |
119 | | * function returns this nsSVGPatternFrame or the first pattern along the |
120 | | * reference chain (if there is one) to have children. |
121 | | */ |
122 | | nsSVGPatternFrame* GetPatternWithChildren(); |
123 | | |
124 | | gfxRect GetPatternRect(uint16_t aPatternUnits, |
125 | | const gfxRect &bbox, |
126 | | const Matrix &callerCTM, |
127 | | nsIFrame *aTarget); |
128 | | gfxMatrix ConstructCTM(const nsSVGViewBox& aViewBox, |
129 | | uint16_t aPatternContentUnits, |
130 | | uint16_t aPatternUnits, |
131 | | const gfxRect &callerBBox, |
132 | | const Matrix &callerCTM, |
133 | | nsIFrame *aTarget); |
134 | | |
135 | | private: |
136 | | // this is a *temporary* reference to the frame of the element currently |
137 | | // referencing our pattern. This must be temporary because different |
138 | | // referencing frames will all reference this one frame |
139 | | mozilla::SVGGeometryFrame* mSource; |
140 | | nsAutoPtr<gfxMatrix> mCTM; |
141 | | |
142 | | protected: |
143 | | // This flag is used to detect loops in xlink:href processing |
144 | | bool mLoopFlag; |
145 | | bool mNoHRefURI; |
146 | | }; |
147 | | |
148 | | #endif |