Backed out changeset b88172246b66 due to Win32 debug failures.
[mozilla-central.git] / layout / mathml / nsIMathMLFrame.h
blob597ba69e80337dcb7f0c461a02af8c08a184cea6
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 ***** */
38 //#define SHOW_BOUNDING_BOX 1
39 #ifndef nsIMathMLFrame_h___
40 #define nsIMathMLFrame_h___
42 #include "nsIRenderingContext.h"
43 #include "nsIFrame.h"
45 struct nsPresentationData;
46 struct nsEmbellishData;
47 struct nsHTMLReflowMetrics;
49 // For MathML, this 'type' will be used to determine the spacing between frames
50 // Subclasses can return a 'type' that will give them a particular spacing
51 enum eMathMLFrameType {
52 eMathMLFrameType_UNKNOWN = -1,
53 eMathMLFrameType_Ordinary,
54 eMathMLFrameType_OperatorOrdinary,
55 eMathMLFrameType_OperatorInvisible,
56 eMathMLFrameType_OperatorUserDefined,
57 eMathMLFrameType_Inner,
58 eMathMLFrameType_ItalicIdentifier,
59 eMathMLFrameType_UprightIdentifier,
60 eMathMLFrameType_COUNT
63 // Abstract base class that provides additional methods for MathML frames
64 class nsIMathMLFrame
66 public:
67 NS_DECL_QUERYFRAME_TARGET(nsIMathMLFrame)
69 /* SUPPORT FOR PRECISE POSITIONING */
70 /*====================================================================*/
72 /* Metrics that _exactly_ enclose the text of the frame.
73 * The frame *must* have *already* being reflowed, before you can call
74 * the GetBoundingMetrics() method.
75 * Note that for a frame with nested children, the bounding metrics
76 * will exactly enclose its children. For example, the bounding metrics
77 * of msub is the smallest rectangle that exactly encloses both the
78 * base and the subscript.
80 NS_IMETHOD
81 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) = 0;
83 NS_IMETHOD
84 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) = 0;
86 NS_IMETHOD
87 SetReference(const nsPoint& aReference) = 0;
89 virtual eMathMLFrameType GetMathMLFrameType() = 0;
91 /* SUPPORT FOR STRETCHY ELEMENTS */
92 /*====================================================================*/
94 /* Stretch :
95 * Called to ask a stretchy MathML frame to stretch itself depending
96 * on its context.
98 * An embellished frame is treated in a special way. When it receives a
99 * Stretch() command, it passes the command to its embellished child and
100 * the stretched size is bubbled up from the inner-most <mo> frame. In other
101 * words, the stretch command descend through the embellished hierarchy.
103 * @param aStretchDirection [in] the direction where to attempt to
104 * stretch.
105 * @param aContainerSize [in] struct that suggests the maximumn size for
106 * the stretched frame. Only member data of the struct that are
107 * relevant to the direction are used (the rest is ignored).
108 * @param aDesiredStretchSize [in/out] On input the current size
109 * of the frame, on output the size after stretching.
111 NS_IMETHOD
112 Stretch(nsIRenderingContext& aRenderingContext,
113 nsStretchDirection aStretchDirection,
114 nsBoundingMetrics& aContainerSize,
115 nsHTMLReflowMetrics& aDesiredStretchSize) = 0;
117 /* Get the mEmbellishData member variable. */
119 NS_IMETHOD
120 GetEmbellishData(nsEmbellishData& aEmbellishData) = 0;
123 /* SUPPORT FOR SCRIPTING ELEMENTS */
124 /*====================================================================*/
126 /* Get the mPresentationData member variable. */
128 NS_IMETHOD
129 GetPresentationData(nsPresentationData& aPresentationData) = 0;
131 /* InheritAutomaticData() / TransmitAutomaticData() :
132 * There are precise rules governing each MathML frame and its children.
133 * Properties such as the scriptlevel or the embellished nature of a frame
134 * depend on those rules. Also, certain properties that we use to emulate
135 * TeX rendering rules are frame-dependent too. These two methods are meant
136 * to be implemented by frame classes that need to assert specific properties
137 * within their subtrees.
139 * InheritAutomaticData() is called in a top-down manner [like nsIFrame::Init],
140 * as we descend the frame tree, whereas TransmitAutomaticData() is called in a
141 * bottom-up manner, as we ascend the tree [like nsIFrame::SetInitialChildList].
142 * However, unlike Init() and SetInitialChildList() which are called only once
143 * during the life-time of a frame (when initially constructing the frame tree),
144 * these two methods are called to build automatic data after the <math>...</math>
145 * subtree has been constructed fully, and are called again as we walk a child's
146 * subtree to handle dynamic changes that happen in the content model.
148 * As a rule of thumb:
150 * 1. Use InheritAutomaticData() to set properties related to your ancestors:
151 * - set properties that are intrinsic to yourself
152 * - set properties that depend on the state that you expect your ancestors
153 * to have already reached in their own InheritAutomaticData().
154 * - set properties that your descendants assume that you would have set in
155 * your InheritAutomaticData() -- this way, they can safely query them and
156 * the process will feed upon itself.
158 * 2. Use TransmitAutomaticData() to set properties related to your descendants:
159 * - set properties that depend on the state that you expect your descendants
160 * to have reached upon processing their own TransmitAutomaticData().
161 * - transmit properties that your descendants expect that you will transmit to
162 * them in your TransmitAutomaticData() -- this way, they remain up-to-date.
163 * - set properties that your ancestors expect that you would set in your
164 * TransmitAutomaticData() -- this way, they can safely query them and the
165 * process will feed upon itself.
168 NS_IMETHOD
169 InheritAutomaticData(nsIFrame* aParent) = 0;
171 NS_IMETHOD
172 TransmitAutomaticData() = 0;
174 /* UpdatePresentationData :
175 * Updates the frame's displaystyle and compression flags. The displaystyle
176 * flag of an environment gets updated according to the MathML specification.
177 * A frame becomes "compressed" (or "cramped") according to TeX rendering
178 * rules (TeXBook, Ch.17, p.140-141).
180 * Note that <mstyle> is the only tag which allows to set
181 * <mstyle displaystyle="true|false">
182 * Therefore <mstyle> has its own peculiar version of this method.
184 * @param aFlagsValues [in]
185 * The new values (e.g., display, compress) that are going to be
186 * updated.
188 * @param aWhichFlags [in]
189 * The flags that are relevant to this call. Since not all calls
190 * are meant to update all flags at once, aWhichFlags is used
191 * to distinguish flags that need to retain their existing values
192 * from flags that need to be turned on (or turned off). If a bit
193 * is set in aWhichFlags, then the corresponding value (which
194 * can be 0 or 1) is taken from aFlagsValues and applied to the
195 * frame. Therefore, by setting their bits in aWhichFlags, and
196 * setting their desired values in aFlagsValues, it is possible to
197 * update some flags in the frame, leaving the other flags unchanged.
199 NS_IMETHOD
200 UpdatePresentationData(PRUint32 aFlagsValues,
201 PRUint32 aWhichFlags) = 0;
203 /* UpdatePresentationDataFromChildAt :
204 * Sets displaystyle and compression flags on the whole tree. For child frames
205 * at aFirstIndex up to aLastIndex, this method sets their displaystyle and
206 * compression flags. The update is propagated down the subtrees of each of
207 * these child frames.
209 * Note that <mstyle> is the only tag which allows
210 * <mstyle displaystyle="true|false">
211 * Therefore <mstyle> has its own peculiar version of this method.
213 * @param aFirstIndex [in]
214 * Index of the first child from where the update is propagated.
216 * @param aLastIndex [in]
217 * Index of the last child where to stop the update.
218 * A value of -1 means up to last existing child.
220 * @param aFlagsValues [in]
221 * The new values (e.g., display, compress) that are going to be
222 * assigned in the whole sub-trees.
224 * @param aWhichFlags [in]
225 * The flags that are relevant to this call. See UpdatePresentationData()
226 * for more details about this parameter.
228 NS_IMETHOD
229 UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
230 PRInt32 aLastIndex,
231 PRUint32 aFlagsValues,
232 PRUint32 aWhichFlags) = 0;
235 // struct used by a container frame to keep track of its embellishments.
236 // By convention, the data that we keep here is bubbled from the embellished
237 // hierarchy, and it remains unchanged unless we have to recover from a change
238 // that occurs in the embellished hierarchy. The struct remains in its nil
239 // state in those frames that are not part of the embellished hierarchy.
240 struct nsEmbellishData {
241 // bits used to mark certain properties of our embellishments
242 PRUint32 flags;
244 // pointer on the <mo> frame at the core of the embellished hierarchy
245 nsIFrame* coreFrame;
247 // stretchy direction that the nsMathMLChar owned by the core <mo> supports
248 nsStretchDirection direction;
250 // spacing that may come from <mo> depending on its 'form'. Since
251 // the 'form' may also depend on the position of the outermost
252 // embellished ancestor, the set up of these values may require
253 // looking up the position of our ancestors.
254 nscoord leftSpace;
255 nscoord rightSpace;
257 nsEmbellishData() {
258 flags = 0;
259 coreFrame = nsnull;
260 direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
261 leftSpace = 0;
262 rightSpace = 0;
266 // struct used by a container frame to modulate its presentation.
267 // By convention, the data that we keep in this struct can change depending
268 // on any of our ancestors and/or descendants. If a data can be resolved
269 // solely from the embellished hierarchy, and it remains immutable once
270 // resolved, we put it in |nsEmbellishData|. If it can be affected by other
271 // things, it comes here. This struct is updated as we receive information
272 // transmitted by our ancestors and is kept in sync with changes in our
273 // descendants that affects us.
274 struct nsPresentationData {
275 // bits for: displaystyle, compressed, etc
276 PRUint32 flags;
278 // handy pointer on our base child (the 'nucleus' in TeX), but it may be
279 // null here (e.g., tags like <mrow>, <mfrac>, <mtable>, etc, won't
280 // pick a particular child in their child list to be the base)
281 nsIFrame* baseFrame;
283 // up-pointer on the mstyle frame, if any, that defines the scope
284 nsIFrame* mstyle;
286 nsPresentationData() {
287 flags = 0;
288 baseFrame = nsnull;
289 mstyle = nsnull;
293 // ==========================================================================
294 // Bits used for the presentation flags -- these bits are set
295 // in their relevant situation as they become available
297 // This bit is set if the frame is in the *context* of displaystyle=true.
298 // Note: This doesn't mean that the frame has displaystyle=true as attribute,
299 // the displaystyle attribute is only allowed on <mstyle> and <mtable>.
300 // The bit merely tells the context of the frame. In the context of
301 // displaystyle="false", it is intended to slightly alter how the
302 // rendering is done in inline mode.
303 #define NS_MATHML_DISPLAYSTYLE 0x00000001U
305 // This bit is used to emulate TeX rendering.
306 // Internal use only, cannot be set by the user with an attribute.
307 #define NS_MATHML_COMPRESSED 0x00000002U
309 // This bit is set if the frame will fire a vertical stretch
310 // command on all its (non-empty) children.
311 // Tags like <mrow> (or an inferred mrow), mpadded, etc, will fire a
312 // vertical stretch command on all their non-empty children
313 #define NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY 0x00000004U
315 // This bit is set if the frame will fire a horizontal stretch
316 // command on all its (non-empty) children.
317 // Tags like munder, mover, munderover, will fire a
318 // horizontal stretch command on all their non-empty children
319 #define NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY 0x00000008U
321 // This bit is set if the frame has the explicit attribute
322 // displaystyle="true" or "false". It is only relevant to <mstyle> and <mtable>
323 // because they are the only tags where the attribute is allowed by the spec.
324 #define NS_MATHML_EXPLICIT_DISPLAYSTYLE 0x00000020U
326 // This bit is set when the frame cannot be formatted due to an
327 // error (e.g., invalid markup such as a <msup> without an overscript).
328 // When set, a visual feedback will be provided to the user.
329 #define NS_MATHML_ERROR 0x80000000U
331 // a bit used for debug
332 #define NS_MATHML_STRETCH_DONE 0x20000000U
334 // This bit is used for visual debug. When set, the bounding box
335 // of your frame is painted. This visual debug enable to ensure that
336 // you have properly filled your mReference and mBoundingMetrics in
337 // Place().
338 #define NS_MATHML_SHOW_BOUNDING_METRICS 0x10000000U
340 // Macros that retrieve those bits
342 #define NS_MATHML_IS_DISPLAYSTYLE(_flags) \
343 (NS_MATHML_DISPLAYSTYLE == ((_flags) & NS_MATHML_DISPLAYSTYLE))
345 #define NS_MATHML_IS_COMPRESSED(_flags) \
346 (NS_MATHML_COMPRESSED == ((_flags) & NS_MATHML_COMPRESSED))
348 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(_flags) \
349 (NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY))
351 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(_flags) \
352 (NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY))
354 #define NS_MATHML_HAS_EXPLICIT_DISPLAYSTYLE(_flags) \
355 (NS_MATHML_EXPLICIT_DISPLAYSTYLE == ((_flags) & NS_MATHML_EXPLICIT_DISPLAYSTYLE))
357 #define NS_MATHML_HAS_ERROR(_flags) \
358 (NS_MATHML_ERROR == ((_flags) & NS_MATHML_ERROR))
360 #define NS_MATHML_STRETCH_WAS_DONE(_flags) \
361 (NS_MATHML_STRETCH_DONE == ((_flags) & NS_MATHML_STRETCH_DONE))
363 #define NS_MATHML_PAINT_BOUNDING_METRICS(_flags) \
364 (NS_MATHML_SHOW_BOUNDING_METRICS == ((_flags) & NS_MATHML_SHOW_BOUNDING_METRICS))
366 // ==========================================================================
367 // Bits used for the embellish flags -- these bits are set
368 // in their relevant situation as they become available
370 // This bit is set if the frame is an embellished operator.
371 #define NS_MATHML_EMBELLISH_OPERATOR 0x00000001
373 // This bit is set if the frame is an <mo> frame or an embellihsed
374 // operator for which the core <mo> has movablelimits="true"
375 #define NS_MATHML_EMBELLISH_MOVABLELIMITS 0x00000002
377 // This bit is set if the frame is an <mo> frame or an embellihsed
378 // operator for which the core <mo> has accent="true"
379 #define NS_MATHML_EMBELLISH_ACCENT 0x00000004
381 // This bit is set if the frame is an <mover> or <munderover> with
382 // an accent frame
383 #define NS_MATHML_EMBELLISH_ACCENTOVER 0x00000008
385 // This bit is set if the frame is an <munder> or <munderover> with
386 // an accentunder frame
387 #define NS_MATHML_EMBELLISH_ACCENTUNDER 0x00000010
389 // Macros that retrieve those bits
391 #define NS_MATHML_IS_EMBELLISH_OPERATOR(_flags) \
392 (NS_MATHML_EMBELLISH_OPERATOR == ((_flags) & NS_MATHML_EMBELLISH_OPERATOR))
394 #define NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(_flags) \
395 (NS_MATHML_EMBELLISH_MOVABLELIMITS == ((_flags) & NS_MATHML_EMBELLISH_MOVABLELIMITS))
397 #define NS_MATHML_EMBELLISH_IS_ACCENT(_flags) \
398 (NS_MATHML_EMBELLISH_ACCENT == ((_flags) & NS_MATHML_EMBELLISH_ACCENT))
400 #define NS_MATHML_EMBELLISH_IS_ACCENTOVER(_flags) \
401 (NS_MATHML_EMBELLISH_ACCENTOVER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTOVER))
403 #define NS_MATHML_EMBELLISH_IS_ACCENTUNDER(_flags) \
404 (NS_MATHML_EMBELLISH_ACCENTUNDER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTUNDER))
406 #endif /* nsIMathMLFrame_h___ */