Bug 1814091 - Move CanvasContext.getPreferredFormat to GPU.getPreferredCanvasFormat...
[gecko.git] / layout / svg / SVGOuterSVGFrame.h
blob68ac7caba5854751a1012729d7bc80b3a5e95877
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_SVGOUTERSVGFRAME_H_
8 #define LAYOUT_SVG_SVGOUTERSVGFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ISVGSVGFrame.h"
12 #include "mozilla/SVGContainerFrame.h"
14 class gfxContext;
16 namespace mozilla {
17 class AutoSVGViewHandler;
18 class SVGFragmentIdentifier;
19 class PresShell;
20 } // namespace mozilla
22 nsContainerFrame* NS_NewSVGOuterSVGFrame(mozilla::PresShell* aPresShell,
23 mozilla::ComputedStyle* aStyle);
24 nsContainerFrame* NS_NewSVGOuterSVGAnonChildFrame(
25 mozilla::PresShell* aPresShell, mozilla::ComputedStyle* aStyle);
27 namespace mozilla {
29 ////////////////////////////////////////////////////////////////////////
30 // SVGOuterSVGFrame class
32 class SVGOuterSVGFrame final : public SVGDisplayContainerFrame,
33 public ISVGSVGFrame {
34 using imgDrawingParams = image::imgDrawingParams;
36 friend nsContainerFrame* ::NS_NewSVGOuterSVGFrame(
37 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
38 friend class AutoSVGViewHandler;
39 friend class SVGFragmentIdentifier;
41 protected:
42 explicit SVGOuterSVGFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
44 public:
45 NS_DECL_QUERYFRAME
46 NS_DECL_FRAMEARENA_HELPERS(SVGOuterSVGFrame)
48 // nsIFrame:
49 nscoord GetMinISize(gfxContext* aRenderingContext) override;
50 nscoord GetPrefISize(gfxContext* aRenderingContext) override;
52 IntrinsicSize GetIntrinsicSize() override;
53 AspectRatio GetIntrinsicRatio() const override;
55 SizeComputationResult ComputeSize(
56 gfxContext* aRenderingContext, WritingMode aWritingMode,
57 const LogicalSize& aCBSize, nscoord aAvailableISize,
58 const LogicalSize& aMargin, const LogicalSize& aBorderPadding,
59 const mozilla::StyleSizeOverrides& aSizeOverrides,
60 ComputeSizeFlags aFlags) override;
62 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
63 const ReflowInput& aReflowInput,
64 nsReflowStatus& aStatus) override;
66 void DidReflow(nsPresContext* aPresContext,
67 const ReflowInput* aReflowInput) override;
69 void UnionChildOverflow(mozilla::OverflowAreas& aOverflowAreas) override;
71 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
72 const nsDisplayListSet& aLists) override;
74 void Init(nsIContent* aContent, nsContainerFrame* aParent,
75 nsIFrame* aPrevInFlow) override;
77 bool IsFrameOfType(uint32_t aFlags) const override {
78 return SVGDisplayContainerFrame::IsFrameOfType(
79 aFlags &
80 ~(eSupportsContainLayoutAndPaint | eReplaced | eReplacedSizing));
83 #ifdef DEBUG_FRAME_DUMP
84 nsresult GetFrameName(nsAString& aResult) const override {
85 return MakeFrameName(u"SVGOuterSVG"_ns, aResult);
87 #endif
89 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
91 void DestroyFrom(nsIFrame* aDestructRoot,
92 PostDestroyData& aPostDestroyData) override;
94 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
95 int32_t aModType) override;
97 nsContainerFrame* GetContentInsertionFrame() override {
98 // Any children must be added to our single anonymous inner frame kid.
99 MOZ_ASSERT(
100 PrincipalChildList().FirstChild() &&
101 PrincipalChildList().FirstChild()->IsSVGOuterSVGAnonChildFrame(),
102 "Where is our anonymous child?");
103 return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
106 bool IsSVGTransformed(Matrix* aOwnTransform,
107 Matrix* aFromParentTransform) const override;
109 // Return our anonymous box child.
110 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
112 // ISVGSVGFrame interface:
113 void NotifyViewportOrTransformChanged(uint32_t aFlags) override;
115 // ISVGDisplayableFrame methods:
116 void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
117 imgDrawingParams& aImgParams,
118 const nsIntRect* aDirtyRect = nullptr) override;
119 SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
120 uint32_t aFlags) override;
122 // SVGContainerFrame methods:
123 gfxMatrix GetCanvasTM() override;
125 bool HasChildrenOnlyTransform(Matrix* aTransform) const override {
126 // Our anonymous wrapper child must claim our children-only transforms as
127 // its own so that our real children (the frames it wraps) are transformed
128 // by them, and we must pretend we don't have any children-only transforms
129 // so that our anonymous child is _not_ transformed by them.
130 return false;
134 * Return true only if the height is unspecified (defaulting to 100%) or else
135 * the height is explicitly set to a percentage value no greater than 100%.
137 bool VerticalScrollbarNotNeeded() const;
139 bool IsCallingReflowSVG() const { return mCallingReflowSVG; }
141 protected:
142 /* Returns true if our content is the document element and our document is
143 * being used as an image.
145 bool IsRootOfImage();
146 float ComputeFullZoom() const;
148 void MaybeSendIntrinsicSizeAndRatioToEmbedder();
149 void MaybeSendIntrinsicSizeAndRatioToEmbedder(Maybe<IntrinsicSize>,
150 Maybe<AspectRatio>);
152 float mFullZoom = 1.0f;
154 bool mCallingReflowSVG = false;
155 bool mIsRootContent = false;
156 bool mIsInObjectOrEmbed = false;
157 bool mIsInIframe = false;
160 ////////////////////////////////////////////////////////////////////////
161 // SVGOuterSVGAnonChildFrame class
164 * SVGOuterSVGFrames have a single direct child that is an instance of this
165 * class, and which is used to wrap their real child frames. Such anonymous
166 * wrapper frames created from this class exist because SVG frames need their
167 * GetPosition() offset to be their offset relative to "user space" (in app
168 * units) so that they can play nicely with nsDisplayTransform. This is fine
169 * for all SVG frames except for direct children of an SVGOuterSVGFrame,
170 * since an SVGOuterSVGFrame can have CSS border and padding (unlike other
171 * SVG frames). The direct children can't include the offsets due to any such
172 * border/padding in their mRects since that would break nsDisplayTransform,
173 * but not including these offsets would break other parts of the Mozilla code
174 * that assume a frame's mRect contains its border-box-to-parent-border-box
175 * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on
176 * it. Wrapping an SVGOuterSVGFrame's children in an instance of this class
177 * with its GetPosition() set to its SVGOuterSVGFrame's border/padding offset
178 * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy.
180 * The reason that this class inherit from SVGDisplayContainerFrame rather
181 * than simply from nsContainerFrame is so that we can avoid having special
182 * handling for these inner wrappers in multiple parts of the SVG code. For
183 * example, the implementations of IsSVGTransformed and GetCanvasTM assume
184 * SVGContainerFrame instances all the way up to the SVGOuterSVGFrame.
186 class SVGOuterSVGAnonChildFrame final : public SVGDisplayContainerFrame {
187 friend nsContainerFrame* ::NS_NewSVGOuterSVGAnonChildFrame(
188 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
190 explicit SVGOuterSVGAnonChildFrame(ComputedStyle* aStyle,
191 nsPresContext* aPresContext)
192 : SVGDisplayContainerFrame(aStyle, aPresContext, kClassID) {}
194 public:
195 NS_DECL_FRAMEARENA_HELPERS(SVGOuterSVGAnonChildFrame)
197 #ifdef DEBUG
198 void Init(nsIContent* aContent, nsContainerFrame* aParent,
199 nsIFrame* aPrevInFlow) override;
200 #endif
202 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
203 const nsDisplayListSet& aLists) override;
205 #ifdef DEBUG_FRAME_DUMP
206 nsresult GetFrameName(nsAString& aResult) const override {
207 return MakeFrameName(u"SVGOuterSVGAnonChild"_ns, aResult);
209 #endif
211 bool IsSVGTransformed(Matrix* aOwnTransform,
212 Matrix* aFromParentTransform) const override;
214 // SVGContainerFrame methods:
215 gfxMatrix GetCanvasTM() override {
216 // GetCanvasTM returns the transform from an SVG frame to the frame's
217 // SVGOuterSVGFrame's content box, so we do not include any x/y offset
218 // set on us for any CSS border or padding on our SVGOuterSVGFrame.
219 return static_cast<SVGOuterSVGFrame*>(GetParent())->GetCanvasTM();
223 } // namespace mozilla
225 #endif // LAYOUT_SVG_SVGOUTERSVGFRAME_H_