|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef __NS_SVGPATTERNFRAME_H__ |
|
7 #define __NS_SVGPATTERNFRAME_H__ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "gfxMatrix.h" |
|
11 #include "mozilla/gfx/2D.h" |
|
12 #include "nsSVGPaintServerFrame.h" |
|
13 |
|
14 class gfxASurface; |
|
15 class gfxContext; |
|
16 class nsIFrame; |
|
17 class nsSVGElement; |
|
18 class nsSVGLength2; |
|
19 class nsSVGPathGeometryFrame; |
|
20 class nsSVGViewBox; |
|
21 |
|
22 namespace mozilla { |
|
23 class SVGAnimatedPreserveAspectRatio; |
|
24 class nsSVGAnimatedTransformList; |
|
25 } // namespace mozilla |
|
26 |
|
27 typedef nsSVGPaintServerFrame nsSVGPatternFrameBase; |
|
28 |
|
29 /** |
|
30 * Patterns can refer to other patterns. We create an nsSVGPaintingProperty |
|
31 * with property type nsGkAtoms::href to track the referenced pattern. |
|
32 */ |
|
33 class nsSVGPatternFrame : public nsSVGPatternFrameBase |
|
34 { |
|
35 public: |
|
36 NS_DECL_FRAMEARENA_HELPERS |
|
37 |
|
38 friend nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell, |
|
39 nsStyleContext* aContext); |
|
40 |
|
41 nsSVGPatternFrame(nsStyleContext* aContext); |
|
42 |
|
43 // nsSVGPaintServerFrame methods: |
|
44 virtual already_AddRefed<gfxPattern> |
|
45 GetPaintServerPattern(nsIFrame *aSource, |
|
46 const gfxMatrix& aContextMatrix, |
|
47 nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, |
|
48 float aOpacity, |
|
49 const gfxRect *aOverrideBounds) MOZ_OVERRIDE; |
|
50 |
|
51 public: |
|
52 typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio; |
|
53 |
|
54 // nsSVGContainerFrame methods: |
|
55 virtual gfxMatrix GetCanvasTM(uint32_t aFor, |
|
56 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; |
|
57 |
|
58 // nsIFrame interface: |
|
59 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
60 nsIAtom* aAttribute, |
|
61 int32_t aModType) MOZ_OVERRIDE; |
|
62 |
|
63 #ifdef DEBUG |
|
64 virtual void Init(nsIContent* aContent, |
|
65 nsIFrame* aParent, |
|
66 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
67 #endif |
|
68 |
|
69 /** |
|
70 * Get the "type" of the frame |
|
71 * |
|
72 * @see nsGkAtoms::svgPatternFrame |
|
73 */ |
|
74 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
75 |
|
76 #ifdef DEBUG_FRAME_DUMP |
|
77 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
|
78 { |
|
79 return MakeFrameName(NS_LITERAL_STRING("SVGPattern"), aResult); |
|
80 } |
|
81 #endif // DEBUG |
|
82 |
|
83 protected: |
|
84 // Internal methods for handling referenced patterns |
|
85 class AutoPatternReferencer; |
|
86 nsSVGPatternFrame* GetReferencedPattern(); |
|
87 nsSVGPatternFrame* GetReferencedPatternIfNotInUse(); |
|
88 |
|
89 // Accessors to lookup pattern attributes |
|
90 uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault); |
|
91 uint16_t GetEnumValue(uint32_t aIndex) |
|
92 { |
|
93 return GetEnumValue(aIndex, mContent); |
|
94 } |
|
95 mozilla::nsSVGAnimatedTransformList* GetPatternTransformList( |
|
96 nsIContent* aDefault); |
|
97 gfxMatrix GetPatternTransform(); |
|
98 const nsSVGViewBox &GetViewBox(nsIContent *aDefault); |
|
99 const nsSVGViewBox &GetViewBox() { return GetViewBox(mContent); } |
|
100 const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio( |
|
101 nsIContent *aDefault); |
|
102 const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio() |
|
103 { |
|
104 return GetPreserveAspectRatio(mContent); |
|
105 } |
|
106 const nsSVGLength2 *GetLengthValue(uint32_t aIndex, nsIContent *aDefault); |
|
107 const nsSVGLength2 *GetLengthValue(uint32_t aIndex) |
|
108 { |
|
109 return GetLengthValue(aIndex, mContent); |
|
110 } |
|
111 |
|
112 nsresult PaintPattern(gfxASurface **surface, |
|
113 gfxMatrix *patternMatrix, |
|
114 const gfxMatrix &aContextMatrix, |
|
115 nsIFrame *aSource, |
|
116 nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, |
|
117 float aGraphicOpacity, |
|
118 const gfxRect *aOverrideBounds); |
|
119 nsIFrame* GetPatternFirstChild(); |
|
120 gfxRect GetPatternRect(uint16_t aPatternUnits, |
|
121 const gfxRect &bbox, |
|
122 const Matrix &callerCTM, |
|
123 nsIFrame *aTarget); |
|
124 gfxMatrix ConstructCTM(const nsSVGViewBox& aViewBox, |
|
125 uint16_t aPatternContentUnits, |
|
126 uint16_t aPatternUnits, |
|
127 const gfxRect &callerBBox, |
|
128 const Matrix &callerCTM, |
|
129 nsIFrame *aTarget); |
|
130 |
|
131 private: |
|
132 // this is a *temporary* reference to the frame of the element currently |
|
133 // referencing our pattern. This must be temporary because different |
|
134 // referencing frames will all reference this one frame |
|
135 nsSVGPathGeometryFrame *mSource; |
|
136 nsAutoPtr<gfxMatrix> mCTM; |
|
137 |
|
138 protected: |
|
139 // This flag is used to detect loops in xlink:href processing |
|
140 bool mLoopFlag; |
|
141 bool mNoHRefURI; |
|
142 }; |
|
143 |
|
144 #endif |