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
{
27 IsSpaceLike() override
{
28 return NS_MATHML_IS_SPACE_LIKE(mPresentationData
.flags
);
32 GetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) override
{
33 aBoundingMetrics
= mBoundingMetrics
;
38 SetBoundingMetrics(const nsBoundingMetrics
& aBoundingMetrics
) override
{
39 mBoundingMetrics
= aBoundingMetrics
;
44 SetReference(const nsPoint
& aReference
) override
{
45 mReference
= aReference
;
49 virtual eMathMLFrameType
GetMathMLFrameType() override
;
52 Stretch(mozilla::gfx::DrawTarget
* aDrawTarget
,
53 nsStretchDirection aStretchDirection
,
54 nsBoundingMetrics
& aContainerSize
,
55 mozilla::ReflowOutput
& aDesiredStretchSize
) override
61 GetEmbellishData(nsEmbellishData
& aEmbellishData
) override
{
62 aEmbellishData
= mEmbellishData
;
67 GetPresentationData(nsPresentationData
& aPresentationData
) override
{
68 aPresentationData
= mPresentationData
;
73 InheritAutomaticData(nsIFrame
* aParent
) override
;
76 TransmitAutomaticData() override
82 UpdatePresentationData(uint32_t aFlagsValues
,
83 uint32_t aFlagsToUpdate
) override
;
86 UpdatePresentationDataFromChildAt(int32_t aFirstIndex
,
88 uint32_t aFlagsValues
,
89 uint32_t aFlagsToUpdate
) override
95 ScriptIncrement(nsIFrame
* aFrame
) override
101 IsMrowLike() override
106 // helper to give a style context suitable for doing the stretching to the
107 // MathMLChar. Frame classes that use this should make the extra style contexts
108 // accessible to the Style System via Get/Set AdditionalStyleContext.
110 ResolveMathMLCharStyle(nsPresContext
* aPresContext
,
111 nsIContent
* aContent
,
112 nsStyleContext
* aParenStyleContext
,
113 nsMathMLChar
* aMathMLChar
);
115 // helper to get the mEmbellishData of a frame
116 // The MathML REC precisely defines an "embellished operator" as:
117 // - an <mo> element;
118 // - or one of the elements <msub>, <msup>, <msubsup>, <munder>, <mover>,
119 // <munderover>, <mmultiscripts>, <mfrac>, or <semantics>, whose first
120 // argument exists and is an embellished operator;
121 //- or one of the elements <mstyle>, <mphantom>, or <mpadded>, such that
122 // an <mrow> containing the same arguments would be an embellished
124 // - or an <maction> element whose selected subexpression exists and is an
125 // embellished operator;
126 // - or an <mrow> whose arguments consist (in any order) of one embellished
127 // operator and zero or more spacelike elements.
129 GetEmbellishDataFrom(nsIFrame
* aFrame
,
130 nsEmbellishData
& aEmbellishData
);
132 // helper to get the presentation data of a frame. If aClimbTree is
133 // set to true and the frame happens to be surrounded by non-MathML
134 // helper frames needed for its support, we walk up the frame hierarchy
135 // until we reach a MathML ancestor or the <root> math element.
137 GetPresentationDataFrom(nsIFrame
* aFrame
,
138 nsPresentationData
& aPresentationData
,
139 bool aClimbTree
= true);
141 // utilities to parse and retrieve numeric values in CSS units
142 // All values are stored in twips.
143 // @pre aLengthValue is the default length value of the attribute.
144 // @post aLengthValue is the length value computed from the attribute.
145 static void ParseNumericValue(const nsString
& aString
,
146 nscoord
* aLengthValue
,
148 nsPresContext
* aPresContext
,
149 nsStyleContext
* aStyleContext
,
150 float aFontSizeInflation
);
153 CalcLength(nsPresContext
* aPresContext
,
154 nsStyleContext
* aStyleContext
,
155 const nsCSSValue
& aCSSValue
,
156 float aFontSizeInflation
);
158 static eMathMLFrameType
159 GetMathMLFrameTypeFor(nsIFrame
* aFrame
)
161 if (aFrame
->IsFrameOfType(nsIFrame::eMathML
)) {
162 nsIMathMLFrame
* mathMLFrame
= do_QueryFrame(aFrame
);
164 return mathMLFrame
->GetMathMLFrameType();
166 return eMathMLFrameType_UNKNOWN
;
169 // estimate of the italic correction
171 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
172 nscoord
& aItalicCorrection
)
174 aItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
175 if (0 > aItalicCorrection
) {
176 aItalicCorrection
= 0;
181 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
182 nscoord
& aLeftItalicCorrection
,
183 nscoord
& aRightItalicCorrection
)
185 aRightItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
186 if (0 > aRightItalicCorrection
) {
187 aRightItalicCorrection
= 0;
189 aLeftItalicCorrection
= -aBoundingMetrics
.leftBearing
;
190 if (0 > aLeftItalicCorrection
) {
191 aLeftItalicCorrection
= 0;
195 // helper methods for getting sup/subdrop's from a child
197 GetSubDropFromChild(nsIFrame
* aChild
,
199 float aFontSizeInflation
)
201 RefPtr
<nsFontMetrics
> fm
=
202 nsLayoutUtils::GetFontMetricsForFrame(aChild
, aFontSizeInflation
);
203 GetSubDrop(fm
, aSubDrop
);
207 GetSupDropFromChild(nsIFrame
* aChild
,
209 float aFontSizeInflation
)
211 RefPtr
<nsFontMetrics
> fm
=
212 nsLayoutUtils::GetFontMetricsForFrame(aChild
, aFontSizeInflation
);
213 GetSupDrop(fm
, aSupDrop
);
217 GetSkewCorrectionFromChild(nsIFrame
* aChild
,
218 nscoord
& aSkewCorrection
)
221 // individual classes should over-ride this method if necessary
225 // 2 levels of subscript shifts
227 GetSubScriptShifts(nsFontMetrics
* fm
,
228 nscoord
& aSubScriptShift1
,
229 nscoord
& aSubScriptShift2
)
231 nscoord xHeight
= fm
->XHeight();
232 aSubScriptShift1
= NSToCoordRound(150.000f
/430.556f
* xHeight
);
233 aSubScriptShift2
= NSToCoordRound(247.217f
/430.556f
* xHeight
);
236 // 3 levels of superscript shifts
238 GetSupScriptShifts(nsFontMetrics
* fm
,
239 nscoord
& aSupScriptShift1
,
240 nscoord
& aSupScriptShift2
,
241 nscoord
& aSupScriptShift3
)
243 nscoord xHeight
= fm
->XHeight();
244 aSupScriptShift1
= NSToCoordRound(412.892f
/430.556f
* xHeight
);
245 aSupScriptShift2
= NSToCoordRound(362.892f
/430.556f
* xHeight
);
246 aSupScriptShift3
= NSToCoordRound(288.889f
/430.556f
* xHeight
);
249 // these are TeX specific params not found in ordinary fonts
252 GetSubDrop(nsFontMetrics
* fm
,
255 nscoord xHeight
= fm
->XHeight();
256 aSubDrop
= NSToCoordRound(50.000f
/430.556f
* xHeight
);
260 GetSupDrop(nsFontMetrics
* fm
,
263 nscoord xHeight
= fm
->XHeight();
264 aSupDrop
= NSToCoordRound(386.108f
/430.556f
* xHeight
);
268 GetNumeratorShifts(nsFontMetrics
* fm
,
273 nscoord xHeight
= fm
->XHeight();
274 numShift1
= NSToCoordRound(676.508f
/430.556f
* xHeight
);
275 numShift2
= NSToCoordRound(393.732f
/430.556f
* xHeight
);
276 numShift3
= NSToCoordRound(443.731f
/430.556f
* xHeight
);
280 GetDenominatorShifts(nsFontMetrics
* fm
,
284 nscoord xHeight
= fm
->XHeight();
285 denShift1
= NSToCoordRound(685.951f
/430.556f
* xHeight
);
286 denShift2
= NSToCoordRound(344.841f
/430.556f
* xHeight
);
290 GetEmHeight(nsFontMetrics
* fm
,
294 // should switch to this API in order to scale with changes of TextZoom
295 emHeight
= fm
->EmHeight();
297 emHeight
= NSToCoordRound(float(fm
->Font().size
));
302 GetAxisHeight (nsFontMetrics
* fm
,
305 axisHeight
= NSToCoordRound(250.000f
/430.556f
* fm
->XHeight());
309 GetBigOpSpacings(nsFontMetrics
* fm
,
310 nscoord
& bigOpSpacing1
,
311 nscoord
& bigOpSpacing2
,
312 nscoord
& bigOpSpacing3
,
313 nscoord
& bigOpSpacing4
,
314 nscoord
& bigOpSpacing5
)
316 nscoord xHeight
= fm
->XHeight();
317 bigOpSpacing1
= NSToCoordRound(111.111f
/430.556f
* xHeight
);
318 bigOpSpacing2
= NSToCoordRound(166.667f
/430.556f
* xHeight
);
319 bigOpSpacing3
= NSToCoordRound(200.000f
/430.556f
* xHeight
);
320 bigOpSpacing4
= NSToCoordRound(600.000f
/430.556f
* xHeight
);
321 bigOpSpacing5
= NSToCoordRound(100.000f
/430.556f
* xHeight
);
325 GetRuleThickness(nsFontMetrics
* fm
,
326 nscoord
& ruleThickness
)
328 nscoord xHeight
= fm
->XHeight();
329 ruleThickness
= NSToCoordRound(40.000f
/430.556f
* xHeight
);
332 // Some parameters are not accurately obtained using the x-height.
333 // Here are some slower variants to obtain the desired metrics
334 // by actually measuring some characters
336 GetRuleThickness(mozilla::gfx::DrawTarget
* aDrawTarget
,
337 nsFontMetrics
* aFontMetrics
,
338 nscoord
& aRuleThickness
);
341 GetAxisHeight(mozilla::gfx::DrawTarget
* aDrawTarget
,
342 nsFontMetrics
* aFontMetrics
,
343 nscoord
& aAxisHeight
);
346 GetRadicalParameters(nsFontMetrics
* aFontMetrics
,
348 nscoord
& aRadicalRuleThickness
,
349 nscoord
& aRadicalExtraAscender
,
350 nscoord
& aRadicalVerticalGap
);
353 #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
354 void DisplayBoundingMetrics(nsDisplayListBuilder
* aBuilder
,
355 nsIFrame
* aFrame
, const nsPoint
& aPt
,
356 const nsBoundingMetrics
& aMetrics
,
357 const nsDisplayListSet
& aLists
);
361 * Display a solid rectangle in the frame's text color. Used for drawing
362 * fraction separators and root/sqrt overbars.
364 void DisplayBar(nsDisplayListBuilder
* aBuilder
,
365 nsIFrame
* aFrame
, const nsRect
& aRect
,
366 const nsDisplayListSet
& aLists
);
368 // information about the presentation policy of the frame
369 nsPresentationData mPresentationData
;
371 // information about a container that is an embellished operator
372 nsEmbellishData mEmbellishData
;
374 // Metrics that _exactly_ enclose the text of the frame
375 nsBoundingMetrics mBoundingMetrics
;
377 // Reference point of the frame: mReference.y is the baseline
381 #endif /* nsMathMLFrame_h___ */