Bug 1895153 - Implement "Find in page..." menu functionality r=android-reviewers...
[gecko.git] / layout / svg / SVGOuterSVGFrame.h
blobea060f3e99aada59ce9a0104fef9e23a38162260
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 #ifdef DEBUG_FRAME_DUMP
78 nsresult GetFrameName(nsAString& aResult) const override {
79 return MakeFrameName(u"SVGOuterSVG"_ns, aResult);
81 #endif
83 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
85 void Destroy(DestroyContext&) override;
87 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
88 int32_t aModType) override;
90 nsContainerFrame* GetContentInsertionFrame() override {
91 // Any children must be added to our single anonymous inner frame kid.
92 MOZ_ASSERT(
93 PrincipalChildList().FirstChild() &&
94 PrincipalChildList().FirstChild()->IsSVGOuterSVGAnonChildFrame(),
95 "Where is our anonymous child?");
96 return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
99 bool IsSVGTransformed(Matrix* aOwnTransform,
100 Matrix* aFromParentTransform) const override;
102 // Return our anonymous box child.
103 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
105 // ISVGSVGFrame interface:
106 void NotifyViewportOrTransformChanged(uint32_t aFlags) override;
108 // ISVGDisplayableFrame methods:
109 void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
110 imgDrawingParams& aImgParams) override;
111 SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
112 uint32_t aFlags) override;
114 // SVGContainerFrame methods:
115 gfxMatrix GetCanvasTM() override;
117 bool HasChildrenOnlyTransform(Matrix* aTransform) const override {
118 // Our anonymous wrapper child must claim our children-only transforms as
119 // its own so that our real children (the frames it wraps) are transformed
120 // by them, and we must pretend we don't have any children-only transforms
121 // so that our anonymous child is _not_ transformed by them.
122 return false;
126 * Return true only if the height is unspecified (defaulting to 100%) or else
127 * the height is explicitly set to a percentage value no greater than 100%.
129 bool VerticalScrollbarNotNeeded() const;
131 bool IsCallingReflowSVG() const { return mCallingReflowSVG; }
133 protected:
134 /* Returns true if our content is the document element and our document is
135 * being used as an image.
137 bool IsRootOfImage();
138 float ComputeFullZoom() const;
140 void MaybeSendIntrinsicSizeAndRatioToEmbedder();
141 void MaybeSendIntrinsicSizeAndRatioToEmbedder(Maybe<IntrinsicSize>,
142 Maybe<AspectRatio>);
144 float mFullZoom = 1.0f;
146 bool mCallingReflowSVG = false;
147 bool mIsRootContent = false;
148 bool mIsInObjectOrEmbed = false;
149 bool mIsInIframe = false;
152 ////////////////////////////////////////////////////////////////////////
153 // SVGOuterSVGAnonChildFrame class
156 * SVGOuterSVGFrames have a single direct child that is an instance of this
157 * class, and which is used to wrap their real child frames. Such anonymous
158 * wrapper frames created from this class exist because SVG frames need their
159 * GetPosition() offset to be their offset relative to "user space" (in app
160 * units) so that they can play nicely with nsDisplayTransform. This is fine
161 * for all SVG frames except for direct children of an SVGOuterSVGFrame,
162 * since an SVGOuterSVGFrame can have CSS border and padding (unlike other
163 * SVG frames). The direct children can't include the offsets due to any such
164 * border/padding in their mRects since that would break nsDisplayTransform,
165 * but not including these offsets would break other parts of the Mozilla code
166 * that assume a frame's mRect contains its border-box-to-parent-border-box
167 * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on
168 * it. Wrapping an SVGOuterSVGFrame's children in an instance of this class
169 * with its GetPosition() set to its SVGOuterSVGFrame's border/padding offset
170 * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy.
172 * The reason that this class inherit from SVGDisplayContainerFrame rather
173 * than simply from nsContainerFrame is so that we can avoid having special
174 * handling for these inner wrappers in multiple parts of the SVG code. For
175 * example, the implementations of IsSVGTransformed and GetCanvasTM assume
176 * SVGContainerFrame instances all the way up to the SVGOuterSVGFrame.
178 class SVGOuterSVGAnonChildFrame final : public SVGDisplayContainerFrame {
179 friend nsContainerFrame* ::NS_NewSVGOuterSVGAnonChildFrame(
180 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
182 explicit SVGOuterSVGAnonChildFrame(ComputedStyle* aStyle,
183 nsPresContext* aPresContext)
184 : SVGDisplayContainerFrame(aStyle, aPresContext, kClassID) {}
186 public:
187 NS_DECL_FRAMEARENA_HELPERS(SVGOuterSVGAnonChildFrame)
189 #ifdef DEBUG
190 void Init(nsIContent* aContent, nsContainerFrame* aParent,
191 nsIFrame* aPrevInFlow) override;
192 #endif
194 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
195 const nsDisplayListSet& aLists) override;
197 #ifdef DEBUG_FRAME_DUMP
198 nsresult GetFrameName(nsAString& aResult) const override {
199 return MakeFrameName(u"SVGOuterSVGAnonChild"_ns, aResult);
201 #endif
203 bool IsSVGTransformed(Matrix* aOwnTransform,
204 Matrix* aFromParentTransform) const override;
206 // SVGContainerFrame methods:
207 gfxMatrix GetCanvasTM() override {
208 // GetCanvasTM returns the transform from an SVG frame to the frame's
209 // SVGOuterSVGFrame's content box, so we do not include any x/y offset
210 // set on us for any CSS border or padding on our SVGOuterSVGFrame.
211 return static_cast<SVGOuterSVGFrame*>(GetParent())->GetCanvasTM();
215 } // namespace mozilla
217 #endif // LAYOUT_SVG_SVGOUTERSVGFRAME_H_