1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

/* * Mode: C++; tabwidth: 2; indenttabsmode: nil; cbasicoffset: 2 * */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla MathML Project.
*
* The Initial Developer of the Original Code is
* The University Of Queensland.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//#define SHOW_BOUNDING_BOX 1
#ifndef nsIMathMLFrame_h___
#define nsIMathMLFrame_h___
#include "nsIRenderingContext.h"
#include "nsIFrame.h"
struct nsPresentationData;
struct nsEmbellishData;
struct nsHTMLReflowMetrics;
// For MathML, this 'type' will be used to determine the spacing between frames
// Subclasses can return a 'type' that will give them a particular spacing
enum eMathMLFrameType {
eMathMLFrameType_UNKNOWN = 1,
eMathMLFrameType_Ordinary,
eMathMLFrameType_OperatorOrdinary,
eMathMLFrameType_OperatorInvisible,
eMathMLFrameType_OperatorUserDefined,
eMathMLFrameType_Inner,
eMathMLFrameType_ItalicIdentifier,
eMathMLFrameType_UprightIdentifier,
eMathMLFrameType_COUNT
};
// Abstract base class that provides additional methods for MathML frames
class nsIMathMLFrame
{
public:
NS_DECL_QUERYFRAME_TARGET(nsIMathMLFrame)
/* SUPPORT FOR PRECISE POSITIONING */
/*====================================================================*/
/* Metrics that _exactly_ enclose the text of the frame.
* The frame *must* have *already* being reflowed, before you can call
* the GetBoundingMetrics() method.
* Note that for a frame with nested children, the bounding metrics
* will exactly enclose its children. For example, the bounding metrics
* of msub is the smallest rectangle that exactly encloses both the
* base and the subscript.
*/
NS_IMETHOD
GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) = 0;
NS_IMETHOD
SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) = 0;
NS_IMETHOD
GetReference(nsPoint& aReference) = 0;
NS_IMETHOD
SetReference(const nsPoint& aReference) = 0;
virtual eMathMLFrameType GetMathMLFrameType() = 0;
/* SUPPORT FOR STRETCHY ELEMENTS */
/*====================================================================*/
/* Stretch :
* Called to ask a stretchy MathML frame to stretch itself depending
* on its context.
*
* An embellished frame is treated in a special way. When it receives a
* Stretch() command, it passes the command to its embellished child and
* the stretched size is bubbled up from the innermost <mo> frame. In other
* words, the stretch command descend through the embellished hierarchy.
*
* @param aStretchDirection [in] the direction where to attempt to
* stretch.
* @param aContainerSize [in] struct that suggests the maximumn size for
* the stretched frame. Only member data of the struct that are
* relevant to the direction are used (the rest is ignored).
* @param aDesiredStretchSize [in/out] On input the current size
* of the frame, on output the size after stretching.
*/
NS_IMETHOD
Stretch(nsIRenderingContext& aRenderingContext,
nsStretchDirection aStretchDirection,
nsBoundingMetrics& aContainerSize,
nsHTMLReflowMetrics& aDesiredStretchSize) = 0;
/* GetEmbellishData/SetEmbellishData :
* Get/Set the mEmbellishData member variable.
*/
NS_IMETHOD
GetEmbellishData(nsEmbellishData& aEmbellishData) = 0;
NS_IMETHOD
SetEmbellishData(const nsEmbellishData& aEmbellishData) = 0;
/* SUPPORT FOR SCRIPTING ELEMENTS */
/*====================================================================*/
/* GetPresentationData/SetPresentationData :
* Get/Set the mPresentationData member variable.
*/
NS_IMETHOD
GetPresentationData(nsPresentationData& aPresentationData) = 0;
NS_IMETHOD
SetPresentationData(const nsPresentationData& aPresentationData) = 0;
/* InheritAutomaticData() / TransmitAutomaticData() :
* There are precise rules governing each MathML frame and its children.
* Properties such as the scriptlevel or the embellished nature of a frame
* depend on those rules. Also, certain properties that we use to emulate
* TeX rendering rules are framedependent too. These two methods are meant
* to be implemented by frame classes that need to assert specific properties
* within their subtrees.
*
* InheritAutomaticData() is called in a topdown manner [like nsIFrame::Init],
* as we descend the frame tree, whereas TransmitAutomaticData() is called in a
* bottomup manner, as we ascend the tree [like nsIFrame::SetInitialChildList].
* However, unlike Init() and SetInitialChildList() which are called only once
* during the lifetime of a frame (when initially constructing the frame tree),
* these two methods are called to build automatic data after the <math>...</math>
* subtree has been constructed fully, and are called again as we walk a child's
* subtree to handle dynamic changes that happen in the content model.
*
* As a rule of thumb:
*
* 1. Use InheritAutomaticData() to set properties related to your ancestors:
*  set properties that are intrinsic to yourself
*  set properties that depend on the state that you expect your ancestors
* to have already reached in their own InheritAutomaticData().
*  set properties that your descendants assume that you would have set in
* your InheritAutomaticData()  this way, they can safely query them and
* the process will feed upon itself.
*
* 2. Use TransmitAutomaticData() to set properties related to your descendants:
*  set properties that depend on the state that you expect your descendants
* to have reached upon processing their own TransmitAutomaticData().
*  transmit properties that your descendants expect that you will transmit to
* them in your TransmitAutomaticData()  this way, they remain uptodate.
*  set properties that your ancestors expect that you would set in your
* TransmitAutomaticData()  this way, they can safely query them and the
* process will feed upon itself.
*/
NS_IMETHOD
InheritAutomaticData(nsIFrame* aParent) = 0;
NS_IMETHOD
TransmitAutomaticData() = 0;
/* UpdatePresentationData :
* Updates the frame's displaystyle and compression flags. The displaystyle
* flag of an environment gets updated according to the MathML specification.
* A frame becomes "compressed" (or "cramped") according to TeX rendering
* rules (TeXBook, Ch.17, p.140141).
*
* Note that <mstyle> is the only tag which allows to set
* <mstyle displaystyle="truefalse">
* Therefore <mstyle> has its own peculiar version of this method.
*
* @param aFlagsValues [in]
* The new values (e.g., display, compress) that are going to be
* updated.
*
* @param aWhichFlags [in]
* The flags that are relevant to this call. Since not all calls
* are meant to update all flags at once, aWhichFlags is used
* to distinguish flags that need to retain their existing values
* from flags that need to be turned on (or turned off). If a bit
* is set in aWhichFlags, then the corresponding value (which
* can be 0 or 1) is taken from aFlagsValues and applied to the
* frame. Therefore, by setting their bits in aWhichFlags, and
* setting their desired values in aFlagsValues, it is possible to
* update some flags in the frame, leaving the other flags unchanged.
*/
NS_IMETHOD
UpdatePresentationData(PRUint32 aFlagsValues,
PRUint32 aWhichFlags) = 0;
/* UpdatePresentationDataFromChildAt :
* Sets displaystyle and compression flags on the whole tree. For child frames
* at aFirstIndex up to aLastIndex, this method sets their displaystyle and
* compression flags. The update is propagated down the subtrees of each of
* these child frames.
*
* Note that <mstyle> is the only tag which allows
* <mstyle displaystyle="truefalse">
* Therefore <mstyle> has its own peculiar version of this method.
*
* @param aFirstIndex [in]
* Index of the first child from where the update is propagated.
*
* @param aLastIndex [in]
* Index of the last child where to stop the update.
* A value of 1 means up to last existing child.
*
* @param aFlagsValues [in]
* The new values (e.g., display, compress) that are going to be
* assigned in the whole subtrees.
*
* @param aWhichFlags [in]
* The flags that are relevant to this call. See UpdatePresentationData()
* for more details about this parameter.
*/
NS_IMETHOD
UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
PRInt32 aLastIndex,
PRUint32 aFlagsValues,
PRUint32 aWhichFlags) = 0;
};
// struct used by a container frame to keep track of its embellishments.
// By convention, the data that we keep here is bubbled from the embellished
// hierarchy, and it remains unchanged unless we have to recover from a change
// that occurs in the embellished hierarchy. The struct remains in its nil
// state in those frames that are not part of the embellished hierarchy.
struct nsEmbellishData {
// bits used to mark certain properties of our embellishments
PRUint32 flags;
// pointer on the <mo> frame at the core of the embellished hierarchy
nsIFrame* coreFrame;
// stretchy direction that the nsMathMLChar owned by the core <mo> supports
nsStretchDirection direction;
// spacing that may come from <mo> depending on its 'form'. Since
// the 'form' may also depend on the position of the outermost
// embellished ancestor, the set up of these values may require
// looking up the position of our ancestors.
nscoord leftSpace;
nscoord rightSpace;
nsEmbellishData() {
flags = 0;
coreFrame = nsnull;
direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
leftSpace = 0;
rightSpace = 0;
}
};
// struct used by a container frame to modulate its presentation.
// By convention, the data that we keep in this struct can change depending
// on any of our ancestors and/or descendants. If a data can be resolved
// solely from the embellished hierarchy, and it remains immutable once
// resolved, we put it in nsEmbellishData. If it can be affected by other
// things, it comes here. This struct is updated as we receive information
// transmitted by our ancestors and is kept in sync with changes in our
// descendants that affects us.
struct nsPresentationData {
// bits for: displaystyle, compressed, etc
PRUint32 flags;
// handy pointer on our base child (the 'nucleus' in TeX), but it may be
// null here (e.g., tags like <mrow>, <mfrac>, <mtable>, etc, won't
// pick a particular child in their child list to be the base)
nsIFrame* baseFrame;
// uppointer on the mstyle frame, if any, that defines the scope
nsIFrame* mstyle;
nsPresentationData() {
flags = 0;
baseFrame = nsnull;
mstyle = nsnull;
}
};
// ==========================================================================
// Bits used for the presentation flags  these bits are set
// in their relevant situation as they become available
// This bit is set if the frame is in the *context* of displaystyle=true.
// Note: This doesn't mean that the frame has displaystyle=true as attribute,
// the displaystyle attribute is only allowed on <mstyle> and <mtable>.
// The bit merely tells the context of the frame. In the context of
// displaystyle="false", it is intended to slightly alter how the
// rendering is done in inline mode.
#define NS_MATHML_DISPLAYSTYLE 0x00000001U
// This bit is used to emulate TeX rendering.
// Internal use only, cannot be set by the user with an attribute.
#define NS_MATHML_COMPRESSED 0x00000002U
// This bit is set if the frame will fire a vertical stretch
// command on all its (nonempty) children.
// Tags like <mrow> (or an inferred mrow), mpadded, etc, will fire a
// vertical stretch command on all their nonempty children
#define NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY 0x00000004U
// This bit is set if the frame will fire a horizontal stretch
// command on all its (nonempty) children.
// Tags like munder, mover, munderover, will fire a
// horizontal stretch command on all their nonempty children
#define NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY 0x00000008U
// This bit is set if the frame has the explicit attribute
// displaystyle="true" or "false". It is only relevant to <mstyle> and <mtable>
// because they are the only tags where the attribute is allowed by the spec.
#define NS_MATHML_EXPLICIT_DISPLAYSTYLE 0x00000020U
// This bit is set when the frame cannot be formatted due to an
// error (e.g., invalid markup such as a <msup> without an overscript).
// When set, a visual feedback will be provided to the user.
#define NS_MATHML_ERROR 0x80000000U
// a bit used for debug
#define NS_MATHML_STRETCH_DONE 0x20000000U
// This bit is used for visual debug. When set, the bounding box
// of your frame is painted. This visual debug enable to ensure that
// you have properly filled your mReference and mBoundingMetrics in
// Place().
#define NS_MATHML_SHOW_BOUNDING_METRICS 0x10000000U
// Macros that retrieve those bits
#define NS_MATHML_IS_DISPLAYSTYLE(_flags) \
(NS_MATHML_DISPLAYSTYLE == ((_flags) & NS_MATHML_DISPLAYSTYLE))
#define NS_MATHML_IS_COMPRESSED(_flags) \
(NS_MATHML_COMPRESSED == ((_flags) & NS_MATHML_COMPRESSED))
#define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(_flags) \
(NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY))
#define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(_flags) \
(NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY))
#define NS_MATHML_HAS_EXPLICIT_DISPLAYSTYLE(_flags) \
(NS_MATHML_EXPLICIT_DISPLAYSTYLE == ((_flags) & NS_MATHML_EXPLICIT_DISPLAYSTYLE))
#define NS_MATHML_HAS_ERROR(_flags) \
(NS_MATHML_ERROR == ((_flags) & NS_MATHML_ERROR))
#define NS_MATHML_STRETCH_WAS_DONE(_flags) \
(NS_MATHML_STRETCH_DONE == ((_flags) & NS_MATHML_STRETCH_DONE))
#define NS_MATHML_PAINT_BOUNDING_METRICS(_flags) \
(NS_MATHML_SHOW_BOUNDING_METRICS == ((_flags) & NS_MATHML_SHOW_BOUNDING_METRICS))
// ==========================================================================
// Bits used for the embellish flags  these bits are set
// in their relevant situation as they become available
// This bit is set if the frame is an embellished operator.
#define NS_MATHML_EMBELLISH_OPERATOR 0x00000001
// This bit is set if the frame is an <mo> frame or an embellihsed
// operator for which the core <mo> has movablelimits="true"
#define NS_MATHML_EMBELLISH_MOVABLELIMITS 0x00000002
// This bit is set if the frame is an <mo> frame or an embellihsed
// operator for which the core <mo> has accent="true"
#define NS_MATHML_EMBELLISH_ACCENT 0x00000004
// This bit is set if the frame is an <mover> or <munderover> with
// an accent frame
#define NS_MATHML_EMBELLISH_ACCENTOVER 0x00000008
// This bit is set if the frame is an <munder> or <munderover> with
// an accentunder frame
#define NS_MATHML_EMBELLISH_ACCENTUNDER 0x00000010
// Macros that retrieve those bits
#define NS_MATHML_IS_EMBELLISH_OPERATOR(_flags) \
(NS_MATHML_EMBELLISH_OPERATOR == ((_flags) & NS_MATHML_EMBELLISH_OPERATOR))
#define NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(_flags) \
(NS_MATHML_EMBELLISH_MOVABLELIMITS == ((_flags) & NS_MATHML_EMBELLISH_MOVABLELIMITS))
#define NS_MATHML_EMBELLISH_IS_ACCENT(_flags) \
(NS_MATHML_EMBELLISH_ACCENT == ((_flags) & NS_MATHML_EMBELLISH_ACCENT))
#define NS_MATHML_EMBELLISH_IS_ACCENTOVER(_flags) \
(NS_MATHML_EMBELLISH_ACCENTOVER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTOVER))
#define NS_MATHML_EMBELLISH_IS_ACCENTUNDER(_flags) \
(NS_MATHML_EMBELLISH_ACCENTUNDER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTUNDER))
#endif /* nsIMathMLFrame_h___ */
