|
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_SVGCLIPPATHFRAME_H__ |
|
7 #define __NS_SVGCLIPPATHFRAME_H__ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "gfxMatrix.h" |
|
11 #include "nsSVGContainerFrame.h" |
|
12 #include "nsSVGUtils.h" |
|
13 |
|
14 class nsRenderingContext; |
|
15 class nsISVGChildFrame; |
|
16 |
|
17 typedef nsSVGContainerFrame nsSVGClipPathFrameBase; |
|
18 |
|
19 class nsSVGClipPathFrame : public nsSVGClipPathFrameBase |
|
20 { |
|
21 friend nsIFrame* |
|
22 NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
23 protected: |
|
24 nsSVGClipPathFrame(nsStyleContext* aContext) |
|
25 : nsSVGClipPathFrameBase(aContext) |
|
26 , mInUse(false) |
|
27 { |
|
28 AddStateBits(NS_FRAME_IS_NONDISPLAY); |
|
29 } |
|
30 |
|
31 public: |
|
32 NS_DECL_FRAMEARENA_HELPERS |
|
33 |
|
34 // nsIFrame methods: |
|
35 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
36 const nsRect& aDirtyRect, |
|
37 const nsDisplayListSet& aLists) MOZ_OVERRIDE {} |
|
38 |
|
39 // nsSVGClipPathFrame methods: |
|
40 nsresult ClipPaint(nsRenderingContext* aContext, |
|
41 nsIFrame* aParent, |
|
42 const gfxMatrix &aMatrix); |
|
43 |
|
44 bool ClipHitTest(nsIFrame* aParent, |
|
45 const gfxMatrix &aMatrix, |
|
46 const nsPoint &aPoint); |
|
47 |
|
48 // Check if this clipPath is made up of more than one geometry object. |
|
49 // If so, the clipping API in cairo isn't enough and we need to use |
|
50 // mask based clipping. |
|
51 bool IsTrivial(nsISVGChildFrame **aSingleChild = nullptr); |
|
52 |
|
53 bool IsValid(); |
|
54 |
|
55 // nsIFrame interface: |
|
56 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
57 nsIAtom* aAttribute, |
|
58 int32_t aModType) MOZ_OVERRIDE; |
|
59 |
|
60 virtual void Init(nsIContent* aContent, |
|
61 nsIFrame* aParent, |
|
62 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
63 |
|
64 /** |
|
65 * Get the "type" of the frame |
|
66 * |
|
67 * @see nsGkAtoms::svgClipPathFrame |
|
68 */ |
|
69 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
70 |
|
71 #ifdef DEBUG_FRAME_DUMP |
|
72 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
|
73 { |
|
74 return MakeFrameName(NS_LITERAL_STRING("SVGClipPath"), aResult); |
|
75 } |
|
76 #endif |
|
77 |
|
78 private: |
|
79 // A helper class to allow us to paint clip paths safely. The helper |
|
80 // automatically sets and clears the mInUse flag on the clip path frame |
|
81 // (to prevent nasty reference loops). It's easy to mess this up |
|
82 // and break things, so this helper makes the code far more robust. |
|
83 class MOZ_STACK_CLASS AutoClipPathReferencer |
|
84 { |
|
85 public: |
|
86 AutoClipPathReferencer(nsSVGClipPathFrame *aFrame |
|
87 MOZ_GUARD_OBJECT_NOTIFIER_PARAM) |
|
88 : mFrame(aFrame) { |
|
89 MOZ_GUARD_OBJECT_NOTIFIER_INIT; |
|
90 NS_ASSERTION(!mFrame->mInUse, "reference loop!"); |
|
91 mFrame->mInUse = true; |
|
92 } |
|
93 ~AutoClipPathReferencer() { |
|
94 mFrame->mInUse = false; |
|
95 } |
|
96 private: |
|
97 nsSVGClipPathFrame *mFrame; |
|
98 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER |
|
99 }; |
|
100 |
|
101 nsIFrame *mClipParent; |
|
102 nsAutoPtr<gfxMatrix> mClipParentMatrix; |
|
103 // recursion prevention flag |
|
104 bool mInUse; |
|
105 |
|
106 // nsSVGContainerFrame methods: |
|
107 virtual gfxMatrix GetCanvasTM(uint32_t aFor, |
|
108 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; |
|
109 }; |
|
110 |
|
111 #endif |