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