1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla MathML Project.
17 * The Initial Developer of the Original Code is
18 * The University Of Queensland.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
23 * Roger B. Sidje <rbs@maths.uq.edu.au>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsMathMLFrame_h___
40 #define nsMathMLFrame_h___
43 #include "nsPresContext.h"
44 #include "nsIRenderingContext.h"
45 #include "nsIFontMetrics.h"
46 #include "nsStyleContext.h"
47 #include "nsMathMLAtoms.h"
48 #include "nsMathMLOperators.h"
49 #include "nsIMathMLFrame.h"
51 #include "nsCSSValue.h"
52 #include "nsMathMLElement.h"
56 // Concrete base class with default methods that derived MathML frames can override
57 class nsMathMLFrame
: public nsIMathMLFrame
{
63 GetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) {
64 aBoundingMetrics
= mBoundingMetrics
;
69 SetBoundingMetrics(const nsBoundingMetrics
& aBoundingMetrics
) {
70 mBoundingMetrics
= aBoundingMetrics
;
75 SetReference(const nsPoint
& aReference
) {
76 mReference
= aReference
;
80 virtual eMathMLFrameType
GetMathMLFrameType();
83 Stretch(nsIRenderingContext
& aRenderingContext
,
84 nsStretchDirection aStretchDirection
,
85 nsBoundingMetrics
& aContainerSize
,
86 nsHTMLReflowMetrics
& aDesiredStretchSize
)
92 GetEmbellishData(nsEmbellishData
& aEmbellishData
) {
93 aEmbellishData
= mEmbellishData
;
98 GetPresentationData(nsPresentationData
& aPresentationData
) {
99 aPresentationData
= mPresentationData
;
104 InheritAutomaticData(nsIFrame
* aParent
);
107 TransmitAutomaticData()
113 UpdatePresentationData(PRUint32 aFlagsValues
,
114 PRUint32 aFlagsToUpdate
);
117 UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex
,
119 PRUint32 aFlagsValues
,
120 PRUint32 aFlagsToUpdate
)
125 // helper to give a style context suitable for doing the stretching to the
126 // MathMLChar. Frame classes that use this should make the extra style contexts
127 // accessible to the Style System via Get/Set AdditionalStyleContext.
129 ResolveMathMLCharStyle(nsPresContext
* aPresContext
,
130 nsIContent
* aContent
,
131 nsStyleContext
* aParenStyleContext
,
132 nsMathMLChar
* aMathMLChar
,
133 PRBool aIsMutableChar
);
135 // helper to get the mEmbellishData of a frame
136 // The MathML REC precisely defines an "embellished operator" as:
137 // - an <mo> element;
138 // - or one of the elements <msub>, <msup>, <msubsup>, <munder>, <mover>,
139 // <munderover>, <mmultiscripts>, <mfrac>, or <semantics>, whose first
140 // argument exists and is an embellished operator;
141 //- or one of the elements <mstyle>, <mphantom>, or <mpadded>, such that
142 // an <mrow> containing the same arguments would be an embellished
144 // - or an <maction> element whose selected subexpression exists and is an
145 // embellished operator;
146 // - or an <mrow> whose arguments consist (in any order) of one embellished
147 // operator and zero or more spacelike elements.
149 GetEmbellishDataFrom(nsIFrame
* aFrame
,
150 nsEmbellishData
& aEmbellishData
);
152 // helper to get the presentation data of a frame. If aClimbTree is
153 // set to true and the frame happens to be surrounded by non-MathML
154 // helper frames needed for its support, we walk up the frame hierarchy
155 // until we reach a MathML ancestor or the <root> math element.
157 GetPresentationDataFrom(nsIFrame
* aFrame
,
158 nsPresentationData
& aPresentationData
,
159 PRBool aClimbTree
= PR_TRUE
);
161 // helper used by <mstyle> and <mtable> to see if they have a displaystyle attribute
163 FindAttrDisplaystyle(nsIContent
* aContent
,
164 nsPresentationData
& aPresentationData
);
166 // helper to check if a content has an attribute. If content is nsnull or if
167 // the attribute is not there, check if the attribute is on the mstyle hierarchy
168 // @return PR_TRUE --if attribute exists
169 // PR_FALSE --if attribute doesn't exist
171 GetAttribute(nsIContent
* aContent
,
172 nsIFrame
* aMathMLmstyleFrame
,
173 nsIAtom
* aAttributeAtom
,
176 // utilities to parse and retrieve numeric values in CSS units
177 // All values are stored in twips.
179 ParseNumericValue(const nsString
& aString
,
180 nsCSSValue
& aCSSValue
) {
181 return nsMathMLElement::ParseNumericValue(aString
, aCSSValue
,
182 nsMathMLElement::PARSE_ALLOW_NEGATIVE
|
183 nsMathMLElement::PARSE_ALLOW_UNITLESS
);
187 CalcLength(nsPresContext
* aPresContext
,
188 nsStyleContext
* aStyleContext
,
189 const nsCSSValue
& aCSSValue
);
192 ParseNamedSpaceValue(nsIFrame
* aMathMLmstyleFrame
,
194 nsCSSValue
& aCSSValue
);
196 static eMathMLFrameType
197 GetMathMLFrameTypeFor(nsIFrame
* aFrame
)
199 if (aFrame
->IsFrameOfType(nsIFrame::eMathML
)) {
200 nsIMathMLFrame
* mathMLFrame
= do_QueryFrame(aFrame
);
202 return mathMLFrame
->GetMathMLFrameType();
204 return eMathMLFrameType_UNKNOWN
;
207 // estimate of the italic correction
209 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
210 nscoord
& aItalicCorrection
)
212 aItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
213 if (0 > aItalicCorrection
) {
214 aItalicCorrection
= 0;
219 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
220 nscoord
& aLeftItalicCorrection
,
221 nscoord
& aRightItalicCorrection
)
223 aRightItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
224 if (0 > aRightItalicCorrection
) {
225 aRightItalicCorrection
= 0;
227 aLeftItalicCorrection
= -aBoundingMetrics
.leftBearing
;
228 if (0 > aLeftItalicCorrection
) {
229 aLeftItalicCorrection
= 0;
233 // helper methods for getting sup/subdrop's from a child
235 GetSubDropFromChild(nsIFrame
* aChild
,
238 const nsStyleFont
* font
= aChild
->GetStyleFont();
239 nsCOMPtr
<nsIFontMetrics
> fm
= aChild
->PresContext()->GetMetricsFor(
241 GetSubDrop(fm
, aSubDrop
);
245 GetSupDropFromChild(nsIFrame
* aChild
,
248 const nsStyleFont
* font
= aChild
->GetStyleFont();
249 nsCOMPtr
<nsIFontMetrics
> fm
= aChild
->PresContext()->GetMetricsFor(
251 GetSupDrop(fm
, aSupDrop
);
255 GetSkewCorrectionFromChild(nsIFrame
* aChild
,
256 nscoord
& aSkewCorrection
)
259 // individual classes should over-ride this method if necessary
263 // 2 levels of subscript shifts
265 GetSubScriptShifts(nsIFontMetrics
* fm
,
266 nscoord
& aSubScriptShift1
,
267 nscoord
& aSubScriptShift2
)
270 fm
->GetXHeight(xHeight
);
271 aSubScriptShift1
= NSToCoordRound(150.000f
/430.556f
* xHeight
);
272 aSubScriptShift2
= NSToCoordRound(247.217f
/430.556f
* xHeight
);
275 // 3 levels of superscript shifts
277 GetSupScriptShifts(nsIFontMetrics
* fm
,
278 nscoord
& aSupScriptShift1
,
279 nscoord
& aSupScriptShift2
,
280 nscoord
& aSupScriptShift3
)
283 fm
->GetXHeight(xHeight
);
284 aSupScriptShift1
= NSToCoordRound(412.892f
/430.556f
* xHeight
);
285 aSupScriptShift2
= NSToCoordRound(362.892f
/430.556f
* xHeight
);
286 aSupScriptShift3
= NSToCoordRound(288.889f
/430.556f
* xHeight
);
289 // these are TeX specific params not found in ordinary fonts
292 GetSubDrop(nsIFontMetrics
* fm
,
296 fm
->GetXHeight(xHeight
);
297 aSubDrop
= NSToCoordRound(50.000f
/430.556f
* xHeight
);
301 GetSupDrop(nsIFontMetrics
* fm
,
305 fm
->GetXHeight(xHeight
);
306 aSupDrop
= NSToCoordRound(386.108f
/430.556f
* xHeight
);
310 GetNumeratorShifts(nsIFontMetrics
* fm
,
316 fm
->GetXHeight(xHeight
);
317 numShift1
= NSToCoordRound(676.508f
/430.556f
* xHeight
);
318 numShift2
= NSToCoordRound(393.732f
/430.556f
* xHeight
);
319 numShift3
= NSToCoordRound(443.731f
/430.556f
* xHeight
);
323 GetDenominatorShifts(nsIFontMetrics
* fm
,
328 fm
->GetXHeight(xHeight
);
329 denShift1
= NSToCoordRound(685.951f
/430.556f
* xHeight
);
330 denShift2
= NSToCoordRound(344.841f
/430.556f
* xHeight
);
334 GetEmHeight(nsIFontMetrics
* fm
,
338 // should switch to this API in order to scale with changes of TextZoom
339 fm
->GetEmHeight(emHeight
);
341 emHeight
= NSToCoordRound(float(fm
->Font().size
));
346 GetAxisHeight (nsIFontMetrics
* fm
,
349 fm
->GetXHeight (axisHeight
);
350 axisHeight
= NSToCoordRound(250.000f
/430.556f
* axisHeight
);
354 GetBigOpSpacings(nsIFontMetrics
* fm
,
355 nscoord
& bigOpSpacing1
,
356 nscoord
& bigOpSpacing2
,
357 nscoord
& bigOpSpacing3
,
358 nscoord
& bigOpSpacing4
,
359 nscoord
& bigOpSpacing5
)
362 fm
->GetXHeight(xHeight
);
363 bigOpSpacing1
= NSToCoordRound(111.111f
/430.556f
* xHeight
);
364 bigOpSpacing2
= NSToCoordRound(166.667f
/430.556f
* xHeight
);
365 bigOpSpacing3
= NSToCoordRound(200.000f
/430.556f
* xHeight
);
366 bigOpSpacing4
= NSToCoordRound(600.000f
/430.556f
* xHeight
);
367 bigOpSpacing5
= NSToCoordRound(100.000f
/430.556f
* xHeight
);
371 GetRuleThickness(nsIFontMetrics
* fm
,
372 nscoord
& ruleThickness
)
375 fm
->GetXHeight(xHeight
);
376 ruleThickness
= NSToCoordRound(40.000f
/430.556f
* xHeight
);
379 // Some parameters are not accurately obtained using the x-height.
380 // Here are some slower variants to obtain the desired metrics
381 // by actually measuring some characters
383 GetRuleThickness(nsIRenderingContext
& aRenderingContext
,
384 nsIFontMetrics
* aFontMetrics
,
385 nscoord
& aRuleThickness
);
388 GetAxisHeight(nsIRenderingContext
& aRenderingContext
,
389 nsIFontMetrics
* aFontMetrics
,
390 nscoord
& aAxisHeight
);
393 #if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
394 nsresult
DisplayBoundingMetrics(nsDisplayListBuilder
* aBuilder
,
395 nsIFrame
* aFrame
, const nsPoint
& aPt
,
396 const nsBoundingMetrics
& aMetrics
,
397 const nsDisplayListSet
& aLists
);
401 * Display a solid rectangle in the frame's text color. Used for drawing
402 * fraction separators and root/sqrt overbars.
404 nsresult
DisplayBar(nsDisplayListBuilder
* aBuilder
,
405 nsIFrame
* aFrame
, const nsRect
& aRect
,
406 const nsDisplayListSet
& aLists
);
408 // information about the presentation policy of the frame
409 nsPresentationData mPresentationData
;
411 // information about a container that is an embellished operator
412 nsEmbellishData mEmbellishData
;
414 // Metrics that _exactly_ enclose the text of the frame
415 nsBoundingMetrics mBoundingMetrics
;
417 // Reference point of the frame: mReference.y is the baseline
421 #endif /* nsMathMLFrame_h___ */