/src/mozilla-central/layout/mathml/nsMathMLmtableFrame.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 nsMathMLmtableFrame_h___ |
8 | | #define nsMathMLmtableFrame_h___ |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "mozilla/UniquePtr.h" |
12 | | #include "nsMathMLContainerFrame.h" |
13 | | #include "nsBlockFrame.h" |
14 | | #include "nsTableWrapperFrame.h" |
15 | | #include "nsTableRowFrame.h" |
16 | | #include "nsTableCellFrame.h" |
17 | | |
18 | | // |
19 | | // <mtable> -- table or matrix |
20 | | // |
21 | | |
22 | | class nsMathMLmtableWrapperFrame final |
23 | | : public nsTableWrapperFrame |
24 | | , public nsMathMLFrame |
25 | | { |
26 | | public: |
27 | | friend nsContainerFrame* |
28 | | NS_NewMathMLmtableOuterFrame(nsIPresShell* aPresShell, |
29 | | ComputedStyle* aStyle); |
30 | | |
31 | | NS_DECL_QUERYFRAME |
32 | | NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtableWrapperFrame) |
33 | | |
34 | | // overloaded nsTableWrapperFrame methods |
35 | | |
36 | | virtual void |
37 | | Reflow(nsPresContext* aPresContext, |
38 | | ReflowOutput& aDesiredSize, |
39 | | const ReflowInput& aReflowInput, |
40 | | nsReflowStatus& aStatus) override; |
41 | | |
42 | | virtual nsresult |
43 | | AttributeChanged(int32_t aNameSpaceID, |
44 | | nsAtom* aAttribute, |
45 | | int32_t aModType) override; |
46 | | |
47 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
48 | 0 | { |
49 | 0 | return nsTableWrapperFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
50 | 0 | } |
51 | | |
52 | | protected: |
53 | | explicit nsMathMLmtableWrapperFrame(ComputedStyle* aStyle) |
54 | | : nsTableWrapperFrame(aStyle, kClassID) |
55 | 0 | {} |
56 | | |
57 | | virtual ~nsMathMLmtableWrapperFrame(); |
58 | | |
59 | | // helper to find the row frame at a given index, positive or negative, e.g., |
60 | | // 1..n means the first row down to the last row, -1..-n means the last row |
61 | | // up to the first row. Used for alignments that are relative to a given row |
62 | | nsIFrame* |
63 | | GetRowFrameAt(int32_t aRowIndex); |
64 | | }; // class nsMathMLmtableWrapperFrame |
65 | | |
66 | | // -------------- |
67 | | |
68 | | class nsMathMLmtableFrame final : public nsTableFrame |
69 | | { |
70 | | public: |
71 | | NS_DECL_QUERYFRAME |
72 | | NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtableFrame) |
73 | | |
74 | | friend nsContainerFrame* |
75 | | NS_NewMathMLmtableFrame(nsIPresShell* aPresShell, |
76 | | ComputedStyle* aStyle); |
77 | | |
78 | | // Overloaded nsTableFrame methods |
79 | | |
80 | | virtual void |
81 | | SetInitialChildList(ChildListID aListID, |
82 | | nsFrameList& aChildList) override; |
83 | | |
84 | | virtual void |
85 | | AppendFrames(ChildListID aListID, |
86 | | nsFrameList& aFrameList) override |
87 | 0 | { |
88 | 0 | nsTableFrame::AppendFrames(aListID, aFrameList); |
89 | 0 | RestyleTable(); |
90 | 0 | } |
91 | | |
92 | | virtual void |
93 | | InsertFrames(ChildListID aListID, |
94 | | nsIFrame* aPrevFrame, |
95 | | nsFrameList& aFrameList) override |
96 | 0 | { |
97 | 0 | nsTableFrame::InsertFrames(aListID, aPrevFrame, aFrameList); |
98 | 0 | RestyleTable(); |
99 | 0 | } |
100 | | |
101 | | virtual void |
102 | | RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override |
103 | 0 | { |
104 | 0 | nsTableFrame::RemoveFrame(aListID, aOldFrame); |
105 | 0 | RestyleTable(); |
106 | 0 | } |
107 | | |
108 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
109 | 0 | { |
110 | 0 | return nsTableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
111 | 0 | } |
112 | | |
113 | | // helper to restyle and reflow the table when a row is changed -- since MathML |
114 | | // attributes are inter-dependent and row/colspan can affect the table, it is |
115 | | // safer (albeit grossly suboptimal) to just relayout the whole thing. |
116 | | void RestyleTable(); |
117 | | |
118 | | /** helper to get the column spacing style value */ |
119 | | nscoord GetColSpacing(int32_t aColIndex) override; |
120 | | |
121 | | /** Sums the combined cell spacing between the columns aStartColIndex to |
122 | | * aEndColIndex. |
123 | | */ |
124 | | nscoord GetColSpacing(int32_t aStartColIndex, |
125 | | int32_t aEndColIndex) override; |
126 | | |
127 | | /** helper to get the row spacing style value */ |
128 | | nscoord GetRowSpacing(int32_t aRowIndex) override; |
129 | | |
130 | | /** Sums the combined cell spacing between the rows aStartRowIndex to |
131 | | * aEndRowIndex. |
132 | | */ |
133 | | nscoord GetRowSpacing(int32_t aStartRowIndex, |
134 | | int32_t aEndRowIndex) override; |
135 | | |
136 | | void SetColSpacingArray(const nsTArray<nscoord>& aColSpacing) |
137 | 0 | { |
138 | 0 | mColSpacing = aColSpacing; |
139 | 0 | } |
140 | | |
141 | | void SetRowSpacingArray(const nsTArray<nscoord>& aRowSpacing) |
142 | 0 | { |
143 | 0 | mRowSpacing = aRowSpacing; |
144 | 0 | } |
145 | | |
146 | | void SetFrameSpacing(nscoord aSpacingX, nscoord aSpacingY) |
147 | 0 | { |
148 | 0 | mFrameSpacingX = aSpacingX; |
149 | 0 | mFrameSpacingY = aSpacingY; |
150 | 0 | } |
151 | | |
152 | | /** Determines whether the placement of table cells is determined by CSS |
153 | | * spacing based on padding and border-spacing, or one based upon the |
154 | | * rowspacing, columnspacing and framespacing attributes. The second |
155 | | * approach is used if the user specifies at least one of those attributes. |
156 | | */ |
157 | | void SetUseCSSSpacing(); |
158 | 0 | bool GetUseCSSSpacing() { return mUseCSSSpacing; } |
159 | | |
160 | | protected: |
161 | | explicit nsMathMLmtableFrame(ComputedStyle* aStyle) |
162 | | : nsTableFrame(aStyle, kClassID) |
163 | | , mFrameSpacingX(0) |
164 | | , mFrameSpacingY(0) |
165 | | , mUseCSSSpacing(false) |
166 | 0 | {} |
167 | | |
168 | | virtual ~nsMathMLmtableFrame(); |
169 | | |
170 | | private: |
171 | | nsTArray<nscoord> mColSpacing; |
172 | | nsTArray<nscoord> mRowSpacing; |
173 | | nscoord mFrameSpacingX; |
174 | | nscoord mFrameSpacingY; |
175 | | bool mUseCSSSpacing; |
176 | | }; // class nsMathMLmtableFrame |
177 | | |
178 | | // -------------- |
179 | | |
180 | | class nsMathMLmtrFrame final : public nsTableRowFrame |
181 | | { |
182 | | public: |
183 | | NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtrFrame) |
184 | | |
185 | | friend nsContainerFrame* |
186 | | NS_NewMathMLmtrFrame(nsIPresShell* aPresShell, |
187 | | ComputedStyle* aStyle); |
188 | | |
189 | | // overloaded nsTableRowFrame methods |
190 | | |
191 | | virtual nsresult |
192 | | AttributeChanged(int32_t aNameSpaceID, |
193 | | nsAtom* aAttribute, |
194 | | int32_t aModType) override; |
195 | | |
196 | | virtual void |
197 | | AppendFrames(ChildListID aListID, |
198 | | nsFrameList& aFrameList) override |
199 | 0 | { |
200 | 0 | nsTableRowFrame::AppendFrames(aListID, aFrameList); |
201 | 0 | RestyleTable(); |
202 | 0 | } |
203 | | |
204 | | virtual void |
205 | | InsertFrames(ChildListID aListID, |
206 | | nsIFrame* aPrevFrame, |
207 | | nsFrameList& aFrameList) override |
208 | 0 | { |
209 | 0 | nsTableRowFrame::InsertFrames(aListID, aPrevFrame, aFrameList); |
210 | 0 | RestyleTable(); |
211 | 0 | } |
212 | | |
213 | | virtual void |
214 | | RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override |
215 | 0 | { |
216 | 0 | nsTableRowFrame::RemoveFrame(aListID, aOldFrame); |
217 | 0 | RestyleTable(); |
218 | 0 | } |
219 | | |
220 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
221 | 0 | { |
222 | 0 | return nsTableRowFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
223 | 0 | } |
224 | | |
225 | | // helper to restyle and reflow the table -- @see nsMathMLmtableFrame. |
226 | | void RestyleTable() |
227 | 0 | { |
228 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
229 | 0 | if (tableFrame && tableFrame->IsFrameOfType(nsIFrame::eMathML)) { |
230 | 0 | // relayout the table |
231 | 0 | ((nsMathMLmtableFrame*)tableFrame)->RestyleTable(); |
232 | 0 | } |
233 | 0 | } |
234 | | |
235 | | protected: |
236 | | explicit nsMathMLmtrFrame(ComputedStyle* aStyle) |
237 | | : nsTableRowFrame(aStyle, kClassID) |
238 | 0 | {} |
239 | | |
240 | | virtual ~nsMathMLmtrFrame(); |
241 | | }; // class nsMathMLmtrFrame |
242 | | |
243 | | // -------------- |
244 | | |
245 | | class nsMathMLmtdFrame final : public nsTableCellFrame |
246 | | { |
247 | | public: |
248 | | NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtdFrame) |
249 | | |
250 | | friend nsContainerFrame* |
251 | | NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, |
252 | | ComputedStyle* aStyle, |
253 | | nsTableFrame* aTableFrame); |
254 | | |
255 | | // overloaded nsTableCellFrame methods |
256 | | |
257 | | virtual void Init(nsIContent* aContent, |
258 | | nsContainerFrame* aParent, |
259 | | nsIFrame* aPrevInFlow) override; |
260 | | |
261 | | virtual nsresult |
262 | | AttributeChanged(int32_t aNameSpaceID, |
263 | | nsAtom* aAttribute, |
264 | | int32_t aModType) override; |
265 | | |
266 | | virtual uint8_t GetVerticalAlign() const override; |
267 | | virtual nsresult ProcessBorders(nsTableFrame* aFrame, |
268 | | nsDisplayListBuilder* aBuilder, |
269 | | const nsDisplayListSet& aLists) override; |
270 | | |
271 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
272 | 0 | { |
273 | 0 | return nsTableCellFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
274 | 0 | } |
275 | | |
276 | | virtual LogicalMargin GetBorderWidth(WritingMode aWM) const override; |
277 | | |
278 | | virtual nsMargin GetBorderOverflow() override; |
279 | | |
280 | | protected: |
281 | | nsMathMLmtdFrame(ComputedStyle* aStyle, nsTableFrame* aTableFrame) |
282 | | : nsTableCellFrame(aStyle, aTableFrame, kClassID) |
283 | 0 | { |
284 | 0 | } |
285 | | |
286 | | virtual ~nsMathMLmtdFrame(); |
287 | | }; // class nsMathMLmtdFrame |
288 | | |
289 | | // -------------- |
290 | | |
291 | | class nsMathMLmtdInnerFrame final |
292 | | : public nsBlockFrame |
293 | | , public nsMathMLFrame |
294 | | { |
295 | | public: |
296 | | friend nsContainerFrame* |
297 | | NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, |
298 | | ComputedStyle* aStyle); |
299 | | |
300 | | NS_DECL_QUERYFRAME |
301 | | NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtdInnerFrame) |
302 | | |
303 | | // Overloaded nsIMathMLFrame methods |
304 | | |
305 | | NS_IMETHOD |
306 | | UpdatePresentationDataFromChildAt(int32_t aFirstIndex, |
307 | | int32_t aLastIndex, |
308 | | uint32_t aFlagsValues, |
309 | | uint32_t aFlagsToUpdate) override |
310 | 0 | { |
311 | 0 | nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(this, |
312 | 0 | aFirstIndex, aLastIndex, aFlagsValues, aFlagsToUpdate); |
313 | 0 | return NS_OK; |
314 | 0 | } |
315 | | |
316 | | virtual void |
317 | | Reflow(nsPresContext* aPresContext, |
318 | | ReflowOutput& aDesiredSize, |
319 | | const ReflowInput& aReflowInput, |
320 | | nsReflowStatus& aStatus) override; |
321 | | |
322 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
323 | 0 | { |
324 | 0 | return nsBlockFrame::IsFrameOfType(aFlags & |
325 | 0 | ~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace)); |
326 | 0 | } |
327 | | |
328 | | virtual const nsStyleText* StyleTextForLineLayout() override; |
329 | | virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override; |
330 | | |
331 | | bool |
332 | | IsMrowLike() override |
333 | 0 | { |
334 | 0 | return mFrames.FirstChild() != |
335 | 0 | mFrames.LastChild() || |
336 | 0 | !mFrames.FirstChild(); |
337 | 0 | } |
338 | | |
339 | | protected: |
340 | | explicit nsMathMLmtdInnerFrame(ComputedStyle* aStyle); |
341 | 0 | virtual ~nsMathMLmtdInnerFrame() {} |
342 | | |
343 | | mozilla::UniquePtr<nsStyleText> mUniqueStyleText; |
344 | | |
345 | | }; // class nsMathMLmtdInnerFrame |
346 | | |
347 | | #endif /* nsMathMLmtableFrame_h___ */ |