|
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_SVGCONTAINERFRAME_H |
|
7 #define NS_SVGCONTAINERFRAME_H |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsContainerFrame.h" |
|
11 #include "nsFrame.h" |
|
12 #include "nsIFrame.h" |
|
13 #include "nsISVGChildFrame.h" |
|
14 #include "nsQueryFrame.h" |
|
15 #include "nsRect.h" |
|
16 #include "nsSVGUtils.h" |
|
17 |
|
18 class nsFrameList; |
|
19 class nsIContent; |
|
20 class nsIPresShell; |
|
21 class nsRenderingContext; |
|
22 class nsStyleContext; |
|
23 |
|
24 struct nsPoint; |
|
25 struct nsRect; |
|
26 struct nsIntRect; |
|
27 |
|
28 typedef nsContainerFrame nsSVGContainerFrameBase; |
|
29 |
|
30 /** |
|
31 * Base class for SVG container frames. Frame sub-classes that do not |
|
32 * display their contents directly (such as the frames for <marker> or |
|
33 * <pattern>) just inherit this class. Frame sub-classes that do or can |
|
34 * display their contents directly (such as the frames for inner-<svg> or |
|
35 * <g>) inherit our nsDisplayContainerFrame sub-class. |
|
36 * |
|
37 * *** WARNING *** |
|
38 * |
|
39 * Do *not* blindly cast to SVG element types in this class's methods (see the |
|
40 * warning comment for nsSVGDisplayContainerFrame below). |
|
41 */ |
|
42 class nsSVGContainerFrame : public nsSVGContainerFrameBase |
|
43 { |
|
44 friend nsIFrame* NS_NewSVGContainerFrame(nsIPresShell* aPresShell, |
|
45 nsStyleContext* aContext); |
|
46 protected: |
|
47 nsSVGContainerFrame(nsStyleContext* aContext) |
|
48 : nsSVGContainerFrameBase(aContext) |
|
49 { |
|
50 AddStateBits(NS_FRAME_SVG_LAYOUT); |
|
51 } |
|
52 |
|
53 public: |
|
54 NS_DECL_QUERYFRAME_TARGET(nsSVGContainerFrame) |
|
55 NS_DECL_QUERYFRAME |
|
56 NS_DECL_FRAMEARENA_HELPERS |
|
57 |
|
58 // Returns the transform to our gfxContext (to device pixels, not CSS px) |
|
59 virtual gfxMatrix GetCanvasTM(uint32_t aFor, |
|
60 nsIFrame* aTransformRoot = nullptr) { |
|
61 return gfxMatrix(); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Returns true if the frame's content has a transform that applies only to |
|
66 * its children, and not to the frame itself. For example, an implicit |
|
67 * transform introduced by a 'viewBox' attribute, or an explicit transform |
|
68 * due to a root-<svg> having its currentScale/currentTransform properties |
|
69 * set. If aTransform is non-null, then it will be set to the transform. |
|
70 */ |
|
71 virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const { |
|
72 return false; |
|
73 } |
|
74 |
|
75 // nsIFrame: |
|
76 virtual nsresult AppendFrames(ChildListID aListID, |
|
77 nsFrameList& aFrameList) MOZ_OVERRIDE; |
|
78 virtual nsresult InsertFrames(ChildListID aListID, |
|
79 nsIFrame* aPrevFrame, |
|
80 nsFrameList& aFrameList) MOZ_OVERRIDE; |
|
81 virtual nsresult RemoveFrame(ChildListID aListID, |
|
82 nsIFrame* aOldFrame) MOZ_OVERRIDE; |
|
83 |
|
84 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
85 { |
|
86 return nsSVGContainerFrameBase::IsFrameOfType( |
|
87 aFlags & ~(nsIFrame::eSVG | nsIFrame::eSVGContainer)); |
|
88 } |
|
89 |
|
90 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
91 const nsRect& aDirtyRect, |
|
92 const nsDisplayListSet& aLists) MOZ_OVERRIDE {} |
|
93 |
|
94 virtual bool UpdateOverflow() MOZ_OVERRIDE; |
|
95 |
|
96 protected: |
|
97 /** |
|
98 * Traverses a frame tree, marking any SVGTextFrame frames as dirty |
|
99 * and calling InvalidateRenderingObservers() on it. |
|
100 */ |
|
101 static void ReflowSVGNonDisplayText(nsIFrame* aContainer); |
|
102 }; |
|
103 |
|
104 /** |
|
105 * Frame class or base-class for SVG containers that can or do display their |
|
106 * contents directly. |
|
107 * |
|
108 * *** WARNING *** |
|
109 * |
|
110 * This class's methods can *not* assume that mContent points to an instance of |
|
111 * an SVG element class since this class is inherited by |
|
112 * nsSVGGenericContainerFrame which is used for unrecognized elements in the |
|
113 * SVG namespace. Do *not* blindly cast to SVG element types. |
|
114 */ |
|
115 class nsSVGDisplayContainerFrame : public nsSVGContainerFrame, |
|
116 public nsISVGChildFrame |
|
117 { |
|
118 protected: |
|
119 nsSVGDisplayContainerFrame(nsStyleContext* aContext) |
|
120 : nsSVGContainerFrame(aContext) |
|
121 { |
|
122 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED); |
|
123 } |
|
124 |
|
125 public: |
|
126 NS_DECL_QUERYFRAME_TARGET(nsSVGDisplayContainerFrame) |
|
127 NS_DECL_QUERYFRAME |
|
128 NS_DECL_FRAMEARENA_HELPERS |
|
129 |
|
130 // nsIFrame: |
|
131 virtual nsresult InsertFrames(ChildListID aListID, |
|
132 nsIFrame* aPrevFrame, |
|
133 nsFrameList& aFrameList) MOZ_OVERRIDE; |
|
134 virtual nsresult RemoveFrame(ChildListID aListID, |
|
135 nsIFrame* aOldFrame) MOZ_OVERRIDE; |
|
136 virtual void Init(nsIContent* aContent, |
|
137 nsIFrame* aParent, |
|
138 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
139 |
|
140 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
141 const nsRect& aDirtyRect, |
|
142 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
143 |
|
144 virtual bool IsSVGTransformed(Matrix *aOwnTransform = nullptr, |
|
145 Matrix *aFromParentTransform = nullptr) const MOZ_OVERRIDE; |
|
146 |
|
147 // nsISVGChildFrame interface: |
|
148 virtual nsresult PaintSVG(nsRenderingContext* aContext, |
|
149 const nsIntRect *aDirtyRect, |
|
150 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; |
|
151 virtual nsIFrame* GetFrameForPoint(const nsPoint &aPoint) MOZ_OVERRIDE; |
|
152 virtual nsRect GetCoveredRegion() MOZ_OVERRIDE; |
|
153 virtual void ReflowSVG() MOZ_OVERRIDE; |
|
154 virtual void NotifySVGChanged(uint32_t aFlags) MOZ_OVERRIDE; |
|
155 virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace, |
|
156 uint32_t aFlags) MOZ_OVERRIDE; |
|
157 virtual bool IsDisplayContainer() MOZ_OVERRIDE { return true; } |
|
158 }; |
|
159 |
|
160 #endif |