|
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 nsMathMLmtableFrame_h___ |
|
7 #define nsMathMLmtableFrame_h___ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsMathMLContainerFrame.h" |
|
11 #include "nsBlockFrame.h" |
|
12 #include "nsTableOuterFrame.h" |
|
13 #include "nsTableRowFrame.h" |
|
14 #include "nsTableCellFrame.h" |
|
15 |
|
16 // |
|
17 // <mtable> -- table or matrix |
|
18 // |
|
19 |
|
20 class nsMathMLmtableOuterFrame : public nsTableOuterFrame, |
|
21 public nsMathMLFrame |
|
22 { |
|
23 public: |
|
24 friend nsIFrame* NS_NewMathMLmtableOuterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
25 |
|
26 NS_DECL_QUERYFRAME |
|
27 NS_DECL_FRAMEARENA_HELPERS |
|
28 |
|
29 // overloaded nsTableOuterFrame methods |
|
30 |
|
31 virtual nsresult |
|
32 Reflow(nsPresContext* aPresContext, |
|
33 nsHTMLReflowMetrics& aDesiredSize, |
|
34 const nsHTMLReflowState& aReflowState, |
|
35 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
36 |
|
37 virtual nsresult |
|
38 AttributeChanged(int32_t aNameSpaceID, |
|
39 nsIAtom* aAttribute, |
|
40 int32_t aModType) MOZ_OVERRIDE; |
|
41 |
|
42 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
43 { |
|
44 return nsTableOuterFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
|
45 } |
|
46 |
|
47 protected: |
|
48 nsMathMLmtableOuterFrame(nsStyleContext* aContext) : nsTableOuterFrame(aContext) {} |
|
49 virtual ~nsMathMLmtableOuterFrame(); |
|
50 |
|
51 // helper to find the row frame at a given index, positive or negative, e.g., |
|
52 // 1..n means the first row down to the last row, -1..-n means the last row |
|
53 // up to the first row. Used for alignments that are relative to a given row |
|
54 nsIFrame* |
|
55 GetRowFrameAt(nsPresContext* aPresContext, |
|
56 int32_t aRowIndex); |
|
57 }; // class nsMathMLmtableOuterFrame |
|
58 |
|
59 // -------------- |
|
60 |
|
61 class nsMathMLmtableFrame : public nsTableFrame |
|
62 { |
|
63 public: |
|
64 NS_DECL_FRAMEARENA_HELPERS |
|
65 |
|
66 friend nsIFrame* NS_NewMathMLmtableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
67 |
|
68 // Overloaded nsTableFrame methods |
|
69 |
|
70 virtual nsresult |
|
71 SetInitialChildList(ChildListID aListID, |
|
72 nsFrameList& aChildList) MOZ_OVERRIDE; |
|
73 |
|
74 virtual nsresult |
|
75 AppendFrames(ChildListID aListID, |
|
76 nsFrameList& aFrameList) MOZ_OVERRIDE |
|
77 { |
|
78 nsresult rv = nsTableFrame::AppendFrames(aListID, aFrameList); |
|
79 RestyleTable(); |
|
80 return rv; |
|
81 } |
|
82 |
|
83 virtual nsresult |
|
84 InsertFrames(ChildListID aListID, |
|
85 nsIFrame* aPrevFrame, |
|
86 nsFrameList& aFrameList) MOZ_OVERRIDE |
|
87 { |
|
88 nsresult rv = nsTableFrame::InsertFrames(aListID, aPrevFrame, aFrameList); |
|
89 RestyleTable(); |
|
90 return rv; |
|
91 } |
|
92 |
|
93 virtual nsresult |
|
94 RemoveFrame(ChildListID aListID, |
|
95 nsIFrame* aOldFrame) MOZ_OVERRIDE |
|
96 { |
|
97 nsresult rv = nsTableFrame::RemoveFrame(aListID, aOldFrame); |
|
98 RestyleTable(); |
|
99 return rv; |
|
100 } |
|
101 |
|
102 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
103 { |
|
104 return nsTableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
|
105 } |
|
106 |
|
107 // helper to restyle and reflow the table when a row is changed -- since MathML |
|
108 // attributes are inter-dependent and row/colspan can affect the table, it is |
|
109 // safer (albeit grossly suboptimal) to just relayout the whole thing. |
|
110 void RestyleTable(); |
|
111 |
|
112 protected: |
|
113 nsMathMLmtableFrame(nsStyleContext* aContext) : nsTableFrame(aContext) {} |
|
114 virtual ~nsMathMLmtableFrame(); |
|
115 }; // class nsMathMLmtableFrame |
|
116 |
|
117 // -------------- |
|
118 |
|
119 class nsMathMLmtrFrame : public nsTableRowFrame |
|
120 { |
|
121 public: |
|
122 NS_DECL_FRAMEARENA_HELPERS |
|
123 |
|
124 friend nsIFrame* NS_NewMathMLmtrFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
125 |
|
126 // overloaded nsTableRowFrame methods |
|
127 |
|
128 virtual nsresult |
|
129 AttributeChanged(int32_t aNameSpaceID, |
|
130 nsIAtom* aAttribute, |
|
131 int32_t aModType) MOZ_OVERRIDE; |
|
132 |
|
133 virtual nsresult |
|
134 AppendFrames(ChildListID aListID, |
|
135 nsFrameList& aFrameList) MOZ_OVERRIDE |
|
136 { |
|
137 nsresult rv = nsTableRowFrame::AppendFrames(aListID, aFrameList); |
|
138 RestyleTable(); |
|
139 return rv; |
|
140 } |
|
141 |
|
142 virtual nsresult |
|
143 InsertFrames(ChildListID aListID, |
|
144 nsIFrame* aPrevFrame, |
|
145 nsFrameList& aFrameList) MOZ_OVERRIDE |
|
146 { |
|
147 nsresult rv = nsTableRowFrame::InsertFrames(aListID, aPrevFrame, aFrameList); |
|
148 RestyleTable(); |
|
149 return rv; |
|
150 } |
|
151 |
|
152 virtual nsresult |
|
153 RemoveFrame(ChildListID aListID, |
|
154 nsIFrame* aOldFrame) MOZ_OVERRIDE |
|
155 { |
|
156 nsresult rv = nsTableRowFrame::RemoveFrame(aListID, aOldFrame); |
|
157 RestyleTable(); |
|
158 return rv; |
|
159 } |
|
160 |
|
161 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
162 { |
|
163 return nsTableRowFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
|
164 } |
|
165 |
|
166 // helper to restyle and reflow the table -- @see nsMathMLmtableFrame. |
|
167 void RestyleTable() |
|
168 { |
|
169 nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); |
|
170 if (tableFrame && tableFrame->IsFrameOfType(nsIFrame::eMathML)) { |
|
171 // relayout the table |
|
172 ((nsMathMLmtableFrame*)tableFrame)->RestyleTable(); |
|
173 } |
|
174 } |
|
175 |
|
176 protected: |
|
177 nsMathMLmtrFrame(nsStyleContext* aContext) : nsTableRowFrame(aContext) {} |
|
178 virtual ~nsMathMLmtrFrame(); |
|
179 }; // class nsMathMLmtrFrame |
|
180 |
|
181 // -------------- |
|
182 |
|
183 class nsMathMLmtdFrame : public nsTableCellFrame |
|
184 { |
|
185 public: |
|
186 NS_DECL_FRAMEARENA_HELPERS |
|
187 |
|
188 friend nsIFrame* NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
189 |
|
190 // overloaded nsTableCellFrame methods |
|
191 |
|
192 virtual nsresult |
|
193 AttributeChanged(int32_t aNameSpaceID, |
|
194 nsIAtom* aAttribute, |
|
195 int32_t aModType) MOZ_OVERRIDE; |
|
196 |
|
197 virtual uint8_t GetVerticalAlign() const MOZ_OVERRIDE; |
|
198 virtual nsresult ProcessBorders(nsTableFrame* aFrame, |
|
199 nsDisplayListBuilder* aBuilder, |
|
200 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
201 |
|
202 virtual int32_t GetRowSpan() MOZ_OVERRIDE; |
|
203 virtual int32_t GetColSpan() MOZ_OVERRIDE; |
|
204 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
205 { |
|
206 return nsTableCellFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); |
|
207 } |
|
208 |
|
209 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE; |
|
210 |
|
211 protected: |
|
212 nsMathMLmtdFrame(nsStyleContext* aContext) : nsTableCellFrame(aContext) {} |
|
213 virtual ~nsMathMLmtdFrame(); |
|
214 }; // class nsMathMLmtdFrame |
|
215 |
|
216 // -------------- |
|
217 |
|
218 class nsMathMLmtdInnerFrame : public nsBlockFrame, |
|
219 public nsMathMLFrame { |
|
220 public: |
|
221 friend nsIFrame* NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
222 |
|
223 NS_DECL_QUERYFRAME |
|
224 NS_DECL_FRAMEARENA_HELPERS |
|
225 |
|
226 // Overloaded nsIMathMLFrame methods |
|
227 |
|
228 NS_IMETHOD |
|
229 UpdatePresentationDataFromChildAt(int32_t aFirstIndex, |
|
230 int32_t aLastIndex, |
|
231 uint32_t aFlagsValues, |
|
232 uint32_t aFlagsToUpdate) MOZ_OVERRIDE |
|
233 { |
|
234 nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(this, |
|
235 aFirstIndex, aLastIndex, aFlagsValues, aFlagsToUpdate); |
|
236 return NS_OK; |
|
237 } |
|
238 |
|
239 virtual nsresult |
|
240 Reflow(nsPresContext* aPresContext, |
|
241 nsHTMLReflowMetrics& aDesiredSize, |
|
242 const nsHTMLReflowState& aReflowState, |
|
243 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
244 |
|
245 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
246 { |
|
247 return nsBlockFrame::IsFrameOfType(aFlags & |
|
248 ~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace)); |
|
249 } |
|
250 |
|
251 virtual const nsStyleText* StyleTextForLineLayout() MOZ_OVERRIDE; |
|
252 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; |
|
253 |
|
254 bool |
|
255 IsMrowLike() MOZ_OVERRIDE { |
|
256 return mFrames.FirstChild() != mFrames.LastChild() || |
|
257 !mFrames.FirstChild(); |
|
258 } |
|
259 |
|
260 protected: |
|
261 nsMathMLmtdInnerFrame(nsStyleContext* aContext); |
|
262 virtual ~nsMathMLmtdInnerFrame(); |
|
263 |
|
264 nsStyleText* mUniqueStyleText; |
|
265 |
|
266 }; // class nsMathMLmtdInnerFrame |
|
267 |
|
268 #endif /* nsMathMLmtableFrame_h___ */ |