Bug 1770025 [wpt PR 34116] - Update wpt metadata, a=testonly
[gecko.git] / layout / svg / SVGGeometryFrame.h
bloba57331883b7f1a227a58219677e857f0b221bd48
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_SVGGEOMETRYFRAME_H_
8 #define LAYOUT_SVG_SVGGEOMETRYFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ISVGDisplayableFrame.h"
12 #include "gfxMatrix.h"
13 #include "gfxRect.h"
14 #include "nsDisplayList.h"
15 #include "nsIFrame.h"
16 #include "nsLiteralString.h"
17 #include "nsQueryFrame.h"
19 namespace mozilla {
21 class DisplaySVGGeometry;
22 class PresShell;
23 class SVGGeometryFrame;
24 class SVGMarkerObserver;
26 namespace gfx {
27 class DrawTarget;
28 } // namespace gfx
30 namespace image {
31 struct imgDrawingParams;
32 } // namespace image
34 } // namespace mozilla
36 class gfxContext;
37 class nsAtom;
38 class nsIFrame;
40 struct nsRect;
42 nsIFrame* NS_NewSVGGeometryFrame(mozilla::PresShell* aPresShell,
43 mozilla::ComputedStyle* aStyle);
45 namespace mozilla {
47 class SVGGeometryFrame : public nsIFrame, public ISVGDisplayableFrame {
48 using DrawTarget = gfx::DrawTarget;
50 friend nsIFrame* ::NS_NewSVGGeometryFrame(mozilla::PresShell* aPresShell,
51 ComputedStyle* aStyle);
53 friend class DisplaySVGGeometry;
55 protected:
56 SVGGeometryFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
57 nsIFrame::ClassID aID = kClassID)
58 : nsIFrame(aStyle, aPresContext, aID) {
59 AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_MAY_BE_TRANSFORMED);
62 public:
63 NS_DECL_QUERYFRAME
64 NS_DECL_FRAMEARENA_HELPERS(SVGGeometryFrame)
66 // nsIFrame interface:
67 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
68 nsIFrame* aPrevInFlow) override;
70 virtual bool IsFrameOfType(uint32_t aFlags) const override {
71 if (aFlags & eSupportsContainLayoutAndPaint) {
72 return false;
75 return nsIFrame::IsFrameOfType(aFlags & ~nsIFrame::eSVG);
78 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
79 int32_t aModType) override;
81 virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
83 virtual bool IsSVGTransformed(
84 Matrix* aOwnTransforms = nullptr,
85 Matrix* aFromParentTransforms = nullptr) const override;
87 #ifdef DEBUG_FRAME_DUMP
88 virtual nsresult GetFrameName(nsAString& aResult) const override {
89 return MakeFrameName(u"SVGGeometry"_ns, aResult);
91 #endif
93 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
94 const nsDisplayListSet& aLists) override;
96 // SVGGeometryFrame methods
97 gfxMatrix GetCanvasTM();
99 bool IsInvisible() const;
101 protected:
102 // ISVGDisplayableFrame interface:
103 virtual void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
104 imgDrawingParams& aImgParams,
105 const nsIntRect* aDirtyRect = nullptr) override;
106 virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
107 virtual void ReflowSVG() override;
108 virtual void NotifySVGChanged(uint32_t aFlags) override;
109 virtual SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
110 uint32_t aFlags) override;
111 virtual bool IsDisplayContainer() override { return false; }
114 * This function returns a set of bit flags indicating which parts of the
115 * element (fill, stroke, bounds) should intercept pointer events. It takes
116 * into account the type of element and the value of the 'pointer-events'
117 * property on the element.
119 virtual uint16_t GetHitTestFlags();
121 private:
122 enum { eRenderFill = 1, eRenderStroke = 2 };
123 void Render(gfxContext* aContext, uint32_t aRenderComponents,
124 const gfxMatrix& aTransform, imgDrawingParams& aImgParams);
126 virtual bool CreateWebRenderCommands(
127 mozilla::wr::DisplayListBuilder& aBuilder,
128 mozilla::wr::IpcResourceUpdateQueue& aResources,
129 const mozilla::layers::StackingContextHelper& aSc,
130 mozilla::layers::RenderRootStateManager* aManager,
131 nsDisplayListBuilder* aDisplayListBuilder, DisplaySVGGeometry* aItem,
132 bool aDryRun);
134 * @param aMatrix The transform that must be multiplied onto aContext to
135 * establish this frame's SVG user space.
137 void PaintMarkers(gfxContext& aContext, const gfxMatrix& aTransform,
138 imgDrawingParams& aImgParams);
141 * Get the stroke width that markers should use, accounting for
142 * non-scaling stroke.
144 float GetStrokeWidthForMarkers();
147 //----------------------------------------------------------------------
148 // Display list item:
150 class DisplaySVGGeometry final : public nsPaintedDisplayItem {
151 using imgDrawingParams = image::imgDrawingParams;
153 public:
154 DisplaySVGGeometry(nsDisplayListBuilder* aBuilder, SVGGeometryFrame* aFrame)
155 : nsPaintedDisplayItem(aBuilder, aFrame) {
156 MOZ_COUNT_CTOR(DisplaySVGGeometry);
157 MOZ_ASSERT(aFrame, "Must have a frame!");
160 MOZ_COUNTED_DTOR_OVERRIDE(DisplaySVGGeometry)
162 NS_DISPLAY_DECL_NAME("DisplaySVGGeometry", TYPE_SVG_GEOMETRY)
164 virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
165 HitTestState* aState,
166 nsTArray<nsIFrame*>* aOutFrames) override;
167 virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
169 nsDisplayItemGeometry* AllocateGeometry(
170 nsDisplayListBuilder* aBuilder) override {
171 return new nsDisplayItemGenericImageGeometry(this, aBuilder);
174 void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
175 const nsDisplayItemGeometry* aGeometry,
176 nsRegion* aInvalidRegion) const override;
178 // Whether this part of the SVG should be natively handled by webrender,
179 // potentially becoming an "active layer" inside a blob image.
180 bool ShouldBeActive(mozilla::wr::DisplayListBuilder& aBuilder,
181 mozilla::wr::IpcResourceUpdateQueue& aResources,
182 const mozilla::layers::StackingContextHelper& aSc,
183 mozilla::layers::RenderRootStateManager* aManager,
184 nsDisplayListBuilder* aDisplayListBuilder) {
185 // We delegate this question to the parent frame to take advantage of
186 // the SVGGeometryFrame inheritance hierarchy which provides actual
187 // implementation details. The dryRun flag prevents serious side-effects.
188 auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
189 return frame->CreateWebRenderCommands(aBuilder, aResources, aSc, aManager,
190 aDisplayListBuilder, this,
191 /*aDryRun=*/true);
194 virtual bool CreateWebRenderCommands(
195 mozilla::wr::DisplayListBuilder& aBuilder,
196 mozilla::wr::IpcResourceUpdateQueue& aResources,
197 const mozilla::layers::StackingContextHelper& aSc,
198 mozilla::layers::RenderRootStateManager* aManager,
199 nsDisplayListBuilder* aDisplayListBuilder) override {
200 // We delegate this question to the parent frame to take advantage of
201 // the SVGGeometryFrame inheritance hierarchy which provides actual
202 // implementation details.
203 auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
204 bool result = frame->CreateWebRenderCommands(aBuilder, aResources, aSc,
205 aManager, aDisplayListBuilder,
206 this, /*aDryRun=*/false);
207 MOZ_ASSERT(result, "ShouldBeActive inconsistent with CreateWRCommands?");
208 return result;
211 bool IsInvisible() const override {
212 auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
213 return frame->IsInvisible();
217 } // namespace mozilla
219 #endif // LAYOUT_SVG_SVGGEOMETRYFRAME_H_