|
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 nsMathMLFrame_h___ |
|
7 #define nsMathMLFrame_h___ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsFontMetrics.h" |
|
11 #include "nsMathMLOperators.h" |
|
12 #include "nsIMathMLFrame.h" |
|
13 #include "nsLayoutUtils.h" |
|
14 #include "nsBoundingMetrics.h" |
|
15 #include "nsIFrame.h" |
|
16 |
|
17 class nsMathMLChar; |
|
18 class nsCSSValue; |
|
19 class nsDisplayListSet; |
|
20 |
|
21 // Concrete base class with default methods that derived MathML frames can override |
|
22 class nsMathMLFrame : public nsIMathMLFrame { |
|
23 public: |
|
24 |
|
25 // nsIMathMLFrame --- |
|
26 |
|
27 virtual bool |
|
28 IsSpaceLike() MOZ_OVERRIDE { |
|
29 return NS_MATHML_IS_SPACE_LIKE(mPresentationData.flags); |
|
30 } |
|
31 |
|
32 NS_IMETHOD |
|
33 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE { |
|
34 aBoundingMetrics = mBoundingMetrics; |
|
35 return NS_OK; |
|
36 } |
|
37 |
|
38 NS_IMETHOD |
|
39 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE { |
|
40 mBoundingMetrics = aBoundingMetrics; |
|
41 return NS_OK; |
|
42 } |
|
43 |
|
44 NS_IMETHOD |
|
45 SetReference(const nsPoint& aReference) MOZ_OVERRIDE { |
|
46 mReference = aReference; |
|
47 return NS_OK; |
|
48 } |
|
49 |
|
50 virtual eMathMLFrameType GetMathMLFrameType() MOZ_OVERRIDE; |
|
51 |
|
52 NS_IMETHOD |
|
53 Stretch(nsRenderingContext& aRenderingContext, |
|
54 nsStretchDirection aStretchDirection, |
|
55 nsBoundingMetrics& aContainerSize, |
|
56 nsHTMLReflowMetrics& aDesiredStretchSize) MOZ_OVERRIDE |
|
57 { |
|
58 return NS_OK; |
|
59 } |
|
60 |
|
61 NS_IMETHOD |
|
62 GetEmbellishData(nsEmbellishData& aEmbellishData) MOZ_OVERRIDE { |
|
63 aEmbellishData = mEmbellishData; |
|
64 return NS_OK; |
|
65 } |
|
66 |
|
67 NS_IMETHOD |
|
68 GetPresentationData(nsPresentationData& aPresentationData) MOZ_OVERRIDE { |
|
69 aPresentationData = mPresentationData; |
|
70 return NS_OK; |
|
71 } |
|
72 |
|
73 NS_IMETHOD |
|
74 InheritAutomaticData(nsIFrame* aParent) MOZ_OVERRIDE; |
|
75 |
|
76 NS_IMETHOD |
|
77 TransmitAutomaticData() MOZ_OVERRIDE |
|
78 { |
|
79 return NS_OK; |
|
80 } |
|
81 |
|
82 NS_IMETHOD |
|
83 UpdatePresentationData(uint32_t aFlagsValues, |
|
84 uint32_t aFlagsToUpdate) MOZ_OVERRIDE; |
|
85 |
|
86 NS_IMETHOD |
|
87 UpdatePresentationDataFromChildAt(int32_t aFirstIndex, |
|
88 int32_t aLastIndex, |
|
89 uint32_t aFlagsValues, |
|
90 uint32_t aFlagsToUpdate) MOZ_OVERRIDE |
|
91 { |
|
92 return NS_OK; |
|
93 } |
|
94 |
|
95 uint8_t |
|
96 ScriptIncrement(nsIFrame* aFrame) MOZ_OVERRIDE |
|
97 { |
|
98 return 0; |
|
99 } |
|
100 |
|
101 bool |
|
102 IsMrowLike() MOZ_OVERRIDE |
|
103 { |
|
104 return false; |
|
105 } |
|
106 |
|
107 // helper to give a style context suitable for doing the stretching to the |
|
108 // MathMLChar. Frame classes that use this should make the extra style contexts |
|
109 // accessible to the Style System via Get/Set AdditionalStyleContext. |
|
110 static void |
|
111 ResolveMathMLCharStyle(nsPresContext* aPresContext, |
|
112 nsIContent* aContent, |
|
113 nsStyleContext* aParenStyleContext, |
|
114 nsMathMLChar* aMathMLChar); |
|
115 |
|
116 // helper to get the mEmbellishData of a frame |
|
117 // The MathML REC precisely defines an "embellished operator" as: |
|
118 // - an <mo> element; |
|
119 // - or one of the elements <msub>, <msup>, <msubsup>, <munder>, <mover>, |
|
120 // <munderover>, <mmultiscripts>, <mfrac>, or <semantics>, whose first |
|
121 // argument exists and is an embellished operator; |
|
122 //- or one of the elements <mstyle>, <mphantom>, or <mpadded>, such that |
|
123 // an <mrow> containing the same arguments would be an embellished |
|
124 // operator; |
|
125 // - or an <maction> element whose selected subexpression exists and is an |
|
126 // embellished operator; |
|
127 // - or an <mrow> whose arguments consist (in any order) of one embellished |
|
128 // operator and zero or more spacelike elements. |
|
129 static void |
|
130 GetEmbellishDataFrom(nsIFrame* aFrame, |
|
131 nsEmbellishData& aEmbellishData); |
|
132 |
|
133 // helper to get the presentation data of a frame. If aClimbTree is |
|
134 // set to true and the frame happens to be surrounded by non-MathML |
|
135 // helper frames needed for its support, we walk up the frame hierarchy |
|
136 // until we reach a MathML ancestor or the <root> math element. |
|
137 static void |
|
138 GetPresentationDataFrom(nsIFrame* aFrame, |
|
139 nsPresentationData& aPresentationData, |
|
140 bool aClimbTree = true); |
|
141 |
|
142 // utilities to parse and retrieve numeric values in CSS units |
|
143 // All values are stored in twips. |
|
144 // @pre aLengthValue is the default length value of the attribute. |
|
145 // @post aLengthValue is the length value computed from the attribute. |
|
146 static void ParseNumericValue(const nsString& aString, |
|
147 nscoord* aLengthValue, |
|
148 uint32_t aFlags, |
|
149 nsPresContext* aPresContext, |
|
150 nsStyleContext* aStyleContext); |
|
151 |
|
152 static nscoord |
|
153 CalcLength(nsPresContext* aPresContext, |
|
154 nsStyleContext* aStyleContext, |
|
155 const nsCSSValue& aCSSValue); |
|
156 |
|
157 static eMathMLFrameType |
|
158 GetMathMLFrameTypeFor(nsIFrame* aFrame) |
|
159 { |
|
160 if (aFrame->IsFrameOfType(nsIFrame::eMathML)) { |
|
161 nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame); |
|
162 if (mathMLFrame) |
|
163 return mathMLFrame->GetMathMLFrameType(); |
|
164 } |
|
165 return eMathMLFrameType_UNKNOWN; |
|
166 } |
|
167 |
|
168 // estimate of the italic correction |
|
169 static void |
|
170 GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics, |
|
171 nscoord& aItalicCorrection) |
|
172 { |
|
173 aItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width; |
|
174 if (0 > aItalicCorrection) { |
|
175 aItalicCorrection = 0; |
|
176 } |
|
177 } |
|
178 |
|
179 static void |
|
180 GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics, |
|
181 nscoord& aLeftItalicCorrection, |
|
182 nscoord& aRightItalicCorrection) |
|
183 { |
|
184 aRightItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width; |
|
185 if (0 > aRightItalicCorrection) { |
|
186 aRightItalicCorrection = 0; |
|
187 } |
|
188 aLeftItalicCorrection = -aBoundingMetrics.leftBearing; |
|
189 if (0 > aLeftItalicCorrection) { |
|
190 aLeftItalicCorrection = 0; |
|
191 } |
|
192 } |
|
193 |
|
194 // helper methods for getting sup/subdrop's from a child |
|
195 static void |
|
196 GetSubDropFromChild(nsIFrame* aChild, |
|
197 nscoord& aSubDrop) |
|
198 { |
|
199 nsRefPtr<nsFontMetrics> fm; |
|
200 nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm)); |
|
201 GetSubDrop(fm, aSubDrop); |
|
202 } |
|
203 |
|
204 static void |
|
205 GetSupDropFromChild(nsIFrame* aChild, |
|
206 nscoord& aSupDrop) |
|
207 { |
|
208 nsRefPtr<nsFontMetrics> fm; |
|
209 nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm)); |
|
210 GetSupDrop(fm, aSupDrop); |
|
211 } |
|
212 |
|
213 static void |
|
214 GetSkewCorrectionFromChild(nsIFrame* aChild, |
|
215 nscoord& aSkewCorrection) |
|
216 { |
|
217 // default is 0 |
|
218 // individual classes should over-ride this method if necessary |
|
219 aSkewCorrection = 0; |
|
220 } |
|
221 |
|
222 // 2 levels of subscript shifts |
|
223 static void |
|
224 GetSubScriptShifts(nsFontMetrics* fm, |
|
225 nscoord& aSubScriptShift1, |
|
226 nscoord& aSubScriptShift2) |
|
227 { |
|
228 nscoord xHeight = fm->XHeight(); |
|
229 aSubScriptShift1 = NSToCoordRound(150.000f/430.556f * xHeight); |
|
230 aSubScriptShift2 = NSToCoordRound(247.217f/430.556f * xHeight); |
|
231 } |
|
232 |
|
233 // 3 levels of superscript shifts |
|
234 static void |
|
235 GetSupScriptShifts(nsFontMetrics* fm, |
|
236 nscoord& aSupScriptShift1, |
|
237 nscoord& aSupScriptShift2, |
|
238 nscoord& aSupScriptShift3) |
|
239 { |
|
240 nscoord xHeight = fm->XHeight(); |
|
241 aSupScriptShift1 = NSToCoordRound(412.892f/430.556f * xHeight); |
|
242 aSupScriptShift2 = NSToCoordRound(362.892f/430.556f * xHeight); |
|
243 aSupScriptShift3 = NSToCoordRound(288.889f/430.556f * xHeight); |
|
244 } |
|
245 |
|
246 // these are TeX specific params not found in ordinary fonts |
|
247 |
|
248 static void |
|
249 GetSubDrop(nsFontMetrics* fm, |
|
250 nscoord& aSubDrop) |
|
251 { |
|
252 nscoord xHeight = fm->XHeight(); |
|
253 aSubDrop = NSToCoordRound(50.000f/430.556f * xHeight); |
|
254 } |
|
255 |
|
256 static void |
|
257 GetSupDrop(nsFontMetrics* fm, |
|
258 nscoord& aSupDrop) |
|
259 { |
|
260 nscoord xHeight = fm->XHeight(); |
|
261 aSupDrop = NSToCoordRound(386.108f/430.556f * xHeight); |
|
262 } |
|
263 |
|
264 static void |
|
265 GetNumeratorShifts(nsFontMetrics* fm, |
|
266 nscoord& numShift1, |
|
267 nscoord& numShift2, |
|
268 nscoord& numShift3) |
|
269 { |
|
270 nscoord xHeight = fm->XHeight(); |
|
271 numShift1 = NSToCoordRound(676.508f/430.556f * xHeight); |
|
272 numShift2 = NSToCoordRound(393.732f/430.556f * xHeight); |
|
273 numShift3 = NSToCoordRound(443.731f/430.556f * xHeight); |
|
274 } |
|
275 |
|
276 static void |
|
277 GetDenominatorShifts(nsFontMetrics* fm, |
|
278 nscoord& denShift1, |
|
279 nscoord& denShift2) |
|
280 { |
|
281 nscoord xHeight = fm->XHeight(); |
|
282 denShift1 = NSToCoordRound(685.951f/430.556f * xHeight); |
|
283 denShift2 = NSToCoordRound(344.841f/430.556f * xHeight); |
|
284 } |
|
285 |
|
286 static void |
|
287 GetEmHeight(nsFontMetrics* fm, |
|
288 nscoord& emHeight) |
|
289 { |
|
290 #if 0 |
|
291 // should switch to this API in order to scale with changes of TextZoom |
|
292 emHeight = fm->EmHeight(); |
|
293 #else |
|
294 emHeight = NSToCoordRound(float(fm->Font().size)); |
|
295 #endif |
|
296 } |
|
297 |
|
298 static void |
|
299 GetAxisHeight (nsFontMetrics* fm, |
|
300 nscoord& axisHeight) |
|
301 { |
|
302 axisHeight = NSToCoordRound(250.000f/430.556f * fm->XHeight()); |
|
303 } |
|
304 |
|
305 static void |
|
306 GetBigOpSpacings(nsFontMetrics* fm, |
|
307 nscoord& bigOpSpacing1, |
|
308 nscoord& bigOpSpacing2, |
|
309 nscoord& bigOpSpacing3, |
|
310 nscoord& bigOpSpacing4, |
|
311 nscoord& bigOpSpacing5) |
|
312 { |
|
313 nscoord xHeight = fm->XHeight(); |
|
314 bigOpSpacing1 = NSToCoordRound(111.111f/430.556f * xHeight); |
|
315 bigOpSpacing2 = NSToCoordRound(166.667f/430.556f * xHeight); |
|
316 bigOpSpacing3 = NSToCoordRound(200.000f/430.556f * xHeight); |
|
317 bigOpSpacing4 = NSToCoordRound(600.000f/430.556f * xHeight); |
|
318 bigOpSpacing5 = NSToCoordRound(100.000f/430.556f * xHeight); |
|
319 } |
|
320 |
|
321 static void |
|
322 GetRuleThickness(nsFontMetrics* fm, |
|
323 nscoord& ruleThickness) |
|
324 { |
|
325 nscoord xHeight = fm->XHeight(); |
|
326 ruleThickness = NSToCoordRound(40.000f/430.556f * xHeight); |
|
327 } |
|
328 |
|
329 // Some parameters are not accurately obtained using the x-height. |
|
330 // Here are some slower variants to obtain the desired metrics |
|
331 // by actually measuring some characters |
|
332 static void |
|
333 GetRuleThickness(nsRenderingContext& aRenderingContext, |
|
334 nsFontMetrics* aFontMetrics, |
|
335 nscoord& aRuleThickness); |
|
336 |
|
337 static void |
|
338 GetAxisHeight(nsRenderingContext& aRenderingContext, |
|
339 nsFontMetrics* aFontMetrics, |
|
340 nscoord& aAxisHeight); |
|
341 |
|
342 protected: |
|
343 #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX) |
|
344 nsresult DisplayBoundingMetrics(nsDisplayListBuilder* aBuilder, |
|
345 nsIFrame* aFrame, const nsPoint& aPt, |
|
346 const nsBoundingMetrics& aMetrics, |
|
347 const nsDisplayListSet& aLists); |
|
348 #endif |
|
349 |
|
350 /** |
|
351 * Display a solid rectangle in the frame's text color. Used for drawing |
|
352 * fraction separators and root/sqrt overbars. |
|
353 */ |
|
354 void DisplayBar(nsDisplayListBuilder* aBuilder, |
|
355 nsIFrame* aFrame, const nsRect& aRect, |
|
356 const nsDisplayListSet& aLists); |
|
357 |
|
358 // information about the presentation policy of the frame |
|
359 nsPresentationData mPresentationData; |
|
360 |
|
361 // information about a container that is an embellished operator |
|
362 nsEmbellishData mEmbellishData; |
|
363 |
|
364 // Metrics that _exactly_ enclose the text of the frame |
|
365 nsBoundingMetrics mBoundingMetrics; |
|
366 |
|
367 // Reference point of the frame: mReference.y is the baseline |
|
368 nsPoint mReference; |
|
369 }; |
|
370 |
|
371 #endif /* nsMathMLFrame_h___ */ |