Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / mathml / base / src / nsMathMLContainerFrame.h
blob84ac240e4c09580c5991fd12f3e6c9d223981ee9
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 * David J. Fiddes <D.J.Fiddes@hw.ac.uk>
25 * Shyjan Mahamud <mahamud@cs.cmu.edu> (added TeX rendering rules)
26 * Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef nsMathMLContainerFrame_h___
43 #define nsMathMLContainerFrame_h___
45 #include "nsCOMPtr.h"
46 #include "nsHTMLContainerFrame.h"
47 #include "nsBlockFrame.h"
48 #include "nsInlineFrame.h"
49 #include "nsMathMLAtoms.h"
50 #include "nsMathMLOperators.h"
51 #include "nsMathMLChar.h"
52 #include "nsMathMLFrame.h"
53 #include "nsMathMLParts.h"
56 * Base class for MathML container frames. It acts like an inferred
57 * mrow. By default, this frame uses its Reflow() method to lay its
58 * children horizontally and ensure that their baselines are aligned.
59 * The Reflow() method relies upon Place() to position children.
60 * By overloading Place() in derived classes, it is therefore possible
61 * to position children in various customized ways.
64 // Options for the preferred size at which to stretch our stretchy children
65 #define STRETCH_CONSIDER_ACTUAL_SIZE 0x00000001 // just use our current size
66 #define STRETCH_CONSIDER_EMBELLISHMENTS 0x00000002 // size calculations include embellishments
68 class nsMathMLContainerFrame : public nsHTMLContainerFrame,
69 public nsMathMLFrame {
70 friend class nsMathMLmfencedFrame;
71 public:
72 nsMathMLContainerFrame(nsStyleContext* aContext) : nsHTMLContainerFrame(aContext) {}
74 NS_DECL_ISUPPORTS_INHERITED
76 // --------------------------------------------------------------------------
77 // Overloaded nsMathMLFrame methods -- see documentation in nsIMathMLFrame.h
79 NS_IMETHOD
80 Stretch(nsIRenderingContext& aRenderingContext,
81 nsStretchDirection aStretchDirection,
82 nsBoundingMetrics& aContainerSize,
83 nsHTMLReflowMetrics& aDesiredStretchSize);
85 NS_IMETHOD
86 UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
87 PRInt32 aLastIndex,
88 PRUint32 aFlagsValues,
89 PRUint32 aFlagsToUpdate)
91 PropagatePresentationDataFromChildAt(this, aFirstIndex, aLastIndex,
92 aFlagsValues, aFlagsToUpdate);
93 return NS_OK;
96 // helper to set the "increment script level" flag on the element belonging
97 // to a child frame given by aChildIndex.
98 // When this flag is set, the style system will increment the scriptlevel
99 // for the child element. This is needed for situations where the style system
100 // cannot itself determine the scriptlevel (mfrac, munder, mover, munderover).
101 // This should be called during reflow. We set the flag and if it changed,
102 // we request appropriate restyling and also queue a post-reflow callback
103 // to ensure that restyle and reflow happens immediately after the current
104 // reflow.
105 void
106 SetIncrementScriptLevel(PRInt32 aChildIndex, PRBool aIncrement);
108 // --------------------------------------------------------------------------
109 // Overloaded nsHTMLContainerFrame methods -- see documentation in nsIFrame.h
111 virtual PRBool IsFrameOfType(PRUint32 aFlags) const
113 return !(aFlags & nsIFrame::eLineParticipant) &&
114 nsHTMLContainerFrame::IsFrameOfType(aFlags &
115 ~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace));
118 virtual PRIntn GetSkipSides() const { return 0; }
120 NS_IMETHOD
121 AppendFrames(nsIAtom* aListName,
122 nsIFrame* aFrameList);
124 NS_IMETHOD
125 InsertFrames(nsIAtom* aListName,
126 nsIFrame* aPrevFrame,
127 nsIFrame* aFrameList);
129 NS_IMETHOD
130 RemoveFrame(nsIAtom* aListName,
131 nsIFrame* aOldFrame);
134 * Both GetMinWidth and GetPrefWidth return whatever
135 * GetIntrinsicWidth returns.
137 virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
138 virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
141 * Return the intrinsic width of the frame's content area.
143 virtual nscoord GetIntrinsicWidth(nsIRenderingContext *aRenderingContext);
145 NS_IMETHOD
146 Reflow(nsPresContext* aPresContext,
147 nsHTMLReflowMetrics& aDesiredSize,
148 const nsHTMLReflowState& aReflowState,
149 nsReflowStatus& aStatus);
151 NS_IMETHOD
152 WillReflow(nsPresContext* aPresContext)
154 mPresentationData.flags &= ~NS_MATHML_ERROR;
155 return nsHTMLContainerFrame::WillReflow(aPresContext);
158 NS_IMETHOD
159 DidReflow(nsPresContext* aPresContext,
160 const nsHTMLReflowState* aReflowState,
161 nsDidReflowStatus aStatus)
164 mPresentationData.flags &= ~NS_MATHML_STRETCH_DONE;
165 return nsHTMLContainerFrame::DidReflow(aPresContext, aReflowState, aStatus);
168 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
169 const nsRect& aDirtyRect,
170 const nsDisplayListSet& aLists);
172 // Notification when an attribute is changed. The MathML module uses the
173 // following paradigm:
175 // 1. If the MathML frame class doesn't have any cached automatic data that
176 // depends on the attribute: we just reflow (e.g., this happens with <msub>,
177 // <msup>, <mmultiscripts>, etc). This is the default behavior implemented
178 // by this base class.
180 // 2. If the MathML frame class has cached automatic data that depends on
181 // the attribute:
182 // 2a. If the automatic data to update resides only within the descendants,
183 // we just re-layout them using ReLayoutChildren(this);
184 // (e.g., this happens with <ms>).
185 // 2b. If the automatic data to update affects us in some way, we ask our parent
186 // to re-layout its children using ReLayoutChildren(mParent);
187 // Therefore, there is an overhead here in that our siblings are re-laid
188 // too (e.g., this happens with <mstyle>, <munder>, <mover>, <munderover>).
189 NS_IMETHOD
190 AttributeChanged(PRInt32 aNameSpaceID,
191 nsIAtom* aAttribute,
192 PRInt32 aModType);
194 // --------------------------------------------------------------------------
195 // Additional methods
197 protected:
198 /* Place :
199 * This method is used to measure or position child frames and other
200 * elements. It may be called any number of times with aPlaceOrigin
201 * false to measure, and the final call of the Reflow process before
202 * returning from Reflow() or Stretch() will have aPlaceOrigin true
203 * to position the elements.
205 * IMPORTANT: This method uses GetReflowAndBoundingMetricsFor() which must
206 * have been set up with SaveReflowAndBoundingMetricsFor().
208 * The Place() method will use this information to compute the desired size
209 * of the frame.
211 * @param aPlaceOrigin [in]
212 * If aPlaceOrigin is false, compute your desired size using the
213 * information from GetReflowAndBoundingMetricsFor. However, child
214 * frames or other elements should not be repositioned.
216 * If aPlaceOrigin is true, reflow is finished. You should position
217 * all your children, and return your desired size. You should now
218 * use FinishReflowChild() on your children to complete post-reflow
219 * operations.
221 * @param aDesiredSize [out] parameter where you should return your desired
222 * size and your ascent/descent info. Compute your desired size using
223 * the information from GetReflowAndBoundingMetricsFor, and include
224 * any space you want for border/padding in the desired size you
225 * return.
227 virtual nsresult
228 Place(nsIRenderingContext& aRenderingContext,
229 PRBool aPlaceOrigin,
230 nsHTMLReflowMetrics& aDesiredSize);
232 // MeasureChildFrames:
234 // A method used by nsMathMLContainerFrame::GetIntrinsicWidth to get the
235 // width that a particular Place method desires. For most frames, this will
236 // just call the object's Place method. However <msqrt> uses
237 // nsMathMLContainerFrame::GetIntrinsicWidth to measure the child frames as
238 // if in an <mrow>, and so <msqrt> frames implement MeasureChildFrames to
239 // use nsMathMLContainerFrame::Place.
240 virtual nsresult
241 MeasureChildFrames(nsIRenderingContext& aRenderingContext,
242 nsHTMLReflowMetrics& aDesiredSize);
245 // helper to re-sync the automatic data in our children and notify our parent to
246 // reflow us when changes (e.g., append/insert/remove) happen in our child list
247 virtual nsresult
248 ChildListChanged(PRInt32 aModType);
250 // helper to get the preferred size that a container frame should use to fire
251 // the stretch on its stretchy child frames.
252 void
253 GetPreferredStretchSize(nsIRenderingContext& aRenderingContext,
254 PRUint32 aOptions,
255 nsStretchDirection aStretchDirection,
256 nsBoundingMetrics& aPreferredStretchSize);
258 public:
259 // error handlers to provide a visual feedback to the user when an error
260 // (typically invalid markup) was encountered during reflow.
261 nsresult
262 ReflowError(nsIRenderingContext& aRenderingContext,
263 nsHTMLReflowMetrics& aDesiredSize);
265 // helper method to reflow a child frame. We are inline frames, and we don't
266 // know our positions until reflow is finished. That's why we ask the
267 // base method not to worry about our position.
268 nsresult
269 ReflowChild(nsIFrame* aKidFrame,
270 nsPresContext* aPresContext,
271 nsHTMLReflowMetrics& aDesiredSize,
272 const nsHTMLReflowState& aReflowState,
273 nsReflowStatus& aStatus);
275 protected:
276 // helper to add the inter-spacing when <math> is the immediate parent.
277 // Since we don't (yet) handle the root <math> element ourselves, we need to
278 // take special care of the inter-frame spacing on elements for which <math>
279 // is the direct xml parent. This function will be repeatedly called from
280 // left to right on the childframes of <math>, and by so doing it will
281 // emulate the spacing that would have been done by a <mrow> container.
282 // e.g., it fixes <math> <mi>f</mi> <mo>q</mo> <mi>f</mi> <mo>I</mo> </math>
283 virtual nscoord
284 FixInterFrameSpacing(nsHTMLReflowMetrics& aDesiredSize);
286 // helper method to complete the post-reflow hook and ensure that embellished
287 // operators don't terminate their Reflow without receiving a Stretch command.
288 virtual nsresult
289 FinalizeReflow(nsIRenderingContext& aRenderingContext,
290 nsHTMLReflowMetrics& aDesiredSize);
292 // Record metrics of a child frame for recovery through the following method
293 static void
294 SaveReflowAndBoundingMetricsFor(nsIFrame* aFrame,
295 const nsHTMLReflowMetrics& aReflowMetrics,
296 const nsBoundingMetrics& aBoundingMetrics);
298 // helper method to facilitate getting the reflow and bounding metrics of a
299 // child frame. The argument aMathMLFrameType, when non null, will return
300 // the 'type' of the frame, which is used to determine the inter-frame
301 // spacing.
302 // IMPORTANT: This function is only meant to be called in Place() methods as
303 // the information is available only when set up with the above method
304 // during Reflow/Stretch() and GetPrefWidth().
305 static void
306 GetReflowAndBoundingMetricsFor(nsIFrame* aFrame,
307 nsHTMLReflowMetrics& aReflowMetrics,
308 nsBoundingMetrics& aBoundingMetrics,
309 eMathMLFrameType* aMathMLFrameType = nsnull);
311 // helper method to clear metrics saved with
312 // SaveReflowAndBoundingMetricsFor() from all child frames.
313 void ClearSavedChildMetrics();
315 // helper to let the update of presentation data pass through
316 // a subtree that may contain non-MathML container frames
317 static void
318 PropagatePresentationDataFor(nsIFrame* aFrame,
319 PRUint32 aFlagsValues,
320 PRUint32 aFlagsToUpdate);
322 public:
323 static void
324 PropagatePresentationDataFromChildAt(nsIFrame* aParentFrame,
325 PRInt32 aFirstChildIndex,
326 PRInt32 aLastChildIndex,
327 PRUint32 aFlagsValues,
328 PRUint32 aFlagsToUpdate);
330 // helper to let the rebuild of automatic data (presentation data
331 // and embellishement data) walk through a subtree that may contain
332 // non-MathML container frames. Note that this method re-builds the
333 // automatic data in the children -- not in aParentFrame itself (except
334 // for those particular operations that the parent frame may do in its
335 // TransmitAutomaticData()). The reason it works this way is because
336 // a container frame knows what it wants for its children, whereas children
337 // have no clue who their parent is. For example, it is <mfrac> who knows
338 // that its children have to be in scriptsizes, and has to transmit this
339 // information to them. Hence, when changes occur in a child frame, the child
340 // has to request the re-build from its parent. Unfortunately, the extra cost
341 // for this is that it will re-sync in the siblings of the child as well.
342 static void
343 RebuildAutomaticDataForChildren(nsIFrame* aParentFrame);
345 // helper to blow away the automatic data cached in a frame's subtree and
346 // re-layout its subtree to reflect changes that may have happen. In the
347 // event where aParentFrame isn't a MathML frame, it will first walk up to
348 // the ancestor that is a MathML frame, and re-layout from there -- this is
349 // to guarantee that automatic data will be rebuilt properly. Note that this
350 // method re-builds the automatic data in the children -- not in the parent
351 // frame itself (except for those particular operations that the parent frame
352 // may do do its TransmitAutomaticData()). @see RebuildAutomaticDataForChildren
354 // aBits are the bits to pass to FrameNeedsReflow() when we call it.
355 static nsresult
356 ReLayoutChildren(nsIFrame* aParentFrame, nsFrameState aBits);
358 protected:
359 // Helper method which positions child frames as an <mrow> on given baseline
360 // y = aBaseline starting from x = aOffsetX, calling FinishReflowChild()
361 // on the frames.
362 void
363 PositionRowChildFrames(nscoord aOffsetX, nscoord aBaseline);
365 // A variant on FinishAndStoreOverflow() that uses the union of child
366 // overflows, the frame bounds, and mBoundingMetrics to set and store the
367 // overflow.
368 void GatherAndStoreOverflow(nsHTMLReflowMetrics* aMetrics);
371 * Call DidReflow() if the NS_FRAME_IN_REFLOW frame bit is set on aFirst and
372 * all its next siblings up to, but not including, aStop.
373 * aStop == nsnull meaning all next siblings with the bit set.
374 * The method does nothing if aFirst == nsnull.
376 static void DidReflowChildren(nsIFrame* aFirst, nsIFrame* aStop = nsnull);
378 private:
379 class RowChildFrameIterator;
380 friend class RowChildFrameIterator;
384 // --------------------------------------------------------------------------
385 // Currently, to benefit from line-breaking inside the <math> element, <math> is
386 // simply mapping to nsBlockFrame or nsInlineFrame.
387 // A separate implemention needs to provide:
388 // 1) line-breaking
389 // 2) proper inter-frame spacing
390 // 3) firing of Stretch() (in which case FinalizeReflow() would have to be cleaned)
391 // Issues: If/when mathml becomes a pluggable component, the separation will be needed.
392 class nsMathMLmathBlockFrame : public nsBlockFrame {
393 public:
394 friend nsIFrame* NS_NewMathMLmathBlockFrame(nsIPresShell* aPresShell,
395 nsStyleContext* aContext, PRUint32 aFlags);
397 // beware, mFrames is not set by nsBlockFrame
398 // cannot use mFrames{.FirstChild()|.etc} since the block code doesn't set mFrames
399 NS_IMETHOD
400 SetInitialChildList(nsIAtom* aListName,
401 nsIFrame* aChildList)
403 NS_ASSERTION(!aListName, "unexpected frame list");
404 nsresult rv = nsBlockFrame::SetInitialChildList(aListName, aChildList);
405 // re-resolve our subtree to set any mathml-expected data
406 nsMathMLContainerFrame::RebuildAutomaticDataForChildren(this);
407 return rv;
410 NS_IMETHOD
411 AppendFrames(nsIAtom* aListName,
412 nsIFrame* aFrameList)
414 NS_ASSERTION(!aListName || nsGkAtoms::nextBidi == aListName,
415 "unexpected frame list");
416 nsresult rv = nsBlockFrame::AppendFrames(aListName, aFrameList);
417 if (NS_LIKELY(!aListName))
418 nsMathMLContainerFrame::ReLayoutChildren(this,
419 NS_FRAME_HAS_DIRTY_CHILDREN);
420 return rv;
423 NS_IMETHOD
424 InsertFrames(nsIAtom* aListName,
425 nsIFrame* aPrevFrame,
426 nsIFrame* aFrameList)
428 NS_ASSERTION(!aListName || nsGkAtoms::nextBidi == aListName,
429 "unexpected frame list");
430 nsresult rv = nsBlockFrame::InsertFrames(aListName, aPrevFrame, aFrameList);
431 if (NS_LIKELY(!aListName))
432 nsMathMLContainerFrame::ReLayoutChildren(this,
433 NS_FRAME_HAS_DIRTY_CHILDREN);
434 return rv;
437 NS_IMETHOD
438 RemoveFrame(nsIAtom* aListName,
439 nsIFrame* aOldFrame)
441 NS_ASSERTION(!aListName || nsGkAtoms::nextBidi == aListName,
442 "unexpected frame list");
443 nsresult rv = nsBlockFrame::RemoveFrame(aListName, aOldFrame);
444 if (NS_LIKELY(!aListName))
445 nsMathMLContainerFrame::ReLayoutChildren(this,
446 NS_FRAME_HAS_DIRTY_CHILDREN);
447 return rv;
450 virtual PRBool IsFrameOfType(PRUint32 aFlags) const {
451 return nsBlockFrame::IsFrameOfType(aFlags &
452 ~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace));
455 protected:
456 nsMathMLmathBlockFrame(nsStyleContext* aContext) : nsBlockFrame(aContext) {
457 // We should always have a space manager. Not that things can really try
458 // to float out of us anyway, but we need one for line layout.
459 AddStateBits(NS_BLOCK_SPACE_MGR);
461 virtual ~nsMathMLmathBlockFrame() {}
464 // --------------
466 class nsMathMLmathInlineFrame : public nsInlineFrame {
467 public:
468 friend nsIFrame* NS_NewMathMLmathInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
470 NS_IMETHOD
471 SetInitialChildList(nsIAtom* aListName,
472 nsIFrame* aChildList)
474 NS_ASSERTION(!aListName, "unexpected frame list");
475 nsresult rv = nsInlineFrame::SetInitialChildList(aListName, aChildList);
476 // re-resolve our subtree to set any mathml-expected data
477 nsMathMLContainerFrame::RebuildAutomaticDataForChildren(this);
478 return rv;
481 NS_IMETHOD
482 AppendFrames(nsIAtom* aListName,
483 nsIFrame* aFrameList)
485 NS_ASSERTION(!aListName || nsGkAtoms::nextBidi == aListName,
486 "unexpected frame list");
487 nsresult rv = nsInlineFrame::AppendFrames(aListName, aFrameList);
488 if (NS_LIKELY(!aListName))
489 nsMathMLContainerFrame::ReLayoutChildren(this,
490 NS_FRAME_HAS_DIRTY_CHILDREN);
491 return rv;
494 NS_IMETHOD
495 InsertFrames(nsIAtom* aListName,
496 nsIFrame* aPrevFrame,
497 nsIFrame* aFrameList)
499 NS_ASSERTION(!aListName || nsGkAtoms::nextBidi == aListName,
500 "unexpected frame list");
501 nsresult rv = nsInlineFrame::InsertFrames(aListName, aPrevFrame, aFrameList);
502 if (NS_LIKELY(!aListName))
503 nsMathMLContainerFrame::ReLayoutChildren(this,
504 NS_FRAME_HAS_DIRTY_CHILDREN);
505 return rv;
508 NS_IMETHOD
509 RemoveFrame(nsIAtom* aListName,
510 nsIFrame* aOldFrame)
512 NS_ASSERTION(!aListName || nsGkAtoms::nextBidi == aListName,
513 "unexpected frame list");
514 nsresult rv = nsInlineFrame::RemoveFrame(aListName, aOldFrame);
515 if (NS_LIKELY(!aListName))
516 nsMathMLContainerFrame::ReLayoutChildren(this,
517 NS_FRAME_HAS_DIRTY_CHILDREN);
518 return rv;
521 virtual PRBool IsFrameOfType(PRUint32 aFlags) const {
522 return nsInlineFrame::IsFrameOfType(aFlags &
523 ~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace));
526 protected:
527 nsMathMLmathInlineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {}
528 virtual ~nsMathMLmathInlineFrame() {}
531 #endif /* nsMathMLContainerFrame_h___ */