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>
24 * Shyjan Mahamud <mahamud@cs.cmu.edu>
25 * Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef nsMathMLChar_h___
42 #define nsMathMLChar_h___
44 #include "nsMathMLOperators.h"
45 #include "nsMathMLFrame.h"
49 // Hints for Stretch() to indicate criteria for stretching
52 NS_STRETCH_NONE
= 0x00,
53 // Variable size stretches
54 NS_STRETCH_VARIABLE_MASK
= 0x0F,
55 NS_STRETCH_NORMAL
= 0x01, // try to stretch to requested size
56 NS_STRETCH_NEARER
= 0x02, // stretch very close to requested size
57 NS_STRETCH_SMALLER
= 0x04, // don't stretch more than requested size
58 NS_STRETCH_LARGER
= 0x08, // don't stretch less than requested size
59 // A largeop in displaystyle
60 NS_STRETCH_LARGEOP
= 0x10,
61 // Intended for internal use:
62 // Find the widest metrics that might be returned from a vertical stretch
63 NS_STRETCH_MAXWIDTH
= 0x20
66 // A single glyph in our internal representation is characterized by a 'code@font'
67 // pair. The 'code' is interpreted as a Unicode point or as the direct glyph index
68 // (depending on the type of nsGlyphTable where this comes from). The 'font' is a
69 // numeric identifier given to the font to which the glyph belongs.
78 PRBool
operator==(const nsGlyphCode
& other
) const
80 return other
.code
== code
&& other
.font
== font
;
82 PRBool
operator!=(const nsGlyphCode
& other
) const
84 return ! operator==(other
);
88 // Class used to handle stretchy symbols (accent, delimiter and boundary symbols).
89 // There are composite characters that need to be built recursively from other
90 // characters. Since these are rare we use a light-weight mechanism to handle
91 // them. Specifically, as need arises we append a singly-linked list of child
92 // chars with their mParent pointing to the first element in the list, except in
93 // the originating first element itself where it points to null. mSibling points
94 // to the next element in the list. Since the originating first element is the
95 // parent of the others, we call it the "root" char of the list. Testing !mParent
96 // tells whether you are that "root" during the recursion. The parent delegates
97 // most of the tasks to the children.
101 // constructor and destructor
102 nsMathMLChar(nsMathMLChar
* aParent
= nsnull
) {
103 MOZ_COUNT_CTOR(nsMathMLChar
);
104 mStyleContext
= nsnull
;
109 ~nsMathMLChar() { // not a virtual destructor: this class is not intended to be subclassed
110 MOZ_COUNT_DTOR(nsMathMLChar
);
111 // there is only one style context owned by the "root" char
112 // and it may be used by child chars as well
113 if (!mParent
&& mStyleContext
) { // only the "root" need to release it
114 mStyleContext
->Release();
122 Display(nsDisplayListBuilder
* aBuilder
,
124 const nsDisplayListSet
& aLists
,
125 const nsRect
* aSelectedRect
= nsnull
);
127 void PaintForeground(nsPresContext
* aPresContext
,
128 nsIRenderingContext
& aRenderingContext
,
132 // This is the method called to ask the char to stretch itself.
133 // @param aContainerSize - IN - suggested size for the stretched char
134 // @param aDesiredStretchSize - OUT - the size that the char wants
136 Stretch(nsPresContext
* aPresContext
,
137 nsIRenderingContext
& aRenderingContext
,
138 nsStretchDirection aStretchDirection
,
139 const nsBoundingMetrics
& aContainerSize
,
140 nsBoundingMetrics
& aDesiredStretchSize
,
141 PRUint32 aStretchHint
= NS_STRETCH_NORMAL
);
144 SetData(nsPresContext
* aPresContext
,
148 GetData(nsString
& aData
) {
154 return mData
.Length();
158 GetStretchDirection() {
162 // Sometimes we only want to pass the data to another routine,
163 // this function helps to avoid copying
170 GetRect(nsRect
& aRect
) {
175 SetRect(const nsRect
& aRect
) {
177 // shift the orgins of child chars if any
178 if (!mParent
&& mSibling
) { // only a "root" having child chars can enter here
179 for (nsMathMLChar
* child
= mSibling
; child
; child
= child
->mSibling
) {
181 child
->GetRect(rect
);
182 rect
.MoveBy(mRect
.x
, mRect
.y
);
183 child
->SetRect(rect
);
188 // Get the maximum width that the character might have after a vertical
191 // @param aStretchHint can be the value that will be passed to Stretch().
192 // It is used to determine whether the operator is stretchy or a largeop.
193 // @param aMaxSize is the value of the "maxsize" attribute.
194 // @param aMaxSizeIsAbsolute indicates whether the aMaxSize is an absolute
195 // value in app units (PR_TRUE) or a multiplier of the base size (PR_FALSE).
197 GetMaxWidth(nsPresContext
* aPresContext
,
198 nsIRenderingContext
& aRenderingContext
,
199 PRUint32 aStretchHint
= NS_STRETCH_NORMAL
,
200 float aMaxSize
= NS_MATHML_OPERATOR_SIZE_INFINITY
,
201 // Perhaps just nsOperatorFlags aFlags.
202 // But need DisplayStyle for largeOp,
203 // or remove the largeop bit from flags.
204 PRBool aMaxSizeIsAbsolute
= PR_FALSE
);
206 // Metrics that _exactly_ enclose the char. The char *must* have *already*
207 // being stretched before you can call the GetBoundingMetrics() method.
208 // IMPORTANT: since chars have their own style contexts, and may be rendered
209 // with glyphs that are not in the parent font, just calling the default
210 // aRenderingContext.GetBoundingMetrics(aChar) can give incorrect results.
212 GetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) {
213 aBoundingMetrics
= mBoundingMetrics
;
217 SetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) {
218 mBoundingMetrics
= aBoundingMetrics
;
221 // Hooks to access the extra leaf style contexts given to the MathMLChars.
222 // They provide an interface to make them accessible to the Style System via
223 // the Get/Set AdditionalStyleContext() APIs. Owners of MathMLChars
224 // should honor these APIs.
225 nsStyleContext
* GetStyleContext() const;
227 void SetStyleContext(nsStyleContext
* aStyleContext
);
230 friend class nsGlyphTable
;
233 // support for handling composite stretchy chars like TeX over/under braces
234 nsMathMLChar
* mSibling
;
235 nsMathMLChar
* mParent
;
240 nsStretchDirection mDirection
;
241 nsBoundingMetrics mBoundingMetrics
;
242 nsStyleContext
* mStyleContext
;
243 nsGlyphTable
* mGlyphTable
;
245 // mFamily is non-empty when the family for the current size is different
246 // from the family in the nsStyleContext.
249 class StretchEnumContext
;
250 friend class StretchEnumContext
;
254 StretchInternal(nsPresContext
* aPresContext
,
255 nsIRenderingContext
& aRenderingContext
,
256 nsStretchDirection
& aStretchDirection
,
257 const nsBoundingMetrics
& aContainerSize
,
258 nsBoundingMetrics
& aDesiredStretchSize
,
259 PRUint32 aStretchHint
,
260 float aMaxSize
= NS_MATHML_OPERATOR_SIZE_INFINITY
,
261 PRBool aMaxSizeIsAbsolute
= PR_FALSE
);
264 ComposeChildren(nsPresContext
* aPresContext
,
265 nsIRenderingContext
& aRenderingContext
,
266 nsGlyphTable
* aGlyphTable
,
268 nsBoundingMetrics
& aCompositeSize
,
269 PRUint32 aStretchHint
);
272 PaintVertically(nsPresContext
* aPresContext
,
273 nsIRenderingContext
& aRenderingContext
,
275 nsStyleContext
* aStyleContext
,
276 nsGlyphTable
* aGlyphTable
,
280 PaintHorizontally(nsPresContext
* aPresContext
,
281 nsIRenderingContext
& aRenderingContext
,
283 nsStyleContext
* aStyleContext
,
284 nsGlyphTable
* aGlyphTable
,
288 #endif /* nsMathMLChar_h___ */