Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / mathml / base / src / nsMathMLFrame.h
blob5d4bfd1dbb001438f6c4e6c34db403897cbd0c8c
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
13 * License.
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.
22 * Contributor(s):
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___
42 #include "nsCOMPtr.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"
50 #include "nsFrame.h"
51 #include "nsCSSValue.h"
52 #include "nsMathMLElement.h"
54 class nsMathMLChar;
56 // Concrete base class with default methods that derived MathML frames can override
57 class nsMathMLFrame : public nsIMathMLFrame {
58 public:
60 // nsISupports ------
62 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
64 NS_IMETHOD_(nsrefcnt) AddRef() {
65 // not meaningfull for frames
66 return 1;
69 NS_IMETHOD_(nsrefcnt) Release() {
70 // not meaningfull for frames
71 return 1;
74 // nsIMathMLFrame ---
76 NS_IMETHOD
77 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) {
78 aBoundingMetrics = mBoundingMetrics;
79 return NS_OK;
82 NS_IMETHOD
83 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) {
84 mBoundingMetrics = aBoundingMetrics;
85 return NS_OK;
88 NS_IMETHOD
89 GetReference(nsPoint& aReference) {
90 aReference = mReference;
91 return NS_OK;
94 NS_IMETHOD
95 SetReference(const nsPoint& aReference) {
96 mReference = aReference;
97 return NS_OK;
100 virtual eMathMLFrameType GetMathMLFrameType();
102 NS_IMETHOD
103 Stretch(nsIRenderingContext& aRenderingContext,
104 nsStretchDirection aStretchDirection,
105 nsBoundingMetrics& aContainerSize,
106 nsHTMLReflowMetrics& aDesiredStretchSize)
108 return NS_OK;
111 NS_IMETHOD
112 GetEmbellishData(nsEmbellishData& aEmbellishData) {
113 aEmbellishData = mEmbellishData;
114 return NS_OK;
117 NS_IMETHOD
118 SetEmbellishData(const nsEmbellishData& aEmbellishData) {
119 mEmbellishData = aEmbellishData;
120 return NS_OK;
123 NS_IMETHOD
124 GetPresentationData(nsPresentationData& aPresentationData) {
125 aPresentationData = mPresentationData;
126 return NS_OK;
129 NS_IMETHOD
130 SetPresentationData(const nsPresentationData& aPresentationData) {
131 mPresentationData = aPresentationData;
132 return NS_OK;
135 NS_IMETHOD
136 InheritAutomaticData(nsIFrame* aParent);
138 NS_IMETHOD
139 TransmitAutomaticData()
141 return NS_OK;
144 NS_IMETHOD
145 UpdatePresentationData(PRUint32 aFlagsValues,
146 PRUint32 aFlagsToUpdate);
148 NS_IMETHOD
149 UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
150 PRInt32 aLastIndex,
151 PRUint32 aFlagsValues,
152 PRUint32 aFlagsToUpdate)
154 return NS_OK;
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.
160 static void
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
175 // operator;
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.
180 static void
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.
188 static void
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
194 static void
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
202 static PRBool
203 GetAttribute(nsIContent* aContent,
204 nsIFrame* aMathMLmstyleFrame,
205 nsIAtom* aAttributeAtom,
206 nsString& aValue);
208 // utilities to parse and retrieve numeric values in CSS units
209 // All values are stored in twips.
210 static PRBool
211 ParseNumericValue(const nsString& aString,
212 nsCSSValue& aCSSValue) {
213 return nsMathMLElement::ParseNumericValue(aString, aCSSValue,
214 nsMathMLElement::PARSE_ALLOW_NEGATIVE |
215 nsMathMLElement::PARSE_ALLOW_UNITLESS);
218 static nscoord
219 CalcLength(nsPresContext* aPresContext,
220 nsStyleContext* aStyleContext,
221 const nsCSSValue& aCSSValue);
223 static PRBool
224 ParseNamedSpaceValue(nsIFrame* aMathMLmstyleFrame,
225 nsString& aString,
226 nsCSSValue& aCSSValue);
228 static eMathMLFrameType
229 GetMathMLFrameTypeFor(nsIFrame* aFrame)
231 if (aFrame->IsFrameOfType(nsIFrame::eMathML)) {
232 nsIMathMLFrame* mathMLFrame;
233 CallQueryInterface(aFrame, &mathMLFrame);
234 if (mathMLFrame)
235 return mathMLFrame->GetMathMLFrameType();
237 return eMathMLFrameType_UNKNOWN;
240 // estimate of the italic correction
241 static void
242 GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics,
243 nscoord& aItalicCorrection)
245 aItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width;
246 if (0 > aItalicCorrection) {
247 aItalicCorrection = 0;
251 static void
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
267 static void
268 GetSubDropFromChild(nsIFrame* aChild,
269 nscoord& aSubDrop)
271 const nsStyleFont* font = aChild->GetStyleFont();
272 nsCOMPtr<nsIFontMetrics> fm = aChild->PresContext()->GetMetricsFor(
273 font->mFont);
274 GetSubDrop(fm, aSubDrop);
277 static void
278 GetSupDropFromChild(nsIFrame* aChild,
279 nscoord& aSupDrop)
281 const nsStyleFont* font = aChild->GetStyleFont();
282 nsCOMPtr<nsIFontMetrics> fm = aChild->PresContext()->GetMetricsFor(
283 font->mFont);
284 GetSupDrop(fm, aSupDrop);
287 static void
288 GetSkewCorrectionFromChild(nsIFrame* aChild,
289 nscoord& aSkewCorrection)
291 // default is 0
292 // individual classes should over-ride this method if necessary
293 aSkewCorrection = 0;
296 // 2 levels of subscript shifts
297 static void
298 GetSubScriptShifts(nsIFontMetrics* fm,
299 nscoord& aSubScriptShift1,
300 nscoord& aSubScriptShift2)
302 nscoord xHeight;
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
309 static void
310 GetSupScriptShifts(nsIFontMetrics* fm,
311 nscoord& aSupScriptShift1,
312 nscoord& aSupScriptShift2,
313 nscoord& aSupScriptShift3)
315 nscoord xHeight;
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
324 static void
325 GetSubDrop(nsIFontMetrics* fm,
326 nscoord& aSubDrop)
328 nscoord xHeight;
329 fm->GetXHeight(xHeight);
330 aSubDrop = NSToCoordRound(50.000f/430.556f * xHeight);
333 static void
334 GetSupDrop(nsIFontMetrics* fm,
335 nscoord& aSupDrop)
337 nscoord xHeight;
338 fm->GetXHeight(xHeight);
339 aSupDrop = NSToCoordRound(386.108f/430.556f * xHeight);
342 static void
343 GetNumeratorShifts(nsIFontMetrics* fm,
344 nscoord& numShift1,
345 nscoord& numShift2,
346 nscoord& numShift3)
348 nscoord xHeight;
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);
355 static void
356 GetDenominatorShifts(nsIFontMetrics* fm,
357 nscoord& denShift1,
358 nscoord& denShift2)
360 nscoord xHeight;
361 fm->GetXHeight(xHeight);
362 denShift1 = NSToCoordRound(685.951f/430.556f * xHeight);
363 denShift2 = NSToCoordRound(344.841f/430.556f * xHeight);
366 static void
367 GetEmHeight(nsIFontMetrics* fm,
368 nscoord& emHeight)
370 #if 0
371 // should switch to this API in order to scale with changes of TextZoom
372 fm->GetEmHeight(emHeight);
373 #else
374 emHeight = NSToCoordRound(float(fm->Font().size));
375 #endif
378 static void
379 GetAxisHeight (nsIFontMetrics* fm,
380 nscoord& axisHeight)
382 fm->GetXHeight (axisHeight);
383 axisHeight = NSToCoordRound(250.000f/430.556f * axisHeight);
386 static void
387 GetBigOpSpacings(nsIFontMetrics* fm,
388 nscoord& bigOpSpacing1,
389 nscoord& bigOpSpacing2,
390 nscoord& bigOpSpacing3,
391 nscoord& bigOpSpacing4,
392 nscoord& bigOpSpacing5)
394 nscoord xHeight;
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);
403 static void
404 GetRuleThickness(nsIFontMetrics* fm,
405 nscoord& ruleThickness)
407 nscoord xHeight;
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
415 static void
416 GetRuleThickness(nsIRenderingContext& aRenderingContext,
417 nsIFontMetrics* aFontMetrics,
418 nscoord& aRuleThickness);
420 static void
421 GetAxisHeight(nsIRenderingContext& aRenderingContext,
422 nsIFontMetrics* aFontMetrics,
423 nscoord& aAxisHeight);
425 protected:
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);
431 #endif
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
451 nsPoint mReference;
454 #endif /* nsMathMLFrame_h___ */