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
{
62 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
);
64 NS_IMETHOD_(nsrefcnt
) AddRef() {
65 // not meaningfull for frames
69 NS_IMETHOD_(nsrefcnt
) Release() {
70 // not meaningfull for frames
77 GetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) {
78 aBoundingMetrics
= mBoundingMetrics
;
83 SetBoundingMetrics(const nsBoundingMetrics
& aBoundingMetrics
) {
84 mBoundingMetrics
= aBoundingMetrics
;
89 GetReference(nsPoint
& aReference
) {
90 aReference
= mReference
;
95 SetReference(const nsPoint
& aReference
) {
96 mReference
= aReference
;
100 virtual eMathMLFrameType
GetMathMLFrameType();
103 Stretch(nsIRenderingContext
& aRenderingContext
,
104 nsStretchDirection aStretchDirection
,
105 nsBoundingMetrics
& aContainerSize
,
106 nsHTMLReflowMetrics
& aDesiredStretchSize
)
112 GetEmbellishData(nsEmbellishData
& aEmbellishData
) {
113 aEmbellishData
= mEmbellishData
;
118 SetEmbellishData(const nsEmbellishData
& aEmbellishData
) {
119 mEmbellishData
= aEmbellishData
;
124 GetPresentationData(nsPresentationData
& aPresentationData
) {
125 aPresentationData
= mPresentationData
;
130 SetPresentationData(const nsPresentationData
& aPresentationData
) {
131 mPresentationData
= aPresentationData
;
136 InheritAutomaticData(nsIFrame
* aParent
);
139 TransmitAutomaticData()
145 UpdatePresentationData(PRUint32 aFlagsValues
,
146 PRUint32 aFlagsToUpdate
);
149 UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex
,
151 PRUint32 aFlagsValues
,
152 PRUint32 aFlagsToUpdate
)
157 // helper to give a style context suitable for doing the stretching to the
158 // MathMLChar. Frame classes that use this should make the extra style contexts
159 // accessible to the Style System via Get/Set AdditionalStyleContext.
161 ResolveMathMLCharStyle(nsPresContext
* aPresContext
,
162 nsIContent
* aContent
,
163 nsStyleContext
* aParenStyleContext
,
164 nsMathMLChar
* aMathMLChar
,
165 PRBool aIsMutableChar
);
167 // helper to get the mEmbellishData of a frame
168 // The MathML REC precisely defines an "embellished operator" as:
169 // - an <mo> element;
170 // - or one of the elements <msub>, <msup>, <msubsup>, <munder>, <mover>,
171 // <munderover>, <mmultiscripts>, <mfrac>, or <semantics>, whose first
172 // argument exists and is an embellished operator;
173 //- or one of the elements <mstyle>, <mphantom>, or <mpadded>, such that
174 // an <mrow> containing the same arguments would be an embellished
176 // - or an <maction> element whose selected subexpression exists and is an
177 // embellished operator;
178 // - or an <mrow> whose arguments consist (in any order) of one embellished
179 // operator and zero or more spacelike elements.
181 GetEmbellishDataFrom(nsIFrame
* aFrame
,
182 nsEmbellishData
& aEmbellishData
);
184 // helper to get the presentation data of a frame. If aClimbTree is
185 // set to true and the frame happens to be surrounded by non-MathML
186 // helper frames needed for its support, we walk up the frame hierarchy
187 // until we reach a MathML ancestor or the <root> math element.
189 GetPresentationDataFrom(nsIFrame
* aFrame
,
190 nsPresentationData
& aPresentationData
,
191 PRBool aClimbTree
= PR_TRUE
);
193 // helper used by <mstyle> and <mtable> to see if they have a displaystyle attribute
195 FindAttrDisplaystyle(nsIContent
* aContent
,
196 nsPresentationData
& aPresentationData
);
198 // helper to check if a content has an attribute. If content is nsnull or if
199 // the attribute is not there, check if the attribute is on the mstyle hierarchy
200 // @return PR_TRUE --if attribute exists
201 // PR_FALSE --if attribute doesn't exist
203 GetAttribute(nsIContent
* aContent
,
204 nsIFrame
* aMathMLmstyleFrame
,
205 nsIAtom
* aAttributeAtom
,
208 // utilities to parse and retrieve numeric values in CSS units
209 // All values are stored in twips.
211 ParseNumericValue(const nsString
& aString
,
212 nsCSSValue
& aCSSValue
) {
213 return nsMathMLElement::ParseNumericValue(aString
, aCSSValue
,
214 nsMathMLElement::PARSE_ALLOW_NEGATIVE
|
215 nsMathMLElement::PARSE_ALLOW_UNITLESS
);
219 CalcLength(nsPresContext
* aPresContext
,
220 nsStyleContext
* aStyleContext
,
221 const nsCSSValue
& aCSSValue
);
224 ParseNamedSpaceValue(nsIFrame
* aMathMLmstyleFrame
,
226 nsCSSValue
& aCSSValue
);
228 static eMathMLFrameType
229 GetMathMLFrameTypeFor(nsIFrame
* aFrame
)
231 if (aFrame
->IsFrameOfType(nsIFrame::eMathML
)) {
232 nsIMathMLFrame
* mathMLFrame
;
233 CallQueryInterface(aFrame
, &mathMLFrame
);
235 return mathMLFrame
->GetMathMLFrameType();
237 return eMathMLFrameType_UNKNOWN
;
240 // estimate of the italic correction
242 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
243 nscoord
& aItalicCorrection
)
245 aItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
246 if (0 > aItalicCorrection
) {
247 aItalicCorrection
= 0;
252 GetItalicCorrection(nsBoundingMetrics
& aBoundingMetrics
,
253 nscoord
& aLeftItalicCorrection
,
254 nscoord
& aRightItalicCorrection
)
256 aRightItalicCorrection
= aBoundingMetrics
.rightBearing
- aBoundingMetrics
.width
;
257 if (0 > aRightItalicCorrection
) {
258 aRightItalicCorrection
= 0;
260 aLeftItalicCorrection
= -aBoundingMetrics
.leftBearing
;
261 if (0 > aLeftItalicCorrection
) {
262 aLeftItalicCorrection
= 0;
266 // helper methods for getting sup/subdrop's from a child
268 GetSubDropFromChild(nsIFrame
* aChild
,
271 const nsStyleFont
* font
= aChild
->GetStyleFont();
272 nsCOMPtr
<nsIFontMetrics
> fm
= aChild
->PresContext()->GetMetricsFor(
274 GetSubDrop(fm
, aSubDrop
);
278 GetSupDropFromChild(nsIFrame
* aChild
,
281 const nsStyleFont
* font
= aChild
->GetStyleFont();
282 nsCOMPtr
<nsIFontMetrics
> fm
= aChild
->PresContext()->GetMetricsFor(
284 GetSupDrop(fm
, aSupDrop
);
288 GetSkewCorrectionFromChild(nsIFrame
* aChild
,
289 nscoord
& aSkewCorrection
)
292 // individual classes should over-ride this method if necessary
296 // 2 levels of subscript shifts
298 GetSubScriptShifts(nsIFontMetrics
* fm
,
299 nscoord
& aSubScriptShift1
,
300 nscoord
& aSubScriptShift2
)
303 fm
->GetXHeight(xHeight
);
304 aSubScriptShift1
= NSToCoordRound(150.000f
/430.556f
* xHeight
);
305 aSubScriptShift2
= NSToCoordRound(247.217f
/430.556f
* xHeight
);
308 // 3 levels of superscript shifts
310 GetSupScriptShifts(nsIFontMetrics
* fm
,
311 nscoord
& aSupScriptShift1
,
312 nscoord
& aSupScriptShift2
,
313 nscoord
& aSupScriptShift3
)
316 fm
->GetXHeight(xHeight
);
317 aSupScriptShift1
= NSToCoordRound(412.892f
/430.556f
* xHeight
);
318 aSupScriptShift2
= NSToCoordRound(362.892f
/430.556f
* xHeight
);
319 aSupScriptShift3
= NSToCoordRound(288.889f
/430.556f
* xHeight
);
322 // these are TeX specific params not found in ordinary fonts
325 GetSubDrop(nsIFontMetrics
* fm
,
329 fm
->GetXHeight(xHeight
);
330 aSubDrop
= NSToCoordRound(50.000f
/430.556f
* xHeight
);
334 GetSupDrop(nsIFontMetrics
* fm
,
338 fm
->GetXHeight(xHeight
);
339 aSupDrop
= NSToCoordRound(386.108f
/430.556f
* xHeight
);
343 GetNumeratorShifts(nsIFontMetrics
* fm
,
349 fm
->GetXHeight(xHeight
);
350 numShift1
= NSToCoordRound(676.508f
/430.556f
* xHeight
);
351 numShift2
= NSToCoordRound(393.732f
/430.556f
* xHeight
);
352 numShift3
= NSToCoordRound(443.731f
/430.556f
* xHeight
);
356 GetDenominatorShifts(nsIFontMetrics
* fm
,
361 fm
->GetXHeight(xHeight
);
362 denShift1
= NSToCoordRound(685.951f
/430.556f
* xHeight
);
363 denShift2
= NSToCoordRound(344.841f
/430.556f
* xHeight
);
367 GetEmHeight(nsIFontMetrics
* fm
,
371 // should switch to this API in order to scale with changes of TextZoom
372 fm
->GetEmHeight(emHeight
);
374 emHeight
= NSToCoordRound(float(fm
->Font().size
));
379 GetAxisHeight (nsIFontMetrics
* fm
,
382 fm
->GetXHeight (axisHeight
);
383 axisHeight
= NSToCoordRound(250.000f
/430.556f
* axisHeight
);
387 GetBigOpSpacings(nsIFontMetrics
* fm
,
388 nscoord
& bigOpSpacing1
,
389 nscoord
& bigOpSpacing2
,
390 nscoord
& bigOpSpacing3
,
391 nscoord
& bigOpSpacing4
,
392 nscoord
& bigOpSpacing5
)
395 fm
->GetXHeight(xHeight
);
396 bigOpSpacing1
= NSToCoordRound(111.111f
/430.556f
* xHeight
);
397 bigOpSpacing2
= NSToCoordRound(166.667f
/430.556f
* xHeight
);
398 bigOpSpacing3
= NSToCoordRound(200.000f
/430.556f
* xHeight
);
399 bigOpSpacing4
= NSToCoordRound(600.000f
/430.556f
* xHeight
);
400 bigOpSpacing5
= NSToCoordRound(100.000f
/430.556f
* xHeight
);
404 GetRuleThickness(nsIFontMetrics
* fm
,
405 nscoord
& ruleThickness
)
408 fm
->GetXHeight(xHeight
);
409 ruleThickness
= NSToCoordRound(40.000f
/430.556f
* xHeight
);
412 // Some parameters are not accurately obtained using the x-height.
413 // Here are some slower variants to obtain the desired metrics
414 // by actually measuring some characters
416 GetRuleThickness(nsIRenderingContext
& aRenderingContext
,
417 nsIFontMetrics
* aFontMetrics
,
418 nscoord
& aRuleThickness
);
421 GetAxisHeight(nsIRenderingContext
& aRenderingContext
,
422 nsIFontMetrics
* aFontMetrics
,
423 nscoord
& aAxisHeight
);
426 #if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
427 nsresult
DisplayBoundingMetrics(nsDisplayListBuilder
* aBuilder
,
428 nsIFrame
* aFrame
, const nsPoint
& aPt
,
429 const nsBoundingMetrics
& aMetrics
,
430 const nsDisplayListSet
& aLists
);
434 * Display a solid rectangle in the frame's text color. Used for drawing
435 * fraction separators and root/sqrt overbars.
437 nsresult
DisplayBar(nsDisplayListBuilder
* aBuilder
,
438 nsIFrame
* aFrame
, const nsRect
& aRect
,
439 const nsDisplayListSet
& aLists
);
441 // information about the presentation policy of the frame
442 nsPresentationData mPresentationData
;
444 // information about a container that is an embellished operator
445 nsEmbellishData mEmbellishData
;
447 // Metrics that _exactly_ enclose the text of the frame
448 nsBoundingMetrics mBoundingMetrics
;
450 // Reference point of the frame: mReference.y is the baseline
454 #endif /* nsMathMLFrame_h___ */