Bug 1818465 - Add test to ensure Utility Actor Names always reflected in about:proces...
[gecko.git] / layout / svg / SVGGradientFrame.h
blob50b78fb06cf0675b3c1f0b05f70d427a00e06965
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"
13 #include "gfxRect.h"
14 #include "nsCOMPtr.h"
15 #include "nsIFrame.h"
16 #include "nsLiteralString.h"
18 class gfxPattern;
19 class nsAtom;
20 class nsIContent;
22 namespace mozilla {
23 class PresShell;
24 class SVGAnimatedTransformList;
26 namespace dom {
27 class SVGLinearGradientElement;
28 class SVGRadialGradientElement;
29 } // namespace dom
30 } // namespace mozilla
32 nsIFrame* NS_NewSVGLinearGradientFrame(mozilla::PresShell* aPresShell,
33 mozilla::ComputedStyle* aStyle);
34 nsIFrame* NS_NewSVGRadialGradientFrame(mozilla::PresShell* aPresShell,
35 mozilla::ComputedStyle* aStyle);
37 namespace mozilla {
39 class SVGGradientFrame : public SVGPaintServerFrame {
40 using ExtendMode = gfx::ExtendMode;
42 protected:
43 SVGGradientFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
44 ClassID aID);
46 public:
47 NS_DECL_ABSTRACT_FRAME(SVGGradientFrame)
48 NS_DECL_QUERYFRAME
49 NS_DECL_QUERYFRAME_TARGET(SVGGradientFrame)
51 // SVGPaintServerFrame methods:
52 already_AddRefed<gfxPattern> GetPaintServerPattern(
53 nsIFrame* aSource, const DrawTarget* aDrawTarget,
54 const gfxMatrix& aContextMatrix, StyleSVGPaint nsStyleSVG::*aFillOrStroke,
55 float aGraphicOpacity, imgDrawingParams& aImgParams,
56 const gfxRect* aOverrideBounds) override;
58 // nsIFrame interface:
59 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
60 int32_t aModType) override;
62 #ifdef DEBUG_FRAME_DUMP
63 nsresult GetFrameName(nsAString& aResult) const override {
64 return MakeFrameName(u"SVGGradient"_ns, aResult);
66 #endif // DEBUG
68 private:
69 /**
70 * Parses this frame's href and - if it references another gradient - returns
71 * it. It also makes this frame a rendering observer of the specified ID.
73 SVGGradientFrame* GetReferencedGradient();
75 // Optionally get a stop frame (returns stop index/count)
76 void GetStopFrames(nsTArray<nsIFrame*>* aStopFrames);
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);
84 protected:
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
104 nsIFrame* mSource;
106 private:
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
110 bool mLoopFlag;
111 // Gradients often don't reference other gradients, so here we cache
112 // the fact that that isn't happening.
113 bool mNoHRefURI;
116 // -------------------------------------------------------------------------
117 // Linear Gradients
118 // -------------------------------------------------------------------------
120 class SVGLinearGradientFrame final : public SVGGradientFrame {
121 friend nsIFrame* ::NS_NewSVGLinearGradientFrame(
122 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
124 protected:
125 explicit SVGLinearGradientFrame(ComputedStyle* aStyle,
126 nsPresContext* aPresContext)
127 : SVGGradientFrame(aStyle, aPresContext, kClassID) {}
129 public:
130 NS_DECL_QUERYFRAME
131 NS_DECL_FRAMEARENA_HELPERS(SVGLinearGradientFrame)
133 // nsIFrame interface:
134 #ifdef DEBUG
135 void Init(nsIContent* aContent, nsContainerFrame* aParent,
136 nsIFrame* aPrevInFlow) override;
137 #endif
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);
146 #endif // DEBUG
148 protected:
149 float GetLengthValue(uint32_t aIndex);
150 mozilla::dom::SVGLinearGradientElement* GetLinearGradientWithLength(
151 uint32_t aIndex,
152 mozilla::dom::SVGLinearGradientElement* aDefault) override;
153 bool GradientVectorLengthIsZero() override;
154 already_AddRefed<gfxPattern> CreateGradient() override;
157 // -------------------------------------------------------------------------
158 // Radial Gradients
159 // -------------------------------------------------------------------------
161 class SVGRadialGradientFrame final : public SVGGradientFrame {
162 friend nsIFrame* ::NS_NewSVGRadialGradientFrame(
163 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
165 protected:
166 explicit SVGRadialGradientFrame(ComputedStyle* aStyle,
167 nsPresContext* aPresContext)
168 : SVGGradientFrame(aStyle, aPresContext, kClassID) {}
170 public:
171 NS_DECL_QUERYFRAME
172 NS_DECL_FRAMEARENA_HELPERS(SVGRadialGradientFrame)
174 // nsIFrame interface:
175 #ifdef DEBUG
176 void Init(nsIContent* aContent, nsContainerFrame* aParent,
177 nsIFrame* aPrevInFlow) override;
178 #endif
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);
187 #endif // DEBUG
189 protected:
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(
195 uint32_t aIndex,
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_