Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / layout / mathml / nsIMathMLFrame.h
blobf27ef806e9d3f8053e992a0d43546e2a0157c978
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;
15 class gfxContext;
16 class nsIFrame;
17 namespace mozilla {
18 class ReflowOutput;
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
36 class nsIMathMLFrame {
37 public:
38 NS_DECL_QUERYFRAME_TARGET(nsIMathMLFrame)
40 // helper to check whether the frame is "space-like", as defined by the spec.
41 virtual bool IsSpaceLike() = 0;
43 /* SUPPORT FOR PRECISE POSITIONING */
44 /*====================================================================*/
46 /* Metrics that _exactly_ enclose the text of the frame.
47 * The frame *must* have *already* being reflowed, before you can call
48 * the GetBoundingMetrics() method.
49 * Note that for a frame with nested children, the bounding metrics
50 * will exactly enclose its children. For example, the bounding metrics
51 * of msub is the smallest rectangle that exactly encloses both the
52 * base and the subscript.
54 NS_IMETHOD
55 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) = 0;
57 NS_IMETHOD
58 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) = 0;
60 NS_IMETHOD
61 SetReference(const nsPoint& aReference) = 0;
63 virtual eMathMLFrameType GetMathMLFrameType() = 0;
65 /* SUPPORT FOR STRETCHY ELEMENTS */
66 /*====================================================================*/
68 /* Stretch :
69 * Called to ask a stretchy MathML frame to stretch itself depending
70 * on its context.
72 * An embellished frame is treated in a special way. When it receives a
73 * Stretch() command, it passes the command to its embellished child and
74 * the stretched size is bubbled up from the inner-most <mo> frame. In other
75 * words, the stretch command descend through the embellished hierarchy.
77 * @param aStretchDirection [in] the direction where to attempt to
78 * stretch.
79 * @param aContainerSize [in] struct that suggests the maximumn size for
80 * the stretched frame. Only member data of the struct that are
81 * relevant to the direction are used (the rest is ignored).
82 * @param aDesiredStretchSize [in/out] On input the current size
83 * of the frame, on output the size after stretching.
85 NS_IMETHOD
86 Stretch(mozilla::gfx::DrawTarget* aDrawTarget,
87 nsStretchDirection aStretchDirection,
88 nsBoundingMetrics& aContainerSize,
89 mozilla::ReflowOutput& aDesiredStretchSize) = 0;
91 /* Get the mEmbellishData member variable. */
93 NS_IMETHOD
94 GetEmbellishData(nsEmbellishData& aEmbellishData) = 0;
96 /* SUPPORT FOR SCRIPTING ELEMENTS */
97 /*====================================================================*/
99 /* Get the mPresentationData member variable. */
101 NS_IMETHOD
102 GetPresentationData(nsPresentationData& aPresentationData) = 0;
104 /* InheritAutomaticData() / TransmitAutomaticData() :
105 * There are precise rules governing each MathML frame and its children.
106 * Properties such as the scriptlevel or the embellished nature of a frame
107 * depend on those rules. Also, certain properties that we use to emulate
108 * TeX rendering rules are frame-dependent too. These two methods are meant
109 * to be implemented by frame classes that need to assert specific properties
110 * within their subtrees.
112 * InheritAutomaticData() is called in a top-down manner [like
113 * nsIFrame::Init], as we descend the frame tree, whereas
114 * TransmitAutomaticData() is called in a bottom-up manner, as we ascend the
115 * tree [like nsIFrame::SetInitialChildList]. However, unlike Init() and
116 * SetInitialChildList() which are called only once during the life-time of a
117 * frame (when initially constructing the frame tree), these two methods are
118 * called to build automatic data after the <math>...</math> subtree has been
119 * constructed fully, and are called again as we walk a child's subtree to
120 * handle dynamic changes that happen in the content model.
122 * As a rule of thumb:
124 * 1. Use InheritAutomaticData() to set properties related to your ancestors:
125 * - set properties that are intrinsic to yourself
126 * - set properties that depend on the state that you expect your ancestors
127 * to have already reached in their own InheritAutomaticData().
128 * - set properties that your descendants assume that you would have set in
129 * your InheritAutomaticData() -- this way, they can safely query them
130 * and the process will feed upon itself.
132 * 2. Use TransmitAutomaticData() to set properties related to your
133 * descendants:
134 * - set properties that depend on the state that you expect your
135 * descendants to have reached upon processing their own
136 * TransmitAutomaticData().
137 * - transmit properties that your descendants expect that you will
138 * transmit to them in your TransmitAutomaticData() -- this way, they
139 * remain up-to-date.
140 * - set properties that your ancestors expect that you would set in your
141 * TransmitAutomaticData() -- this way, they can safely query them and
142 * the process will feed upon itself.
145 NS_IMETHOD
146 InheritAutomaticData(nsIFrame* aParent) = 0;
148 NS_IMETHOD
149 TransmitAutomaticData() = 0;
151 /* UpdatePresentationData:
152 * Updates the frame's compression flag.
153 * A frame becomes "compressed" (or "cramped") according to TeX rendering
154 * rules (TeXBook, Ch.17, p.140-141).
156 * @param aFlagsValues [in]
157 * The new values (e.g., compress) that are going to be
158 * updated.
160 * @param aWhichFlags [in]
161 * The flags that are relevant to this call. Since not all calls
162 * are meant to update all flags at once, aWhichFlags is used
163 * to distinguish flags that need to retain their existing values
164 * from flags that need to be turned on (or turned off). If a bit
165 * is set in aWhichFlags, then the corresponding value (which
166 * can be 0 or 1) is taken from aFlagsValues and applied to the
167 * frame. Therefore, by setting their bits in aWhichFlags, and
168 * setting their desired values in aFlagsValues, it is possible to
169 * update some flags in the frame, leaving the other flags unchanged.
171 NS_IMETHOD
172 UpdatePresentationData(uint32_t aFlagsValues, uint32_t aWhichFlags) = 0;
174 /* UpdatePresentationDataFromChildAt :
175 * Sets compression flag on the whole tree. For child frames
176 * at aFirstIndex up to aLastIndex, this method sets their
177 * compression flags. The update is propagated down the subtrees of each of
178 * these child frames.
180 * @param aFirstIndex [in]
181 * Index of the first child from where the update is propagated.
183 * @param aLastIndex [in]
184 * Index of the last child where to stop the update.
185 * A value of -1 means up to last existing child.
187 * @param aFlagsValues [in]
188 * The new values (e.g., compress) that are going to be
189 * assigned in the whole sub-trees.
191 * @param aWhichFlags [in]
192 * The flags that are relevant to this call. See
193 * UpdatePresentationData() for more details about this parameter.
195 NS_IMETHOD
196 UpdatePresentationDataFromChildAt(int32_t aFirstIndex, int32_t aLastIndex,
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
202 // scriptlevel.
203 // Returns 0 if the specified frame isn't a child frame.
204 virtual uint8_t ScriptIncrement(nsIFrame* aFrame) = 0;
206 // Returns true if the frame is considered to be an mrow for layout purposes.
207 // This includes inferred mrows, but excludes <mrow> elements with a single
208 // child. In the latter case, the child is to be treated as if it wasn't
209 // within an mrow, so we pretend the mrow isn't mrow-like.
210 virtual bool IsMrowLike() = 0;
213 // struct used by a container frame to keep track of its embellishments.
214 // By convention, the data that we keep here is bubbled from the embellished
215 // hierarchy, and it remains unchanged unless we have to recover from a change
216 // that occurs in the embellished hierarchy. The struct remains in its nil
217 // state in those frames that are not part of the embellished hierarchy.
218 struct nsEmbellishData {
219 // bits used to mark certain properties of our embellishments
220 uint32_t flags;
222 // pointer on the <mo> frame at the core of the embellished hierarchy
223 nsIFrame* coreFrame;
225 // stretchy direction that the nsMathMLChar owned by the core <mo> supports
226 nsStretchDirection direction;
228 // spacing that may come from <mo> depending on its 'form'. Since
229 // the 'form' may also depend on the position of the outermost
230 // embellished ancestor, the set up of these values may require
231 // looking up the position of our ancestors.
232 nscoord leadingSpace;
233 nscoord trailingSpace;
235 nsEmbellishData() {
236 flags = 0;
237 coreFrame = nullptr;
238 direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
239 leadingSpace = 0;
240 trailingSpace = 0;
244 // struct used by a container frame to modulate its presentation.
245 // By convention, the data that we keep in this struct can change depending
246 // on any of our ancestors and/or descendants. If a data can be resolved
247 // solely from the embellished hierarchy, and it remains immutable once
248 // resolved, we put it in |nsEmbellishData|. If it can be affected by other
249 // things, it comes here. This struct is updated as we receive information
250 // transmitted by our ancestors and is kept in sync with changes in our
251 // descendants that affects us.
252 struct nsPresentationData {
253 // bits for: compressed, etc
254 uint32_t flags;
256 // handy pointer on our base child (the 'nucleus' in TeX), but it may be
257 // null here (e.g., tags like <mrow>, <mfrac>, <mtable>, etc, won't
258 // pick a particular child in their child list to be the base)
259 nsIFrame* baseFrame;
261 nsPresentationData() {
262 flags = 0;
263 baseFrame = nullptr;
267 // ==========================================================================
268 // Bits used for the presentation flags -- these bits are set
269 // in their relevant situation as they become available
271 // This bit is used to emulate TeX rendering.
272 // Internal use only, cannot be set by the user with an attribute.
273 #define NS_MATHML_COMPRESSED 0x00000002U
275 // This bit is set if the frame will fire a vertical stretch
276 // command on all its (non-empty) children.
277 // Tags like <mrow> (or an inferred mrow), mpadded, etc, will fire a
278 // vertical stretch command on all their non-empty children
279 #define NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY 0x00000004U
281 // This bit is set if the frame will fire a horizontal stretch
282 // command on all its (non-empty) children.
283 // Tags like munder, mover, munderover, will fire a
284 // horizontal stretch command on all their non-empty children
285 #define NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY 0x00000008U
287 // This bit is set if the frame is "space-like", as defined by the spec.
288 #define NS_MATHML_SPACE_LIKE 0x00000040U
290 // This bit is set if a token frame should be rendered with the dtls font
291 // feature setting.
292 #define NS_MATHML_DTLS 0x00000080U
294 // This bit is set when the frame cannot be formatted due to an
295 // error (e.g., invalid markup such as a <msup> without an overscript).
296 // When set, a visual feedback will be provided to the user.
297 #define NS_MATHML_ERROR 0x80000000U
299 // a bit used for debug
300 #define NS_MATHML_STRETCH_DONE 0x20000000U
302 // This bit is used for visual debug. When set, the bounding box
303 // of your frame is painted. This visual debug enable to ensure that
304 // you have properly filled your mReference and mBoundingMetrics in
305 // Place().
306 #define NS_MATHML_SHOW_BOUNDING_METRICS 0x10000000U
308 // Macros that retrieve those bits
310 #define NS_MATHML_IS_COMPRESSED(_flags) \
311 (NS_MATHML_COMPRESSED == ((_flags) & NS_MATHML_COMPRESSED))
313 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(_flags) \
314 (NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY == \
315 ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY))
317 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(_flags) \
318 (NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY == \
319 ((_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 == \
335 ((_flags) & NS_MATHML_SHOW_BOUNDING_METRICS))
337 // ==========================================================================
338 // Bits used for the embellish flags -- these bits are set
339 // in their relevant situation as they become available
341 // This bit is set if the frame is an embellished operator.
342 #define NS_MATHML_EMBELLISH_OPERATOR 0x00000001
344 // This bit is set if the frame is an <mo> frame or an embellihsed
345 // operator for which the core <mo> has movablelimits="true"
346 #define NS_MATHML_EMBELLISH_MOVABLELIMITS 0x00000002
348 // This bit is set if the frame is an <mo> frame or an embellihsed
349 // operator for which the core <mo> has accent="true"
350 #define NS_MATHML_EMBELLISH_ACCENT 0x00000004
352 // This bit is set if the frame is an <mover> or <munderover> with
353 // an accent frame
354 #define NS_MATHML_EMBELLISH_ACCENTOVER 0x00000008
356 // This bit is set if the frame is an <munder> or <munderover> with
357 // an accentunder frame
358 #define NS_MATHML_EMBELLISH_ACCENTUNDER 0x00000010
360 // This bit is set on the core if it is a fence operator.
361 #define NS_MATHML_EMBELLISH_FENCE 0x00000020
363 // This bit is set on the core if it is a separator operator.
364 #define NS_MATHML_EMBELLISH_SEPARATOR 0x00000040
366 // Macros that retrieve those bits
368 #define NS_MATHML_IS_EMBELLISH_OPERATOR(_flags) \
369 (NS_MATHML_EMBELLISH_OPERATOR == ((_flags) & NS_MATHML_EMBELLISH_OPERATOR))
371 #define NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(_flags) \
372 (NS_MATHML_EMBELLISH_MOVABLELIMITS == \
373 ((_flags) & NS_MATHML_EMBELLISH_MOVABLELIMITS))
375 #define NS_MATHML_EMBELLISH_IS_ACCENT(_flags) \
376 (NS_MATHML_EMBELLISH_ACCENT == ((_flags) & NS_MATHML_EMBELLISH_ACCENT))
378 #define NS_MATHML_EMBELLISH_IS_ACCENTOVER(_flags) \
379 (NS_MATHML_EMBELLISH_ACCENTOVER == \
380 ((_flags) & NS_MATHML_EMBELLISH_ACCENTOVER))
382 #define NS_MATHML_EMBELLISH_IS_ACCENTUNDER(_flags) \
383 (NS_MATHML_EMBELLISH_ACCENTUNDER == \
384 ((_flags) & NS_MATHML_EMBELLISH_ACCENTUNDER))
386 #define NS_MATHML_EMBELLISH_IS_FENCE(_flags) \
387 (NS_MATHML_EMBELLISH_FENCE == ((_flags) & NS_MATHML_EMBELLISH_FENCE))
389 #define NS_MATHML_EMBELLISH_IS_SEPARATOR(_flags) \
390 (NS_MATHML_EMBELLISH_SEPARATOR == ((_flags) & NS_MATHML_EMBELLISH_SEPARATOR))
392 #endif /* nsIMathMLFrame_h___ */