Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef __NS_SVGPAINTSERVERFRAME_H__
7 : #define __NS_SVGPAINTSERVERFRAME_H__
8 :
9 : #include "gfxRect.h"
10 : #include "mozilla/Attributes.h"
11 : #include "nsCOMPtr.h"
12 : #include "nsFrame.h"
13 : #include "nsIFrame.h"
14 : #include "nsQueryFrame.h"
15 : #include "nsSVGContainerFrame.h"
16 : #include "nsSVGUtils.h"
17 :
18 : namespace mozilla {
19 : namespace gfx {
20 : class DrawTarget;
21 : } // namespace gfx
22 : } // namespace mozilla
23 :
24 : class gfxContext;
25 : class gfxPattern;
26 : class nsStyleContext;
27 :
28 : /**
29 : * RAII class used to temporarily set and remove the
30 : * NS_FRAME_DRAWING_AS_PAINTSERVER frame state bit while a frame is being
31 : * drawn as a paint server.
32 : */
33 : class MOZ_RAII AutoSetRestorePaintServerState
34 : {
35 : public:
36 0 : explicit AutoSetRestorePaintServerState(
37 : nsIFrame* aFrame
38 0 : MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
39 0 : mFrame(aFrame)
40 : {
41 0 : MOZ_GUARD_OBJECT_NOTIFIER_INIT;
42 0 : mFrame->AddStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
43 0 : }
44 0 : ~AutoSetRestorePaintServerState()
45 0 : {
46 0 : mFrame->RemoveStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
47 0 : }
48 :
49 : private:
50 : nsIFrame* mFrame;
51 : MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
52 : };
53 :
54 0 : class nsSVGPaintServerFrame : public nsSVGContainerFrame
55 : {
56 : protected:
57 : typedef mozilla::gfx::DrawTarget DrawTarget;
58 :
59 0 : nsSVGPaintServerFrame(nsStyleContext* aContext, ClassID aID)
60 0 : : nsSVGContainerFrame(aContext, aID)
61 : {
62 0 : AddStateBits(NS_FRAME_IS_NONDISPLAY);
63 0 : }
64 :
65 : public:
66 : typedef mozilla::image::imgDrawingParams imgDrawingParams;
67 :
68 : NS_DECL_ABSTRACT_FRAME(nsSVGPaintServerFrame)
69 :
70 : /**
71 : * Constructs a gfxPattern of the paint server rendering.
72 : *
73 : * @param aContextMatrix The transform matrix that is currently applied to
74 : * the gfxContext that is being drawn to. This is needed by SVG patterns so
75 : * that surfaces of the correct size can be created. (SVG gradients are
76 : * vector based, so it's not used there.)
77 : */
78 : virtual already_AddRefed<gfxPattern>
79 : GetPaintServerPattern(nsIFrame *aSource,
80 : const DrawTarget* aDrawTarget,
81 : const gfxMatrix& aContextMatrix,
82 : nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
83 : float aOpacity,
84 : imgDrawingParams& aImgParams,
85 : const gfxRect* aOverrideBounds = nullptr) = 0;
86 :
87 : // nsIFrame methods:
88 0 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
89 : const nsRect& aDirtyRect,
90 0 : const nsDisplayListSet& aLists) override {}
91 :
92 0 : virtual bool IsFrameOfType(uint32_t aFlags) const override
93 : {
94 0 : return nsSVGContainerFrame::IsFrameOfType(aFlags & ~nsIFrame::eSVGPaintServer);
95 : }
96 : };
97 :
98 : #endif // __NS_SVGPAINTSERVERFRAME_H__
|