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_SVGGRADIENTFRAME_H_
8 #define LAYOUT_SVG_SVGGRADIENTFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SVGPaintServerFrame.h"
12 #include "gfxMatrix.h"
15 #include "nsCSSRenderingGradients.h"
17 #include "nsLiteralString.h"
25 class SVGAnimatedTransformList
;
28 class SVGLinearGradientElement
;
29 class SVGRadialGradientElement
;
31 } // namespace mozilla
33 nsIFrame
* NS_NewSVGLinearGradientFrame(mozilla::PresShell
* aPresShell
,
34 mozilla::ComputedStyle
* aStyle
);
35 nsIFrame
* NS_NewSVGRadialGradientFrame(mozilla::PresShell
* aPresShell
,
36 mozilla::ComputedStyle
* aStyle
);
40 class SVGGradientFrame
: public SVGPaintServerFrame
{
41 using ExtendMode
= gfx::ExtendMode
;
44 SVGGradientFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
,
48 NS_DECL_ABSTRACT_FRAME(SVGGradientFrame
)
50 NS_DECL_QUERYFRAME_TARGET(SVGGradientFrame
)
52 // SVGPaintServerFrame methods:
53 already_AddRefed
<gfxPattern
> GetPaintServerPattern(
54 nsIFrame
* aSource
, const DrawTarget
* aDrawTarget
,
55 const gfxMatrix
& aContextMatrix
, StyleSVGPaint
nsStyleSVG::*aFillOrStroke
,
56 float aGraphicOpacity
, imgDrawingParams
& aImgParams
,
57 const gfxRect
* aOverrideBounds
) override
;
59 // nsIFrame interface:
60 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
61 int32_t aModType
) override
;
63 #ifdef DEBUG_FRAME_DUMP
64 nsresult
GetFrameName(nsAString
& aResult
) const override
{
65 return MakeFrameName(u
"SVGGradient"_ns
, aResult
);
71 * Parses this frame's href and - if it references another gradient - returns
72 * it. It also makes this frame a rendering observer of the specified ID.
74 SVGGradientFrame
* GetReferencedGradient();
76 void GetStops(nsTArray
<ColorStop
>* aStops
, float aGraphicOpacity
);
78 const SVGAnimatedTransformList
* GetGradientTransformList(
79 nsIContent
* aDefault
);
80 // Will be singular for gradientUnits="objectBoundingBox" with an empty bbox.
81 gfxMatrix
GetGradientTransform(nsIFrame
* aSource
,
82 const gfxRect
* aOverrideBounds
);
85 virtual bool GradientVectorLengthIsZero() = 0;
86 virtual already_AddRefed
<gfxPattern
> CreateGradient() = 0;
88 // Accessors to lookup gradient attributes
89 uint16_t GetEnumValue(uint32_t aIndex
, nsIContent
* aDefault
);
90 uint16_t GetEnumValue(uint32_t aIndex
) {
91 return GetEnumValue(aIndex
, mContent
);
93 uint16_t GetGradientUnits();
94 uint16_t GetSpreadMethod();
96 // Gradient-type-specific lookups since the length values differ between
97 // linear and radial gradients
98 virtual dom::SVGLinearGradientElement
* GetLinearGradientWithLength(
99 uint32_t aIndex
, dom::SVGLinearGradientElement
* aDefault
);
100 virtual dom::SVGRadialGradientElement
* GetRadialGradientWithLength(
101 uint32_t aIndex
, dom::SVGRadialGradientElement
* aDefault
);
103 // The frame our gradient is (currently) being applied to
107 // Flag to mark this frame as "in use" during recursive calls along our
108 // gradient's reference chain so we can detect reference loops. See:
109 // http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
111 // Gradients often don't reference other gradients, so here we cache
112 // the fact that that isn't happening.
116 // -------------------------------------------------------------------------
118 // -------------------------------------------------------------------------
120 class SVGLinearGradientFrame final
: public SVGGradientFrame
{
121 friend nsIFrame
* ::NS_NewSVGLinearGradientFrame(
122 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
125 explicit SVGLinearGradientFrame(ComputedStyle
* aStyle
,
126 nsPresContext
* aPresContext
)
127 : SVGGradientFrame(aStyle
, aPresContext
, kClassID
) {}
131 NS_DECL_FRAMEARENA_HELPERS(SVGLinearGradientFrame
)
133 // nsIFrame interface:
135 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
136 nsIFrame
* aPrevInFlow
) override
;
139 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
140 int32_t aModType
) override
;
142 #ifdef DEBUG_FRAME_DUMP
143 nsresult
GetFrameName(nsAString
& aResult
) const override
{
144 return MakeFrameName(u
"SVGLinearGradient"_ns
, aResult
);
149 float GetLengthValue(uint32_t aIndex
);
150 mozilla::dom::SVGLinearGradientElement
* GetLinearGradientWithLength(
152 mozilla::dom::SVGLinearGradientElement
* aDefault
) override
;
153 bool GradientVectorLengthIsZero() override
;
154 already_AddRefed
<gfxPattern
> CreateGradient() override
;
157 // -------------------------------------------------------------------------
159 // -------------------------------------------------------------------------
161 class SVGRadialGradientFrame final
: public SVGGradientFrame
{
162 friend nsIFrame
* ::NS_NewSVGRadialGradientFrame(
163 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
166 explicit SVGRadialGradientFrame(ComputedStyle
* aStyle
,
167 nsPresContext
* aPresContext
)
168 : SVGGradientFrame(aStyle
, aPresContext
, kClassID
) {}
172 NS_DECL_FRAMEARENA_HELPERS(SVGRadialGradientFrame
)
174 // nsIFrame interface:
176 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
177 nsIFrame
* aPrevInFlow
) override
;
180 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
181 int32_t aModType
) override
;
183 #ifdef DEBUG_FRAME_DUMP
184 nsresult
GetFrameName(nsAString
& aResult
) const override
{
185 return MakeFrameName(u
"SVGRadialGradient"_ns
, aResult
);
190 float GetLengthValue(uint32_t aIndex
);
191 float GetLengthValue(uint32_t aIndex
, float aDefaultValue
);
192 float GetLengthValueFromElement(
193 uint32_t aIndex
, mozilla::dom::SVGRadialGradientElement
& aElement
);
194 mozilla::dom::SVGRadialGradientElement
* GetRadialGradientWithLength(
196 mozilla::dom::SVGRadialGradientElement
* aDefault
) override
;
197 bool GradientVectorLengthIsZero() override
;
198 already_AddRefed
<gfxPattern
> CreateGradient() override
;
201 } // namespace mozilla
203 #endif // LAYOUT_SVG_SVGGRADIENTFRAME_H_