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