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"
14 #include "nsDisplayList.h"
16 #include "nsLiteralString.h"
17 #include "nsQueryFrame.h"
21 class DisplaySVGGeometry
;
23 class SVGGeometryFrame
;
24 class SVGMarkerObserver
;
31 struct imgDrawingParams
;
34 } // namespace mozilla
42 nsIFrame
* NS_NewSVGGeometryFrame(mozilla::PresShell
* aPresShell
,
43 mozilla::ComputedStyle
* aStyle
);
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
;
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
);
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
) {
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
);
93 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
94 const nsDisplayListSet
& aLists
) override
;
96 // SVGGeometryFrame methods
97 gfxMatrix
GetCanvasTM();
99 bool IsInvisible() const;
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();
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
,
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
;
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,
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?");
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_