Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / svg / SVGMaskFrame.h
blobed868f18a0885afe0809d7d0d6f2268f727e167e
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_SVGMASKFRAME_H_
8 #define LAYOUT_SVG_SVGMASKFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/SVGContainerFrame.h"
13 #include "mozilla/gfx/2D.h"
14 #include "gfxPattern.h"
15 #include "gfxMatrix.h"
17 class gfxContext;
19 namespace mozilla {
20 class PresShell;
21 } // namespace mozilla
23 nsIFrame* NS_NewSVGMaskFrame(mozilla::PresShell* aPresShell,
24 mozilla::ComputedStyle* aStyle);
26 namespace mozilla {
28 class SVGMaskFrame final : public SVGContainerFrame {
29 friend nsIFrame* ::NS_NewSVGMaskFrame(mozilla::PresShell* aPresShell,
30 ComputedStyle* aStyle);
32 using Matrix = gfx::Matrix;
33 using SourceSurface = gfx::SourceSurface;
34 using imgDrawingParams = image::imgDrawingParams;
36 protected:
37 explicit SVGMaskFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
38 : SVGContainerFrame(aStyle, aPresContext, kClassID), mInUse(false) {
39 AddStateBits(NS_FRAME_IS_NONDISPLAY |
40 NS_STATE_SVG_RENDERING_OBSERVER_CONTAINER);
43 public:
44 NS_DECL_FRAMEARENA_HELPERS(SVGMaskFrame)
46 struct MaskParams {
47 gfx::DrawTarget* dt;
48 nsIFrame* maskedFrame;
49 const gfxMatrix& toUserSpace;
50 float opacity;
51 StyleMaskMode maskMode;
52 imgDrawingParams& imgParams;
54 explicit MaskParams(gfx::DrawTarget* aDt, nsIFrame* aMaskedFrame,
55 const gfxMatrix& aToUserSpace, float aOpacity,
56 StyleMaskMode aMaskMode, imgDrawingParams& aImgParams)
57 : dt(aDt),
58 maskedFrame(aMaskedFrame),
59 toUserSpace(aToUserSpace),
60 opacity(aOpacity),
61 maskMode(aMaskMode),
62 imgParams(aImgParams) {}
65 // SVGMaskFrame method:
67 /**
68 * Generate a mask surface for the target frame.
70 * The return surface can be null, it's the caller's responsibility to
71 * null-check before dereferencing.
73 already_AddRefed<SourceSurface> GetMaskForMaskedFrame(MaskParams& aParams);
75 gfxRect GetMaskArea(nsIFrame* aMaskedFrame);
77 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
78 int32_t aModType) override;
80 #ifdef DEBUG
81 void Init(nsIContent* aContent, nsContainerFrame* aParent,
82 nsIFrame* aPrevInFlow) override;
83 #endif
85 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
86 const nsDisplayListSet& aLists) override {}
88 #ifdef DEBUG_FRAME_DUMP
89 nsresult GetFrameName(nsAString& aResult) const override {
90 return MakeFrameName(u"SVGMask"_ns, aResult);
92 #endif
94 private:
95 /**
96 * If the mask element transforms its children due to
97 * maskContentUnits="objectBoundingBox" being set on it, this function
98 * returns the resulting transform.
100 gfxMatrix GetMaskTransform(nsIFrame* aMaskedFrame);
102 gfxMatrix mMatrixForChildren;
103 // recursion prevention flag
104 bool mInUse;
106 // SVGContainerFrame methods:
107 gfxMatrix GetCanvasTM() override;
110 } // namespace mozilla
112 #endif // LAYOUT_SVG_SVGMASKFRAME_H_