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/. */
7 #ifndef LAYOUT_SVG_SVGPATTERNFRAME_H_
8 #define LAYOUT_SVG_SVGPATTERNFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "gfxMatrix.h"
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/SVGPaintServerFrame.h"
15 #include "mozilla/UniquePtr.h"
21 class SVGAnimatedLength
;
22 class SVGAnimatedPreserveAspectRatio
;
23 class SVGAnimatedTransformList
;
24 class SVGAnimatedViewBox
;
25 class SVGGeometryFrame
;
26 } // namespace mozilla
28 nsIFrame
* NS_NewSVGPatternFrame(mozilla::PresShell
* aPresShell
,
29 mozilla::ComputedStyle
* aStyle
);
33 class SVGPatternFrame final
: public SVGPaintServerFrame
{
34 using SourceSurface
= gfx::SourceSurface
;
37 NS_DECL_FRAMEARENA_HELPERS(SVGPatternFrame
)
40 friend nsIFrame
* ::NS_NewSVGPatternFrame(mozilla::PresShell
* aPresShell
,
41 ComputedStyle
* aStyle
);
43 explicit SVGPatternFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
);
45 // SVGPaintServerFrame methods:
46 already_AddRefed
<gfxPattern
> GetPaintServerPattern(
47 nsIFrame
* aSource
, const DrawTarget
* aDrawTarget
,
48 const gfxMatrix
& aContextMatrix
, StyleSVGPaint
nsStyleSVG::*aFillOrStroke
,
49 float aGraphicOpacity
, imgDrawingParams
& aImgParams
,
50 const gfxRect
* aOverrideBounds
) override
;
53 // SVGContainerFrame methods:
54 gfxMatrix
GetCanvasTM() override
;
56 // nsIFrame interface:
57 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
58 int32_t aModType
) override
;
61 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
62 nsIFrame
* aPrevInFlow
) override
;
65 #ifdef DEBUG_FRAME_DUMP
66 nsresult
GetFrameName(nsAString
& aResult
) const override
{
67 return MakeFrameName(u
"SVGPattern"_ns
, aResult
);
73 * Parses this frame's href and - if it references another pattern - returns
74 * it. It also makes this frame a rendering observer of the specified ID.
76 SVGPatternFrame
* GetReferencedPattern();
78 // Accessors to lookup pattern attributes
79 uint16_t GetEnumValue(uint32_t aIndex
, nsIContent
* aDefault
);
80 uint16_t GetEnumValue(uint32_t aIndex
) {
81 return GetEnumValue(aIndex
, mContent
);
83 SVGPatternFrame
* GetPatternTransformFrame(SVGPatternFrame
* aDefault
);
84 gfxMatrix
GetPatternTransform();
85 const SVGAnimatedViewBox
& GetViewBox(nsIContent
* aDefault
);
86 const SVGAnimatedViewBox
& GetViewBox() { return GetViewBox(mContent
); }
87 const SVGAnimatedPreserveAspectRatio
& GetPreserveAspectRatio(
88 nsIContent
* aDefault
);
89 const SVGAnimatedPreserveAspectRatio
& GetPreserveAspectRatio() {
90 return GetPreserveAspectRatio(mContent
);
92 const SVGAnimatedLength
* GetLengthValue(uint32_t aIndex
,
93 nsIContent
* aDefault
);
94 const SVGAnimatedLength
* GetLengthValue(uint32_t aIndex
) {
95 return GetLengthValue(aIndex
, mContent
);
98 void PaintChildren(DrawTarget
* aDrawTarget
,
99 SVGPatternFrame
* aPatternWithChildren
, nsIFrame
* aSource
,
100 float aGraphicOpacity
, imgDrawingParams
& aImgParams
);
102 already_AddRefed
<SourceSurface
> PaintPattern(
103 const DrawTarget
* aDrawTarget
, Matrix
* patternMatrix
,
104 const Matrix
& aContextMatrix
, nsIFrame
* aSource
,
105 StyleSVGPaint
nsStyleSVG::*aFillOrStroke
, float aGraphicOpacity
,
106 const gfxRect
* aOverrideBounds
, imgDrawingParams
& aImgParams
);
109 * A <pattern> element may reference another <pattern> element using
110 * xlink:href and, if it doesn't have any child content of its own, then it
111 * will "inherit" the children of the referenced pattern (which may itself be
112 * inheriting its children if it references another <pattern>). This
113 * function returns this SVGPatternFrame or the first pattern along the
114 * reference chain (if there is one) to have children.
116 SVGPatternFrame
* GetPatternWithChildren();
118 gfxRect
GetPatternRect(uint16_t aPatternUnits
, const gfxRect
& bbox
,
119 const Matrix
& aTargetCTM
, nsIFrame
* aTarget
);
120 gfxMatrix
ConstructCTM(const SVGAnimatedViewBox
& aViewBox
,
121 uint16_t aPatternContentUnits
, uint16_t aPatternUnits
,
122 const gfxRect
& callerBBox
, const Matrix
& callerCTM
,
126 // this is a *temporary* reference to the frame of the element currently
127 // referencing our pattern. This must be temporary because different
128 // referencing frames will all reference this one frame
129 SVGGeometryFrame
* mSource
;
130 UniquePtr
<gfxMatrix
> mCTM
;
133 // This flag is used to detect loops in xlink:href processing
138 } // namespace mozilla
140 #endif // LAYOUT_SVG_SVGPATTERNFRAME_H_