Bumping manifests a=b2g-bump
[gecko.git] / layout / mathml / nsMathMLFrame.h
blobe2f15ef4f0dc8e6e94bf9758211d02c124064e64
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"
15 #include "nsIFrame.h"
17 class nsMathMLChar;
18 class nsCSSValue;
19 class nsDisplayListSet;
21 // Concrete base class with default methods that derived MathML frames can override
22 class nsMathMLFrame : public nsIMathMLFrame {
23 public:
25 // nsIMathMLFrame ---
27 virtual bool
28 IsSpaceLike() MOZ_OVERRIDE {
29 return NS_MATHML_IS_SPACE_LIKE(mPresentationData.flags);
32 NS_IMETHOD
33 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE {
34 aBoundingMetrics = mBoundingMetrics;
35 return NS_OK;
38 NS_IMETHOD
39 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE {
40 mBoundingMetrics = aBoundingMetrics;
41 return NS_OK;
44 NS_IMETHOD
45 SetReference(const nsPoint& aReference) MOZ_OVERRIDE {
46 mReference = aReference;
47 return NS_OK;
50 virtual eMathMLFrameType GetMathMLFrameType() MOZ_OVERRIDE;
52 NS_IMETHOD
53 Stretch(nsRenderingContext& aRenderingContext,
54 nsStretchDirection aStretchDirection,
55 nsBoundingMetrics& aContainerSize,
56 nsHTMLReflowMetrics& aDesiredStretchSize) MOZ_OVERRIDE
58 return NS_OK;
61 NS_IMETHOD
62 GetEmbellishData(nsEmbellishData& aEmbellishData) MOZ_OVERRIDE {
63 aEmbellishData = mEmbellishData;
64 return NS_OK;
67 NS_IMETHOD
68 GetPresentationData(nsPresentationData& aPresentationData) MOZ_OVERRIDE {
69 aPresentationData = mPresentationData;
70 return NS_OK;
73 NS_IMETHOD
74 InheritAutomaticData(nsIFrame* aParent) MOZ_OVERRIDE;
76 NS_IMETHOD
77 TransmitAutomaticData() MOZ_OVERRIDE
79 return NS_OK;
82 NS_IMETHOD
83 UpdatePresentationData(uint32_t aFlagsValues,
84 uint32_t aFlagsToUpdate) MOZ_OVERRIDE;
86 NS_IMETHOD
87 UpdatePresentationDataFromChildAt(int32_t aFirstIndex,
88 int32_t aLastIndex,
89 uint32_t aFlagsValues,
90 uint32_t aFlagsToUpdate) MOZ_OVERRIDE
92 return NS_OK;
95 uint8_t
96 ScriptIncrement(nsIFrame* aFrame) MOZ_OVERRIDE
98 return 0;
101 bool
102 IsMrowLike() MOZ_OVERRIDE
104 return false;
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);
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);
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);
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 float aFontSizeInflation);
153 static nscoord
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);
164 if (mathMLFrame)
165 return mathMLFrame->GetMathMLFrameType();
167 return eMathMLFrameType_UNKNOWN;
170 // estimate of the italic correction
171 static void
172 GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics,
173 nscoord& aItalicCorrection)
175 aItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width;
176 if (0 > aItalicCorrection) {
177 aItalicCorrection = 0;
181 static void
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
197 static void
198 GetSubDropFromChild(nsIFrame* aChild,
199 nscoord& aSubDrop,
200 float aFontSizeInflation)
202 nsRefPtr<nsFontMetrics> fm;
203 nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm),
204 aFontSizeInflation);
205 GetSubDrop(fm, aSubDrop);
208 static void
209 GetSupDropFromChild(nsIFrame* aChild,
210 nscoord& aSupDrop,
211 float aFontSizeInflation)
213 nsRefPtr<nsFontMetrics> fm;
214 nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm),
215 aFontSizeInflation);
216 GetSupDrop(fm, aSupDrop);
219 static void
220 GetSkewCorrectionFromChild(nsIFrame* aChild,
221 nscoord& aSkewCorrection)
223 // default is 0
224 // individual classes should over-ride this method if necessary
225 aSkewCorrection = 0;
228 // 2 levels of subscript shifts
229 static void
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
240 static void
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
254 static void
255 GetSubDrop(nsFontMetrics* fm,
256 nscoord& aSubDrop)
258 nscoord xHeight = fm->XHeight();
259 aSubDrop = NSToCoordRound(50.000f/430.556f * xHeight);
262 static void
263 GetSupDrop(nsFontMetrics* fm,
264 nscoord& aSupDrop)
266 nscoord xHeight = fm->XHeight();
267 aSupDrop = NSToCoordRound(386.108f/430.556f * xHeight);
270 static void
271 GetNumeratorShifts(nsFontMetrics* fm,
272 nscoord& numShift1,
273 nscoord& numShift2,
274 nscoord& numShift3)
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);
282 static void
283 GetDenominatorShifts(nsFontMetrics* fm,
284 nscoord& denShift1,
285 nscoord& denShift2)
287 nscoord xHeight = fm->XHeight();
288 denShift1 = NSToCoordRound(685.951f/430.556f * xHeight);
289 denShift2 = NSToCoordRound(344.841f/430.556f * xHeight);
292 static void
293 GetEmHeight(nsFontMetrics* fm,
294 nscoord& emHeight)
296 #if 0
297 // should switch to this API in order to scale with changes of TextZoom
298 emHeight = fm->EmHeight();
299 #else
300 emHeight = NSToCoordRound(float(fm->Font().size));
301 #endif
304 static void
305 GetAxisHeight (nsFontMetrics* fm,
306 nscoord& axisHeight)
308 axisHeight = NSToCoordRound(250.000f/430.556f * fm->XHeight());
311 static void
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);
327 static void
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
338 static void
339 GetRuleThickness(nsRenderingContext& aRenderingContext,
340 nsFontMetrics* aFontMetrics,
341 nscoord& aRuleThickness);
343 static void
344 GetAxisHeight(nsRenderingContext& aRenderingContext,
345 nsFontMetrics* aFontMetrics,
346 nscoord& aAxisHeight);
348 static void
349 GetRadicalParameters(nsFontMetrics* aFontMetrics,
350 bool aDisplayStyle,
351 nscoord& aRadicalRuleThickness,
352 nscoord& aRadicalExtraAscender,
353 nscoord& aRadicalVerticalGap);
355 protected:
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);
361 #endif
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
381 nsPoint mReference;
384 #endif /* nsMathMLFrame_h___ */