Bug 1818465 - Add test to ensure Utility Actor Names always reflected in about:proces...
[gecko.git] / layout / svg / SVGClipPathFrame.h
blob153d14c6dd73a21a7ea6b4f2f6fa1ac17581754d
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_SVGCLIPPATHFRAME_H_
8 #define LAYOUT_SVG_SVGCLIPPATHFRAME_H_
10 #include "gfxMatrix.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/SVGContainerFrame.h"
14 class gfxContext;
16 namespace mozilla {
17 class ISVGDisplayableFrame;
18 class PresShell;
19 } // namespace mozilla
21 nsIFrame* NS_NewSVGClipPathFrame(mozilla::PresShell* aPresShell,
22 mozilla::ComputedStyle* aStyle);
24 namespace mozilla {
26 class SVGClipPathFrame final : public SVGContainerFrame {
27 friend nsIFrame* ::NS_NewSVGClipPathFrame(mozilla::PresShell* aPresShell,
28 ComputedStyle* aStyle);
30 using Matrix = gfx::Matrix;
31 using SourceSurface = gfx::SourceSurface;
32 using imgDrawingParams = image::imgDrawingParams;
34 protected:
35 explicit SVGClipPathFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
36 : SVGContainerFrame(aStyle, aPresContext, kClassID),
37 mIsBeingProcessed(false) {
38 AddStateBits(NS_FRAME_IS_NONDISPLAY | NS_STATE_SVG_CLIPPATH_CHILD |
39 NS_FRAME_MAY_BE_TRANSFORMED);
42 public:
43 NS_DECL_FRAMEARENA_HELPERS(SVGClipPathFrame)
45 // nsIFrame methods:
46 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
47 const nsDisplayListSet& aLists) override {}
49 bool IsSVGTransformed(Matrix* aOwnTransforms,
50 Matrix* aFromParentTransforms) const override;
52 // SVGClipPathFrame methods:
54 /**
55 * Applies the clipPath by pushing a clip path onto the DrawTarget.
57 * This method must only be used if IsTrivial() returns true, otherwise use
58 * GetClipMask.
60 * @param aContext The context that the clip path is to be applied to.
61 * @param aClippedFrame The/an nsIFrame of the element that references this
62 * clipPath that is currently being processed.
63 * @param aMatrix The transform from aClippedFrame's user space to aContext's
64 * current transform.
66 void ApplyClipPath(gfxContext& aContext, nsIFrame* aClippedFrame,
67 const gfxMatrix& aMatrix);
69 /**
70 * Returns an alpha mask surface containing the clipping geometry.
72 * This method must only be used if IsTrivial() returns false, otherwise use
73 * ApplyClipPath.
75 * @param aReferenceContext Used to determine the backend for and size of the
76 * returned SourceSurface, the size being limited to the device space clip
77 * extents on the context.
78 * @param aClippedFrame The/an nsIFrame of the element that references this
79 * clipPath that is currently being processed.
80 * @param aMatrix The transform from aClippedFrame's user space to aContext's
81 * current transform.
82 * @param [in, optional] aExtraMask An extra surface that the returned
83 * surface should be masked with.
85 already_AddRefed<SourceSurface> GetClipMask(
86 gfxContext& aReferenceContext, nsIFrame* aClippedFrame,
87 const gfxMatrix& aMatrix, SourceSurface* aExtraMask = nullptr);
89 /**
90 * Paint mask directly onto a given context(aMaskContext).
92 * @param aMaskContext The target of mask been painting on.
93 * @param aClippedFrame The/an nsIFrame of the element that references this
94 * clipPath that is currently being processed.
95 * @param aMatrix The transform from aClippedFrame's user space to
96 * current transform.
97 * @param [in, optional] aExtraMask An extra surface that the returned
98 * surface should be masked with.
100 void PaintClipMask(gfxContext& aMaskContext, nsIFrame* aClippedFrame,
101 const gfxMatrix& aMatrix, SourceSurface* aExtraMask);
104 * aPoint is expected to be in aClippedFrame's SVG user space.
106 bool PointIsInsideClipPath(nsIFrame* aClippedFrame, const gfxPoint& aPoint);
108 // Check if this clipPath is made up of more than one geometry object.
109 // If so, the clipping API in cairo isn't enough and we need to use
110 // mask based clipping.
111 bool IsTrivial(ISVGDisplayableFrame** aSingleChild = nullptr);
113 bool IsValid();
115 // nsIFrame interface:
116 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
117 int32_t aModType) override;
119 #ifdef DEBUG
120 void Init(nsIContent* aContent, nsContainerFrame* aParent,
121 nsIFrame* aPrevInFlow) override;
122 #endif
124 #ifdef DEBUG_FRAME_DUMP
125 nsresult GetFrameName(nsAString& aResult) const override {
126 return MakeFrameName(u"SVGClipPath"_ns, aResult);
128 #endif
130 SVGBBox GetBBoxForClipPathFrame(const SVGBBox& aBBox,
131 const gfxMatrix& aMatrix, uint32_t aFlags);
134 * If the clipPath element transforms its children due to
135 * clipPathUnits="objectBoundingBox" being set on it and/or due to the
136 * 'transform' attribute being set on it, this function returns the resulting
137 * transform.
139 gfxMatrix GetClipPathTransform(nsIFrame* aClippedFrame);
141 private:
142 // SVGContainerFrame methods:
143 gfxMatrix GetCanvasTM() override;
145 already_AddRefed<DrawTarget> CreateClipMask(gfxContext& aReferenceContext,
146 gfx::IntPoint& aOffset);
148 void PaintFrameIntoMask(nsIFrame* aFrame, nsIFrame* aClippedFrame,
149 gfxContext& aTarget);
151 // Set, during a GetClipMask() call, to the transform that still needs to be
152 // concatenated to the transform of the DrawTarget that was passed to
153 // GetClipMask in order to establish the coordinate space that the clipPath
154 // establishes for its contents (i.e. including applying 'clipPathUnits' and
155 // any 'transform' attribute set on the clipPath) specifically for clipping
156 // the frame that was passed to GetClipMask at that moment in time. This is
157 // set so that if our GetCanvasTM method is called while GetClipMask is
158 // painting its children, the returned matrix will include the transforms
159 // that should be used when creating the mask for the frame passed to
160 // GetClipMask.
162 // Note: The removal of GetCanvasTM is nearly complete, so our GetCanvasTM
163 // may not even be called soon/any more.
164 gfxMatrix mMatrixForChildren;
166 // Flag used to indicate whether a methods that may reenter due to
167 // following a reference to another instance is currently executing.
168 bool mIsBeingProcessed;
171 } // namespace mozilla
173 #endif // LAYOUT_SVG_SVGCLIPPATHFRAME_H_