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"
17 class ISVGDisplayableFrame
;
19 } // namespace mozilla
21 nsIFrame
* NS_NewSVGClipPathFrame(mozilla::PresShell
* aPresShell
,
22 mozilla::ComputedStyle
* aStyle
);
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
;
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
|
40 NS_STATE_SVG_RENDERING_OBSERVER_CONTAINER
);
44 NS_DECL_FRAMEARENA_HELPERS(SVGClipPathFrame
)
47 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
48 const nsDisplayListSet
& aLists
) override
{}
50 bool IsSVGTransformed(Matrix
* aOwnTransforms
,
51 Matrix
* aFromParentTransforms
) const override
;
53 // SVGClipPathFrame methods:
56 * Applies the clipPath by pushing a clip path onto the DrawTarget.
58 * This method must only be used if IsTrivial() returns true, otherwise use
61 * @param aContext The context that the clip path is to be applied to.
62 * @param aClippedFrame The/an nsIFrame of the element that references this
63 * clipPath that is currently being processed.
64 * @param aMatrix The transform from aClippedFrame's user space to aContext's
67 void ApplyClipPath(gfxContext
& aContext
, nsIFrame
* aClippedFrame
,
68 const gfxMatrix
& aMatrix
);
71 * Returns an alpha mask surface containing the clipping geometry.
73 * This method must only be used if IsTrivial() returns false, otherwise use
76 * @param aReferenceContext Used to determine the backend for and size of the
77 * returned SourceSurface, the size being limited to the device space clip
78 * extents on the context.
79 * @param aClippedFrame The/an nsIFrame of the element that references this
80 * clipPath that is currently being processed.
81 * @param aMatrix The transform from aClippedFrame's user space to aContext's
83 * @param [in, optional] aExtraMask An extra surface that the returned
84 * surface should be masked with.
86 already_AddRefed
<SourceSurface
> GetClipMask(
87 gfxContext
& aReferenceContext
, nsIFrame
* aClippedFrame
,
88 const gfxMatrix
& aMatrix
, SourceSurface
* aExtraMask
= nullptr);
91 * Paint mask directly onto a given context(aMaskContext).
93 * @param aMaskContext The target of mask been painting on.
94 * @param aClippedFrame The/an nsIFrame of the element that references this
95 * clipPath that is currently being processed.
96 * @param aMatrix The transform from aClippedFrame's user space to
98 * @param [in, optional] aExtraMask An extra surface that the returned
99 * surface should be masked with.
101 void PaintClipMask(gfxContext
& aMaskContext
, nsIFrame
* aClippedFrame
,
102 const gfxMatrix
& aMatrix
, SourceSurface
* aExtraMask
);
105 * aPoint is expected to be in aClippedFrame's SVG user space.
107 bool PointIsInsideClipPath(nsIFrame
* aClippedFrame
, const gfxPoint
& aPoint
);
109 // Check if this clipPath is made up of more than one geometry object.
110 // If so, the clipping API in cairo isn't enough and we need to use
111 // mask based clipping.
112 bool IsTrivial(ISVGDisplayableFrame
** aSingleChild
= nullptr);
114 // nsIFrame interface:
115 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
116 int32_t aModType
) override
;
119 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
120 nsIFrame
* aPrevInFlow
) override
;
123 #ifdef DEBUG_FRAME_DUMP
124 nsresult
GetFrameName(nsAString
& aResult
) const override
{
125 return MakeFrameName(u
"SVGClipPath"_ns
, aResult
);
129 SVGBBox
GetBBoxForClipPathFrame(const SVGBBox
& aBBox
,
130 const gfxMatrix
& aMatrix
, uint32_t aFlags
);
133 * If the clipPath element transforms its children due to
134 * clipPathUnits="objectBoundingBox" being set on it and/or due to the
135 * 'transform' attribute being set on it, this function returns the resulting
138 gfxMatrix
GetClipPathTransform(nsIFrame
* aClippedFrame
);
141 // SVGContainerFrame methods:
142 gfxMatrix
GetCanvasTM() override
;
144 already_AddRefed
<DrawTarget
> CreateClipMask(gfxContext
& aReferenceContext
,
145 gfx::IntPoint
& aOffset
);
147 void PaintFrameIntoMask(nsIFrame
* aFrame
, nsIFrame
* aClippedFrame
,
148 gfxContext
& aTarget
);
150 void PaintChildren(gfxContext
& aMaskContext
, nsIFrame
* aClippedFrame
,
151 const gfxMatrix
& aMatrix
);
155 // Set, during a GetClipMask() call, to the transform that still needs to be
156 // concatenated to the transform of the DrawTarget that was passed to
157 // GetClipMask in order to establish the coordinate space that the clipPath
158 // establishes for its contents (i.e. including applying 'clipPathUnits' and
159 // any 'transform' attribute set on the clipPath) specifically for clipping
160 // the frame that was passed to GetClipMask at that moment in time. This is
161 // set so that if our GetCanvasTM method is called while GetClipMask is
162 // painting its children, the returned matrix will include the transforms
163 // that should be used when creating the mask for the frame passed to
166 // Note: The removal of GetCanvasTM is nearly complete, so our GetCanvasTM
167 // may not even be called soon/any more.
168 gfxMatrix mMatrixForChildren
;
170 // Flag used to indicate whether a methods that may reenter due to
171 // following a reference to another instance is currently executing.
172 bool mIsBeingProcessed
;
175 } // namespace mozilla
177 #endif // LAYOUT_SVG_SVGCLIPPATHFRAME_H_