no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / layout / svg / SVGGeometryFrame.h
blob9d515410d0a6860ec298a1f97269eac3064cb9bc
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/DisplaySVGItem.h"
12 #include "mozilla/ISVGDisplayableFrame.h"
13 #include "gfxMatrix.h"
14 #include "gfxRect.h"
15 #include "nsIFrame.h"
17 namespace mozilla {
19 class DisplaySVGGeometry;
20 class PresShell;
21 class SVGGeometryFrame;
22 class SVGMarkerObserver;
24 namespace gfx {
25 class DrawTarget;
26 } // namespace gfx
28 namespace image {
29 struct imgDrawingParams;
30 } // namespace image
32 } // namespace mozilla
34 class gfxContext;
35 class nsAtom;
36 class nsIFrame;
38 struct nsRect;
40 nsIFrame* NS_NewSVGGeometryFrame(mozilla::PresShell* aPresShell,
41 mozilla::ComputedStyle* aStyle);
43 namespace mozilla {
45 class SVGGeometryFrame final : public nsIFrame, public ISVGDisplayableFrame {
46 using DrawTarget = gfx::DrawTarget;
48 friend nsIFrame* ::NS_NewSVGGeometryFrame(mozilla::PresShell* aPresShell,
49 ComputedStyle* aStyle);
51 friend class DisplaySVGGeometry;
53 protected:
54 SVGGeometryFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
55 nsIFrame::ClassID aID = kClassID)
56 : nsIFrame(aStyle, aPresContext, aID) {
57 AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_MAY_BE_TRANSFORMED);
60 public:
61 NS_DECL_QUERYFRAME
62 NS_DECL_FRAMEARENA_HELPERS(SVGGeometryFrame)
64 // nsIFrame interface:
65 void Init(nsIContent* aContent, nsContainerFrame* aParent,
66 nsIFrame* aPrevInFlow) override;
68 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
69 int32_t aModType) override;
71 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
73 bool IsSVGTransformed(Matrix* aOwnTransforms = nullptr,
74 Matrix* aFromParentTransforms = nullptr) const override;
76 #ifdef DEBUG_FRAME_DUMP
77 nsresult GetFrameName(nsAString& aResult) const override {
78 return MakeFrameName(u"SVGGeometry"_ns, aResult);
80 #endif
82 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
83 const nsDisplayListSet& aLists) override;
85 // SVGGeometryFrame methods
86 gfxMatrix GetCanvasTM();
88 bool IsInvisible() const;
90 private:
91 // ISVGDisplayableFrame interface:
92 void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
93 imgDrawingParams& aImgParams) override;
94 nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
95 void ReflowSVG() override;
96 void NotifySVGChanged(uint32_t aFlags) override;
97 SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
98 uint32_t aFlags) override;
99 bool IsDisplayContainer() override { return false; }
101 enum { eRenderFill = 1, eRenderStroke = 2 };
102 void Render(gfxContext* aContext, uint32_t aRenderComponents,
103 const gfxMatrix& aTransform, imgDrawingParams& aImgParams);
105 bool CreateWebRenderCommands(
106 mozilla::wr::DisplayListBuilder& aBuilder,
107 mozilla::wr::IpcResourceUpdateQueue& aResources,
108 const mozilla::layers::StackingContextHelper& aSc,
109 mozilla::layers::RenderRootStateManager* aManager,
110 nsDisplayListBuilder* aDisplayListBuilder, DisplaySVGGeometry* aItem,
111 bool aDryRun);
113 * @param aMatrix The transform that must be multiplied onto aContext to
114 * establish this frame's SVG user space.
116 void PaintMarkers(gfxContext& aContext, const gfxMatrix& aTransform,
117 imgDrawingParams& aImgParams);
120 * Get the stroke width that markers should use, accounting for
121 * non-scaling stroke.
123 float GetStrokeWidthForMarkers();
126 //----------------------------------------------------------------------
127 // Display list item:
129 class DisplaySVGGeometry final : public DisplaySVGItem {
130 public:
131 DisplaySVGGeometry(nsDisplayListBuilder* aBuilder, SVGGeometryFrame* aFrame)
132 : DisplaySVGItem(aBuilder, aFrame) {
133 MOZ_COUNT_CTOR(DisplaySVGGeometry);
136 MOZ_COUNTED_DTOR_OVERRIDE(DisplaySVGGeometry)
138 NS_DISPLAY_DECL_NAME("DisplaySVGGeometry", TYPE_SVG_GEOMETRY)
140 // Whether this part of the SVG should be natively handled by webrender,
141 // potentially becoming an "active layer" inside a blob image.
142 bool ShouldBeActive(mozilla::wr::DisplayListBuilder& aBuilder,
143 mozilla::wr::IpcResourceUpdateQueue& aResources,
144 const mozilla::layers::StackingContextHelper& aSc,
145 mozilla::layers::RenderRootStateManager* aManager,
146 nsDisplayListBuilder* aDisplayListBuilder) {
147 // We delegate this question to the parent frame to take advantage of
148 // the SVGGeometryFrame inheritance hierarchy which provides actual
149 // implementation details. The dryRun flag prevents serious side-effects.
150 auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
151 return frame->CreateWebRenderCommands(aBuilder, aResources, aSc, aManager,
152 aDisplayListBuilder, this,
153 /*aDryRun=*/true);
156 bool CreateWebRenderCommands(
157 mozilla::wr::DisplayListBuilder& aBuilder,
158 mozilla::wr::IpcResourceUpdateQueue& aResources,
159 const mozilla::layers::StackingContextHelper& aSc,
160 mozilla::layers::RenderRootStateManager* aManager,
161 nsDisplayListBuilder* aDisplayListBuilder) override {
162 // We delegate this question to the parent frame to take advantage of
163 // the SVGGeometryFrame inheritance hierarchy which provides actual
164 // implementation details.
165 auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
166 bool result = frame->CreateWebRenderCommands(aBuilder, aResources, aSc,
167 aManager, aDisplayListBuilder,
168 this, /*aDryRun=*/false);
169 MOZ_ASSERT(result, "ShouldBeActive inconsistent with CreateWRCommands?");
170 return result;
173 bool IsInvisible() const override {
174 auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
175 return frame->IsInvisible();
179 } // namespace mozilla
181 #endif // LAYOUT_SVG_SVGGEOMETRYFRAME_H_