bug 523370 - fixing bogus OOM with empty double free lists. r=dmandelin
[mozilla-central.git] / layout / mathml / nsMathMLOperators.h
blob18072ffc7ea58630e80a1dcd6c9f12eae02f7645
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>
24 * Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsMathMLOperators_h___
41 #define nsMathMLOperators_h___
43 #include "nsCoord.h"
45 enum nsStretchDirection {
46 NS_STRETCH_DIRECTION_UNSUPPORTED = -1,
47 NS_STRETCH_DIRECTION_DEFAULT = 0,
48 NS_STRETCH_DIRECTION_HORIZONTAL = 1,
49 NS_STRETCH_DIRECTION_VERTICAL = 2
52 typedef PRUint32 nsOperatorFlags;
53 enum {
54 // define the bits used to handle the operator
55 NS_MATHML_OPERATOR_MUTABLE = 1<<30,
56 NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR = 1<<29,
57 NS_MATHML_OPERATOR_EMBELLISH_ISOLATED = 1<<28,
58 NS_MATHML_OPERATOR_CENTERED = 1<<27,
59 NS_MATHML_OPERATOR_INVISIBLE = 1<<26,
61 // define the bits used in the Operator Dictionary
63 // the very last two bits tell us the form
64 NS_MATHML_OPERATOR_FORM = 0x3,
65 NS_MATHML_OPERATOR_FORM_INFIX = 1,
66 NS_MATHML_OPERATOR_FORM_PREFIX = 2,
67 NS_MATHML_OPERATOR_FORM_POSTFIX = 3,
68 // the next 2 bits tell us the stretchiness
69 NS_MATHML_OPERATOR_STRETCHY = 0xC,
70 NS_MATHML_OPERATOR_STRETCHY_VERT = 1<<2,
71 NS_MATHML_OPERATOR_STRETCHY_HORIZ = 1<<3,
72 // other bits used in the Operator Dictionary
73 NS_MATHML_OPERATOR_FENCE = 1<<4,
74 NS_MATHML_OPERATOR_ACCENT = 1<<5,
75 NS_MATHML_OPERATOR_LARGEOP = 1<<6,
76 NS_MATHML_OPERATOR_SEPARATOR = 1<<7,
77 NS_MATHML_OPERATOR_MOVABLELIMITS = 1<<8,
78 NS_MATHML_OPERATOR_SYMMETRIC = 1<<9,
80 // Additional bits not stored in the dictionary
81 NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE = 1<<10,
82 NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE = 1<<11,
83 NS_MATHML_OPERATOR_LEFTSPACE_ATTR = 1<<12,
84 NS_MATHML_OPERATOR_RIGHTSPACE_ATTR = 1<<13
87 #define NS_MATHML_OPERATOR_SIZE_INFINITY NS_IEEEPositiveInfinity()
89 // Style invariant chararacters (chars have their own intrinsic predefined style)
90 enum eMATHVARIANT {
91 eMATHVARIANT_NONE = -1,
92 eMATHVARIANT_normal = 0,
93 eMATHVARIANT_bold,
94 eMATHVARIANT_italic,
95 eMATHVARIANT_bold_italic,
96 eMATHVARIANT_sans_serif,
97 eMATHVARIANT_bold_sans_serif,
98 eMATHVARIANT_sans_serif_italic,
99 eMATHVARIANT_sans_serif_bold_italic,
100 eMATHVARIANT_monospace,
101 eMATHVARIANT_script,
102 eMATHVARIANT_bold_script,
103 eMATHVARIANT_fraktur,
104 eMATHVARIANT_bold_fraktur,
105 eMATHVARIANT_double_struck,
106 eMATHVARIANT_COUNT
109 class nsMathMLOperators {
110 public:
111 static void AddRefTable(void);
112 static void ReleaseTable(void);
113 static void CleanUp();
115 // LookupOperator:
116 // Given the string value of an operator and its form (last two bits of flags),
117 // this method returns true if the operator is found in the Operator Dictionary.
118 // Attributes of the operator are returned in the output parameters.
119 // If the operator is not found under the supplied form but is found under a
120 // different form, the method returns true as well. The caller can test the
121 // output parameter aFlags to know exactly under which form the operator was
122 // found in the Operator Dictionary.
123 static PRBool
124 LookupOperator(const nsString& aOperator,
125 const nsOperatorFlags aForm,
126 nsOperatorFlags* aFlags,
127 float* aLeftSpace,
128 float* aRightSpace);
130 // LookupOperators:
131 // Helper to return all the forms under which an operator is listed in the
132 // Operator Dictionary. The caller must pass arrays of size 4, and use
133 // aFlags[NS_MATHML_OPERATOR_FORM_{INFIX|POSTFIX|PREFIX}], aLeftSpace[], etc,
134 // to access the attributes of the operator under a particular form. If the
135 // operator wasn't found under a form, its entry aFlags[form] is set to zero.
136 static void
137 LookupOperators(const nsString& aOperator,
138 nsOperatorFlags* aFlags,
139 float* aLeftSpace,
140 float* aRightSpace);
142 // IsMutableOperator:
143 // Return true if the operator exists and is stretchy or largeop
144 static PRBool
145 IsMutableOperator(const nsString& aOperator);
147 // Helper functions for stretchy operators. These are used by the
148 // nsMathMLChar class.
149 static PRInt32 CountStretchyOperator();
150 static PRInt32 FindStretchyOperator(PRUnichar aOperator);
151 static nsStretchDirection GetStretchyDirectionAt(PRInt32 aIndex);
152 static void DisableStretchyOperatorAt(PRInt32 aIndex);
154 // Return the variant type of one Unicode Mathematical Alphanumeric Symbol
155 // character (which may be represented by a surrogate pair), or return
156 // eMATHVARIANT_NONE if aChar is not such a character.
157 static eMATHVARIANT LookupInvariantChar(const nsAString& aChar);
159 // Return the styled Mathematical Alphanumeric Symbol character
160 // corresponding to a BMP character and a mathvariant value, or return aChar
161 // if there is no such corresponding character.
162 // Note the result may be dependent on aChar, and should be considered a
163 // temporary.
164 static const nsDependentSubstring
165 TransformVariantChar(const PRUnichar& aChar, eMATHVARIANT aVariant);
169 ////////////////////////////////////////////////////////////////////////////
170 // Macros that retrieve the bits used to handle operators
172 #define NS_MATHML_OPERATOR_IS_MUTABLE(_flags) \
173 (NS_MATHML_OPERATOR_MUTABLE == ((_flags) & NS_MATHML_OPERATOR_MUTABLE))
175 #define NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(_flags) \
176 (NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR))
178 #define NS_MATHML_OPERATOR_EMBELLISH_IS_ISOLATED(_flags) \
179 (NS_MATHML_OPERATOR_EMBELLISH_ISOLATED == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ISOLATED))
181 #define NS_MATHML_OPERATOR_IS_CENTERED(_flags) \
182 (NS_MATHML_OPERATOR_CENTERED == ((_flags) & NS_MATHML_OPERATOR_CENTERED))
184 #define NS_MATHML_OPERATOR_IS_INVISIBLE(_flags) \
185 (NS_MATHML_OPERATOR_INVISIBLE == ((_flags) & NS_MATHML_OPERATOR_INVISIBLE))
187 #define NS_MATHML_OPERATOR_GET_FORM(_flags) \
188 ((_flags) & NS_MATHML_OPERATOR_FORM)
190 #define NS_MATHML_OPERATOR_GET_STRETCHY_DIR(_flags) \
191 ((_flags) & NS_MATHML_OPERATOR_STRETCHY)
193 #define NS_MATHML_OPERATOR_FORM_IS_INFIX(_flags) \
194 (NS_MATHML_OPERATOR_FORM_INFIX == ((_flags) & NS_MATHML_OPERATOR_FORM_INFIX))
196 #define NS_MATHML_OPERATOR_FORM_IS_PREFIX(_flags) \
197 (NS_MATHML_OPERATOR_FORM_PREFIX == ((_flags) & NS_MATHML_OPERATOR_FORM_PREFIX))
199 #define NS_MATHML_OPERATOR_FORM_IS_POSTFIX(_flags) \
200 (NS_MATHML_OPERATOR_FORM_POSTFIX == ((_flags) & NS_MATHML_OPERATOR_FORM_POSTFIX ))
202 #define NS_MATHML_OPERATOR_IS_STRETCHY(_flags) \
203 (0 != ((_flags) & NS_MATHML_OPERATOR_STRETCHY))
205 #define NS_MATHML_OPERATOR_IS_STRETCHY_VERT(_flags) \
206 (NS_MATHML_OPERATOR_STRETCHY_VERT == ((_flags) & NS_MATHML_OPERATOR_STRETCHY_VERT))
208 #define NS_MATHML_OPERATOR_IS_STRETCHY_HORIZ(_flags) \
209 (NS_MATHML_OPERATOR_STRETCHY_HORIZ == ((_flags) & NS_MATHML_OPERATOR_STRETCHY_HORIZ))
211 #define NS_MATHML_OPERATOR_IS_FENCE(_flags) \
212 (NS_MATHML_OPERATOR_FENCE == ((_flags) & NS_MATHML_OPERATOR_FENCE))
214 #define NS_MATHML_OPERATOR_IS_ACCENT(_flags) \
215 (NS_MATHML_OPERATOR_ACCENT == ((_flags) & NS_MATHML_OPERATOR_ACCENT))
217 #define NS_MATHML_OPERATOR_IS_LARGEOP(_flags) \
218 (NS_MATHML_OPERATOR_LARGEOP == ((_flags) & NS_MATHML_OPERATOR_LARGEOP))
220 #define NS_MATHML_OPERATOR_IS_SEPARATOR(_flags) \
221 (NS_MATHML_OPERATOR_SEPARATOR == ((_flags) & NS_MATHML_OPERATOR_SEPARATOR))
223 #define NS_MATHML_OPERATOR_IS_MOVABLELIMITS(_flags) \
224 (NS_MATHML_OPERATOR_MOVABLELIMITS == ((_flags) & NS_MATHML_OPERATOR_MOVABLELIMITS))
226 #define NS_MATHML_OPERATOR_IS_SYMMETRIC(_flags) \
227 (NS_MATHML_OPERATOR_SYMMETRIC == ((_flags) & NS_MATHML_OPERATOR_SYMMETRIC))
229 #define NS_MATHML_OPERATOR_MINSIZE_IS_ABSOLUTE(_flags) \
230 (NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE == ((_flags) & NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE))
232 #define NS_MATHML_OPERATOR_MAXSIZE_IS_ABSOLUTE(_flags) \
233 (NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE == ((_flags) & NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE))
235 #define NS_MATHML_OPERATOR_HAS_LEFTSPACE_ATTR(_flags) \
236 (NS_MATHML_OPERATOR_LEFTSPACE_ATTR == ((_flags) & NS_MATHML_OPERATOR_LEFTSPACE_ATTR))
238 #define NS_MATHML_OPERATOR_HAS_RIGHTSPACE_ATTR(_flags) \
239 (NS_MATHML_OPERATOR_RIGHTSPACE_ATTR == ((_flags) & NS_MATHML_OPERATOR_RIGHTSPACE_ATTR))
241 #endif /* nsMathMLOperators_h___ */