1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 //#define SHOW_BOUNDING_BOX 1
7 #ifndef nsIMathMLFrame_h___
8 #define nsIMathMLFrame_h___
10 #include "nsQueryFrame.h"
11 #include "nsMathMLOperators.h"
13 struct nsPresentationData
;
14 struct nsEmbellishData
;
19 } // namespace mozilla
21 // For MathML, this 'type' will be used to determine the spacing between frames
22 // Subclasses can return a 'type' that will give them a particular spacing
23 enum eMathMLFrameType
{
24 eMathMLFrameType_UNKNOWN
= -1,
25 eMathMLFrameType_Ordinary
,
26 eMathMLFrameType_OperatorOrdinary
,
27 eMathMLFrameType_OperatorInvisible
,
28 eMathMLFrameType_OperatorUserDefined
,
29 eMathMLFrameType_Inner
,
30 eMathMLFrameType_ItalicIdentifier
,
31 eMathMLFrameType_UprightIdentifier
,
32 eMathMLFrameType_COUNT
35 // Abstract base class that provides additional methods for MathML frames
39 NS_DECL_QUERYFRAME_TARGET(nsIMathMLFrame
)
41 // helper to check whether the frame is "space-like", as defined by the spec.
42 virtual bool IsSpaceLike() = 0;
44 /* SUPPORT FOR PRECISE POSITIONING */
45 /*====================================================================*/
47 /* Metrics that _exactly_ enclose the text of the frame.
48 * The frame *must* have *already* being reflowed, before you can call
49 * the GetBoundingMetrics() method.
50 * Note that for a frame with nested children, the bounding metrics
51 * will exactly enclose its children. For example, the bounding metrics
52 * of msub is the smallest rectangle that exactly encloses both the
53 * base and the subscript.
56 GetBoundingMetrics(nsBoundingMetrics
& aBoundingMetrics
) = 0;
59 SetBoundingMetrics(const nsBoundingMetrics
& aBoundingMetrics
) = 0;
62 SetReference(const nsPoint
& aReference
) = 0;
64 virtual eMathMLFrameType
GetMathMLFrameType() = 0;
66 /* SUPPORT FOR STRETCHY ELEMENTS */
67 /*====================================================================*/
70 * Called to ask a stretchy MathML frame to stretch itself depending
73 * An embellished frame is treated in a special way. When it receives a
74 * Stretch() command, it passes the command to its embellished child and
75 * the stretched size is bubbled up from the inner-most <mo> frame. In other
76 * words, the stretch command descend through the embellished hierarchy.
78 * @param aStretchDirection [in] the direction where to attempt to
80 * @param aContainerSize [in] struct that suggests the maximumn size for
81 * the stretched frame. Only member data of the struct that are
82 * relevant to the direction are used (the rest is ignored).
83 * @param aDesiredStretchSize [in/out] On input the current size
84 * of the frame, on output the size after stretching.
87 Stretch(mozilla::gfx::DrawTarget
* aDrawTarget
,
88 nsStretchDirection aStretchDirection
,
89 nsBoundingMetrics
& aContainerSize
,
90 mozilla::ReflowOutput
& aDesiredStretchSize
) = 0;
92 /* Get the mEmbellishData member variable. */
95 GetEmbellishData(nsEmbellishData
& aEmbellishData
) = 0;
98 /* SUPPORT FOR SCRIPTING ELEMENTS */
99 /*====================================================================*/
101 /* Get the mPresentationData member variable. */
104 GetPresentationData(nsPresentationData
& aPresentationData
) = 0;
106 /* InheritAutomaticData() / TransmitAutomaticData() :
107 * There are precise rules governing each MathML frame and its children.
108 * Properties such as the scriptlevel or the embellished nature of a frame
109 * depend on those rules. Also, certain properties that we use to emulate
110 * TeX rendering rules are frame-dependent too. These two methods are meant
111 * to be implemented by frame classes that need to assert specific properties
112 * within their subtrees.
114 * InheritAutomaticData() is called in a top-down manner [like nsIFrame::Init],
115 * as we descend the frame tree, whereas TransmitAutomaticData() is called in a
116 * bottom-up manner, as we ascend the tree [like nsIFrame::SetInitialChildList].
117 * However, unlike Init() and SetInitialChildList() which are called only once
118 * during the life-time of a frame (when initially constructing the frame tree),
119 * these two methods are called to build automatic data after the <math>...</math>
120 * subtree has been constructed fully, and are called again as we walk a child's
121 * subtree to handle dynamic changes that happen in the content model.
123 * As a rule of thumb:
125 * 1. Use InheritAutomaticData() to set properties related to your ancestors:
126 * - set properties that are intrinsic to yourself
127 * - set properties that depend on the state that you expect your ancestors
128 * to have already reached in their own InheritAutomaticData().
129 * - set properties that your descendants assume that you would have set in
130 * your InheritAutomaticData() -- this way, they can safely query them and
131 * the process will feed upon itself.
133 * 2. Use TransmitAutomaticData() to set properties related to your descendants:
134 * - set properties that depend on the state that you expect your descendants
135 * to have reached upon processing their own TransmitAutomaticData().
136 * - transmit properties that your descendants expect that you will transmit to
137 * them in your TransmitAutomaticData() -- this way, they remain up-to-date.
138 * - set properties that your ancestors expect that you would set in your
139 * TransmitAutomaticData() -- this way, they can safely query them and the
140 * process will feed upon itself.
144 InheritAutomaticData(nsIFrame
* aParent
) = 0;
147 TransmitAutomaticData() = 0;
149 /* UpdatePresentationData:
150 * Updates the frame's compression flag.
151 * A frame becomes "compressed" (or "cramped") according to TeX rendering
152 * rules (TeXBook, Ch.17, p.140-141).
154 * @param aFlagsValues [in]
155 * The new values (e.g., compress) that are going to be
158 * @param aWhichFlags [in]
159 * The flags that are relevant to this call. Since not all calls
160 * are meant to update all flags at once, aWhichFlags is used
161 * to distinguish flags that need to retain their existing values
162 * from flags that need to be turned on (or turned off). If a bit
163 * is set in aWhichFlags, then the corresponding value (which
164 * can be 0 or 1) is taken from aFlagsValues and applied to the
165 * frame. Therefore, by setting their bits in aWhichFlags, and
166 * setting their desired values in aFlagsValues, it is possible to
167 * update some flags in the frame, leaving the other flags unchanged.
170 UpdatePresentationData(uint32_t aFlagsValues
,
171 uint32_t aWhichFlags
) = 0;
173 /* UpdatePresentationDataFromChildAt :
174 * Sets compression flag on the whole tree. For child frames
175 * at aFirstIndex up to aLastIndex, this method sets their
176 * compression flags. The update is propagated down the subtrees of each of
177 * these child frames.
179 * @param aFirstIndex [in]
180 * Index of the first child from where the update is propagated.
182 * @param aLastIndex [in]
183 * Index of the last child where to stop the update.
184 * A value of -1 means up to last existing child.
186 * @param aFlagsValues [in]
187 * The new values (e.g., compress) that are going to be
188 * assigned in the whole sub-trees.
190 * @param aWhichFlags [in]
191 * The flags that are relevant to this call. See UpdatePresentationData()
192 * for more details about this parameter.
195 UpdatePresentationDataFromChildAt(int32_t aFirstIndex
,
197 uint32_t aFlagsValues
,
198 uint32_t aWhichFlags
) = 0;
200 // If aFrame is a child frame, returns the script increment which this frame
201 // imposes on the specified frame, ignoring any artificial adjustments to
203 // Returns 0 if the specified frame isn't a child frame.
205 ScriptIncrement(nsIFrame
* aFrame
) = 0;
207 // Returns true if the frame is considered to be an mrow for layout purposes.
208 // This includes inferred mrows, but excludes <mrow> elements with a single
209 // child. In the latter case, the child is to be treated as if it wasn't
210 // within an mrow, so we pretend the mrow isn't mrow-like.
215 // struct used by a container frame to keep track of its embellishments.
216 // By convention, the data that we keep here is bubbled from the embellished
217 // hierarchy, and it remains unchanged unless we have to recover from a change
218 // that occurs in the embellished hierarchy. The struct remains in its nil
219 // state in those frames that are not part of the embellished hierarchy.
220 struct nsEmbellishData
{
221 // bits used to mark certain properties of our embellishments
224 // pointer on the <mo> frame at the core of the embellished hierarchy
227 // stretchy direction that the nsMathMLChar owned by the core <mo> supports
228 nsStretchDirection direction
;
230 // spacing that may come from <mo> depending on its 'form'. Since
231 // the 'form' may also depend on the position of the outermost
232 // embellished ancestor, the set up of these values may require
233 // looking up the position of our ancestors.
234 nscoord leadingSpace
;
235 nscoord trailingSpace
;
240 direction
= NS_STRETCH_DIRECTION_UNSUPPORTED
;
246 // struct used by a container frame to modulate its presentation.
247 // By convention, the data that we keep in this struct can change depending
248 // on any of our ancestors and/or descendants. If a data can be resolved
249 // solely from the embellished hierarchy, and it remains immutable once
250 // resolved, we put it in |nsEmbellishData|. If it can be affected by other
251 // things, it comes here. This struct is updated as we receive information
252 // transmitted by our ancestors and is kept in sync with changes in our
253 // descendants that affects us.
254 struct nsPresentationData
{
255 // bits for: compressed, etc
258 // handy pointer on our base child (the 'nucleus' in TeX), but it may be
259 // null here (e.g., tags like <mrow>, <mfrac>, <mtable>, etc, won't
260 // pick a particular child in their child list to be the base)
263 nsPresentationData() {
269 // ==========================================================================
270 // Bits used for the presentation flags -- these bits are set
271 // in their relevant situation as they become available
273 // This bit is used to emulate TeX rendering.
274 // Internal use only, cannot be set by the user with an attribute.
275 #define NS_MATHML_COMPRESSED 0x00000002U
277 // This bit is set if the frame will fire a vertical stretch
278 // command on all its (non-empty) children.
279 // Tags like <mrow> (or an inferred mrow), mpadded, etc, will fire a
280 // vertical stretch command on all their non-empty children
281 #define NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY 0x00000004U
283 // This bit is set if the frame will fire a horizontal stretch
284 // command on all its (non-empty) children.
285 // Tags like munder, mover, munderover, will fire a
286 // horizontal stretch command on all their non-empty children
287 #define NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY 0x00000008U
289 // This bit is set if the frame is "space-like", as defined by the spec.
290 #define NS_MATHML_SPACE_LIKE 0x00000040U
292 // This bit is set if a token frame should be rendered with the dtls font
294 #define NS_MATHML_DTLS 0x00000080U
296 // This bit is set when the frame cannot be formatted due to an
297 // error (e.g., invalid markup such as a <msup> without an overscript).
298 // When set, a visual feedback will be provided to the user.
299 #define NS_MATHML_ERROR 0x80000000U
301 // a bit used for debug
302 #define NS_MATHML_STRETCH_DONE 0x20000000U
304 // This bit is used for visual debug. When set, the bounding box
305 // of your frame is painted. This visual debug enable to ensure that
306 // you have properly filled your mReference and mBoundingMetrics in
308 #define NS_MATHML_SHOW_BOUNDING_METRICS 0x10000000U
310 // Macros that retrieve those bits
312 #define NS_MATHML_IS_COMPRESSED(_flags) \
313 (NS_MATHML_COMPRESSED == ((_flags) & NS_MATHML_COMPRESSED))
315 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(_flags) \
316 (NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY))
318 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(_flags) \
319 (NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY))
321 #define NS_MATHML_IS_SPACE_LIKE(_flags) \
322 (NS_MATHML_SPACE_LIKE == ((_flags) & NS_MATHML_SPACE_LIKE))
324 #define NS_MATHML_IS_DTLS_SET(_flags) \
325 (NS_MATHML_DTLS == ((_flags) & NS_MATHML_DTLS))
327 #define NS_MATHML_HAS_ERROR(_flags) \
328 (NS_MATHML_ERROR == ((_flags) & NS_MATHML_ERROR))
330 #define NS_MATHML_STRETCH_WAS_DONE(_flags) \
331 (NS_MATHML_STRETCH_DONE == ((_flags) & NS_MATHML_STRETCH_DONE))
333 #define NS_MATHML_PAINT_BOUNDING_METRICS(_flags) \
334 (NS_MATHML_SHOW_BOUNDING_METRICS == ((_flags) & NS_MATHML_SHOW_BOUNDING_METRICS))
336 // ==========================================================================
337 // Bits used for the embellish flags -- these bits are set
338 // in their relevant situation as they become available
340 // This bit is set if the frame is an embellished operator.
341 #define NS_MATHML_EMBELLISH_OPERATOR 0x00000001
343 // This bit is set if the frame is an <mo> frame or an embellihsed
344 // operator for which the core <mo> has movablelimits="true"
345 #define NS_MATHML_EMBELLISH_MOVABLELIMITS 0x00000002
347 // This bit is set if the frame is an <mo> frame or an embellihsed
348 // operator for which the core <mo> has accent="true"
349 #define NS_MATHML_EMBELLISH_ACCENT 0x00000004
351 // This bit is set if the frame is an <mover> or <munderover> with
353 #define NS_MATHML_EMBELLISH_ACCENTOVER 0x00000008
355 // This bit is set if the frame is an <munder> or <munderover> with
356 // an accentunder frame
357 #define NS_MATHML_EMBELLISH_ACCENTUNDER 0x00000010
359 // This bit is set on the core if it is a fence operator.
360 #define NS_MATHML_EMBELLISH_FENCE 0x00000020
362 // This bit is set on the core if it is a separator operator.
363 #define NS_MATHML_EMBELLISH_SEPARATOR 0x00000040
365 // Macros that retrieve those bits
367 #define NS_MATHML_IS_EMBELLISH_OPERATOR(_flags) \
368 (NS_MATHML_EMBELLISH_OPERATOR == ((_flags) & NS_MATHML_EMBELLISH_OPERATOR))
370 #define NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(_flags) \
371 (NS_MATHML_EMBELLISH_MOVABLELIMITS == ((_flags) & NS_MATHML_EMBELLISH_MOVABLELIMITS))
373 #define NS_MATHML_EMBELLISH_IS_ACCENT(_flags) \
374 (NS_MATHML_EMBELLISH_ACCENT == ((_flags) & NS_MATHML_EMBELLISH_ACCENT))
376 #define NS_MATHML_EMBELLISH_IS_ACCENTOVER(_flags) \
377 (NS_MATHML_EMBELLISH_ACCENTOVER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTOVER))
379 #define NS_MATHML_EMBELLISH_IS_ACCENTUNDER(_flags) \
380 (NS_MATHML_EMBELLISH_ACCENTUNDER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTUNDER))
382 #define NS_MATHML_EMBELLISH_IS_FENCE(_flags) \
383 (NS_MATHML_EMBELLISH_FENCE == ((_flags) & NS_MATHML_EMBELLISH_FENCE))
385 #define NS_MATHML_EMBELLISH_IS_SEPARATOR(_flags) \
386 (NS_MATHML_EMBELLISH_SEPARATOR == ((_flags) & NS_MATHML_EMBELLISH_SEPARATOR))
388 #endif /* nsIMathMLFrame_h___ */