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