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/. */
6 #ifndef nsMathMLFrame_h___
7 #define nsMathMLFrame_h___
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"
19 class nsDisplayListSet
;
21 // Concrete base class with default methods that derived MathML frames can override
22 class nsMathMLFrame
: public nsIMathMLFrame
{
28 IsSpaceLike() MOZ_OVERRIDE
{
29 return NS_MATHML_IS_SPACE_LIKE(mPresentationData
.flags
);
33 GetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) MOZ_OVERRIDE
{
34 aBoundingMetrics
= mBoundingMetrics
;
39 SetBoundingMetrics(const nsBoundingMetrics
& aBoundingMetrics
) MOZ_OVERRIDE
{
40 mBoundingMetrics
= aBoundingMetrics
;
45 SetReference(const nsPoint
& aReference
) MOZ_OVERRIDE
{
46 mReference
= aReference
;
50 virtual eMathMLFrameType
GetMathMLFrameType() MOZ_OVERRIDE
;
53 Stretch(nsRenderingContext
& aRenderingContext
,
54 nsStretchDirection aStretchDirection
,
55 nsBoundingMetrics
& aContainerSize
,
56 nsHTMLReflowMetrics
& aDesiredStretchSize
) MOZ_OVERRIDE
62 GetEmbellishData(nsEmbellishData
& aEmbellishData
) MOZ_OVERRIDE
{
63 aEmbellishData
= mEmbellishData
;
68 GetPresentationData(nsPresentationData
& aPresentationData
) MOZ_OVERRIDE
{
69 aPresentationData
= mPresentationData
;
74 InheritAutomaticData(nsIFrame
* aParent
) MOZ_OVERRIDE
;
77 TransmitAutomaticData() MOZ_OVERRIDE
83 UpdatePresentationData(uint32_t aFlagsValues
,
84 uint32_t aFlagsToUpdate
) MOZ_OVERRIDE
;
87 UpdatePresentationDataFromChildAt(int32_t aFirstIndex
,
89 uint32_t aFlagsValues
,
90 uint32_t aFlagsToUpdate
) MOZ_OVERRIDE
96 ScriptIncrement(nsIFrame
* aFrame
) MOZ_OVERRIDE
102 IsMrowLike() MOZ_OVERRIDE
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.
111 ResolveMathMLCharStyle(nsPresContext
* aPresContext
,
112 nsIContent
* aContent
,
113 nsStyleContext
* aParenStyleContext
,
114 nsMathMLChar
* aMathMLChar
);
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
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.
130 GetEmbellishDataFrom(nsIFrame
* aFrame
,
131 nsEmbellishData
& aEmbellishData
);
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.
138 GetPresentationDataFrom(nsIFrame
* aFrame
,
139 nsPresentationData
& aPresentationData
,
140 bool aClimbTree
= true);
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
,
149 nsPresContext
* aPresContext
,
150 nsStyleContext
* aStyleContext
,
151 float aFontSizeInflation
);
154 CalcLength(nsPresContext
* aPresContext
,
155 nsStyleContext
* aStyleContext
,
156 const nsCSSValue
& aCSSValue
,
157 float aFontSizeInflation
);
159 static eMathMLFrameType
160 GetMathMLFrameTypeFor(nsIFrame
* aFrame
)
162 if (aFrame
->IsFrameOfType(nsIFrame::eMathML
)) {
163 nsIMathMLFrame
* mathMLFrame
= do_QueryFrame(aFrame
);
165 return mathMLFrame
->GetMathMLFrameType();
167 return eMathMLFrameType_UNKNOWN
;
170 // estimate of the italic correction
172 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
173 nscoord
& aItalicCorrection
)
175 aItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
176 if (0 > aItalicCorrection
) {
177 aItalicCorrection
= 0;
182 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
183 nscoord
& aLeftItalicCorrection
,
184 nscoord
& aRightItalicCorrection
)
186 aRightItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
187 if (0 > aRightItalicCorrection
) {
188 aRightItalicCorrection
= 0;
190 aLeftItalicCorrection
= -aBoundingMetrics
.leftBearing
;
191 if (0 > aLeftItalicCorrection
) {
192 aLeftItalicCorrection
= 0;
196 // helper methods for getting sup/subdrop's from a child
198 GetSubDropFromChild(nsIFrame
* aChild
,
200 float aFontSizeInflation
)
202 nsRefPtr
<nsFontMetrics
> fm
;
203 nsLayoutUtils::GetFontMetricsForFrame(aChild
, getter_AddRefs(fm
),
205 GetSubDrop(fm
, aSubDrop
);
209 GetSupDropFromChild(nsIFrame
* aChild
,
211 float aFontSizeInflation
)
213 nsRefPtr
<nsFontMetrics
> fm
;
214 nsLayoutUtils::GetFontMetricsForFrame(aChild
, getter_AddRefs(fm
),
216 GetSupDrop(fm
, aSupDrop
);
220 GetSkewCorrectionFromChild(nsIFrame
* aChild
,
221 nscoord
& aSkewCorrection
)
224 // individual classes should over-ride this method if necessary
228 // 2 levels of subscript shifts
230 GetSubScriptShifts(nsFontMetrics
* fm
,
231 nscoord
& aSubScriptShift1
,
232 nscoord
& aSubScriptShift2
)
234 nscoord xHeight
= fm
->XHeight();
235 aSubScriptShift1
= NSToCoordRound(150.000f
/430.556f
* xHeight
);
236 aSubScriptShift2
= NSToCoordRound(247.217f
/430.556f
* xHeight
);
239 // 3 levels of superscript shifts
241 GetSupScriptShifts(nsFontMetrics
* fm
,
242 nscoord
& aSupScriptShift1
,
243 nscoord
& aSupScriptShift2
,
244 nscoord
& aSupScriptShift3
)
246 nscoord xHeight
= fm
->XHeight();
247 aSupScriptShift1
= NSToCoordRound(412.892f
/430.556f
* xHeight
);
248 aSupScriptShift2
= NSToCoordRound(362.892f
/430.556f
* xHeight
);
249 aSupScriptShift3
= NSToCoordRound(288.889f
/430.556f
* xHeight
);
252 // these are TeX specific params not found in ordinary fonts
255 GetSubDrop(nsFontMetrics
* fm
,
258 nscoord xHeight
= fm
->XHeight();
259 aSubDrop
= NSToCoordRound(50.000f
/430.556f
* xHeight
);
263 GetSupDrop(nsFontMetrics
* fm
,
266 nscoord xHeight
= fm
->XHeight();
267 aSupDrop
= NSToCoordRound(386.108f
/430.556f
* xHeight
);
271 GetNumeratorShifts(nsFontMetrics
* fm
,
276 nscoord xHeight
= fm
->XHeight();
277 numShift1
= NSToCoordRound(676.508f
/430.556f
* xHeight
);
278 numShift2
= NSToCoordRound(393.732f
/430.556f
* xHeight
);
279 numShift3
= NSToCoordRound(443.731f
/430.556f
* xHeight
);
283 GetDenominatorShifts(nsFontMetrics
* fm
,
287 nscoord xHeight
= fm
->XHeight();
288 denShift1
= NSToCoordRound(685.951f
/430.556f
* xHeight
);
289 denShift2
= NSToCoordRound(344.841f
/430.556f
* xHeight
);
293 GetEmHeight(nsFontMetrics
* fm
,
297 // should switch to this API in order to scale with changes of TextZoom
298 emHeight
= fm
->EmHeight();
300 emHeight
= NSToCoordRound(float(fm
->Font().size
));
305 GetAxisHeight (nsFontMetrics
* fm
,
308 axisHeight
= NSToCoordRound(250.000f
/430.556f
* fm
->XHeight());
312 GetBigOpSpacings(nsFontMetrics
* fm
,
313 nscoord
& bigOpSpacing1
,
314 nscoord
& bigOpSpacing2
,
315 nscoord
& bigOpSpacing3
,
316 nscoord
& bigOpSpacing4
,
317 nscoord
& bigOpSpacing5
)
319 nscoord xHeight
= fm
->XHeight();
320 bigOpSpacing1
= NSToCoordRound(111.111f
/430.556f
* xHeight
);
321 bigOpSpacing2
= NSToCoordRound(166.667f
/430.556f
* xHeight
);
322 bigOpSpacing3
= NSToCoordRound(200.000f
/430.556f
* xHeight
);
323 bigOpSpacing4
= NSToCoordRound(600.000f
/430.556f
* xHeight
);
324 bigOpSpacing5
= NSToCoordRound(100.000f
/430.556f
* xHeight
);
328 GetRuleThickness(nsFontMetrics
* fm
,
329 nscoord
& ruleThickness
)
331 nscoord xHeight
= fm
->XHeight();
332 ruleThickness
= NSToCoordRound(40.000f
/430.556f
* xHeight
);
335 // Some parameters are not accurately obtained using the x-height.
336 // Here are some slower variants to obtain the desired metrics
337 // by actually measuring some characters
339 GetRuleThickness(nsRenderingContext
& aRenderingContext
,
340 nsFontMetrics
* aFontMetrics
,
341 nscoord
& aRuleThickness
);
344 GetAxisHeight(nsRenderingContext
& aRenderingContext
,
345 nsFontMetrics
* aFontMetrics
,
346 nscoord
& aAxisHeight
);
349 GetRadicalParameters(nsFontMetrics
* aFontMetrics
,
351 nscoord
& aRadicalRuleThickness
,
352 nscoord
& aRadicalExtraAscender
,
353 nscoord
& aRadicalVerticalGap
);
356 #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
357 nsresult
DisplayBoundingMetrics(nsDisplayListBuilder
* aBuilder
,
358 nsIFrame
* aFrame
, const nsPoint
& aPt
,
359 const nsBoundingMetrics
& aMetrics
,
360 const nsDisplayListSet
& aLists
);
364 * Display a solid rectangle in the frame's text color. Used for drawing
365 * fraction separators and root/sqrt overbars.
367 void DisplayBar(nsDisplayListBuilder
* aBuilder
,
368 nsIFrame
* aFrame
, const nsRect
& aRect
,
369 const nsDisplayListSet
& aLists
);
371 // information about the presentation policy of the frame
372 nsPresentationData mPresentationData
;
374 // information about a container that is an embellished operator
375 nsEmbellishData mEmbellishData
;
377 // Metrics that _exactly_ enclose the text of the frame
378 nsBoundingMetrics mBoundingMetrics
;
380 // Reference point of the frame: mReference.y is the baseline
384 #endif /* nsMathMLFrame_h___ */