1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=2:et:sw=2:
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Dan Rosen <dr@netscape.com>
25 * Mats Palmgren <mats.palmgren@bredband.net>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 * construction of a frame tree that is nearly isomorphic to the content
43 * tree and updating of that tree in response to dynamic changes
46 #include "nsCSSFrameConstructor.h"
50 #include "nsISupportsArray.h"
51 #include "nsHashtable.h"
52 #include "nsIHTMLDocument.h"
53 #include "nsIStyleRule.h"
55 #include "nsGkAtoms.h"
56 #include "nsPresContext.h"
57 #include "nsILinkHandler.h"
58 #include "nsIDocument.h"
59 #include "nsTableFrame.h"
60 #include "nsTableColGroupFrame.h"
61 #include "nsTableColFrame.h"
62 #include "nsIDOMHTMLDocument.h"
63 #include "nsIDOMHTMLTableColElement.h"
64 #include "nsIDOMHTMLTableCaptionElem.h"
65 #include "nsHTMLParts.h"
66 #include "nsIPresShell.h"
67 #include "nsStyleSet.h"
68 #include "nsIViewManager.h"
69 #include "nsIEventStateManager.h"
70 #include "nsIScrollableView.h"
71 #include "nsStyleConsts.h"
72 #include "nsTableOuterFrame.h"
73 #include "nsIDOMXULElement.h"
74 #include "nsHTMLContainerFrame.h"
75 #include "nsINameSpaceManager.h"
76 #include "nsIDOMHTMLSelectElement.h"
77 #include "nsIDOMHTMLLegendElement.h"
78 #include "nsIComboboxControlFrame.h"
79 #include "nsIListControlFrame.h"
80 #include "nsISelectControlFrame.h"
81 #include "nsIRadioControlFrame.h"
82 #include "nsICheckboxControlFrame.h"
83 #include "nsIDOMCharacterData.h"
84 #include "nsIDOMHTMLImageElement.h"
85 #include "nsPlaceholderFrame.h"
86 #include "nsTableRowGroupFrame.h"
87 #include "nsStyleChangeList.h"
88 #include "nsIFormControl.h"
89 #include "nsCSSAnonBoxes.h"
90 #include "nsCSSPseudoElements.h"
91 #include "nsIDeviceContext.h"
92 #include "nsTextFragment.h"
93 #include "nsISupportsArray.h"
94 #include "nsIAnonymousContentCreator.h"
95 #include "nsFrameManager.h"
96 #include "nsLegendFrame.h"
97 #include "nsIContentIterator.h"
98 #include "nsBoxLayoutState.h"
99 #include "nsBindingManager.h"
100 #include "nsXBLBinding.h"
101 #include "nsITheme.h"
102 #include "nsContentCID.h"
103 #include "nsContentUtils.h"
104 #include "nsIScriptError.h"
105 #include "nsIDocShell.h"
106 #include "nsIDocShellTreeItem.h"
107 #include "nsObjectFrame.h"
108 #include "nsRuleNode.h"
109 #include "nsIDOMMutationEvent.h"
110 #include "nsChildIterator.h"
111 #include "nsCSSRendering.h"
112 #include "nsISelectElement.h"
113 #include "nsLayoutErrors.h"
114 #include "nsLayoutUtils.h"
115 #include "nsAutoPtr.h"
116 #include "nsBoxFrame.h"
117 #include "nsIBoxLayout.h"
118 #include "nsImageFrame.h"
119 #include "nsIObjectLoadingContent.h"
120 #include "nsContentErrors.h"
121 #include "nsIPrincipal.h"
122 #include "nsIDOMWindowInternal.h"
123 #include "nsStyleUtil.h"
124 #include "nsIFocusEventSuppressor.h"
128 #include "nsIRootBox.h"
129 #include "nsIDOMXULCommandDispatcher.h"
130 #include "nsIDOMXULDocument.h"
131 #include "nsIXULDocument.h"
134 #include "nsIAccessibilityService.h"
135 #include "nsIAccessibleEvent.h"
138 #include "nsInlineFrame.h"
139 #include "nsBlockFrame.h"
141 #include "nsIScrollableFrame.h"
143 #include "nsIXBLService.h"
145 #undef NOISY_FIRST_LETTER
148 #include "nsMathMLParts.h"
151 #include "nsSVGEffects.h"
155 NS_NewHTMLCanvasFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
157 #if defined(MOZ_MEDIA)
159 NS_NewHTMLVideoFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
163 #include "nsISVGTextContentMetrics.h"
168 NS_NewSVGOuterSVGFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
170 NS_NewSVGInnerSVGFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
172 NS_NewSVGPathGeometryFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
174 NS_NewSVGGFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
176 NS_NewSVGGenericContainerFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
178 NS_NewSVGForeignObjectFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
180 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
182 NS_NewSVGGlyphFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsIFrame
* parent
, nsStyleContext
* aContext
);
184 NS_NewSVGSwitchFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
186 NS_NewSVGTextFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
188 NS_NewSVGTSpanFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsIFrame
* parent
, nsStyleContext
* aContext
);
190 NS_NewSVGContainerFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
192 NS_NewSVGUseFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
194 NS_SVG_PassesConditionalProcessingTests(nsIContent
*aContent
);
196 NS_NewSVGLinearGradientFrame(nsIPresShell
*aPresShell
, nsIContent
*aContent
, nsStyleContext
* aContext
);
198 NS_NewSVGRadialGradientFrame(nsIPresShell
*aPresShell
, nsIContent
*aContent
, nsStyleContext
* aContext
);
200 NS_NewSVGStopFrame(nsIPresShell
*aPresShell
, nsIContent
*aContent
, nsIFrame
*aParentFrame
, nsStyleContext
* aContext
);
202 NS_NewSVGMarkerFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
204 NS_NewSVGImageFrame(nsIPresShell
*aPresShell
, nsIContent
*aContent
, nsStyleContext
* aContext
);
206 NS_NewSVGClipPathFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
208 NS_NewSVGTextPathFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsIFrame
* parent
, nsStyleContext
* aContext
);
210 NS_NewSVGFilterFrame(nsIPresShell
*aPresShell
, nsIContent
*aContent
, nsStyleContext
* aContext
);
212 NS_NewSVGPatternFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
214 NS_NewSVGMaskFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
216 NS_NewSVGLeafFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
219 #include "nsIDocument.h"
220 #include "nsIDOMElement.h"
221 #include "nsIDOMNodeList.h"
222 #include "nsIDOMDocument.h"
223 #include "nsIDOMDocumentXBL.h"
224 #include "nsIScrollable.h"
225 #include "nsINodeInfo.h"
227 #include "nsWidgetsCID.h"
228 #include "nsNodeInfoManager.h"
229 #include "nsContentCreatorFunctions.h"
230 #include "nsIServiceManager.h"
232 // Global object maintenance
233 nsIXBLService
* nsCSSFrameConstructor::gXBLService
= nsnull
;
236 static PRBool gGotXBLFormPrefs
= PR_FALSE
;
237 static PRBool gUseXBLForms
= PR_FALSE
;
240 // Set the environment variable GECKO_FRAMECTOR_DEBUG_FLAGS to one or
241 // more of the following flags (comma separated) for handy debug
243 static PRBool gNoisyContentUpdates
= PR_FALSE
;
244 static PRBool gReallyNoisyContentUpdates
= PR_FALSE
;
245 static PRBool gNoisyInlineConstruction
= PR_FALSE
;
246 static PRBool gVerifyFastFindFrame
= PR_FALSE
;
247 static PRBool gTablePseudoFrame
= PR_FALSE
;
249 struct FrameCtorDebugFlags
{
254 static FrameCtorDebugFlags gFlags
[] = {
255 { "content-updates", &gNoisyContentUpdates
},
256 { "really-noisy-content-updates", &gReallyNoisyContentUpdates
},
257 { "noisy-inline", &gNoisyInlineConstruction
},
258 { "fast-find-frame", &gVerifyFastFindFrame
},
259 { "table-pseudo", &gTablePseudoFrame
},
262 #define NUM_DEBUG_FLAGS (sizeof(gFlags) / sizeof(gFlags[0]))
267 #include "nsMenuFrame.h"
268 #include "nsPopupSetFrame.h"
269 #include "nsTreeColFrame.h"
270 #include "nsIBoxObject.h"
271 #include "nsPIListBoxObject.h"
272 #include "nsListBoxBodyFrame.h"
273 #include "nsListItemFrame.h"
275 //------------------------------------------------------------------
278 NS_NewAutoRepeatBoxFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
281 NS_NewRootBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
284 NS_NewDocElementBoxFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
287 NS_NewThumbFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
290 NS_NewDeckFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, nsIBoxLayout
* aLayoutManager
= nsnull
);
293 NS_NewLeafBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
296 NS_NewStackFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, nsIBoxLayout
* aLayoutManager
= nsnull
);
299 NS_NewProgressMeterFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
302 NS_NewImageBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
305 NS_NewTextBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
308 NS_NewGroupBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
311 NS_NewButtonBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
314 NS_NewSplitterFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
317 NS_NewMenuPopupFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
320 NS_NewPopupSetFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
323 NS_NewMenuFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRUint32 aFlags
);
326 NS_NewMenuBarFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
329 NS_NewTreeBodyFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
333 NS_NewGridLayout2 ( nsIPresShell
* aPresShell
, nsIBoxLayout
** aNewLayout
);
335 NS_NewGridRowLeafLayout ( nsIPresShell
* aPresShell
, nsIBoxLayout
** aNewLayout
);
337 NS_NewGridRowLeafFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRBool aIsRoot
, nsIBoxLayout
* aLayout
);
339 NS_NewGridRowGroupLayout ( nsIPresShell
* aPresShell
, nsIBoxLayout
** aNewLayout
);
341 NS_NewGridRowGroupFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRBool aIsRoot
, nsIBoxLayout
* aLayout
);
344 NS_NewListBoxLayout ( nsIPresShell
* aPresShell
, nsCOMPtr
<nsIBoxLayout
>& aNewLayout
);
349 NS_NewTitleBarFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
352 NS_NewResizerFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
358 NS_NewHTMLScrollFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRBool aIsRoot
);
361 NS_NewXULScrollFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRBool aIsRoot
);
364 NS_NewSliderFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
367 NS_NewScrollbarFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
370 NS_NewScrollbarButtonFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
373 #ifdef NOISY_FINDFRAME
374 static PRInt32 FFWC_totalCount
=0;
375 static PRInt32 FFWC_doLoop
=0;
376 static PRInt32 FFWC_doSibling
=0;
377 static PRInt32 FFWC_recursions
=0;
378 static PRInt32 FFWC_nextInFlows
=0;
379 static PRInt32 FFWC_slowSearchForText
=0;
383 DeletingFrameSubtree(nsFrameManager
* aFrameManager
,
389 SVG_GetFirstNonAAncestorFrame(nsIFrame
*aParentFrame
)
391 for (nsIFrame
*ancestorFrame
= aParentFrame
; ancestorFrame
!= nsnull
;
392 ancestorFrame
= ancestorFrame
->GetParent()) {
393 if (ancestorFrame
->GetType() != nsGkAtoms::svgAFrame
) {
394 return ancestorFrame
;
401 static inline nsIFrame
*
402 GetFieldSetAreaFrame(nsIFrame
* aFieldsetFrame
)
404 // Depends on the fieldset child frame order - see ConstructFieldSetFrame() below.
405 nsIFrame
* firstChild
= aFieldsetFrame
->GetFirstChild(nsnull
);
406 return firstChild
&& firstChild
->GetNextSibling() ? firstChild
->GetNextSibling() : firstChild
;
409 //----------------------------------------------------------------------
412 IsInlineOutside(nsIFrame
* aFrame
)
414 return aFrame
->GetStyleDisplay()->IsInlineOutside();
418 * True if aFrame is an actual inline frame in the sense of non-replaced
419 * display:inline CSS boxes. In other words, it can be affected by {ib}
420 * splitting and can contain first-letter frames. Basically, this is either an
421 * inline frame (positioned or otherwise) or an line frame (this last because
422 * it can contain first-letter and because inserting blocks in the middle of it
423 * needs to terminate it).
426 IsInlineFrame(const nsIFrame
* aFrame
)
428 return aFrame
->IsFrameOfType(nsIFrame::eLineParticipant
);
432 * If any children require a block parent, return the first such child.
433 * Otherwise return null.
436 AnyKidsNeedBlockParent(nsIFrame
*aFrameList
)
438 for (nsIFrame
*k
= aFrameList
; k
; k
= k
->GetNextSibling()) {
439 // Line participants, such as text and inline frames, can't be
440 // directly inside a XUL box; they must be wrapped in an
441 // intermediate block.
442 if (k
->IsFrameOfType(nsIFrame::eLineParticipant
)) {
443 return k
->GetContent();
449 // Reparent a frame into a wrapper frame that is a child of its old parent.
451 ReparentFrame(nsFrameManager
* aFrameManager
,
452 nsIFrame
* aNewParentFrame
,
455 aFrame
->SetParent(aNewParentFrame
);
456 aFrameManager
->ReParentStyleContext(aFrame
);
457 if (aFrame
->GetStateBits() &
458 (NS_FRAME_HAS_VIEW
| NS_FRAME_HAS_CHILD_WITH_VIEW
)) {
459 // No need to walk up the tree, since the bits are already set
460 // right on the parent of aNewParentFrame.
461 NS_ASSERTION(aNewParentFrame
->GetParent()->GetStateBits() &
462 NS_FRAME_HAS_CHILD_WITH_VIEW
,
463 "aNewParentFrame's parent should have this bit set!");
464 aNewParentFrame
->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW
);
468 //----------------------------------------------------------------------
470 // When inline frames get weird and have block frames in them, we
471 // annotate them to help us respond to incremental content changes
475 IsFrameSpecial(nsIFrame
* aFrame
)
477 return (aFrame
->GetStateBits() & NS_FRAME_IS_SPECIAL
) != 0;
480 static nsIFrame
* GetSpecialSibling(nsIFrame
* aFrame
)
482 // We only store the "special sibling" annotation with the first
483 // frame in the continuation chain. Walk back to find that frame now.
484 aFrame
= aFrame
->GetFirstContinuation();
486 void* value
= aFrame
->GetProperty(nsGkAtoms::IBSplitSpecialSibling
);
488 return static_cast<nsIFrame
*>(value
);
492 GetIBSplitSpecialPrevSiblingForAnonymousBlock(nsIFrame
* aFrame
)
494 NS_PRECONDITION(IsFrameSpecial(aFrame
) && !IsInlineFrame(aFrame
),
495 "Shouldn't call this");
497 // We only store the "special sibling" annotation with the first
498 // frame in the continuation chain. Walk back to find that frame now.
500 static_cast<nsIFrame
*>
501 (aFrame
->GetFirstContinuation()->
502 GetProperty(nsGkAtoms::IBSplitSpecialPrevSibling
));
506 GetLastSpecialSibling(nsIFrame
* aFrame
)
508 for (nsIFrame
*frame
= aFrame
, *next
; ; frame
= next
) {
509 next
= GetSpecialSibling(frame
);
513 NS_NOTREACHED("unreachable code");
518 SetFrameIsSpecial(nsIFrame
* aFrame
, nsIFrame
* aSpecialSibling
)
520 NS_PRECONDITION(aFrame
, "bad args!");
522 // Mark the frame and all of its siblings as "special".
523 for (nsIFrame
* frame
= aFrame
; frame
!= nsnull
; frame
= frame
->GetNextContinuation()) {
524 frame
->AddStateBits(NS_FRAME_IS_SPECIAL
);
527 if (aSpecialSibling
) {
528 // We should be the first-in-flow
529 NS_ASSERTION(!aFrame
->GetPrevInFlow(),
530 "assigning special sibling to other than first-in-flow!");
532 // Store the "special sibling" (if we were given one) with the
533 // first frame in the flow.
534 aFrame
->SetProperty(nsGkAtoms::IBSplitSpecialSibling
, aSpecialSibling
);
539 GetIBContainingBlockFor(nsIFrame
* aFrame
)
541 NS_PRECONDITION(IsFrameSpecial(aFrame
),
542 "GetIBContainingBlockFor() should only be called on known IB frames");
544 // Get the first "normal" ancestor of the target frame.
545 nsIFrame
* parentFrame
;
547 parentFrame
= aFrame
->GetParent();
550 NS_ERROR("no unsplit block frame in IB hierarchy");
554 // Note that we ignore non-special frames which have a pseudo on their
555 // style context -- they're not the frames we're looking for! In
556 // particular, they may be hiding a real parent that _is_ special.
557 if (!IsFrameSpecial(parentFrame
) &&
558 !parentFrame
->GetStyleContext()->GetPseudoType())
561 aFrame
= parentFrame
;
565 NS_ASSERTION(parentFrame
, "no normal ancestor found for special frame in GetIBContainingBlockFor");
566 NS_ASSERTION(parentFrame
!= aFrame
, "parentFrame is actually the child frame - bogus reslt");
571 //----------------------------------------------------------------------
573 // Block/inline frame construction logic. We maintain a few invariants here:
575 // 1. Block frames contain block and inline frames.
577 // 2. Inline frames only contain inline frames. If an inline parent has a block
578 // child then the block child is migrated upward until it lands in a block
579 // parent (the inline frames containing block is where it will end up).
582 FindFirstBlock(nsIFrame
* aKid
, nsIFrame
** aPrevKid
)
584 nsIFrame
* prevKid
= nsnull
;
586 if (!IsInlineOutside(aKid
)) {
591 aKid
= aKid
->GetNextSibling();
598 FindLastBlock(nsIFrame
* aKid
)
600 nsIFrame
* lastBlock
= nsnull
;
602 if (!IsInlineOutside(aKid
)) {
605 aKid
= aKid
->GetNextSibling();
611 * The special-prev-sibling is useful for
612 * finding the "special parent" of a frame (i.e., a frame from which a
613 * good parent style context can be obtained), one looks at the
614 * special previous sibling annotation of the real parent of the frame
615 * (if the real parent has NS_FRAME_IS_SPECIAL).
618 MarkIBSpecialPrevSibling(nsIFrame
*aAnonymousFrame
,
619 nsIFrame
*aSpecialParent
)
621 aAnonymousFrame
->SetProperty(nsGkAtoms::IBSplitSpecialPrevSibling
,
622 aSpecialParent
, nsnull
, nsnull
);
625 // -----------------------------------------------------------
628 IsOutOfFlowList(nsIAtom
* aListName
)
631 aListName
== nsGkAtoms::floatList
||
632 aListName
== nsGkAtoms::absoluteList
||
633 aListName
== nsGkAtoms::overflowOutOfFlowList
||
634 aListName
== nsGkAtoms::fixedList
;
637 // Helper function that recursively removes content to frame mappings and
638 // undisplayed content mappings.
639 // This differs from DeletingFrameSubtree() because the frames have not yet been
640 // added to the frame hierarchy.
641 // XXXbz it would really help if we merged the two methods somehow... :(
643 DoCleanupFrameReferences(nsFrameManager
* aFrameManager
,
646 nsIContent
* content
= aFrameIn
->GetContent();
648 if (aFrameIn
->GetType() == nsGkAtoms::placeholderFrame
) {
649 nsPlaceholderFrame
* placeholder
= static_cast<nsPlaceholderFrame
*>
651 // if the frame is a placeholder use the out of flow frame
652 aFrameIn
= nsPlaceholderFrame::GetRealFrameForPlaceholder(placeholder
);
654 // And don't forget to unregister the placeholder mapping. Note that this
655 // means it's the caller's responsibility to actually destroy the
656 // out-of-flow pointed to by the placeholder, since after this point the
657 // out-of-flow is not reachable via the placeholder.
658 aFrameManager
->UnregisterPlaceholderFrame(placeholder
);
661 // Remove the mapping from the content object to its frame
662 aFrameManager
->RemoveAsPrimaryFrame(content
, aFrameIn
);
663 aFrameManager
->ClearAllUndisplayedContentIn(content
);
665 // Recursively walk the child frames.
666 nsIAtom
* childListName
= nsnull
;
667 PRInt32 childListIndex
= 0;
669 nsIFrame
* childFrame
= aFrameIn
->GetFirstChild(childListName
);
671 DoCleanupFrameReferences(aFrameManager
, childFrame
);
673 // Get the next sibling child frame
674 childFrame
= childFrame
->GetNextSibling();
677 childListName
= aFrameIn
->GetAdditionalChildListName(childListIndex
++);
678 } while (childListName
);
681 // Helper function that walks a frame list and calls DoCleanupFrameReference()
683 CleanupFrameReferences(nsFrameManager
* aFrameManager
,
684 nsIFrame
* aFrameList
)
687 DoCleanupFrameReferences(aFrameManager
, aFrameList
);
689 // Get the sibling frame
690 aFrameList
= aFrameList
->GetNextSibling();
694 // -----------------------------------------------------------
696 // Structure used when constructing formatting object trees.
697 struct nsFrameItems
{
701 nsFrameItems(nsIFrame
* aFrame
= nsnull
);
703 // Appends the frame to the end of the list
704 void AddChild(nsIFrame
* aChild
);
706 // Inserts the frame somewhere in the list
707 void InsertChildAfter(nsIFrame
* aChild
, nsIFrame
* aAfter
);
709 // Remove the frame from the list, return PR_FALSE if not found. If
710 // aPrevSibling is given, it must have aChild as its GetNextSibling().
711 // aPrevSibling may be null to indicate that the list should be searched.
712 PRBool
RemoveChild(nsIFrame
* aChild
, nsIFrame
* aPrevSibling
);
715 nsFrameItems::nsFrameItems(nsIFrame
* aFrame
)
716 : childList(aFrame
), lastChild(aFrame
)
721 nsFrameItems::AddChild(nsIFrame
* aChild
)
724 nsIFrame
* oldLastChild
= lastChild
;
727 if (childList
== nsnull
) {
728 childList
= lastChild
= aChild
;
732 NS_ASSERTION(aChild
!= lastChild
,
733 "Same frame being added to frame list twice?");
734 lastChild
->SetNextSibling(aChild
);
737 // if aChild has siblings, lastChild needs to be the last one
738 for (nsIFrame
* sib
= lastChild
->GetNextSibling(); sib
;
739 sib
= sib
->GetNextSibling()) {
740 NS_ASSERTION(oldLastChild
!= sib
, "Loop in frame list");
746 nsFrameItems::InsertChildAfter(nsIFrame
* aChild
, nsIFrame
* aAfter
)
748 if (!childList
|| (aAfter
&& !aAfter
->GetNextSibling())) {
749 // Appending to the end of the list
754 // Inserting at beginning of list
755 aChild
->SetNextSibling(childList
);
759 aChild
->SetNextSibling(aAfter
->GetNextSibling());
760 aAfter
->SetNextSibling(aChild
);
764 nsFrameItems::RemoveChild(nsIFrame
* aFrame
, nsIFrame
* aPrevSibling
)
766 NS_PRECONDITION(aFrame
, "null ptr");
774 for (sib
= childList
; sib
&& sib
!= aFrame
; sib
= sib
->GetNextSibling()) {
782 NS_ASSERTION(!prev
|| prev
->GetNextSibling() == aFrame
,
783 "Unexpected prevsibling");
785 if (aFrame
== childList
) {
786 childList
= aFrame
->GetNextSibling();
788 prev
->SetNextSibling(aFrame
->GetNextSibling());
790 if (aFrame
== lastChild
) {
793 aFrame
->SetNextSibling(nsnull
);
797 // -----------------------------------------------------------
799 // Structure used when constructing formatting object trees. Contains
800 // state information needed for absolutely positioned elements
801 struct nsAbsoluteItems
: nsFrameItems
{
802 // containing block for absolutely positioned elements
803 nsIFrame
* containingBlock
;
805 nsAbsoluteItems(nsIFrame
* aContainingBlock
);
807 // XXXbz Does this need a debug-only assignment operator that nulls out the
808 // childList in the nsAbsoluteItems we're copying? Introducing a difference
809 // between debug and non-debug behavior seems bad, so I guess not...
811 NS_ASSERTION(!childList
,
812 "Dangling child list. Someone forgot to insert it?");
816 // Appends the frame to the end of the list
817 void AddChild(nsIFrame
* aChild
);
820 nsAbsoluteItems::nsAbsoluteItems(nsIFrame
* aContainingBlock
)
821 : containingBlock(aContainingBlock
)
825 // Additional behavior is that it sets the frame's NS_FRAME_OUT_OF_FLOW flag
827 nsAbsoluteItems::AddChild(nsIFrame
* aChild
)
829 NS_ASSERTION(aChild
->PresContext()->FrameManager()->
830 GetPlaceholderFrameFor(aChild
),
831 "Child without placeholder being added to nsAbsoluteItems?");
832 aChild
->AddStateBits(NS_FRAME_OUT_OF_FLOW
);
833 nsFrameItems::AddChild(aChild
);
836 // Structures used to record the creation of pseudo table frames where
837 // the content belongs to some ancestor.
838 // PseudoFrames are necessary when the childframe cannot be the direct
839 // ancestor of the content based parent frame. The amount of necessary pseudo
840 // frames is limited as the worst case would be table frame nested directly
841 // into another table frame. So the member structures of nsPseudoFrames can be
842 // viewed as a ring buffer where you start with the necessary frame type and
843 // add higher frames as long as necessary to fit into the initial parent frame.
844 // mLowestType is some sort of stack pointer which shows the start of the
845 // ringbuffer. The insertion of pseudo frames can happen between every
846 // two frames so we need to push and pop the pseudo frame data when children
847 // of a frame are created.
848 // The colgroup frame is special as it can harbour only col children.
849 // Once all children of given frame are known, the pseudo frames can be
850 // processed that means attached to the corresponding parent frames.
851 // The behaviour is in general described at
852 // http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes
853 // however there are implementation details that extend the CSS 2.1
855 // 1. every table frame is wrapped in an outer table frame, which is always a
857 // 2. the outer table frame will be also created to hold a caption.
858 // 3. each table cell will have a pseudo inner table cell frame.
859 // 4. a colgroup frame is created between a column and a table
860 // 5. a rowgroup frame is created between a row and a table
861 // A table frame can only have rowgroups or column groups as children.
862 // A outer table frame can only have one caption and one table frame
864 // Every table even if all table frames are specified will require the
865 // creation of two types of pseudo frames: the outer table frame and the inner
866 // table cell frames.
868 struct nsPseudoFrameData
{
869 nsIFrame
* mFrame
; // created pseudo frame
870 nsFrameItems mChildList
; // child frames pending to be added to the pseudo
871 nsFrameItems mChildList2
; // child frames pending to be added to the pseudo
874 nsPseudoFrameData(nsPseudoFrameData
& aOther
);
881 struct nsPseudoFrames
{
882 nsPseudoFrameData mTableOuter
;
883 nsPseudoFrameData mTableInner
;
884 nsPseudoFrameData mRowGroup
;
885 nsPseudoFrameData mColGroup
;
886 nsPseudoFrameData mRow
;
887 nsPseudoFrameData mCellOuter
;
888 nsPseudoFrameData mCellInner
;
890 // the frame type of the most descendant pseudo frame, no AddRef
891 nsIAtom
* mLowestType
;
894 nsPseudoFrames
& operator=(const nsPseudoFrames
& aOther
);
895 void Reset(nsPseudoFrames
* aSave
= nsnull
);
896 PRBool
IsEmpty() { return (!mLowestType
&& !mColGroup
.mFrame
); }
902 nsPseudoFrameData::nsPseudoFrameData()
903 : mFrame(nsnull
), mChildList(), mChildList2()
906 nsPseudoFrameData::nsPseudoFrameData(nsPseudoFrameData
& aOther
)
907 : mFrame(aOther
.mFrame
), mChildList(aOther
.mChildList
),
908 mChildList2(aOther
.mChildList2
)
912 nsPseudoFrameData::Reset()
915 mChildList
.childList
= mChildList
.lastChild
= nsnull
;
916 mChildList2
.childList
= mChildList2
.lastChild
= nsnull
;
921 nsPseudoFrameData::Dump()
923 nsIFrame
* main
= nsnull
;
924 nsIFrame
* second
= nsnull
;
925 printf(" %p\n", static_cast<void*>(mFrame
));
926 main
= mChildList
.childList
;
929 second
= mChildList2
.childList
;
930 while (main
|| second
) {
931 printf(" %p %p\n", static_cast<void*>(main
),
932 static_cast<void*>(second
));
934 main
= main
->GetNextSibling();
936 second
= second
->GetNextSibling();
940 nsPseudoFrames::nsPseudoFrames()
941 : mTableOuter(), mTableInner(), mRowGroup(), mColGroup(),
942 mRow(), mCellOuter(), mCellInner(), mLowestType(nsnull
)
945 nsPseudoFrames
& nsPseudoFrames::operator=(const nsPseudoFrames
& aOther
)
947 mTableOuter
= aOther
.mTableOuter
;
948 mTableInner
= aOther
.mTableInner
;
949 mColGroup
= aOther
.mColGroup
;
950 mRowGroup
= aOther
.mRowGroup
;
952 mCellOuter
= aOther
.mCellOuter
;
953 mCellInner
= aOther
.mCellInner
;
954 mLowestType
= aOther
.mLowestType
;
959 nsPseudoFrames::Reset(nsPseudoFrames
* aSave
)
972 mLowestType
= nsnull
;
977 nsPseudoFrames::Dump()
980 // check that it is really empty, warn otherwise
981 NS_ASSERTION(!mTableOuter
.mFrame
, "Pseudo Outer Table Frame not empty");
982 NS_ASSERTION(!mTableOuter
.mChildList
.childList
, "Pseudo Outer Table Frame has primary children");
983 NS_ASSERTION(!mTableOuter
.mChildList2
.childList
,"Pseudo Outer Table Frame has secondary children");
984 NS_ASSERTION(!mTableInner
.mFrame
, "Pseudo Inner Table Frame not empty");
985 NS_ASSERTION(!mTableInner
.mChildList
.childList
, "Pseudo Inner Table Frame has primary children");
986 NS_ASSERTION(!mTableInner
.mChildList2
.childList
,"Pseudo Inner Table Frame has secondary children");
987 NS_ASSERTION(!mColGroup
.mFrame
, "Pseudo Colgroup Frame not empty");
988 NS_ASSERTION(!mColGroup
.mChildList
.childList
, "Pseudo Colgroup Table Frame has primary children");
989 NS_ASSERTION(!mColGroup
.mChildList2
.childList
, "Pseudo Colgroup Table Frame has secondary children");
990 NS_ASSERTION(!mRowGroup
.mFrame
, "Pseudo Rowgroup Frame not empty");
991 NS_ASSERTION(!mRowGroup
.mChildList
.childList
, "Pseudo Rowgroup Frame has primary children");
992 NS_ASSERTION(!mRowGroup
.mChildList2
.childList
, "Pseudo Rowgroup Frame has secondary children");
993 NS_ASSERTION(!mRow
.mFrame
, "Pseudo Row Frame not empty");
994 NS_ASSERTION(!mRow
.mChildList
.childList
, "Pseudo Row Frame has primary children");
995 NS_ASSERTION(!mRow
.mChildList2
.childList
, "Pseudo Row Frame has secondary children");
996 NS_ASSERTION(!mCellOuter
.mFrame
, "Pseudo Outer Cell Frame not empty");
997 NS_ASSERTION(!mCellOuter
.mChildList
.childList
, "Pseudo Outer Cell Frame has primary children");
998 NS_ASSERTION(!mCellOuter
.mChildList2
.childList
, "Pseudo Outer Cell Frame has secondary children");
999 NS_ASSERTION(!mCellInner
.mFrame
, "Pseudo Inner Cell Frame not empty");
1000 NS_ASSERTION(!mCellInner
.mChildList
.childList
, "Pseudo Inner Cell Frame has primary children");
1001 NS_ASSERTION(!mCellInner
.mChildList2
.childList
, "Pseudo inner Cell Frame has secondary children");
1004 if (mTableOuter
.mFrame
|| mTableOuter
.mChildList
.childList
|| mTableOuter
.mChildList2
.childList
) {
1005 if (nsGkAtoms::tableOuterFrame
== mLowestType
) {
1006 printf("LOW OuterTable\n");
1009 printf(" OuterTable\n");
1013 if (mTableInner
.mFrame
|| mTableInner
.mChildList
.childList
|| mTableInner
.mChildList2
.childList
) {
1014 if (nsGkAtoms::tableFrame
== mLowestType
) {
1015 printf("LOW InnerTable\n");
1018 printf(" InnerTable\n");
1022 if (mColGroup
.mFrame
|| mColGroup
.mChildList
.childList
|| mColGroup
.mChildList2
.childList
) {
1023 if (nsGkAtoms::tableColGroupFrame
== mLowestType
) {
1024 printf("LOW ColGroup\n");
1027 printf(" ColGroup\n");
1031 if (mRowGroup
.mFrame
|| mRowGroup
.mChildList
.childList
|| mRowGroup
.mChildList2
.childList
) {
1032 if (nsGkAtoms::tableRowGroupFrame
== mLowestType
) {
1033 printf("LOW RowGroup\n");
1036 printf(" RowGroup\n");
1040 if (mRow
.mFrame
|| mRow
.mChildList
.childList
|| mRow
.mChildList2
.childList
) {
1041 if (nsGkAtoms::tableRowFrame
== mLowestType
) {
1042 printf("LOW Row\n");
1050 if (mCellOuter
.mFrame
|| mCellOuter
.mChildList
.childList
|| mCellOuter
.mChildList2
.childList
) {
1051 if (IS_TABLE_CELL(mLowestType
)) {
1052 printf("LOW OuterCell\n");
1055 printf(" OuterCell\n");
1059 if (mCellInner
.mFrame
|| mCellInner
.mChildList
.childList
|| mCellInner
.mChildList2
.childList
) {
1060 printf(" InnerCell\n");
1066 // -----------------------------------------------------------
1068 // Structure for saving the existing state when pushing/poping containing
1069 // blocks. The destructor restores the state to its previous state
1070 class nsFrameConstructorSaveState
{
1072 nsFrameConstructorSaveState();
1073 ~nsFrameConstructorSaveState();
1076 nsAbsoluteItems
* mItems
; // pointer to struct whose data we save/restore
1077 PRBool
* mFirstLetterStyle
;
1078 PRBool
* mFirstLineStyle
;
1079 PRBool
* mFixedPosIsAbsPos
;
1081 nsAbsoluteItems mSavedItems
; // copy of original data
1082 PRBool mSavedFirstLetterStyle
;
1083 PRBool mSavedFirstLineStyle
;
1084 PRBool mSavedFixedPosIsAbsPos
;
1086 // The name of the child list in which our frames would belong
1087 nsIAtom
* mChildListName
;
1088 nsFrameConstructorState
* mState
;
1090 friend class nsFrameConstructorState
;
1093 // Structure used for maintaining state information during the
1094 // frame construction process
1095 class NS_STACK_CLASS nsFrameConstructorState
{
1097 nsPresContext
*mPresContext
;
1098 nsIPresShell
*mPresShell
;
1099 nsFrameManager
*mFrameManager
;
1102 // The root box, if any.
1103 nsIRootBox
* mRootBox
;
1104 // Frames destined for the nsGkAtoms::popupList.
1105 nsAbsoluteItems mPopupItems
;
1108 // Containing block information for out-of-flow frames.
1109 nsAbsoluteItems mFixedItems
;
1110 nsAbsoluteItems mAbsoluteItems
;
1111 nsAbsoluteItems mFloatedItems
;
1112 PRBool mFirstLetterStyle
;
1113 PRBool mFirstLineStyle
;
1115 // When working with the -moz-transform property, we want to hook
1116 // the abs-pos and fixed-pos lists together, since transformed
1117 // elements are fixed-pos containing blocks. This flag determines
1118 // whether or not we want to wire the fixed-pos and abs-pos lists
1120 PRBool mFixedPosIsAbsPos
;
1122 nsCOMPtr
<nsILayoutHistoryState
> mFrameState
;
1123 nsPseudoFrames mPseudoFrames
;
1124 // These bits will be added to the state bits of any frame we construct
1125 // using this state.
1126 nsFrameState mAdditionalStateBits
;
1129 // Use the passed-in history state.
1130 nsFrameConstructorState(nsIPresShell
* aPresShell
,
1131 nsIFrame
* aFixedContainingBlock
,
1132 nsIFrame
* aAbsoluteContainingBlock
,
1133 nsIFrame
* aFloatContainingBlock
,
1134 nsILayoutHistoryState
* aHistoryState
);
1135 // Get the history state from the pres context's pres shell.
1136 nsFrameConstructorState(nsIPresShell
* aPresShell
,
1137 nsIFrame
* aFixedContainingBlock
,
1138 nsIFrame
* aAbsoluteContainingBlock
,
1139 nsIFrame
* aFloatContainingBlock
);
1141 ~nsFrameConstructorState();
1143 // Function to push the existing absolute containing block state and
1144 // create a new scope. Code that uses this function should get matching
1145 // logic in GetAbsoluteContainingBlock.
1146 void PushAbsoluteContainingBlock(nsIFrame
* aNewAbsoluteContainingBlock
,
1147 nsFrameConstructorSaveState
& aSaveState
);
1149 // Function to push the existing float containing block state and
1150 // create a new scope. Code that uses this function should get matching
1151 // logic in GetFloatContainingBlock.
1152 // Pushing a null float containing block forbids any frames from being
1153 // floated until a new float containing block is pushed.
1154 // XXX we should get rid of null float containing blocks and teach the
1155 // various frame classes to deal with floats instead.
1156 void PushFloatContainingBlock(nsIFrame
* aNewFloatContainingBlock
,
1157 nsFrameConstructorSaveState
& aSaveState
,
1158 PRBool aFirstLetterStyle
,
1159 PRBool aFirstLineStyle
);
1161 // Function to return the proper geometric parent for a frame with display
1162 // struct given by aStyleDisplay and parent's frame given by
1163 // aContentParentFrame. If the frame is not allowed to be positioned, pass
1164 // false for aCanBePositioned.
1165 nsIFrame
* GetGeometricParent(const nsStyleDisplay
* aStyleDisplay
,
1166 nsIFrame
* aContentParentFrame
);
1169 * Function to add a new frame to the right frame list. This MUST be called
1170 * on frames before their children have been processed if the frames might
1171 * conceivably be out-of-flow; otherwise cleanup in error cases won't work
1172 * right. Also, this MUST be called on frames after they have been
1174 * @param aNewFrame the frame to add
1175 * @param aFrameItems the list to add in-flow frames to
1176 * @param aContent the content pointer for aNewFrame
1177 * @param aStyleContext the style context resolved for aContent
1178 * @param aParentFrame the parent frame for the content if it were in-flow
1179 * @param aCanBePositioned pass false if the frame isn't allowed to be
1181 * @param aCanBeFloated pass false if the frame isn't allowed to be
1183 * @param aIsOutOfFlowPopup pass true if the frame is an out-of-flow popup
1185 * @throws NS_ERROR_OUT_OF_MEMORY if it happens.
1186 * @note If this method throws, that means that aNewFrame was not inserted
1187 * into any frame lists. Furthermore, this method will handle cleanup
1188 * of aNewFrame (via calling CleanupFrameReferences() and Destroy() on
1191 nsresult
AddChild(nsIFrame
* aNewFrame
,
1192 nsFrameItems
& aFrameItems
,
1193 nsIContent
* aContent
,
1194 nsStyleContext
* aStyleContext
,
1195 nsIFrame
* aParentFrame
,
1196 PRBool aCanBePositioned
= PR_TRUE
,
1197 PRBool aCanBeFloated
= PR_TRUE
,
1198 PRBool aIsOutOfFlowPopup
= PR_FALSE
,
1199 PRBool aInsertAfter
= PR_FALSE
,
1200 nsIFrame
* aInsertAfterFrame
= nsnull
);
1203 * Function to return the fixed-pos element list. Normally this will just hand back the
1204 * fixed-pos element list, but in case we're dealing with a transformed element that's
1205 * acting as an abs-pos and fixed-pos container, we'll hand back the abs-pos list. Callers should
1206 * use this function if they want to get the list acting as the fixed-pos item parent.
1208 nsAbsoluteItems
& GetFixedItems()
1210 return mFixedPosIsAbsPos
? mAbsoluteItems
: mFixedItems
;
1212 const nsAbsoluteItems
& GetFixedItems() const
1214 return mFixedPosIsAbsPos
? mAbsoluteItems
: mFixedItems
;
1218 friend class nsFrameConstructorSaveState
;
1221 * ProcessFrameInsertions takes the frames in aFrameItems and adds them as
1222 * kids to the aChildListName child list of |aFrameItems.containingBlock|.
1224 void ProcessFrameInsertions(nsAbsoluteItems
& aFrameItems
,
1225 nsIAtom
* aChildListName
);
1228 nsFrameConstructorState::nsFrameConstructorState(nsIPresShell
* aPresShell
,
1229 nsIFrame
* aFixedContainingBlock
,
1230 nsIFrame
* aAbsoluteContainingBlock
,
1231 nsIFrame
* aFloatContainingBlock
,
1232 nsILayoutHistoryState
* aHistoryState
)
1233 : mPresContext(aPresShell
->GetPresContext()),
1234 mPresShell(aPresShell
),
1235 mFrameManager(aPresShell
->FrameManager()),
1237 mRootBox(nsIRootBox::GetRootBox(aPresShell
)),
1238 mPopupItems(mRootBox
? mRootBox
->GetPopupSetFrame() : nsnull
),
1240 mFixedItems(aFixedContainingBlock
),
1241 mAbsoluteItems(aAbsoluteContainingBlock
),
1242 mFloatedItems(aFloatContainingBlock
),
1243 mFirstLetterStyle(PR_FALSE
),
1244 mFirstLineStyle(PR_FALSE
),
1245 // See PushAbsoluteContaningBlock below
1246 mFixedPosIsAbsPos(aAbsoluteContainingBlock
&&
1247 aAbsoluteContainingBlock
->GetStyleDisplay()->
1249 mFrameState(aHistoryState
),
1251 mAdditionalStateBits(0)
1253 MOZ_COUNT_CTOR(nsFrameConstructorState
);
1256 nsFrameConstructorState::nsFrameConstructorState(nsIPresShell
* aPresShell
,
1257 nsIFrame
* aFixedContainingBlock
,
1258 nsIFrame
* aAbsoluteContainingBlock
,
1259 nsIFrame
* aFloatContainingBlock
)
1260 : mPresContext(aPresShell
->GetPresContext()),
1261 mPresShell(aPresShell
),
1262 mFrameManager(aPresShell
->FrameManager()),
1264 mRootBox(nsIRootBox::GetRootBox(aPresShell
)),
1265 mPopupItems(mRootBox
? mRootBox
->GetPopupSetFrame() : nsnull
),
1267 mFixedItems(aFixedContainingBlock
),
1268 mAbsoluteItems(aAbsoluteContainingBlock
),
1269 mFloatedItems(aFloatContainingBlock
),
1270 mFirstLetterStyle(PR_FALSE
),
1271 mFirstLineStyle(PR_FALSE
),
1272 // See PushAbsoluteContaningBlock below
1273 mFixedPosIsAbsPos(aAbsoluteContainingBlock
&&
1274 aAbsoluteContainingBlock
->GetStyleDisplay()->
1277 mAdditionalStateBits(0)
1279 MOZ_COUNT_CTOR(nsFrameConstructorState
);
1280 mFrameState
= aPresShell
->GetDocument()->GetLayoutHistoryState();
1283 nsFrameConstructorState::~nsFrameConstructorState()
1285 // Frame order comparison functions only work properly when the placeholders
1286 // have been inserted into the frame tree. So for example if we have a new float
1287 // containing the placeholder for a new abs-pos frame, and we process the abs-pos
1288 // insertion first, then we won't be able to find the right place to insert in
1289 // in the abs-pos list. So put floats in first, because they can contain placeholders
1290 // for abs-pos and fixed-pos items whose containing blocks are outside the floats.
1291 // Then put abs-pos frames in, because they can contain placeholders for fixed-pos
1292 // items whose containing block is outside the abs-pos frames.
1293 MOZ_COUNT_DTOR(nsFrameConstructorState
);
1294 ProcessFrameInsertions(mFloatedItems
, nsGkAtoms::floatList
);
1295 ProcessFrameInsertions(mAbsoluteItems
, nsGkAtoms::absoluteList
);
1296 ProcessFrameInsertions(mFixedItems
, nsGkAtoms::fixedList
);
1298 ProcessFrameInsertions(mPopupItems
, nsGkAtoms::popupList
);
1303 AdjustAbsoluteContainingBlock(nsIFrame
* aContainingBlockIn
)
1305 if (!aContainingBlockIn
) {
1309 // Always use the container's first continuation. (Inline frames can have
1310 // non-fluid bidi continuations...)
1311 return aContainingBlockIn
->GetFirstContinuation();
1315 nsFrameConstructorState::PushAbsoluteContainingBlock(nsIFrame
* aNewAbsoluteContainingBlock
,
1316 nsFrameConstructorSaveState
& aSaveState
)
1318 aSaveState
.mItems
= &mAbsoluteItems
;
1319 aSaveState
.mSavedItems
= mAbsoluteItems
;
1320 aSaveState
.mChildListName
= nsGkAtoms::absoluteList
;
1321 aSaveState
.mState
= this;
1323 /* Store whether we're wiring the abs-pos and fixed-pos lists together. */
1324 aSaveState
.mFixedPosIsAbsPos
= &mFixedPosIsAbsPos
;
1325 aSaveState
.mSavedFixedPosIsAbsPos
= mFixedPosIsAbsPos
;
1328 nsAbsoluteItems(AdjustAbsoluteContainingBlock(aNewAbsoluteContainingBlock
));
1330 /* See if we're wiring the fixed-pos and abs-pos lists together. This happens iff
1331 * we're a transformed element.
1333 mFixedPosIsAbsPos
= (aNewAbsoluteContainingBlock
&&
1334 aNewAbsoluteContainingBlock
->GetStyleDisplay()->HasTransform());
1338 nsFrameConstructorState::PushFloatContainingBlock(nsIFrame
* aNewFloatContainingBlock
,
1339 nsFrameConstructorSaveState
& aSaveState
,
1340 PRBool aFirstLetterStyle
,
1341 PRBool aFirstLineStyle
)
1343 // XXXbz we should probably just be able to assert that
1344 // aNewFloatContainingBlock is a float containing block... see XXX comment at
1345 // the top of ProcessChildren.
1346 NS_PRECONDITION(!aNewFloatContainingBlock
||
1347 aNewFloatContainingBlock
->GetContentInsertionFrame()->
1348 IsFloatContainingBlock(),
1349 "Please push a real float containing block!");
1350 aSaveState
.mItems
= &mFloatedItems
;
1351 aSaveState
.mFirstLetterStyle
= &mFirstLetterStyle
;
1352 aSaveState
.mFirstLineStyle
= &mFirstLineStyle
;
1353 aSaveState
.mSavedItems
= mFloatedItems
;
1354 aSaveState
.mSavedFirstLetterStyle
= mFirstLetterStyle
;
1355 aSaveState
.mSavedFirstLineStyle
= mFirstLineStyle
;
1356 aSaveState
.mChildListName
= nsGkAtoms::floatList
;
1357 aSaveState
.mState
= this;
1358 mFloatedItems
= nsAbsoluteItems(aNewFloatContainingBlock
);
1359 mFirstLetterStyle
= aFirstLetterStyle
;
1360 mFirstLineStyle
= aFirstLineStyle
;
1364 nsFrameConstructorState::GetGeometricParent(const nsStyleDisplay
* aStyleDisplay
,
1365 nsIFrame
* aContentParentFrame
)
1367 NS_PRECONDITION(aStyleDisplay
, "Must have display struct!");
1369 // If there is no container for a fixed, absolute, or floating root
1370 // frame, we will ignore the positioning. This hack is originally
1371 // brought to you by the letter T: tables, since other roots don't
1372 // even call into this code. See bug 178855.
1374 // XXX Disabling positioning in this case is a hack. If one was so inclined,
1375 // one could support this either by (1) inserting a dummy block between the
1376 // table and the canvas or (2) teaching the canvas how to reflow positioned
1377 // elements. (1) has the usual problems when multiple frames share the same
1378 // content (notice all the special cases in this file dealing with inner
1379 // tables and outer tables which share the same content). (2) requires some
1380 // work and possible factoring.
1382 // XXXbz couldn't we just force position to "static" on roots and
1383 // float to "none"? That's OK per CSS 2.1, as far as I can tell.
1385 if (aStyleDisplay
->IsFloating() && mFloatedItems
.containingBlock
) {
1386 NS_ASSERTION(!aStyleDisplay
->IsAbsolutelyPositioned(),
1387 "Absolutely positioned _and_ floating?");
1388 return mFloatedItems
.containingBlock
;
1391 if (aStyleDisplay
->mPosition
== NS_STYLE_POSITION_ABSOLUTE
&&
1392 mAbsoluteItems
.containingBlock
) {
1393 return mAbsoluteItems
.containingBlock
;
1396 if (aStyleDisplay
->mPosition
== NS_STYLE_POSITION_FIXED
&&
1397 GetFixedItems().containingBlock
) {
1398 return GetFixedItems().containingBlock
;
1401 return aContentParentFrame
;
1405 nsFrameConstructorState::AddChild(nsIFrame
* aNewFrame
,
1406 nsFrameItems
& aFrameItems
,
1407 nsIContent
* aContent
,
1408 nsStyleContext
* aStyleContext
,
1409 nsIFrame
* aParentFrame
,
1410 PRBool aCanBePositioned
,
1411 PRBool aCanBeFloated
,
1412 PRBool aIsOutOfFlowPopup
,
1413 PRBool aInsertAfter
,
1414 nsIFrame
* aInsertAfterFrame
)
1416 const nsStyleDisplay
* disp
= aNewFrame
->GetStyleDisplay();
1418 // The comments in GetGeometricParent regarding root table frames
1419 // all apply here, unfortunately.
1421 PRBool needPlaceholder
= PR_FALSE
;
1422 nsFrameItems
* frameItems
= &aFrameItems
;
1424 if (NS_UNLIKELY(aIsOutOfFlowPopup
)) {
1425 NS_ASSERTION(aNewFrame
->GetParent() == mPopupItems
.containingBlock
,
1426 "Popup whose parent is not the popup containing block?");
1427 NS_ASSERTION(mPopupItems
.containingBlock
, "Must have a popup set frame!");
1428 needPlaceholder
= PR_TRUE
;
1429 frameItems
= &mPopupItems
;
1433 if (aCanBeFloated
&& disp
->IsFloating() &&
1434 mFloatedItems
.containingBlock
) {
1435 NS_ASSERTION(aNewFrame
->GetParent() == mFloatedItems
.containingBlock
,
1436 "Float whose parent is not the float containing block?");
1437 needPlaceholder
= PR_TRUE
;
1438 frameItems
= &mFloatedItems
;
1440 else if (aCanBePositioned
) {
1441 if (disp
->mPosition
== NS_STYLE_POSITION_ABSOLUTE
&&
1442 mAbsoluteItems
.containingBlock
) {
1443 NS_ASSERTION(aNewFrame
->GetParent() == mAbsoluteItems
.containingBlock
,
1444 "Abs pos whose parent is not the abs pos containing block?");
1445 needPlaceholder
= PR_TRUE
;
1446 frameItems
= &mAbsoluteItems
;
1448 if (disp
->mPosition
== NS_STYLE_POSITION_FIXED
&&
1449 GetFixedItems().containingBlock
) {
1450 NS_ASSERTION(aNewFrame
->GetParent() == GetFixedItems().containingBlock
,
1451 "Fixed pos whose parent is not the fixed pos containing block?");
1452 needPlaceholder
= PR_TRUE
;
1453 frameItems
= &GetFixedItems();
1457 if (needPlaceholder
) {
1458 NS_ASSERTION(frameItems
!= &aFrameItems
,
1459 "Putting frame in-flow _and_ want a placeholder?");
1460 nsIFrame
* placeholderFrame
;
1462 nsCSSFrameConstructor::CreatePlaceholderFrameFor(mPresShell
,
1469 if (NS_FAILED(rv
)) {
1470 // Note that aNewFrame could be the top frame for a scrollframe setup,
1471 // hence already set as the primary frame. So we have to clean up here.
1472 // But it shouldn't have any out-of-flow kids.
1473 // XXXbz Maybe add a utility function to assert that?
1474 CleanupFrameReferences(mFrameManager
, aNewFrame
);
1475 aNewFrame
->Destroy();
1479 placeholderFrame
->AddStateBits(mAdditionalStateBits
);
1480 // Add the placeholder frame to the flow
1481 aFrameItems
.AddChild(placeholderFrame
);
1485 NS_ASSERTION(aNewFrame
->GetParent() == aParentFrame
,
1486 "In-flow frame has wrong parent");
1491 frameItems
->InsertChildAfter(aNewFrame
, aInsertAfterFrame
);
1493 frameItems
->AddChild(aNewFrame
);
1496 // Now add the special siblings too.
1497 nsIFrame
* specialSibling
= aNewFrame
;
1498 while (specialSibling
&& IsFrameSpecial(specialSibling
)) {
1499 specialSibling
= GetSpecialSibling(specialSibling
);
1500 if (specialSibling
) {
1501 NS_ASSERTION(frameItems
== &aFrameItems
,
1502 "IB split ending up in an out-of-flow childlist?");
1503 frameItems
->AddChild(specialSibling
);
1511 nsFrameConstructorState::ProcessFrameInsertions(nsAbsoluteItems
& aFrameItems
,
1512 nsIAtom
* aChildListName
)
1514 #define NS_NONXUL_LIST_TEST (&aFrameItems == &mFloatedItems && \
1515 aChildListName == nsGkAtoms::floatList) || \
1516 (&aFrameItems == &mAbsoluteItems && \
1517 aChildListName == nsGkAtoms::absoluteList) || \
1518 (&aFrameItems == &mFixedItems && \
1519 aChildListName == nsGkAtoms::fixedList)
1521 NS_PRECONDITION(NS_NONXUL_LIST_TEST
||
1522 (&aFrameItems
== &mPopupItems
&&
1523 aChildListName
== nsGkAtoms::popupList
),
1524 "Unexpected aFrameItems/aChildListName combination");
1526 NS_PRECONDITION(NS_NONXUL_LIST_TEST
,
1527 "Unexpected aFrameItems/aChildListName combination");
1530 nsIFrame
* firstNewFrame
= aFrameItems
.childList
;
1532 if (!firstNewFrame
) {
1536 nsIFrame
* containingBlock
= aFrameItems
.containingBlock
;
1538 NS_ASSERTION(containingBlock
,
1539 "Child list without containing block?");
1541 // Insert the frames hanging out in aItems. We can use SetInitialChildList()
1542 // if the containing block hasn't been reflown yet (so NS_FRAME_FIRST_REFLOW
1543 // is set) and doesn't have any frames in the aChildListName child list yet.
1544 nsIFrame
* firstChild
= containingBlock
->GetFirstChild(aChildListName
);
1545 nsresult rv
= NS_OK
;
1546 if (!firstChild
&& (containingBlock
->GetStateBits() & NS_FRAME_FIRST_REFLOW
)) {
1547 rv
= containingBlock
->SetInitialChildList(aChildListName
, firstNewFrame
);
1549 // Note that whether the frame construction context is doing an append or
1550 // not is not helpful here, since it could be appending to some frame in
1551 // the middle of the document, which means we're not necessarily
1552 // appending to the children of the containing block.
1554 // We need to make sure the 'append to the end of document' case is fast.
1555 // So first test the last child of the containing block
1556 nsIFrame
* lastChild
= nsLayoutUtils::GetLastSibling(firstChild
);
1558 // CompareTreePosition uses placeholder hierarchy for out of flow frames,
1559 // so this will make out-of-flows respect the ordering of placeholders,
1560 // which is great because it takes care of anonymous content.
1562 nsLayoutUtils::CompareTreePosition(lastChild
, firstNewFrame
, containingBlock
) < 0) {
1563 // no lastChild, or lastChild comes before the new children, so just append
1564 rv
= containingBlock
->AppendFrames(aChildListName
, firstNewFrame
);
1566 nsIFrame
* insertionPoint
= nsnull
;
1567 // try the other children
1568 for (nsIFrame
* f
= firstChild
; f
!= lastChild
; f
= f
->GetNextSibling()) {
1570 nsLayoutUtils::CompareTreePosition(f
, firstNewFrame
, containingBlock
);
1572 // f comes after the new children, so stop here and insert after
1573 // the previous frame
1579 rv
= containingBlock
->InsertFrames(aChildListName
, insertionPoint
,
1583 aFrameItems
.childList
= nsnull
;
1584 // XXXbz And if NS_FAILED(rv), what? I guess we need to clean up the list
1585 // and deal with all the placeholders... but what if the placeholders aren't
1586 // in the document yet? Could that happen?
1587 NS_ASSERTION(NS_SUCCEEDED(rv
), "Frames getting lost!");
1591 nsFrameConstructorSaveState::nsFrameConstructorSaveState()
1593 mFirstLetterStyle(nsnull
),
1594 mFirstLineStyle(nsnull
),
1595 mFixedPosIsAbsPos(nsnull
),
1596 mSavedItems(nsnull
),
1597 mSavedFirstLetterStyle(PR_FALSE
),
1598 mSavedFirstLineStyle(PR_FALSE
),
1599 mSavedFixedPosIsAbsPos(PR_FALSE
),
1600 mChildListName(nsnull
),
1605 nsFrameConstructorSaveState::~nsFrameConstructorSaveState()
1607 // Restore the state
1609 NS_ASSERTION(mState
, "Can't have mItems set without having a state!");
1610 mState
->ProcessFrameInsertions(*mItems
, mChildListName
);
1611 *mItems
= mSavedItems
;
1613 // We've transferred the child list, so drop the pointer we held to it.
1614 // Note that this only matters for the assert in ~nsAbsoluteItems.
1615 mSavedItems
.childList
= nsnull
;
1618 if (mFirstLetterStyle
) {
1619 *mFirstLetterStyle
= mSavedFirstLetterStyle
;
1621 if (mFirstLineStyle
) {
1622 *mFirstLineStyle
= mSavedFirstLineStyle
;
1624 if (mFixedPosIsAbsPos
) {
1625 *mFixedPosIsAbsPos
= mSavedFixedPosIsAbsPos
;
1630 PRBool
IsBorderCollapse(nsIFrame
* aFrame
)
1632 for (nsIFrame
* frame
= aFrame
; frame
; frame
= frame
->GetParent()) {
1633 if (nsGkAtoms::tableFrame
== frame
->GetType()) {
1634 return ((nsTableFrame
*)frame
)->IsBorderCollapse();
1637 NS_ASSERTION(PR_FALSE
, "program error");
1642 * Utility method, called from MoveChildrenTo(), that recursively
1643 * descends down the frame hierarchy looking for floating frames that
1644 * need parent pointer adjustments to account for the containment block
1645 * changes that could occur as the result of the reparenting done in
1649 AdjustFloatParentPtrs(nsIFrame
* aFrame
,
1650 nsFrameConstructorState
& aState
,
1651 nsFrameConstructorState
& aOuterState
)
1653 NS_PRECONDITION(aFrame
, "must have frame to work with");
1655 nsIFrame
*outOfFlowFrame
= nsPlaceholderFrame::GetRealFrameFor(aFrame
);
1656 if (outOfFlowFrame
!= aFrame
) {
1657 if (outOfFlowFrame
->GetStyleDisplay()->IsFloating()) {
1658 // Update the parent pointer for outOfFlowFrame since its
1659 // containing block has changed as the result of reparenting
1660 // and move it from the outer state to the inner, bug 307277.
1662 nsIFrame
*parent
= aState
.mFloatedItems
.containingBlock
;
1663 NS_ASSERTION(parent
, "Should have float containing block here!");
1664 NS_ASSERTION(outOfFlowFrame
->GetParent() == aOuterState
.mFloatedItems
.containingBlock
,
1665 "expected the float to be a child of the outer CB");
1667 if (aOuterState
.mFloatedItems
.RemoveChild(outOfFlowFrame
, nsnull
)) {
1668 aState
.mFloatedItems
.AddChild(outOfFlowFrame
);
1670 NS_NOTREACHED("float wasn't in the outer state float list");
1673 outOfFlowFrame
->SetParent(parent
);
1674 if (outOfFlowFrame
->GetStateBits() &
1675 (NS_FRAME_HAS_VIEW
| NS_FRAME_HAS_CHILD_WITH_VIEW
)) {
1676 // We don't need to walk up the tree, since we're doing this
1678 parent
->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW
);
1682 // All out-of-flows are automatically float containing blocks, so we're
1687 if (aFrame
->IsFloatContainingBlock()) {
1688 // No need to recurse further; floats whose placeholders are
1689 // inside a block already have the right parent.
1693 // Dive down into children to see if any of their
1694 // placeholders need adjusting.
1695 nsIFrame
*childFrame
= aFrame
->GetFirstChild(nsnull
);
1696 while (childFrame
) {
1697 // XXX_kin: Do we need to prevent descent into anonymous content here?
1699 AdjustFloatParentPtrs(childFrame
, aState
, aOuterState
);
1700 childFrame
= childFrame
->GetNextSibling();
1705 * Moves frames to a new parent, updating the style context and propagating
1706 * relevant frame state bits. |aState| may be null, in which case the parent
1707 * pointers of out-of-flow frames will remain untouched.
1710 MoveChildrenTo(nsFrameManager
* aFrameManager
,
1711 nsIFrame
* aNewParent
,
1712 nsIFrame
* aFrameList
,
1713 nsIFrame
* aFrameListEnd
,
1714 nsFrameConstructorState
* aState
,
1715 nsFrameConstructorState
* aOuterState
)
1717 PRBool setHasChildWithView
= PR_FALSE
;
1719 while (aFrameList
&& aFrameList
!= aFrameListEnd
) {
1720 if (!setHasChildWithView
1721 && (aFrameList
->GetStateBits() & (NS_FRAME_HAS_VIEW
| NS_FRAME_HAS_CHILD_WITH_VIEW
))) {
1722 setHasChildWithView
= PR_TRUE
;
1725 aFrameList
->SetParent(aNewParent
);
1727 // If aState is not null, the caller expects us to make adjustments so that
1728 // floats whose placeholders are descendants of frames in aFrameList point
1729 // to the correct parent.
1731 NS_ASSERTION(aOuterState
, "need an outer state too");
1732 AdjustFloatParentPtrs(aFrameList
, *aState
, *aOuterState
);
1735 aFrameList
= aFrameList
->GetNextSibling();
1738 if (setHasChildWithView
) {
1740 aNewParent
->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW
);
1741 aNewParent
= aNewParent
->GetParent();
1742 } while (aNewParent
&&
1743 !(aNewParent
->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW
));
1747 // -----------------------------------------------------------
1750 // Structure used to ensure that bindings are properly enqueued in the
1751 // binding manager's attached queue.
1752 struct NS_STACK_CLASS nsAutoEnqueueBinding
1754 nsAutoEnqueueBinding(nsIDocument
* aDocument
) :
1755 mDocument(aDocument
)
1758 ~nsAutoEnqueueBinding();
1760 nsRefPtr
<nsXBLBinding
> mBinding
;
1762 nsIDocument
* mDocument
;
1765 nsAutoEnqueueBinding::~nsAutoEnqueueBinding()
1768 mDocument
->BindingManager()->AddToAttachedQueue(mBinding
);
1773 // Helper function that determines the child list name that aChildFrame
1776 GetChildListNameFor(nsIFrame
* aChildFrame
)
1780 if (aChildFrame
->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER
) {
1781 listName
= nsGkAtoms::overflowContainersList
;
1783 // See if the frame is moved out of the flow
1784 else if (aChildFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
1785 // Look at the style information to tell
1786 const nsStyleDisplay
* disp
= aChildFrame
->GetStyleDisplay();
1788 if (NS_STYLE_POSITION_ABSOLUTE
== disp
->mPosition
) {
1789 listName
= nsGkAtoms::absoluteList
;
1790 } else if (NS_STYLE_POSITION_FIXED
== disp
->mPosition
) {
1791 if (nsLayoutUtils::IsReallyFixedPos(aChildFrame
)) {
1792 listName
= nsGkAtoms::fixedList
;
1794 listName
= nsGkAtoms::absoluteList
;
1797 } else if (NS_STYLE_DISPLAY_POPUP
== disp
->mDisplay
) {
1798 // Out-of-flows that are DISPLAY_POPUP must be kids of the root popup set
1800 nsIFrame
* parent
= aChildFrame
->GetParent();
1801 NS_ASSERTION(parent
&& parent
->GetType() == nsGkAtoms::popupSetFrame
,
1802 "Unexpected parent");
1805 // XXX FIXME: Bug 350740
1806 // Return here, because the postcondition for this function actually
1807 // fails for this case, since the popups are not in a "real" frame list
1808 // in the popup set.
1809 return nsGkAtoms::popupList
;
1812 NS_ASSERTION(aChildFrame
->GetStyleDisplay()->IsFloating(),
1813 "not a floated frame");
1814 listName
= nsGkAtoms::floatList
;
1822 // Verify that the frame is actually in that child list or in the
1823 // corresponding overflow list.
1824 nsIFrame
* parent
= aChildFrame
->GetParent();
1825 PRBool found
= nsFrameList(parent
->GetFirstChild(listName
))
1826 .ContainsFrame(aChildFrame
);
1828 if (!(aChildFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)) {
1829 found
= nsFrameList(parent
->GetFirstChild(nsGkAtoms::overflowList
))
1830 .ContainsFrame(aChildFrame
);
1832 else if (aChildFrame
->GetStyleDisplay()->IsFloating()) {
1833 found
= nsFrameList(parent
->GetFirstChild(nsGkAtoms::overflowOutOfFlowList
))
1834 .ContainsFrame(aChildFrame
);
1836 // else it's positioned and should have been on the 'listName' child list.
1837 NS_POSTCONDITION(found
, "not in child list");
1844 //----------------------------------------------------------------------
1846 nsCSSFrameConstructor::nsCSSFrameConstructor(nsIDocument
*aDocument
,
1847 nsIPresShell
*aPresShell
)
1848 : mDocument(aDocument
)
1849 , mPresShell(aPresShell
)
1850 , mInitialContainingBlock(nsnull
)
1851 , mRootElementStyleFrame(nsnull
)
1852 , mFixedContainingBlock(nsnull
)
1853 , mDocElementContainingBlock(nsnull
)
1854 , mGfxScrollFrame(nsnull
)
1855 , mPageSequenceFrame(nsnull
)
1857 , mFocusSuppressCount(0)
1858 , mQuotesDirty(PR_FALSE
)
1859 , mCountersDirty(PR_FALSE
)
1860 , mIsDestroyingFrameTree(PR_FALSE
)
1861 , mRebuildAllStyleData(PR_FALSE
)
1862 , mHasRootAbsPosContainingBlock(PR_FALSE
)
1863 , mHoverGeneration(0)
1864 , mRebuildAllExtraHint(nsChangeHint(0))
1866 if (!gGotXBLFormPrefs
) {
1867 gGotXBLFormPrefs
= PR_TRUE
;
1870 nsContentUtils::GetBoolPref("nglayout.debug.enable_xbl_forms");
1873 // XXXbz this should be in Init() or something!
1874 if (!mPendingRestyles
.Init()) {
1879 static PRBool gFirstTime
= PR_TRUE
;
1881 gFirstTime
= PR_FALSE
;
1882 char* flags
= PR_GetEnv("GECKO_FRAMECTOR_DEBUG_FLAGS");
1884 PRBool error
= PR_FALSE
;
1886 char* comma
= PL_strchr(flags
, ',');
1890 PRBool found
= PR_FALSE
;
1891 FrameCtorDebugFlags
* flag
= gFlags
;
1892 FrameCtorDebugFlags
* limit
= gFlags
+ NUM_DEBUG_FLAGS
;
1893 while (flag
< limit
) {
1894 if (PL_strcasecmp(flag
->name
, flags
) == 0) {
1895 *(flag
->on
) = PR_TRUE
;
1896 printf("nsCSSFrameConstructor: setting %s debug flag on\n", flag
->name
);
1914 printf("Here are the available GECKO_FRAMECTOR_DEBUG_FLAGS:\n");
1915 FrameCtorDebugFlags
* flag
= gFlags
;
1916 FrameCtorDebugFlags
* limit
= gFlags
+ NUM_DEBUG_FLAGS
;
1917 while (flag
< limit
) {
1918 printf(" %s\n", flag
->name
);
1921 printf("Note: GECKO_FRAMECTOR_DEBUG_FLAGS is a comma separated list of flag\n");
1922 printf("names (no whitespace)\n");
1929 nsIXBLService
* nsCSSFrameConstructor::GetXBLService()
1932 nsresult rv
= CallGetService("@mozilla.org/xbl;1", &gXBLService
);
1934 gXBLService
= nsnull
;
1941 nsCSSFrameConstructor::NotifyDestroyingFrame(nsIFrame
* aFrame
)
1943 NS_PRECONDITION(mUpdateCount
!= 0,
1944 "Should be in an update while destroying frames");
1946 if (aFrame
->GetStateBits() & NS_FRAME_GENERATED_CONTENT
) {
1947 if (mQuoteList
.DestroyNodesFor(aFrame
))
1951 if (mCounterManager
.DestroyNodesFor(aFrame
)) {
1952 // Technically we don't need to update anything if we destroyed only
1953 // USE nodes. However, this is unlikely to happen in the real world
1954 // since USE nodes generally go along with INCREMENT nodes.
1959 struct nsGenConInitializer
{
1960 nsAutoPtr
<nsGenConNode
> mNode
;
1961 nsGenConList
* mList
;
1962 void (nsCSSFrameConstructor::*mDirtyAll
)();
1964 nsGenConInitializer(nsGenConNode
* aNode
, nsGenConList
* aList
,
1965 void (nsCSSFrameConstructor::*aDirtyAll
)())
1966 : mNode(aNode
), mList(aList
), mDirtyAll(aDirtyAll
) {}
1970 DestroyGenConInitializer(void* aFrame
,
1971 nsIAtom
* aPropertyName
,
1972 void* aPropertyValue
,
1975 delete static_cast<nsGenConInitializer
*>(aPropertyValue
);
1978 already_AddRefed
<nsIContent
>
1979 nsCSSFrameConstructor::CreateGenConTextNode(const nsString
& aString
,
1980 nsCOMPtr
<nsIDOMCharacterData
>* aText
,
1981 nsGenConInitializer
* aInitializer
)
1983 nsCOMPtr
<nsIContent
> content
;
1984 NS_NewTextNode(getter_AddRefs(content
), mDocument
->NodeInfoManager());
1986 // XXX The quotes/counters code doesn't like the text pointer
1987 // being null in case of dynamic changes!
1988 NS_ASSERTION(!aText
, "this OOM case isn't handled very well");
1991 content
->SetText(aString
, PR_FALSE
);
1993 *aText
= do_QueryInterface(content
);
1996 content
->SetProperty(nsGkAtoms::genConInitializerProperty
, aInitializer
,
1997 DestroyGenConInitializer
);
1999 return content
.forget();
2002 already_AddRefed
<nsIContent
>
2003 nsCSSFrameConstructor::CreateGeneratedContent(nsIContent
* aParentContent
,
2004 nsStyleContext
* aStyleContext
,
2005 PRUint32 aContentIndex
)
2007 // Get the content value
2008 const nsStyleContentData
&data
=
2009 aStyleContext
->GetStyleContent()->ContentAt(aContentIndex
);
2010 nsStyleContentType type
= data
.mType
;
2012 if (eStyleContentType_Image
== type
) {
2013 if (!data
.mContent
.mImage
) {
2014 // CSS had something specified that couldn't be converted to an
2019 // Create an image content object and pass it the image request.
2020 // XXX Check if it's an image type we can handle...
2022 nsCOMPtr
<nsINodeInfo
> nodeInfo
;
2023 nodeInfo
= mDocument
->NodeInfoManager()->GetNodeInfo(nsGkAtoms::mozgeneratedcontentimage
, nsnull
,
2024 kNameSpaceID_XHTML
);
2026 nsCOMPtr
<nsIContent
> content
;
2027 NS_NewGenConImageContent(getter_AddRefs(content
), nodeInfo
,
2028 data
.mContent
.mImage
);
2029 return content
.forget();
2033 case eStyleContentType_String
:
2034 return CreateGenConTextNode(nsDependentString(data
.mContent
.mString
), nsnull
,
2037 case eStyleContentType_Attr
:
2039 nsCOMPtr
<nsIAtom
> attrName
;
2040 PRInt32 attrNameSpace
= kNameSpaceID_None
;
2041 nsAutoString
contentString(data
.mContent
.mString
);
2042 PRInt32 barIndex
= contentString
.FindChar('|'); // CSS namespace delimiter
2043 if (-1 != barIndex
) {
2044 nsAutoString nameSpaceVal
;
2045 contentString
.Left(nameSpaceVal
, barIndex
);
2047 attrNameSpace
= nameSpaceVal
.ToInteger(&error
, 10);
2048 contentString
.Cut(0, barIndex
+ 1);
2049 if (contentString
.Length()) {
2050 attrName
= do_GetAtom(contentString
);
2054 attrName
= do_GetAtom(contentString
);
2061 nsCOMPtr
<nsIContent
> content
;
2062 NS_NewAttributeContent(mDocument
->NodeInfoManager(),
2063 attrNameSpace
, attrName
, getter_AddRefs(content
));
2064 return content
.forget();
2067 case eStyleContentType_Counter
:
2068 case eStyleContentType_Counters
:
2070 nsCSSValue::Array
* counters
= data
.mContent
.mCounters
;
2071 nsCounterList
* counterList
= mCounterManager
.CounterListFor(
2072 nsDependentString(counters
->Item(0).GetStringBufferValue()));
2076 nsCounterUseNode
* node
=
2077 new nsCounterUseNode(counters
, aContentIndex
,
2078 type
== eStyleContentType_Counters
);
2082 nsGenConInitializer
* initializer
=
2083 new nsGenConInitializer(node
, counterList
,
2084 &nsCSSFrameConstructor::CountersDirty
);
2085 return CreateGenConTextNode(EmptyString(), &node
->mText
, initializer
);
2088 case eStyleContentType_Image
:
2089 NS_NOTREACHED("handled by if above");
2092 case eStyleContentType_OpenQuote
:
2093 case eStyleContentType_CloseQuote
:
2094 case eStyleContentType_NoOpenQuote
:
2095 case eStyleContentType_NoCloseQuote
:
2098 new nsQuoteNode(type
, aContentIndex
);
2102 nsGenConInitializer
* initializer
=
2103 new nsGenConInitializer(node
, &mQuoteList
,
2104 &nsCSSFrameConstructor::QuotesDirty
);
2105 return CreateGenConTextNode(EmptyString(), &node
->mText
, initializer
);
2108 case eStyleContentType_AltContent
:
2110 // Use the "alt" attribute; if that fails and the node is an HTML
2111 // <input>, try the value attribute and then fall back to some default
2112 // localized text we have.
2113 // XXX what if the 'alt' attribute is added later, how will we
2114 // detect that and do the right thing here?
2115 if (aParentContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::alt
)) {
2116 nsCOMPtr
<nsIContent
> content
;
2117 NS_NewAttributeContent(mDocument
->NodeInfoManager(),
2118 kNameSpaceID_None
, nsGkAtoms::alt
, getter_AddRefs(content
));
2119 return content
.forget();
2122 if (aParentContent
->IsNodeOfType(nsINode::eHTML
) &&
2123 aParentContent
->NodeInfo()->Equals(nsGkAtoms::input
)) {
2124 if (aParentContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::value
)) {
2125 nsCOMPtr
<nsIContent
> content
;
2126 NS_NewAttributeContent(mDocument
->NodeInfoManager(),
2127 kNameSpaceID_None
, nsGkAtoms::value
, getter_AddRefs(content
));
2128 return content
.forget();
2132 nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES
,
2134 return CreateGenConTextNode(temp
, nsnull
, nsnull
);
2144 static void DestroyContent(void *aObject
,
2145 nsIAtom
*aPropertyName
,
2146 void *aPropertyValue
,
2149 nsIContent
* content
= static_cast<nsIContent
*>(aPropertyValue
);
2150 content
->UnbindFromTree();
2151 NS_RELEASE(content
);
2155 * aParentFrame - the frame that should be the parent of the generated
2156 * content. This is the frame for the corresponding content node,
2157 * which must not be a leaf frame.
2159 * Any frames created are added to aFrameItems (or possibly left
2160 * in the table pseudoframe state in aState).
2162 * We create an XML element (tag _moz_generated_content_before or
2163 * _moz_generated_content_after) representing the pseudoelement. We
2164 * create a DOM node for each 'content' item and make those nodes the
2165 * children of the XML element. Then we create a frame subtree for
2166 * the XML element as if it were a regular child of
2167 * aParentFrame/aParentContent, giving the XML element the ::before or
2171 nsCSSFrameConstructor::CreateGeneratedContentFrame(nsFrameConstructorState
& aState
,
2172 nsIFrame
* aParentFrame
,
2173 nsIContent
* aParentContent
,
2174 nsStyleContext
* aStyleContext
,
2175 nsIAtom
* aPseudoElement
,
2176 nsFrameItems
& aFrameItems
)
2178 if (!aParentContent
->IsNodeOfType(nsINode::eELEMENT
))
2181 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
2183 // Probe for the existence of the pseudo-element
2184 nsRefPtr
<nsStyleContext
> pseudoStyleContext
;
2185 pseudoStyleContext
= styleSet
->ProbePseudoStyleFor(aParentContent
,
2188 if (!pseudoStyleContext
)
2190 // |ProbePseudoStyleFor| checked the 'display' property and the
2191 // |ContentCount()| of the 'content' property for us.
2192 nsCOMPtr
<nsINodeInfo
> nodeInfo
;
2193 nsIAtom
* elemName
= aPseudoElement
== nsCSSPseudoElements::before
?
2194 nsGkAtoms::mozgeneratedcontentbefore
: nsGkAtoms::mozgeneratedcontentafter
;
2195 nodeInfo
= mDocument
->NodeInfoManager()->GetNodeInfo(elemName
, nsnull
,
2197 nsIContent
* container
;
2198 nsresult rv
= NS_NewXMLElement(&container
, nodeInfo
);
2201 container
->SetNativeAnonymous();
2202 // Transfer ownership to the frame
2203 aParentFrame
->SetProperty(aPseudoElement
, container
, DestroyContent
);
2205 rv
= container
->BindToTree(mDocument
, aParentContent
, aParentContent
, PR_TRUE
);
2206 if (NS_FAILED(rv
)) {
2207 container
->UnbindFromTree();
2211 PRUint32 contentCount
= pseudoStyleContext
->GetStyleContent()->ContentCount();
2212 for (PRUint32 contentIndex
= 0; contentIndex
< contentCount
; contentIndex
++) {
2213 nsCOMPtr
<nsIContent
> content
=
2214 CreateGeneratedContent(aParentContent
, pseudoStyleContext
, contentIndex
);
2216 container
->AppendChildTo(content
, PR_FALSE
);
2220 nsFrameState savedStateBits
= aState
.mAdditionalStateBits
;
2221 // Ensure that frames created here are all tagged with
2222 // NS_FRAME_GENERATED_CONTENT.
2223 aState
.mAdditionalStateBits
|= NS_FRAME_GENERATED_CONTENT
;
2225 ConstructFrameInternal(aState
, container
, aParentFrame
,
2226 elemName
, kNameSpaceID_None
, pseudoStyleContext
, aFrameItems
, PR_TRUE
);
2227 aState
.mAdditionalStateBits
= savedStateBits
;
2231 nsCSSFrameConstructor::CreateInputFrame(nsFrameConstructorState
& aState
,
2232 nsIContent
* aContent
,
2233 nsIFrame
* aParentFrame
,
2235 nsStyleContext
* aStyleContext
,
2237 const nsStyleDisplay
* aStyleDisplay
,
2238 PRBool
& aFrameHasBeenInitialized
,
2239 PRBool
& aAddedToFrameList
,
2240 nsFrameItems
& aFrameItems
,
2241 PRBool aHasPseudoParent
)
2243 // Make sure to keep IsSpecialContent in synch with this code
2245 // Note: do not do anything in this method that assumes pseudo-frames have
2246 // been processed. If you feel the urge to do something like that, fix
2247 // callers accordingly.
2248 nsCOMPtr
<nsIFormControl
> control
= do_QueryInterface(aContent
);
2250 NS_ERROR("input doesn't implement nsIFormControl?");
2254 switch (control
->GetType()) {
2255 case NS_FORM_INPUT_SUBMIT
:
2256 case NS_FORM_INPUT_RESET
:
2257 case NS_FORM_INPUT_BUTTON
:
2260 return NS_OK
; // update IsSpecialContent if this becomes functional
2262 nsresult rv
= ConstructButtonFrame(aState
, aContent
, aParentFrame
,
2263 aTag
, aStyleContext
, aFrame
,
2264 aStyleDisplay
, aFrameItems
,
2266 aAddedToFrameList
= PR_TRUE
;
2267 aFrameHasBeenInitialized
= PR_TRUE
;
2271 case NS_FORM_INPUT_CHECKBOX
:
2273 return NS_OK
; // see comment above
2274 return ConstructCheckboxControlFrame(aFrame
, aContent
, aStyleContext
);
2276 case NS_FORM_INPUT_RADIO
:
2278 return NS_OK
; // see comment above
2279 return ConstructRadioControlFrame(aFrame
, aContent
, aStyleContext
);
2281 case NS_FORM_INPUT_FILE
:
2283 *aFrame
= NS_NewFileControlFrame(mPresShell
, aStyleContext
);
2286 // The (block-like) file control frame should have a space manager
2287 (*aFrame
)->AddStateBits(NS_BLOCK_SPACE_MGR
);
2291 return NS_ERROR_OUT_OF_MEMORY
;
2295 case NS_FORM_INPUT_HIDDEN
:
2296 return NS_OK
; // this does not create a frame so it needs special handling
2297 // in IsSpecialContent
2299 case NS_FORM_INPUT_IMAGE
:
2300 return CreateHTMLImageFrame(aContent
, aStyleContext
,
2301 NS_NewImageControlFrame
, aFrame
);
2303 case NS_FORM_INPUT_TEXT
:
2304 case NS_FORM_INPUT_PASSWORD
:
2306 *aFrame
= NS_NewTextControlFrame(mPresShell
, aStyleContext
);
2308 return NS_UNLIKELY(!*aFrame
) ? NS_ERROR_OUT_OF_MEMORY
: NS_OK
;
2312 NS_ASSERTION(0, "Unknown input type!");
2313 return NS_ERROR_INVALID_ARG
;
2318 nsCSSFrameConstructor::CreateHTMLImageFrame(nsIContent
* aContent
,
2319 nsStyleContext
* aStyleContext
,
2320 ImageFrameCreatorFunc aFunc
,
2325 // Make sure to keep IsSpecialContent in synch with this code
2326 if (nsImageFrame::ShouldCreateImageFrameFor(aContent
, aStyleContext
)) {
2327 *aFrame
= (*aFunc
)(mPresShell
, aStyleContext
);
2329 if (NS_UNLIKELY(!*aFrame
))
2330 return NS_ERROR_OUT_OF_MEMORY
;
2337 TextIsOnlyWhitespace(nsIContent
* aContent
)
2339 return aContent
->IsNodeOfType(nsINode::eTEXT
) &&
2340 aContent
->TextIsOnlyWhitespace();
2343 /****************************************************
2344 ** BEGIN TABLE SECTION
2345 ****************************************************/
2347 // The term pseudo frame is being used instead of anonymous frame, since anonymous
2348 // frame has been used elsewhere to refer to frames that have generated content
2350 // aIncludeSpecial applies to captions, col groups, cols and cells.
2351 // These do not generate pseudo frame wrappers for foreign children.
2354 IsTableRelated(PRUint8 aDisplay
,
2355 PRBool aIncludeSpecial
)
2357 if ((aDisplay
== NS_STYLE_DISPLAY_TABLE
) ||
2358 (aDisplay
== NS_STYLE_DISPLAY_INLINE_TABLE
) ||
2359 (aDisplay
== NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
) ||
2360 (aDisplay
== NS_STYLE_DISPLAY_TABLE_ROW_GROUP
) ||
2361 (aDisplay
== NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
) ||
2362 (aDisplay
== NS_STYLE_DISPLAY_TABLE_ROW
)) {
2365 else if (aIncludeSpecial
&&
2366 ((aDisplay
== NS_STYLE_DISPLAY_TABLE_CAPTION
) ||
2367 (aDisplay
== NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
) ||
2368 (aDisplay
== NS_STYLE_DISPLAY_TABLE_COLUMN
) ||
2369 (aDisplay
== NS_STYLE_DISPLAY_TABLE_CELL
))) {
2372 else return PR_FALSE
;
2376 IsTableRelated(nsIAtom
* aParentType
,
2377 PRBool aIncludeSpecial
)
2379 if ((nsGkAtoms::tableFrame
== aParentType
) ||
2380 (nsGkAtoms::tableRowGroupFrame
== aParentType
) ||
2381 (nsGkAtoms::tableRowFrame
== aParentType
)) {
2384 else if (aIncludeSpecial
&&
2385 ((nsGkAtoms::tableCaptionFrame
== aParentType
) ||
2386 (nsGkAtoms::tableColGroupFrame
== aParentType
) ||
2387 (nsGkAtoms::tableColFrame
== aParentType
) ||
2388 IS_TABLE_CELL(aParentType
))) {
2391 else return PR_FALSE
;
2395 AdjustCaptionParentFrame(nsIFrame
* aParentFrame
)
2397 if (nsGkAtoms::tableFrame
== aParentFrame
->GetType()) {
2398 return aParentFrame
->GetParent();;
2400 return aParentFrame
;
2404 * If the parent frame is a |tableFrame| and the child is a
2405 * |captionFrame|, then we want to insert the frames beneath the
2406 * |tableFrame|'s parent frame. Returns |PR_TRUE| if the parent frame
2407 * needed to be fixed up.
2410 GetCaptionAdjustedParent(nsIFrame
* aParentFrame
,
2411 const nsIFrame
* aChildFrame
,
2412 nsIFrame
** aAdjParentFrame
)
2414 *aAdjParentFrame
= aParentFrame
;
2415 PRBool haveCaption
= PR_FALSE
;
2417 if (nsGkAtoms::tableCaptionFrame
== aChildFrame
->GetType()) {
2418 haveCaption
= PR_TRUE
;
2419 *aAdjParentFrame
= AdjustCaptionParentFrame(aParentFrame
);
2425 ProcessPseudoFrame(nsPseudoFrameData
& aPseudoData
,
2428 nsresult rv
= NS_OK
;
2430 aParent
= aPseudoData
.mFrame
;
2431 nsFrameItems
* items
= &aPseudoData
.mChildList
;
2432 if (items
&& items
->childList
) {
2433 rv
= aParent
->SetInitialChildList(nsnull
, items
->childList
);
2434 if (NS_FAILED(rv
)) return rv
;
2436 aPseudoData
.Reset();
2441 ProcessPseudoRowGroupFrame(nsPseudoFrameData
& aPseudoData
,
2444 nsresult rv
= NS_OK
;
2446 aParent
= aPseudoData
.mFrame
;
2447 nsFrameItems
* items
= &aPseudoData
.mChildList
;
2448 if (items
&& items
->childList
) {
2449 nsTableRowGroupFrame
* rgFrame
= nsTableFrame::GetRowGroupFrame(aParent
);
2450 rv
= rgFrame
->SetInitialChildList(nsnull
, items
->childList
);
2451 if (NS_FAILED(rv
)) return rv
;
2453 aPseudoData
.Reset();
2458 ProcessPseudoTableFrame(nsPseudoFrames
& aPseudoFrames
,
2461 nsresult rv
= NS_OK
;
2463 // process the col group frame, if it exists
2464 if (aPseudoFrames
.mColGroup
.mFrame
) {
2465 rv
= ProcessPseudoFrame(aPseudoFrames
.mColGroup
, aParent
);
2468 // process the inner table frame
2469 rv
= ProcessPseudoFrame(aPseudoFrames
.mTableInner
, aParent
);
2471 // process the outer table frame
2472 aParent
= aPseudoFrames
.mTableOuter
.mFrame
;
2473 nsFrameItems
* items
= &aPseudoFrames
.mTableOuter
.mChildList
;
2474 if (items
&& items
->childList
) {
2475 rv
= aParent
->SetInitialChildList(nsnull
, items
->childList
);
2476 if (NS_FAILED(rv
)) return rv
;
2478 nsFrameItems
* captions
= &aPseudoFrames
.mTableOuter
.mChildList2
;
2479 if (captions
&& captions
->childList
) {
2480 rv
= aParent
->SetInitialChildList(nsGkAtoms::captionList
, captions
->childList
);
2482 aPseudoFrames
.mTableOuter
.Reset();
2487 ProcessPseudoCellFrame(nsPseudoFrames
& aPseudoFrames
,
2490 nsresult rv
= NS_OK
;
2492 rv
= ProcessPseudoFrame(aPseudoFrames
.mCellInner
, aParent
);
2493 if (NS_FAILED(rv
)) return rv
;
2494 rv
= ProcessPseudoFrame(aPseudoFrames
.mCellOuter
, aParent
);
2498 // limit the processing up to the frame type indicated by aHighestType.
2499 // make a complete processing when aHighestType is null
2501 ProcessPseudoFrames(nsFrameConstructorState
& aState
,
2502 nsIAtom
* aHighestType
,
2503 nsIFrame
*& aHighestFrame
)
2505 nsresult rv
= NS_OK
;
2507 aHighestFrame
= nsnull
;
2510 if (gTablePseudoFrame
) {
2511 printf("*** ProcessPseudoFrames enter***\n");
2512 aState
.mPseudoFrames
.Dump();
2516 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2518 if (nsGkAtoms::tableFrame
== pseudoFrames
.mLowestType
) {
2519 if (pseudoFrames
.mColGroup
.mFrame
) {
2520 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, aHighestFrame
);
2521 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2523 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2524 if (nsGkAtoms::tableOuterFrame
== aHighestType
) return rv
;
2526 if (pseudoFrames
.mCellOuter
.mFrame
) {
2527 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2528 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2530 if (pseudoFrames
.mRow
.mFrame
) {
2531 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2532 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2534 if (pseudoFrames
.mRowGroup
.mFrame
) {
2535 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2536 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2539 else if (nsGkAtoms::tableRowGroupFrame
== pseudoFrames
.mLowestType
) {
2540 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2541 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2542 if (pseudoFrames
.mColGroup
.mFrame
) {
2543 nsIFrame
* colGroupHigh
;
2544 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, colGroupHigh
);
2545 if (aHighestFrame
&&
2546 nsGkAtoms::tableRowGroupFrame
== aHighestFrame
->GetType() &&
2547 !pseudoFrames
.mTableInner
.mFrame
) {
2548 // table frames are special they can have two types of pseudo frames as
2549 // children that need to be processed in one pass, we only need to link
2550 // them if the parent is not a pseudo where the link is already done
2551 // We sort this later out inside nsTableFrame.
2552 colGroupHigh
->SetNextSibling(aHighestFrame
);
2554 aHighestFrame
= colGroupHigh
;
2555 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2557 if (pseudoFrames
.mTableOuter
.mFrame
) {
2558 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2559 if (nsGkAtoms::tableOuterFrame
== aHighestType
) return rv
;
2561 if (pseudoFrames
.mCellOuter
.mFrame
) {
2562 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2563 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2565 if (pseudoFrames
.mRow
.mFrame
) {
2566 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2567 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2570 else if (nsGkAtoms::tableRowFrame
== pseudoFrames
.mLowestType
) {
2571 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2572 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2574 if (pseudoFrames
.mRowGroup
.mFrame
) {
2575 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2576 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2578 if (pseudoFrames
.mColGroup
.mFrame
) {
2579 nsIFrame
* colGroupHigh
;
2580 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, colGroupHigh
);
2581 if (aHighestFrame
&&
2582 nsGkAtoms::tableRowGroupFrame
== aHighestFrame
->GetType() &&
2583 !pseudoFrames
.mTableInner
.mFrame
) {
2584 // table frames are special they can have two types of pseudo frames as
2585 // children that need to be processed in one pass, we only need to link
2586 // them if the parent is not a pseudo where the link is already done
2587 // We sort this later out inside nsTableFrame.
2588 colGroupHigh
->SetNextSibling(aHighestFrame
);
2590 aHighestFrame
= colGroupHigh
;
2591 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2593 if (pseudoFrames
.mTableOuter
.mFrame
) {
2594 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2595 if (nsGkAtoms::tableOuterFrame
== aHighestType
) return rv
;
2597 if (pseudoFrames
.mCellOuter
.mFrame
) {
2598 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2599 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2602 else if (IS_TABLE_CELL(pseudoFrames
.mLowestType
)) {
2603 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2604 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2606 if (pseudoFrames
.mRow
.mFrame
) {
2607 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2608 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2610 if (pseudoFrames
.mRowGroup
.mFrame
) {
2611 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2612 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2614 if (pseudoFrames
.mColGroup
.mFrame
) {
2615 nsIFrame
* colGroupHigh
;
2616 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, colGroupHigh
);
2617 if (aHighestFrame
&&
2618 nsGkAtoms::tableRowGroupFrame
== aHighestFrame
->GetType() &&
2619 !pseudoFrames
.mTableInner
.mFrame
) {
2620 // table frames are special they can have two types of pseudo frames as
2621 // children that need to be processed in one pass, we only need to link
2622 // them if the parent is not a pseudo where the link is already done
2623 // We sort this later out inside nsTableFrame.
2624 colGroupHigh
->SetNextSibling(aHighestFrame
);
2626 aHighestFrame
= colGroupHigh
;
2627 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2629 if (pseudoFrames
.mTableOuter
.mFrame
) {
2630 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2633 else if (pseudoFrames
.mColGroup
.mFrame
) {
2634 // process the col group frame
2635 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, aHighestFrame
);
2642 ProcessPseudoFrames(nsFrameConstructorState
& aState
,
2643 nsFrameItems
& aItems
)
2647 if (gTablePseudoFrame
) {
2648 printf("*** ProcessPseudoFrames complete enter***\n");
2649 aState
.mPseudoFrames
.Dump();
2653 nsIFrame
* highestFrame
;
2654 nsresult rv
= ProcessPseudoFrames(aState
, nsnull
, highestFrame
);
2656 aItems
.AddChild(highestFrame
);
2660 if (gTablePseudoFrame
) {
2661 printf("*** ProcessPseudoFrames complete leave, highestframe:%p***\n",
2662 static_cast<void*>(highestFrame
));
2663 aState
.mPseudoFrames
.Dump();
2666 aState
.mPseudoFrames
.Reset();
2671 ProcessPseudoFrames(nsFrameConstructorState
& aState
,
2672 nsIAtom
* aHighestType
)
2675 if (gTablePseudoFrame
) {
2676 printf("*** ProcessPseudoFrames limited enter highest:");
2677 if (nsGkAtoms::tableOuterFrame
== aHighestType
)
2678 printf("OuterTable");
2679 else if (nsGkAtoms::tableFrame
== aHighestType
)
2680 printf("InnerTable");
2681 else if (nsGkAtoms::tableColGroupFrame
== aHighestType
)
2683 else if (nsGkAtoms::tableRowGroupFrame
== aHighestType
)
2685 else if (nsGkAtoms::tableRowFrame
== aHighestType
)
2687 else if (IS_TABLE_CELL(aHighestType
))
2690 NS_ASSERTION(PR_FALSE
, "invalid call to ProcessPseudoFrames ");
2692 aState
.mPseudoFrames
.Dump();
2696 nsIFrame
* highestFrame
;
2697 nsresult rv
= ProcessPseudoFrames(aState
, aHighestType
, highestFrame
);
2700 if (gTablePseudoFrame
) {
2701 printf("*** ProcessPseudoFrames limited leave:%p***\n",
2702 static_cast<void*>(highestFrame
));
2703 aState
.mPseudoFrames
.Dump();
2710 nsCSSFrameConstructor::CreatePseudoTableFrame(PRInt32 aNameSpaceID
,
2711 nsFrameConstructorState
& aState
,
2712 nsIFrame
* aParentFrameIn
)
2714 nsresult rv
= NS_OK
;
2716 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mCellInner
.mFrame
)
2717 ? aState
.mPseudoFrames
.mCellInner
.mFrame
: aParentFrameIn
;
2718 if (!parentFrame
) return rv
;
2720 nsStyleContext
*parentStyle
;
2721 nsRefPtr
<nsStyleContext
> childStyle
;
2723 parentStyle
= parentFrame
->GetStyleContext();
2724 nsIContent
* parentContent
= parentFrame
->GetContent();
2726 // Thankfully, the parent can't change display type without causing
2727 // frame reconstruction, so this won't need to change.
2728 nsIAtom
*pseudoType
;
2729 if (parentStyle
->GetStyleDisplay()->mDisplay
== NS_STYLE_DISPLAY_INLINE
)
2730 pseudoType
= nsCSSAnonBoxes::inlineTable
;
2732 pseudoType
= nsCSSAnonBoxes::table
;
2734 // create the SC for the inner table which will be the parent of the outer table's SC
2735 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2739 nsPseudoFrameData
& pseudoOuter
= aState
.mPseudoFrames
.mTableOuter
;
2740 nsPseudoFrameData
& pseudoInner
= aState
.mPseudoFrames
.mTableInner
;
2742 // construct the pseudo outer and inner as part of the pseudo frames
2744 rv
= ConstructTableFrame(aState
, parentContent
,
2745 parentFrame
, childStyle
, aNameSpaceID
,
2746 PR_TRUE
, items
, pseudoOuter
.mFrame
,
2747 pseudoInner
.mFrame
);
2749 if (NS_FAILED(rv
)) return rv
;
2751 // set pseudo data for the newly created frames
2752 pseudoOuter
.mChildList
.AddChild(pseudoInner
.mFrame
);
2753 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableFrame
;
2755 // set pseudo data for the parent
2756 if (aState
.mPseudoFrames
.mCellInner
.mFrame
) {
2757 aState
.mPseudoFrames
.mCellInner
.mChildList
.AddChild(pseudoOuter
.mFrame
);
2760 if (gTablePseudoFrame
) {
2761 printf("*** CreatePseudoTableFrame ***\n");
2762 aState
.mPseudoFrames
.Dump();
2769 nsCSSFrameConstructor::CreatePseudoRowGroupFrame(PRInt32 aNameSpaceID
,
2770 nsFrameConstructorState
& aState
,
2771 nsIFrame
* aParentFrameIn
)
2773 nsresult rv
= NS_OK
;
2775 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mTableInner
.mFrame
)
2776 ? aState
.mPseudoFrames
.mTableInner
.mFrame
: aParentFrameIn
;
2777 if (!parentFrame
) return rv
;
2779 nsStyleContext
*parentStyle
;
2780 nsRefPtr
<nsStyleContext
> childStyle
;
2782 parentStyle
= parentFrame
->GetStyleContext();
2783 nsIContent
* parentContent
= parentFrame
->GetContent();
2785 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2786 nsCSSAnonBoxes::tableRowGroup
,
2789 nsPseudoFrameData
& pseudo
= aState
.mPseudoFrames
.mRowGroup
;
2791 // construct the pseudo row group as part of the pseudo frames
2792 PRBool pseudoParent
;
2794 rv
= ConstructTableRowGroupFrame(aState
, parentContent
,
2795 parentFrame
, childStyle
, aNameSpaceID
,
2796 PR_TRUE
, items
, pseudo
.mFrame
, pseudoParent
);
2797 if (NS_FAILED(rv
)) return rv
;
2799 // set pseudo data for the newly created frames
2800 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableRowGroupFrame
;
2802 // set pseudo data for the parent
2803 if (aState
.mPseudoFrames
.mTableInner
.mFrame
) {
2804 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(pseudo
.mFrame
);
2807 if (gTablePseudoFrame
) {
2808 printf("*** CreatePseudoRowGroupFrame ***\n");
2809 aState
.mPseudoFrames
.Dump();
2816 nsCSSFrameConstructor::CreatePseudoColGroupFrame(PRInt32 aNameSpaceID
,
2817 nsFrameConstructorState
& aState
,
2818 nsIFrame
* aParentFrameIn
)
2820 nsresult rv
= NS_OK
;
2822 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mTableInner
.mFrame
)
2823 ? aState
.mPseudoFrames
.mTableInner
.mFrame
: aParentFrameIn
;
2824 if (!parentFrame
) return rv
;
2826 nsStyleContext
*parentStyle
;
2827 nsRefPtr
<nsStyleContext
> childStyle
;
2829 parentStyle
= parentFrame
->GetStyleContext();
2830 nsIContent
* parentContent
= parentFrame
->GetContent();
2832 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2833 nsCSSAnonBoxes::tableColGroup
,
2836 nsPseudoFrameData
& pseudo
= aState
.mPseudoFrames
.mColGroup
;
2838 // construct the pseudo col group as part of the pseudo frames
2839 PRBool pseudoParent
;
2841 rv
= ConstructTableColGroupFrame(aState
, parentContent
,
2842 parentFrame
, childStyle
, aNameSpaceID
,
2843 PR_TRUE
, items
, pseudo
.mFrame
, pseudoParent
);
2844 if (NS_FAILED(rv
)) return rv
;
2845 ((nsTableColGroupFrame
*)pseudo
.mFrame
)->SetColType(eColGroupAnonymousCol
);
2847 // Do not set aState.mPseudoFrames.mLowestType here as colgroup frame will
2848 // be always below a table frame but we can not descent any further as col
2849 // frames can not have children and will not wrap table foreign frames.
2851 // set pseudo data for the parent
2852 if (aState
.mPseudoFrames
.mTableInner
.mFrame
) {
2853 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(pseudo
.mFrame
);
2856 if (gTablePseudoFrame
) {
2857 printf("*** CreatePseudoColGroupFrame ***\n");
2858 aState
.mPseudoFrames
.Dump();
2865 nsCSSFrameConstructor::CreatePseudoRowFrame(PRInt32 aNameSpaceID
,
2866 nsFrameConstructorState
& aState
,
2867 nsIFrame
* aParentFrameIn
)
2869 nsresult rv
= NS_OK
;
2871 nsIFrame
* parentFrame
= aParentFrameIn
;
2872 if (aState
.mPseudoFrames
.mRowGroup
.mFrame
) {
2873 parentFrame
= (nsIFrame
*) nsTableFrame::GetRowGroupFrame(aState
.mPseudoFrames
.mRowGroup
.mFrame
);
2875 if (!parentFrame
) return rv
;
2877 nsStyleContext
*parentStyle
;
2878 nsRefPtr
<nsStyleContext
> childStyle
;
2880 parentStyle
= parentFrame
->GetStyleContext();
2881 nsIContent
* parentContent
= parentFrame
->GetContent();
2883 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2884 nsCSSAnonBoxes::tableRow
,
2887 nsPseudoFrameData
& pseudo
= aState
.mPseudoFrames
.mRow
;
2889 // construct the pseudo row as part of the pseudo frames
2890 PRBool pseudoParent
;
2892 rv
= ConstructTableRowFrame(aState
, parentContent
,
2893 parentFrame
, childStyle
, aNameSpaceID
,
2894 PR_TRUE
, items
, pseudo
.mFrame
, pseudoParent
);
2895 if (NS_FAILED(rv
)) return rv
;
2897 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableRowFrame
;
2899 // set pseudo data for the parent
2900 if (aState
.mPseudoFrames
.mRowGroup
.mFrame
) {
2901 aState
.mPseudoFrames
.mRowGroup
.mChildList
.AddChild(pseudo
.mFrame
);
2904 if (gTablePseudoFrame
) {
2905 printf("*** CreatePseudoRowFrame ***\n");
2906 aState
.mPseudoFrames
.Dump();
2913 nsCSSFrameConstructor::CreatePseudoCellFrame(PRInt32 aNameSpaceID
,
2914 nsFrameConstructorState
& aState
,
2915 nsIFrame
* aParentFrameIn
)
2917 nsresult rv
= NS_OK
;
2919 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mRow
.mFrame
)
2920 ? aState
.mPseudoFrames
.mRow
.mFrame
: aParentFrameIn
;
2921 if (!parentFrame
) return rv
;
2923 nsStyleContext
*parentStyle
;
2924 nsRefPtr
<nsStyleContext
> childStyle
;
2926 parentStyle
= parentFrame
->GetStyleContext();
2927 nsIContent
* parentContent
= parentFrame
->GetContent();
2929 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2930 nsCSSAnonBoxes::tableCell
,
2933 nsPseudoFrameData
& pseudoOuter
= aState
.mPseudoFrames
.mCellOuter
;
2934 nsPseudoFrameData
& pseudoInner
= aState
.mPseudoFrames
.mCellInner
;
2936 // construct the pseudo outer and inner as part of the pseudo frames
2937 PRBool pseudoParent
;
2939 rv
= ConstructTableCellFrame(aState
, parentContent
, parentFrame
, childStyle
,
2940 aNameSpaceID
, PR_TRUE
, items
,
2941 pseudoOuter
.mFrame
, pseudoInner
.mFrame
,
2943 if (NS_FAILED(rv
)) return rv
;
2945 // set pseudo data for the newly created frames
2946 pseudoOuter
.mChildList
.AddChild(pseudoInner
.mFrame
);
2947 // give it nsGkAtoms::tableCellFrame, if it is really nsGkAtoms::bcTableCellFrame, it will match later
2948 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableCellFrame
;
2950 // set pseudo data for the parent
2951 if (aState
.mPseudoFrames
.mRow
.mFrame
) {
2952 aState
.mPseudoFrames
.mRow
.mChildList
.AddChild(pseudoOuter
.mFrame
);
2955 if (gTablePseudoFrame
) {
2956 printf("*** CreatePseudoCellFrame ***\n");
2957 aState
.mPseudoFrames
.Dump();
2963 // called if the parent is not a table
2965 nsCSSFrameConstructor::GetPseudoTableFrame(PRInt32 aNameSpaceID
,
2966 nsFrameConstructorState
& aState
,
2967 nsIFrame
& aParentFrameIn
)
2969 nsresult rv
= NS_OK
;
2971 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2972 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2974 if (pseudoFrames
.IsEmpty()) {
2975 PRBool created
= PR_FALSE
;
2976 if (nsGkAtoms::tableRowGroupFrame
== parentFrameType
) { // row group parent
2977 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2978 if (NS_FAILED(rv
)) return rv
;
2981 if (created
|| (nsGkAtoms::tableRowFrame
== parentFrameType
)) { // row parent
2982 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2983 if (NS_FAILED(rv
)) return rv
;
2985 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2988 if (!pseudoFrames
.mTableInner
.mFrame
) {
2989 if (pseudoFrames
.mRowGroup
.mFrame
&& !(pseudoFrames
.mRow
.mFrame
)) {
2990 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
2991 if (NS_FAILED(rv
)) return rv
;
2993 if (pseudoFrames
.mRow
.mFrame
&& !(pseudoFrames
.mCellOuter
.mFrame
)) {
2994 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
2995 if (NS_FAILED(rv
)) return rv
;
2997 CreatePseudoTableFrame(aNameSpaceID
, aState
);
3003 // called if the parent is not a col group
3005 nsCSSFrameConstructor::GetPseudoColGroupFrame(PRInt32 aNameSpaceID
,
3006 nsFrameConstructorState
& aState
,
3007 nsIFrame
& aParentFrameIn
)
3009 nsresult rv
= NS_OK
;
3011 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
3012 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
3014 if (pseudoFrames
.IsEmpty()) {
3015 PRBool created
= PR_FALSE
;
3016 if (nsGkAtoms::tableRowGroupFrame
== parentFrameType
) { // row group parent
3017 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3020 if (created
|| (nsGkAtoms::tableRowFrame
== parentFrameType
)) { // row parent
3021 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3024 if (created
|| IS_TABLE_CELL(parentFrameType
) || // cell parent
3025 (nsGkAtoms::tableCaptionFrame
== parentFrameType
) || // caption parent
3026 !IsTableRelated(parentFrameType
, PR_TRUE
)) { // block parent
3027 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3029 rv
= CreatePseudoColGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3032 if (!pseudoFrames
.mColGroup
.mFrame
) {
3033 if (!pseudoFrames
.mTableInner
.mFrame
) {
3034 if (pseudoFrames
.mRowGroup
.mFrame
&& !(pseudoFrames
.mRow
.mFrame
)) {
3035 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
3037 if (pseudoFrames
.mRow
.mFrame
&& !(pseudoFrames
.mCellOuter
.mFrame
)) {
3038 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
3040 if (pseudoFrames
.mCellOuter
.mFrame
&& !(pseudoFrames
.mTableOuter
.mFrame
)) {
3041 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
);
3044 rv
= CreatePseudoColGroupFrame(aNameSpaceID
, aState
);
3050 // called if the parent is not a row group
3052 nsCSSFrameConstructor::GetPseudoRowGroupFrame(PRInt32 aNameSpaceID
,
3053 nsFrameConstructorState
& aState
,
3054 nsIFrame
& aParentFrameIn
)
3056 nsresult rv
= NS_OK
;
3058 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
3059 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
3061 if (!pseudoFrames
.mLowestType
) {
3062 PRBool created
= PR_FALSE
;
3063 if (nsGkAtoms::tableRowFrame
== parentFrameType
) { // row parent
3064 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3067 if (created
|| IS_TABLE_CELL(parentFrameType
) || // cell parent
3068 (nsGkAtoms::tableCaptionFrame
== parentFrameType
) || // caption parent
3069 !IsTableRelated(parentFrameType
, PR_TRUE
)) { // block parent
3070 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3072 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3075 if (!pseudoFrames
.mRowGroup
.mFrame
) {
3076 if (pseudoFrames
.mRow
.mFrame
&& !(pseudoFrames
.mCellOuter
.mFrame
)) {
3077 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
3079 if (pseudoFrames
.mCellOuter
.mFrame
&& !(pseudoFrames
.mTableOuter
.mFrame
)) {
3080 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
);
3082 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
);
3088 // called if the parent is not a row
3090 nsCSSFrameConstructor::GetPseudoRowFrame(PRInt32 aNameSpaceID
,
3091 nsFrameConstructorState
& aState
,
3092 nsIFrame
& aParentFrameIn
)
3094 nsresult rv
= NS_OK
;
3096 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
3097 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
3099 if (!pseudoFrames
.mLowestType
) {
3100 PRBool created
= PR_FALSE
;
3101 if (IS_TABLE_CELL(parentFrameType
) || // cell parent
3102 (nsGkAtoms::tableCaptionFrame
== parentFrameType
) || // caption parent
3103 !IsTableRelated(parentFrameType
, PR_TRUE
)) { // block parent
3104 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3107 if (created
|| (nsGkAtoms::tableFrame
== parentFrameType
)) { // table parent
3108 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3110 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3113 if (!pseudoFrames
.mRow
.mFrame
) {
3114 if (pseudoFrames
.mCellOuter
.mFrame
&& !pseudoFrames
.mTableOuter
.mFrame
) {
3115 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
);
3117 if (pseudoFrames
.mTableInner
.mFrame
&& !(pseudoFrames
.mRowGroup
.mFrame
)) {
3118 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
);
3120 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
3126 // called if the parent is not a cell or block
3128 nsCSSFrameConstructor::GetPseudoCellFrame(PRInt32 aNameSpaceID
,
3129 nsFrameConstructorState
& aState
,
3130 nsIFrame
& aParentFrameIn
)
3132 nsresult rv
= NS_OK
;
3134 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
3135 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
3137 if (!pseudoFrames
.mLowestType
) {
3138 PRBool created
= PR_FALSE
;
3139 if (nsGkAtoms::tableFrame
== parentFrameType
) { // table parent
3140 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3143 if (created
|| (nsGkAtoms::tableRowGroupFrame
== parentFrameType
)) { // row group parent
3144 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3147 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
3149 else if (!pseudoFrames
.mCellOuter
.mFrame
) {
3150 if (pseudoFrames
.mTableInner
.mFrame
&& !(pseudoFrames
.mRowGroup
.mFrame
)) {
3151 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
);
3153 if (pseudoFrames
.mRowGroup
.mFrame
&& !(pseudoFrames
.mRow
.mFrame
)) {
3154 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
3156 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
3162 nsCSSFrameConstructor::GetParentFrame(PRInt32 aNameSpaceID
,
3163 nsIFrame
& aParentFrameIn
,
3164 nsIAtom
* aChildFrameType
,
3165 nsFrameConstructorState
& aState
,
3166 nsIFrame
*& aParentFrame
,
3167 PRBool
& aIsPseudoParent
)
3169 nsresult rv
= NS_OK
;
3171 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
3172 nsIFrame
* pseudoParentFrame
= nsnull
;
3173 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
3174 aParentFrame
= &aParentFrameIn
;
3175 aIsPseudoParent
= PR_FALSE
;
3177 nsFrameState savedStateBits
= aState
.mAdditionalStateBits
;
3178 aState
.mAdditionalStateBits
&= ~NS_FRAME_GENERATED_CONTENT
;
3180 if (nsGkAtoms::tableOuterFrame
== aChildFrameType
) { // table child
3181 if (IsTableRelated(parentFrameType
, PR_TRUE
) &&
3182 (nsGkAtoms::tableCaptionFrame
!= parentFrameType
) ) { // need pseudo cell parent
3183 rv
= GetPseudoCellFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3184 if (NS_FAILED(rv
)) return rv
;
3185 pseudoParentFrame
= pseudoFrames
.mCellInner
.mFrame
;
3188 else if (nsGkAtoms::tableCaptionFrame
== aChildFrameType
) { // caption child
3189 if (nsGkAtoms::tableOuterFrame
!= parentFrameType
) { // need pseudo table parent
3190 rv
= GetPseudoTableFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3191 if (NS_FAILED(rv
)) return rv
;
3192 pseudoParentFrame
= pseudoFrames
.mTableOuter
.mFrame
;
3195 else if (nsGkAtoms::tableColGroupFrame
== aChildFrameType
) { // col group child
3196 if (nsGkAtoms::tableFrame
!= parentFrameType
) { // need pseudo table parent
3197 rv
= GetPseudoTableFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3198 if (NS_FAILED(rv
)) return rv
;
3199 pseudoParentFrame
= pseudoFrames
.mTableInner
.mFrame
;
3202 else if (nsGkAtoms::tableColFrame
== aChildFrameType
) { // col child
3203 if (nsGkAtoms::tableColGroupFrame
!= parentFrameType
) { // need pseudo col group parent
3204 rv
= GetPseudoColGroupFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3205 if (NS_FAILED(rv
)) return rv
;
3206 pseudoParentFrame
= pseudoFrames
.mColGroup
.mFrame
;
3209 else if (nsGkAtoms::tableRowGroupFrame
== aChildFrameType
) { // row group child
3210 // XXX can this go away?
3211 if (nsGkAtoms::tableFrame
!= parentFrameType
) {
3212 // trees allow row groups to contain row groups, so don't create pseudo frames
3213 rv
= GetPseudoTableFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3214 if (NS_FAILED(rv
)) return rv
;
3215 pseudoParentFrame
= pseudoFrames
.mTableInner
.mFrame
;
3218 else if (nsGkAtoms::tableRowFrame
== aChildFrameType
) { // row child
3219 if (nsGkAtoms::tableRowGroupFrame
!= parentFrameType
) { // need pseudo row group parent
3220 rv
= GetPseudoRowGroupFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3221 if (NS_FAILED(rv
)) return rv
;
3222 pseudoParentFrame
= pseudoFrames
.mRowGroup
.mFrame
;
3225 else if (IS_TABLE_CELL(aChildFrameType
)) { // cell child
3226 if (nsGkAtoms::tableRowFrame
!= parentFrameType
) { // need pseudo row parent
3227 rv
= GetPseudoRowFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3228 if (NS_FAILED(rv
)) return rv
;
3229 pseudoParentFrame
= pseudoFrames
.mRow
.mFrame
;
3232 else if (nsGkAtoms::tableFrame
== aChildFrameType
) { // invalid
3233 NS_ASSERTION(PR_FALSE
, "GetParentFrame called on nsGkAtoms::tableFrame child");
3235 else { // foreign frame
3236 if (IsTableRelated(parentFrameType
, PR_FALSE
)) { // need pseudo cell parent
3237 rv
= GetPseudoCellFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3238 if (NS_FAILED(rv
)) return rv
;
3239 pseudoParentFrame
= pseudoFrames
.mCellInner
.mFrame
;
3243 if (pseudoParentFrame
) {
3244 aParentFrame
= pseudoParentFrame
;
3245 aIsPseudoParent
= PR_TRUE
;
3248 aState
.mAdditionalStateBits
= savedStateBits
;
3253 IsSpecialContent(nsIContent
* aContent
,
3255 PRInt32 aNameSpaceID
,
3256 nsStyleContext
* aStyleContext
)
3258 // Gross hack. Return true if this is a content node that we'd create a
3259 // frame for based on something other than display -- in other words if this
3260 // is a node that could never have a nsTableCellFrame, for example.
3261 if (aContent
->IsNodeOfType(nsINode::eHTML
) ||
3262 aNameSpaceID
== kNameSpaceID_XHTML
) {
3263 // XXXbz this is duplicating some logic from ConstructHTMLFrame....
3264 // Would be nice to avoid that. :(
3266 if (aTag
== nsGkAtoms::input
) {
3267 nsCOMPtr
<nsIFormControl
> control
= do_QueryInterface(aContent
);
3269 PRInt32 type
= control
->GetType();
3270 if (NS_FORM_INPUT_HIDDEN
== type
) {
3271 return PR_FALSE
; // input hidden does not create a special frame
3273 else if (NS_FORM_INPUT_IMAGE
== type
) {
3274 return nsImageFrame::ShouldCreateImageFrameFor(aContent
, aStyleContext
);
3281 if (aTag
== nsGkAtoms::img
||
3282 aTag
== nsGkAtoms::mozgeneratedcontentimage
) {
3283 return nsImageFrame::ShouldCreateImageFrameFor(aContent
, aStyleContext
);
3286 if (aTag
== nsGkAtoms::object
||
3287 aTag
== nsGkAtoms::applet
||
3288 aTag
== nsGkAtoms::embed
) {
3289 return !(aContent
->IntrinsicState() &
3290 (NS_EVENT_STATE_BROKEN
| NS_EVENT_STATE_USERDISABLED
|
3291 NS_EVENT_STATE_SUPPRESSED
));
3295 aTag
== nsGkAtoms::br
||
3296 aTag
== nsGkAtoms::wbr
||
3297 aTag
== nsGkAtoms::textarea
||
3298 aTag
== nsGkAtoms::select
||
3299 aTag
== nsGkAtoms::fieldset
||
3300 aTag
== nsGkAtoms::legend
||
3301 aTag
== nsGkAtoms::frameset
||
3302 aTag
== nsGkAtoms::iframe
||
3303 aTag
== nsGkAtoms::spacer
||
3304 aTag
== nsGkAtoms::button
||
3305 aTag
== nsGkAtoms::isindex
||
3306 aTag
== nsGkAtoms::canvas
||
3307 #if defined(MOZ_MEDIA)
3308 aTag
== nsGkAtoms::video
||
3309 aTag
== nsGkAtoms::audio
||
3315 if (aNameSpaceID
== kNameSpaceID_XUL
)
3318 aTag
== nsGkAtoms::button
||
3319 aTag
== nsGkAtoms::checkbox
||
3320 aTag
== nsGkAtoms::radio
||
3321 aTag
== nsGkAtoms::autorepeatbutton
||
3322 aTag
== nsGkAtoms::titlebar
||
3323 aTag
== nsGkAtoms::resizer
||
3324 aTag
== nsGkAtoms::image
||
3325 aTag
== nsGkAtoms::spring
||
3326 aTag
== nsGkAtoms::spacer
||
3327 aTag
== nsGkAtoms::treechildren
||
3328 aTag
== nsGkAtoms::treecol
||
3329 aTag
== nsGkAtoms::text
||
3330 aTag
== nsGkAtoms::description
||
3331 aTag
== nsGkAtoms::label
||
3332 aTag
== nsGkAtoms::menu
||
3333 aTag
== nsGkAtoms::menuitem
||
3334 aTag
== nsGkAtoms::menubutton
||
3335 aTag
== nsGkAtoms::menubar
||
3336 (aTag
== nsGkAtoms::popupgroup
&&
3337 aContent
->IsRootOfNativeAnonymousSubtree()) ||
3338 aTag
== nsGkAtoms::iframe
||
3339 aTag
== nsGkAtoms::editor
||
3340 aTag
== nsGkAtoms::browser
||
3341 aTag
== nsGkAtoms::progressmeter
||
3343 aTag
== nsGkAtoms::slider
||
3344 aTag
== nsGkAtoms::scrollbar
||
3345 aTag
== nsGkAtoms::scrollbarbutton
||
3347 aTag
== nsGkAtoms::splitter
||
3352 if (aNameSpaceID
== kNameSpaceID_SVG
&& NS_SVGEnabled()) {
3353 // All SVG content is special...
3359 if (aNameSpaceID
== kNameSpaceID_MathML
)
3361 aTag
== nsGkAtoms::mi_
||
3362 aTag
== nsGkAtoms::mn_
||
3363 aTag
== nsGkAtoms::ms_
||
3364 aTag
== nsGkAtoms::mtext_
||
3365 aTag
== nsGkAtoms::mo_
||
3366 aTag
== nsGkAtoms::mfrac_
||
3367 aTag
== nsGkAtoms::msup_
||
3368 aTag
== nsGkAtoms::msub_
||
3369 aTag
== nsGkAtoms::msubsup_
||
3370 aTag
== nsGkAtoms::munder_
||
3371 aTag
== nsGkAtoms::mover_
||
3372 aTag
== nsGkAtoms::munderover_
||
3373 aTag
== nsGkAtoms::mphantom_
||
3374 aTag
== nsGkAtoms::mpadded_
||
3375 aTag
== nsGkAtoms::mspace_
||
3376 aTag
== nsGkAtoms::mfenced_
||
3377 aTag
== nsGkAtoms::mmultiscripts_
||
3378 aTag
== nsGkAtoms::mstyle_
||
3379 aTag
== nsGkAtoms::msqrt_
||
3380 aTag
== nsGkAtoms::mroot_
||
3381 aTag
== nsGkAtoms::maction_
||
3382 aTag
== nsGkAtoms::mrow_
||
3383 aTag
== nsGkAtoms::merror_
||
3384 aTag
== nsGkAtoms::none
||
3385 aTag
== nsGkAtoms::mprescripts_
||
3386 aTag
== nsGkAtoms::math
;
3392 nsCSSFrameConstructor::AdjustParentFrame(nsFrameConstructorState
& aState
,
3393 nsIContent
* aChildContent
,
3394 nsIFrame
* & aParentFrame
,
3396 PRInt32 aNameSpaceID
,
3397 nsStyleContext
* aChildStyle
,
3398 nsFrameItems
* & aFrameItems
,
3399 nsFrameConstructorSaveState
& aSaveState
,
3400 PRBool
& aSuppressFrame
,
3401 PRBool
& aCreatedPseudo
)
3403 NS_PRECONDITION(aChildStyle
, "Must have child's style context");
3404 NS_PRECONDITION(aFrameItems
, "Must have frame items to work with");
3406 aSuppressFrame
= PR_FALSE
;
3407 aCreatedPseudo
= PR_FALSE
;
3408 if (!aParentFrame
) {
3409 // Nothing to do here
3413 PRBool childIsSpecialContent
= PR_FALSE
; // lazy lookup
3414 // Only use the outer table frame as parent if the child is going to use a
3415 // tableCaptionFrame, otherwise the inner table frame is the parent
3417 nsIAtom
* parentType
= aParentFrame
->GetType();
3418 NS_ASSERTION(parentType
!= nsGkAtoms::tableOuterFrame
,
3419 "Shouldn't be happening");
3420 if (parentType
== nsGkAtoms::tableColGroupFrame
) {
3421 childIsSpecialContent
= IsSpecialContent(aChildContent
, aTag
, aNameSpaceID
,
3423 if (childIsSpecialContent
||
3424 (aChildStyle
->GetStyleDisplay()->mDisplay
!=
3425 NS_STYLE_DISPLAY_TABLE_COLUMN
)) {
3426 aSuppressFrame
= PR_TRUE
;
3431 // If our parent is a table, table-row-group, or table-row, and
3432 // we're not table-related in any way, we have to create table
3433 // pseudo-frames so that we have a table cell to live in.
3434 if (IsTableRelated(aParentFrame
->GetType(), PR_FALSE
) &&
3435 (!IsTableRelated(aChildStyle
->GetStyleDisplay()->mDisplay
, PR_TRUE
) ||
3436 // Also need to create a pseudo-parent if the child is going to end up
3437 // with a frame based on something other than display.
3438 childIsSpecialContent
|| // looked it up before
3439 IsSpecialContent(aChildContent
, aTag
, aNameSpaceID
, aChildStyle
))) {
3440 nsFrameState savedStateBits
= aState
.mAdditionalStateBits
;
3441 aState
.mAdditionalStateBits
&= ~NS_FRAME_GENERATED_CONTENT
;
3442 nsresult rv
= GetPseudoCellFrame(aNameSpaceID
, aState
, *aParentFrame
);
3443 if (NS_FAILED(rv
)) {
3446 aState
.mAdditionalStateBits
= savedStateBits
;
3448 NS_ASSERTION(aState
.mPseudoFrames
.mCellInner
.mFrame
,
3449 "Must have inner cell frame now!");
3451 aParentFrame
= aState
.mPseudoFrames
.mCellInner
.mFrame
;
3452 aFrameItems
= &aState
.mPseudoFrames
.mCellInner
.mChildList
;
3453 // We pushed an anonymous table cell. The inner block of this
3454 // needs to become the float containing block.
3455 aState
.PushFloatContainingBlock(aParentFrame
, aSaveState
, PR_FALSE
,
3457 aCreatedPseudo
= PR_TRUE
;
3462 // Pull all the captions present in aItems out into aCaptions
3464 PullOutCaptionFrames(nsFrameItems
& aItems
, nsFrameItems
& aCaptions
)
3466 nsIFrame
*child
= aItems
.childList
;
3467 nsIFrame
* prev
= nsnull
;
3469 nsIFrame
*nextSibling
= child
->GetNextSibling();
3470 if (nsGkAtoms::tableCaptionFrame
== child
->GetType()) {
3471 aItems
.RemoveChild(child
, prev
);
3472 aCaptions
.AddChild(child
);
3476 child
= nextSibling
;
3481 // Construct the outer, inner table frames and the children frames for the table.
3482 // XXX Page break frames for pseudo table frames are not constructed to avoid the risk
3483 // associated with revising the pseudo frame mechanism. The long term solution
3484 // of having frames handle page-break-before/after will solve the problem.
3486 nsCSSFrameConstructor::ConstructTableFrame(nsFrameConstructorState
& aState
,
3487 nsIContent
* aContent
,
3488 nsIFrame
* aContentParent
,
3489 nsStyleContext
* aStyleContext
,
3490 PRInt32 aNameSpaceID
,
3492 nsFrameItems
& aChildItems
,
3493 nsIFrame
*& aNewOuterFrame
,
3494 nsIFrame
*& aNewInnerFrame
)
3496 nsresult rv
= NS_OK
;
3499 // create the pseudo SC for the outer table as a child of the inner SC
3500 nsRefPtr
<nsStyleContext
> outerStyleContext
;
3501 outerStyleContext
= mPresShell
->StyleSet()->
3502 ResolvePseudoStyleFor(aContent
, nsCSSAnonBoxes::tableOuter
, aStyleContext
);
3504 // Create the outer table frame which holds the caption and inner table frame
3506 if (kNameSpaceID_MathML
== aNameSpaceID
)
3507 aNewOuterFrame
= NS_NewMathMLmtableOuterFrame(mPresShell
,
3511 aNewOuterFrame
= NS_NewTableOuterFrame(mPresShell
, outerStyleContext
);
3513 nsIFrame
* parentFrame
= aContentParent
;
3514 nsFrameItems
* frameItems
= &aChildItems
;
3515 // We may need to push a float containing block
3516 nsFrameConstructorSaveState floatSaveState
;
3518 // this frame may have a pseudo parent
3519 PRBool hasPseudoParent
= PR_FALSE
;
3520 GetParentFrame(aNameSpaceID
,*parentFrame
, nsGkAtoms::tableOuterFrame
,
3521 aState
, parentFrame
, hasPseudoParent
);
3522 if (!hasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3523 ProcessPseudoFrames(aState
, aChildItems
);
3525 if (hasPseudoParent
) {
3526 aState
.PushFloatContainingBlock(parentFrame
, floatSaveState
,
3527 PR_FALSE
, PR_FALSE
);
3528 frameItems
= &aState
.mPseudoFrames
.mCellInner
.mChildList
;
3529 if (aState
.mPseudoFrames
.mTableOuter
.mFrame
) {
3530 ProcessPseudoFrames(aState
, nsGkAtoms::tableOuterFrame
);
3535 nsIFrame
* geometricParent
= aState
.GetGeometricParent
3536 (outerStyleContext
->GetStyleDisplay(),
3539 // Init the table outer frame and see if we need to create a view, e.g.
3540 // the frame is absolutely positioned
3541 InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
, aNewOuterFrame
);
3542 nsHTMLContainerFrame::CreateViewForFrame(aNewOuterFrame
, aContentParent
,
3545 // Create the inner table frame
3547 if (kNameSpaceID_MathML
== aNameSpaceID
)
3548 aNewInnerFrame
= NS_NewMathMLmtableFrame(mPresShell
, aStyleContext
);
3551 aNewInnerFrame
= NS_NewTableFrame(mPresShell
, aStyleContext
);
3553 InitAndRestoreFrame(aState
, aContent
, aNewOuterFrame
, nsnull
,
3557 // Put the newly created frames into the right child list
3558 aNewOuterFrame
->SetInitialChildList(nsnull
, aNewInnerFrame
);
3560 rv
= aState
.AddChild(aNewOuterFrame
, *frameItems
, aContent
,
3561 aStyleContext
, parentFrame
);
3562 if (NS_FAILED(rv
)) {
3566 if (!mInitialContainingBlock
) {
3567 // The frame we're constructing will be the initial containing block.
3568 // Set mInitialContainingBlock before processing children.
3569 mInitialContainingBlock
= aNewOuterFrame
;
3572 nsFrameItems childItems
;
3573 rv
= ProcessChildren(aState
, aContent
, aNewInnerFrame
, PR_TRUE
, childItems
,
3575 // XXXbz what about cleaning up?
3576 if (NS_FAILED(rv
)) return rv
;
3578 // if there are any anonymous children for the table, create frames for them
3579 CreateAnonymousFrames(nsnull
, aState
, aContent
, aNewInnerFrame
,
3580 PR_FALSE
, childItems
);
3582 nsFrameItems captionItems
;
3583 PullOutCaptionFrames(childItems
, captionItems
);
3585 // Set the inner table frame's initial primary list
3586 aNewInnerFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3588 // Set the outer table frame's secondary childlist lists
3589 if (captionItems
.childList
) {
3590 aNewOuterFrame
->SetInitialChildList(nsGkAtoms::captionList
,
3591 captionItems
.childList
);
3599 nsCSSFrameConstructor::ConstructTableCaptionFrame(nsFrameConstructorState
& aState
,
3600 nsIContent
* aContent
,
3601 nsIFrame
* aParentFrameIn
,
3602 nsStyleContext
* aStyleContext
,
3603 PRInt32 aNameSpaceID
,
3604 nsFrameItems
& aChildItems
,
3605 nsIFrame
*& aNewFrame
,
3606 PRBool
& aIsPseudoParent
)
3609 nsresult rv
= NS_OK
;
3610 if (!aParentFrameIn
) return rv
;
3612 nsIFrame
* parentFrame
= aParentFrameIn
;
3613 aIsPseudoParent
= PR_FALSE
;
3614 // this frame may have a pseudo parent
3615 GetParentFrame(aNameSpaceID
, *aParentFrameIn
,
3616 nsGkAtoms::tableCaptionFrame
, aState
, parentFrame
,
3618 if (!aIsPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3619 ProcessPseudoFrames(aState
, aChildItems
);
3622 aNewFrame
= NS_NewTableCaptionFrame(mPresShell
, aStyleContext
);
3623 if (NS_UNLIKELY(!aNewFrame
)) {
3624 return NS_ERROR_OUT_OF_MEMORY
;
3626 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3627 // XXXbz should we be passing in a non-null aContentParentFrame?
3628 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, nsnull
, PR_FALSE
);
3630 PRBool haveFirstLetterStyle
, haveFirstLineStyle
;
3631 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
3632 &haveFirstLetterStyle
, &haveFirstLineStyle
);
3634 // The caption frame is a float container
3635 nsFrameConstructorSaveState floatSaveState
;
3636 aState
.PushFloatContainingBlock(aNewFrame
, floatSaveState
,
3637 haveFirstLetterStyle
, haveFirstLineStyle
);
3638 nsFrameItems childItems
;
3639 rv
= ProcessChildren(aState
, aContent
, aNewFrame
,
3640 PR_TRUE
, childItems
, PR_TRUE
);
3641 if (NS_FAILED(rv
)) return rv
;
3642 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3643 if (aIsPseudoParent
) {
3644 aState
.mPseudoFrames
.mTableOuter
.mChildList2
.AddChild(aNewFrame
);
3652 nsCSSFrameConstructor::ConstructTableRowGroupFrame(nsFrameConstructorState
& aState
,
3653 nsIContent
* aContent
,
3654 nsIFrame
* aParentFrameIn
,
3655 nsStyleContext
* aStyleContext
,
3656 PRInt32 aNameSpaceID
,
3658 nsFrameItems
& aChildItems
,
3659 nsIFrame
*& aNewFrame
,
3660 PRBool
& aIsPseudoParent
)
3662 nsresult rv
= NS_OK
;
3663 if (!aParentFrameIn
) return rv
;
3665 nsIFrame
* parentFrame
= aParentFrameIn
;
3666 aIsPseudoParent
= PR_FALSE
;
3668 // this frame may have a pseudo parent
3669 GetParentFrame(aNameSpaceID
, *aParentFrameIn
,
3670 nsGkAtoms::tableRowGroupFrame
, aState
, parentFrame
,
3672 if (!aIsPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3673 ProcessPseudoFrames(aState
, aChildItems
);
3675 if (!aIsPseudo
&& aIsPseudoParent
&& aState
.mPseudoFrames
.mRowGroup
.mFrame
) {
3676 ProcessPseudoFrames(aState
, nsGkAtoms::tableRowGroupFrame
);
3680 const nsStyleDisplay
* styleDisplay
= aStyleContext
->GetStyleDisplay();
3682 aNewFrame
= NS_NewTableRowGroupFrame(mPresShell
, aStyleContext
);
3684 nsIFrame
* scrollFrame
= nsnull
;
3685 if (styleDisplay
->IsScrollableOverflow()) {
3686 // Create an area container for the frame
3687 BuildScrollFrame(aState
, aContent
, aStyleContext
, aNewFrame
, parentFrame
,
3688 nsnull
, scrollFrame
, aStyleContext
);
3692 if (NS_UNLIKELY(!aNewFrame
)) {
3693 return NS_ERROR_OUT_OF_MEMORY
;
3695 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3696 // XXXbz should we be passing in a non-null aContentParentFrame?
3697 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, nsnull
, PR_FALSE
);
3701 nsFrameItems childItems
;
3702 rv
= ProcessChildren(aState
, aContent
, aNewFrame
, PR_TRUE
, childItems
,
3705 if (NS_FAILED(rv
)) return rv
;
3707 // if there are any anonymous children for the table, create frames for them
3708 CreateAnonymousFrames(nsnull
, aState
, aContent
, aNewFrame
,
3709 PR_FALSE
, childItems
);
3711 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3712 if (aIsPseudoParent
) {
3713 nsIFrame
* child
= (scrollFrame
) ? scrollFrame
: aNewFrame
;
3714 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(child
);
3718 // if there is a scroll frame, use it as the one constructed
3720 aNewFrame
= scrollFrame
;
3727 nsCSSFrameConstructor::ConstructTableColGroupFrame(nsFrameConstructorState
& aState
,
3728 nsIContent
* aContent
,
3729 nsIFrame
* aParentFrameIn
,
3730 nsStyleContext
* aStyleContext
,
3731 PRInt32 aNameSpaceID
,
3733 nsFrameItems
& aChildItems
,
3734 nsIFrame
*& aNewFrame
,
3735 PRBool
& aIsPseudoParent
)
3737 nsresult rv
= NS_OK
;
3738 if (!aParentFrameIn
) return rv
;
3740 nsIFrame
* parentFrame
= aParentFrameIn
;
3741 aIsPseudoParent
= PR_FALSE
;
3743 // this frame may have a pseudo parent
3744 GetParentFrame(aNameSpaceID
, *aParentFrameIn
,
3745 nsGkAtoms::tableColGroupFrame
, aState
, parentFrame
,
3747 if (!aIsPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3748 ProcessPseudoFrames(aState
, aChildItems
);
3750 if (!aIsPseudo
&& aIsPseudoParent
&& aState
.mPseudoFrames
.mColGroup
.mFrame
) {
3751 ProcessPseudoFrames(aState
, nsGkAtoms::tableColGroupFrame
);
3755 aNewFrame
= NS_NewTableColGroupFrame(mPresShell
, aStyleContext
);
3756 if (NS_UNLIKELY(!aNewFrame
)) {
3757 return NS_ERROR_OUT_OF_MEMORY
;
3759 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3762 nsFrameItems childItems
;
3763 rv
= ProcessChildren(aState
, aContent
, aNewFrame
, PR_TRUE
, childItems
,
3765 if (NS_FAILED(rv
)) return rv
;
3766 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3767 if (aIsPseudoParent
) {
3768 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(aNewFrame
);
3776 nsCSSFrameConstructor::ConstructTableRowFrame(nsFrameConstructorState
& aState
,
3777 nsIContent
* aContent
,
3778 nsIFrame
* aParentFrameIn
,
3779 nsStyleContext
* aStyleContext
,
3780 PRInt32 aNameSpaceID
,
3782 nsFrameItems
& aChildItems
,
3783 nsIFrame
*& aNewFrame
,
3784 PRBool
& aIsPseudoParent
)
3786 nsresult rv
= NS_OK
;
3787 if (!aParentFrameIn
) return rv
;
3789 nsIFrame
* parentFrame
= aParentFrameIn
;
3790 aIsPseudoParent
= PR_FALSE
;
3792 // this frame may have a pseudo parent
3793 GetParentFrame(aNameSpaceID
, *aParentFrameIn
,
3794 nsGkAtoms::tableRowFrame
, aState
, parentFrame
,
3796 if (!aIsPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3797 ProcessPseudoFrames(aState
, aChildItems
);
3799 if (!aIsPseudo
&& aIsPseudoParent
&& aState
.mPseudoFrames
.mRow
.mFrame
) {
3800 ProcessPseudoFrames(aState
, nsGkAtoms::tableRowFrame
);
3805 if (kNameSpaceID_MathML
== aNameSpaceID
)
3806 aNewFrame
= NS_NewMathMLmtrFrame(mPresShell
, aStyleContext
);
3809 aNewFrame
= NS_NewTableRowFrame(mPresShell
, aStyleContext
);
3811 if (NS_UNLIKELY(!aNewFrame
)) {
3812 return NS_ERROR_OUT_OF_MEMORY
;
3814 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3815 // XXXbz should we be passing in a non-null aContentParentFrame?
3816 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, nsnull
, PR_FALSE
);
3818 nsFrameItems childItems
;
3819 rv
= ProcessChildren(aState
, aContent
, aNewFrame
, PR_TRUE
, childItems
,
3821 if (NS_FAILED(rv
)) return rv
;
3822 // if there are any anonymous children for the table, create frames for them
3823 CreateAnonymousFrames(nsnull
, aState
, aContent
, aNewFrame
,
3824 PR_FALSE
, childItems
);
3826 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3827 if (aIsPseudoParent
) {
3828 aState
.mPseudoFrames
.mRowGroup
.mChildList
.AddChild(aNewFrame
);
3836 nsCSSFrameConstructor::ConstructTableColFrame(nsFrameConstructorState
& aState
,
3837 nsIContent
* aContent
,
3838 nsIFrame
* aParentFrameIn
,
3839 nsStyleContext
* aStyleContext
,
3840 PRInt32 aNameSpaceID
,
3842 nsFrameItems
& aChildItems
,
3843 nsIFrame
*& aNewFrame
,
3844 PRBool
& aIsPseudoParent
)
3846 nsresult rv
= NS_OK
;
3847 if (!aParentFrameIn
|| !aStyleContext
) return rv
;
3849 nsIFrame
* parentFrame
= aParentFrameIn
;
3850 aIsPseudoParent
= PR_FALSE
;
3852 // this frame may have a pseudo parent
3853 GetParentFrame(aNameSpaceID
, *aParentFrameIn
,
3854 nsGkAtoms::tableColFrame
, aState
, parentFrame
,
3856 if (!aIsPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3857 ProcessPseudoFrames(aState
, aChildItems
);
3861 nsTableColFrame
* colFrame
= NS_NewTableColFrame(mPresShell
, aStyleContext
);
3862 aNewFrame
= colFrame
;
3863 if (NS_UNLIKELY(!aNewFrame
)) {
3864 return NS_ERROR_OUT_OF_MEMORY
;
3866 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3868 // construct additional col frames if the col frame has a span > 1
3869 PRInt32 span
= colFrame
->GetSpan();
3870 nsIFrame
* lastCol
= aNewFrame
;
3871 nsStyleContext
* styleContext
= nsnull
;
3872 for (PRInt32 spanX
= 1; spanX
< span
; spanX
++) {
3873 // The same content node should always resolve to the same style context.
3875 styleContext
= aNewFrame
->GetStyleContext();
3876 nsTableColFrame
* newCol
= NS_NewTableColFrame(mPresShell
, styleContext
);
3877 if (NS_UNLIKELY(!newCol
)) {
3878 return NS_ERROR_OUT_OF_MEMORY
;
3880 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, newCol
, PR_FALSE
);
3881 lastCol
->SetNextSibling(newCol
);
3882 lastCol
->SetNextContinuation(newCol
);
3883 newCol
->SetPrevContinuation(lastCol
);
3884 newCol
->SetColType(eColAnonymousCol
);
3888 if (!aIsPseudo
&& aIsPseudoParent
) {
3889 aState
.mPseudoFrames
.mColGroup
.mChildList
.AddChild(aNewFrame
);
3896 nsCSSFrameConstructor::ConstructTableCellFrame(nsFrameConstructorState
& aState
,
3897 nsIContent
* aContent
,
3898 nsIFrame
* aParentFrameIn
,
3899 nsStyleContext
* aStyleContext
,
3900 PRInt32 aNameSpaceID
,
3902 nsFrameItems
& aChildItems
,
3903 nsIFrame
*& aNewCellOuterFrame
,
3904 nsIFrame
*& aNewCellInnerFrame
,
3905 PRBool
& aIsPseudoParent
)
3907 nsresult rv
= NS_OK
;
3908 if (!aParentFrameIn
) return rv
;
3910 nsIFrame
* parentFrame
= aParentFrameIn
;
3911 aIsPseudoParent
= PR_FALSE
;
3913 // this frame may have a pseudo parent
3914 // use nsGkAtoms::tableCellFrame which will match if it is really nsGkAtoms::bcTableCellFrame
3915 GetParentFrame(aNameSpaceID
, *aParentFrameIn
,
3916 nsGkAtoms::tableCellFrame
, aState
, parentFrame
,
3918 if (!aIsPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3919 ProcessPseudoFrames(aState
, aChildItems
);
3921 if (!aIsPseudo
&& aIsPseudoParent
&& aState
.mPseudoFrames
.mCellOuter
.mFrame
) {
3922 ProcessPseudoFrames(aState
, nsGkAtoms::tableCellFrame
);
3926 // <mtable> is border separate in mathml.css and the MathML code doesn't implement
3927 // border collapse. For those users who style <mtable> with border collapse,
3928 // give them the default non-MathML table frames that understand border collpase.
3929 // This won't break us because MathML table frames are all subclasses of the default
3930 // table code, and so we can freely mix <mtable> with <mtr> or <tr>, <mtd> or <td>.
3931 // What will happen is just that non-MathML frames won't understand MathML attributes
3932 // and will therefore miss the special handling that the MathML code does.
3933 if (kNameSpaceID_MathML
== aNameSpaceID
&& !IsBorderCollapse(parentFrame
))
3934 aNewCellOuterFrame
= NS_NewMathMLmtdFrame(mPresShell
, aStyleContext
);
3937 // Warning: If you change this and add a wrapper frame around table cell
3938 // frames, make sure Bug 368554 doesn't regress!
3939 // See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp.
3940 aNewCellOuterFrame
= NS_NewTableCellFrame(mPresShell
, aStyleContext
,
3941 IsBorderCollapse(parentFrame
));
3943 if (NS_UNLIKELY(!aNewCellOuterFrame
)) {
3944 return NS_ERROR_OUT_OF_MEMORY
;
3947 // Initialize the table cell frame
3948 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewCellOuterFrame
);
3949 // XXXbz should we be passing in a non-null aContentParentFrame?
3950 nsHTMLContainerFrame::CreateViewForFrame(aNewCellOuterFrame
, nsnull
, PR_FALSE
);
3952 // Resolve pseudo style and initialize the body cell frame
3953 nsRefPtr
<nsStyleContext
> innerPseudoStyle
;
3954 innerPseudoStyle
= mPresShell
->StyleSet()->
3955 ResolvePseudoStyleFor(aContent
,
3956 nsCSSAnonBoxes::cellContent
, aStyleContext
);
3958 // Create a block frame that will format the cell's content
3961 if (kNameSpaceID_MathML
== aNameSpaceID
) {
3962 aNewCellInnerFrame
= NS_NewMathMLmtdInnerFrame(mPresShell
, innerPseudoStyle
);
3968 aNewCellInnerFrame
= NS_NewTableCellInnerFrame(mPresShell
, innerPseudoStyle
);
3973 if (NS_UNLIKELY(!aNewCellInnerFrame
)) {
3974 aNewCellOuterFrame
->Destroy();
3975 aNewCellOuterFrame
= nsnull
;
3976 return NS_ERROR_OUT_OF_MEMORY
;
3979 InitAndRestoreFrame(aState
, aContent
, aNewCellOuterFrame
, nsnull
, aNewCellInnerFrame
);
3982 PRBool haveFirstLetterStyle
= PR_FALSE
, haveFirstLineStyle
= PR_FALSE
;
3984 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
3985 &haveFirstLetterStyle
, &haveFirstLineStyle
);
3988 // The block frame is a float container
3989 nsFrameConstructorSaveState floatSaveState
;
3990 aState
.PushFloatContainingBlock(isBlock
? aNewCellInnerFrame
: nsnull
,
3992 haveFirstLetterStyle
, haveFirstLineStyle
);
3994 // Process the child content
3995 nsFrameItems childItems
;
3996 rv
= ProcessChildren(aState
, aContent
, aNewCellInnerFrame
,
3997 PR_TRUE
, childItems
, isBlock
);
3999 if (NS_FAILED(rv
)) {
4001 // XXXbz kids of this stuff need to be cleaned up too!
4002 aNewCellInnerFrame
->Destroy();
4003 aNewCellInnerFrame
= nsnull
;
4004 aNewCellOuterFrame
->Destroy();
4005 aNewCellOuterFrame
= nsnull
;
4009 aNewCellInnerFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4010 aNewCellOuterFrame
->SetInitialChildList(nsnull
, aNewCellInnerFrame
);
4011 if (aIsPseudoParent
) {
4012 aState
.mPseudoFrames
.mRow
.mChildList
.AddChild(aNewCellOuterFrame
);
4020 NeedFrameFor(nsIFrame
* aParentFrame
,
4021 nsIContent
* aChildContent
)
4023 // don't create a whitespace frame if aParentFrame doesn't want it.
4024 // always create frames for children in generated content. counter(),
4025 // quotes, and attr() content can easily change dynamically and we don't
4026 // want to be reconstructing frames. It's not even clear that these
4027 // should be considered ignorable just because they evaluate to
4029 return !aParentFrame
->IsFrameOfType(nsIFrame::eExcludesIgnorableWhitespace
)
4030 || !TextIsOnlyWhitespace(aChildContent
)
4031 || aParentFrame
->IsGeneratedContentFrame();
4034 const nsStyleDisplay
*
4035 nsCSSFrameConstructor::GetDisplay(nsIFrame
* aFrame
)
4037 if (nsnull
== aFrame
) {
4040 return aFrame
->GetStyleContext()->GetStyleDisplay();
4043 /***********************************************
4045 ***********************************************/
4047 static PRBool
CheckOverflow(nsPresContext
* aPresContext
,
4048 const nsStyleDisplay
* aDisplay
)
4050 if (aDisplay
->mOverflowX
== NS_STYLE_OVERFLOW_VISIBLE
)
4053 if (aDisplay
->mOverflowX
== NS_STYLE_OVERFLOW_CLIP
)
4054 aPresContext
->SetViewportOverflowOverride(NS_STYLE_OVERFLOW_HIDDEN
,
4055 NS_STYLE_OVERFLOW_HIDDEN
);
4057 aPresContext
->SetViewportOverflowOverride(aDisplay
->mOverflowX
,
4058 aDisplay
->mOverflowY
);
4063 * This checks the root element and the HTML BODY, if any, for an "overflow" property
4064 * that should be applied to the viewport. If one is found then we return the
4065 * element that we took the overflow from (which should then be treated as
4066 * "overflow:visible"), and we store the overflow style in the prescontext.
4067 * @return if scroll was propagated from some content node, the content node it
4068 * was propagated from.
4071 nsCSSFrameConstructor::PropagateScrollToViewport()
4074 nsPresContext
* presContext
= mPresShell
->GetPresContext();
4075 presContext
->SetViewportOverflowOverride(NS_STYLE_OVERFLOW_AUTO
,
4076 NS_STYLE_OVERFLOW_AUTO
);
4078 // We never mess with the viewport scroll state
4079 // when printing or in print preview
4080 if (presContext
->IsPaginated()) {
4084 nsIContent
* docElement
= mDocument
->GetRootContent();
4086 // Check the style on the document root element
4087 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
4088 nsRefPtr
<nsStyleContext
> rootStyle
;
4089 rootStyle
= styleSet
->ResolveStyleFor(docElement
, nsnull
);
4093 if (CheckOverflow(presContext
, rootStyle
->GetStyleDisplay())) {
4094 // tell caller we stole the overflow style from the root element
4098 // Don't look in the BODY for non-HTML documents or HTML documents
4099 // with non-HTML roots
4100 // XXX this should be earlier; we shouldn't even look at the document root
4101 // for non-HTML documents. Fix this once we support explicit CSS styling
4103 // XXX what about XHTML?
4104 nsCOMPtr
<nsIDOMHTMLDocument
> htmlDoc(do_QueryInterface(mDocument
));
4105 if (!htmlDoc
|| !docElement
->IsNodeOfType(nsINode::eHTML
)) {
4109 nsCOMPtr
<nsIDOMHTMLElement
> body
;
4110 htmlDoc
->GetBody(getter_AddRefs(body
));
4111 nsCOMPtr
<nsIContent
> bodyElement
= do_QueryInterface(body
);
4114 !bodyElement
->NodeInfo()->Equals(nsGkAtoms::body
)) {
4115 // The body is not a <body> tag, it's a <frameset>.
4119 nsRefPtr
<nsStyleContext
> bodyStyle
;
4120 bodyStyle
= styleSet
->ResolveStyleFor(bodyElement
, rootStyle
);
4125 if (CheckOverflow(presContext
, bodyStyle
->GetStyleDisplay())) {
4126 // tell caller we stole the overflow style from the body element
4137 nsCSSFrameConstructor::ConstructDocElementFrame(nsFrameConstructorState
& aState
,
4138 nsIContent
* aDocElement
,
4139 nsIFrame
* aParentFrame
,
4140 nsIFrame
** aNewFrame
)
4142 *aNewFrame
= nsnull
;
4144 if (!mTempFrameTreeState
)
4145 aState
.mPresShell
->CaptureHistoryState(getter_AddRefs(mTempFrameTreeState
));
4147 // ----- reattach gfx scrollbars ------
4148 // Gfx scrollframes were created in the root frame but the primary frame map may have been destroyed if a
4149 // new style sheet was loaded so lets reattach the frames to their content.
4150 // XXX this seems truly bogus, we wipe out mGfxScrollFrame below
4151 if (mGfxScrollFrame
) {
4152 nsIFrame
* gfxScrollbarFrame1
= mGfxScrollFrame
->GetFirstChild(nsnull
);
4153 if (gfxScrollbarFrame1
) {
4154 // XXX This works, but why?
4155 aState
.mFrameManager
->
4156 SetPrimaryFrameFor(gfxScrollbarFrame1
->GetContent(), gfxScrollbarFrame1
);
4158 nsIFrame
* gfxScrollbarFrame2
= gfxScrollbarFrame1
->GetNextSibling();
4159 if (gfxScrollbarFrame2
) {
4160 // XXX This works, but why?
4161 aState
.mFrameManager
->
4162 SetPrimaryFrameFor(gfxScrollbarFrame2
->GetContent(), gfxScrollbarFrame2
);
4167 // --------- CREATE AREA OR BOX FRAME -------
4168 nsRefPtr
<nsStyleContext
> styleContext
;
4169 styleContext
= mPresShell
->StyleSet()->ResolveStyleFor(aDocElement
,
4172 const nsStyleDisplay
* display
= styleContext
->GetStyleDisplay();
4174 // Ensure that our XBL bindings are installed.
4175 if (display
->mBinding
) {
4176 // Get the XBL loader.
4178 PRBool resolveStyle
;
4180 nsIXBLService
* xblService
= GetXBLService();
4182 return NS_ERROR_FAILURE
;
4184 nsRefPtr
<nsXBLBinding
> binding
;
4185 rv
= xblService
->LoadBindings(aDocElement
, display
->mBinding
->mURI
,
4186 display
->mBinding
->mOriginPrincipal
,
4187 PR_FALSE
, getter_AddRefs(binding
),
4190 return NS_OK
; // Binding will load asynchronously.
4193 mDocument
->BindingManager()->AddToAttachedQueue(binding
);
4197 styleContext
= mPresShell
->StyleSet()->ResolveStyleFor(aDocElement
,
4199 display
= styleContext
->GetStyleDisplay();
4203 // --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------
4206 PRBool propagatedScrollToViewport
=
4207 PropagateScrollToViewport() == aDocElement
;
4209 NS_ASSERTION(!display
->IsScrollableOverflow() ||
4210 aState
.mPresContext
->IsPaginated() ||
4211 propagatedScrollToViewport
,
4212 "Scrollbars should have been propagated to the viewport");
4215 if (NS_UNLIKELY(display
->mDisplay
== NS_STYLE_DISPLAY_NONE
)) {
4216 mInitialContainingBlock
= nsnull
;
4217 mRootElementStyleFrame
= nsnull
;
4221 nsFrameConstructorSaveState absoluteSaveState
;
4222 if (mHasRootAbsPosContainingBlock
) {
4223 // Push the absolute containing block now so we can absolutely position
4225 aState
.PushAbsoluteContainingBlock(mDocElementContainingBlock
, absoluteSaveState
);
4230 // The rules from CSS 2.1, section 9.2.4, have already been applied
4231 // by the style system, so we can assume that display->mDisplay is
4232 // either NONE, BLOCK, or TABLE.
4234 PRBool docElemIsTable
= (display
->mDisplay
== NS_STYLE_DISPLAY_TABLE
) &&
4235 !IsSpecialContent(aDocElement
, aDocElement
->Tag(),
4236 aDocElement
->GetNameSpaceID(),
4239 // contentFrame is the primary frame for the root element. *aNewFrame
4240 // is the frame that will be the child of the initial containing block.
4241 // These are usually the same frame but they can be different, in
4242 // particular if the root frame is positioned, in which case
4243 // contentFrame is the out-of-flow frame and *aNewFrame is the
4245 nsIFrame
* contentFrame
;
4246 PRBool processChildren
= PR_FALSE
;
4247 if (docElemIsTable
) {
4248 nsIFrame
* innerTableFrame
;
4249 nsFrameItems frameItems
;
4250 // if the document is a table then just populate it.
4251 rv
= ConstructTableFrame(aState
, aDocElement
,
4252 aParentFrame
, styleContext
,
4253 kNameSpaceID_None
, PR_FALSE
, frameItems
, contentFrame
,
4257 if (!contentFrame
|| !frameItems
.childList
)
4258 return NS_ERROR_FAILURE
;
4259 *aNewFrame
= frameItems
.childList
;
4260 NS_ASSERTION(!frameItems
.childList
->GetNextSibling(),
4261 "multiple root element frames");
4263 // otherwise build a box or a block
4265 if (aDocElement
->IsNodeOfType(nsINode::eXUL
)) {
4266 contentFrame
= NS_NewDocElementBoxFrame(mPresShell
, styleContext
);
4267 if (NS_UNLIKELY(!contentFrame
)) {
4268 return NS_ERROR_OUT_OF_MEMORY
;
4270 InitAndRestoreFrame(aState
, aDocElement
, aParentFrame
, nsnull
, contentFrame
);
4271 *aNewFrame
= contentFrame
;
4272 processChildren
= PR_TRUE
;
4277 if (aDocElement
->GetNameSpaceID() == kNameSpaceID_SVG
) {
4278 if (aDocElement
->Tag() == nsGkAtoms::svg
&& NS_SVGEnabled()) {
4279 contentFrame
= NS_NewSVGOuterSVGFrame(mPresShell
, aDocElement
, styleContext
);
4280 if (NS_UNLIKELY(!contentFrame
)) {
4281 return NS_ERROR_OUT_OF_MEMORY
;
4283 InitAndRestoreFrame(aState
, aDocElement
,
4284 aState
.GetGeometricParent(display
, aParentFrame
),
4285 nsnull
, contentFrame
);
4287 // AddChild takes care of transforming the frame tree for fixed-pos
4288 // or abs-pos situations
4289 nsFrameItems frameItems
;
4290 rv
= aState
.AddChild(contentFrame
, frameItems
, aDocElement
,
4291 styleContext
, aParentFrame
);
4292 if (NS_FAILED(rv
) || !frameItems
.childList
) {
4295 *aNewFrame
= frameItems
.childList
;
4296 processChildren
= PR_TRUE
;
4298 // See if we need to create a view, e.g. the frame is absolutely positioned
4299 nsHTMLContainerFrame::CreateViewForFrame(contentFrame
, aParentFrame
, PR_FALSE
);
4301 return NS_ERROR_FAILURE
;
4307 contentFrame
= NS_NewBlockFrame(mPresShell
, styleContext
,
4308 NS_BLOCK_SPACE_MGR
|NS_BLOCK_MARGIN_ROOT
);
4310 return NS_ERROR_OUT_OF_MEMORY
;
4311 nsFrameItems frameItems
;
4312 rv
= ConstructBlock(aState
, display
, aDocElement
,
4313 aState
.GetGeometricParent(display
, aParentFrame
),
4314 aParentFrame
, styleContext
, &contentFrame
,
4315 frameItems
, display
->IsPositioned());
4316 if (NS_FAILED(rv
) || !frameItems
.childList
)
4318 *aNewFrame
= frameItems
.childList
;
4319 NS_ASSERTION(!frameItems
.childList
->GetNextSibling(),
4320 "multiple root element frames");
4324 // set the primary frame
4325 aState
.mFrameManager
->SetPrimaryFrameFor(aDocElement
, contentFrame
);
4327 NS_ASSERTION(processChildren
? !mInitialContainingBlock
:
4328 mInitialContainingBlock
== contentFrame
,
4329 "unexpected mInitialContainingBlock");
4330 mInitialContainingBlock
= contentFrame
;
4332 // Figure out which frame has the main style for the document element,
4333 // assigning it to mRootElementStyleFrame.
4334 // Backgrounds should be propagated from that frame to the viewport.
4336 contentFrame
->GetParentStyleContextFrame(aState
.mPresContext
,
4337 &mRootElementStyleFrame
, &isChild
);
4339 mRootElementStyleFrame
= mInitialContainingBlock
;
4342 if (processChildren
) {
4343 // Still need to process the child content
4344 nsFrameItems childItems
;
4346 // Create any anonymous frames the doc element frame requires
4347 // This must happen before ProcessChildren to ensure that popups are
4348 // never constructed before the popupset.
4349 CreateAnonymousFrames(nsnull
, aState
, aDocElement
, contentFrame
,
4350 PR_FALSE
, childItems
, PR_TRUE
);
4351 NS_ASSERTION(!nsLayoutUtils::GetAsBlock(contentFrame
),
4352 "Only XUL and SVG frames should reach here");
4353 ProcessChildren(aState
, aDocElement
, contentFrame
, PR_TRUE
, childItems
,
4356 // Set the initial child lists
4357 contentFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4365 nsCSSFrameConstructor::ConstructRootFrame(nsIContent
* aDocElement
,
4366 nsIFrame
** aNewFrame
)
4368 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
4369 NS_PRECONDITION(aNewFrame
, "null out param");
4372 how the root frame hierarchy should look
4374 Galley presentation, non-XUL, with scrolling (i.e. not a frameset):
4376 ViewportFrame [fixed-cb]
4378 CanvasFrame [abs-cb]
4379 root element frame (nsBlockFrame, nsSVGOuterSVGFrame,
4380 nsTableOuterFrame, nsPlaceholderFrame)
4382 Galley presentation, non-XUL, without scrolling (i.e. a frameset):
4384 ViewportFrame [fixed-cb]
4385 CanvasFrame [abs-cb]
4386 root element frame (nsBlockFrame)
4388 Galley presentation, XUL
4390 ViewportFrame [fixed-cb]
4392 root element frame (nsDocElementBoxFrame)
4394 Print presentation, non-XUL
4397 nsSimplePageSequenceFrame
4398 nsPageFrame [fixed-cb]
4400 CanvasFrame [abs-cb]
4401 root element frame (nsBlockFrame, nsSVGOuterSVGFrame,
4402 nsTableOuterFrame, nsPlaceholderFrame)
4404 Print-preview presentation, non-XUL
4408 nsSimplePageSequenceFrame
4409 nsPageFrame [fixed-cb]
4411 CanvasFrame [abs-cb]
4412 root element frame (nsBlockFrame, nsSVGOuterSVGFrame,
4413 nsTableOuterFrame, nsPlaceholderFrame)
4415 Print/print preview of XUL is not supported.
4416 [fixed-cb]: the default containing block for fixed-pos content
4417 [abs-cb]: the default containing block for abs-pos content
4419 Meaning of nsCSSFrameConstructor fields:
4420 mInitialContainingBlock is "root element frame".
4421 mDocElementContainingBlock is the parent of mInitialContainingBlock
4422 (i.e. CanvasFrame or nsRootBoxFrame)
4423 mFixedContainingBlock is the [fixed-cb]
4424 mGfxScrollFrame is the nsHTMLScrollFrame mentioned above, or null if there isn't one
4425 mPageSequenceFrame is the nsSimplePageSequenceFrame, or null if there isn't one
4428 // Set up our style rule observer.
4430 mPresShell
->StyleSet()->SetBindingManager(mDocument
->BindingManager());
4433 // --------- BUILD VIEWPORT -----------
4434 nsIFrame
* viewportFrame
= nsnull
;
4435 nsRefPtr
<nsStyleContext
> viewportPseudoStyle
;
4436 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
4438 viewportPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4439 nsCSSAnonBoxes::viewport
,
4442 viewportFrame
= NS_NewViewportFrame(mPresShell
, viewportPseudoStyle
);
4444 nsPresContext
* presContext
= mPresShell
->GetPresContext();
4446 // XXXbz do we _have_ to pass a null content pointer to that frame?
4447 // Would it really kill us to pass in the root element or something?
4448 // What would that break?
4449 viewportFrame
->Init(nsnull
, nsnull
, nsnull
);
4451 // Bind the viewport frame to the root view
4452 nsIViewManager
* viewManager
= mPresShell
->GetViewManager();
4455 viewManager
->GetRootView(rootView
);
4456 viewportFrame
->SetView(rootView
);
4458 nsContainerFrame::SyncFrameViewProperties(presContext
, viewportFrame
,
4459 viewportPseudoStyle
, rootView
);
4461 // The viewport is the containing block for 'fixed' elements
4462 mFixedContainingBlock
= viewportFrame
;
4464 // --------- CREATE ROOT FRAME -------
4467 // Create the root frame. The document element's frame is a child of the
4470 // The root frame serves two purposes:
4471 // - reserves space for any margins needed for the document element's frame
4472 // - renders the document element's background. This ensures the background covers
4473 // the entire canvas as specified by the CSS2 spec
4475 PRBool isPaginated
= presContext
->IsRootPaginatedDocument();
4477 nsIFrame
* rootFrame
= nsnull
;
4478 nsIAtom
* rootPseudo
;
4482 if (aDocElement
->IsNodeOfType(nsINode::eXUL
))
4484 // pass a temporary stylecontext, the correct one will be set later
4485 rootFrame
= NS_NewRootBoxFrame(mPresShell
, viewportPseudoStyle
);
4489 // pass a temporary stylecontext, the correct one will be set later
4490 rootFrame
= NS_NewCanvasFrame(mPresShell
, viewportPseudoStyle
);
4491 mHasRootAbsPosContainingBlock
= PR_TRUE
;
4494 rootPseudo
= nsCSSAnonBoxes::canvas
;
4495 mDocElementContainingBlock
= rootFrame
;
4497 // Create a page sequence frame
4498 rootFrame
= NS_NewSimplePageSequenceFrame(mPresShell
, viewportPseudoStyle
);
4499 mPageSequenceFrame
= rootFrame
;
4500 rootPseudo
= nsCSSAnonBoxes::pageSequence
;
4504 // --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------
4506 // If the device supports scrolling (e.g., in galley mode on the screen and
4507 // for print-preview, but not when printing), then create a scroll frame that
4508 // will act as the scrolling mechanism for the viewport.
4509 // XXX Do we even need a viewport when printing to a printer?
4511 // As long as the webshell doesn't prohibit it, and the device supports
4512 // it, create a scroll frame that will act as the scolling mechanism for
4515 // Threre are three possible values stored in the docshell:
4516 // 1) nsIScrollable::Scrollbar_Never = no scrollbars
4517 // 2) nsIScrollable::Scrollbar_Auto = scrollbars appear if needed
4518 // 3) nsIScrollable::Scrollbar_Always = scrollbars always
4519 // Only need to create a scroll frame/view for cases 2 and 3.
4521 PRBool isHTML
= aDocElement
->IsNodeOfType(nsINode::eHTML
);
4522 PRBool isXUL
= PR_FALSE
;
4525 isXUL
= aDocElement
->IsNodeOfType(nsINode::eXUL
);
4528 // Never create scrollbars for XUL documents
4529 PRBool isScrollable
= !isXUL
;
4531 // Never create scrollbars for frameset documents.
4533 nsCOMPtr
<nsIHTMLDocument
> htmlDoc
= do_QueryInterface(mDocument
);
4534 if (htmlDoc
&& htmlDoc
->GetIsFrameset())
4535 isScrollable
= PR_FALSE
;
4539 isScrollable
= presContext
->HasPaginatedScrolling();
4542 // We no longer need to do overflow propagation here. It's taken care of
4543 // when we construct frames for the element whose overflow might be
4545 NS_ASSERTION(!isScrollable
|| !isXUL
,
4546 "XUL documents should never be scrollable - see above");
4548 nsIFrame
* newFrame
= rootFrame
;
4549 nsRefPtr
<nsStyleContext
> rootPseudoStyle
;
4550 // we must create a state because if the scrollbars are GFX it needs the
4551 // state to build the scrollbar frames.
4552 nsFrameConstructorState
state(mPresShell
, nsnull
, nsnull
, nsnull
);
4554 nsIFrame
* parentFrame
= viewportFrame
;
4556 // If paginated, make sure we don't put scrollbars in
4557 if (!isScrollable
) {
4558 rootPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4560 viewportPseudoStyle
);
4562 if (rootPseudo
== nsCSSAnonBoxes::canvas
) {
4563 rootPseudo
= nsCSSAnonBoxes::scrolledCanvas
;
4565 NS_ASSERTION(rootPseudo
== nsCSSAnonBoxes::pageSequence
,
4566 "Unknown root pseudo");
4567 rootPseudo
= nsCSSAnonBoxes::scrolledPageSequence
;
4570 // Build the frame. We give it the content we are wrapping which is the document,
4571 // the root frame, the parent view port frame, and we should get back the new
4572 // frame and the scrollable view if one was created.
4574 // resolve a context for the scrollframe
4575 nsRefPtr
<nsStyleContext
> styleContext
;
4576 styleContext
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4577 nsCSSAnonBoxes::viewportScroll
,
4578 viewportPseudoStyle
);
4580 // Note that the viewport scrollframe is always built with
4581 // overflow:auto style. This forces the scroll frame to create
4582 // anonymous content for both scrollbars. This is necessary even
4583 // if the HTML or BODY elements are overriding the viewport
4584 // scroll style to 'hidden' --- dynamic style changes might put
4585 // scrollbars back on the viewport and we don't want to have to
4586 // reframe the viewport to create the scrollbar content.
4588 rootPseudoStyle
= BeginBuildingScrollFrame( state
,
4597 nsIScrollableFrame
* scrollable
;
4598 CallQueryInterface(newFrame
, &scrollable
);
4599 NS_ENSURE_TRUE(scrollable
, NS_ERROR_FAILURE
);
4601 nsIScrollableView
* scrollableView
= scrollable
->GetScrollableView();
4602 NS_ENSURE_TRUE(scrollableView
, NS_ERROR_FAILURE
);
4604 viewManager
->SetRootScrollableView(scrollableView
);
4605 parentFrame
= newFrame
;
4607 mGfxScrollFrame
= newFrame
;
4610 rootFrame
->SetStyleContextWithoutNotification(rootPseudoStyle
);
4611 rootFrame
->Init(aDocElement
, parentFrame
, nsnull
);
4614 FinishBuildingScrollFrame(parentFrame
, rootFrame
);
4617 if (isPaginated
) { // paginated
4618 // Create the first page
4619 // Set the initial child lists
4620 nsIFrame
*pageFrame
, *canvasFrame
;
4621 ConstructPageFrame(mPresShell
, presContext
, rootFrame
, nsnull
,
4622 pageFrame
, canvasFrame
);
4623 rootFrame
->SetInitialChildList(nsnull
, pageFrame
);
4625 // The eventual parent of the document element frame.
4626 // XXX should this be set for every new page (in ConstructPageFrame)?
4627 mDocElementContainingBlock
= canvasFrame
;
4628 mHasRootAbsPosContainingBlock
= PR_TRUE
;
4631 viewportFrame
->SetInitialChildList(nsnull
, newFrame
);
4633 *aNewFrame
= viewportFrame
;
4639 nsCSSFrameConstructor::ConstructPageFrame(nsIPresShell
* aPresShell
,
4640 nsPresContext
* aPresContext
,
4641 nsIFrame
* aParentFrame
,
4642 nsIFrame
* aPrevPageFrame
,
4643 nsIFrame
*& aPageFrame
,
4644 nsIFrame
*& aCanvasFrame
)
4646 nsStyleContext
* parentStyleContext
= aParentFrame
->GetStyleContext();
4647 nsStyleSet
*styleSet
= aPresShell
->StyleSet();
4649 nsRefPtr
<nsStyleContext
> pagePseudoStyle
;
4650 pagePseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4651 nsCSSAnonBoxes::page
,
4652 parentStyleContext
);
4654 aPageFrame
= NS_NewPageFrame(aPresShell
, pagePseudoStyle
);
4655 if (NS_UNLIKELY(!aPageFrame
))
4656 return NS_ERROR_OUT_OF_MEMORY
;
4658 // Initialize the page frame and force it to have a view. This makes printing of
4659 // the pages easier and faster.
4660 aPageFrame
->Init(nsnull
, aParentFrame
, aPrevPageFrame
);
4662 nsRefPtr
<nsStyleContext
> pageContentPseudoStyle
;
4663 pageContentPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4664 nsCSSAnonBoxes::pageContent
,
4667 nsIFrame
* pageContentFrame
= NS_NewPageContentFrame(aPresShell
, pageContentPseudoStyle
);
4668 if (NS_UNLIKELY(!pageContentFrame
))
4669 return NS_ERROR_OUT_OF_MEMORY
;
4671 // Initialize the page content frame and force it to have a view. Also make it the
4672 // containing block for fixed elements which are repeated on every page.
4673 nsIFrame
* prevPageContentFrame
= nsnull
;
4674 if (aPrevPageFrame
) {
4675 prevPageContentFrame
= aPrevPageFrame
->GetFirstChild(nsnull
);
4676 NS_ASSERTION(prevPageContentFrame
, "missing page content frame");
4678 pageContentFrame
->Init(nsnull
, aPageFrame
, prevPageContentFrame
);
4679 aPageFrame
->SetInitialChildList(nsnull
, pageContentFrame
);
4680 mFixedContainingBlock
= pageContentFrame
;
4682 nsRefPtr
<nsStyleContext
> canvasPseudoStyle
;
4683 canvasPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4684 nsCSSAnonBoxes::canvas
,
4685 pageContentPseudoStyle
);
4687 aCanvasFrame
= NS_NewCanvasFrame(aPresShell
, canvasPseudoStyle
);
4688 if (NS_UNLIKELY(!aCanvasFrame
))
4689 return NS_ERROR_OUT_OF_MEMORY
;
4691 nsIFrame
* prevCanvasFrame
= nsnull
;
4692 if (prevPageContentFrame
) {
4693 prevCanvasFrame
= prevPageContentFrame
->GetFirstChild(nsnull
);
4694 NS_ASSERTION(prevCanvasFrame
, "missing canvas frame");
4696 aCanvasFrame
->Init(nsnull
, pageContentFrame
, prevCanvasFrame
);
4697 pageContentFrame
->SetInitialChildList(nsnull
, aCanvasFrame
);
4704 nsCSSFrameConstructor::CreatePlaceholderFrameFor(nsIPresShell
* aPresShell
,
4705 nsIContent
* aContent
,
4707 nsStyleContext
* aStyleContext
,
4708 nsIFrame
* aParentFrame
,
4709 nsIFrame
* aPrevInFlow
,
4710 nsIFrame
** aPlaceholderFrame
)
4712 nsRefPtr
<nsStyleContext
> placeholderStyle
= aPresShell
->StyleSet()->
4713 ResolveStyleForNonElement(aStyleContext
->GetParent());
4715 // The placeholder frame gets a pseudo style context
4716 nsPlaceholderFrame
* placeholderFrame
=
4717 (nsPlaceholderFrame
*)NS_NewPlaceholderFrame(aPresShell
, placeholderStyle
);
4719 if (placeholderFrame
) {
4720 placeholderFrame
->Init(aContent
, aParentFrame
, aPrevInFlow
);
4722 // The placeholder frame has a pointer back to the out-of-flow frame
4723 placeholderFrame
->SetOutOfFlowFrame(aFrame
);
4725 aFrame
->AddStateBits(NS_FRAME_OUT_OF_FLOW
);
4727 // Add mapping from absolutely positioned frame to its placeholder frame
4728 aPresShell
->FrameManager()->RegisterPlaceholderFrame(placeholderFrame
);
4730 *aPlaceholderFrame
= static_cast<nsIFrame
*>(placeholderFrame
);
4735 return NS_ERROR_OUT_OF_MEMORY
;
4740 nsCSSFrameConstructor::ConstructRadioControlFrame(nsIFrame
** aNewFrame
,
4741 nsIContent
* aContent
,
4742 nsStyleContext
* aStyleContext
)
4744 *aNewFrame
= NS_NewGfxRadioControlFrame(mPresShell
, aStyleContext
);
4745 if (NS_UNLIKELY(!*aNewFrame
)) {
4746 return NS_ERROR_OUT_OF_MEMORY
;
4749 nsRefPtr
<nsStyleContext
> radioStyle
;
4750 radioStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4751 nsCSSAnonBoxes::radio
,
4753 nsIRadioControlFrame
* radio
= nsnull
;
4754 if (*aNewFrame
&& NS_SUCCEEDED(CallQueryInterface(*aNewFrame
, &radio
))) {
4755 radio
->SetRadioButtonFaceStyleContext(radioStyle
);
4761 nsCSSFrameConstructor::ConstructCheckboxControlFrame(nsIFrame
** aNewFrame
,
4762 nsIContent
* aContent
,
4763 nsStyleContext
* aStyleContext
)
4765 *aNewFrame
= NS_NewGfxCheckboxControlFrame(mPresShell
, aStyleContext
);
4766 if (NS_UNLIKELY(!*aNewFrame
)) {
4767 return NS_ERROR_OUT_OF_MEMORY
;
4770 nsRefPtr
<nsStyleContext
> checkboxStyle
;
4771 checkboxStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4772 nsCSSAnonBoxes::check
,
4774 nsICheckboxControlFrame
* checkbox
= nsnull
;
4775 if (*aNewFrame
&& NS_SUCCEEDED(CallQueryInterface(*aNewFrame
, &checkbox
))) {
4776 checkbox
->SetCheckboxFaceStyleContext(checkboxStyle
);
4782 nsCSSFrameConstructor::ConstructButtonFrame(nsFrameConstructorState
& aState
,
4783 nsIContent
* aContent
,
4784 nsIFrame
* aParentFrame
,
4786 nsStyleContext
* aStyleContext
,
4787 nsIFrame
** aNewFrame
,
4788 const nsStyleDisplay
* aStyleDisplay
,
4789 nsFrameItems
& aFrameItems
,
4790 PRBool aHasPseudoParent
)
4792 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
4793 ProcessPseudoFrames(aState
, aFrameItems
);
4796 *aNewFrame
= nsnull
;
4797 nsIFrame
* buttonFrame
= nsnull
;
4799 if (nsGkAtoms::button
== aTag
) {
4800 buttonFrame
= NS_NewHTMLButtonControlFrame(mPresShell
, aStyleContext
);
4803 buttonFrame
= NS_NewGfxButtonControlFrame(mPresShell
, aStyleContext
);
4805 if (NS_UNLIKELY(!buttonFrame
)) {
4806 return NS_ERROR_OUT_OF_MEMORY
;
4808 // Initialize the button frame
4809 nsresult rv
= InitAndRestoreFrame(aState
, aContent
,
4810 aState
.GetGeometricParent(aStyleDisplay
, aParentFrame
),
4811 nsnull
, buttonFrame
);
4812 if (NS_FAILED(rv
)) {
4813 buttonFrame
->Destroy();
4816 // See if we need to create a view, e.g. the frame is absolutely positioned
4817 nsHTMLContainerFrame::CreateViewForFrame(buttonFrame
, aParentFrame
, PR_FALSE
);
4821 nsRefPtr
<nsStyleContext
> styleContext
;
4822 styleContext
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4823 nsCSSAnonBoxes::buttonContent
,
4826 nsIFrame
* areaFrame
= NS_NewAreaFrame(mPresShell
, styleContext
,
4827 NS_BLOCK_SPACE_MGR
);
4829 if (NS_UNLIKELY(!areaFrame
)) {
4830 buttonFrame
->Destroy();
4831 return NS_ERROR_OUT_OF_MEMORY
;
4833 rv
= InitAndRestoreFrame(aState
, aContent
, buttonFrame
, nsnull
, areaFrame
);
4834 if (NS_FAILED(rv
)) {
4835 areaFrame
->Destroy();
4836 buttonFrame
->Destroy();
4840 rv
= aState
.AddChild(buttonFrame
, aFrameItems
, aContent
, aStyleContext
,
4842 if (NS_FAILED(rv
)) {
4843 areaFrame
->Destroy();
4844 buttonFrame
->Destroy();
4849 if (!buttonFrame
->IsLeaf()) {
4850 // input type="button" have only anonymous content
4851 // The area frame is a float container
4852 PRBool haveFirstLetterStyle
, haveFirstLineStyle
;
4853 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
4854 &haveFirstLetterStyle
, &haveFirstLineStyle
);
4855 nsFrameConstructorSaveState floatSaveState
;
4856 aState
.PushFloatContainingBlock(areaFrame
, floatSaveState
,
4857 haveFirstLetterStyle
,
4858 haveFirstLineStyle
);
4861 nsFrameConstructorSaveState absoluteSaveState
;
4862 nsFrameItems childItems
;
4864 if (aStyleDisplay
->IsPositioned()) {
4865 // The area frame becomes a container for child frames that are
4866 // absolutely positioned
4867 aState
.PushAbsoluteContainingBlock(areaFrame
, absoluteSaveState
);
4870 rv
= ProcessChildren(aState
, aContent
, areaFrame
, PR_TRUE
, childItems
,
4871 buttonFrame
->GetStyleDisplay()->IsBlockOutside());
4872 if (NS_FAILED(rv
)) return rv
;
4874 // Set the areas frame's initial child lists
4875 areaFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4878 buttonFrame
->SetInitialChildList(nsnull
, areaFrame
);
4880 nsFrameItems anonymousChildItems
;
4881 // if there are any anonymous children create frames for them
4882 CreateAnonymousFrames(aTag
, aState
, aContent
, buttonFrame
,
4883 PR_FALSE
, anonymousChildItems
);
4884 if (anonymousChildItems
.childList
) {
4885 // the anonymous content is already parented to the area frame
4886 aState
.mFrameManager
->AppendFrames(areaFrame
, nsnull
, anonymousChildItems
.childList
);
4889 // our new button frame returned is the top frame.
4890 *aNewFrame
= buttonFrame
;
4896 nsCSSFrameConstructor::ConstructSelectFrame(nsFrameConstructorState
& aState
,
4897 nsIContent
* aContent
,
4898 nsIFrame
* aParentFrame
,
4900 nsStyleContext
* aStyleContext
,
4901 nsIFrame
*& aNewFrame
,
4902 const nsStyleDisplay
* aStyleDisplay
,
4903 PRBool
& aFrameHasBeenInitialized
,
4904 nsFrameItems
& aFrameItems
)
4906 nsresult rv
= NS_OK
;
4907 const PRInt32 kNoSizeSpecified
= -1;
4909 // Construct a frame-based listbox or combobox
4910 nsCOMPtr
<nsIDOMHTMLSelectElement
> sel(do_QueryInterface(aContent
));
4913 sel
->GetSize(&size
);
4914 PRBool multipleSelect
= PR_FALSE
;
4915 sel
->GetMultiple(&multipleSelect
);
4916 // Construct a combobox if size=1 or no size is specified and its multiple select
4917 if (((1 == size
|| 0 == size
) || (kNoSizeSpecified
== size
)) && (PR_FALSE
== multipleSelect
)) {
4918 // Construct a frame-based combo box.
4919 // The frame-based combo box is built out of three parts. A display area, a button and
4920 // a dropdown list. The display area and button are created through anonymous content.
4921 // The drop-down list's frame is created explicitly. The combobox frame shares its content
4922 // with the drop-down list.
4923 PRUint32 flags
= NS_BLOCK_SPACE_MGR
;
4924 nsIFrame
* comboboxFrame
= NS_NewComboboxControlFrame(mPresShell
, aStyleContext
, flags
);
4926 // Save the history state so we don't restore during construction
4927 // since the complete tree is required before we restore.
4928 nsILayoutHistoryState
*historyState
= aState
.mFrameState
;
4929 aState
.mFrameState
= nsnull
;
4930 // Initialize the combobox frame
4931 InitAndRestoreFrame(aState
, aContent
,
4932 aState
.GetGeometricParent(aStyleDisplay
, aParentFrame
),
4933 nsnull
, comboboxFrame
);
4935 nsHTMLContainerFrame::CreateViewForFrame(comboboxFrame
, aParentFrame
, PR_FALSE
);
4937 rv
= aState
.AddChild(comboboxFrame
, aFrameItems
, aContent
, aStyleContext
,
4939 if (NS_FAILED(rv
)) {
4943 ///////////////////////////////////////////////////////////////////
4944 // Combobox - Old Native Implementation
4945 ///////////////////////////////////////////////////////////////////
4946 nsIComboboxControlFrame
* comboBox
= nsnull
;
4947 CallQueryInterface(comboboxFrame
, &comboBox
);
4948 NS_ASSERTION(comboBox
, "NS_NewComboboxControlFrame returned frame that "
4949 "doesn't implement nsIComboboxControlFrame");
4951 // Resolve pseudo element style for the dropdown list
4952 nsRefPtr
<nsStyleContext
> listStyle
;
4953 listStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4954 nsCSSAnonBoxes::dropDownList
,
4958 nsIFrame
* listFrame
= NS_NewListControlFrame(mPresShell
, listStyle
);
4960 // Notify the listbox that it is being used as a dropdown list.
4961 nsIListControlFrame
* listControlFrame
;
4962 rv
= CallQueryInterface(listFrame
, &listControlFrame
);
4963 if (NS_SUCCEEDED(rv
)) {
4964 listControlFrame
->SetComboboxFrame(comboboxFrame
);
4966 // Notify combobox that it should use the listbox as it's popup
4967 comboBox
->SetDropDown(listFrame
);
4969 NS_ASSERTION(!listStyle
->GetStyleDisplay()->IsPositioned(),
4970 "Ended up with positioned dropdown list somehow.");
4971 NS_ASSERTION(!listStyle
->GetStyleDisplay()->IsFloating(),
4972 "Ended up with floating dropdown list somehow.");
4974 // Initialize the scroll frame positioned. Note that it is NOT
4975 // initialized as absolutely positioned.
4976 nsIFrame
* scrolledFrame
= NS_NewSelectsAreaFrame(mPresShell
, aStyleContext
, flags
);
4978 InitializeSelectFrame(aState
, listFrame
, scrolledFrame
, aContent
,
4979 comboboxFrame
, listStyle
, PR_TRUE
, aFrameItems
);
4981 // Set flag so the events go to the listFrame not child frames.
4982 // XXX: We should replace this with a real widget manager similar
4983 // to how the nsFormControlFrame works. Re-directing events is a temporary Kludge.
4984 NS_ASSERTION(listFrame
->GetView(), "ListFrame's view is nsnull");
4985 //listFrame->GetView()->SetViewFlags(NS_VIEW_PUBLIC_FLAG_DONT_CHECK_CHILDREN);
4987 // Create display and button frames from the combobox's anonymous content.
4988 // The anonymous content is appended to existing anonymous content for this
4989 // element (the scrollbars).
4991 nsFrameItems childItems
;
4992 CreateAnonymousFrames(nsGkAtoms::combobox
, aState
, aContent
,
4993 comboboxFrame
, PR_TRUE
, childItems
);
4995 comboboxFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4997 // Initialize the additional popup child list which contains the
4998 // dropdown list frame.
4999 nsFrameItems popupItems
;
5000 popupItems
.AddChild(listFrame
);
5001 comboboxFrame
->SetInitialChildList(nsGkAtoms::selectPopupList
,
5002 popupItems
.childList
);
5004 aNewFrame
= comboboxFrame
;
5005 aFrameHasBeenInitialized
= PR_TRUE
;
5006 aState
.mFrameState
= historyState
;
5007 if (aState
.mFrameState
&& aState
.mFrameManager
) {
5008 // Restore frame state for the entire subtree of |comboboxFrame|.
5009 aState
.mFrameManager
->RestoreFrameState(comboboxFrame
,
5010 aState
.mFrameState
);
5013 ///////////////////////////////////////////////////////////////////
5014 // ListBox - Old Native Implementation
5015 ///////////////////////////////////////////////////////////////////
5016 nsIFrame
* listFrame
= NS_NewListControlFrame(mPresShell
, aStyleContext
);
5021 rv
= NS_ERROR_OUT_OF_MEMORY
;
5024 nsIFrame
* scrolledFrame
= NS_NewSelectsAreaFrame(
5025 mPresShell
, aStyleContext
, NS_BLOCK_SPACE_MGR
);
5027 // ******* this code stolen from Initialze ScrollFrame ********
5028 // please adjust this code to use BuildScrollFrame.
5030 InitializeSelectFrame(aState
, listFrame
, scrolledFrame
, aContent
,
5031 aParentFrame
, aStyleContext
, PR_FALSE
, aFrameItems
);
5033 aNewFrame
= listFrame
;
5035 aFrameHasBeenInitialized
= PR_TRUE
;
5043 * Used to be InitializeScrollFrame but now it's only used for the select tag
5044 * But the select tag should really be fixed to use GFX scrollbars that can
5045 * be create with BuildScrollFrame.
5048 nsCSSFrameConstructor::InitializeSelectFrame(nsFrameConstructorState
& aState
,
5049 nsIFrame
* scrollFrame
,
5050 nsIFrame
* scrolledFrame
,
5051 nsIContent
* aContent
,
5052 nsIFrame
* aParentFrame
,
5053 nsStyleContext
* aStyleContext
,
5054 PRBool aBuildCombobox
,
5055 nsFrameItems
& aFrameItems
)
5057 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
5060 nsIFrame
* geometricParent
= aState
.GetGeometricParent(display
, aParentFrame
);
5062 // We don't call InitAndRestoreFrame for scrollFrame because we can only
5063 // restore the frame state after its parts have been created (in particular,
5064 // the scrollable view). So we have to split Init and Restore.
5066 // Initialize the frame
5067 scrollFrame
->Init(aContent
, geometricParent
, nsnull
);
5069 if (!aBuildCombobox
) {
5070 nsresult rv
= aState
.AddChild(scrollFrame
, aFrameItems
, aContent
,
5071 aStyleContext
, aParentFrame
);
5072 if (NS_FAILED(rv
)) {
5077 nsHTMLContainerFrame::CreateViewForFrame(scrollFrame
, aParentFrame
,
5079 if (aBuildCombobox
) {
5080 // Give the drop-down list a popup widget
5081 nsIView
* view
= scrollFrame
->GetView();
5082 NS_ASSERTION(view
, "We asked for a view but didn't get one");
5084 view
->GetViewManager()->SetViewFloating(view
, PR_TRUE
);
5086 nsWidgetInitData widgetData
;
5087 widgetData
.mWindowType
= eWindowType_popup
;
5088 widgetData
.mBorderStyle
= eBorderStyle_default
;
5090 #if defined(XP_MACOSX) || defined(XP_BEOS)
5091 static NS_DEFINE_IID(kCPopUpCID
, NS_POPUP_CID
);
5092 view
->CreateWidget(kCPopUpCID
, &widgetData
, nsnull
);
5094 static NS_DEFINE_IID(kCChildCID
, NS_CHILD_CID
);
5095 view
->CreateWidget(kCChildCID
, &widgetData
, nsnull
);
5100 nsStyleContext
* scrolledPseudoStyle
;
5101 BuildScrollFrame(aState
, aContent
, aStyleContext
, scrolledFrame
,
5102 geometricParent
, aParentFrame
, scrollFrame
,
5103 scrolledPseudoStyle
);
5105 if (aState
.mFrameState
&& aState
.mFrameManager
) {
5106 // Restore frame state for the scroll frame
5107 aState
.mFrameManager
->RestoreFrameStateFor(scrollFrame
, aState
.mFrameState
);
5110 // The area frame is a float container
5111 PRBool haveFirstLetterStyle
, haveFirstLineStyle
;
5112 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
5113 &haveFirstLetterStyle
, &haveFirstLineStyle
);
5114 nsFrameConstructorSaveState floatSaveState
;
5115 aState
.PushFloatContainingBlock(scrolledFrame
, floatSaveState
,
5116 haveFirstLetterStyle
, haveFirstLineStyle
);
5119 nsFrameConstructorSaveState absoluteSaveState
;
5120 nsFrameItems childItems
;
5122 if (display
->IsPositioned()) {
5123 // The area frame becomes a container for child frames that are
5124 // absolutely positioned
5125 aState
.PushAbsoluteContainingBlock(scrolledFrame
, absoluteSaveState
);
5128 ProcessChildren(aState
, aContent
, scrolledFrame
, PR_FALSE
,
5129 childItems
, PR_TRUE
);
5131 // Set the scrolled frame's initial child lists
5132 scrolledFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
5137 nsCSSFrameConstructor::ConstructFieldSetFrame(nsFrameConstructorState
& aState
,
5138 nsIContent
* aContent
,
5139 nsIFrame
* aParentFrame
,
5141 nsStyleContext
* aStyleContext
,
5142 nsIFrame
*& aNewFrame
,
5143 nsFrameItems
& aFrameItems
,
5144 const nsStyleDisplay
* aStyleDisplay
,
5145 PRBool
& aFrameHasBeenInitialized
)
5147 nsIFrame
* newFrame
= NS_NewFieldSetFrame(mPresShell
, aStyleContext
);
5148 if (NS_UNLIKELY(!newFrame
)) {
5149 return NS_ERROR_OUT_OF_MEMORY
;
5153 InitAndRestoreFrame(aState
, aContent
,
5154 aState
.GetGeometricParent(aStyleDisplay
, aParentFrame
),
5157 // See if we need to create a view, e.g. the frame is absolutely
5159 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, aParentFrame
, PR_FALSE
);
5161 // Resolve style and initialize the frame
5162 nsRefPtr
<nsStyleContext
> styleContext
;
5163 styleContext
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
5164 nsCSSAnonBoxes::fieldsetContent
,
5167 nsIFrame
* areaFrame
= NS_NewAreaFrame(mPresShell
, styleContext
,
5168 NS_BLOCK_SPACE_MGR
| NS_BLOCK_MARGIN_ROOT
);
5169 InitAndRestoreFrame(aState
, aContent
, newFrame
, nsnull
, areaFrame
);
5171 nsresult rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
5173 if (NS_FAILED(rv
)) {
5178 // The area frame is a float container
5179 PRBool haveFirstLetterStyle
, haveFirstLineStyle
;
5180 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
5181 &haveFirstLetterStyle
, &haveFirstLineStyle
);
5182 nsFrameConstructorSaveState floatSaveState
;
5183 aState
.PushFloatContainingBlock(areaFrame
, floatSaveState
,
5184 haveFirstLetterStyle
,
5185 haveFirstLineStyle
);
5188 nsFrameConstructorSaveState absoluteSaveState
;
5189 nsFrameItems childItems
;
5191 if (aStyleDisplay
->IsPositioned()) {
5192 // The area frame becomes a container for child frames that are
5193 // absolutely positioned
5194 aState
.PushAbsoluteContainingBlock(areaFrame
, absoluteSaveState
);
5197 ProcessChildren(aState
, aContent
, areaFrame
, PR_TRUE
,
5198 childItems
, PR_TRUE
);
5200 static NS_DEFINE_IID(kLegendFrameCID
, NS_LEGEND_FRAME_CID
);
5201 nsIFrame
* child
= childItems
.childList
;
5202 nsIFrame
* previous
= nsnull
;
5203 nsIFrame
* legendFrame
= nsnull
;
5204 while (nsnull
!= child
) {
5205 nsresult result
= child
->QueryInterface(kLegendFrameCID
, (void**)&legendFrame
);
5206 if (NS_SUCCEEDED(result
) && legendFrame
) {
5207 // We want the legend to be the first frame in the fieldset child list.
5208 // That way the EventStateManager will do the right thing when tabbing
5209 // from a selection point within the legend (bug 236071), which is
5210 // used for implementing legend access keys (bug 81481).
5211 // GetAdjustedParentFrame() below depends on this frame order.
5212 if (nsnull
!= previous
) {
5213 previous
->SetNextSibling(legendFrame
->GetNextSibling());
5215 childItems
.childList
= legendFrame
->GetNextSibling();
5217 legendFrame
->SetNextSibling(areaFrame
);
5218 legendFrame
->SetParent(newFrame
);
5222 child
= child
->GetNextSibling();
5225 // Set the scrolled frame's initial child lists
5226 areaFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
5228 // Set the scroll frame's initial child list
5229 newFrame
->SetInitialChildList(nsnull
, legendFrame
? legendFrame
: areaFrame
);
5231 // our new frame returned is the top frame which is the list frame.
5232 aNewFrame
= newFrame
;
5234 // yes we have already initialized our frame
5235 aFrameHasBeenInitialized
= PR_TRUE
;
5241 FindAncestorWithGeneratedContentPseudo(nsIFrame
* aFrame
)
5243 for (nsIFrame
* f
= aFrame
->GetParent(); f
; f
= f
->GetParent()) {
5244 NS_ASSERTION(f
->IsGeneratedContentFrame(),
5245 "should not have exited generated content");
5246 nsIAtom
* pseudo
= f
->GetStyleContext()->GetPseudoType();
5247 if (pseudo
== nsCSSPseudoElements::before
||
5248 pseudo
== nsCSSPseudoElements::after
)
5255 nsCSSFrameConstructor::ConstructTextFrame(nsFrameConstructorState
& aState
,
5256 nsIContent
* aContent
,
5257 nsIFrame
* aParentFrame
,
5258 nsStyleContext
* aStyleContext
,
5259 nsFrameItems
& aFrameItems
,
5260 PRBool aPseudoParent
)
5262 // process pending pseudo frames. whitespace doesn't have an effect.
5263 if (!aPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty() &&
5264 !TextIsOnlyWhitespace(aContent
))
5265 ProcessPseudoFrames(aState
, aFrameItems
);
5267 nsIFrame
* newFrame
= nsnull
;
5270 if (aParentFrame
->IsFrameOfType(nsIFrame::eSVG
)) {
5271 nsIFrame
*ancestorFrame
= SVG_GetFirstNonAAncestorFrame(aParentFrame
);
5272 if (ancestorFrame
) {
5273 nsISVGTextContentMetrics
* metrics
;
5274 CallQueryInterface(ancestorFrame
, &metrics
);
5278 newFrame
= NS_NewSVGGlyphFrame(mPresShell
, aContent
,
5279 ancestorFrame
, aStyleContext
);
5285 newFrame
= NS_NewTextFrame(mPresShell
, aStyleContext
);
5288 if (NS_UNLIKELY(!newFrame
))
5289 return NS_ERROR_OUT_OF_MEMORY
;
5291 nsresult rv
= InitAndRestoreFrame(aState
, aContent
, aParentFrame
,
5294 if (NS_FAILED(rv
)) {
5295 newFrame
->Destroy();
5299 // We never need to create a view for a text frame.
5301 if (newFrame
->IsGeneratedContentFrame()) {
5302 nsAutoPtr
<nsGenConInitializer
> initializer
;
5304 static_cast<nsGenConInitializer
*>(
5305 aContent
->UnsetProperty(nsGkAtoms::genConInitializerProperty
));
5307 if (initializer
->mNode
->InitTextFrame(initializer
->mList
,
5308 FindAncestorWithGeneratedContentPseudo(newFrame
), newFrame
)) {
5309 (this->*(initializer
->mDirtyAll
))();
5311 initializer
->mNode
.forget();
5315 // Add the newly constructed frame to the flow
5316 aFrameItems
.AddChild(newFrame
);
5318 // Text frames don't go in the content->frame hash table, because
5319 // they're anonymous. This keeps the hash table smaller
5325 nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState
& aState
,
5326 nsIContent
* aContent
,
5327 nsIFrame
* aParentFrame
,
5329 PRInt32 aNameSpaceID
,
5330 nsStyleContext
* aStyleContext
,
5331 nsFrameItems
& aFrameItems
,
5332 PRBool aHasPseudoParent
)
5334 // Ignore the tag if it's not HTML content and if it doesn't extend (via XBL)
5335 // a valid HTML namespace. This check must match the one in
5336 // ShouldHaveFirstLineStyle.
5337 if (!aContent
->IsNodeOfType(nsINode::eHTML
) &&
5338 aNameSpaceID
!= kNameSpaceID_XHTML
) {
5342 PRBool frameHasBeenInitialized
= PR_FALSE
;
5343 nsIFrame
* newFrame
= nsnull
; // the frame we construct
5344 PRBool addToHashTable
= PR_TRUE
;
5345 PRBool isFloatContainer
= PR_FALSE
;
5346 PRBool addedToFrameList
= PR_FALSE
;
5347 nsresult rv
= NS_OK
;
5349 PRBool triedFrame
= PR_FALSE
;
5351 // See if the element is absolute or fixed positioned
5352 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
5354 // Create a frame based on the tag
5355 if (nsGkAtoms::img
== aTag
|| nsGkAtoms::mozgeneratedcontentimage
== aTag
) {
5356 // Make sure to keep IsSpecialContent in synch with this code
5357 rv
= CreateHTMLImageFrame(aContent
, aStyleContext
, NS_NewImageFrame
,
5360 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5361 ProcessPseudoFrames(aState
, aFrameItems
);
5365 else if (nsGkAtoms::br
== aTag
) {
5366 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5367 ProcessPseudoFrames(aState
, aFrameItems
);
5369 newFrame
= NS_NewBRFrame(mPresShell
, aStyleContext
);
5370 triedFrame
= PR_TRUE
;
5372 // BR frames don't go in the content->frame hash table: typically
5373 // there are many BR content objects and this would increase the size
5374 // of the hash table, and it's doubtful we need the mapping anyway
5375 addToHashTable
= PR_FALSE
;
5377 else if (nsGkAtoms::wbr
== aTag
) {
5378 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5379 ProcessPseudoFrames(aState
, aFrameItems
);
5381 newFrame
= NS_NewWBRFrame(mPresShell
, aStyleContext
);
5382 triedFrame
= PR_TRUE
;
5384 else if (nsGkAtoms::input
== aTag
) {
5385 // Make sure to keep IsSpecialContent in synch with this code
5386 rv
= CreateInputFrame(aState
, aContent
, aParentFrame
,
5387 aTag
, aStyleContext
, &newFrame
,
5388 display
, frameHasBeenInitialized
,
5389 addedToFrameList
, aFrameItems
,
5391 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty() &&
5392 newFrame
&& !addedToFrameList
) {
5393 // We'll still be adding this new frame, and it's a replaced
5394 // element, so process pseudo-frames now.
5395 ProcessPseudoFrames(aState
, aFrameItems
);
5398 else if (nsGkAtoms::textarea
== aTag
) {
5399 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5400 ProcessPseudoFrames(aState
, aFrameItems
);
5402 newFrame
= NS_NewTextControlFrame(mPresShell
, aStyleContext
);
5403 triedFrame
= PR_TRUE
;
5405 else if (nsGkAtoms::select
== aTag
) {
5406 if (!gUseXBLForms
) {
5407 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5408 ProcessPseudoFrames(aState
, aFrameItems
);
5410 rv
= ConstructSelectFrame(aState
, aContent
, aParentFrame
,
5411 aTag
, aStyleContext
, newFrame
,
5412 display
, frameHasBeenInitialized
,
5415 NS_ASSERTION(nsPlaceholderFrame::GetRealFrameFor(aFrameItems
.lastChild
) ==
5417 "Frame didn't get added to aFrameItems?");
5418 addedToFrameList
= PR_TRUE
;
5422 else if (nsGkAtoms::object
== aTag
||
5423 nsGkAtoms::applet
== aTag
||
5424 nsGkAtoms::embed
== aTag
) {
5425 // Make sure to keep IsSpecialContent in synch with this code
5426 if (!(aContent
->IntrinsicState() &
5427 (NS_EVENT_STATE_BROKEN
| NS_EVENT_STATE_USERDISABLED
|
5428 NS_EVENT_STATE_SUPPRESSED
))) {
5429 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5430 ProcessPseudoFrames(aState
, aFrameItems
);
5433 nsCOMPtr
<nsIObjectLoadingContent
> objContent(do_QueryInterface(aContent
));
5434 NS_ASSERTION(objContent
,
5435 "applet, embed and object must implement nsIObjectLoadingContent!");
5437 // XBL might trigger this...
5438 return NS_ERROR_UNEXPECTED
;
5442 objContent
->GetDisplayedType(&type
);
5443 if (type
== nsIObjectLoadingContent::TYPE_LOADING
) {
5444 // Ideally, this should show the standby attribute
5445 // XXX Should we return something that is replaced, or make
5446 // nsFrame replaced but not its subclasses?
5447 newFrame
= NS_NewEmptyFrame(mPresShell
, aStyleContext
);
5449 else if (type
== nsIObjectLoadingContent::TYPE_PLUGIN
)
5450 newFrame
= NS_NewObjectFrame(mPresShell
, aStyleContext
);
5451 else if (type
== nsIObjectLoadingContent::TYPE_IMAGE
)
5452 newFrame
= NS_NewImageFrame(mPresShell
, aStyleContext
);
5453 else if (type
== nsIObjectLoadingContent::TYPE_DOCUMENT
)
5454 newFrame
= NS_NewSubDocumentFrame(mPresShell
, aStyleContext
);
5457 NS_ERROR("Shouldn't get here if we're not broken and not "
5458 "suppressed and not blocked");
5461 triedFrame
= PR_TRUE
;
5464 else if (nsGkAtoms::fieldset
== aTag
) {
5465 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5466 ProcessPseudoFrames(aState
, aFrameItems
);
5468 rv
= ConstructFieldSetFrame(aState
, aContent
, aParentFrame
,
5469 aTag
, aStyleContext
, newFrame
,
5470 aFrameItems
, display
, frameHasBeenInitialized
);
5471 NS_ASSERTION(nsPlaceholderFrame::GetRealFrameFor(aFrameItems
.lastChild
) ==
5473 "Frame didn't get added to aFrameItems?");
5474 addedToFrameList
= PR_TRUE
;
5476 else if (nsGkAtoms::legend
== aTag
) {
5477 NS_ASSERTION(!display
->IsAbsolutelyPositioned() && !display
->IsFloating(),
5478 "Legends should not be positioned and should not float");
5480 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5481 ProcessPseudoFrames(aState
, aFrameItems
);
5483 newFrame
= NS_NewLegendFrame(mPresShell
, aStyleContext
);
5484 triedFrame
= PR_TRUE
;
5486 isFloatContainer
= PR_TRUE
;
5488 else if (nsGkAtoms::frameset
== aTag
) {
5489 NS_ASSERTION(!display
->IsAbsolutelyPositioned() && !display
->IsFloating(),
5490 "Framesets should not be positioned and should not float");
5492 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5493 ProcessPseudoFrames(aState
, aFrameItems
);
5496 newFrame
= NS_NewHTMLFramesetFrame(mPresShell
, aStyleContext
);
5497 triedFrame
= PR_TRUE
;
5499 else if (nsGkAtoms::iframe
== aTag
) {
5500 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5501 ProcessPseudoFrames(aState
, aFrameItems
);
5504 newFrame
= NS_NewSubDocumentFrame(mPresShell
, aStyleContext
);
5505 triedFrame
= PR_TRUE
;
5508 // the nsSubDocumentFrame needs to know about its content parent during ::Init.
5509 // there is no reasonable way to get the value there.
5510 // so we store it as a frame property.
5511 nsCOMPtr
<nsIAtom
> contentParentAtom
= do_GetAtom("contentParent");
5512 aState
.mPresContext
->PropertyTable()->
5513 SetProperty(newFrame
, contentParentAtom
,
5514 aParentFrame
, nsnull
, nsnull
);
5517 else if (nsGkAtoms::spacer
== aTag
) {
5518 NS_ASSERTION(!display
->IsAbsolutelyPositioned() && !display
->IsFloating(),
5519 "Spacers should not be positioned and should not float");
5520 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5521 ProcessPseudoFrames(aState
, aFrameItems
);
5523 newFrame
= NS_NewSpacerFrame(mPresShell
, aStyleContext
);
5524 triedFrame
= PR_TRUE
;
5526 else if (nsGkAtoms::button
== aTag
) {
5527 rv
= ConstructButtonFrame(aState
, aContent
, aParentFrame
,
5528 aTag
, aStyleContext
, &newFrame
,
5529 display
, aFrameItems
, aHasPseudoParent
);
5530 // the html4 button needs to act just like a
5531 // regular button except contain html content
5532 // so it must be replaced or html outside it will
5533 // draw into its borders. -EDV
5534 frameHasBeenInitialized
= PR_TRUE
;
5535 addedToFrameList
= PR_TRUE
;
5536 isFloatContainer
= PR_TRUE
;
5538 else if (nsGkAtoms::isindex
== aTag
) {
5539 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5540 ProcessPseudoFrames(aState
, aFrameItems
);
5542 newFrame
= NS_NewIsIndexFrame(mPresShell
, aStyleContext
);
5543 triedFrame
= PR_TRUE
;
5545 else if (nsGkAtoms::canvas
== aTag
) {
5546 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5547 ProcessPseudoFrames(aState
, aFrameItems
);
5549 newFrame
= NS_NewHTMLCanvasFrame(mPresShell
, aStyleContext
);
5550 triedFrame
= PR_TRUE
;
5552 #if defined(MOZ_MEDIA)
5553 else if (nsGkAtoms::video
== aTag
|| nsGkAtoms::audio
== aTag
) {
5554 // We create video frames for audio elements so we can show controls.
5555 // Note that html.css specifies display:none for audio elements
5556 // without the "controls" attribute.
5557 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
5558 ProcessPseudoFrames(aState
, aFrameItems
);
5560 newFrame
= NS_NewHTMLVideoFrame(mPresShell
, aStyleContext
);
5561 triedFrame
= PR_TRUE
;
5564 if (NS_UNLIKELY(triedFrame
&& !newFrame
)) {
5565 return NS_ERROR_OUT_OF_MEMORY
;
5567 else if (NS_FAILED(rv
) || !newFrame
) {
5571 // If we succeeded in creating a frame then initialize it, process its
5572 // children (if requested), and set the initial child list
5574 // Note: at this point we should construct kids for newFrame only if
5575 // it's not a leaf and hasn't been initialized yet.
5577 if (!frameHasBeenInitialized
) {
5578 NS_ASSERTION(!addedToFrameList
,
5579 "Frames that were already added to the frame list should be "
5580 "initialized by now!");
5581 nsIFrame
* geometricParent
= aState
.GetGeometricParent(display
,
5584 rv
= InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
, newFrame
);
5585 NS_ASSERTION(NS_SUCCEEDED(rv
), "InitAndRestoreFrame failed");
5586 // See if we need to create a view, e.g. the frame is absolutely
5588 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, aParentFrame
, PR_FALSE
);
5590 rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
5592 if (NS_FAILED(rv
)) {
5595 addedToFrameList
= PR_TRUE
;
5597 // Process the child content if requested
5598 nsFrameItems childItems
;
5599 nsFrameConstructorSaveState absoluteSaveState
;
5600 nsFrameConstructorSaveState floatSaveState
;
5601 if (!newFrame
->IsLeaf()) {
5602 if (display
->IsPositioned()) {
5603 aState
.PushAbsoluteContainingBlock(newFrame
, absoluteSaveState
);
5605 if (isFloatContainer
) {
5606 PRBool haveFirstLetterStyle
, haveFirstLineStyle
;
5607 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
5608 &haveFirstLetterStyle
,
5609 &haveFirstLineStyle
);
5610 aState
.PushFloatContainingBlock(newFrame
, floatSaveState
,
5611 PR_FALSE
, PR_FALSE
);
5614 // Process the child frames
5615 rv
= ProcessChildren(aState
, aContent
, newFrame
,
5616 PR_TRUE
, childItems
, PR_FALSE
);
5619 // if there are any anonymous children create frames for them
5620 CreateAnonymousFrames(aTag
, aState
, aContent
, newFrame
,
5621 PR_FALSE
, childItems
);
5623 // Set the frame's initial child list
5624 if (childItems
.childList
) {
5625 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
5629 if (!addedToFrameList
) {
5630 // Gotta do it here. Note that things like absolutely positioned replaced
5631 // elements and the like will end up in this code. So use the AddChild
5633 rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
5635 if (NS_FAILED(rv
)) {
5640 if (addToHashTable
) {
5641 // Add a mapping from content object to primary frame. Note that for
5642 // floated and positioned frames this is the out-of-flow frame and not
5643 // the placeholder frame
5644 aState
.mFrameManager
->SetPrimaryFrameFor(aContent
, newFrame
);
5651 nsCSSFrameConstructor::CreateAnonymousFrames(nsIAtom
* aTag
,
5652 nsFrameConstructorState
& aState
,
5653 nsIContent
* aParent
,
5654 nsIFrame
* aNewFrame
,
5655 PRBool aAppendToExisting
,
5656 nsFrameItems
& aChildItems
,
5659 // See if we might have anonymous content
5660 // by looking at the tag rather than doing a QueryInterface on
5661 // the frame. Only these tags' frames can have anonymous content
5662 // through nsIAnonymousContentCreator. We do this check for
5663 // performance reasons. If we did a QueryInterface on every tag it
5664 // would be inefficient.
5666 // nsGenericElement::SetDocument ought to keep a list like this one,
5667 // but it can't because scroll frames get around this.
5669 aTag
!= nsGkAtoms::input
&&
5670 aTag
!= nsGkAtoms::textarea
&&
5671 aTag
!= nsGkAtoms::combobox
&&
5672 aTag
!= nsGkAtoms::isindex
&&
5673 aTag
!= nsGkAtoms::scrollbar
5675 && aTag
!= nsGkAtoms::use
5678 && aTag
!= nsGkAtoms::video
5679 && aTag
!= nsGkAtoms::audio
5684 return CreateAnonymousFrames(aState
, aParent
, mDocument
, aNewFrame
,
5685 aAppendToExisting
, aChildItems
);
5688 // after the node has been constructed and initialized create any
5689 // anonymous content a node needs.
5691 nsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState
& aState
,
5692 nsIContent
* aParent
,
5693 nsIDocument
* aDocument
,
5694 nsIFrame
* aParentFrame
,
5695 PRBool aAppendToExisting
,
5696 nsFrameItems
& aChildItems
)
5698 nsIAnonymousContentCreator
* creator
= nsnull
;
5699 CallQueryInterface(aParentFrame
, &creator
);
5705 nsAutoTArray
<nsIContent
*, 4> newAnonymousItems
;
5706 rv
= creator
->CreateAnonymousContent(newAnonymousItems
);
5707 NS_ENSURE_SUCCESS(rv
, rv
);
5709 PRUint32 count
= newAnonymousItems
.Length();
5714 // save the incoming pseudo frame state, so that we don't end up
5715 // with those pseudoframes in aChildItems
5716 nsPseudoFrames priorPseudoFrames
;
5717 aState
.mPseudoFrames
.Reset(&priorPseudoFrames
);
5719 for (PRUint32 i
=0; i
< count
; i
++) {
5720 // get our child's content and set its parent to our content
5721 nsIContent
* content
= newAnonymousItems
[i
];
5722 NS_ASSERTION(content
, "null anonymous content?");
5725 // least-surprise CSS binding until we do the SVG specified
5726 // cascading rules for <svg:use> - bug 265894
5728 !aParent
->NodeInfo()->Equals(nsGkAtoms::use
, kNameSpaceID_SVG
))
5731 content
->SetNativeAnonymous();
5734 rv
= content
->BindToTree(aDocument
, aParent
, aParent
, PR_TRUE
);
5735 if (NS_FAILED(rv
)) {
5736 content
->UnbindFromTree();
5740 nsIFrame
* newFrame
= creator
->CreateFrameFor(content
);
5742 aChildItems
.AddChild(newFrame
);
5745 // create the frame and attach it to our frame
5746 ConstructFrame(aState
, content
, aParentFrame
, aChildItems
);
5750 creator
->PostCreateFrames();
5752 // process the current pseudo frame state
5753 if (!aState
.mPseudoFrames
.IsEmpty()) {
5754 ProcessPseudoFrames(aState
, aChildItems
);
5757 // restore the incoming pseudo frame state
5758 aState
.mPseudoFrames
= priorPseudoFrames
;
5764 PRBool
IsXULDisplayType(const nsStyleDisplay
* aDisplay
)
5766 return (aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_BOX
||
5767 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_GRID
||
5768 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_STACK
||
5769 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_BOX
||
5770 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GRID
||
5771 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_STACK
||
5772 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GRID_GROUP
||
5773 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GRID_LINE
||
5774 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_DECK
||
5775 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_POPUP
||
5776 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GROUPBOX
5781 nsCSSFrameConstructor::ConstructXULFrame(nsFrameConstructorState
& aState
,
5782 nsIContent
* aContent
,
5783 nsIFrame
* aParentFrame
,
5785 PRInt32 aNameSpaceID
,
5786 nsStyleContext
* aStyleContext
,
5787 nsFrameItems
& aFrameItems
,
5789 PRBool aHasPseudoParent
,
5790 PRBool
* aHaltProcessing
)
5792 *aHaltProcessing
= PR_FALSE
;
5794 PRBool primaryFrameSet
= PR_FALSE
;
5795 nsresult rv
= NS_OK
;
5796 PRBool isPopup
= PR_FALSE
;
5797 PRBool frameHasBeenInitialized
= PR_FALSE
;
5799 // XXXbz somewhere here we should process pseudo frames if !aHasPseudoParent
5801 // this is the new frame that will be created
5802 nsIFrame
* newFrame
= nsnull
;
5804 // this is the also the new frame that is created. But if a scroll frame is needed
5805 // the content will be mapped to the scrollframe and topFrame will point to it.
5806 // newFrame will still point to the child that we created like a "div" for example.
5807 nsIFrame
* topFrame
= nsnull
;
5809 // Store aParentFrame away, since we plan to stomp on it later
5810 nsIFrame
* origParentFrame
= aParentFrame
;
5812 NS_ASSERTION(aTag
!= nsnull
, "null XUL tag");
5816 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
5818 PRBool isXULNS
= (aNameSpaceID
== kNameSpaceID_XUL
);
5819 PRBool isXULDisplay
= IsXULDisplayType(display
);
5821 // don't apply xul display types to tag based frames
5822 if (isXULDisplay
&& !isXULNS
) {
5823 isXULDisplay
= !IsSpecialContent(aContent
, aTag
, aNameSpaceID
, aStyleContext
);
5826 PRBool triedFrame
= PR_FALSE
;
5828 if (isXULNS
|| isXULDisplay
) {
5829 PRBool mayBeScrollable
= PR_FALSE
;
5832 triedFrame
= PR_TRUE
;
5834 // First try creating a frame based on the tag
5835 // Make sure to keep IsSpecialContent in synch with this code
5837 // BUTTON CONSTRUCTION
5838 if (aTag
== nsGkAtoms::button
|| aTag
== nsGkAtoms::checkbox
|| aTag
== nsGkAtoms::radio
) {
5839 newFrame
= NS_NewButtonBoxFrame(mPresShell
, aStyleContext
);
5841 // Boxes can scroll.
5842 mayBeScrollable
= PR_TRUE
;
5843 } // End of BUTTON CONSTRUCTION logic
5844 // AUTOREPEATBUTTON CONSTRUCTION
5845 else if (aTag
== nsGkAtoms::autorepeatbutton
) {
5846 newFrame
= NS_NewAutoRepeatBoxFrame(mPresShell
, aStyleContext
);
5848 // Boxes can scroll.
5849 mayBeScrollable
= PR_TRUE
;
5850 } // End of AUTOREPEATBUTTON CONSTRUCTION logic
5852 // TITLEBAR CONSTRUCTION
5853 else if (aTag
== nsGkAtoms::titlebar
) {
5854 newFrame
= NS_NewTitleBarFrame(mPresShell
, aStyleContext
);
5856 // Boxes can scroll.
5857 mayBeScrollable
= PR_TRUE
;
5858 } // End of TITLEBAR CONSTRUCTION logic
5860 // RESIZER CONSTRUCTION
5861 else if (aTag
== nsGkAtoms::resizer
) {
5862 newFrame
= NS_NewResizerFrame(mPresShell
, aStyleContext
);
5864 // Boxes can scroll.
5865 mayBeScrollable
= PR_TRUE
;
5866 } // End of RESIZER CONSTRUCTION logic
5868 else if (aTag
== nsGkAtoms::image
) {
5869 newFrame
= NS_NewImageBoxFrame(mPresShell
, aStyleContext
);
5871 else if (aTag
== nsGkAtoms::spring
||
5872 aTag
== nsGkAtoms::spacer
) {
5873 newFrame
= NS_NewLeafBoxFrame(mPresShell
, aStyleContext
);
5875 else if (aTag
== nsGkAtoms::treechildren
) {
5876 newFrame
= NS_NewTreeBodyFrame(mPresShell
, aStyleContext
);
5878 else if (aTag
== nsGkAtoms::treecol
) {
5879 newFrame
= NS_NewTreeColFrame(mPresShell
, aStyleContext
);
5881 // TEXT CONSTRUCTION
5882 else if (aTag
== nsGkAtoms::text
|| aTag
== nsGkAtoms::label
||
5883 aTag
== nsGkAtoms::description
) {
5884 if ((aTag
== nsGkAtoms::label
|| aTag
== nsGkAtoms::description
) &&
5885 (! aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::value
))) {
5886 // XXX we should probably be calling ConstructBlock here to handle
5887 // things like columns etc
5888 newFrame
= NS_NewAreaFrame(mPresShell
, aStyleContext
,
5889 NS_BLOCK_SPACE_MGR
| NS_BLOCK_MARGIN_ROOT
);
5892 newFrame
= NS_NewTextBoxFrame(mPresShell
, aStyleContext
);
5895 // End of TEXT CONSTRUCTION logic
5897 // Menu Construction
5898 else if (aTag
== nsGkAtoms::menu
||
5899 aTag
== nsGkAtoms::menuitem
||
5900 aTag
== nsGkAtoms::menubutton
) {
5901 // A derived class box frame
5902 // that has custom reflow to prevent menu children
5903 // from becoming part of the flow.
5904 newFrame
= NS_NewMenuFrame(mPresShell
, aStyleContext
,
5905 (aTag
!= nsGkAtoms::menuitem
));
5907 else if (aTag
== nsGkAtoms::menubar
) {
5909 // On Mac OS X, we use the system menubar for any root chrome shell
5911 PRBool isRootChromeShell
= PR_FALSE
;
5912 nsCOMPtr
<nsISupports
> container
= aState
.mPresContext
->GetContainer();
5914 nsCOMPtr
<nsIDocShellTreeItem
> treeItem(do_QueryInterface(container
));
5917 treeItem
->GetItemType(&type
);
5918 if (nsIDocShellTreeItem::typeChrome
== type
) {
5919 nsCOMPtr
<nsIDocShellTreeItem
> parent
;
5920 treeItem
->GetParent(getter_AddRefs(parent
));
5921 isRootChromeShell
= !parent
;
5926 if (isRootChromeShell
) {
5927 *aHaltProcessing
= PR_TRUE
;
5932 newFrame
= NS_NewMenuBarFrame(mPresShell
, aStyleContext
);
5934 else if (aTag
== nsGkAtoms::popupgroup
&&
5935 aContent
->IsRootOfNativeAnonymousSubtree()) {
5936 // This frame contains child popups
5937 newFrame
= NS_NewPopupSetFrame(mPresShell
, aStyleContext
);
5939 else if (aTag
== nsGkAtoms::iframe
|| aTag
== nsGkAtoms::editor
||
5940 aTag
== nsGkAtoms::browser
) {
5941 newFrame
= NS_NewSubDocumentFrame(mPresShell
, aStyleContext
);
5943 // PROGRESS METER CONSTRUCTION
5944 else if (aTag
== nsGkAtoms::progressmeter
) {
5945 newFrame
= NS_NewProgressMeterFrame(mPresShell
, aStyleContext
);
5947 // End of PROGRESS METER CONSTRUCTION logic
5950 // SLIDER CONSTRUCTION
5951 if (aTag
== nsGkAtoms::slider
) {
5952 newFrame
= NS_NewSliderFrame(mPresShell
, aStyleContext
);
5954 // End of SLIDER CONSTRUCTION logic
5956 // SCROLLBAR CONSTRUCTION
5957 else if (aTag
== nsGkAtoms::scrollbar
) {
5958 newFrame
= NS_NewScrollbarFrame(mPresShell
, aStyleContext
);
5960 // End of SCROLLBAR CONSTRUCTION logic
5962 // SCROLLBUTTON CONSTRUCTION
5963 else if (aTag
== nsGkAtoms::scrollbarbutton
) {
5964 newFrame
= NS_NewScrollbarButtonFrame(mPresShell
, aStyleContext
);
5966 // End of SCROLLBUTTON CONSTRUCTION logic
5969 // SPLITTER CONSTRUCTION
5970 else if (aTag
== nsGkAtoms::splitter
) {
5971 newFrame
= NS_NewSplitterFrame(mPresShell
, aStyleContext
);
5973 // End of SPLITTER CONSTRUCTION logic
5976 triedFrame
= PR_FALSE
;
5981 // Display types for XUL start here
5982 // Make sure this is kept in sync with nsCSSProps::kDisplayKTable
5984 if (!newFrame
&& isXULDisplay
) {
5985 triedFrame
= PR_TRUE
;
5987 if (display
->mDisplay
== NS_STYLE_DISPLAY_INLINE_BOX
||
5988 display
->mDisplay
== NS_STYLE_DISPLAY_BOX
) {
5989 newFrame
= NS_NewBoxFrame(mPresShell
, aStyleContext
, PR_FALSE
, nsnull
);
5991 // Boxes can scroll.
5992 mayBeScrollable
= PR_TRUE
;
5993 } // End of BOX CONSTRUCTION logic
5995 // ------- Begin Grid ---------
5996 else if (display
->mDisplay
== NS_STYLE_DISPLAY_INLINE_GRID
||
5997 display
->mDisplay
== NS_STYLE_DISPLAY_GRID
) {
5998 nsCOMPtr
<nsIBoxLayout
> layout
;
5999 NS_NewGridLayout2(mPresShell
, getter_AddRefs(layout
));
6000 newFrame
= NS_NewBoxFrame(mPresShell
, aStyleContext
, PR_FALSE
, layout
);
6002 // Boxes can scroll.
6003 mayBeScrollable
= PR_TRUE
;
6004 } //------- End Grid ------
6006 // ------- Begin Rows/Columns ---------
6007 else if (display
->mDisplay
== NS_STYLE_DISPLAY_GRID_GROUP
) {
6008 nsCOMPtr
<nsIBoxLayout
> layout
;
6010 if (aTag
== nsGkAtoms::listboxbody
) {
6011 NS_NewListBoxLayout(mPresShell
, layout
);
6012 newFrame
= NS_NewListBoxBodyFrame(mPresShell
, aStyleContext
, PR_FALSE
, layout
);
6016 NS_NewGridRowGroupLayout(mPresShell
, getter_AddRefs(layout
));
6017 newFrame
= NS_NewGridRowGroupFrame(mPresShell
, aStyleContext
, PR_FALSE
, layout
);
6020 // Boxes can scroll.
6021 if (display
->IsScrollableOverflow()) {
6022 // set the top to be the newly created scrollframe
6023 BuildScrollFrame(aState
, aContent
, aStyleContext
, newFrame
,
6024 aParentFrame
, nsnull
, topFrame
, aStyleContext
);
6026 // we have a scrollframe so the parent becomes the scroll frame.
6027 aParentFrame
= newFrame
->GetParent();
6029 primaryFrameSet
= PR_TRUE
;
6031 frameHasBeenInitialized
= PR_TRUE
;
6033 } //------- End Grid ------
6035 // ------- Begin Row/Column ---------
6036 else if (display
->mDisplay
== NS_STYLE_DISPLAY_GRID_LINE
) {
6037 nsCOMPtr
<nsIBoxLayout
> layout
;
6040 NS_NewGridRowLeafLayout(mPresShell
, getter_AddRefs(layout
));
6042 if (aTag
== nsGkAtoms::listitem
)
6043 newFrame
= NS_NewListItemFrame(mPresShell
, aStyleContext
, PR_FALSE
, layout
);
6045 newFrame
= NS_NewGridRowLeafFrame(mPresShell
, aStyleContext
, PR_FALSE
, layout
);
6047 // Boxes can scroll.
6048 mayBeScrollable
= PR_TRUE
;
6049 } //------- End Grid ------
6050 // End of STACK CONSTRUCTION logic
6051 // DECK CONSTRUCTION
6052 else if (display
->mDisplay
== NS_STYLE_DISPLAY_DECK
) {
6053 newFrame
= NS_NewDeckFrame(mPresShell
, aStyleContext
);
6055 // End of DECK CONSTRUCTION logic
6056 else if (display
->mDisplay
== NS_STYLE_DISPLAY_GROUPBOX
) {
6057 newFrame
= NS_NewGroupBoxFrame(mPresShell
, aStyleContext
);
6059 // Boxes can scroll.
6060 mayBeScrollable
= PR_TRUE
;
6062 // STACK CONSTRUCTION
6063 else if (display
->mDisplay
== NS_STYLE_DISPLAY_STACK
||
6064 display
->mDisplay
== NS_STYLE_DISPLAY_INLINE_STACK
) {
6065 newFrame
= NS_NewStackFrame(mPresShell
, aStyleContext
);
6067 mayBeScrollable
= PR_TRUE
;
6069 else if (display
->mDisplay
== NS_STYLE_DISPLAY_POPUP
) {
6070 // If a popup is inside a menu, then the menu understands the complex
6071 // rules/behavior governing the cascade of multiple menu popups and can handle
6072 // having the real popup frame placed under it as a child.
6073 // If, however, the parent is *not* a menu frame, then we need to create
6074 // a placeholder frame for the popup, and then we add the popup frame to the
6075 // root popup set (that manages all such "detached" popups).
6076 if (aParentFrame
->GetType() != nsGkAtoms::menuFrame
) {
6077 if (!aState
.mPopupItems
.containingBlock
) {
6078 // Just don't create a frame for this popup; we can't do
6079 // anything with it, since there is no root popup set.
6080 *aHaltProcessing
= PR_TRUE
;
6081 NS_ASSERTION(!aState
.mRootBox
, "Popup containing block is missing");
6086 NS_ASSERTION(aState
.mPopupItems
.containingBlock
->GetType() ==
6087 nsGkAtoms::popupSetFrame
,
6088 "Popup containing block isn't a nsIPopupSetFrame");
6093 // This is its own frame that derives from box.
6094 newFrame
= NS_NewMenuPopupFrame(mPresShell
, aStyleContext
);
6096 if (aTag
== nsGkAtoms::tooltip
) {
6097 if (aContent
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::_default
,
6098 nsGkAtoms::_true
, eIgnoreCase
)) {
6099 // Tell the root box about the tooltip.
6100 if (aState
.mRootBox
)
6101 aState
.mRootBox
->SetDefaultTooltip(aContent
);
6107 triedFrame
= PR_FALSE
;
6112 if (mayBeScrollable
&& display
->IsScrollableOverflow()) {
6113 // set the top to be the newly created scrollframe
6114 BuildScrollFrame(aState
, aContent
, aStyleContext
, newFrame
,
6115 aParentFrame
, nsnull
, topFrame
, aStyleContext
);
6117 // we have a scrollframe so the parent becomes the scroll frame.
6118 // XXXldb Do we really want to do this? The one case where it
6119 // matters when |frameHasBeenInitialized| is true is one where
6120 // I think we'd be better off the other way around.
6121 aParentFrame
= newFrame
->GetParent();
6122 primaryFrameSet
= PR_TRUE
;
6123 frameHasBeenInitialized
= PR_TRUE
;
6127 if (NS_UNLIKELY(triedFrame
&& !newFrame
))
6129 rv
= NS_ERROR_OUT_OF_MEMORY
;
6132 // If we succeeded in creating a frame then initialize it, process its
6133 // children (if requested), and set the initial child list
6134 if (NS_SUCCEEDED(rv
) && newFrame
!= nsnull
) {
6136 // if no top frame was created then the top is the new frame
6137 if (topFrame
== nsnull
)
6138 topFrame
= newFrame
;
6140 // xul does not support absolute positioning
6141 nsIFrame
* geometricParent
;
6144 NS_ASSERTION(aState
.mPopupItems
.containingBlock
, "How did we get here?");
6145 geometricParent
= aState
.mPopupItems
.containingBlock
;
6150 geometricParent
= aParentFrame
;
6154 nsIFrame* geometricParent = aState.GetGeometricParent(display, aParentFrame);
6156 // if the new frame was already initialized to initialize it again.
6157 if (!frameHasBeenInitialized
) {
6159 rv
= InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
, newFrame
);
6161 if (NS_FAILED(rv
)) {
6162 newFrame
->Destroy();
6167 // if our parent is a block frame then do things the way html likes it
6168 // if not then we are in a box so do what boxes like. On example is boxes
6169 // do not support the absolute positioning of their children. While html blocks
6170 // that's why we call different things here.
6171 nsIAtom* frameType = geometricParent->GetType();
6172 if ((frameType == nsGkAtoms::blockFrame) ||
6173 (frameType == nsGkAtoms::areaFrame)) {
6175 // See if we need to create a view, e.g. the frame is absolutely positioned
6176 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, aParentFrame
, PR_FALSE
);
6180 // we are in a box so do the box thing.
6181 nsBoxFrame::CreateViewForFrame(aState.mPresContext, newFrame,
6182 aStyleContext, PR_FALSE);
6188 // Add the new frame to our list of frame items. Note that we
6189 // don't support floating or positioning of XUL frames.
6190 rv
= aState
.AddChild(topFrame
, aFrameItems
, aContent
, aStyleContext
,
6191 origParentFrame
, PR_FALSE
, PR_FALSE
, isPopup
);
6192 if (NS_FAILED(rv
)) {
6197 if (aTag
== nsGkAtoms::popupgroup
&&
6198 aContent
->IsRootOfNativeAnonymousSubtree()) {
6199 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(mPresShell
);
6201 NS_ASSERTION(rootBox
->GetPopupSetFrame() == newFrame
,
6202 "Unexpected PopupSetFrame");
6203 aState
.mPopupItems
.containingBlock
= rootBox
->GetPopupSetFrame();
6208 // If the new frame isn't a float containing block, then push a null
6209 // float containing block to disable floats. This is needed to disable
6210 // floats within XUL frames.
6211 nsFrameConstructorSaveState floatSaveState
;
6212 PRBool isFloatContainingBlock
=
6213 newFrame
->GetContentInsertionFrame()->IsFloatContainingBlock();
6214 aState
.PushFloatContainingBlock(isFloatContainingBlock
? newFrame
: nsnull
,
6215 floatSaveState
, PR_FALSE
, PR_FALSE
);
6217 // Process the child content if requested
6218 nsFrameItems childItems
;
6219 if (!newFrame
->IsLeaf()) {
6220 // XXXbz don't we need calls to ShouldBuildChildFrames
6221 // elsewhere too? Why only for XUL?
6222 if (mDocument
->BindingManager()->ShouldBuildChildFrames(aContent
)) {
6223 rv
= ProcessChildren(aState
, aContent
, newFrame
, PR_FALSE
,
6224 childItems
, PR_FALSE
);
6228 // XXX These should go after the wrapper!
6229 CreateAnonymousFrames(aTag
, aState
, aContent
, newFrame
, PR_FALSE
,
6232 // Set the frame's initial child list
6233 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
6237 // register tooltip support if needed
6238 if (aTag
== nsGkAtoms::treechildren
|| // trees always need titletips
6239 aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::tooltiptext
) ||
6240 aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::tooltip
))
6242 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(mPresShell
);
6244 rootBox
->AddTooltipSupport(aContent
);
6251 // the top frame is always what we map the content to. This is the frame that contains a pointer
6252 // to the content node.
6254 // Add a mapping from content object to primary frame. Note that for
6255 // floated and positioned frames this is the out-of-flow frame and not
6256 // the placeholder frame
6257 if (!primaryFrameSet
)
6258 aState
.mFrameManager
->SetPrimaryFrameFor(aContent
, topFrame
);
6265 nsCSSFrameConstructor::AddLazyChildren(nsIContent
* aContent
,
6266 nsLazyFrameConstructionCallback
* aCallback
,
6267 void* aArg
, PRBool aIsSynch
)
6269 nsCOMPtr
<nsIRunnable
> event
=
6270 new LazyGenerateChildrenEvent(aContent
, mPresShell
, aCallback
, aArg
);
6271 return aIsSynch
? event
->Run() :
6272 NS_DispatchToCurrentThread(event
);
6275 already_AddRefed
<nsStyleContext
>
6276 nsCSSFrameConstructor::BeginBuildingScrollFrame(nsFrameConstructorState
& aState
,
6277 nsIContent
* aContent
,
6278 nsStyleContext
* aContentStyle
,
6279 nsIFrame
* aParentFrame
,
6280 nsIFrame
* aContentParentFrame
,
6281 nsIAtom
* aScrolledPseudo
,
6283 nsIFrame
*& aNewFrame
)
6285 nsIFrame
* parentFrame
= nsnull
;
6286 nsIFrame
* gfxScrollFrame
= aNewFrame
;
6288 nsFrameItems anonymousItems
;
6290 nsRefPtr
<nsStyleContext
> contentStyle
= aContentStyle
;
6292 if (!gfxScrollFrame
) {
6293 // Build a XULScrollFrame when the child is a box, otherwise an
6295 if (IsXULDisplayType(aContentStyle
->GetStyleDisplay())) {
6296 gfxScrollFrame
= NS_NewXULScrollFrame(mPresShell
, contentStyle
, aIsRoot
);
6298 gfxScrollFrame
= NS_NewHTMLScrollFrame(mPresShell
, contentStyle
, aIsRoot
);
6301 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, gfxScrollFrame
);
6304 nsHTMLContainerFrame::CreateViewForFrame(gfxScrollFrame
,
6305 aContentParentFrame
, PR_FALSE
);
6308 // if there are any anonymous children for the scroll frame, create
6310 CreateAnonymousFrames(aState
, aContent
, mDocument
, gfxScrollFrame
,
6311 PR_FALSE
, anonymousItems
);
6313 parentFrame
= gfxScrollFrame
;
6314 aNewFrame
= gfxScrollFrame
;
6316 // we used the style that was passed in. So resolve another one.
6317 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
6318 nsStyleContext
* aScrolledChildStyle
= styleSet
->ResolvePseudoStyleFor(aContent
,
6320 contentStyle
).get();
6322 if (gfxScrollFrame
) {
6323 gfxScrollFrame
->SetInitialChildList(nsnull
, anonymousItems
.childList
);
6326 return aScrolledChildStyle
;
6330 nsCSSFrameConstructor::FinishBuildingScrollFrame(nsIFrame
* aScrollFrame
,
6331 nsIFrame
* aScrolledFrame
)
6333 aScrollFrame
->AppendFrames(nsnull
, aScrolledFrame
);
6335 // force the scrolled frame to have a view. The view will be parented to
6336 // the correct anonymous inner view because the scrollframes override
6337 // nsIFrame::GetParentViewForChildFrame.
6338 nsHTMLContainerFrame::CreateViewForFrame(aScrolledFrame
, nsnull
, PR_TRUE
);
6339 nsIView
* view
= aScrolledFrame
->GetView();
6346 * Called to wrap a gfx scrollframe around a frame. The hierarchy will look like this
6348 * ------- for gfx scrollbars ------
6354 * Frame (scrolled frame you passed in)
6357 *-----------------------------------
6360 * ScrollFrame: This is a frame that manages gfx cross platform frame based scrollbars.
6362 * @param aContent the content node of the child to wrap.
6363 * @param aScrolledFrame The frame of the content to wrap. This should not be
6364 * Initialized. This method will initialize it with a scrolled pseudo
6365 * and no nsIContent. The content will be attached to the scrollframe
6367 * @param aContentStyle the style context that has already been resolved for the content being passed in.
6369 * @param aParentFrame The parent to attach the scroll frame to
6371 * @param aNewFrame The new scrollframe or gfx scrollframe that we create. It will contain the
6372 * scrolled frame you passed in. (returned)
6373 * If this is not null, we'll just use it
6374 * @param aScrolledContentStyle the style that was resolved for the scrolled frame. (returned)
6377 nsCSSFrameConstructor::BuildScrollFrame(nsFrameConstructorState
& aState
,
6378 nsIContent
* aContent
,
6379 nsStyleContext
* aContentStyle
,
6380 nsIFrame
* aScrolledFrame
,
6381 nsIFrame
* aParentFrame
,
6382 nsIFrame
* aContentParentFrame
,
6383 nsIFrame
*& aNewFrame
,
6384 nsStyleContext
*& aScrolledContentStyle
)
6386 nsRefPtr
<nsStyleContext
> scrolledContentStyle
=
6387 BeginBuildingScrollFrame(aState
, aContent
, aContentStyle
, aParentFrame
,
6388 aContentParentFrame
, nsCSSAnonBoxes::scrolledContent
,
6389 PR_FALSE
, aNewFrame
);
6391 aScrolledFrame
->SetStyleContextWithoutNotification(scrolledContentStyle
);
6392 InitAndRestoreFrame(aState
, aContent
, aNewFrame
, nsnull
, aScrolledFrame
);
6394 FinishBuildingScrollFrame(aNewFrame
, aScrolledFrame
);
6396 aScrolledContentStyle
= scrolledContentStyle
;
6398 // now set the primary frame to the ScrollFrame
6399 aState
.mFrameManager
->SetPrimaryFrameFor( aContent
, aNewFrame
);
6405 nsCSSFrameConstructor::ConstructFrameByDisplayType(nsFrameConstructorState
& aState
,
6406 const nsStyleDisplay
* aDisplay
,
6407 nsIContent
* aContent
,
6408 PRInt32 aNameSpaceID
,
6410 nsIFrame
* aParentFrame
,
6411 nsStyleContext
* aStyleContext
,
6412 nsFrameItems
& aFrameItems
,
6413 PRBool aHasPseudoParent
)
6415 PRBool primaryFrameSet
= PR_FALSE
;
6416 nsIFrame
* newFrame
= nsnull
; // the frame we construct
6417 PRBool addToHashTable
= PR_TRUE
;
6418 PRBool addedToFrameList
= PR_FALSE
;
6419 nsresult rv
= NS_OK
;
6421 // The style system ensures that floated and positioned frames are
6423 NS_ASSERTION(!(aDisplay
->IsFloating() ||
6424 aDisplay
->IsAbsolutelyPositioned()) ||
6425 aDisplay
->IsBlockOutside(),
6426 "Style system did not apply CSS2.1 section 9.7 fixups");
6428 // If this is "body", try propagating its scroll style to the viewport
6429 // Note that we need to do this even if the body is NOT scrollable;
6430 // it might have dynamically changed from scrollable to not scrollable,
6431 // and that might need to be propagated.
6432 PRBool propagatedScrollToViewport
= PR_FALSE
;
6433 if (aContent
->NodeInfo()->Equals(nsGkAtoms::body
) &&
6434 aContent
->IsNodeOfType(nsINode::eHTML
)) {
6435 propagatedScrollToViewport
=
6436 PropagateScrollToViewport() == aContent
;
6439 // If the frame is a block-level frame and is scrollable, then wrap it
6440 // in a scroll frame.
6441 // XXX Ignore tables for the time being
6442 if (aDisplay
->IsBlockInside() &&
6443 aDisplay
->IsScrollableOverflow() &&
6444 !propagatedScrollToViewport
) {
6446 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6447 ProcessPseudoFrames(aState
, aFrameItems
);
6450 nsRefPtr
<nsStyleContext
> scrolledContentStyle
6451 = BeginBuildingScrollFrame(aState
, aContent
, aStyleContext
,
6452 aState
.GetGeometricParent(aDisplay
, aParentFrame
),
6454 nsCSSAnonBoxes::scrolledContent
,
6455 PR_FALSE
, newFrame
);
6458 // pass a temporary stylecontext, the correct one will be set later
6459 nsIFrame
* scrolledFrame
=
6460 NS_NewAreaFrame(mPresShell
, aStyleContext
,
6461 NS_BLOCK_SPACE_MGR
| NS_BLOCK_MARGIN_ROOT
);
6463 nsFrameItems blockItem
;
6464 rv
= ConstructBlock(aState
,
6465 scrolledContentStyle
->GetStyleDisplay(), aContent
,
6466 newFrame
, newFrame
, scrolledContentStyle
,
6467 &scrolledFrame
, blockItem
, aDisplay
->IsPositioned());
6468 NS_ASSERTION(blockItem
.childList
== scrolledFrame
,
6469 "Scrollframe's frameItems should be exactly the scrolled frame");
6470 FinishBuildingScrollFrame(newFrame
, scrolledFrame
);
6472 rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
6474 if (NS_FAILED(rv
)) {
6478 addedToFrameList
= PR_TRUE
;
6480 // See if the frame is absolute or fixed positioned
6481 else if (aDisplay
->IsAbsolutelyPositioned() &&
6482 (NS_STYLE_DISPLAY_BLOCK
== aDisplay
->mDisplay
||
6483 NS_STYLE_DISPLAY_LIST_ITEM
== aDisplay
->mDisplay
)) {
6485 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6486 ProcessPseudoFrames(aState
, aFrameItems
);
6489 // Create a frame to wrap up the absolute positioned item
6490 // pass a temporary stylecontext, the correct one will be set later
6491 newFrame
= NS_NewAbsoluteItemWrapperFrame(mPresShell
, aStyleContext
);
6493 rv
= ConstructBlock(aState
, aDisplay
, aContent
,
6494 aState
.GetGeometricParent(aDisplay
, aParentFrame
), aParentFrame
,
6495 aStyleContext
, &newFrame
, aFrameItems
, PR_TRUE
);
6496 if (NS_FAILED(rv
)) {
6500 addedToFrameList
= PR_TRUE
;
6502 // See if the frame is floated and it's a block frame
6503 else if (aDisplay
->IsFloating() &&
6504 (NS_STYLE_DISPLAY_BLOCK
== aDisplay
->mDisplay
||
6505 NS_STYLE_DISPLAY_LIST_ITEM
== aDisplay
->mDisplay
)) {
6506 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6507 ProcessPseudoFrames(aState
, aFrameItems
);
6509 // Create an area frame
6510 // pass a temporary stylecontext, the correct one will be set later
6511 newFrame
= NS_NewFloatingItemWrapperFrame(mPresShell
, aStyleContext
);
6513 rv
= ConstructBlock(aState
, aDisplay
, aContent
,
6514 aState
.GetGeometricParent(aDisplay
, aParentFrame
),
6515 aParentFrame
, aStyleContext
, &newFrame
, aFrameItems
,
6516 aDisplay
->mPosition
== NS_STYLE_POSITION_RELATIVE
||
6517 aDisplay
->HasTransform());
6518 if (NS_FAILED(rv
)) {
6522 addedToFrameList
= PR_TRUE
;
6524 // See if it's relatively positioned or transformed
6525 else if ((NS_STYLE_POSITION_RELATIVE
== aDisplay
->mPosition
||
6526 aDisplay
->HasTransform()) &&
6527 (aDisplay
->IsBlockInside() ||
6528 (NS_STYLE_DISPLAY_INLINE
== aDisplay
->mDisplay
))) {
6529 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6530 ProcessPseudoFrames(aState
, aFrameItems
);
6532 // Is it block-level or inline-level?
6533 if (aDisplay
->IsBlockInside()) {
6534 // Create a wrapper frame. Only need space manager if it's inline-block
6535 PRUint32 flags
= (aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_BLOCK
?
6536 NS_BLOCK_SPACE_MGR
| NS_BLOCK_MARGIN_ROOT
: 0);
6537 newFrame
= NS_NewRelativeItemWrapperFrame(mPresShell
, aStyleContext
,
6539 // XXXbz should we be passing in a non-null aContentParentFrame?
6540 ConstructBlock(aState
, aDisplay
, aContent
,
6541 aParentFrame
, nsnull
, aStyleContext
, &newFrame
,
6542 aFrameItems
, PR_TRUE
);
6543 addedToFrameList
= PR_TRUE
;
6545 // Create a positioned inline frame
6546 newFrame
= NS_NewPositionedInlineFrame(mPresShell
, aStyleContext
);
6547 // Note that we want to insert the inline after processing kids, since
6548 // processing of kids may split the inline.
6549 ConstructInline(aState
, aDisplay
, aContent
,
6550 aParentFrame
, aStyleContext
, PR_TRUE
, newFrame
);
6553 // See if it's a block frame of some sort
6554 else if ((NS_STYLE_DISPLAY_BLOCK
== aDisplay
->mDisplay
) ||
6555 (NS_STYLE_DISPLAY_LIST_ITEM
== aDisplay
->mDisplay
) ||
6556 (NS_STYLE_DISPLAY_RUN_IN
== aDisplay
->mDisplay
) ||
6557 (NS_STYLE_DISPLAY_COMPACT
== aDisplay
->mDisplay
) ||
6558 (NS_STYLE_DISPLAY_INLINE_BLOCK
== aDisplay
->mDisplay
)) {
6559 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6560 ProcessPseudoFrames(aState
, aFrameItems
);
6563 if (NS_STYLE_DISPLAY_INLINE_BLOCK
== aDisplay
->mDisplay
) {
6564 flags
= NS_BLOCK_SPACE_MGR
| NS_BLOCK_MARGIN_ROOT
;
6566 // Create the block frame
6567 newFrame
= NS_NewBlockFrame(mPresShell
, aStyleContext
, flags
);
6568 if (newFrame
) { // That worked so construct the block and its children
6569 // XXXbz should we be passing in a non-null aContentParentFrame?
6570 rv
= ConstructBlock(aState
, aDisplay
, aContent
,
6571 aParentFrame
, nsnull
, aStyleContext
, &newFrame
,
6572 aFrameItems
, PR_FALSE
);
6573 addedToFrameList
= PR_TRUE
;
6576 rv
= NS_ERROR_OUT_OF_MEMORY
;
6579 // See if it's an inline frame of some sort
6580 else if ((NS_STYLE_DISPLAY_INLINE
== aDisplay
->mDisplay
) ||
6581 (NS_STYLE_DISPLAY_MARKER
== aDisplay
->mDisplay
)) {
6582 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6583 ProcessPseudoFrames(aState
, aFrameItems
);
6585 // Create the inline frame
6586 newFrame
= NS_NewInlineFrame(mPresShell
, aStyleContext
);
6587 if (newFrame
) { // That worked so construct the inline and its children
6588 // Note that we want to insert the inline after processing kids, since
6589 // processing of kids may split the inline.
6590 rv
= ConstructInline(aState
, aDisplay
, aContent
,
6591 aParentFrame
, aStyleContext
, PR_FALSE
, newFrame
);
6594 rv
= NS_ERROR_OUT_OF_MEMORY
;
6597 // To keep the hash table small don't add inline frames (they're
6598 // typically things like FONT and B), because we can quickly
6599 // find them if we need to
6600 addToHashTable
= PR_FALSE
;
6602 // otherwise let the display property influence the frame type to create
6604 // XXX This section now only handles table frames; should be
6605 // factored out probably
6607 // Use the 'display' property to choose a frame type
6608 switch (aDisplay
->mDisplay
) {
6609 case NS_STYLE_DISPLAY_TABLE
:
6610 case NS_STYLE_DISPLAY_INLINE_TABLE
:
6612 nsIFrame
* innerTable
;
6613 rv
= ConstructTableFrame(aState
, aContent
,
6614 aParentFrame
, aStyleContext
,
6615 aNameSpaceID
, PR_FALSE
, aFrameItems
, newFrame
,
6617 addedToFrameList
= PR_TRUE
;
6618 // Note: table construction function takes care of initializing
6619 // the frame, processing children, and setting the initial child
6624 // the next 5 cases are only relevant if the parent is not a table, ConstructTableFrame handles children
6625 case NS_STYLE_DISPLAY_TABLE_CAPTION
:
6627 // aParentFrame may be an inner table frame rather than an outer frame
6628 // In this case we need to get the outer frame.
6629 nsIFrame
* parentFrame
= AdjustCaptionParentFrame(aParentFrame
);
6630 rv
= ConstructTableCaptionFrame(aState
, aContent
, parentFrame
,
6631 aStyleContext
, aNameSpaceID
, aFrameItems
,
6632 newFrame
, aHasPseudoParent
);
6633 if (NS_SUCCEEDED(rv
) && !aHasPseudoParent
) {
6634 aFrameItems
.AddChild(newFrame
);
6639 case NS_STYLE_DISPLAY_TABLE_ROW_GROUP
:
6640 case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
:
6641 case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
:
6642 rv
= ConstructTableRowGroupFrame(aState
, aContent
, aParentFrame
,
6643 aStyleContext
, aNameSpaceID
, PR_FALSE
,
6644 aFrameItems
, newFrame
,
6646 if (NS_SUCCEEDED(rv
) && !aHasPseudoParent
) {
6647 aFrameItems
.AddChild(newFrame
);
6651 case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
:
6652 rv
= ConstructTableColGroupFrame(aState
, aContent
, aParentFrame
,
6653 aStyleContext
, aNameSpaceID
,
6654 PR_FALSE
, aFrameItems
, newFrame
,
6656 if (NS_SUCCEEDED(rv
) && !aHasPseudoParent
) {
6657 aFrameItems
.AddChild(newFrame
);
6661 case NS_STYLE_DISPLAY_TABLE_COLUMN
:
6662 rv
= ConstructTableColFrame(aState
, aContent
, aParentFrame
,
6663 aStyleContext
, aNameSpaceID
, PR_FALSE
,
6664 aFrameItems
, newFrame
, aHasPseudoParent
);
6665 if (NS_SUCCEEDED(rv
) && !aHasPseudoParent
) {
6666 aFrameItems
.AddChild(newFrame
);
6670 case NS_STYLE_DISPLAY_TABLE_ROW
:
6671 rv
= ConstructTableRowFrame(aState
, aContent
, aParentFrame
,
6672 aStyleContext
, aNameSpaceID
, PR_FALSE
,
6673 aFrameItems
, newFrame
, aHasPseudoParent
);
6674 if (NS_SUCCEEDED(rv
) && !aHasPseudoParent
) {
6675 aFrameItems
.AddChild(newFrame
);
6679 case NS_STYLE_DISPLAY_TABLE_CELL
:
6681 nsIFrame
* innerTable
;
6682 rv
= ConstructTableCellFrame(aState
, aContent
, aParentFrame
,
6683 aStyleContext
, aNameSpaceID
,
6684 PR_FALSE
, aFrameItems
, newFrame
,
6685 innerTable
, aHasPseudoParent
);
6686 if (NS_SUCCEEDED(rv
) && !aHasPseudoParent
) {
6687 aFrameItems
.AddChild(newFrame
);
6693 NS_NOTREACHED("How did we get here?");
6698 if (!addedToFrameList
) {
6700 NS_ASSERTION(!aDisplay
->IsAbsolutelyPositioned() &&
6701 !aDisplay
->IsFloating(),
6702 "Things that could be out-of-flow need to handle adding "
6703 "to the frame list themselves");
6705 rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
6707 NS_ASSERTION(NS_SUCCEEDED(rv
),
6708 "Cases where AddChild() can fail must handle it themselves");
6711 if (newFrame
&& addToHashTable
) {
6712 // Add a mapping from content object to primary frame. Note that for
6713 // floated and positioned frames this is the out-of-flow frame and not
6714 // the placeholder frame
6715 if (!primaryFrameSet
) {
6716 aState
.mFrameManager
->SetPrimaryFrameFor(aContent
, newFrame
);
6724 nsCSSFrameConstructor::InitAndRestoreFrame(const nsFrameConstructorState
& aState
,
6725 nsIContent
* aContent
,
6726 nsIFrame
* aParentFrame
,
6727 nsIFrame
* aPrevInFlow
,
6728 nsIFrame
* aNewFrame
,
6729 PRBool aAllowCounters
)
6731 NS_PRECONDITION(mUpdateCount
!= 0,
6732 "Should be in an update while creating frames");
6734 nsresult rv
= NS_OK
;
6736 NS_ASSERTION(aNewFrame
, "Null frame cannot be initialized");
6738 return NS_ERROR_NULL_POINTER
;
6740 // Initialize the frame
6741 rv
= aNewFrame
->Init(aContent
, aParentFrame
, aPrevInFlow
);
6742 aNewFrame
->AddStateBits(aState
.mAdditionalStateBits
);
6744 if (aState
.mFrameState
&& aState
.mFrameManager
) {
6745 // Restore frame state for just the newly created frame.
6746 aState
.mFrameManager
->RestoreFrameStateFor(aNewFrame
, aState
.mFrameState
);
6749 if (aAllowCounters
&& !aPrevInFlow
&&
6750 mCounterManager
.AddCounterResetsAndIncrements(aNewFrame
)) {
6757 already_AddRefed
<nsStyleContext
>
6758 nsCSSFrameConstructor::ResolveStyleContext(nsIFrame
* aParentFrame
,
6759 nsIContent
* aContent
)
6761 nsStyleContext
* parentStyleContext
= nsnull
;
6762 if (aContent
->GetParent()) {
6763 aParentFrame
= nsFrame::CorrectStyleParentFrame(aParentFrame
, nsnull
);
6766 // Resolve the style context based on the content object and the parent
6768 parentStyleContext
= aParentFrame
->GetStyleContext();
6770 // Perhaps aParentFrame is a canvasFrame and we're replicating
6771 // fixed-pos frames.
6772 // XXX should we create a way to tell ConstructFrame which style
6773 // context to use, and pass it the style context for the
6774 // previous page's fixed-pos frame?
6777 // This has got to be a call from ConstructDocElementTableFrame.
6778 // Not sure how best to assert that here.
6781 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
6783 if (aContent
->IsNodeOfType(nsINode::eELEMENT
)) {
6784 return styleSet
->ResolveStyleFor(aContent
, parentStyleContext
);
6787 NS_ASSERTION(aContent
->IsNodeOfType(nsINode::eTEXT
),
6788 "shouldn't waste time creating style contexts for "
6789 "comments and processing instructions");
6791 return styleSet
->ResolveStyleForNonElement(parentStyleContext
);
6798 nsCSSFrameConstructor::FlushAccumulatedBlock(nsFrameConstructorState
& aState
,
6799 nsIContent
* aContent
,
6800 nsIFrame
* aParentFrame
,
6801 nsFrameItems
* aBlockItems
,
6802 nsFrameItems
* aNewItems
)
6804 if (!aBlockItems
->childList
) {
6809 nsStyleContext
* parentContext
=
6810 nsFrame::CorrectStyleParentFrame(aParentFrame
,
6811 nsCSSAnonBoxes::mozMathMLAnonymousBlock
)->GetStyleContext();
6812 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
6813 nsRefPtr
<nsStyleContext
> blockContext
;
6814 blockContext
= styleSet
->ResolvePseudoStyleFor(aContent
,
6815 nsCSSAnonBoxes::mozMathMLAnonymousBlock
,
6818 // then, create a block frame that will wrap the child frames. Make it a
6819 // MathML frame so that Get(Absolute/Float)ContainingBlockFor know that this
6820 // is not a suitable block.
6821 nsIFrame
* blockFrame
= NS_NewMathMLmathBlockFrame(mPresShell
, blockContext
,
6822 NS_BLOCK_SPACE_MGR
| NS_BLOCK_MARGIN_ROOT
);
6823 if (NS_UNLIKELY(!blockFrame
))
6824 return NS_ERROR_OUT_OF_MEMORY
;
6826 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, blockFrame
);
6827 for (nsIFrame
* f
= aBlockItems
->childList
; f
; f
= f
->GetNextSibling()) {
6828 ReparentFrame(aState
.mFrameManager
, blockFrame
, f
);
6830 // abs-pos and floats are disabled in MathML children so we don't have to
6831 // worry about messing up those.
6832 blockFrame
->SetInitialChildList(nsnull
, aBlockItems
->childList
);
6833 *aBlockItems
= nsFrameItems();
6834 aNewItems
->AddChild(blockFrame
);
6839 nsCSSFrameConstructor::ConstructMathMLFrame(nsFrameConstructorState
& aState
,
6840 nsIContent
* aContent
,
6841 nsIFrame
* aParentFrame
,
6843 PRInt32 aNameSpaceID
,
6844 nsStyleContext
* aStyleContext
,
6845 nsFrameItems
& aFrameItems
,
6846 PRBool aHasPseudoParent
)
6848 // Make sure that we remain confined in the MathML world
6849 if (aNameSpaceID
!= kNameSpaceID_MathML
)
6852 nsresult rv
= NS_OK
;
6854 NS_ASSERTION(aTag
!= nsnull
, "null MathML tag");
6858 // Initialize the new frame
6859 nsIFrame
* newFrame
= nsnull
;
6861 // Make sure to keep IsSpecialContent in synch with this code
6862 const nsStyleDisplay
* disp
= aStyleContext
->GetStyleDisplay();
6864 // Leverage IsSpecialContent to check if one of the |if aTag| below will
6865 // surely match (knowing that aNameSpaceID == kNameSpaceID_MathML here)
6866 if (IsSpecialContent(aContent
, aTag
, aNameSpaceID
, aStyleContext
)) {
6867 // process pending pseudo frames
6868 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
6869 ProcessPseudoFrames(aState
, aFrameItems
);
6873 if (aTag
== nsGkAtoms::mi_
||
6874 aTag
== nsGkAtoms::mn_
||
6875 aTag
== nsGkAtoms::ms_
||
6876 aTag
== nsGkAtoms::mtext_
)
6877 newFrame
= NS_NewMathMLTokenFrame(mPresShell
, aStyleContext
);
6878 else if (aTag
== nsGkAtoms::mo_
)
6879 newFrame
= NS_NewMathMLmoFrame(mPresShell
, aStyleContext
);
6880 else if (aTag
== nsGkAtoms::mfrac_
)
6881 newFrame
= NS_NewMathMLmfracFrame(mPresShell
, aStyleContext
);
6882 else if (aTag
== nsGkAtoms::msup_
)
6883 newFrame
= NS_NewMathMLmsupFrame(mPresShell
, aStyleContext
);
6884 else if (aTag
== nsGkAtoms::msub_
)
6885 newFrame
= NS_NewMathMLmsubFrame(mPresShell
, aStyleContext
);
6886 else if (aTag
== nsGkAtoms::msubsup_
)
6887 newFrame
= NS_NewMathMLmsubsupFrame(mPresShell
, aStyleContext
);
6888 else if (aTag
== nsGkAtoms::munder_
)
6889 newFrame
= NS_NewMathMLmunderFrame(mPresShell
, aStyleContext
);
6890 else if (aTag
== nsGkAtoms::mover_
)
6891 newFrame
= NS_NewMathMLmoverFrame(mPresShell
, aStyleContext
);
6892 else if (aTag
== nsGkAtoms::munderover_
)
6893 newFrame
= NS_NewMathMLmunderoverFrame(mPresShell
, aStyleContext
);
6894 else if (aTag
== nsGkAtoms::mphantom_
)
6895 newFrame
= NS_NewMathMLmphantomFrame(mPresShell
, aStyleContext
);
6896 else if (aTag
== nsGkAtoms::mpadded_
)
6897 newFrame
= NS_NewMathMLmpaddedFrame(mPresShell
, aStyleContext
);
6898 else if (aTag
== nsGkAtoms::mspace_
||
6899 aTag
== nsGkAtoms::none
||
6900 aTag
== nsGkAtoms::mprescripts_
)
6901 newFrame
= NS_NewMathMLmspaceFrame(mPresShell
, aStyleContext
);
6902 else if (aTag
== nsGkAtoms::mfenced_
)
6903 newFrame
= NS_NewMathMLmfencedFrame(mPresShell
, aStyleContext
);
6904 else if (aTag
== nsGkAtoms::mmultiscripts_
)
6905 newFrame
= NS_NewMathMLmmultiscriptsFrame(mPresShell
, aStyleContext
);
6906 else if (aTag
== nsGkAtoms::mstyle_
)
6907 newFrame
= NS_NewMathMLmstyleFrame(mPresShell
, aStyleContext
);
6908 else if (aTag
== nsGkAtoms::msqrt_
)
6909 newFrame
= NS_NewMathMLmsqrtFrame(mPresShell
, aStyleContext
);
6910 else if (aTag
== nsGkAtoms::mroot_
)
6911 newFrame
= NS_NewMathMLmrootFrame(mPresShell
, aStyleContext
);
6912 else if (aTag
== nsGkAtoms::maction_
)
6913 newFrame
= NS_NewMathMLmactionFrame(mPresShell
, aStyleContext
);
6914 else if (aTag
== nsGkAtoms::mrow_
||
6915 aTag
== nsGkAtoms::merror_
)
6916 newFrame
= NS_NewMathMLmrowFrame(mPresShell
, aStyleContext
);
6917 else if (aTag
== nsGkAtoms::math
) {
6918 // root <math> element
6919 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
6920 PRBool isBlock
= (NS_STYLE_DISPLAY_BLOCK
== display
->mDisplay
);
6921 newFrame
= NS_NewMathMLmathFrame(mPresShell
, isBlock
, aStyleContext
);
6927 // If we succeeded in creating a frame then initialize it, process its
6928 // children (if requested), and set the initial child list
6930 NS_ASSERTION(newFrame
->IsFrameOfType(nsIFrame::eExcludesIgnorableWhitespace
),
6931 "Ignorable whitespace should be excluded");
6933 // Only <math> elements can be floated or positioned. All other MathML
6934 // should be in-flow.
6935 PRBool isMath
= aTag
== nsGkAtoms::math
;
6937 nsIFrame
* geometricParent
=
6938 isMath
? aState
.GetGeometricParent(disp
, aParentFrame
) : aParentFrame
;
6940 InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
, newFrame
);
6942 // See if we need to create a view, e.g. the frame is absolutely positioned
6943 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, aParentFrame
, PR_FALSE
);
6945 rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
6946 aParentFrame
, isMath
, isMath
);
6947 if (NS_FAILED(rv
)) {
6951 // Push a null float containing block to disable floating within mathml
6952 nsFrameConstructorSaveState floatSaveState
;
6953 aState
.PushFloatContainingBlock(nsnull
, floatSaveState
, PR_FALSE
,
6956 // Same for absolute positioning
6957 nsFrameConstructorSaveState absoluteSaveState
;
6958 aState
.PushAbsoluteContainingBlock(nsnull
, absoluteSaveState
);
6960 // MathML frames are inline frames, so just process their kids
6961 nsFrameItems childItems
;
6962 if (!newFrame
->IsLeaf()) {
6963 rv
= ProcessChildren(aState
, aContent
, newFrame
, PR_TRUE
,
6964 childItems
, PR_FALSE
);
6967 CreateAnonymousFrames(aTag
, aState
, aContent
, newFrame
, PR_FALSE
,
6970 // Wrap runs of inline children in a block
6971 if (NS_SUCCEEDED(rv
)) {
6972 nsFrameItems newItems
;
6973 nsFrameItems currentBlock
;
6975 while ((f
= childItems
.childList
) != nsnull
) {
6976 PRBool wrapFrame
= IsInlineFrame(f
) || IsFrameSpecial(f
);
6978 rv
= FlushAccumulatedBlock(aState
, aContent
, newFrame
, ¤tBlock
, &newItems
);
6983 childItems
.RemoveChild(f
, nsnull
);
6985 currentBlock
.AddChild(f
);
6987 newItems
.AddChild(f
);
6990 rv
= FlushAccumulatedBlock(aState
, aContent
, newFrame
, ¤tBlock
, &newItems
);
6992 if (childItems
.childList
) {
6993 // an error must have occurred, delete unprocessed frames
6994 CleanupFrameReferences(aState
.mFrameManager
, childItems
.childList
);
6995 nsFrameList(childItems
.childList
).DestroyFrames();
6998 childItems
= newItems
;
7001 // Set the frame's initial child list
7002 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
7007 return NS_ERROR_OUT_OF_MEMORY
;
7010 #endif // MOZ_MATHML
7015 nsCSSFrameConstructor::ConstructSVGFrame(nsFrameConstructorState
& aState
,
7016 nsIContent
* aContent
,
7017 nsIFrame
* aParentFrame
,
7019 PRInt32 aNameSpaceID
,
7020 nsStyleContext
* aStyleContext
,
7021 nsFrameItems
& aFrameItems
,
7022 PRBool aHasPseudoParent
,
7023 PRBool
* aHaltProcessing
)
7025 NS_ASSERTION(aNameSpaceID
== kNameSpaceID_SVG
, "SVG frame constructed in wrong namespace");
7026 *aHaltProcessing
= PR_FALSE
;
7028 nsresult rv
= NS_OK
;
7029 PRBool forceView
= PR_FALSE
;
7030 PRBool isOuterSVGNode
= PR_FALSE
;
7031 const nsStyleDisplay
* disp
= aStyleContext
->GetStyleDisplay();
7033 NS_ASSERTION(aTag
!= nsnull
, "null SVG tag");
7037 // XXXbz somewhere here we should process pseudo frames if !aHasPseudoParent
7039 // Initialize the new frame
7040 nsIFrame
* newFrame
= nsnull
;
7042 // Default to aParentFrame for the geometricParent; it's adjusted in
7043 // cases when we allow anything else.
7044 nsIFrame
* geometricParent
= aParentFrame
;
7046 PRBool parentIsSVG
= PR_FALSE
;
7047 if (aParentFrame
&& aParentFrame
->GetContent()) {
7049 nsIAtom
* parentTag
=
7050 mDocument
->BindingManager()->ResolveTag(aParentFrame
->GetContent(),
7053 // It's not clear whether the SVG spec intends to allow any SVG
7054 // content within svg:foreignObject at all (SVG 1.1, section
7055 // 23.2), but if it does, it better be svg:svg. So given that
7056 // we're allowing it, treat it as a non-SVG parent.
7057 parentIsSVG
= parentNSID
== kNameSpaceID_SVG
&&
7058 parentTag
!= nsGkAtoms::foreignObject
;
7061 if ((aTag
!= nsGkAtoms::svg
&& !parentIsSVG
) ||
7062 (aTag
== nsGkAtoms::desc
|| aTag
== nsGkAtoms::title
)) {
7063 // Sections 5.1 and G.4 of SVG 1.1 say that SVG elements other than
7064 // svg:svg not contained within svg:svg are incorrect, although they
7065 // don't seem to specify error handling. Ignore them, since many of
7066 // our frame classes can't deal. It *may* be that the document
7067 // should at that point be considered in error according to F.2, but
7068 // it's hard to tell.
7070 // Style mutation can't change this situation, so don't bother
7071 // adding to the undisplayed content map.
7073 // We don't currently handle any UI for desc/title
7074 *aHaltProcessing
= PR_TRUE
;
7078 // Reduce the number of frames we create unnecessarily. Note that this is not
7079 // where we select which frame in a <switch> to render! That happens in
7080 // nsSVGSwitchFrame::PaintSVG.
7081 if (!NS_SVG_PassesConditionalProcessingTests(aContent
)) {
7082 // Note that just returning is probably not right. According
7083 // to the spec, <use> is allowed to use an element that fails its
7084 // conditional, but because we never actually create the frame when
7085 // a conditional fails and when we use GetReferencedFrame to find the
7086 // references, things don't work right.
7088 *aHaltProcessing
= PR_TRUE
;
7092 // Make sure to keep IsSpecialContent in synch with this code
7093 if (aTag
== nsGkAtoms::svg
) {
7095 // This is the outermost <svg> element.
7096 isOuterSVGNode
= PR_TRUE
;
7098 // Set the right geometricParent
7099 geometricParent
= aState
.GetGeometricParent(disp
, aParentFrame
);
7101 forceView
= PR_TRUE
;
7102 newFrame
= NS_NewSVGOuterSVGFrame(mPresShell
, aContent
, aStyleContext
);
7105 // This is an inner <svg> element
7106 newFrame
= NS_NewSVGInnerSVGFrame(mPresShell
, aContent
, aStyleContext
);
7109 else if (aTag
== nsGkAtoms::g
) {
7110 newFrame
= NS_NewSVGGFrame(mPresShell
, aContent
, aStyleContext
);
7112 else if (aTag
== nsGkAtoms::svgSwitch
) {
7113 newFrame
= NS_NewSVGSwitchFrame(mPresShell
, aContent
, aStyleContext
);
7115 else if (aTag
== nsGkAtoms::polygon
||
7116 aTag
== nsGkAtoms::polyline
||
7117 aTag
== nsGkAtoms::circle
||
7118 aTag
== nsGkAtoms::ellipse
||
7119 aTag
== nsGkAtoms::line
||
7120 aTag
== nsGkAtoms::rect
||
7121 aTag
== nsGkAtoms::path
)
7122 newFrame
= NS_NewSVGPathGeometryFrame(mPresShell
, aContent
, aStyleContext
);
7123 else if (aTag
== nsGkAtoms::defs
) {
7124 newFrame
= NS_NewSVGContainerFrame(mPresShell
, aContent
, aStyleContext
);
7126 else if (aTag
== nsGkAtoms::foreignObject
) {
7127 newFrame
= NS_NewSVGForeignObjectFrame(mPresShell
, aContent
, aStyleContext
);
7129 else if (aTag
== nsGkAtoms::a
) {
7130 newFrame
= NS_NewSVGAFrame(mPresShell
, aContent
, aStyleContext
);
7132 else if (aTag
== nsGkAtoms::text
) {
7133 nsIFrame
*ancestorFrame
= SVG_GetFirstNonAAncestorFrame(aParentFrame
);
7134 if (ancestorFrame
) {
7135 nsISVGTextContentMetrics
* metrics
;
7136 CallQueryInterface(ancestorFrame
, &metrics
);
7137 // Text cannot be nested
7139 newFrame
= NS_NewSVGTextFrame(mPresShell
, aContent
, aStyleContext
);
7142 else if (aTag
== nsGkAtoms::tspan
) {
7143 nsIFrame
*ancestorFrame
= SVG_GetFirstNonAAncestorFrame(aParentFrame
);
7144 if (ancestorFrame
) {
7145 nsISVGTextContentMetrics
* metrics
;
7146 CallQueryInterface(ancestorFrame
, &metrics
);
7148 newFrame
= NS_NewSVGTSpanFrame(mPresShell
, aContent
,
7149 ancestorFrame
, aStyleContext
);
7152 else if (aTag
== nsGkAtoms::linearGradient
) {
7153 newFrame
= NS_NewSVGLinearGradientFrame(mPresShell
, aContent
, aStyleContext
);
7155 else if (aTag
== nsGkAtoms::radialGradient
) {
7156 newFrame
= NS_NewSVGRadialGradientFrame(mPresShell
, aContent
, aStyleContext
);
7158 else if (aTag
== nsGkAtoms::stop
) {
7159 newFrame
= NS_NewSVGStopFrame(mPresShell
, aContent
, aParentFrame
, aStyleContext
);
7161 else if (aTag
== nsGkAtoms::use
) {
7162 newFrame
= NS_NewSVGUseFrame(mPresShell
, aContent
, aStyleContext
);
7164 else if (aTag
== nsGkAtoms::marker
) {
7165 newFrame
= NS_NewSVGMarkerFrame(mPresShell
, aContent
, aStyleContext
);
7167 else if (aTag
== nsGkAtoms::image
) {
7168 newFrame
= NS_NewSVGImageFrame(mPresShell
, aContent
, aStyleContext
);
7170 else if (aTag
== nsGkAtoms::clipPath
) {
7171 newFrame
= NS_NewSVGClipPathFrame(mPresShell
, aContent
, aStyleContext
);
7173 else if (aTag
== nsGkAtoms::textPath
) {
7174 nsIFrame
*ancestorFrame
= SVG_GetFirstNonAAncestorFrame(aParentFrame
);
7175 if (ancestorFrame
&&
7176 ancestorFrame
->GetType() == nsGkAtoms::svgTextFrame
) {
7177 newFrame
= NS_NewSVGTextPathFrame(mPresShell
, aContent
,
7178 ancestorFrame
, aStyleContext
);
7181 else if (aTag
== nsGkAtoms::filter
) {
7182 newFrame
= NS_NewSVGFilterFrame(mPresShell
, aContent
, aStyleContext
);
7184 else if (aTag
== nsGkAtoms::pattern
) {
7185 newFrame
= NS_NewSVGPatternFrame(mPresShell
, aContent
, aStyleContext
);
7187 else if (aTag
== nsGkAtoms::mask
) {
7188 newFrame
= NS_NewSVGMaskFrame(mPresShell
, aContent
, aStyleContext
);
7190 else if (aTag
== nsGkAtoms::feDistantLight
||
7191 aTag
== nsGkAtoms::fePointLight
||
7192 aTag
== nsGkAtoms::feSpotLight
||
7193 aTag
== nsGkAtoms::feBlend
||
7194 aTag
== nsGkAtoms::feColorMatrix
||
7195 aTag
== nsGkAtoms::feFuncR
||
7196 aTag
== nsGkAtoms::feFuncG
||
7197 aTag
== nsGkAtoms::feFuncB
||
7198 aTag
== nsGkAtoms::feFuncA
||
7199 aTag
== nsGkAtoms::feComposite
||
7200 aTag
== nsGkAtoms::feConvolveMatrix
||
7201 aTag
== nsGkAtoms::feDisplacementMap
||
7202 aTag
== nsGkAtoms::feFlood
||
7203 aTag
== nsGkAtoms::feGaussianBlur
||
7204 aTag
== nsGkAtoms::feImage
||
7205 aTag
== nsGkAtoms::feMergeNode
||
7206 aTag
== nsGkAtoms::feMorphology
||
7207 aTag
== nsGkAtoms::feOffset
||
7208 aTag
== nsGkAtoms::feTile
||
7209 aTag
== nsGkAtoms::feTurbulence
) {
7210 // We don't really use the frame, just need it for the style
7211 // information, so create the simplest possible frame.
7212 newFrame
= NS_NewSVGLeafFrame(mPresShell
, aStyleContext
);
7216 if (newFrame
== nsnull
) {
7217 // Either we have an unknown tag, or construction of a frame
7218 // failed. One reason why frame construction for a known tag might
7219 // have failed is that the content element doesn't implement all
7220 // interfaces required by the frame. This happens e.g. when using
7221 // 'extends' in xbl to extend an xbl binding from an svg
7222 // element. In that case, the bound content element will always be
7223 // a standard xml element, and not be of the right type.
7224 // The best we can do here is to create a generic svg container frame.
7225 // XXXldb This really isn't what the SVG spec says to do.
7227 // printf("Warning: Creating SVGGenericContainerFrame for tag <");
7228 // nsAutoString str;
7229 // aTag->ToString(str);
7230 // printf("%s>\n", NS_ConvertUTF16toUTF8(str).get());
7232 newFrame
= NS_NewSVGGenericContainerFrame(mPresShell
, aContent
, aStyleContext
);
7234 // If we succeeded in creating a frame then initialize it, process its
7235 // children (if requested), and set the initial child list
7236 if (newFrame
!= nsnull
) {
7237 InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
, newFrame
);
7238 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, aParentFrame
, forceView
);
7240 rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
7241 aParentFrame
, isOuterSVGNode
, isOuterSVGNode
);
7242 if (NS_FAILED(rv
)) {
7246 nsFrameItems childItems
;
7247 if (aTag
== nsGkAtoms::foreignObject
) {
7248 // Resolve pseudo style and create an inner block frame
7249 // XXX this breaks style inheritance
7250 nsRefPtr
<nsStyleContext
> innerPseudoStyle
;
7251 innerPseudoStyle
= mPresShell
->StyleSet()->
7252 ResolvePseudoStyleFor(aContent
,
7253 nsCSSAnonBoxes::mozSVGForeignContent
, aStyleContext
);
7255 nsIFrame
* blockFrame
= NS_NewBlockFrame(mPresShell
, innerPseudoStyle
,
7256 NS_BLOCK_SPACE_MGR
|
7257 NS_BLOCK_MARGIN_ROOT
);
7258 if (NS_UNLIKELY(!blockFrame
))
7259 return NS_ERROR_OUT_OF_MEMORY
;
7261 // Claim to be relatively positioned so that we end up being the
7262 // absolute containing block.
7263 nsFrameConstructorSaveState saveState
;
7264 aState
.PushFloatContainingBlock(nsnull
, saveState
, PR_FALSE
, PR_FALSE
);
7265 rv
= ConstructBlock(aState
, innerPseudoStyle
->GetStyleDisplay(), aContent
,
7266 newFrame
, newFrame
, innerPseudoStyle
,
7267 &blockFrame
, childItems
, PR_TRUE
);
7268 // Give the blockFrame a view so that GetOffsetTo works for descendants
7269 // of blockFrame with views...
7270 nsHTMLContainerFrame::CreateViewForFrame(blockFrame
, nsnull
, PR_TRUE
);
7272 // Process the child content if requested.
7273 if (!newFrame
->IsLeaf()) {
7274 rv
= ProcessChildren(aState
, aContent
, newFrame
, PR_FALSE
, childItems
,
7277 CreateAnonymousFrames(aTag
, aState
, aContent
, newFrame
,
7278 PR_FALSE
, childItems
);
7281 // Set the frame's initial child list
7282 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
7286 return NS_ERROR_FAILURE
;
7291 // If page-break-before is set, this function constructs a page break frame,
7292 // EXCEPT for on these types of elements:
7293 // * row groups, rows, cells (these are handled internally by tables)
7294 // * fixed- and absolutely-positioned elements (currently, our positioning
7295 // code doesn't expect positioned frames to have nsPageBreakFrame siblings)
7297 // Returns true iff we should construct a page break frame after this element.
7299 nsCSSFrameConstructor::PageBreakBefore(nsFrameConstructorState
& aState
,
7300 nsIContent
* aContent
,
7301 nsIFrame
* aParentFrame
,
7302 nsStyleContext
* aStyleContext
,
7303 nsFrameItems
& aFrameItems
)
7305 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
7307 if (NS_STYLE_DISPLAY_NONE
!= display
->mDisplay
&&
7308 NS_STYLE_POSITION_FIXED
!= display
->mPosition
&&
7309 NS_STYLE_POSITION_ABSOLUTE
!= display
->mPosition
&&
7310 (NS_STYLE_DISPLAY_TABLE
== display
->mDisplay
||
7311 !IsTableRelated(display
->mDisplay
, PR_TRUE
))) {
7312 if (display
->mBreakBefore
) {
7313 ConstructPageBreakFrame(aState
, aContent
, aParentFrame
, aStyleContext
,
7316 return display
->mBreakAfter
;
7322 nsCSSFrameConstructor::ConstructPageBreakFrame(nsFrameConstructorState
& aState
,
7323 nsIContent
* aContent
,
7324 nsIFrame
* aParentFrame
,
7325 nsStyleContext
* aStyleContext
,
7326 nsFrameItems
& aFrameItems
)
7328 nsRefPtr
<nsStyleContext
> pseudoStyle
;
7329 pseudoStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(nsnull
,
7330 nsCSSAnonBoxes::pageBreak
,
7332 nsIFrame
* pageBreakFrame
= NS_NewPageBreakFrame(mPresShell
, pseudoStyle
);
7333 if (pageBreakFrame
) {
7334 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, pageBreakFrame
);
7335 aFrameItems
.AddChild(pageBreakFrame
);
7340 return NS_ERROR_OUT_OF_MEMORY
;
7345 nsCSSFrameConstructor::ConstructFrame(nsFrameConstructorState
& aState
,
7346 nsIContent
* aContent
,
7347 nsIFrame
* aParentFrame
,
7348 nsFrameItems
& aFrameItems
)
7351 NS_PRECONDITION(nsnull
!= aParentFrame
, "no parent frame");
7353 nsresult rv
= NS_OK
;
7355 // don't create a whitespace frame if aParent doesn't want it
7356 if (!NeedFrameFor(aParentFrame
, aContent
)) {
7360 // never create frames for comments or PIs
7361 if (aContent
->IsNodeOfType(nsINode::eCOMMENT
) ||
7362 aContent
->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION
))
7365 nsRefPtr
<nsStyleContext
> styleContext
;
7366 styleContext
= ResolveStyleContext(aParentFrame
, aContent
);
7368 PRBool pageBreakAfter
= PR_FALSE
;
7370 if (aState
.mPresContext
->IsPaginated()) {
7371 // See if there is a page break before, if so construct one. Also see if there is one after
7372 pageBreakAfter
= PageBreakBefore(aState
, aContent
, aParentFrame
,
7373 styleContext
, aFrameItems
);
7376 // construct the frame
7377 rv
= ConstructFrameInternal(aState
, aContent
, aParentFrame
,
7378 aContent
->Tag(), aContent
->GetNameSpaceID(),
7379 styleContext
, aFrameItems
, PR_FALSE
);
7381 if (NS_SUCCEEDED(rv
) && pageBreakAfter
) {
7382 // Construct the page break after
7383 ConstructPageBreakFrame(aState
, aContent
, aParentFrame
, styleContext
,
7392 nsCSSFrameConstructor::ConstructFrameInternal( nsFrameConstructorState
& aState
,
7393 nsIContent
* aContent
,
7394 nsIFrame
* aParentFrame
,
7396 PRInt32 aNameSpaceID
,
7397 nsStyleContext
* aStyleContext
,
7398 nsFrameItems
& aFrameItems
,
7401 // The following code allows the user to specify the base tag
7402 // of an element using XBL. XUL and HTML objects (like boxes, menus, etc.)
7403 // can then be extended arbitrarily.
7404 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
7405 nsRefPtr
<nsStyleContext
> styleContext(aStyleContext
);
7406 nsAutoEnqueueBinding
binding(mDocument
);
7410 // Ensure that our XBL bindings are installed.
7411 if (display
->mBinding
) {
7412 // Get the XBL loader.
7414 // Load the bindings.
7415 PRBool resolveStyle
;
7417 nsIXBLService
* xblService
= GetXBLService();
7419 return NS_ERROR_FAILURE
;
7421 rv
= xblService
->LoadBindings(aContent
, display
->mBinding
->mURI
,
7422 display
->mBinding
->mOriginPrincipal
,
7423 PR_FALSE
, getter_AddRefs(binding
.mBinding
),
7429 styleContext
= ResolveStyleContext(aParentFrame
, aContent
);
7430 display
= styleContext
->GetStyleDisplay();
7433 PRInt32 nameSpaceID
;
7434 nsCOMPtr
<nsIAtom
> baseTag
=
7435 mDocument
->BindingManager()->ResolveTag(aContent
, &nameSpaceID
);
7437 if (baseTag
!= aTag
|| aNameSpaceID
!= nameSpaceID
) {
7438 // Construct the frame using the XBL base tag.
7439 rv
= ConstructFrameInternal(aState
,
7452 // Pre-check for display "none" - if we find that, don't create
7454 if (NS_STYLE_DISPLAY_NONE
== display
->mDisplay
) {
7455 aState
.mFrameManager
->SetUndisplayedContent(aContent
, styleContext
);
7459 nsIFrame
* adjParentFrame
= aParentFrame
;
7460 nsFrameItems
* frameItems
= &aFrameItems
;
7461 PRBool pseudoParent
= PR_FALSE
;
7462 PRBool suppressFrame
= PR_FALSE
;
7463 nsFrameConstructorSaveState pseudoSaveState
;
7464 nsresult rv
= AdjustParentFrame(aState
, aContent
, adjParentFrame
,
7465 aTag
, aNameSpaceID
, styleContext
,
7466 frameItems
, pseudoSaveState
,
7467 suppressFrame
, pseudoParent
);
7468 if (NS_FAILED(rv
) || suppressFrame
) {
7472 if (aContent
->IsNodeOfType(nsINode::eTEXT
))
7473 return ConstructTextFrame(aState
, aContent
, adjParentFrame
, styleContext
,
7474 *frameItems
, pseudoParent
);
7477 // Don't create frames for non-SVG children of SVG elements
7478 if (aNameSpaceID
!= kNameSpaceID_SVG
&&
7480 aParentFrame
->IsFrameOfType(nsIFrame::eSVG
) &&
7481 !aParentFrame
->IsFrameOfType(nsIFrame::eSVGForeignObject
)
7487 // If the page contains markup that overrides text direction, and
7488 // does not contain any characters that would activate the Unicode
7489 // bidi algorithm, we need to call |SetBidiEnabled| on the pres
7490 // context before reflow starts. This requires us to resolve some
7491 // style information now. See bug 115921.
7493 if (styleContext
->GetStyleVisibility()->mDirection
==
7494 NS_STYLE_DIRECTION_RTL
)
7495 aState
.mPresContext
->SetBidiEnabled();
7497 // Start background loads during frame construction. This is just
7498 // a hint; the paint code will do the right thing in any case.
7500 styleContext
->GetStyleBackground();
7503 nsIFrame
* lastChild
= frameItems
->lastChild
;
7505 // Handle specific frame types
7506 rv
= ConstructHTMLFrame(aState
, aContent
, adjParentFrame
, aTag
, aNameSpaceID
,
7507 styleContext
, *frameItems
, pseudoParent
);
7509 // Failing to find a matching HTML frame, try creating a specialized
7510 // XUL frame. This is temporary, pending planned factoring of this
7511 // whole process into separate, pluggable steps.
7512 if (NS_SUCCEEDED(rv
) &&
7513 (!frameItems
->childList
|| lastChild
== frameItems
->lastChild
)) {
7514 PRBool haltProcessing
;
7516 rv
= ConstructXULFrame(aState
, aContent
, adjParentFrame
, aTag
,
7517 aNameSpaceID
, styleContext
,
7518 *frameItems
, aXBLBaseTag
, pseudoParent
,
7521 if (haltProcessing
) {
7528 if (NS_SUCCEEDED(rv
) &&
7529 (!frameItems
->childList
|| lastChild
== frameItems
->lastChild
)) {
7530 rv
= ConstructMathMLFrame(aState
, aContent
, adjParentFrame
, aTag
,
7531 aNameSpaceID
, styleContext
, *frameItems
,
7538 if (NS_SUCCEEDED(rv
) &&
7539 (!frameItems
->childList
|| lastChild
== frameItems
->lastChild
) &&
7540 aNameSpaceID
== kNameSpaceID_SVG
&&
7542 PRBool haltProcessing
;
7543 rv
= ConstructSVGFrame(aState
, aContent
, adjParentFrame
, aTag
,
7544 aNameSpaceID
, styleContext
,
7545 *frameItems
, pseudoParent
, &haltProcessing
);
7546 if (haltProcessing
) {
7552 if (NS_SUCCEEDED(rv
) &&
7553 (!frameItems
->childList
|| lastChild
== frameItems
->lastChild
)) {
7554 // When there is no explicit frame to create, assume it's a
7555 // container and let display style dictate the rest
7556 rv
= ConstructFrameByDisplayType(aState
, display
, aContent
, aNameSpaceID
,
7557 aTag
, adjParentFrame
, styleContext
,
7558 *frameItems
, pseudoParent
);
7566 IsRootBoxFrame(nsIFrame
*aFrame
)
7568 return (aFrame
->GetType() == nsGkAtoms::rootFrame
);
7572 nsCSSFrameConstructor::ReconstructDocElementHierarchy()
7574 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
7575 return ReconstructDocElementHierarchyInternal();
7579 nsCSSFrameConstructor::ReconstructDocElementHierarchyInternal()
7582 if (gNoisyContentUpdates
) {
7583 printf("nsCSSFrameConstructor::ReconstructDocElementHierarchy\n");
7587 nsresult rv
= NS_OK
;
7589 // XXXbz is that null-check needed? Why?
7590 if (mDocument
&& mPresShell
) {
7591 nsIContent
*rootContent
= mDocument
->GetRootContent();
7594 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
7595 nsnull
, nsnull
, mTempFrameTreeState
);
7597 // Before removing the frames associated with the content object, ask them to save their
7598 // state onto a temporary state object.
7599 CaptureStateFor(state
.mFrameManager
->GetRootFrame(), mTempFrameTreeState
);
7601 // Get the frame that corresponds to the document element
7602 nsIFrame
* docElementFrame
=
7603 state
.mFrameManager
->GetPrimaryFrameFor(rootContent
, -1);
7605 if (docElementFrame
) {
7606 // Destroy out-of-flow frames that might not be in the frame subtree
7607 // rooted at docElementFrame
7608 ::DeletingFrameSubtree(state
.mFrameManager
, docElementFrame
);
7611 // Remove any existing fixed items: they are always on the
7612 // FixedContainingBlock. Note that this has to be done before we call
7613 // ClearPlaceholderFrameMap(), since RemoveFixedItems uses the
7614 // placeholder frame map.
7615 rv
= RemoveFixedItems(state
, docElementFrame
);
7617 if (NS_SUCCEEDED(rv
)) {
7618 nsPlaceholderFrame
* placeholderFrame
= nsnull
;
7619 if (docElementFrame
&&
7620 (docElementFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)) {
7621 // Get the placeholder frame now, before we tear down the
7622 // placeholder frame map
7624 state
.mFrameManager
->GetPlaceholderFrameFor(docElementFrame
);
7625 NS_ASSERTION(placeholderFrame
, "No placeholder for out-of-flow?");
7628 // Clear the hash tables that map from content to frame and out-of-flow
7629 // frame to placeholder frame
7630 state
.mFrameManager
->ClearPrimaryFrameMap();
7631 state
.mFrameManager
->ClearPlaceholderFrameMap();
7632 state
.mFrameManager
->ClearUndisplayedContentMap();
7634 if (docElementFrame
) {
7635 // Take the docElementFrame, and remove it from its parent.
7636 // XXXbz So why can't we reuse ContentRemoved?
7638 // Notify self that we will destroy the entire frame tree, this blocks
7639 // RemoveMappingsForFrameSubtree() which would otherwise lead to a
7640 // crash since we cleared the placeholder map above (bug 398982).
7641 PRBool wasDestroyingFrameTree
= mIsDestroyingFrameTree
;
7642 WillDestroyFrameTree(PR_FALSE
);
7644 rv
= state
.mFrameManager
->RemoveFrame(docElementFrame
->GetParent(),
7645 GetChildListNameFor(docElementFrame
), docElementFrame
);
7647 if (placeholderFrame
) {
7648 // Remove the placeholder frame first (XXX second for now) (so
7649 // that it doesn't retain a dangling pointer to memory)
7650 rv
|= state
.mFrameManager
->RemoveFrame(placeholderFrame
->GetParent(),
7651 nsnull
, placeholderFrame
);
7654 mIsDestroyingFrameTree
= wasDestroyingFrameTree
;
7655 if (NS_FAILED(rv
)) {
7662 if (rootContent
&& NS_SUCCEEDED(rv
)) {
7663 mInitialContainingBlock
= nsnull
;
7664 mRootElementStyleFrame
= nsnull
;
7666 // We don't reuse the old frame constructor state because,
7667 // for example, its mPopupItems may be stale
7668 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
7669 nsnull
, nsnull
, mTempFrameTreeState
);
7671 // Create the new document element hierarchy
7673 rv
= ConstructDocElementFrame(state
, rootContent
,
7674 mDocElementContainingBlock
, &newChild
);
7676 // newChild could be null even if |rv| is success, thanks to XBL.
7677 if (NS_SUCCEEDED(rv
) && newChild
) {
7678 rv
= state
.mFrameManager
->InsertFrames(mDocElementContainingBlock
,
7679 nsnull
, nsnull
, newChild
);
7689 nsCSSFrameConstructor::GetFrameFor(nsIContent
* aContent
)
7691 // Get the primary frame associated with the content
7692 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
7697 nsIFrame
* insertionFrame
= frame
->GetContentInsertionFrame();
7699 NS_ASSERTION(insertionFrame
== frame
|| !frame
->IsLeaf(),
7700 "The insertion frame is the primary frame or the primary frame isn't a leaf");
7702 return insertionFrame
;
7706 nsCSSFrameConstructor::GetAbsoluteContainingBlock(nsIFrame
* aFrame
)
7708 NS_PRECONDITION(nsnull
!= mInitialContainingBlock
, "no initial containing block");
7710 // Starting with aFrame, look for a frame that is absolutely positioned or
7711 // relatively positioned
7712 nsIFrame
* containingBlock
= nsnull
;
7713 for (nsIFrame
* frame
= aFrame
; frame
&& !containingBlock
;
7714 frame
= frame
->GetParent()) {
7715 if (frame
->IsFrameOfType(nsIFrame::eMathML
)) {
7716 // If it's mathml, bail out -- no absolute positioning out from inside
7717 // mathml frames. Note that we don't make this part of the loop
7718 // condition because of the stuff at the end of this method...
7722 // Is it positioned?
7723 // If it's table-related then ignore it, because for the time
7724 // being table-related frames are not containers for absolutely
7725 // positioned child frames.
7726 const nsStyleDisplay
* disp
= frame
->GetStyleDisplay();
7728 if (disp
->IsPositioned() && !IsTableRelated(disp
->mDisplay
, PR_TRUE
)) {
7729 // Find the outermost wrapped block under this frame
7730 for (nsIFrame
* wrappedFrame
= aFrame
; wrappedFrame
!= frame
->GetParent();
7731 wrappedFrame
= wrappedFrame
->GetParent()) {
7732 nsIAtom
* frameType
= wrappedFrame
->GetType();
7733 if (nsGkAtoms::areaFrame
== frameType
||
7734 nsGkAtoms::blockFrame
== frameType
||
7735 nsGkAtoms::positionedInlineFrame
== frameType
) {
7736 containingBlock
= wrappedFrame
;
7737 } else if (nsGkAtoms::fieldSetFrame
== frameType
) {
7738 // If the positioned frame is a fieldset, use the area frame inside it.
7739 // We don't use GetContentInsertionFrame for fieldsets yet.
7740 containingBlock
= GetFieldSetAreaFrame(wrappedFrame
);
7745 if (!containingBlock
)
7746 NS_WARNING("Positioned frame that does not handle positioned kids; looking further up the parent chain");
7751 // If we found an absolutely positioned containing block, then use the
7752 // first-continuation.
7753 if (containingBlock
)
7754 return AdjustAbsoluteContainingBlock(containingBlock
);
7756 // If we didn't find it, then use the document element containing block
7757 return mHasRootAbsPosContainingBlock
? mDocElementContainingBlock
: nsnull
;
7761 nsCSSFrameConstructor::GetFloatContainingBlock(nsIFrame
* aFrame
)
7763 NS_PRECONDITION(mInitialContainingBlock
, "no initial containing block");
7765 // Starting with aFrame, look for a frame that is a float containing block.
7766 // IF we hit a mathml frame, bail out; we don't allow floating out of mathml
7767 // frames, because they don't seem to be able to deal.
7768 for (nsIFrame
* containingBlock
= aFrame
;
7769 containingBlock
&& !containingBlock
->IsFrameOfType(nsIFrame::eMathML
) &&
7770 !containingBlock
->IsBoxFrame();
7771 containingBlock
= containingBlock
->GetParent()) {
7772 if (containingBlock
->IsFloatContainingBlock()) {
7773 return containingBlock
;
7777 // If we didn't find a containing block, then there just isn't
7778 // one.... return null
7783 * This function will check whether aContainer has :after generated content.
7784 * If so, appending to it should actually insert. The return value is the
7785 * parent to use for newly-appended content. *aAfterFrame points to the :after
7786 * frame before which appended content should go, if there is one.
7789 AdjustAppendParentForAfterContent(nsPresContext
* aPresContext
,
7790 nsIContent
* aContainer
,
7791 nsIFrame
* aParentFrame
,
7792 nsIFrame
** aAfterFrame
)
7794 // See if the parent has an :after pseudo-element. Check for the presence
7795 // of style first, since nsLayoutUtils::GetAfterFrame is sorta expensive.
7796 nsStyleContext
* parentStyle
= aParentFrame
->GetStyleContext();
7797 if (nsLayoutUtils::HasPseudoStyle(aContainer
, parentStyle
,
7798 nsCSSPseudoElements::after
,
7800 nsIFrame
* afterFrame
= nsLayoutUtils::GetAfterFrame(aParentFrame
);
7802 *aAfterFrame
= afterFrame
;
7803 return afterFrame
->GetParent();
7807 *aAfterFrame
= nsnull
;
7808 return aParentFrame
;
7812 * This function is called by ContentAppended() and ContentInserted()
7813 * when appending flowed frames to a parent's principal child list. It
7814 * handles the case where the parent frame has :after pseudo-element
7815 * generated content.
7818 nsCSSFrameConstructor::AppendFrames(nsFrameConstructorState
& aState
,
7819 nsIContent
* aContainer
,
7820 nsIFrame
* aParentFrame
,
7821 nsFrameItems
& aFrameList
,
7822 nsIFrame
* aAfterFrame
)
7825 nsIFrame
* debugAfterFrame
;
7826 nsIFrame
* debugNewParent
=
7827 ::AdjustAppendParentForAfterContent(aState
.mPresContext
, aContainer
,
7828 aParentFrame
, &debugAfterFrame
);
7829 NS_ASSERTION(debugNewParent
== aParentFrame
, "Incorrect parent");
7830 NS_ASSERTION(debugAfterFrame
== aAfterFrame
, "Incorrect after frame");
7833 nsFrameManager
* frameManager
= aState
.mFrameManager
;
7835 NS_ASSERTION(!IsFrameSpecial(aParentFrame
) ||
7836 IsInlineFrame(aParentFrame
) ||
7837 !IsInlineOutside(aAfterFrame
),
7838 "Shouldn't have inline :after content on the block in an "
7840 nsFrameList
frames(aParentFrame
->GetFirstChild(nsnull
));
7842 // Insert the frames before the :after pseudo-element.
7843 return frameManager
->InsertFrames(aParentFrame
, nsnull
,
7844 frames
.GetPrevSiblingFor(aAfterFrame
),
7845 aFrameList
.childList
);
7848 if (IsFrameSpecial(aParentFrame
) &&
7849 !IsInlineFrame(aParentFrame
) &&
7850 IsInlineOutside(aFrameList
.lastChild
)) {
7851 NS_ASSERTION(!aParentFrame
->GetNextContinuation() ||
7852 !aParentFrame
->GetNextContinuation()->GetFirstChild(nsnull
),
7853 "Shouldn't happen");
7855 // We want to put some of the frames into the following inline frame.
7856 nsIFrame
* lastBlock
= FindLastBlock(aFrameList
.childList
);
7857 nsIFrame
* firstTrailingInline
;
7859 firstTrailingInline
= lastBlock
->GetNextSibling();
7860 lastBlock
->SetNextSibling(nsnull
);
7861 aFrameList
.lastChild
= lastBlock
;
7863 firstTrailingInline
= aFrameList
.childList
;
7864 aFrameList
= nsFrameItems();
7867 NS_ASSERTION(firstTrailingInline
, "How did that happen?");
7868 nsIFrame
* parentFrame
= aParentFrame
;
7870 // As we go up the tree creating trailing inlines, we have to move floats
7871 // up to ancestor blocks. This means that at any given time we'll be
7872 // working with two frame constructor states, and aState is one of the two
7873 // only at the first step. Create some space to do this so we don't have
7874 // to allocate as we go.
7875 char stateBuf
[2 * sizeof(nsFrameConstructorState
)];
7876 nsFrameConstructorState
* sourceState
= &aState
;
7877 nsFrameConstructorState
* targetState
=
7878 reinterpret_cast<nsFrameConstructorState
*>(stateBuf
);
7880 // Now we loop, because it might be the case that the parent of our special
7881 // block is another special block, and that we're at the very end of it,
7882 // and in that case if we create a new special inline we'll have to create
7883 // a parent for it too.
7885 NS_ASSERTION(IsFrameSpecial(parentFrame
) && !IsInlineFrame(parentFrame
),
7886 "Shouldn't be in this code");
7887 nsIFrame
* inlineSibling
= GetSpecialSibling(parentFrame
);
7888 PRBool isPositioned
= PR_FALSE
;
7889 nsIContent
* content
= nsnull
;
7890 nsStyleContext
* styleContext
= nsnull
;
7891 if (!inlineSibling
) {
7892 nsIFrame
* firstInline
=
7893 GetIBSplitSpecialPrevSiblingForAnonymousBlock(parentFrame
);
7894 NS_ASSERTION(firstInline
, "How did that happen?");
7896 content
= firstInline
->GetContent();
7897 styleContext
= firstInline
->GetStyleContext();
7898 isPositioned
= (styleContext
->GetStyleDisplay()->mPosition
==
7899 NS_STYLE_POSITION_RELATIVE
);
7902 nsIFrame
* stateParent
=
7903 inlineSibling
? inlineSibling
->GetParent() : parentFrame
->GetParent();
7906 nsFrameConstructorState(mPresShell
, mFixedContainingBlock
,
7907 GetAbsoluteContainingBlock(stateParent
),
7908 GetFloatContainingBlock(stateParent
));
7909 nsIFrame
* newInlineSibling
=
7910 MoveFramesToEndOfIBSplit(*sourceState
, inlineSibling
,
7911 isPositioned
, content
,
7912 styleContext
, firstTrailingInline
,
7913 parentFrame
, targetState
);
7915 if (sourceState
== &aState
) {
7916 NS_ASSERTION(targetState
==
7917 reinterpret_cast<nsFrameConstructorState
*>(stateBuf
),
7918 "Bogus target state?");
7919 // Set sourceState to the value targetState should have next.
7920 sourceState
= targetState
+ 1;
7922 // Go ahead and process whatever insertions we didn't move out
7923 sourceState
->~nsFrameConstructorState();
7926 // We're done with the source state. The target becomes the new source,
7927 // and we point the target pointer to the available memory.
7928 nsFrameConstructorState
* temp
= sourceState
;
7929 sourceState
= targetState
;
7930 targetState
= temp
;;
7932 if (inlineSibling
) {
7933 // we're all set -- we just moved things to a frame that was already
7935 NS_ASSERTION(newInlineSibling
== inlineSibling
, "What happened?");
7939 SetFrameIsSpecial(parentFrame
->GetFirstContinuation(), newInlineSibling
);
7941 // We had to create a frame for this new inline sibling. Figure out
7942 // the right parentage for it.
7943 // XXXbz add a test for this?
7944 nsIFrame
* newParentFrame
= parentFrame
->GetParent();
7945 NS_ASSERTION(!IsInlineFrame(newParentFrame
),
7946 "The block in an {ib} split shouldn't be living inside "
7948 if (!IsFrameSpecial(newParentFrame
) ||
7949 newParentFrame
->GetNextContinuation() ||
7950 parentFrame
->GetNextSibling()) {
7951 // Just insert after parentFrame
7952 frameManager
->InsertFrames(newParentFrame
, nsnull
, parentFrame
,
7954 firstTrailingInline
= nsnull
;
7956 // recurse up the tree
7957 parentFrame
= newParentFrame
;
7958 firstTrailingInline
= newInlineSibling
;
7960 } while (firstTrailingInline
);
7962 // Process the float insertions on the last target state we had.
7963 sourceState
->~nsFrameConstructorState();
7966 if (!aFrameList
.childList
) {
7967 // It all got eaten by the special inline
7971 return frameManager
->AppendFrames(aParentFrame
, nsnull
,
7972 aFrameList
.childList
);
7975 #define UNSET_DISPLAY 255
7978 nsCSSFrameConstructor::FindPreviousAnonymousSibling(nsIContent
* aContainer
,
7981 nsCOMPtr
<nsIDOMDocumentXBL
> xblDoc(do_QueryInterface(mDocument
));
7982 NS_ASSERTION(xblDoc
, "null xblDoc for content element in FindNextAnonymousSibling");
7986 // Grovel through the anonymous elements looking for aChild. We'll
7987 // start our search for a previous frame there.
7988 nsCOMPtr
<nsIDOMNodeList
> nodeList
;
7989 nsCOMPtr
<nsIDOMElement
> elt(do_QueryInterface(aContainer
));
7990 xblDoc
->GetAnonymousNodes(elt
, getter_AddRefs(nodeList
));
7996 nodeList
->GetLength(&length
);
7999 for (index
= PRInt32(length
) - 1; index
>= 0; --index
) {
8000 nsCOMPtr
<nsIDOMNode
> node
;
8001 nodeList
->Item(PRUint32(index
), getter_AddRefs(node
));
8003 nsCOMPtr
<nsIContent
> child
= do_QueryInterface(node
);
8004 if (child
== aChild
)
8008 // We want the node immediately before aChild. Keep going until we
8009 // run off the beginning of the nodeList, or we find a frame.
8010 PRUint8 childDisplay
= UNSET_DISPLAY
;
8011 while (--index
>= 0) {
8012 nsCOMPtr
<nsIDOMNode
> node
;
8013 nodeList
->Item(PRUint32(index
), getter_AddRefs(node
));
8015 nsCOMPtr
<nsIContent
> child
= do_QueryInterface(node
);
8017 // Get its frame. If it doesn't have one, continue on to the
8018 // anonymous element that preceded it.
8019 nsIFrame
* prevSibling
= FindFrameForContentSibling(child
, aChild
,
8020 childDisplay
, PR_TRUE
);
8022 // Found a previous sibling, we're done!
8031 * Find the frame for the anonymous content immediately following
8035 nsCSSFrameConstructor::FindNextAnonymousSibling(nsIContent
* aContainer
,
8038 nsCOMPtr
<nsIDOMDocumentXBL
> xblDoc(do_QueryInterface(mDocument
));
8039 NS_ASSERTION(xblDoc
, "null xblDoc for content element in FindNextAnonymousSibling");
8043 // Grovel through the anonymous elements looking for aChild
8044 nsCOMPtr
<nsIDOMNodeList
> nodeList
;
8045 nsCOMPtr
<nsIDOMElement
> elt(do_QueryInterface(aContainer
));
8046 xblDoc
->GetAnonymousNodes(elt
, getter_AddRefs(nodeList
));
8052 nodeList
->GetLength(&length
);
8055 for (index
= 0; index
< PRInt32(length
); ++index
) {
8056 nsCOMPtr
<nsIDOMNode
> node
;
8057 nodeList
->Item(PRUint32(index
), getter_AddRefs(node
));
8059 nsCOMPtr
<nsIContent
> child
= do_QueryInterface(node
);
8060 if (child
== aChild
)
8064 // We want the node immediately after aChild. Keep going until we
8065 // run off the end of the nodeList, or we find a next sibling.
8066 PRUint8 childDisplay
= UNSET_DISPLAY
;
8067 while (++index
< PRInt32(length
)) {
8068 nsCOMPtr
<nsIDOMNode
> node
;
8069 nodeList
->Item(PRUint32(index
), getter_AddRefs(node
));
8071 nsCOMPtr
<nsIContent
> child
= do_QueryInterface(node
);
8074 nsIFrame
* nextSibling
= FindFrameForContentSibling(child
, aChild
,
8075 childDisplay
, PR_FALSE
);
8077 // Found a next sibling, we're done!
8085 // This gets called to see if the frames corresponding to aSiblingDisplay and aDisplay
8086 // should be siblings in the frame tree. Although (1) rows and cols, (2) row groups
8087 // and col groups, (3) row groups and captions, (4) legends and content inside fieldsets, (5) popups and other kids of the menu
8088 // are siblings from a content perspective, they are not considered siblings in the
8091 nsCSSFrameConstructor::IsValidSibling(nsIFrame
* aSibling
,
8092 nsIContent
* aContent
,
8095 nsIFrame
* parentFrame
= aSibling
->GetParent();
8096 nsIAtom
* parentType
= nsnull
;
8097 nsIAtom
* grandparentType
= nsnull
;
8099 parentType
= parentFrame
->GetType();
8100 nsIFrame
* grandparentFrame
= parentFrame
->GetParent();
8101 if (grandparentFrame
) {
8102 grandparentType
= grandparentFrame
->GetType();
8106 PRUint8 siblingDisplay
= aSibling
->GetStyleDisplay()->mDisplay
;
8107 if ((NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
== siblingDisplay
) ||
8108 (NS_STYLE_DISPLAY_TABLE_COLUMN
== siblingDisplay
) ||
8109 (NS_STYLE_DISPLAY_TABLE_CAPTION
== siblingDisplay
) ||
8110 (NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
== siblingDisplay
) ||
8111 (NS_STYLE_DISPLAY_TABLE_ROW_GROUP
== siblingDisplay
) ||
8112 (NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
== siblingDisplay
) ||
8113 nsGkAtoms::menuFrame
== parentType
) {
8114 // if we haven't already, construct a style context to find the display type of aContent
8115 if (UNSET_DISPLAY
== aDisplay
) {
8116 nsRefPtr
<nsStyleContext
> styleContext
;
8117 nsIFrame
* styleParent
;
8118 PRBool providerIsChild
;
8119 if (NS_FAILED(aSibling
->
8120 GetParentStyleContextFrame(aSibling
->PresContext(),
8122 &providerIsChild
)) ||
8124 NS_NOTREACHED("Shouldn't happen");
8127 styleContext
= ResolveStyleContext(styleParent
, aContent
);
8128 if (!styleContext
) return PR_FALSE
;
8129 const nsStyleDisplay
* display
= styleContext
->GetStyleDisplay();
8130 aDisplay
= display
->mDisplay
;
8132 if (nsGkAtoms::menuFrame
== parentType
) {
8134 (NS_STYLE_DISPLAY_POPUP
== aDisplay
) ==
8135 (NS_STYLE_DISPLAY_POPUP
== siblingDisplay
);
8137 switch (siblingDisplay
) {
8138 case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
:
8139 return (NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
== aDisplay
);
8140 case NS_STYLE_DISPLAY_TABLE_COLUMN
:
8141 return (NS_STYLE_DISPLAY_TABLE_COLUMN
== aDisplay
);
8142 case NS_STYLE_DISPLAY_TABLE_CAPTION
:
8143 return (NS_STYLE_DISPLAY_TABLE_CAPTION
== aDisplay
);
8144 default: // all of the row group types
8145 return (NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
== aDisplay
) ||
8146 (NS_STYLE_DISPLAY_TABLE_ROW_GROUP
== aDisplay
) ||
8147 (NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
== aDisplay
) ||
8148 (NS_STYLE_DISPLAY_TABLE_CAPTION
== aDisplay
);
8151 else if (nsGkAtoms::fieldSetFrame
== parentType
||
8152 (nsGkAtoms::fieldSetFrame
== grandparentType
&&
8153 nsGkAtoms::areaFrame
== parentType
)) {
8154 // Legends can be sibling of legends but not of other content in the fieldset
8155 nsIAtom
* sibType
= aSibling
->GetType();
8156 nsCOMPtr
<nsIDOMHTMLLegendElement
> legendContent(do_QueryInterface(aContent
));
8158 if ((legendContent
&& (nsGkAtoms::legendFrame
!= sibType
)) ||
8159 (!legendContent
&& (nsGkAtoms::legendFrame
== sibType
)))
8167 nsCSSFrameConstructor::FindFrameForContentSibling(nsIContent
* aContent
,
8168 nsIContent
* aTargetContent
,
8169 PRUint8
& aTargetContentDisplay
,
8170 PRBool aPrevSibling
)
8172 nsIFrame
* sibling
= mPresShell
->GetPrimaryFrameFor(aContent
);
8177 // If the frame is out-of-flow, GPFF() will have returned the
8178 // out-of-flow frame; we want the placeholder.
8179 if (sibling
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
8180 nsIFrame
* placeholderFrame
;
8181 mPresShell
->GetPlaceholderFrameFor(sibling
, &placeholderFrame
);
8182 NS_ASSERTION(placeholderFrame
, "no placeholder for out-of-flow frame");
8183 sibling
= placeholderFrame
;
8186 // The frame we have now should never be a continuation
8187 NS_ASSERTION(!sibling
->GetPrevContinuation(), "How did that happen?");
8190 // The frame may be a special frame (a split inline frame that
8191 // contains a block). Get the last part of that split.
8192 if (IsFrameSpecial(sibling
)) {
8193 sibling
= GetLastSpecialSibling(sibling
);
8196 // The frame may have a continuation. If so, we want the last
8197 // non-overflow-container continuation as our previous sibling.
8198 sibling
= sibling
->GetTailContinuation();
8201 if (aTargetContent
&&
8202 !IsValidSibling(sibling
, aTargetContent
, aTargetContentDisplay
)) {
8210 * Find the ``rightmost'' frame for the content immediately preceding
8211 * aIndexInContainer, following continuations if necessary.
8214 nsCSSFrameConstructor::FindPreviousSibling(nsIContent
* aContainer
,
8215 PRInt32 aIndexInContainer
,
8218 NS_ASSERTION(aContainer
, "null argument");
8220 ChildIterator first
, iter
;
8221 nsresult rv
= ChildIterator::Init(aContainer
, &first
, &iter
);
8222 NS_ENSURE_SUCCESS(rv
, nsnull
);
8223 iter
.seek(aIndexInContainer
);
8225 PRUint8 childDisplay
= UNSET_DISPLAY
;
8226 // Note: not all content objects are associated with a frame (e.g., if it's
8227 // `display: none') so keep looking until we find a previous frame
8228 while (iter
-- != first
) {
8229 nsIFrame
* prevSibling
=
8230 FindFrameForContentSibling(nsCOMPtr
<nsIContent
>(*iter
), aChild
,
8231 childDisplay
, PR_TRUE
);
8235 nsIFrame
* containerFrame
= nsnull
;
8236 containerFrame
= mPresShell
->GetPrimaryFrameFor(aContainer
);
8237 NS_ASSERTION(prevSibling
!= containerFrame
, "Previous Sibling is the Container's frame");
8239 // Found a previous sibling, we're done!
8248 * Find the frame for the content node immediately following
8249 * aIndexInContainer.
8252 nsCSSFrameConstructor::FindNextSibling(nsIContent
* aContainer
,
8253 PRInt32 aIndexInContainer
,
8256 ChildIterator iter
, last
;
8257 nsresult rv
= ChildIterator::Init(aContainer
, &iter
, &last
);
8258 NS_ENSURE_SUCCESS(rv
, nsnull
);
8259 iter
.seek(aIndexInContainer
);
8261 // Catch the case where someone tries to append
8265 PRUint8 childDisplay
= UNSET_DISPLAY
;
8267 while (++iter
!= last
) {
8268 nsIFrame
* nextSibling
=
8269 FindFrameForContentSibling(nsCOMPtr
<nsIContent
>(*iter
), aChild
,
8270 childDisplay
, PR_FALSE
);
8273 // We found a next sibling, we're done!
8282 ShouldIgnoreSelectChild(nsIContent
* aContainer
)
8284 // Ignore options and optgroups inside a select (size > 1)
8285 nsIAtom
*containerTag
= aContainer
->Tag();
8287 if (containerTag
== nsGkAtoms::optgroup
||
8288 containerTag
== nsGkAtoms::select
) {
8289 nsIContent
* selectContent
= aContainer
;
8291 while (containerTag
!= nsGkAtoms::select
) {
8292 selectContent
= selectContent
->GetParent();
8293 if (!selectContent
) {
8296 containerTag
= selectContent
->Tag();
8299 nsCOMPtr
<nsISelectElement
> selectElement
= do_QueryInterface(selectContent
);
8300 if (selectElement
) {
8301 nsAutoString selSize
;
8302 aContainer
->GetAttr(kNameSpaceID_None
, nsGkAtoms::size
, selSize
);
8303 if (!selSize
.IsEmpty()) {
8305 return (selSize
.ToInteger(&err
) > 1);
8313 // For fieldsets, returns the area frame, if the child is not a legend.
8315 GetAdjustedParentFrame(nsIFrame
* aParentFrame
,
8316 nsIAtom
* aParentFrameType
,
8317 nsIContent
* aParentContent
,
8318 PRInt32 aChildIndex
)
8320 NS_PRECONDITION(nsGkAtoms::tableOuterFrame
!= aParentFrameType
,
8321 "Shouldn't be happening!");
8323 nsIContent
*childContent
= aParentContent
->GetChildAt(aChildIndex
);
8324 nsIFrame
* newParent
= nsnull
;
8326 if (nsGkAtoms::fieldSetFrame
== aParentFrameType
) {
8327 // If the parent is a fieldSet, use the fieldSet's area frame as the
8328 // parent unless the new content is a legend.
8329 nsCOMPtr
<nsIDOMHTMLLegendElement
> legendContent(do_QueryInterface(childContent
));
8330 if (!legendContent
) {
8331 newParent
= GetFieldSetAreaFrame(aParentFrame
);
8334 return (newParent
) ? newParent
: aParentFrame
;
8338 InvalidateCanvasIfNeeded(nsIFrame
* aFrame
);
8341 IsSpecialFramesetChild(nsIContent
* aContent
)
8343 // IMPORTANT: This must match the conditions in nsHTMLFramesetFrame::Init.
8344 return aContent
->IsNodeOfType(nsINode::eHTML
) &&
8345 (aContent
->Tag() == nsGkAtoms::frameset
||
8346 aContent
->Tag() == nsGkAtoms::frame
);
8350 nsCSSFrameConstructor::ContentAppended(nsIContent
* aContainer
,
8351 PRInt32 aNewIndexInContainer
)
8353 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
8354 NS_PRECONDITION(mUpdateCount
!= 0,
8355 "Should be in an update while creating frames");
8358 if (gNoisyContentUpdates
) {
8359 printf("nsCSSFrameConstructor::ContentAppended container=%p index=%d\n",
8360 static_cast<void*>(aContainer
), aNewIndexInContainer
);
8361 if (gReallyNoisyContentUpdates
&& aContainer
) {
8362 aContainer
->List(stdout
, 0);
8369 PRInt32 namespaceID
;
8371 mDocument
->BindingManager()->ResolveTag(aContainer
, &namespaceID
);
8373 // Just ignore tree tags, anyway we don't create any frames for them.
8374 if (tag
== nsGkAtoms::treechildren
||
8375 tag
== nsGkAtoms::treeitem
||
8376 tag
== nsGkAtoms::treerow
||
8377 (namespaceID
== kNameSpaceID_XUL
&& gUseXBLForms
&&
8378 ShouldIgnoreSelectChild(aContainer
)))
8384 // Get the frame associated with the content
8385 nsIFrame
* parentFrame
= GetFrameFor(aContainer
);
8389 // See if we have an XBL insertion point. If so, then that's our
8390 // real parent frame; if not, then the frame hasn't been built yet
8391 // and we just bail.
8393 nsIFrame
* insertionPoint
;
8394 PRBool multiple
= PR_FALSE
;
8395 GetInsertionPoint(parentFrame
, nsnull
, &insertionPoint
, &multiple
);
8396 if (! insertionPoint
)
8397 return NS_OK
; // Don't build the frames.
8399 PRBool hasInsertion
= PR_FALSE
;
8401 nsIDocument
* document
= nsnull
;
8402 nsIContent
*firstAppendedChild
=
8403 aContainer
->GetChildAt(aNewIndexInContainer
);
8404 if (firstAppendedChild
) {
8405 document
= firstAppendedChild
->GetDocument();
8408 document
->BindingManager()->GetInsertionParent(firstAppendedChild
)) {
8409 hasInsertion
= PR_TRUE
;
8413 if (multiple
|| hasInsertion
) {
8414 // We have an insertion point. There are some additional tests we need to do
8415 // in order to ensure that an append is a safe operation.
8416 PRUint32 childCount
= 0;
8419 // We may need to make multiple ContentInserted calls instead. A
8420 // reasonable heuristic to employ (in order to maintain good performance)
8421 // is to find out if the insertion point's content node contains any
8422 // explicit children. If it does not, then it is highly likely that
8423 // an append is occurring. (Note it is not definite, and there are insane
8424 // cases we will not deal with by employing this heuristic, but it beats
8425 // always falling back to multiple ContentInserted calls).
8427 // In the multiple insertion point case, we know we're going to need to do
8428 // multiple ContentInserted calls anyway.
8429 childCount
= insertionPoint
->GetContent()->GetChildCount();
8432 if (multiple
|| childCount
> 0) {
8433 // Now comes the fun part. For each appended child, we must obtain its
8434 // insertion point and find its exact position within that insertion point.
8435 // We then make a ContentInserted call with the correct computed index.
8436 nsIContent
* insertionContent
= insertionPoint
->GetContent();
8438 PRUint32 containerCount
= aContainer
->GetChildCount();
8439 for (PRUint32 i
= aNewIndexInContainer
; i
< containerCount
; i
++) {
8440 nsIContent
*child
= aContainer
->GetChildAt(i
);
8442 // Filters are in effect, so the insertion point needs to be refetched for
8444 GetInsertionPoint(parentFrame
, child
, &insertionPoint
);
8445 if (!insertionPoint
) {
8446 // This content node doesn't have an insertion point, so we just
8450 insertionContent
= insertionPoint
->GetContent();
8453 // Construct an iterator to locate this child at its correct index.
8454 ChildIterator iter
, last
;
8455 for (ChildIterator::Init(insertionContent
, &iter
, &last
);
8458 LAYOUT_PHASE_TEMP_EXIT();
8459 nsIContent
* item
= nsCOMPtr
<nsIContent
>(*iter
);
8461 // Call ContentInserted with this index.
8462 ContentInserted(aContainer
, child
,
8463 iter
.position(), mTempFrameTreeState
);
8464 LAYOUT_PHASE_TEMP_REENTER();
8472 parentFrame
= insertionPoint
;
8474 if (parentFrame
->GetType() == nsGkAtoms::frameSetFrame
) {
8475 // Check whether we have any kids we care about.
8476 PRUint32 count
= aContainer
->GetChildCount();
8477 for (PRUint32 i
= aNewIndexInContainer
; i
< count
; ++i
) {
8478 if (IsSpecialFramesetChild(aContainer
->GetChildAt(i
))) {
8479 // Just reframe the parent, since framesets are weird like that.
8480 return RecreateFramesForContent(parentFrame
->GetContent());
8485 if (parentFrame
->IsLeaf()) {
8486 // Nothing to do here; we shouldn't be constructing kids of leaves
8491 if (parentFrame
->IsFrameOfType(nsIFrame::eMathML
))
8492 return RecreateFramesForContent(parentFrame
->GetContent());
8495 // If the frame we are manipulating is a ``special'' frame (that is, one
8496 // that's been created as a result of a block-in-inline situation) then we
8497 // need to append to the last special sibling, not to the frame itself.
8498 if (IsFrameSpecial(parentFrame
)) {
8500 if (gNoisyContentUpdates
) {
8501 printf("nsCSSFrameConstructor::ContentAppended: parentFrame=");
8502 nsFrame::ListTag(stdout
, parentFrame
);
8503 printf(" is special\n");
8507 // Since we're appending, we'll walk to the last anonymous frame
8508 // that was created for the broken inline frame.
8509 parentFrame
= GetLastSpecialSibling(parentFrame
);
8512 // Get continuation that parents the last child
8513 parentFrame
= nsLayoutUtils::GetLastContinuationWithChild(parentFrame
);
8515 nsIAtom
* frameType
= parentFrame
->GetType();
8516 // Deal with fieldsets
8517 parentFrame
= ::GetAdjustedParentFrame(parentFrame
, frameType
,
8518 aContainer
, aNewIndexInContainer
);
8520 // Deal with possible :after generated content on the parent
8521 nsIFrame
* parentAfterFrame
;
8523 ::AdjustAppendParentForAfterContent(mPresShell
->GetPresContext(),
8524 aContainer
, parentFrame
,
8527 // Create some new frames
8529 nsFrameItems frameItems
;
8530 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
8531 GetAbsoluteContainingBlock(parentFrame
),
8532 GetFloatContainingBlock(parentFrame
));
8534 // See if the containing block has :first-letter style applied.
8535 PRBool haveFirstLetterStyle
= PR_FALSE
, haveFirstLineStyle
= PR_FALSE
;
8536 nsIFrame
* containingBlock
= state
.mFloatedItems
.containingBlock
;
8537 if (containingBlock
) {
8538 haveFirstLetterStyle
= HasFirstLetterStyle(containingBlock
);
8539 haveFirstLineStyle
=
8540 ShouldHaveFirstLineStyle(containingBlock
->GetContent(),
8541 containingBlock
->GetStyleContext());
8544 if (haveFirstLetterStyle
) {
8545 // Before we get going, remove the current letter frames
8546 RemoveLetterFrames(state
.mPresContext
, state
.mPresShell
,
8547 state
.mFrameManager
, containingBlock
);
8550 // if the container is a table and a caption was appended, it needs to be put in
8551 // the outer table frame's additional child list.
8552 nsFrameItems captionItems
;
8554 // The last frame that we added to the list.
8555 nsIFrame
* oldNewFrame
= nsnull
;
8558 count
= aContainer
->GetChildCount();
8559 for (i
= aNewIndexInContainer
; i
< count
; i
++) {
8560 nsIFrame
* newFrame
= nsnull
;
8561 nsIContent
*childContent
= aContainer
->GetChildAt(i
);
8563 ConstructFrame(state
, childContent
, parentFrame
, frameItems
);
8564 newFrame
= frameItems
.lastChild
;
8566 if (newFrame
&& newFrame
!= oldNewFrame
) {
8567 InvalidateCanvasIfNeeded(newFrame
);
8568 oldNewFrame
= newFrame
;
8572 if (nsGkAtoms::tableFrame
== frameType
) {
8573 // Pull out the captions. Note that we don't want to do that as we go,
8574 // because processing a single caption can add a whole bunch of things to
8575 // the frame items due to pseudoframe processing. So we'd have to pull
8576 // captions from a list anyway; might as well do that here.
8577 PullOutCaptionFrames(frameItems
, captionItems
);
8581 // process the current pseudo frame state
8582 if (!state
.mPseudoFrames
.IsEmpty()) {
8583 ProcessPseudoFrames(state
, frameItems
);
8586 if (haveFirstLineStyle
&& parentFrame
== containingBlock
) {
8587 // It's possible that some of the new frames go into a
8588 // first-line frame. Look at them and see...
8589 AppendFirstLineFrames(state
, containingBlock
->GetContent(),
8590 containingBlock
, frameItems
);
8593 nsresult result
= NS_OK
;
8595 // Notify the parent frame passing it the list of new frames
8596 if (NS_SUCCEEDED(result
) &&
8597 (frameItems
.childList
|| captionItems
.childList
)) {
8598 // Perform special check for diddling around with the frames in
8599 // a special inline frame.
8601 // If we're appending before :after content, then we're not really
8602 // appending, so let WipeContainingBlock know that.
8603 if (WipeContainingBlock(state
, containingBlock
, parentFrame
, frameItems
,
8604 !parentAfterFrame
, nsnull
)) {
8608 // Append the flowed frames to the principal child list, tables need special treatment
8609 if (nsGkAtoms::tableFrame
== frameType
) {
8610 if (captionItems
.childList
) { // append the caption to the outer table
8611 nsIFrame
* outerTable
= parentFrame
->GetParent();
8613 state
.mFrameManager
->AppendFrames(outerTable
,
8614 nsGkAtoms::captionList
,
8615 captionItems
.childList
);
8618 if (frameItems
.childList
) { // append children of the inner table
8619 AppendFrames(state
, aContainer
, parentFrame
, frameItems
,
8624 AppendFrames(state
, aContainer
, parentFrame
, frameItems
,
8629 // Recover first-letter frames
8630 if (haveFirstLetterStyle
) {
8631 RecoverLetterFrames(state
, containingBlock
);
8635 if (gReallyNoisyContentUpdates
) {
8636 nsIFrameDebug
* fdbg
= nsnull
;
8637 CallQueryInterface(parentFrame
, &fdbg
);
8639 printf("nsCSSFrameConstructor::ContentAppended: resulting frame model:\n");
8640 fdbg
->List(stdout
, 0);
8650 enum content_operation
8656 // Helper function to lookup the listbox body frame and send a notification
8657 // for insertion or removal of content
8659 PRBool
NotifyListBoxBody(nsPresContext
* aPresContext
,
8660 nsIContent
* aContainer
,
8662 PRInt32 aIndexInContainer
,
8663 nsIDocument
* aDocument
,
8664 nsIFrame
* aChildFrame
,
8665 PRBool aUseXBLForms
,
8666 content_operation aOperation
)
8671 if (aContainer
->IsNodeOfType(nsINode::eXUL
) &&
8672 aChild
->IsNodeOfType(nsINode::eXUL
) &&
8673 aContainer
->Tag() == nsGkAtoms::listbox
&&
8674 aChild
->Tag() == nsGkAtoms::listitem
) {
8675 nsCOMPtr
<nsIDOMXULElement
> xulElement
= do_QueryInterface(aContainer
);
8676 nsCOMPtr
<nsIBoxObject
> boxObject
;
8677 xulElement
->GetBoxObject(getter_AddRefs(boxObject
));
8678 nsCOMPtr
<nsPIListBoxObject
> listBoxObject
= do_QueryInterface(boxObject
);
8679 if (listBoxObject
) {
8680 nsListBoxBodyFrame
* listBoxBodyFrame
= listBoxObject
->GetListBoxBody(PR_FALSE
);
8681 if (listBoxBodyFrame
) {
8682 if (aOperation
== CONTENT_REMOVED
) {
8683 // Except if we have an aChildFrame and its parent is not the right
8684 // thing, then we don't do this. Pseudo frames are so much fun....
8685 if (!aChildFrame
|| aChildFrame
->GetParent() == listBoxBodyFrame
) {
8686 listBoxBodyFrame
->OnContentRemoved(aPresContext
, aChildFrame
,
8691 listBoxBodyFrame
->OnContentInserted(aPresContext
, aChild
);
8698 PRInt32 namespaceID
;
8699 aDocument
->BindingManager()->ResolveTag(aContainer
, &namespaceID
);
8701 // XBL form control cruft... should that really be testing that the
8702 // namespace is XUL? Seems odd...
8703 if (aUseXBLForms
&& aContainer
->GetParent() &&
8704 namespaceID
== kNameSpaceID_XUL
&& ShouldIgnoreSelectChild(aContainer
))
8712 nsCSSFrameConstructor::ContentInserted(nsIContent
* aContainer
,
8714 PRInt32 aIndexInContainer
,
8715 nsILayoutHistoryState
* aFrameState
)
8717 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
8718 NS_PRECONDITION(mUpdateCount
!= 0,
8719 "Should be in an update while creating frames");
8721 // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and
8722 // the :empty pseudo-class?
8724 if (gNoisyContentUpdates
) {
8725 printf("nsCSSFrameConstructor::ContentInserted container=%p child=%p index=%d\n",
8726 static_cast<void*>(aContainer
),
8727 static_cast<void*>(aChild
),
8729 if (gReallyNoisyContentUpdates
) {
8730 (aContainer
? aContainer
: aChild
)->List(stdout
, 0);
8735 nsresult rv
= NS_OK
;
8738 if (NotifyListBoxBody(mPresShell
->GetPresContext(), aContainer
, aChild
,
8740 mDocument
, nsnull
, gUseXBLForms
, CONTENT_INSERTED
))
8744 // If we have a null parent, then this must be the document element
8747 nsIContent
*docElement
= mDocument
->GetRootContent();
8749 if (aChild
== docElement
) {
8750 NS_PRECONDITION(nsnull
== mInitialContainingBlock
, "initial containing block already created");
8752 if (!mDocElementContainingBlock
)
8753 return NS_OK
; // We get into this situation when an XBL binding is asynchronously
8754 // applied to the root tag (e.g., <window> in XUL). It's ok. We can
8755 // just bail here because the root will really be built later during
8758 // Create frames for the document element and its child elements
8759 nsIFrame
* docElementFrame
;
8760 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
, nsnull
,
8761 nsnull
, aFrameState
);
8762 rv
= ConstructDocElementFrame(state
,
8764 mDocElementContainingBlock
,
8767 if (NS_SUCCEEDED(rv
) && docElementFrame
) {
8768 if (mDocElementContainingBlock
->GetStateBits() & NS_FRAME_FIRST_REFLOW
) {
8769 // Set the initial child list for the parent and wait on the initial
8771 mDocElementContainingBlock
->SetInitialChildList(nsnull
,
8774 // Whoops, we've already received our initial reflow! Insert the doc.
8775 // element as a child so it reflows (note that containing block is
8776 // empty, so we can simply append).
8777 NS_ASSERTION(mDocElementContainingBlock
->GetFirstChild(nsnull
) == nsnull
,
8778 "Unexpected child of document element containing block");
8779 mDocElementContainingBlock
->AppendFrames(nsnull
, docElementFrame
);
8781 InvalidateCanvasIfNeeded(docElementFrame
);
8783 if (gReallyNoisyContentUpdates
) {
8784 nsIFrameDebug
* fdbg
= nsnull
;
8785 CallQueryInterface(docElementFrame
, &fdbg
);
8787 printf("nsCSSFrameConstructor::ContentInserted: resulting frame model:\n");
8788 fdbg
->List(stdout
, 0);
8795 // otherwise this is not a child of the root element, and we
8796 // won't let it have a frame.
8800 // Otherwise, we've got parent content. Find its frame.
8801 nsIFrame
* parentFrame
= GetFrameFor(aContainer
);
8803 return NS_OK
; // XXXwaterson will this break selects? (See ``Here
8804 // we have been notified...'' below.)
8806 // See if we have an XBL insertion point. If so, then that's our
8807 // real parent frame; if not, then the frame hasn't been built yet
8808 // and we just bail.
8809 nsIFrame
* insertionPoint
;
8810 GetInsertionPoint(parentFrame
, aChild
, &insertionPoint
);
8811 if (! insertionPoint
)
8812 return NS_OK
; // Don't build the frames.
8814 parentFrame
= insertionPoint
;
8816 // Find the frame that precedes the insertion point. Walk backwards
8817 // from the parent frame to get the parent content, because if an
8818 // XBL insertion point is involved, we'll need to use _that_ to find
8819 // the preceding frame.
8820 nsIContent
* container
= parentFrame
->GetContent();
8822 // XXX if the insertionPoint was different from the original
8823 // parentFrame, then aIndexInContainer is most likely completely
8824 // wrong. What we need to do here is remember the original index,
8825 // then as we insert, search the child list where we're about to put
8826 // the new frame to make sure that it appears after any siblings
8827 // with a lower index, and before any siblings with a higher
8828 // index. Same with FindNextSibling(), below.
8829 nsIFrame
* prevSibling
= (aIndexInContainer
>= 0)
8830 ? FindPreviousSibling(container
, aIndexInContainer
, aChild
)
8831 : FindPreviousAnonymousSibling(aContainer
, aChild
);
8833 PRBool isAppend
= PR_FALSE
;
8834 nsIFrame
* appendAfterFrame
; // This is only looked at when isAppend is true
8835 nsIFrame
* nextSibling
= nsnull
;
8837 // If there is no previous sibling, then find the frame that follows
8838 if (! prevSibling
) {
8839 nextSibling
= (aIndexInContainer
>= 0)
8840 ? FindNextSibling(container
, aIndexInContainer
, aChild
)
8841 : FindNextAnonymousSibling(aContainer
, aChild
);
8844 // Now, find the geometric parent so that we can handle
8845 // continuations properly. Use the prev sibling if we have it;
8846 // otherwise use the next sibling.
8848 parentFrame
= prevSibling
->GetParent()->GetContentInsertionFrame();
8850 else if (nextSibling
) {
8851 parentFrame
= nextSibling
->GetParent()->GetContentInsertionFrame();
8854 // No previous or next sibling, so treat this like an appended frame.
8856 // Deal with fieldsets
8857 parentFrame
= ::GetAdjustedParentFrame(parentFrame
, parentFrame
->GetType(),
8858 aContainer
, aIndexInContainer
);
8860 ::AdjustAppendParentForAfterContent(mPresShell
->GetPresContext(),
8861 aContainer
, parentFrame
,
8865 if (parentFrame
->GetType() == nsGkAtoms::frameSetFrame
&&
8866 IsSpecialFramesetChild(aChild
)) {
8867 // Just reframe the parent, since framesets are weird like that.
8868 return RecreateFramesForContent(parentFrame
->GetContent());
8871 // Don't construct kids of leaves
8872 if (parentFrame
->IsLeaf()) {
8877 if (parentFrame
->IsFrameOfType(nsIFrame::eMathML
))
8878 return RecreateFramesForContent(parentFrame
->GetContent());
8881 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
8882 GetAbsoluteContainingBlock(parentFrame
),
8883 GetFloatContainingBlock(parentFrame
),
8887 // Recover state for the containing block - we need to know if
8888 // it has :first-letter or :first-line style applied to it. The
8889 // reason we care is that the internal structure in these cases
8890 // is not the normal structure and requires custom updating
8892 nsIFrame
* containingBlock
= state
.mFloatedItems
.containingBlock
;
8893 PRBool haveFirstLetterStyle
= PR_FALSE
;
8894 PRBool haveFirstLineStyle
= PR_FALSE
;
8896 // In order to shave off some cycles, we only dig up the
8897 // containing block haveFirst* flags if the parent frame where
8898 // the insertion/append is occurring is an inline or block
8899 // container. For other types of containers this isn't relevant.
8900 const nsStyleDisplay
* parentDisplay
= parentFrame
->GetStyleDisplay();
8902 // Examine the parentFrame where the insertion is taking
8903 // place. If it's a certain kind of container then some special
8904 // processing is done.
8905 if ((NS_STYLE_DISPLAY_BLOCK
== parentDisplay
->mDisplay
) ||
8906 (NS_STYLE_DISPLAY_LIST_ITEM
== parentDisplay
->mDisplay
) ||
8907 (NS_STYLE_DISPLAY_INLINE
== parentDisplay
->mDisplay
) ||
8908 (NS_STYLE_DISPLAY_INLINE_BLOCK
== parentDisplay
->mDisplay
)) {
8909 // Recover the special style flags for the containing block
8910 if (containingBlock
) {
8911 haveFirstLetterStyle
= HasFirstLetterStyle(containingBlock
);
8912 haveFirstLineStyle
=
8913 ShouldHaveFirstLineStyle(containingBlock
->GetContent(),
8914 containingBlock
->GetStyleContext());
8917 if (haveFirstLetterStyle
) {
8918 // Get the correct parentFrame and prevSibling - if a
8919 // letter-frame is present, use its parent.
8920 if (parentFrame
->GetType() == nsGkAtoms::letterFrame
) {
8921 parentFrame
= parentFrame
->GetParent();
8922 container
= parentFrame
->GetContent();
8925 // Remove the old letter frames before doing the insertion
8926 RemoveLetterFrames(state
.mPresContext
, mPresShell
,
8927 state
.mFrameManager
,
8928 state
.mFloatedItems
.containingBlock
);
8930 // Removing the letterframes messes around with the frame tree, removing
8931 // and creating frames. We need to reget our prevsibling.
8932 // See XXX comment the first time we do this in this method....
8933 prevSibling
= (aIndexInContainer
>= 0)
8934 ? FindPreviousSibling(container
, aIndexInContainer
, aChild
)
8935 : FindPreviousAnonymousSibling(aContainer
, aChild
);
8937 // If there is no previous sibling, then find the frame that follows
8938 if (! prevSibling
) {
8939 nextSibling
= (aIndexInContainer
>= 0)
8940 ? FindNextSibling(container
, aIndexInContainer
, aChild
)
8941 : FindNextAnonymousSibling(aContainer
, aChild
);
8947 // We're inserting the new frame as the first child. See if the
8948 // parent has a :before pseudo-element
8949 nsIFrame
* firstChild
= parentFrame
->GetFirstChild(nsnull
);
8952 nsLayoutUtils::IsGeneratedContentFor(aContainer
, firstChild
,
8953 nsCSSPseudoElements::before
)) {
8954 // Insert the new frames after the last continuation of the :before
8955 prevSibling
= firstChild
->GetTailContinuation();
8956 parentFrame
= prevSibling
->GetParent();
8957 // We perhaps could leave this true and take the AppendFrames path
8958 // below, but we'd have to update appendAfterFrame and it seems safer
8959 // to force all insert-after-:before cases to take these to take the
8960 // InsertFrames path
8961 isAppend
= PR_FALSE
;
8965 // if the container is a table and a caption will be appended, it needs to be
8966 // put in the outer table frame's additional child list.
8968 nsFrameItems frameItems
, captionItems
;
8970 ConstructFrame(state
, aChild
, parentFrame
, frameItems
);
8971 if (frameItems
.childList
) {
8972 InvalidateCanvasIfNeeded(frameItems
.childList
);
8974 if (nsGkAtoms::tableCaptionFrame
== frameItems
.childList
->GetType()) {
8975 NS_ASSERTION(frameItems
.childList
== frameItems
.lastChild
,
8976 "adding a non caption frame to the caption childlist?");
8977 captionItems
.AddChild(frameItems
.childList
);
8978 frameItems
= nsFrameItems();
8982 // process the current pseudo frame state
8983 if (!state
.mPseudoFrames
.IsEmpty())
8984 ProcessPseudoFrames(state
, frameItems
);
8986 // If the parent of our current prevSibling is different from the frame we'll
8987 // actually use as the parent, then the calculated insertion point is now
8988 // invalid and as it is unknown where to insert correctly we append instead
8990 if (prevSibling
&& frameItems
.childList
&&
8991 frameItems
.childList
->GetParent() != prevSibling
->GetParent()) {
8992 prevSibling
= nsnull
;
8995 ::AdjustAppendParentForAfterContent(mPresShell
->GetPresContext(),
8997 frameItems
.childList
->GetParent(),
9001 // Perform special check for diddling around with the frames in
9002 // a special inline frame.
9004 // If we're appending before :after content, then we're not really
9005 // appending, so let WipeContainingBlock know that.
9006 if (WipeContainingBlock(state
, containingBlock
, parentFrame
, frameItems
,
9007 isAppend
&& !appendAfterFrame
, prevSibling
))
9010 if (haveFirstLineStyle
&& parentFrame
== containingBlock
) {
9011 // It's possible that the new frame goes into a first-line
9012 // frame. Look at it and see...
9014 // Use append logic when appending
9015 AppendFirstLineFrames(state
, containingBlock
->GetContent(),
9016 containingBlock
, frameItems
);
9019 // Use more complicated insert logic when inserting
9020 InsertFirstLineFrames(state
, aContainer
, containingBlock
, &parentFrame
,
9021 prevSibling
, frameItems
);
9025 nsIFrame
* const newFrame
= frameItems
.childList
;
9026 if (NS_SUCCEEDED(rv
) && newFrame
) {
9027 NS_ASSERTION(!captionItems
.childList
, "leaking caption frames");
9028 // Notify the parent frame
9030 AppendFrames(state
, aContainer
, parentFrame
, frameItems
,
9033 state
.mFrameManager
->InsertFrames(parentFrame
,
9034 nsnull
, prevSibling
, newFrame
);
9038 // we might have a caption treat it here
9039 nsIFrame
* newCaptionFrame
= captionItems
.childList
;
9040 if (NS_SUCCEEDED(rv
) && newCaptionFrame
) {
9041 nsIFrame
* outerTableFrame
;
9042 if (GetCaptionAdjustedParent(parentFrame
, newCaptionFrame
, &outerTableFrame
)) {
9043 // If the parent of our current prevSibling is different from the frame
9044 // we'll actually use as the parent, then the calculated insertion
9045 // point is now invalid (bug 341382).
9046 if (prevSibling
&& prevSibling
->GetParent() != outerTableFrame
) {
9047 prevSibling
= nsnull
;
9049 // If the parent is not a outer table frame we will try to add frames
9050 // to a named child list that the parent does not honour and the frames
9052 NS_ASSERTION(nsGkAtoms::tableOuterFrame
== outerTableFrame
->GetType(),
9053 "Pseudo frame construction failure, "
9054 "a caption can be only a child of a outer table frame");
9056 state
.mFrameManager
->AppendFrames(outerTableFrame
,
9057 nsGkAtoms::captionList
,
9061 state
.mFrameManager
->InsertFrames(outerTableFrame
,
9062 nsGkAtoms::captionList
,
9063 prevSibling
, newCaptionFrame
);
9069 if (haveFirstLetterStyle
) {
9070 // Recover the letter frames for the containing block when
9071 // it has first-letter style.
9072 RecoverLetterFrames(state
, state
.mFloatedItems
.containingBlock
);
9076 if (gReallyNoisyContentUpdates
&& parentFrame
) {
9077 nsIFrameDebug
* fdbg
= nsnull
;
9078 CallQueryInterface(parentFrame
, &fdbg
);
9080 printf("nsCSSFrameConstructor::ContentInserted: resulting frame model:\n");
9081 fdbg
->List(stdout
, 0);
9090 nsCSSFrameConstructor::ReinsertContent(nsIContent
* aContainer
,
9093 PRInt32 ix
= aContainer
->IndexOf(aChild
);
9094 // XXX For now, do a brute force remove and insert.
9095 // XXXbz this probably doesn't work so well with anonymous content
9096 // XXXbz doesn't this need to do the state-saving stuff that
9097 // RecreateFramesForContent does?
9098 PRBool didReconstruct
;
9099 nsresult res
= ContentRemoved(aContainer
, aChild
, ix
, &didReconstruct
);
9101 if (NS_SUCCEEDED(res
) && !didReconstruct
) {
9102 // If ContentRemoved just reconstructed everything, there is no need to
9103 // reinsert the content here
9104 res
= ContentInserted(aContainer
, aChild
, ix
, nsnull
);
9111 DoDeletingFrameSubtree(nsFrameManager
* aFrameManager
,
9112 nsVoidArray
& aDestroyQueue
,
9113 nsIFrame
* aRemovedFrame
,
9117 DoDeletingOverflowContainers(nsFrameManager
* aFrameManager
,
9118 nsVoidArray
& aDestroyQueue
,
9119 nsIFrame
* aRemovedFrame
,
9122 // The invariant that "continuing frames should be found as part of the
9123 // walk over the top-most frame's continuing frames" does not hold for
9124 // out-of-flow overflow containers, so we need to walk them too.
9125 // Note that DoDeletingFrameSubtree() skips the child lists where
9126 // overflow containers live so we won't process them twice.
9127 const PRBool orphanSubtree
= aRemovedFrame
== aFrame
;
9128 for (nsIFrame
* next
= aFrame
->GetNextContinuation();
9129 next
&& (next
->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER
);
9130 next
= next
->GetNextContinuation()) {
9131 DoDeletingFrameSubtree(aFrameManager
, aDestroyQueue
,
9132 orphanSubtree
? next
: aRemovedFrame
,
9138 * Called when a frame subtree is about to be deleted. Two important
9141 * 1. For each frame in the subtree, we remove the mapping from the
9142 * content object to its frame
9144 * 2. For child frames that have been moved out of the flow, we enqueue
9145 * the out-of-flow frame for deletion *if* the out-of-flow frame's
9146 * geometric parent is not in |aRemovedFrame|'s hierarchy (e.g., an
9147 * absolutely positioned element that has been promoted to be a direct
9148 * descendant of an area frame).
9150 * Note: this function should only be called by DeletingFrameSubtree()
9152 * @param aRemovedFrame this is the frame that was removed from the
9153 * content model. As we recurse we need to remember this so we
9154 * can check if out-of-flow frames are a descendant of the frame
9156 * @param aFrame the local subtree that is being deleted. This is initially
9157 * the same as aRemovedFrame, but as we recurse down the tree
9161 DoDeletingFrameSubtree(nsFrameManager
* aFrameManager
,
9162 nsVoidArray
& aDestroyQueue
,
9163 nsIFrame
* aRemovedFrame
,
9167 #define RECURSE(top, child) \
9168 DoDeletingFrameSubtree(aFrameManager, aDestroyQueue, (top), (child)); \
9169 DoDeletingOverflowContainers(aFrameManager, aDestroyQueue, (top), (child));
9171 // Remove the mapping from the content object to its frame.
9172 nsIContent
* content
= aFrame
->GetContent();
9174 aFrameManager
->RemoveAsPrimaryFrame(content
, aFrame
);
9175 aFrameManager
->ClearAllUndisplayedContentIn(content
);
9178 nsIAtom
* childListName
= nsnull
;
9179 PRInt32 childListIndex
= 0;
9182 // Walk aFrame's normal flow child frames looking for placeholder frames.
9183 nsIFrame
* childFrame
= aFrame
->GetFirstChild(childListName
);
9184 for (; childFrame
; childFrame
= childFrame
->GetNextSibling()) {
9185 NS_ASSERTION(!(childFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
),
9186 "out-of-flow on wrong child list");
9187 if (NS_LIKELY(nsGkAtoms::placeholderFrame
!= childFrame
->GetType())) {
9188 RECURSE(aRemovedFrame
, childFrame
);
9190 nsIFrame
* outOfFlowFrame
=
9191 nsPlaceholderFrame::GetRealFrameForPlaceholder(childFrame
);
9193 // Remove the mapping from the out-of-flow frame to its placeholder.
9194 aFrameManager
->UnregisterPlaceholderFrame((nsPlaceholderFrame
*)childFrame
);
9195 // Don't SetOutOfFlowFrame(nsnull) here because the float cache depends
9196 // on it when the float is removed later on, see bug 348688 comment 6.
9198 // Queue the out-of-flow frame to be destroyed only if aRemovedFrame is _not_
9199 // one of its ancestor frames or if it is a popup frame.
9200 // If aRemovedFrame is an ancestor of the out-of-flow frame, then
9201 // the out-of-flow frame will be destroyed by aRemovedFrame.
9202 if (outOfFlowFrame
->GetStyleDisplay()->mDisplay
== NS_STYLE_DISPLAY_POPUP
||
9203 !nsLayoutUtils::IsProperAncestorFrame(aRemovedFrame
, outOfFlowFrame
)) {
9204 NS_ASSERTION(aDestroyQueue
.IndexOf(outOfFlowFrame
) == kNotFound
,
9205 "out-of-flow is already in the destroy queue");
9206 aDestroyQueue
.AppendElement(outOfFlowFrame
);
9207 // Recurse into the out-of-flow, it is now the aRemovedFrame.
9208 RECURSE(outOfFlowFrame
, outOfFlowFrame
);
9211 // Also recurse into the out-of-flow when it's a descendant of aRemovedFrame
9212 // since we don't walk those lists, see |childListName| increment below.
9213 RECURSE(aRemovedFrame
, outOfFlowFrame
);
9218 // Move to next child list but skip lists with frames we should have
9219 // a placeholder for or that contains only next-in-flow overflow containers
9220 // (which we walk explicitly above).
9222 childListName
= aFrame
->GetAdditionalChildListName(childListIndex
++);
9223 } while (IsOutOfFlowList(childListName
) ||
9224 childListName
== nsGkAtoms::overflowContainersList
||
9225 childListName
== nsGkAtoms::excessOverflowContainersList
);
9226 } while (childListName
);
9230 * Called when a frame is about to be deleted. Calls DoDeletingFrameSubtree()
9231 * for aFrame and each of its continuing frames
9234 DeletingFrameSubtree(nsFrameManager
* aFrameManager
,
9237 NS_ENSURE_TRUE(aFrame
, NS_OK
); // XXXldb Remove this sometime in the future.
9239 // If there's no frame manager it's probably because the pres shell is
9241 if (NS_UNLIKELY(!aFrameManager
)) {
9245 nsAutoVoidArray destroyQueue
;
9247 // If it's a "special" block-in-inline frame, then we can't really deal.
9248 // That really shouldn't be happening.
9249 NS_ASSERTION(!IsFrameSpecial(aFrame
),
9250 "DeletingFrameSubtree on a special frame. Prepare to crash.");
9253 DoDeletingFrameSubtree(aFrameManager
, destroyQueue
, aFrame
, aFrame
);
9255 // If it's split, then get the continuing frame. Note that we only do
9256 // this for the top-most frame being deleted. Don't do it if we're
9257 // recursing over a subtree, because those continuing frames should be
9258 // found as part of the walk over the top-most frame's continuing frames.
9259 // Walking them again will make this an N^2/2 algorithm.
9260 // The above is true for normal child next-in-flows but not overflow
9261 // containers which we do walk because they *can* escape the subtree
9262 // we're deleting. We skip [excess]overflowContainersList where
9263 // they live to avoid processing them more than once.
9264 aFrame
= aFrame
->GetNextContinuation();
9267 // Now destroy any out-of-flow frames that have been enqueued for
9269 for (PRInt32 i
= destroyQueue
.Count() - 1; i
>= 0; --i
) {
9270 nsIFrame
* outOfFlowFrame
= static_cast<nsIFrame
*>(destroyQueue
[i
]);
9272 // Ask the out-of-flow's parent to delete the out-of-flow
9273 // frame from the right list.
9274 aFrameManager
->RemoveFrame(outOfFlowFrame
->GetParent(),
9275 GetChildListNameFor(outOfFlowFrame
),
9283 nsCSSFrameConstructor::RemoveMappingsForFrameSubtree(nsIFrame
* aRemovedFrame
)
9285 if (NS_UNLIKELY(mIsDestroyingFrameTree
)) {
9286 // The frame tree might not be in a consistent state after
9287 // WillDestroyFrameTree() has been called. Most likely we're destroying
9288 // the pres shell which means the frame manager takes care of clearing all
9289 // mappings so there is no need to walk the frame tree here, bug 372576.
9293 // Save the frame tree's state before deleting it
9294 CaptureStateFor(aRemovedFrame
, mTempFrameTreeState
);
9296 return ::DeletingFrameSubtree(mPresShell
->FrameManager(), aRemovedFrame
);
9299 static void UnregisterPlaceholderChain(nsFrameManager
* frameManager
,
9300 nsPlaceholderFrame
* placeholderFrame
)
9302 // Remove the mapping from the frame to its placeholder
9303 nsPlaceholderFrame
* curFrame
= placeholderFrame
;
9305 frameManager
->UnregisterPlaceholderFrame(curFrame
);
9306 curFrame
->SetOutOfFlowFrame(nsnull
);
9307 curFrame
= static_cast<nsPlaceholderFrame
*>(curFrame
->GetNextContinuation());
9312 nsCSSFrameConstructor::ContentRemoved(nsIContent
* aContainer
,
9314 PRInt32 aIndexInContainer
,
9315 PRBool
* aDidReconstruct
)
9317 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
9318 NS_PRECONDITION(mUpdateCount
!= 0,
9319 "Should be in an update while destroying frames");
9321 *aDidReconstruct
= PR_FALSE
;
9323 // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and
9324 // the :empty pseudo-class?
9327 if (gNoisyContentUpdates
) {
9328 printf("nsCSSFrameConstructor::ContentRemoved container=%p child=%p index=%d\n",
9329 static_cast<void*>(aContainer
),
9330 static_cast<void*>(aChild
),
9332 if (gReallyNoisyContentUpdates
) {
9333 aContainer
->List(stdout
, 0);
9338 nsFrameManager
*frameManager
= mPresShell
->FrameManager();
9339 nsPresContext
*presContext
= mPresShell
->GetPresContext();
9340 nsresult rv
= NS_OK
;
9342 // Find the child frame that maps the content
9343 nsIFrame
* childFrame
=
9344 mPresShell
->FrameManager()->GetPrimaryFrameFor(aChild
, aIndexInContainer
);
9346 if (!childFrame
|| childFrame
->GetContent() != aChild
) {
9347 // XXXbz the GetContent() != aChild check is needed due to bug 135040.
9348 // Remove it once that's fixed.
9349 frameManager
->ClearUndisplayedContentIn(aChild
, aContainer
);
9353 if (NotifyListBoxBody(presContext
, aContainer
, aChild
, aIndexInContainer
,
9354 mDocument
, childFrame
, gUseXBLForms
, CONTENT_REMOVED
))
9360 InvalidateCanvasIfNeeded(childFrame
);
9362 // If the frame we are manipulating is a special frame then do
9363 // something different instead of just inserting newly created
9365 // NOTE: if we are in ReinsertContent,
9366 // then do not reframe as we are already doing just that!
9367 if (MaybeRecreateContainerForIBSplitterFrame(childFrame
, &rv
)) {
9368 *aDidReconstruct
= PR_TRUE
;
9372 // Get the childFrame's parent frame
9373 nsIFrame
* parentFrame
= childFrame
->GetParent();
9374 nsIAtom
* parentType
= parentFrame
->GetType();
9376 if (parentType
== nsGkAtoms::frameSetFrame
&&
9377 IsSpecialFramesetChild(aChild
)) {
9378 // Just reframe the parent, since framesets are weird like that.
9379 *aDidReconstruct
= PR_TRUE
;
9380 return RecreateFramesForContent(parentFrame
->GetContent());
9384 // If we're a child of MathML, then we should reframe the MathML content.
9385 // If we're non-MathML, then we would be wrapped in a block so we need to
9386 // check our grandparent in that case.
9387 nsIFrame
* possibleMathMLAncestor
= parentType
== nsGkAtoms::blockFrame
?
9388 parentFrame
->GetParent() : parentFrame
;
9389 if (possibleMathMLAncestor
->IsFrameOfType(nsIFrame::eMathML
)) {
9390 *aDidReconstruct
= PR_TRUE
;
9391 return RecreateFramesForContent(possibleMathMLAncestor
->GetContent());
9395 // Undo XUL wrapping if it's no longer needed.
9396 // (If we're in the XUL block-wrapping situation, parentFrame is the
9398 nsIFrame
* grandparentFrame
= parentFrame
->GetParent();
9399 if (grandparentFrame
&& grandparentFrame
->IsBoxFrame() &&
9400 (grandparentFrame
->GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK
) &&
9401 // check if this frame is the only one needing wrapping
9402 aChild
== AnyKidsNeedBlockParent(parentFrame
->GetFirstChild(nsnull
)) &&
9403 !AnyKidsNeedBlockParent(childFrame
->GetNextSibling())) {
9404 *aDidReconstruct
= PR_TRUE
;
9405 return RecreateFramesForContent(grandparentFrame
->GetContent());
9408 // Examine the containing-block for the removed content and see if
9409 // :first-letter style applies.
9410 nsIFrame
* containingBlock
= GetFloatContainingBlock(parentFrame
);
9411 PRBool haveFLS
= containingBlock
&& HasFirstLetterStyle(containingBlock
);
9413 // Trap out to special routine that handles adjusting a blocks
9414 // frame tree when first-letter style is present.
9415 #ifdef NOISY_FIRST_LETTER
9416 printf("ContentRemoved: containingBlock=");
9417 nsFrame::ListTag(stdout
, containingBlock
);
9418 printf(" parentFrame=");
9419 nsFrame::ListTag(stdout
, parentFrame
);
9420 printf(" childFrame=");
9421 nsFrame::ListTag(stdout
, childFrame
);
9425 // First update the containing blocks structure by removing the
9426 // existing letter frames. This makes the subsequent logic
9428 RemoveLetterFrames(presContext
, mPresShell
, frameManager
,
9431 // Recover childFrame and parentFrame
9432 childFrame
= mPresShell
->GetPrimaryFrameFor(aChild
);
9433 if (!childFrame
|| childFrame
->GetContent() != aChild
) {
9434 // XXXbz the GetContent() != aChild check is needed due to bug 135040.
9435 // Remove it once that's fixed.
9436 frameManager
->ClearUndisplayedContentIn(aChild
, aContainer
);
9439 parentFrame
= childFrame
->GetParent();
9441 #ifdef NOISY_FIRST_LETTER
9442 printf(" ==> revised parentFrame=");
9443 nsFrame::ListTag(stdout
, parentFrame
);
9444 printf(" childFrame=");
9445 nsFrame::ListTag(stdout
, childFrame
);
9451 if (gReallyNoisyContentUpdates
) {
9452 printf("nsCSSFrameConstructor::ContentRemoved: childFrame=");
9453 nsFrame::ListTag(stdout
, childFrame
);
9456 nsIFrameDebug
* fdbg
= nsnull
;
9457 CallQueryInterface(parentFrame
, &fdbg
);
9459 fdbg
->List(stdout
, 0);
9463 // Walk the frame subtree deleting any out-of-flow frames, and
9464 // remove the mapping from content objects to frames
9465 ::DeletingFrameSubtree(frameManager
, childFrame
);
9467 // See if the child frame is an out-of-flow
9468 if (childFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
9469 nsPlaceholderFrame
* placeholderFrame
=
9470 frameManager
->GetPlaceholderFrameFor(childFrame
);
9471 NS_ASSERTION(placeholderFrame
, "No placeholder for out-of-flow?");
9473 UnregisterPlaceholderChain(frameManager
, placeholderFrame
);
9475 // Now we remove the out-of-flow frame
9476 // XXX has to be done first for now: for floats, the block's line list
9477 // contains an array of pointers to the placeholder - we have to
9478 // remove the float first (which gets rid of the lines
9479 // reference to the placeholder and float) and then remove the
9481 rv
= frameManager
->RemoveFrame(parentFrame
,
9482 GetChildListNameFor(childFrame
),
9485 // Remove the placeholder frame first (XXX second for now) (so
9486 // that it doesn't retain a dangling pointer to memory)
9487 nsIFrame
* placeholderParent
= placeholderFrame
->GetParent();
9488 ::DeletingFrameSubtree(frameManager
, placeholderFrame
);
9489 rv
|= frameManager
->RemoveFrame(placeholderParent
,
9490 nsnull
, placeholderFrame
);
9492 // Notify the parent frame that it should delete the frame
9493 // check for a table caption which goes on an additional child list with a different parent
9494 nsIFrame
* outerTableFrame
;
9495 if (GetCaptionAdjustedParent(parentFrame
, childFrame
, &outerTableFrame
)) {
9496 rv
= frameManager
->RemoveFrame(outerTableFrame
,
9497 nsGkAtoms::captionList
,
9501 rv
= frameManager
->RemoveFrame(parentFrame
, nsnull
, childFrame
);
9505 if (mInitialContainingBlock
== childFrame
) {
9506 mInitialContainingBlock
= nsnull
;
9507 mRootElementStyleFrame
= nsnull
;
9510 if (haveFLS
&& mInitialContainingBlock
) {
9511 NS_ASSERTION(containingBlock
== GetFloatContainingBlock(parentFrame
),
9512 "What happened here?");
9513 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
9514 GetAbsoluteContainingBlock(parentFrame
),
9516 RecoverLetterFrames(state
, containingBlock
);
9520 if (gReallyNoisyContentUpdates
&& parentFrame
) {
9521 nsIFrameDebug
* fdbg
= nsnull
;
9522 CallQueryInterface(parentFrame
, &fdbg
);
9524 printf("nsCSSFrameConstructor::ContentRemoved: resulting frame model:\n");
9525 fdbg
->List(stdout
, 0);
9535 // To ensure that the functions below are only called within
9536 // |ApplyRenderingChangeToTree|.
9537 static PRBool gInApplyRenderingChangeToTree
= PR_FALSE
;
9541 DoApplyRenderingChangeToTree(nsIFrame
* aFrame
,
9542 nsIViewManager
* aViewManager
,
9543 nsFrameManager
* aFrameManager
,
9544 nsChangeHint aChange
);
9547 * @param aBoundsRect returns the bounds enclosing the areas covered by aFrame and its childre
9548 * This rect is relative to aFrame's parent
9551 UpdateViewsForTree(nsIFrame
* aFrame
, nsIViewManager
* aViewManager
,
9552 nsFrameManager
* aFrameManager
,
9553 nsChangeHint aChange
)
9555 NS_PRECONDITION(gInApplyRenderingChangeToTree
,
9556 "should only be called within ApplyRenderingChangeToTree");
9558 nsIView
* view
= aFrame
->GetView();
9560 if (aChange
& nsChangeHint_SyncFrameView
) {
9561 nsContainerFrame::SyncFrameViewProperties(aFrame
->PresContext(),
9562 aFrame
, nsnull
, view
);
9566 // now do children of frame
9567 PRInt32 listIndex
= 0;
9568 nsIAtom
* childList
= nsnull
;
9571 nsIFrame
* child
= aFrame
->GetFirstChild(childList
);
9573 if (!(child
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)
9574 || (child
->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER
)) {
9575 // only do frames that don't have placeholders
9576 if (nsGkAtoms::placeholderFrame
== child
->GetType()) { // placeholder
9577 // get out of flow frame and start over there
9578 nsIFrame
* outOfFlowFrame
=
9579 nsPlaceholderFrame::GetRealFrameForPlaceholder(child
);
9581 DoApplyRenderingChangeToTree(outOfFlowFrame
, aViewManager
,
9582 aFrameManager
, aChange
);
9584 else { // regular frame
9585 UpdateViewsForTree(child
, aViewManager
, aFrameManager
, aChange
);
9588 child
= child
->GetNextSibling();
9590 childList
= aFrame
->GetAdditionalChildListName(listIndex
++);
9591 } while (childList
);
9595 DoApplyRenderingChangeToTree(nsIFrame
* aFrame
,
9596 nsIViewManager
* aViewManager
,
9597 nsFrameManager
* aFrameManager
,
9598 nsChangeHint aChange
)
9600 NS_PRECONDITION(gInApplyRenderingChangeToTree
,
9601 "should only be called within ApplyRenderingChangeToTree");
9603 for ( ; aFrame
; aFrame
= nsLayoutUtils::GetNextContinuationOrSpecialSibling(aFrame
)) {
9604 // Get view if this frame has one and trigger an update. If the
9605 // frame doesn't have a view, find the nearest containing view
9606 // (adjusting r's coordinate system to reflect the nesting) and
9608 UpdateViewsForTree(aFrame
, aViewManager
, aFrameManager
, aChange
);
9610 // if frame has view, will already be invalidated
9611 if ((aChange
& nsChangeHint_RepaintFrame
) &&
9612 !aFrame
->IsFrameOfType(nsIFrame::eSVG
)) {
9613 aFrame
->Invalidate(aFrame
->GetOverflowRect());
9619 ApplyRenderingChangeToTree(nsPresContext
* aPresContext
,
9621 nsChangeHint aChange
)
9623 nsIPresShell
*shell
= aPresContext
->PresShell();
9624 PRBool isPaintingSuppressed
= PR_FALSE
;
9625 shell
->IsPaintingSuppressed(&isPaintingSuppressed
);
9626 if (isPaintingSuppressed
) {
9627 // Don't allow synchronous rendering changes when painting is turned off.
9628 aChange
= NS_SubtractHint(aChange
, nsChangeHint_RepaintFrame
);
9634 // If the frame's background is propagated to an ancestor, walk up to
9636 const nsStyleBackground
*bg
;
9638 while (!nsCSSRendering::FindBackground(aPresContext
, aFrame
,
9640 aFrame
= aFrame
->GetParent();
9641 NS_ASSERTION(aFrame
, "root frame must paint");
9644 nsIViewManager
* viewManager
= aPresContext
->GetViewManager();
9646 // Trigger rendering updates by damaging this frame and any
9647 // continuations of this frame.
9649 // XXX this needs to detect the need for a view due to an opacity change and deal with it...
9651 nsIViewManager::UpdateViewBatch
batch(viewManager
);
9654 gInApplyRenderingChangeToTree
= PR_TRUE
;
9656 DoApplyRenderingChangeToTree(aFrame
, viewManager
, shell
->FrameManager(),
9659 gInApplyRenderingChangeToTree
= PR_FALSE
;
9662 batch
.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC
);
9666 * This method invalidates the canvas when frames are removed or added for a
9667 * node that might have its background propagated to the canvas, i.e., a
9668 * document root node or an HTML BODY which is a child of the root node.
9670 * @param aFrame a frame for a content node about to be removed or a frme that
9671 * was just created for a content node that was inserted.
9674 InvalidateCanvasIfNeeded(nsIFrame
* aFrame
)
9676 NS_ASSERTION(aFrame
, "Must have frame!");
9678 // Note that for both in ContentRemoved and ContentInserted the content node
9679 // will still have the right parent pointer, so looking at that is ok.
9681 nsIContent
* node
= aFrame
->GetContent();
9682 nsIContent
* parent
= node
->GetParent();
9684 // Has a parent; might not be what we want
9685 nsIContent
* grandParent
= parent
->GetParent();
9687 // Has a grandparent, so not what we want
9691 // Check whether it's an HTML body
9692 if (node
->Tag() != nsGkAtoms::body
||
9693 !node
->IsNodeOfType(nsINode::eHTML
)) {
9698 // At this point the node has no parent or it's an HTML <body> child of the
9699 // root. We might not need to invalidate in this case (eg we might be in
9700 // XHTML or something), but chances are we want to. Play it safe. Find the
9701 // frame to invalidate and do it.
9702 nsIFrame
*ancestor
= aFrame
;
9703 const nsStyleBackground
*bg
;
9705 nsPresContext
* presContext
= aFrame
->PresContext();
9706 while (!nsCSSRendering::FindBackground(presContext
, ancestor
,
9708 ancestor
= ancestor
->GetParent();
9709 NS_ASSERTION(ancestor
, "canvas must paint");
9712 if (ancestor
->GetType() == nsGkAtoms::canvasFrame
) {
9713 // The canvas frame's dimensions are not meaningful; invalidate the
9714 // viewport instead.
9715 ancestor
= ancestor
->GetParent();
9718 if (ancestor
!= aFrame
) {
9719 // Wrap this in a DEFERRED view update batch so we don't try to
9720 // flush out layout here
9722 nsIViewManager::UpdateViewBatch
batch(presContext
->GetViewManager());
9723 ApplyRenderingChangeToTree(presContext
, ancestor
,
9724 nsChangeHint_RepaintFrame
);
9725 batch
.EndUpdateViewBatch(NS_VMREFRESH_DEFERRED
);
9730 nsCSSFrameConstructor::StyleChangeReflow(nsIFrame
* aFrame
)
9732 // If the frame hasn't even received an initial reflow, then don't
9733 // send it a style-change reflow!
9734 if (aFrame
->GetStateBits() & NS_FRAME_FIRST_REFLOW
)
9738 if (gNoisyContentUpdates
) {
9739 printf("nsCSSFrameConstructor::StyleChangeReflow: aFrame=");
9740 nsFrame::ListTag(stdout
, aFrame
);
9745 // If the frame is part of a split block-in-inline hierarchy, then
9746 // target the style-change reflow at the first ``normal'' ancestor
9747 // so we're sure that the style change will propagate to any
9748 // anonymously created siblings.
9749 if (IsFrameSpecial(aFrame
))
9750 aFrame
= GetIBContainingBlockFor(aFrame
);
9753 mPresShell
->FrameNeedsReflow(aFrame
, nsIPresShell::eStyleChange
,
9755 aFrame
= aFrame
->GetNextContinuation();
9762 nsCSSFrameConstructor::CharacterDataChanged(nsIContent
* aContent
,
9765 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
9766 nsresult rv
= NS_OK
;
9768 // Find the child frame
9769 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
9771 // Notify the first frame that maps the content. It will generate a reflow
9774 // It's possible the frame whose content changed isn't inserted into the
9775 // frame hierarchy yet, or that there is no frame that maps the content
9776 if (nsnull
!= frame
) {
9778 NS_FRAME_LOG(NS_FRAME_TRACE_CALLS
,
9779 ("nsCSSFrameConstructor::CharacterDataChanged: content=%p[%s] subcontent=%p frame=%p",
9780 aContent
, ContentTag(aContent
, 0),
9781 aSubContent
, frame
));
9784 // Special check for text content that is a child of a letter frame. If
9785 // this happens, we should remove the letter frame, do whatever we're
9786 // planning to do with this notification, then put the letter frame back.
9787 // Note that this is basically what ReinsertContent ends up doing; the
9788 // reason we dont' want to call that here is that our text content could be
9789 // native anonymous, in which case ReinsertContent would completely barf on
9790 // it. And reinserting the non-anonymous ancestor would just lead us to
9791 // come back into this notification (e.g. if quotes or counters are
9792 // involved), leading to a loop.
9793 nsIFrame
* block
= GetFloatContainingBlock(frame
);
9794 PRBool haveFirstLetterStyle
= PR_FALSE
;
9796 // See if the block has first-letter style applied to it.
9797 haveFirstLetterStyle
= HasFirstLetterStyle(block
);
9798 if (haveFirstLetterStyle
) {
9799 RemoveLetterFrames(mPresShell
->GetPresContext(), mPresShell
,
9800 mPresShell
->FrameManager(), block
);
9801 // Reget |frame|, since we might have killed it.
9802 // Do we really need to call CharacterDataChanged in this case, though?
9803 frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
9804 NS_ASSERTION(frame
, "Should have frame here!");
9808 frame
->CharacterDataChanged(mPresShell
->GetPresContext(), aContent
,
9811 if (haveFirstLetterStyle
) {
9812 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
9813 GetAbsoluteContainingBlock(frame
),
9815 RecoverLetterFrames(state
, block
);
9823 nsCSSFrameConstructor::ProcessRestyledFrames(nsStyleChangeList
& aChangeList
)
9825 PRInt32 count
= aChangeList
.Count();
9829 // Make sure to not rebuild quote or counter lists while we're
9830 // processing restyles
9833 nsPropertyTable
*propTable
= mPresShell
->GetPresContext()->PropertyTable();
9835 // Mark frames so that we skip frames that die along the way, bug 123049.
9836 // A frame can be in the list multiple times with different hints. Further
9837 // optmization is possible if nsStyleChangeList::AppendChange could coalesce
9838 PRInt32 index
= count
;
9840 while (0 <= --index
) {
9841 const nsStyleChangeData
* changeData
;
9842 aChangeList
.ChangeAt(index
, &changeData
);
9843 if (changeData
->mFrame
) {
9844 propTable
->SetProperty(changeData
->mFrame
,
9845 nsGkAtoms::changeListProperty
,
9846 nsnull
, nsnull
, nsnull
);
9851 while (0 <= --index
) {
9853 nsIContent
* content
;
9855 aChangeList
.ChangeAt(index
, frame
, content
, hint
);
9856 if (frame
&& frame
->GetContent() != content
) {
9857 // XXXbz this is due to image maps messing with the primary frame map.
9858 // See bug 135040. Remove this block once that's fixed.
9860 if (!(hint
& nsChangeHint_ReconstructFrame
)) {
9865 // skip any frame that has been destroyed due to a ripple effect
9869 propTable
->GetProperty(frame
, nsGkAtoms::changeListProperty
, &res
);
9871 if (NS_PROPTABLE_PROP_NOT_THERE
== res
)
9875 if (hint
& nsChangeHint_ReconstructFrame
) {
9876 RecreateFramesForContent(content
);
9878 NS_ASSERTION(frame
, "This shouldn't happen");
9880 if (hint
& nsChangeHint_UpdateEffects
) {
9881 nsSVGEffects::UpdateEffects(frame
);
9884 if (hint
& nsChangeHint_ReflowFrame
) {
9885 StyleChangeReflow(frame
);
9887 if (hint
& (nsChangeHint_RepaintFrame
| nsChangeHint_SyncFrameView
)) {
9888 ApplyRenderingChangeToTree(mPresShell
->GetPresContext(), frame
, hint
);
9890 if (hint
& nsChangeHint_UpdateCursor
) {
9891 nsIViewManager
* viewMgr
= mPresShell
->GetViewManager();
9893 viewMgr
->SynthesizeMouseMove(PR_FALSE
);
9900 // cleanup references and verify the style tree. Note that the latter needs
9901 // to happen once we've processed the whole list, since until then the tree
9902 // is not in fact in a consistent state.
9904 while (0 <= --index
) {
9905 const nsStyleChangeData
* changeData
;
9906 aChangeList
.ChangeAt(index
, &changeData
);
9907 if (changeData
->mFrame
) {
9908 propTable
->DeleteProperty(changeData
->mFrame
,
9909 nsGkAtoms::changeListProperty
);
9913 // reget frame from content since it may have been regenerated...
9914 if (changeData
->mContent
) {
9915 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(changeData
->mContent
);
9917 mPresShell
->FrameManager()->DebugVerifyStyleTree(frame
);
9920 NS_WARNING("Unable to test style tree integrity -- no content node");
9925 aChangeList
.Clear();
9930 nsCSSFrameConstructor::RestyleElement(nsIContent
*aContent
,
9931 nsIFrame
*aPrimaryFrame
,
9932 nsChangeHint aMinHint
)
9934 NS_ASSERTION(aPrimaryFrame
== mPresShell
->GetPrimaryFrameFor(aContent
),
9935 "frame/content mismatch");
9936 if (aPrimaryFrame
&& aPrimaryFrame
->GetContent() != aContent
) {
9937 // XXXbz this is due to image maps messing with the primary frame mapping.
9938 // See bug 135040. We can remove this block once that's fixed.
9939 aPrimaryFrame
= nsnull
;
9941 NS_ASSERTION(!aPrimaryFrame
|| aPrimaryFrame
->GetContent() == aContent
,
9942 "frame/content mismatch");
9944 if (aMinHint
& nsChangeHint_ReconstructFrame
) {
9945 RecreateFramesForContent(aContent
);
9946 } else if (aPrimaryFrame
) {
9947 nsStyleChangeList changeList
;
9948 mPresShell
->FrameManager()->
9949 ComputeStyleChangeFor(aPrimaryFrame
, &changeList
, aMinHint
);
9950 ProcessRestyledFrames(changeList
);
9952 // no frames, reconstruct for content
9953 MaybeRecreateFramesForContent(aContent
);
9958 nsCSSFrameConstructor::RestyleLaterSiblings(nsIContent
*aContent
)
9960 nsIContent
*parent
= aContent
->GetParent();
9962 return; // root element has no later siblings
9964 for (PRInt32 index
= parent
->IndexOf(aContent
) + 1,
9965 index_end
= parent
->GetChildCount();
9966 index
!= index_end
; ++index
) {
9967 nsIContent
*child
= parent
->GetChildAt(index
);
9968 if (!child
->IsNodeOfType(nsINode::eELEMENT
))
9971 nsIFrame
* primaryFrame
= mPresShell
->GetPrimaryFrameFor(child
);
9972 RestyleElement(child
, primaryFrame
, NS_STYLE_HINT_NONE
);
9977 nsCSSFrameConstructor::ContentStatesChanged(nsIContent
* aContent1
,
9978 nsIContent
* aContent2
,
9981 DoContentStateChanged(aContent1
, aStateMask
);
9982 DoContentStateChanged(aContent2
, aStateMask
);
9987 nsCSSFrameConstructor::DoContentStateChanged(nsIContent
* aContent
,
9990 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
9991 nsPresContext
*presContext
= mPresShell
->GetPresContext();
9992 NS_ASSERTION(styleSet
, "couldn't get style set");
9995 nsChangeHint hint
= NS_STYLE_HINT_NONE
;
9996 // Any change to a content state that affects which frames we construct
9997 // must lead to a frame reconstruct here if we already have a frame.
9998 // Note that we never decide through non-CSS means to not create frames
9999 // based on content states, so if we already don't have a frame we don't
10000 // need to force a reframe -- if it's needed, the HasStateDependentStyle
10001 // call will handle things.
10002 nsIFrame
* primaryFrame
= mPresShell
->GetPrimaryFrameFor(aContent
);
10003 if (primaryFrame
) {
10004 // If it's generated content, ignore LOADING/etc state changes on it.
10005 if (!primaryFrame
->IsGeneratedContentFrame() &&
10006 (aStateMask
& (NS_EVENT_STATE_BROKEN
| NS_EVENT_STATE_USERDISABLED
|
10007 NS_EVENT_STATE_SUPPRESSED
| NS_EVENT_STATE_LOADING
))) {
10008 hint
= nsChangeHint_ReconstructFrame
;
10010 PRUint8 app
= primaryFrame
->GetStyleDisplay()->mAppearance
;
10012 nsITheme
*theme
= presContext
->GetTheme();
10013 if (theme
&& theme
->ThemeSupportsWidget(presContext
,
10014 primaryFrame
, app
)) {
10015 PRBool repaint
= PR_FALSE
;
10016 theme
->WidgetStateChanged(primaryFrame
, app
, nsnull
, &repaint
);
10018 NS_UpdateHint(hint
, nsChangeHint_RepaintFrame
);
10025 nsReStyleHint rshint
=
10026 styleSet
->HasStateDependentStyle(presContext
, aContent
, aStateMask
);
10028 if ((aStateMask
& NS_EVENT_STATE_HOVER
) && rshint
!= 0) {
10029 ++mHoverGeneration
;
10032 PostRestyleEvent(aContent
, rshint
, hint
);
10037 nsCSSFrameConstructor::AttributeChanged(nsIContent
* aContent
,
10038 PRInt32 aNameSpaceID
,
10039 nsIAtom
* aAttribute
,
10041 PRUint32 aStateMask
)
10043 nsresult result
= NS_OK
;
10045 // Hold onto the PresShell to prevent ourselves from being destroyed.
10046 // XXXbz how, exactly, would this attribute change cause us to be
10047 // destroyed from inside this function?
10048 nsCOMPtr
<nsIPresShell
> shell
= mPresShell
;
10050 // Get the frame associated with the content which is the highest in the frame tree
10051 nsIFrame
* primaryFrame
= shell
->GetPrimaryFrameFor(aContent
);
10054 NS_FRAME_LOG(NS_FRAME_TRACE_CALLS
,
10055 ("HTMLStyleSheet::AttributeChanged: content=%p[%s] frame=%p",
10056 aContent
, ContentTag(aContent
, 0), frame
));
10059 // the style tag has its own interpretation based on aHint
10060 nsChangeHint hint
= aContent
->GetAttributeChangeHint(aAttribute
, aModType
);
10062 PRBool reframe
= (hint
& nsChangeHint_ReconstructFrame
) != 0;
10065 // The following listbox widget trap prevents offscreen listbox widget
10066 // content from being removed and re-inserted (which is what would
10067 // happen otherwise).
10068 if (!primaryFrame
&& !reframe
) {
10069 PRInt32 namespaceID
;
10071 mDocument
->BindingManager()->ResolveTag(aContent
, &namespaceID
);
10073 if (namespaceID
== kNameSpaceID_XUL
&&
10074 (tag
== nsGkAtoms::listitem
||
10075 tag
== nsGkAtoms::listcell
))
10079 if (aAttribute
== nsGkAtoms::tooltiptext
||
10080 aAttribute
== nsGkAtoms::tooltip
)
10082 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(mPresShell
);
10084 if (aModType
== nsIDOMMutationEvent::REMOVAL
)
10085 rootBox
->RemoveTooltipSupport(aContent
);
10086 if (aModType
== nsIDOMMutationEvent::ADDITION
)
10087 rootBox
->AddTooltipSupport(aContent
);
10093 if (primaryFrame
) {
10094 // See if we have appearance information for a theme.
10095 const nsStyleDisplay
* disp
= primaryFrame
->GetStyleDisplay();
10096 if (disp
->mAppearance
) {
10097 nsPresContext
* presContext
= mPresShell
->GetPresContext();
10098 nsITheme
*theme
= presContext
->GetTheme();
10099 if (theme
&& theme
->ThemeSupportsWidget(presContext
, primaryFrame
, disp
->mAppearance
)) {
10100 PRBool repaint
= PR_FALSE
;
10101 theme
->WidgetStateChanged(primaryFrame
, disp
->mAppearance
, aAttribute
, &repaint
);
10103 NS_UpdateHint(hint
, nsChangeHint_RepaintFrame
);
10107 // let the frame deal with it now, so we don't have to deal later
10108 result
= primaryFrame
->AttributeChanged(aNameSpaceID
, aAttribute
,
10110 // XXXwaterson should probably check for special IB siblings
10111 // here, and propagate the AttributeChanged notification to
10112 // them, as well. Currently, inline frames don't do anything on
10113 // this notification, so it's not that big a deal.
10116 // See if we can optimize away the style re-resolution -- must be called after
10117 // the frame's AttributeChanged() in case it does something that affects the style
10118 nsFrameManager
*frameManager
= shell
->FrameManager();
10119 nsReStyleHint rshint
= frameManager
->HasAttributeDependentStyle(aContent
,
10124 PostRestyleEvent(aContent
, rshint
, hint
);
10130 nsCSSFrameConstructor::BeginUpdate() {
10131 NS_SuppressFocusEvent();
10132 ++mFocusSuppressCount
;
10137 nsCSSFrameConstructor::EndUpdate()
10139 if (mUpdateCount
== 1) {
10140 // This is the end of our last update. Before we decrement
10141 // mUpdateCount, recalc quotes and counters as needed.
10143 RecalcQuotesAndCounters();
10144 NS_ASSERTION(mUpdateCount
== 1, "Odd update count");
10147 if (mFocusSuppressCount
) {
10148 NS_UnsuppressFocusEvent();
10149 --mFocusSuppressCount
;
10154 nsCSSFrameConstructor::RecalcQuotesAndCounters()
10156 if (mQuotesDirty
) {
10157 mQuotesDirty
= PR_FALSE
;
10158 mQuoteList
.RecalcAll();
10161 if (mCountersDirty
) {
10162 mCountersDirty
= PR_FALSE
;
10163 mCounterManager
.RecalcAll();
10166 NS_ASSERTION(!mQuotesDirty
, "Quotes updates will be lost");
10167 NS_ASSERTION(!mCountersDirty
, "Counter updates will be lost");
10170 class nsFocusUnsuppressEvent
: public nsRunnable
{
10172 NS_DECL_NSIRUNNABLE
10173 nsFocusUnsuppressEvent(PRUint32 aCount
) : mCount(aCount
) {}
10178 NS_IMETHODIMP
nsFocusUnsuppressEvent::Run()
10182 NS_UnsuppressFocusEvent();
10188 nsCSSFrameConstructor::WillDestroyFrameTree(PRBool aDestroyingPresShell
)
10190 #if defined(DEBUG_dbaron_off)
10191 mCounterManager
.Dump();
10194 mIsDestroyingFrameTree
= PR_TRUE
;
10196 // Prevent frame tree destruction from being O(N^2)
10197 mQuoteList
.Clear();
10198 mCounterManager
.Clear();
10200 // Cancel all pending re-resolves
10201 mRestyleEvent
.Revoke();
10203 if (mFocusSuppressCount
&& aDestroyingPresShell
) {
10204 nsRefPtr
<nsFocusUnsuppressEvent
> ev
=
10205 new nsFocusUnsuppressEvent(mFocusSuppressCount
);
10206 if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev
))) {
10207 mFocusSuppressCount
= 0;
10214 // XXXbz I'd really like this method to go away. Once we have inline-block and
10215 // I can just use that for sized broken images, that can happen, maybe.
10216 void nsCSSFrameConstructor::GetAlternateTextFor(nsIContent
* aContent
,
10217 nsIAtom
* aTag
, // content object's tag
10218 nsXPIDLString
& aAltText
)
10220 // The "alt" attribute specifies alternate text that is rendered
10221 // when the image can not be displayed
10223 // If there's no "alt" attribute, and aContent is an input
10224 // element, then use the value of the "value" attribute
10225 if (!aContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::alt
, aAltText
) &&
10226 nsGkAtoms::input
== aTag
) {
10227 // If there's no "value" attribute either, then use the localized string
10228 // for "Submit" as the alternate text.
10229 if (!aContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::value
, aAltText
)) {
10230 nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES
,
10231 "Submit", aAltText
);
10237 nsCSSFrameConstructor::CreateContinuingOuterTableFrame(nsIPresShell
* aPresShell
,
10238 nsPresContext
* aPresContext
,
10240 nsIFrame
* aParentFrame
,
10241 nsIContent
* aContent
,
10242 nsStyleContext
* aStyleContext
,
10243 nsIFrame
** aContinuingFrame
)
10245 nsIFrame
* newFrame
= NS_NewTableOuterFrame(aPresShell
, aStyleContext
);
10248 newFrame
->Init(aContent
, aParentFrame
, aFrame
);
10249 // XXXbz should we be passing in a non-null aContentParentFrame?
10250 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10252 // Create a continuing inner table frame, and if there's a caption then
10253 // replicate the caption
10254 nsFrameItems newChildFrames
;
10256 nsIFrame
* childFrame
= aFrame
->GetFirstChild(nsnull
);
10258 nsIFrame
* continuingTableFrame
;
10259 nsresult rv
= CreateContinuingFrame(aPresContext
, childFrame
, newFrame
,
10260 &continuingTableFrame
);
10261 if (NS_FAILED(rv
)) {
10262 newFrame
->Destroy();
10263 *aContinuingFrame
= nsnull
;
10266 newChildFrames
.AddChild(continuingTableFrame
);
10268 NS_ASSERTION(!childFrame
->GetNextSibling(),"there can be only one inner table frame");
10271 // Set the outer table's initial child list
10272 newFrame
->SetInitialChildList(nsnull
, newChildFrames
.childList
);
10274 *aContinuingFrame
= newFrame
;
10278 *aContinuingFrame
= nsnull
;
10279 return NS_ERROR_OUT_OF_MEMORY
;
10284 nsCSSFrameConstructor::CreateContinuingTableFrame(nsIPresShell
* aPresShell
,
10285 nsPresContext
* aPresContext
,
10287 nsIFrame
* aParentFrame
,
10288 nsIContent
* aContent
,
10289 nsStyleContext
* aStyleContext
,
10290 nsIFrame
** aContinuingFrame
)
10292 nsIFrame
* newFrame
= NS_NewTableFrame(aPresShell
, aStyleContext
);
10295 newFrame
->Init(aContent
, aParentFrame
, aFrame
);
10296 // XXXbz should we be passing in a non-null aContentParentFrame?
10297 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10299 // Replicate any header/footer frames
10300 nsFrameItems childFrames
;
10301 nsIFrame
* childFrame
= aFrame
->GetFirstChild(nsnull
);
10302 for ( ; childFrame
; childFrame
= childFrame
->GetNextSibling()) {
10303 // See if it's a header/footer, possibly wrapped in a scroll frame.
10304 nsTableRowGroupFrame
* rowGroupFrame
=
10305 nsTableFrame::GetRowGroupFrame(childFrame
);
10306 if (rowGroupFrame
) {
10307 // If the row group was continued, then don't replicate it.
10308 nsIFrame
* rgNextInFlow
= rowGroupFrame
->GetNextInFlow();
10309 if (rgNextInFlow
) {
10310 rowGroupFrame
->SetRepeatable(PR_FALSE
);
10312 else if (rowGroupFrame
->IsRepeatable()) {
10313 // Replicate the header/footer frame.
10314 nsTableRowGroupFrame
* headerFooterFrame
;
10315 nsFrameItems childItems
;
10316 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
10317 GetAbsoluteContainingBlock(newFrame
),
10320 headerFooterFrame
= static_cast<nsTableRowGroupFrame
*>
10321 (NS_NewTableRowGroupFrame(aPresShell
, rowGroupFrame
->GetStyleContext()));
10322 nsIContent
* headerFooter
= rowGroupFrame
->GetContent();
10323 headerFooterFrame
->Init(headerFooter
, newFrame
, nsnull
);
10324 ProcessChildren(state
, headerFooter
, headerFooterFrame
,
10325 PR_TRUE
, childItems
, PR_FALSE
);
10326 NS_ASSERTION(!state
.mFloatedItems
.childList
, "unexpected floated element");
10327 headerFooterFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
10328 headerFooterFrame
->SetRepeatable(PR_TRUE
);
10330 // Table specific initialization
10331 headerFooterFrame
->InitRepeatedFrame(aPresContext
, rowGroupFrame
);
10333 // XXX Deal with absolute and fixed frames...
10334 childFrames
.AddChild(headerFooterFrame
);
10339 // Set the table frame's initial child list
10340 newFrame
->SetInitialChildList(nsnull
, childFrames
.childList
);
10342 *aContinuingFrame
= newFrame
;
10346 *aContinuingFrame
= nsnull
;
10347 return NS_ERROR_OUT_OF_MEMORY
;
10352 nsCSSFrameConstructor::CreateContinuingFrame(nsPresContext
* aPresContext
,
10354 nsIFrame
* aParentFrame
,
10355 nsIFrame
** aContinuingFrame
,
10358 nsIPresShell
* shell
= aPresContext
->PresShell();
10359 nsStyleContext
* styleContext
= aFrame
->GetStyleContext();
10360 nsIFrame
* newFrame
= nsnull
;
10361 nsresult rv
= NS_OK
;
10362 nsIFrame
* nextContinuation
= aFrame
->GetNextContinuation();
10363 nsIFrame
* nextInFlow
= aFrame
->GetNextInFlow();
10365 // Use the frame type to determine what type of frame to create
10366 nsIAtom
* frameType
= aFrame
->GetType();
10367 nsIContent
* content
= aFrame
->GetContent();
10369 NS_ASSERTION(aFrame
->GetSplittableType() != NS_FRAME_NOT_SPLITTABLE
,
10370 "why CreateContinuingFrame for a non-splittable frame?");
10372 if (nsGkAtoms::textFrame
== frameType
) {
10373 newFrame
= NS_NewContinuingTextFrame(shell
, styleContext
);
10376 newFrame
->Init(content
, aParentFrame
, aFrame
);
10377 // XXXbz should we be passing in a non-null aContentParentFrame?
10378 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10381 } else if (nsGkAtoms::inlineFrame
== frameType
) {
10382 newFrame
= NS_NewInlineFrame(shell
, styleContext
);
10385 newFrame
->Init(content
, aParentFrame
, aFrame
);
10386 // XXXbz should we be passing in a non-null aContentParentFrame?
10387 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10390 } else if (nsGkAtoms::blockFrame
== frameType
) {
10391 newFrame
= NS_NewBlockFrame(shell
, styleContext
);
10394 newFrame
->Init(content
, aParentFrame
, aFrame
);
10395 // XXXbz should we be passing in a non-null aContentParentFrame?
10396 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10399 } else if (nsGkAtoms::areaFrame
== frameType
) {
10400 newFrame
= NS_NewAreaFrame(shell
, styleContext
, 0);
10403 newFrame
->Init(content
, aParentFrame
, aFrame
);
10404 // XXXbz should we be passing in a non-null aContentParentFrame?
10405 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10408 } else if (nsGkAtoms::columnSetFrame
== frameType
) {
10409 newFrame
= NS_NewColumnSetFrame(shell
, styleContext
, 0);
10412 newFrame
->Init(content
, aParentFrame
, aFrame
);
10413 // XXXbz should we be passing in a non-null aContentParentFrame?
10414 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10417 } else if (nsGkAtoms::positionedInlineFrame
== frameType
) {
10418 newFrame
= NS_NewPositionedInlineFrame(shell
, styleContext
);
10421 newFrame
->Init(content
, aParentFrame
, aFrame
);
10422 // XXXbz should we be passing in a non-null aContentParentFrame?
10423 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10426 } else if (nsGkAtoms::pageFrame
== frameType
) {
10427 nsIFrame
* canvasFrame
;
10428 rv
= ConstructPageFrame(shell
, aPresContext
, aParentFrame
, aFrame
,
10429 newFrame
, canvasFrame
);
10430 } else if (nsGkAtoms::tableOuterFrame
== frameType
) {
10431 rv
= CreateContinuingOuterTableFrame(shell
, aPresContext
, aFrame
, aParentFrame
,
10432 content
, styleContext
, &newFrame
);
10434 } else if (nsGkAtoms::tableFrame
== frameType
) {
10435 rv
= CreateContinuingTableFrame(shell
, aPresContext
, aFrame
, aParentFrame
,
10436 content
, styleContext
, &newFrame
);
10438 } else if (nsGkAtoms::tableRowGroupFrame
== frameType
) {
10439 newFrame
= NS_NewTableRowGroupFrame(shell
, styleContext
);
10442 newFrame
->Init(content
, aParentFrame
, aFrame
);
10443 // XXXbz should we be passing in a non-null aContentParentFrame?
10444 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10447 } else if (nsGkAtoms::tableRowFrame
== frameType
) {
10448 newFrame
= NS_NewTableRowFrame(shell
, styleContext
);
10451 newFrame
->Init(content
, aParentFrame
, aFrame
);
10452 // XXXbz should we be passing in a non-null aContentParentFrame?
10453 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10455 // Create a continuing frame for each table cell frame
10456 nsFrameItems newChildList
;
10457 nsIFrame
* cellFrame
= aFrame
->GetFirstChild(nsnull
);
10458 while (cellFrame
) {
10459 // See if it's a table cell frame
10460 if (IS_TABLE_CELL(cellFrame
->GetType())) {
10461 nsIFrame
* continuingCellFrame
;
10462 rv
= CreateContinuingFrame(aPresContext
, cellFrame
, newFrame
,
10463 &continuingCellFrame
);
10464 if (NS_FAILED(rv
)) {
10465 nsFrameList
tmp(newChildList
.childList
);
10466 tmp
.DestroyFrames();
10467 newFrame
->Destroy();
10468 *aContinuingFrame
= nsnull
;
10469 return NS_ERROR_OUT_OF_MEMORY
;
10471 newChildList
.AddChild(continuingCellFrame
);
10473 cellFrame
= cellFrame
->GetNextSibling();
10476 // Set the table cell's initial child list
10477 newFrame
->SetInitialChildList(nsnull
, newChildList
.childList
);
10480 } else if (IS_TABLE_CELL(frameType
)) {
10481 // Warning: If you change this and add a wrapper frame around table cell
10482 // frames, make sure Bug 368554 doesn't regress!
10483 // See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp.
10484 newFrame
= NS_NewTableCellFrame(shell
, styleContext
, IsBorderCollapse(aParentFrame
));
10487 newFrame
->Init(content
, aParentFrame
, aFrame
);
10488 // XXXbz should we be passing in a non-null aContentParentFrame?
10489 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10491 // Create a continuing area frame
10492 nsIFrame
* continuingAreaFrame
;
10493 nsIFrame
* areaFrame
= aFrame
->GetFirstChild(nsnull
);
10494 rv
= CreateContinuingFrame(aPresContext
, areaFrame
, newFrame
,
10495 &continuingAreaFrame
);
10496 if (NS_FAILED(rv
)) {
10497 newFrame
->Destroy();
10498 *aContinuingFrame
= nsnull
;
10502 // Set the table cell's initial child list
10503 newFrame
->SetInitialChildList(nsnull
, continuingAreaFrame
);
10506 } else if (nsGkAtoms::lineFrame
== frameType
) {
10507 newFrame
= NS_NewFirstLineFrame(shell
, styleContext
);
10510 newFrame
->Init(content
, aParentFrame
, aFrame
);
10511 // XXXbz should we be passing in a non-null aContentParentFrame?
10512 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10515 } else if (nsGkAtoms::letterFrame
== frameType
) {
10516 newFrame
= NS_NewFirstLetterFrame(shell
, styleContext
);
10519 newFrame
->Init(content
, aParentFrame
, aFrame
);
10520 // XXXbz should we be passing in a non-null aContentParentFrame?
10521 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10524 } else if (nsGkAtoms::imageFrame
== frameType
) {
10525 newFrame
= NS_NewImageFrame(shell
, styleContext
);
10528 newFrame
->Init(content
, aParentFrame
, aFrame
);
10530 } else if (nsGkAtoms::imageControlFrame
== frameType
) {
10531 newFrame
= NS_NewImageControlFrame(shell
, styleContext
);
10534 newFrame
->Init(content
, aParentFrame
, aFrame
);
10536 } else if (nsGkAtoms::placeholderFrame
== frameType
) {
10537 // create a continuing out of flow frame
10538 nsIFrame
* oofFrame
= nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame
);
10539 nsIFrame
* oofContFrame
;
10540 rv
= CreateContinuingFrame(aPresContext
, oofFrame
, aParentFrame
, &oofContFrame
);
10541 if (NS_FAILED(rv
)) {
10542 *aContinuingFrame
= nsnull
;
10545 // create a continuing placeholder frame
10546 rv
= CreatePlaceholderFrameFor(shell
, content
, oofContFrame
, styleContext
,
10547 aParentFrame
, aFrame
, &newFrame
);
10548 if (NS_FAILED(rv
)) {
10549 oofContFrame
->Destroy();
10550 *aContinuingFrame
= nsnull
;
10553 } else if (nsGkAtoms::fieldSetFrame
== frameType
) {
10554 newFrame
= NS_NewFieldSetFrame(shell
, styleContext
);
10557 newFrame
->Init(content
, aParentFrame
, aFrame
);
10559 // XXXbz should we be passing in a non-null aContentParentFrame?
10560 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, nsnull
, PR_FALSE
);
10562 // Create a continuing area frame
10563 // XXXbz we really shouldn't have to do this by hand!
10564 nsIFrame
* continuingAreaFrame
;
10565 nsIFrame
* areaFrame
= GetFieldSetAreaFrame(aFrame
);
10566 rv
= CreateContinuingFrame(aPresContext
, areaFrame
, newFrame
,
10567 &continuingAreaFrame
);
10568 if (NS_FAILED(rv
)) {
10569 newFrame
->Destroy();
10570 *aContinuingFrame
= nsnull
;
10573 // Set the fieldset's initial child list
10574 newFrame
->SetInitialChildList(nsnull
, continuingAreaFrame
);
10577 NS_NOTREACHED("unexpected frame type");
10578 *aContinuingFrame
= nsnull
;
10579 return NS_ERROR_UNEXPECTED
;
10582 *aContinuingFrame
= newFrame
;
10585 return NS_ERROR_OUT_OF_MEMORY
;
10588 // Init() set newFrame to be a fluid continuation of aFrame.
10589 // If we want a non-fluid continuation, we need to call SetPrevContinuation()
10590 // to reset NS_FRAME_IS_FLUID_CONTINUATION.
10592 newFrame
->SetPrevContinuation(aFrame
);
10595 // A continuation of generated content is also generated content
10596 if (aFrame
->GetStateBits() & NS_FRAME_GENERATED_CONTENT
) {
10597 newFrame
->AddStateBits(NS_FRAME_GENERATED_CONTENT
);
10600 // A continuation of an out-of-flow is also an out-of-flow
10601 if (aFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
10602 newFrame
->AddStateBits(NS_FRAME_OUT_OF_FLOW
);
10606 nextInFlow
->SetPrevInFlow(newFrame
);
10607 newFrame
->SetNextInFlow(nextInFlow
);
10608 } else if (nextContinuation
) {
10609 nextContinuation
->SetPrevContinuation(newFrame
);
10610 newFrame
->SetNextContinuation(nextContinuation
);
10616 nsCSSFrameConstructor::ReplicateFixedFrames(nsPageContentFrame
* aParentFrame
)
10618 // Now deal with fixed-pos things.... They should appear on all pages,
10619 // so we want to move over the placeholders when processing the child
10620 // of the pageContentFrame.
10622 nsIFrame
* prevPageContentFrame
= aParentFrame
->GetPrevInFlow();
10623 if (!prevPageContentFrame
) {
10626 nsIFrame
* canvasFrame
= aParentFrame
->GetFirstChild(nsnull
);
10627 nsIFrame
* prevCanvasFrame
= prevPageContentFrame
->GetFirstChild(nsnull
);
10628 if (!canvasFrame
|| !prevCanvasFrame
) {
10629 // document's root element frame missing
10630 return NS_ERROR_UNEXPECTED
;
10633 nsFrameItems fixedPlaceholders
;
10634 nsIFrame
* firstFixed
= prevPageContentFrame
->GetFirstChild(nsGkAtoms::fixedList
);
10639 //XXXbz Should mInitialContainingBlock be docRootFrame? It probably doesn't matter.
10640 // Don't allow abs-pos descendants of the fixed content to escape the content.
10641 // This should not normally be possible (because fixed-pos elements should
10642 // be absolute containers) but fixed-pos tables currently aren't abs-pos
10644 nsFrameConstructorState
state(mPresShell
, aParentFrame
,
10646 mInitialContainingBlock
);
10648 // Iterate across fixed frames and replicate each whose placeholder is a
10649 // descendant of aFrame. (We don't want to explicitly copy placeholders that
10650 // are within fixed frames, because that would cause duplicates on the new
10651 // page - bug 389619)
10652 for (nsIFrame
* fixed
= firstFixed
; fixed
; fixed
= fixed
->GetNextSibling()) {
10653 nsIFrame
* prevPlaceholder
= nsnull
;
10654 mPresShell
->GetPlaceholderFrameFor(fixed
, &prevPlaceholder
);
10655 if (prevPlaceholder
&&
10656 nsLayoutUtils::IsProperAncestorFrame(prevCanvasFrame
, prevPlaceholder
)) {
10657 nsresult rv
= ConstructFrame(state
, fixed
->GetContent(),
10658 canvasFrame
, fixedPlaceholders
);
10659 NS_ENSURE_SUCCESS(rv
, rv
);
10663 // Add the placeholders to our primary child list.
10664 // XXXbz this is a little screwed up, since the fixed frames will have
10665 // broken auto-positioning. Oh, well.
10666 NS_ASSERTION(!canvasFrame
->GetFirstChild(nsnull
),
10667 "leaking frames; doc root continuation must be empty");
10668 canvasFrame
->SetInitialChildList(nsnull
, fixedPlaceholders
.childList
);
10673 IsBindingAncestor(nsIContent
* aContent
, nsIContent
* aBindingRoot
)
10676 // Native-anonymous content doesn't contain insertion points, so
10677 // we don't need to search through it.
10678 if (aContent
->IsRootOfNativeAnonymousSubtree())
10680 nsIContent
* bindingParent
= aContent
->GetBindingParent();
10681 if (!bindingParent
)
10683 if (bindingParent
== aBindingRoot
)
10685 aContent
= bindingParent
;
10689 // Helper function that searches the immediate child frames
10690 // (and their children if the frames are "special")
10691 // for a frame that maps the specified content object
10693 nsCSSFrameConstructor::FindFrameWithContent(nsFrameManager
* aFrameManager
,
10694 nsIFrame
* aParentFrame
,
10695 nsIContent
* aParentContent
,
10696 nsIContent
* aContent
,
10697 nsFindFrameHint
* aHint
)
10700 #ifdef NOISY_FINDFRAME
10702 printf("looking for content=%p, given aParentFrame %p parentContent %p, hint is %s\n",
10703 aContent
, aParentFrame
, aParentContent
, aHint
? "set" : "NULL");
10706 NS_ENSURE_TRUE(aParentFrame
!= nsnull
, nsnull
);
10709 // Search for the frame in each child list that aParentFrame supports
10710 nsIAtom
* listName
= nsnull
;
10711 PRInt32 listIndex
= 0;
10712 PRBool searchAgain
;
10715 #ifdef NOISY_FINDFRAME
10718 nsIFrame
* kidFrame
= nsnull
;
10720 searchAgain
= PR_FALSE
;
10722 // if we were given an hint, try to use it here to find a good
10723 // previous frame to start our search (|kidFrame|).
10725 #ifdef NOISY_FINDFRAME
10726 printf(" hint frame is %p\n", aHint
->mPrimaryFrameForPrevSibling
);
10728 // start with the primary frame for aContent's previous sibling
10729 kidFrame
= aHint
->mPrimaryFrameForPrevSibling
;
10730 // But if it's out of flow, start from its placeholder.
10731 if (kidFrame
&& (kidFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)) {
10732 kidFrame
= aFrameManager
->GetPlaceholderFrameFor(kidFrame
);
10736 // then use the next sibling frame as our starting point
10737 if (kidFrame
->GetNextSibling()) {
10738 kidFrame
= kidFrame
->GetNextSibling();
10741 // The hint frame had no next sibling. Try the next-in-flow or
10742 // special sibling of the parent of the hint frame (or its
10743 // associated placeholder).
10744 nsIFrame
*parentFrame
= kidFrame
->GetParent();
10747 parentFrame
= nsLayoutUtils::GetNextContinuationOrSpecialSibling(parentFrame
);
10750 // Found it, continue the search with its first child.
10751 kidFrame
= parentFrame
->GetFirstChild(listName
);
10752 // Leave |aParentFrame| as-is, since the only time we'll
10753 // reuse it is if the hint fails.
10756 #ifdef NOISY_FINDFRAME
10757 printf(" hint gives us kidFrame=%p with parent frame %p content %p\n",
10758 kidFrame
, aParentFrame
, aParentContent
);
10762 if (!kidFrame
) { // we didn't have enough info to prune, start searching from the beginning
10763 kidFrame
= aParentFrame
->GetFirstChild(listName
);
10766 // See if the child frame points to the content object we're
10768 nsIContent
* kidContent
= kidFrame
->GetContent();
10769 if (kidContent
== aContent
) {
10771 // We found a match. Return the out-of-flow if it's a placeholder
10772 return nsPlaceholderFrame::GetRealFrameFor(kidFrame
);
10775 // only do this if there is content
10777 // We search the immediate children only, but if the child frame has
10778 // the same content pointer as its parent then we need to search its
10779 // child frames, too.
10780 // We also need to search if the child content is anonymous and scoped
10781 // to the parent content.
10782 // XXXldb What makes us continue the search once we're inside
10783 // the anonymous subtree?
10784 if (aParentContent
== kidContent
||
10785 (aParentContent
&& IsBindingAncestor(kidContent
, aParentContent
)))
10787 #ifdef NOISY_FINDFRAME
10789 printf(" recursing with new parent set to kidframe=%p, parentContent=%p\n",
10790 kidFrame
, aParentContent
);
10792 nsIFrame
* matchingFrame
=
10793 FindFrameWithContent(aFrameManager
,
10794 nsPlaceholderFrame::GetRealFrameFor(kidFrame
),
10795 aParentContent
, aContent
, nsnull
);
10797 if (matchingFrame
) {
10798 return matchingFrame
;
10803 // Get the next sibling frame
10804 kidFrame
= kidFrame
->GetNextSibling();
10805 #ifdef NOISY_FINDFRAME
10808 printf(" searching sibling frame %p\n", kidFrame
);
10814 // If we get here, and we had a hint, then we didn't find a frame.
10815 // The hint may have been a frame whose location in the frame tree
10816 // doesn't match the location of its corresponding element in the
10817 // DOM tree, e.g. a floated or absolutely positioned frame, or e.g.
10818 // a <col> frame, in which case we'd be off in the weeds looking
10819 // through something other than the primary frame list.
10820 // Reboot the search from scratch, without the hint, but using the
10821 // null child list again.
10823 searchAgain
= PR_TRUE
;
10826 listName
= aParentFrame
->GetAdditionalChildListName(listIndex
++);
10827 } while (IsOutOfFlowList(listName
));
10829 } while(listName
|| searchAgain
);
10831 // We didn't find a matching frame. If aFrame has a next-in-flow,
10832 // then continue looking there
10833 aParentFrame
= nsLayoutUtils::GetNextContinuationOrSpecialSibling(aParentFrame
);
10834 #ifdef NOISY_FINDFRAME
10835 if (aParentFrame
) {
10836 FFWC_nextInFlows
++;
10837 printf(" searching NIF frame %p\n", aParentFrame
);
10840 } while (aParentFrame
);
10842 // No matching frame
10846 // Request to find the primary frame associated with a given content object.
10847 // This is typically called by the pres shell when there is no mapping in
10848 // the pres shell hash table
10850 nsCSSFrameConstructor::FindPrimaryFrameFor(nsFrameManager
* aFrameManager
,
10851 nsIContent
* aContent
,
10853 nsFindFrameHint
* aHint
)
10855 NS_ASSERTION(aFrameManager
&& aContent
&& aFrame
, "bad arg");
10857 *aFrame
= nsnull
; // initialize OUT parameter
10859 // We want to be able to quickly map from a content object to its frame,
10860 // but we also want to keep the hash table small. Therefore, many frames
10861 // are not added to the hash table when they're first created:
10863 // - inline frames (often things like FONT and B)
10865 // - internal table frames (row-group, row, cell, col-group, col)
10867 // That means we need to need to search for the frame
10868 nsIFrame
* parentFrame
; // this pointer is used to iterate across all frames that map to parentContent
10870 // Get the frame that corresponds to the parent content object.
10871 // Note that this may recurse indirectly, because the pres shell will
10872 // call us back if there is no mapping in the hash table
10873 nsCOMPtr
<nsIContent
> parentContent
= aContent
->GetParent(); // Get this once
10874 if (parentContent
) {
10875 parentFrame
= aFrameManager
->GetPrimaryFrameFor(parentContent
, -1);
10876 while (parentFrame
) {
10877 // Search the child frames for a match
10878 *aFrame
= FindFrameWithContent(aFrameManager
, parentFrame
,
10879 parentContent
, aContent
, aHint
);
10880 #ifdef NOISY_FINDFRAME
10881 printf("FindFrameWithContent returned %p\n", *aFrame
);
10885 // if we're given a hint and we were told to verify, then compare the resulting frame with
10886 // the frame we get by calling FindFrameWithContent *without* the hint.
10887 // Assert if they do not match
10888 // Note that this makes finding frames *slower* than it was before the fix.
10889 if (gVerifyFastFindFrame
&& aHint
)
10891 #ifdef NOISY_FINDFRAME
10892 printf("VERIFYING...\n");
10894 nsIFrame
*verifyTestFrame
=
10895 FindFrameWithContent(aFrameManager
, parentFrame
,
10896 parentContent
, aContent
, nsnull
);
10897 #ifdef NOISY_FINDFRAME
10898 printf("VERIFY returned %p\n", verifyTestFrame
);
10900 NS_ASSERTION(verifyTestFrame
== *aFrame
, "hint shortcut found wrong frame");
10903 // If we found a match, then add a mapping to the hash table so
10904 // next time this will be quick
10906 aFrameManager
->SetPrimaryFrameFor(aContent
, *aFrame
);
10909 else if (IsFrameSpecial(parentFrame
)) {
10910 // If it's a "special" frame (that is, part of an inline
10911 // that's been split because it contained a block), we need to
10912 // follow the out-of-flow "special sibling" link, and search
10913 // *that* subtree as well.
10914 parentFrame
= GetSpecialSibling(parentFrame
);
10922 if (aHint
&& !*aFrame
)
10923 { // if we had a hint, and we didn't get a frame, see if we should try the slow way
10924 if (aContent
->IsNodeOfType(nsINode::eTEXT
))
10926 #ifdef NOISY_FINDFRAME
10927 FFWC_slowSearchForText
++;
10929 // since we're passing in a null hint, we're guaranteed to only recurse once
10930 return FindPrimaryFrameFor(aFrameManager
, aContent
, aFrame
, nsnull
);
10934 #ifdef NOISY_FINDFRAME
10935 printf("%10s %10s %10s %10s %10s \n",
10936 "total", "doLoop", "doSibling", "recur", "nextIF", "slowSearch");
10937 printf("%10d %10d %10d %10d %10d \n",
10938 FFWC_totalCount
, FFWC_doLoop
, FFWC_doSibling
, FFWC_recursions
,
10939 FFWC_nextInFlows
, FFWC_slowSearchForText
);
10946 nsCSSFrameConstructor::GetInsertionPoint(nsIFrame
* aParentFrame
,
10947 nsIContent
* aChildContent
,
10948 nsIFrame
** aInsertionPoint
,
10951 // Make the insertion point be the parent frame by default, in case
10952 // we have to bail early.
10953 *aInsertionPoint
= aParentFrame
;
10955 nsIContent
* container
= aParentFrame
->GetContent();
10959 nsBindingManager
*bindingManager
= mDocument
->BindingManager();
10961 nsIContent
* insertionElement
;
10962 if (aChildContent
) {
10963 // We've got an explicit insertion child. Check to see if it's
10965 if (aChildContent
->GetBindingParent() == container
) {
10966 // This child content is anonymous. Don't use the insertion
10967 // point, since that's only for the explicit kids.
10972 insertionElement
= bindingManager
->GetInsertionPoint(container
,
10979 insertionElement
= bindingManager
->GetSingleInsertionPoint(container
,
10982 if (multiple
&& aMultiple
)
10983 *aMultiple
= multiple
; // Record the fact that filters are in use.
10986 if (insertionElement
) {
10987 nsIFrame
* insertionPoint
= mPresShell
->GetPrimaryFrameFor(insertionElement
);
10988 if (insertionPoint
) {
10989 // Use the content insertion frame of the insertion point.
10990 insertionPoint
= insertionPoint
->GetContentInsertionFrame();
10991 if (insertionPoint
&& insertionPoint
!= aParentFrame
)
10992 GetInsertionPoint(insertionPoint
, aChildContent
, aInsertionPoint
, aMultiple
);
10995 // There was no frame created yet for the insertion point.
10996 *aInsertionPoint
= nsnull
;
11000 // fieldsets have multiple insertion points. Note that we might
11001 // have to look at insertionElement here...
11002 if (aMultiple
&& !*aMultiple
) {
11003 nsIContent
* content
= insertionElement
? insertionElement
: container
;
11004 if (content
->IsNodeOfType(nsINode::eHTML
) &&
11005 content
->Tag() == nsGkAtoms::fieldset
) {
11006 *aMultiple
= PR_TRUE
;
11013 // Capture state for the frame tree rooted at the frame associated with the
11014 // content object, aContent
11016 nsCSSFrameConstructor::CaptureStateForFramesOf(nsIContent
* aContent
,
11017 nsILayoutHistoryState
* aHistoryState
)
11019 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
11021 CaptureStateFor(frame
, aHistoryState
);
11026 // Capture state for the frame tree rooted at aFrame.
11028 nsCSSFrameConstructor::CaptureStateFor(nsIFrame
* aFrame
,
11029 nsILayoutHistoryState
* aHistoryState
)
11031 if (aFrame
&& aHistoryState
) {
11032 mPresShell
->FrameManager()->CaptureFrameState(aFrame
, aHistoryState
);
11038 nsCSSFrameConstructor::MaybeRecreateFramesForContent(nsIContent
* aContent
)
11040 nsresult result
= NS_OK
;
11041 nsFrameManager
*frameManager
= mPresShell
->FrameManager();
11043 nsStyleContext
*oldContext
= frameManager
->GetUndisplayedContent(aContent
);
11045 // The parent has a frame, so try resolving a new context.
11046 nsRefPtr
<nsStyleContext
> newContext
= mPresShell
->StyleSet()->
11047 ResolveStyleFor(aContent
, oldContext
->GetParent());
11049 frameManager
->ChangeUndisplayedContent(aContent
, newContext
);
11050 if (newContext
->GetStyleDisplay()->mDisplay
!= NS_STYLE_DISPLAY_NONE
) {
11051 result
= RecreateFramesForContent(aContent
);
11058 nsCSSFrameConstructor::MaybeRecreateContainerForIBSplitterFrame(nsIFrame
* aFrame
,
11061 NS_PRECONDITION(aFrame
, "Must have a frame");
11062 NS_PRECONDITION(aFrame
->GetParent(), "Frame shouldn't be root");
11063 NS_PRECONDITION(aResult
, "Null out param?");
11064 NS_PRECONDITION(aFrame
== aFrame
->GetFirstContinuation(),
11065 "aFrame not the result of GetPrimaryFrameFor()?");
11067 if (IsFrameSpecial(aFrame
)) {
11068 // The removal functions can't handle removal of an {ib} split directly; we
11069 // need to rebuild the containing block.
11071 if (gNoisyContentUpdates
) {
11072 printf("nsCSSFrameConstructor::MaybeRecreateContainerForIBSplitterFrame: "
11074 nsFrame::ListTag(stdout
, aFrame
);
11075 printf(" is special\n");
11079 *aResult
= ReframeContainingBlock(aFrame
);
11083 // We might still need to reconstruct things if the parent of aFrame is
11084 // special, since in that case the removal of aFrame might affect the
11085 // splitting of its parent.
11086 nsIFrame
* parent
= aFrame
->GetParent();
11087 if (!IsFrameSpecial(parent
)) {
11091 // If aFrame is an inline, then it cannot possibly have caused the splitting.
11092 // If the frame is being reconstructed and being changed to a block, the
11093 // ContentInserted call will handle the containing block reframe. So in this
11094 // case, try to be conservative about whether we need to reframe. The only
11095 // case when it's needed is if the inline is the only child of the tail end
11096 // of an {ib} split, because the splitting code doesn't produce this tail end
11097 // if it would have no kids. If that ever changes, this code should change.
11098 if (IsInlineOutside(aFrame
) &&
11100 // Not a kid of the third part of the IB split
11101 GetSpecialSibling(parent
) || !IsInlineOutside(parent
) ||
11102 // Or not the only child
11103 aFrame
->GetTailContinuation()->GetNextSibling() ||
11104 aFrame
!= parent
->GetFirstContinuation()->GetFirstChild(nsnull
)
11110 if (gNoisyContentUpdates
) {
11111 printf("nsCSSFrameConstructor::MaybeRecreateContainerForIBSplitterFrame: "
11113 nsFrame::ListTag(stdout
, parent
);
11114 printf(" is special\n");
11118 *aResult
= ReframeContainingBlock(parent
);
11123 nsCSSFrameConstructor::RecreateFramesForContent(nsIContent
* aContent
)
11125 // If there is no document, we don't want to recreate frames for it. (You
11126 // shouldn't generally be giving this method content without a document
11128 // Rebuilding the frame tree can have bad effects, especially if it's the
11129 // frame tree for chrome (see bug 157322).
11130 NS_ENSURE_TRUE(aContent
->GetDocument(), NS_ERROR_FAILURE
);
11132 // Is the frame `special'? If so, we need to reframe the containing
11133 // block *here*, rather than trying to remove and re-insert the
11134 // content (which would otherwise result in *two* nested reframe
11135 // containing block from ContentRemoved() and ContentInserted(),
11136 // below!). We'd really like to optimize away one of those
11137 // containing block reframes, hence the code here.
11139 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
11140 if (frame
&& frame
->IsFrameOfType(nsIFrame::eMathML
)) {
11141 // Reframe the topmost MathML element to prevent exponential blowup
11142 // (see bug 397518)
11144 nsIContent
* parentContent
= aContent
->GetParent();
11145 nsIFrame
* parentContentFrame
= mPresShell
->GetPrimaryFrameFor(parentContent
);
11146 if (!parentContentFrame
|| !parentContentFrame
->IsFrameOfType(nsIFrame::eMathML
))
11148 aContent
= parentContent
;
11149 frame
= parentContentFrame
;
11154 nsIFrame
* nonGeneratedAncestor
= nsLayoutUtils::GetNonGeneratedAncestor(frame
);
11155 if (nonGeneratedAncestor
->GetContent() != aContent
) {
11156 return RecreateFramesForContent(nonGeneratedAncestor
->GetContent());
11160 nsresult rv
= NS_OK
;
11162 if (frame
&& MaybeRecreateContainerForIBSplitterFrame(frame
, &rv
)) {
11166 nsCOMPtr
<nsIContent
> container
= aContent
->GetParent();
11168 // XXXbz what if this is anonymous content?
11169 PRInt32 indexInContainer
= container
->IndexOf(aContent
);
11170 // Before removing the frames associated with the content object,
11171 // ask them to save their state onto a temporary state object.
11172 CaptureStateForFramesOf(aContent
, mTempFrameTreeState
);
11174 // Remove the frames associated with the content object on which
11175 // the attribute change occurred.
11176 PRBool didReconstruct
;
11177 rv
= ContentRemoved(container
, aContent
, indexInContainer
, &didReconstruct
);
11179 if (NS_SUCCEEDED(rv
) && !didReconstruct
) {
11180 // Now, recreate the frames associated with this content object. If
11181 // ContentRemoved triggered reconstruction, then we don't need to do this
11182 // because the frames will already have been built.
11183 rv
= ContentInserted(container
, aContent
,
11184 indexInContainer
, mTempFrameTreeState
);
11187 // The content is the root node, so just rebuild the world.
11188 ReconstructDocElementHierarchy();
11191 #ifdef ACCESSIBILITY
11192 if (mPresShell
->IsAccessibilityActive()) {
11195 nsIFrame
*newFrame
= mPresShell
->GetPrimaryFrameFor(aContent
);
11196 event
= newFrame
? PRUint32(nsIAccessibleEvent::EVENT_ASYNCH_SIGNIFICANT_CHANGE
) :
11197 PRUint32(nsIAccessibleEvent::EVENT_ASYNCH_HIDE
);
11200 event
= nsIAccessibleEvent::EVENT_ASYNCH_SHOW
;
11203 // A significant enough change occured that this part
11204 // of the accessible tree is no longer valid.
11205 nsCOMPtr
<nsIAccessibilityService
> accService
=
11206 do_GetService("@mozilla.org/accessibilityService;1");
11208 accService
->InvalidateSubtreeFor(mPresShell
, aContent
, event
);
11216 //////////////////////////////////////////////////////////////////////
11218 // Block frame construction code
11220 already_AddRefed
<nsStyleContext
>
11221 nsCSSFrameConstructor::GetFirstLetterStyle(nsIContent
* aContent
,
11222 nsStyleContext
* aStyleContext
)
11225 return mPresShell
->StyleSet()->
11226 ResolvePseudoStyleFor(aContent
,
11227 nsCSSPseudoElements::firstLetter
, aStyleContext
);
11232 already_AddRefed
<nsStyleContext
>
11233 nsCSSFrameConstructor::GetFirstLineStyle(nsIContent
* aContent
,
11234 nsStyleContext
* aStyleContext
)
11237 return mPresShell
->StyleSet()->
11238 ResolvePseudoStyleFor(aContent
,
11239 nsCSSPseudoElements::firstLine
, aStyleContext
);
11244 // Predicate to see if a given content (block element) has
11245 // first-letter style applied to it.
11247 nsCSSFrameConstructor::ShouldHaveFirstLetterStyle(nsIContent
* aContent
,
11248 nsStyleContext
* aStyleContext
)
11250 return nsLayoutUtils::HasPseudoStyle(aContent
, aStyleContext
,
11251 nsCSSPseudoElements::firstLetter
,
11252 mPresShell
->GetPresContext());
11256 nsCSSFrameConstructor::HasFirstLetterStyle(nsIFrame
* aBlockFrame
)
11258 NS_PRECONDITION(aBlockFrame
, "Need a frame");
11259 NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlockFrame
),
11260 "Not a block frame?");
11262 return (aBlockFrame
->GetStateBits() & NS_BLOCK_HAS_FIRST_LETTER_STYLE
) != 0;
11266 nsCSSFrameConstructor::ShouldHaveFirstLineStyle(nsIContent
* aContent
,
11267 nsStyleContext
* aStyleContext
)
11269 PRBool hasFirstLine
=
11270 nsLayoutUtils::HasPseudoStyle(aContent
, aStyleContext
,
11271 nsCSSPseudoElements::firstLine
,
11272 mPresShell
->GetPresContext());
11273 if (hasFirstLine
) {
11274 // But disable for fieldsets
11275 PRInt32 namespaceID
;
11276 nsIAtom
* tag
= mDocument
->BindingManager()->ResolveTag(aContent
,
11278 // This check must match the one in ConstructHTMLFrame.
11279 hasFirstLine
= tag
!= nsGkAtoms::fieldset
||
11280 (namespaceID
!= kNameSpaceID_XHTML
&&
11281 !aContent
->IsNodeOfType(nsINode::eHTML
));
11284 return hasFirstLine
;
11288 nsCSSFrameConstructor::ShouldHaveSpecialBlockStyle(nsIContent
* aContent
,
11289 nsStyleContext
* aStyleContext
,
11290 PRBool
* aHaveFirstLetterStyle
,
11291 PRBool
* aHaveFirstLineStyle
)
11293 *aHaveFirstLetterStyle
=
11294 ShouldHaveFirstLetterStyle(aContent
, aStyleContext
);
11295 *aHaveFirstLineStyle
=
11296 ShouldHaveFirstLineStyle(aContent
, aStyleContext
);
11300 * Request to process the child content elements and create frames.
11302 * @param aContent the content object whose child elements to process
11303 * @param aFrame the frame associated with aContent. This will be the
11304 * parent frame (both content and geometric) for the flowed
11308 nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState
& aState
,
11309 nsIContent
* aContent
,
11311 PRBool aCanHaveGeneratedContent
,
11312 nsFrameItems
& aFrameItems
,
11313 PRBool aParentIsBlock
)
11315 NS_PRECONDITION(!aFrame
->IsLeaf(), "Bogus ProcessChildren caller!");
11316 // XXXbz ideally, this would do all the pushing of various
11317 // containing blocks as needed, so callers don't have to do it...
11318 nsresult rv
= NS_OK
;
11319 // :before/:after content should have the same style context parent
11321 nsStyleContext
* styleContext
=
11322 nsFrame::CorrectStyleParentFrame(aFrame
, nsnull
)->GetStyleContext();
11324 // save the incoming pseudo frame state
11325 nsPseudoFrames priorPseudoFrames
;
11326 aState
.mPseudoFrames
.Reset(&priorPseudoFrames
);
11328 if (aCanHaveGeneratedContent
) {
11329 // Probe for generated content before
11330 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
11331 styleContext
, nsCSSPseudoElements::before
,
11335 ChildIterator iter
, last
;
11336 for (ChildIterator::Init(aContent
, &iter
, &last
);
11339 rv
= ConstructFrame(aState
, nsCOMPtr
<nsIContent
>(*iter
),
11340 aFrame
, aFrameItems
);
11345 if (aCanHaveGeneratedContent
) {
11346 // Probe for generated content after
11347 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
11348 styleContext
, nsCSSPseudoElements::after
,
11352 // process the current pseudo frame state
11353 if (!aState
.mPseudoFrames
.IsEmpty()) {
11354 ProcessPseudoFrames(aState
, aFrameItems
);
11357 // restore the incoming pseudo frame state
11358 aState
.mPseudoFrames
= priorPseudoFrames
;
11360 NS_ASSERTION(!aParentIsBlock
|| !aFrame
->IsBoxFrame(),
11361 "can't be both block and box");
11363 if (aParentIsBlock
) {
11364 if (aState
.mFirstLetterStyle
) {
11365 rv
= WrapFramesInFirstLetterFrame(aState
, aContent
, aFrame
, aFrameItems
);
11367 if (aState
.mFirstLineStyle
) {
11368 rv
= WrapFramesInFirstLineFrame(aState
, aContent
, aFrame
, aFrameItems
);
11372 nsIContent
*badKid
;
11373 if (aFrame
->IsBoxFrame() &&
11374 (badKid
= AnyKidsNeedBlockParent(aFrameItems
.childList
))) {
11375 nsAutoString parentTag
, kidTag
;
11376 aContent
->Tag()->ToString(parentTag
);
11377 badKid
->Tag()->ToString(kidTag
);
11378 const PRUnichar
* params
[] = { parentTag
.get(), kidTag
.get() };
11379 nsStyleContext
*frameStyleContext
= aFrame
->GetStyleContext();
11380 const nsStyleDisplay
*display
= frameStyleContext
->GetStyleDisplay();
11381 const char *message
=
11382 (display
->mDisplay
== NS_STYLE_DISPLAY_INLINE_BOX
)
11383 ? "NeededToWrapXULInlineBox" : "NeededToWrapXUL";
11384 nsContentUtils::ReportToConsole(nsContentUtils::eXUL_PROPERTIES
,
11386 params
, NS_ARRAY_LENGTH(params
),
11387 mDocument
->GetDocumentURI(),
11388 EmptyString(), 0, 0, // not useful
11389 nsIScriptError::warningFlag
,
11390 "FrameConstructor");
11392 nsRefPtr
<nsStyleContext
> blockSC
= mPresShell
->StyleSet()->
11393 ResolvePseudoStyleFor(aContent
,
11394 nsCSSAnonBoxes::mozXULAnonymousBlock
,
11395 frameStyleContext
);
11396 nsIFrame
*blockFrame
= NS_NewBlockFrame(mPresShell
, blockSC
);
11397 // We might, in theory, want to set NS_BLOCK_SPACE_MGR and
11398 // NS_BLOCK_MARGIN_ROOT, but I think it's a bad idea given that
11399 // a real block placed here wouldn't get those set on it.
11401 InitAndRestoreFrame(aState
, aContent
, aFrame
, nsnull
,
11402 blockFrame
, PR_FALSE
);
11404 NS_ASSERTION(!blockFrame
->HasView(), "need to do view reparenting");
11405 for (nsIFrame
*f
= aFrameItems
.childList
; f
; f
= f
->GetNextSibling()) {
11406 ReparentFrame(aState
.mFrameManager
, blockFrame
, f
);
11409 blockFrame
->AppendFrames(nsnull
, aFrameItems
.childList
);
11410 aFrameItems
= nsFrameItems();
11411 aFrameItems
.AddChild(blockFrame
);
11413 aFrame
->AddStateBits(NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK
);
11419 //----------------------------------------------------------------------
11421 // Support for :first-line style
11423 // Special routine to handle placing a list of frames into a block
11424 // frame that has first-line style. The routine ensures that the first
11425 // collection of inline frames end up in a first-line frame.
11427 nsCSSFrameConstructor::WrapFramesInFirstLineFrame(
11428 nsFrameConstructorState
& aState
,
11429 nsIContent
* aBlockContent
,
11430 nsIFrame
* aBlockFrame
,
11431 nsFrameItems
& aFrameItems
)
11433 nsresult rv
= NS_OK
;
11435 // Find the first and last inline frame in aFrameItems
11436 nsIFrame
* kid
= aFrameItems
.childList
;
11437 nsIFrame
* firstInlineFrame
= nsnull
;
11438 nsIFrame
* lastInlineFrame
= nsnull
;
11440 if (IsInlineOutside(kid
)) {
11441 if (!firstInlineFrame
) firstInlineFrame
= kid
;
11442 lastInlineFrame
= kid
;
11447 kid
= kid
->GetNextSibling();
11450 // If we don't find any inline frames, then there is nothing to do
11451 if (!firstInlineFrame
) {
11455 // Create line frame
11456 nsStyleContext
* parentStyle
=
11457 nsFrame::CorrectStyleParentFrame(aBlockFrame
,
11458 nsCSSPseudoElements::firstLine
)->
11460 nsRefPtr
<nsStyleContext
> firstLineStyle
= GetFirstLineStyle(aBlockContent
,
11463 nsIFrame
* lineFrame
= NS_NewFirstLineFrame(mPresShell
, firstLineStyle
);
11466 // Initialize the line frame
11467 rv
= InitAndRestoreFrame(aState
, aBlockContent
, aBlockFrame
, nsnull
,
11470 // Mangle the list of frames we are giving to the block: first
11471 // chop the list in two after lastInlineFrame
11472 nsIFrame
* secondBlockFrame
= lastInlineFrame
->GetNextSibling();
11473 lastInlineFrame
->SetNextSibling(nsnull
);
11475 // The lineFrame will be the block's first child; the rest of the
11476 // frame list (after lastInlineFrame) will be the second and
11477 // subsequent children; join the list together and reset
11478 // aFrameItems appropriately.
11479 if (secondBlockFrame
) {
11480 lineFrame
->SetNextSibling(secondBlockFrame
);
11482 if (aFrameItems
.childList
== lastInlineFrame
) {
11483 // Just in case the block had exactly one inline child
11484 aFrameItems
.lastChild
= lineFrame
;
11486 aFrameItems
.childList
= lineFrame
;
11488 // Give the inline frames to the lineFrame <b>after</b> reparenting them
11489 kid
= firstInlineFrame
;
11490 NS_ASSERTION(lineFrame
->GetStyleContext() == firstLineStyle
,
11491 "Bogus style context on line frame");
11493 ReparentFrame(aState
.mFrameManager
, lineFrame
, kid
);
11494 kid
= kid
->GetNextSibling();
11496 lineFrame
->SetInitialChildList(nsnull
, firstInlineFrame
);
11499 rv
= NS_ERROR_OUT_OF_MEMORY
;
11505 // Special routine to handle appending a new frame to a block frame's
11506 // child list. Takes care of placing the new frame into the right
11507 // place when first-line style is present.
11509 nsCSSFrameConstructor::AppendFirstLineFrames(
11510 nsFrameConstructorState
& aState
,
11511 nsIContent
* aBlockContent
,
11512 nsIFrame
* aBlockFrame
,
11513 nsFrameItems
& aFrameItems
)
11515 // It's possible that aBlockFrame needs to have a first-line frame
11516 // created because it doesn't currently have any children.
11517 nsIFrame
* blockKid
= aBlockFrame
->GetFirstChild(nsnull
);
11519 return WrapFramesInFirstLineFrame(aState
, aBlockContent
,
11520 aBlockFrame
, aFrameItems
);
11523 // Examine the last block child - if it's a first-line frame then
11524 // appended frames need special treatment.
11525 nsresult rv
= NS_OK
;
11526 nsFrameList
blockFrames(blockKid
);
11527 nsIFrame
* lastBlockKid
= blockFrames
.LastChild();
11528 if (lastBlockKid
->GetType() != nsGkAtoms::lineFrame
) {
11529 // No first-line frame at the end of the list, therefore there is
11530 // an interveening block between any first-line frame the frames
11531 // we are appending. Therefore, we don't need any special
11532 // treatment of the appended frames.
11535 nsIFrame
* lineFrame
= lastBlockKid
;
11537 // Find the first and last inline frame in aFrameItems
11538 nsIFrame
* kid
= aFrameItems
.childList
;
11539 nsIFrame
* firstInlineFrame
= nsnull
;
11540 nsIFrame
* lastInlineFrame
= nsnull
;
11542 if (IsInlineOutside(kid
)) {
11543 if (!firstInlineFrame
) firstInlineFrame
= kid
;
11544 lastInlineFrame
= kid
;
11549 kid
= kid
->GetNextSibling();
11552 // If we don't find any inline frames, then there is nothing to do
11553 if (!firstInlineFrame
) {
11557 // The inline frames get appended to the lineFrame. Make sure they
11558 // are reparented properly.
11559 nsIFrame
* remainingFrames
= lastInlineFrame
->GetNextSibling();
11560 lastInlineFrame
->SetNextSibling(nsnull
);
11561 kid
= firstInlineFrame
;
11563 ReparentFrame(aState
.mFrameManager
, lineFrame
, kid
);
11564 kid
= kid
->GetNextSibling();
11566 aState
.mFrameManager
->AppendFrames(lineFrame
, nsnull
, firstInlineFrame
);
11568 // The remaining frames get appended to the block frame
11569 if (remainingFrames
) {
11570 aFrameItems
.childList
= remainingFrames
;
11573 aFrameItems
.childList
= nsnull
;
11574 aFrameItems
.lastChild
= nsnull
;
11580 // Special routine to handle inserting a new frame into a block
11581 // frame's child list. Takes care of placing the new frame into the
11582 // right place when first-line style is present.
11584 nsCSSFrameConstructor::InsertFirstLineFrames(
11585 nsFrameConstructorState
& aState
,
11586 nsIContent
* aContent
,
11587 nsIFrame
* aBlockFrame
,
11588 nsIFrame
** aParentFrame
,
11589 nsIFrame
* aPrevSibling
,
11590 nsFrameItems
& aFrameItems
)
11592 nsresult rv
= NS_OK
;
11593 // XXXbz If you make this method actually do something, check to make sure
11594 // that the caller is passing what you expect. In particular, which content
11597 nsIFrame
* parentFrame
= *aParentFrame
;
11598 nsIFrame
* newFrame
= aFrameItems
.childList
;
11599 PRBool isInline
= IsInlineOutside(newFrame
);
11601 if (!aPrevSibling
) {
11602 // Insertion will become the first frame. Two cases: we either
11603 // already have a first-line frame or we don't.
11604 nsIFrame
* firstBlockKid
= aBlockFrame
->GetFirstChild(nsnull
);
11605 if (firstBlockKid
->GetType() == nsGkAtoms::lineFrame
) {
11606 // We already have a first-line frame
11607 nsIFrame
* lineFrame
= firstBlockKid
;
11610 // Easy case: the new inline frame will go into the lineFrame.
11611 ReparentFrame(aState
.mFrameManager
, lineFrame
, newFrame
);
11612 aState
.mFrameManager
->InsertFrames(lineFrame
, nsnull
, nsnull
,
11615 // Since the frame is going into the lineFrame, don't let it
11616 // go into the block too.
11617 aFrameItems
.childList
= nsnull
;
11618 aFrameItems
.lastChild
= nsnull
;
11621 // Harder case: We are about to insert a block level element
11622 // before the first-line frame.
11623 // XXX need a method to steal away frames from the line-frame
11627 // We do not have a first-line frame
11629 // We now need a first-line frame to contain the inline frame.
11630 nsIFrame
* lineFrame
= NS_NewFirstLineFrame(firstLineStyle
);
11632 rv
= NS_ERROR_OUT_OF_MEMORY
;
11635 if (NS_SUCCEEDED(rv
)) {
11636 // Lookup first-line style context
11637 nsStyleContext
* parentStyle
=
11638 nsFrame::CorrectStyleParentFrame(aBlockFrame
,
11639 nsCSSPseudoElements::firstLine
)->
11641 nsRefPtr
<nsStyleContext
> firstLineStyle
=
11642 GetFirstLineStyle(aContent
, parentStyle
);
11644 // Initialize the line frame
11645 rv
= InitAndRestoreFrame(aState
, aContent
, aBlockFrame
,
11646 nsnull
, lineFrame
);
11648 // Make sure the caller inserts the lineFrame into the
11649 // blocks list of children.
11650 aFrameItems
.childList
= lineFrame
;
11651 aFrameItems
.lastChild
= lineFrame
;
11653 // Give the inline frames to the lineFrame <b>after</b>
11654 // reparenting them
11655 NS_ASSERTION(lineFrame
->GetStyleContext() == firstLineStyle
,
11656 "Bogus style context on line frame");
11657 ReparentFrame(aPresContext
, lineFrame
, newFrame
);
11658 lineFrame
->SetInitialChildList(nsnull
, newFrame
);
11662 // Easy case: the regular insertion logic can insert the new
11663 // frame because it's a block frame.
11668 // Insertion will not be the first frame.
11669 nsIFrame
* prevSiblingParent
= aPrevSibling
->GetParent();
11670 if (prevSiblingParent
== aBlockFrame
) {
11671 // Easy case: The prev-siblings parent is the block
11672 // frame. Therefore the prev-sibling is not currently in a
11673 // line-frame. Therefore the new frame which is going after it,
11674 // regardless of type, is not going into a line-frame.
11677 // If the prevSiblingParent is not the block-frame then it must
11678 // be a line-frame (if it were a letter-frame, that logic would
11679 // already have adjusted the prev-sibling to be the
11682 // Easy case: the insertion can go where the caller thinks it
11683 // should go (which is into prevSiblingParent).
11686 // Block elements don't end up in line-frames, therefore
11687 // change the insertion point to aBlockFrame. However, there
11688 // might be more inline elements following aPrevSibling that
11689 // need to be pulled out of the line-frame and become children
11691 nsIFrame
* nextSibling
= aPrevSibling
->GetNextSibling();
11692 nsIFrame
* nextLineFrame
= prevSiblingParent
->GetNextInFlow();
11693 if (nextSibling
|| nextLineFrame
) {
11694 // Oy. We have work to do. Create a list of the new frames
11695 // that are going into the block by stripping them away from
11696 // the line-frame(s).
11697 nsFrameList
list(nextSibling
);
11699 nsLineFrame
* lineFrame
= (nsLineFrame
*) prevSiblingParent
;
11700 lineFrame
->StealFramesFrom(nextSibling
);
11703 nsLineFrame
* nextLineFrame
= (nsLineFrame
*) lineFrame
;
11705 nextLineFrame
= nextLineFrame
->GetNextInFlow();
11706 if (!nextLineFrame
) {
11709 nsIFrame
* kids
= nextLineFrame
->GetFirstChild(nsnull
);
11713 // We got lucky: aPrevSibling was the last inline frame in
11715 ReparentFrame(aState
.mFrameManager
, aBlockFrame
, newFrame
);
11716 aState
.mFrameManager
->InsertFrames(aBlockFrame
, nsnull
,
11717 prevSiblingParent
, newFrame
);
11718 aFrameItems
.childList
= nsnull
;
11719 aFrameItems
.lastChild
= nsnull
;
11729 //----------------------------------------------------------------------
11731 // First-letter support
11733 // Determine how many characters in the text fragment apply to the
11736 FirstLetterCount(const nsTextFragment
* aFragment
)
11739 PRInt32 firstLetterLength
= 0;
11740 PRBool done
= PR_FALSE
;
11742 PRInt32 i
, n
= aFragment
->GetLength();
11743 for (i
= 0; i
< n
; i
++) {
11744 PRUnichar ch
= aFragment
->CharAt(i
);
11745 if (XP_IS_SPACE(ch
)) {
11746 if (firstLetterLength
) {
11754 if ((ch
== '\'') || (ch
== '\"')) {
11755 if (firstLetterLength
) {
11760 firstLetterLength
= 1;
11773 NeedFirstLetterContinuation(nsIContent
* aContent
)
11775 NS_PRECONDITION(aContent
, "null ptr");
11777 PRBool result
= PR_FALSE
;
11779 const nsTextFragment
* frag
= aContent
->GetText();
11781 PRInt32 flc
= FirstLetterCount(frag
);
11782 PRInt32 tl
= frag
->GetLength();
11791 static PRBool
IsFirstLetterContent(nsIContent
* aContent
)
11793 return aContent
->TextLength() &&
11794 !aContent
->TextIsOnlyWhitespace();
11798 * Create a letter frame, only make it a floating frame.
11801 nsCSSFrameConstructor::CreateFloatingLetterFrame(
11802 nsFrameConstructorState
& aState
,
11803 nsIFrame
* aBlockFrame
,
11804 nsIContent
* aTextContent
,
11805 nsIFrame
* aTextFrame
,
11806 nsIContent
* aBlockContent
,
11807 nsIFrame
* aParentFrame
,
11808 nsStyleContext
* aStyleContext
,
11809 nsFrameItems
& aResult
)
11811 // Create the first-letter-frame
11813 nsIFrame
* letterFrame
;
11814 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
11816 letterFrame
= NS_NewFirstLetterFrame(mPresShell
, aStyleContext
);
11817 // We don't want to use a text content for a non-text frame (because we want
11818 // its primary frame to be a text frame). So use its parent for the
11820 nsIContent
* letterContent
= aTextContent
->GetParent();
11821 InitAndRestoreFrame(aState
, letterContent
,
11822 aState
.GetGeometricParent(aStyleContext
->GetStyleDisplay(),
11824 nsnull
, letterFrame
);
11826 // Init the text frame to refer to the letter frame. Make sure we
11827 // get a proper style context for it (the one passed in is for the
11828 // letter frame and will have the float property set on it; the text
11829 // frame shouldn't have that set).
11830 nsRefPtr
<nsStyleContext
> textSC
;
11831 textSC
= styleSet
->ResolveStyleForNonElement(aStyleContext
);
11832 aTextFrame
->SetStyleContextWithoutNotification(textSC
);
11833 InitAndRestoreFrame(aState
, aTextContent
, letterFrame
, nsnull
, aTextFrame
);
11835 // And then give the text frame to the letter frame
11836 letterFrame
->SetInitialChildList(nsnull
, aTextFrame
);
11838 // See if we will need to continue the text frame (does it contain
11839 // more than just the first-letter text or not?) If it does, then we
11840 // create (in advance) a continuation frame for it.
11841 nsIFrame
* nextTextFrame
= nsnull
;
11842 if (NeedFirstLetterContinuation(aTextContent
)) {
11843 // Create continuation
11844 rv
= CreateContinuingFrame(aState
.mPresContext
, aTextFrame
, aParentFrame
,
11846 if (NS_FAILED(rv
)) {
11847 letterFrame
->Destroy();
11850 // Repair the continuations style context
11851 nsStyleContext
* parentStyleContext
= aStyleContext
->GetParent();
11852 if (parentStyleContext
) {
11853 nsRefPtr
<nsStyleContext
> newSC
;
11854 newSC
= styleSet
->ResolveStyleForNonElement(parentStyleContext
);
11856 nextTextFrame
->SetStyleContext(newSC
);
11861 NS_ASSERTION(aResult
.childList
== nsnull
,
11862 "aResult should be an empty nsFrameItems!");
11863 nsIFrame
* insertAfter
= nsnull
;
11865 // Put the new float before any of the floats in the block we're
11866 // doing first-letter for, that is, before any floats whose parent is aBlockFrame
11867 for (f
= aState
.mFloatedItems
.childList
; f
; f
= f
->GetNextSibling()) {
11868 if (f
->GetParent() == aBlockFrame
)
11873 rv
= aState
.AddChild(letterFrame
, aResult
, letterContent
, aStyleContext
,
11874 aParentFrame
, PR_FALSE
, PR_TRUE
, PR_FALSE
, PR_TRUE
,
11877 if (nextTextFrame
) {
11878 if (NS_FAILED(rv
)) {
11879 nextTextFrame
->Destroy();
11881 aResult
.AddChild(nextTextFrame
);
11887 * Create a new letter frame for aTextFrame. The letter frame will be
11888 * a child of aParentFrame.
11891 nsCSSFrameConstructor::CreateLetterFrame(nsFrameConstructorState
& aState
,
11892 nsIFrame
* aBlockFrame
,
11893 nsIContent
* aTextContent
,
11894 nsIFrame
* aParentFrame
,
11895 nsFrameItems
& aResult
)
11897 NS_PRECONDITION(aTextContent
->IsNodeOfType(nsINode::eTEXT
),
11898 "aTextContent isn't text");
11899 NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlockFrame
),
11900 "Not a block frame?");
11902 // Get style context for the first-letter-frame
11903 nsStyleContext
* parentStyleContext
=
11904 nsFrame::CorrectStyleParentFrame(aParentFrame
,
11905 nsCSSPseudoElements::firstLetter
)->
11907 // Use content from containing block so that we can actually
11908 // find a matching style rule.
11909 nsIContent
* blockContent
=
11910 aState
.mFloatedItems
.containingBlock
->GetContent();
11912 NS_ASSERTION(blockContent
== aBlockFrame
->GetContent(),
11913 "Unexpected block content");
11915 // Create first-letter style rule
11916 nsRefPtr
<nsStyleContext
> sc
= GetFirstLetterStyle(blockContent
,
11917 parentStyleContext
);
11919 nsRefPtr
<nsStyleContext
> textSC
;
11920 textSC
= mPresShell
->StyleSet()->ResolveStyleForNonElement(sc
);
11922 // Create a new text frame (the original one will be discarded)
11923 // pass a temporary stylecontext, the correct one will be set later
11924 nsIFrame
* textFrame
= NS_NewTextFrame(mPresShell
, textSC
);
11926 // Create the right type of first-letter frame
11927 const nsStyleDisplay
* display
= sc
->GetStyleDisplay();
11928 if (display
->IsFloating()) {
11929 // Make a floating first-letter frame
11930 CreateFloatingLetterFrame(aState
, aBlockFrame
, aTextContent
, textFrame
,
11931 blockContent
, aParentFrame
,
11935 // Make an inflow first-letter frame
11936 nsIFrame
* letterFrame
= NS_NewFirstLetterFrame(mPresShell
, sc
);
11939 // Initialize the first-letter-frame. We don't want to use a text
11940 // content for a non-text frame (because we want its primary frame to
11941 // be a text frame). So use its parent for the first-letter.
11942 nsIContent
* letterContent
= aTextContent
->GetParent();
11943 letterFrame
->Init(letterContent
, aParentFrame
, nsnull
);
11945 InitAndRestoreFrame(aState
, aTextContent
, letterFrame
, nsnull
,
11948 letterFrame
->SetInitialChildList(nsnull
, textFrame
);
11949 aResult
.childList
= aResult
.lastChild
= letterFrame
;
11950 aBlockFrame
->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_CHILD
);
11959 nsCSSFrameConstructor::WrapFramesInFirstLetterFrame(
11960 nsFrameConstructorState
& aState
,
11961 nsIContent
* aBlockContent
,
11962 nsIFrame
* aBlockFrame
,
11963 nsFrameItems
& aBlockFrames
)
11965 nsresult rv
= NS_OK
;
11967 aBlockFrame
->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_STYLE
);
11969 nsIFrame
* parentFrame
= nsnull
;
11970 nsIFrame
* textFrame
= nsnull
;
11971 nsIFrame
* prevFrame
= nsnull
;
11972 nsFrameItems letterFrames
;
11973 PRBool stopLooking
= PR_FALSE
;
11974 rv
= WrapFramesInFirstLetterFrame(aState
, aBlockFrame
, aBlockFrame
,
11975 aBlockFrames
.childList
,
11976 &parentFrame
, &textFrame
, &prevFrame
,
11977 letterFrames
, &stopLooking
);
11978 if (NS_FAILED(rv
)) {
11982 if (parentFrame
== aBlockFrame
) {
11983 // Text textFrame out of the blocks frame list and substitute the
11984 // letter frame(s) instead.
11985 nsIFrame
* nextSibling
= textFrame
->GetNextSibling();
11986 textFrame
->SetNextSibling(nsnull
);
11988 prevFrame
->SetNextSibling(letterFrames
.childList
);
11991 aBlockFrames
.childList
= letterFrames
.childList
;
11993 letterFrames
.lastChild
->SetNextSibling(nextSibling
);
11995 // Destroy the old textFrame
11996 textFrame
->Destroy();
11998 // Repair lastChild; the only time this needs to happen is when
11999 // the block had one child (the text frame).
12000 if (!nextSibling
) {
12001 aBlockFrames
.lastChild
= letterFrames
.lastChild
;
12005 // Take the old textFrame out of the inline parents child list
12006 ::DeletingFrameSubtree(aState
.mFrameManager
, textFrame
);
12007 parentFrame
->RemoveFrame(nsnull
, textFrame
);
12009 // Insert in the letter frame(s)
12010 parentFrame
->InsertFrames(nsnull
, prevFrame
, letterFrames
.childList
);
12018 nsCSSFrameConstructor::WrapFramesInFirstLetterFrame(
12019 nsFrameConstructorState
& aState
,
12020 nsIFrame
* aBlockFrame
,
12021 nsIFrame
* aParentFrame
,
12022 nsIFrame
* aParentFrameList
,
12023 nsIFrame
** aModifiedParent
,
12024 nsIFrame
** aTextFrame
,
12025 nsIFrame
** aPrevFrame
,
12026 nsFrameItems
& aLetterFrames
,
12027 PRBool
* aStopLooking
)
12029 nsresult rv
= NS_OK
;
12031 nsIFrame
* prevFrame
= nsnull
;
12032 nsIFrame
* frame
= aParentFrameList
;
12035 nsIFrame
* nextFrame
= frame
->GetNextSibling();
12037 nsIAtom
* frameType
= frame
->GetType();
12038 if (nsGkAtoms::textFrame
== frameType
) {
12039 // Wrap up first-letter content in a letter frame
12040 nsIContent
* textContent
= frame
->GetContent();
12041 if (IsFirstLetterContent(textContent
)) {
12042 // Create letter frame to wrap up the text
12043 rv
= CreateLetterFrame(aState
, aBlockFrame
, textContent
,
12044 aParentFrame
, aLetterFrames
);
12045 if (NS_FAILED(rv
)) {
12049 // Provide adjustment information for parent
12050 *aModifiedParent
= aParentFrame
;
12051 *aTextFrame
= frame
;
12052 *aPrevFrame
= prevFrame
;
12053 *aStopLooking
= PR_TRUE
;
12057 else if (IsInlineFrame(frame
) && frameType
!= nsGkAtoms::brFrame
) {
12058 nsIFrame
* kids
= frame
->GetFirstChild(nsnull
);
12059 WrapFramesInFirstLetterFrame(aState
, aBlockFrame
, frame
, kids
,
12060 aModifiedParent
, aTextFrame
,
12061 aPrevFrame
, aLetterFrames
, aStopLooking
);
12062 if (*aStopLooking
) {
12067 // This will stop us looking to create more letter frames. For
12068 // example, maybe the frame-type is "letterFrame" or
12069 // "placeholderFrame". This keeps us from creating extra letter
12070 // frames, and also prevents us from creating letter frames when
12071 // the first real content child of a block is not text (e.g. an
12072 // image, hr, etc.)
12073 *aStopLooking
= PR_TRUE
;
12085 nsCSSFrameConstructor::RemoveFloatingFirstLetterFrames(
12086 nsPresContext
* aPresContext
,
12087 nsIPresShell
* aPresShell
,
12088 nsFrameManager
* aFrameManager
,
12089 nsIFrame
* aBlockFrame
,
12090 PRBool
* aStopLooking
)
12092 // First look for the float frame that is a letter frame
12093 nsIFrame
* floatFrame
= aBlockFrame
->GetFirstChild(nsGkAtoms::floatList
);
12094 while (floatFrame
) {
12095 // See if we found a floating letter frame
12096 if (nsGkAtoms::letterFrame
== floatFrame
->GetType()) {
12099 floatFrame
= floatFrame
->GetNextSibling();
12106 // Take the text frame away from the letter frame (so it isn't
12107 // destroyed when we destroy the letter frame).
12108 nsIFrame
* textFrame
= floatFrame
->GetFirstChild(nsnull
);
12113 // Discover the placeholder frame for the letter frame
12114 nsIFrame
* parentFrame
;
12115 nsPlaceholderFrame
* placeholderFrame
=
12116 aFrameManager
->GetPlaceholderFrameFor(floatFrame
);
12118 if (!placeholderFrame
) {
12119 // Somethings really wrong
12122 parentFrame
= placeholderFrame
->GetParent();
12123 if (!parentFrame
) {
12124 // Somethings really wrong
12128 // Create a new text frame with the right style context that maps
12129 // all of the content that was previously part of the letter frame
12130 // (and probably continued elsewhere).
12131 nsStyleContext
* parentSC
= parentFrame
->GetStyleContext();
12135 nsIContent
* textContent
= textFrame
->GetContent();
12136 if (!textContent
) {
12139 nsRefPtr
<nsStyleContext
> newSC
;
12140 newSC
= aPresShell
->StyleSet()->ResolveStyleForNonElement(parentSC
);
12144 nsIFrame
* newTextFrame
= NS_NewTextFrame(aPresShell
, newSC
);
12145 if (NS_UNLIKELY(!newTextFrame
)) {
12146 return NS_ERROR_OUT_OF_MEMORY
;;
12148 newTextFrame
->Init(textContent
, parentFrame
, nsnull
);
12150 // Destroy the old text frame's continuations (the old text frame
12151 // will be destroyed when its letter frame is destroyed).
12152 nsIFrame
* nextTextFrame
= textFrame
->GetNextContinuation();
12153 while (nextTextFrame
) {
12154 nsIFrame
* nextTextParent
= nextTextFrame
->GetParent();
12155 if (nextTextParent
) {
12156 nsSplittableFrame::RemoveFromFlow(nextTextFrame
);
12157 ::DeletingFrameSubtree(aFrameManager
, nextTextFrame
);
12158 aFrameManager
->RemoveFrame(nextTextParent
, nsnull
, nextTextFrame
);
12160 nextTextFrame
= textFrame
->GetNextContinuation();
12163 // First find out where (in the content) the placeholder frames
12164 // text is and its previous sibling frame, if any. Note that:
12165 // 1) The placeholder had better be in the principal child list of
12167 // 2) It's probably near the beginning (since we're a first-letter frame),
12168 // so just doing a linear search for the prevSibling is ok.
12169 // 3) Trying to use FindPreviousSibling will fail if the first-letter is in
12170 // anonymous content (eg generated content).
12171 nsFrameList
siblingList(parentFrame
->GetFirstChild(nsnull
));
12172 NS_ASSERTION(siblingList
.ContainsFrame(placeholderFrame
),
12173 "Placeholder not in parent's principal child list?");
12174 nsIFrame
* prevSibling
= siblingList
.GetPrevSiblingFor(placeholderFrame
);
12176 // Now that everything is set...
12177 #ifdef NOISY_FIRST_LETTER
12178 printf("RemoveFloatingFirstLetterFrames: textContent=%p oldTextFrame=%p newTextFrame=%p\n",
12179 textContent
.get(), textFrame
, newTextFrame
);
12182 UnregisterPlaceholderChain(aFrameManager
, placeholderFrame
);
12184 // Remove the float frame
12185 ::DeletingFrameSubtree(aFrameManager
, floatFrame
);
12186 aFrameManager
->RemoveFrame(aBlockFrame
, nsGkAtoms::floatList
,
12189 // Remove placeholder frame
12190 ::DeletingFrameSubtree(aFrameManager
, placeholderFrame
);
12191 aFrameManager
->RemoveFrame(parentFrame
, nsnull
, placeholderFrame
);
12193 // Insert text frame in its place
12194 aFrameManager
->InsertFrames(parentFrame
, nsnull
,
12195 prevSibling
, newTextFrame
);
12201 nsCSSFrameConstructor::RemoveFirstLetterFrames(nsPresContext
* aPresContext
,
12202 nsIPresShell
* aPresShell
,
12203 nsFrameManager
* aFrameManager
,
12205 PRBool
* aStopLooking
)
12207 nsIFrame
* prevSibling
= nsnull
;
12208 nsIFrame
* kid
= aFrame
->GetFirstChild(nsnull
);
12211 if (nsGkAtoms::letterFrame
== kid
->GetType()) {
12212 // Bingo. Found it. First steal away the text frame.
12213 nsIFrame
* textFrame
= kid
->GetFirstChild(nsnull
);
12218 // Create a new textframe
12219 nsStyleContext
* parentSC
= aFrame
->GetStyleContext();
12223 nsIContent
* textContent
= textFrame
->GetContent();
12224 if (!textContent
) {
12227 nsRefPtr
<nsStyleContext
> newSC
;
12228 newSC
= aPresShell
->StyleSet()->ResolveStyleForNonElement(parentSC
);
12232 textFrame
= NS_NewTextFrame(aPresShell
, newSC
);
12233 textFrame
->Init(textContent
, aFrame
, nsnull
);
12235 // Next rip out the kid and replace it with the text frame
12236 ::DeletingFrameSubtree(aFrameManager
, kid
);
12237 aFrameManager
->RemoveFrame(aFrame
, nsnull
, kid
);
12239 // Insert text frame in its place
12240 aFrameManager
->InsertFrames(aFrame
, nsnull
, prevSibling
, textFrame
);
12242 *aStopLooking
= PR_TRUE
;
12243 aFrame
->RemoveStateBits(NS_BLOCK_HAS_FIRST_LETTER_CHILD
);
12246 else if (IsInlineFrame(kid
)) {
12247 // Look inside child inline frame for the letter frame
12248 RemoveFirstLetterFrames(aPresContext
, aPresShell
, aFrameManager
, kid
,
12250 if (*aStopLooking
) {
12255 kid
= kid
->GetNextSibling();
12262 nsCSSFrameConstructor::RemoveLetterFrames(nsPresContext
* aPresContext
,
12263 nsIPresShell
* aPresShell
,
12264 nsFrameManager
* aFrameManager
,
12265 nsIFrame
* aBlockFrame
)
12267 aBlockFrame
= aBlockFrame
->GetFirstContinuation();
12269 PRBool stopLooking
= PR_FALSE
;
12272 rv
= RemoveFloatingFirstLetterFrames(aPresContext
, aPresShell
,
12274 aBlockFrame
, &stopLooking
);
12275 if (NS_SUCCEEDED(rv
) && !stopLooking
) {
12276 rv
= RemoveFirstLetterFrames(aPresContext
, aPresShell
, aFrameManager
,
12277 aBlockFrame
, &stopLooking
);
12282 aBlockFrame
= aBlockFrame
->GetNextContinuation();
12283 } while (aBlockFrame
);
12287 // Fixup the letter frame situation for the given block
12289 nsCSSFrameConstructor::RecoverLetterFrames(nsFrameConstructorState
& aState
,
12290 nsIFrame
* aBlockFrame
)
12292 aBlockFrame
= aBlockFrame
->GetFirstContinuation();
12294 nsIFrame
* parentFrame
= nsnull
;
12295 nsIFrame
* textFrame
= nsnull
;
12296 nsIFrame
* prevFrame
= nsnull
;
12297 nsFrameItems letterFrames
;
12298 PRBool stopLooking
= PR_FALSE
;
12301 // XXX shouldn't this bit be set already (bug 408493), assert instead?
12302 aBlockFrame
->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_STYLE
);
12303 rv
= WrapFramesInFirstLetterFrame(aState
, aBlockFrame
, aBlockFrame
,
12304 aBlockFrame
->GetFirstChild(nsnull
),
12305 &parentFrame
, &textFrame
, &prevFrame
,
12306 letterFrames
, &stopLooking
);
12307 if (NS_FAILED(rv
)) {
12313 aBlockFrame
= aBlockFrame
->GetNextContinuation();
12314 } while (aBlockFrame
);
12317 // Take the old textFrame out of the parents child list
12318 ::DeletingFrameSubtree(aState
.mFrameManager
, textFrame
);
12319 parentFrame
->RemoveFrame(nsnull
, textFrame
);
12321 // Insert in the letter frame(s)
12322 parentFrame
->InsertFrames(nsnull
, prevFrame
, letterFrames
.childList
);
12327 //----------------------------------------------------------------------
12329 // listbox Widget Routines
12332 nsCSSFrameConstructor::CreateListBoxContent(nsPresContext
* aPresContext
,
12333 nsIFrame
* aParentFrame
,
12334 nsIFrame
* aPrevFrame
,
12335 nsIContent
* aChild
,
12336 nsIFrame
** aNewFrame
,
12338 PRBool aIsScrollbar
,
12339 nsILayoutHistoryState
* aFrameState
)
12342 nsresult rv
= NS_OK
;
12344 // Construct a new frame
12345 if (nsnull
!= aParentFrame
) {
12346 nsFrameItems frameItems
;
12347 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
12348 GetAbsoluteContainingBlock(aParentFrame
),
12349 GetFloatContainingBlock(aParentFrame
),
12350 mTempFrameTreeState
);
12352 nsRefPtr
<nsStyleContext
> styleContext
;
12353 styleContext
= ResolveStyleContext(aParentFrame
, aChild
);
12355 // Pre-check for display "none" - only if we find that, do we create
12356 // any frame at all
12357 const nsStyleDisplay
* display
= styleContext
->GetStyleDisplay();
12359 if (NS_STYLE_DISPLAY_NONE
== display
->mDisplay
) {
12360 *aNewFrame
= nsnull
;
12366 rv
= ConstructFrameInternal(state
, aChild
,
12367 aParentFrame
, aChild
->Tag(),
12368 aChild
->GetNameSpaceID(),
12369 styleContext
, frameItems
, PR_FALSE
);
12370 if (!state
.mPseudoFrames
.IsEmpty()) {
12371 ProcessPseudoFrames(state
, frameItems
);
12374 nsIFrame
* newFrame
= frameItems
.childList
;
12375 *aNewFrame
= newFrame
;
12377 if (NS_SUCCEEDED(rv
) && (nsnull
!= newFrame
)) {
12378 // Notify the parent frame
12380 rv
= ((nsListBoxBodyFrame
*)aParentFrame
)->ListBoxAppendFrames(newFrame
);
12382 rv
= ((nsListBoxBodyFrame
*)aParentFrame
)->ListBoxInsertFrames(aPrevFrame
, newFrame
);
12390 return NS_ERROR_FAILURE
;
12394 //----------------------------------------
12397 nsCSSFrameConstructor::ConstructBlock(nsFrameConstructorState
& aState
,
12398 const nsStyleDisplay
* aDisplay
,
12399 nsIContent
* aContent
,
12400 nsIFrame
* aParentFrame
,
12401 nsIFrame
* aContentParentFrame
,
12402 nsStyleContext
* aStyleContext
,
12403 nsIFrame
** aNewFrame
,
12404 nsFrameItems
& aFrameItems
,
12405 PRBool aAbsPosContainer
)
12407 // Create column wrapper if necessary
12408 nsIFrame
* blockFrame
= *aNewFrame
;
12409 nsIFrame
* parent
= aParentFrame
;
12410 nsIFrame
* contentParent
= aContentParentFrame
;
12411 nsRefPtr
<nsStyleContext
> blockStyle
= aStyleContext
;
12412 const nsStyleColumn
* columns
= aStyleContext
->GetStyleColumn();
12414 if (columns
->mColumnCount
!= NS_STYLE_COLUMN_COUNT_AUTO
12415 || columns
->mColumnWidth
.GetUnit() != eStyleUnit_Auto
) {
12416 nsIFrame
* columnSetFrame
= nsnull
;
12417 columnSetFrame
= NS_NewColumnSetFrame(mPresShell
, aStyleContext
, 0);
12418 if (!columnSetFrame
) {
12419 return NS_ERROR_OUT_OF_MEMORY
;
12422 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, columnSetFrame
);
12423 // See if we need to create a view, e.g. the frame is absolutely positioned
12424 nsHTMLContainerFrame::CreateViewForFrame(columnSetFrame
, aContentParentFrame
,
12426 blockStyle
= mPresShell
->StyleSet()->
12427 ResolvePseudoStyleFor(aContent
, nsCSSAnonBoxes::columnContent
,
12429 contentParent
= columnSetFrame
;
12430 parent
= columnSetFrame
;
12431 *aNewFrame
= columnSetFrame
;
12433 columnSetFrame
->SetInitialChildList(nsnull
, blockFrame
);
12436 blockFrame
->SetStyleContextWithoutNotification(blockStyle
);
12437 InitAndRestoreFrame(aState
, aContent
, parent
, nsnull
, blockFrame
);
12439 nsresult rv
= aState
.AddChild(*aNewFrame
, aFrameItems
, aContent
,
12441 aContentParentFrame
? aContentParentFrame
:
12443 if (NS_FAILED(rv
)) {
12447 // See if we need to create a view, e.g. the frame is absolutely positioned
12448 nsHTMLContainerFrame::CreateViewForFrame(blockFrame
, contentParent
, PR_FALSE
);
12450 if (!mInitialContainingBlock
) {
12451 // The frame we're constructing will be the initial containing block.
12452 // Set mInitialContainingBlock before processing children.
12453 mInitialContainingBlock
= *aNewFrame
;
12456 // We should make the outer frame be the absolute containing block,
12457 // if one is required. We have to do this because absolute
12458 // positioning must be computed with respect to the CSS dimensions
12459 // of the element, which are the dimensions of the outer block. But
12460 // we can't really do that because only blocks can have absolute
12461 // children. So use the block and try to compensate with hacks
12462 // in nsBlockFrame::CalculateContainingBlockSizeForAbsolutes.
12463 nsFrameConstructorSaveState absoluteSaveState
;
12464 if (aAbsPosContainer
) {
12465 // NS_ASSERTION(aRelPos, "should have made area frame for this");
12466 aState
.PushAbsoluteContainingBlock(blockFrame
, absoluteSaveState
);
12469 // See if the block has first-letter style applied to it...
12470 PRBool haveFirstLetterStyle
, haveFirstLineStyle
;
12471 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
,
12472 &haveFirstLetterStyle
, &haveFirstLineStyle
);
12474 // Process the child content
12475 nsFrameItems childItems
;
12476 nsFrameConstructorSaveState floatSaveState
;
12477 aState
.PushFloatContainingBlock(blockFrame
, floatSaveState
,
12478 haveFirstLetterStyle
,
12479 haveFirstLineStyle
);
12480 rv
= ProcessChildren(aState
, aContent
, blockFrame
, PR_TRUE
, childItems
,
12483 CreateAnonymousFrames(aContent
->Tag(), aState
, aContent
, blockFrame
,
12484 PR_FALSE
, childItems
);
12486 // Set the frame's initial child list
12487 blockFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
12493 AreAllKidsInline(nsIFrame
* aFrameList
)
12495 nsIFrame
* kid
= aFrameList
;
12497 if (!IsInlineOutside(kid
)) {
12500 kid
= kid
->GetNextSibling();
12506 nsCSSFrameConstructor::ConstructInline(nsFrameConstructorState
& aState
,
12507 const nsStyleDisplay
* aDisplay
,
12508 nsIContent
* aContent
,
12509 nsIFrame
* aParentFrame
,
12510 nsStyleContext
* aStyleContext
,
12511 PRBool aIsPositioned
,
12512 nsIFrame
* aNewFrame
)
12514 // Initialize the frame
12515 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, aNewFrame
);
12517 nsFrameConstructorSaveState absoluteSaveState
; // definition cannot be inside next block
12518 // because the object's destructor is significant
12519 // this is part of the fix for bug 42372
12521 // Any inline frame might need a view (because of opacity, or fixed background)
12522 // XXXbz should we be passing in a non-null aContentParentFrame?
12523 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, nsnull
, PR_FALSE
);
12525 if (aIsPositioned
) {
12526 // Relatively positioned frames becomes a container for child
12527 // frames that are positioned
12528 aState
.PushAbsoluteContainingBlock(aNewFrame
, absoluteSaveState
);
12531 // Process the child content
12532 nsFrameItems childItems
;
12533 PRBool kidsAllInline
;
12534 nsresult rv
= ProcessInlineChildren(aState
, aContent
, aNewFrame
, PR_TRUE
,
12535 childItems
, &kidsAllInline
);
12536 if (kidsAllInline
) {
12537 // Set the inline frame's initial child list
12538 CreateAnonymousFrames(aContent
->Tag(), aState
, aContent
, aNewFrame
,
12539 PR_FALSE
, childItems
);
12541 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
12545 // This inline frame contains several types of children. Therefore
12546 // this frame has to be chopped into several pieces. We will produce
12547 // as a result of this 3 lists of children. The first list contains
12548 // all of the inline children that precede the first block child
12549 // (and may be empty). The second list contains all of the block
12550 // children and any inlines that are between them (and must not be
12551 // empty, otherwise - why are we here?). The final list contains all
12552 // of the inline children that follow the final block child.
12554 // Find the first block child which defines list1 and list2
12555 nsIFrame
* list1
= childItems
.childList
;
12556 nsIFrame
* prevToFirstBlock
;
12557 nsIFrame
* list2
= FindFirstBlock(list1
, &prevToFirstBlock
);
12558 if (prevToFirstBlock
) {
12559 prevToFirstBlock
->SetNextSibling(nsnull
);
12565 // Find the last block child which defines the end of list2 and the
12567 nsIFrame
* afterFirstBlock
= list2
->GetNextSibling();
12568 nsIFrame
* list3
= nsnull
;
12569 nsIFrame
* lastBlock
= FindLastBlock(afterFirstBlock
);
12573 list3
= lastBlock
->GetNextSibling();
12574 lastBlock
->SetNextSibling(nsnull
);
12576 // list1's frames belong to this inline frame so go ahead and take them
12577 aNewFrame
->SetInitialChildList(nsnull
, list1
);
12579 // list2's frames belong to an anonymous block that we create right
12580 // now. The anonymous block will be the parent of the block children
12582 nsIAtom
* blockStyle
;
12583 nsRefPtr
<nsStyleContext
> blockSC
;
12584 nsIFrame
* blockFrame
;
12585 if (aIsPositioned
) {
12586 blockStyle
= nsCSSAnonBoxes::mozAnonymousPositionedBlock
;
12588 blockSC
= mPresShell
->StyleSet()->
12589 ResolvePseudoStyleFor(aContent
, blockStyle
, aStyleContext
);
12591 blockFrame
= NS_NewRelativeItemWrapperFrame(mPresShell
, blockSC
, 0);
12594 blockStyle
= nsCSSAnonBoxes::mozAnonymousBlock
;
12596 blockSC
= mPresShell
->StyleSet()->
12597 ResolvePseudoStyleFor(aContent
, blockStyle
, aStyleContext
);
12599 blockFrame
= NS_NewBlockFrame(mPresShell
, blockSC
);
12602 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, blockFrame
, PR_FALSE
);
12604 // Any inline frame could have a view (e.g., opacity)
12605 // XXXbz should we be passing in a non-null aContentParentFrame?
12606 nsHTMLContainerFrame::CreateViewForFrame(blockFrame
, nsnull
, PR_FALSE
);
12608 if (blockFrame
->HasView() || aNewFrame
->HasView()) {
12609 // Move list2's frames into the new view
12610 nsHTMLContainerFrame::ReparentFrameViewList(aState
.mPresContext
, list2
,
12611 list2
->GetParent(), blockFrame
);
12614 blockFrame
->SetInitialChildList(nsnull
, list2
);
12616 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
12617 GetAbsoluteContainingBlock(blockFrame
),
12618 GetFloatContainingBlock(blockFrame
));
12620 // If we have an inline between two blocks all inside an inline and the inner
12621 // inline contains a float, the float will end up in the float list of the
12622 // parent block of the inline, but its parent pointer will be the anonymous
12623 // block we create... AdjustFloatParentPtrs() deals with this by moving the
12624 // float from the outer state |aState| to the inner |state|.
12625 MoveChildrenTo(state
.mFrameManager
, blockFrame
, list2
, nsnull
, &state
,
12628 // list3's frames belong to another inline frame
12629 nsIFrame
* inlineFrame
= nsnull
;
12631 // If we ever start constructing a second inline in the split even when
12632 // list3 is null, the logic in MaybeRecreateContainerForIBSplitterFrame
12633 // needs to be adjusted. Also, if you're changing this code also change
12636 inlineFrame
= MoveFramesToEndOfIBSplit(aState
, nsnull
,
12637 aIsPositioned
, aContent
,
12638 aStyleContext
, list3
,
12639 blockFrame
, nsnull
);
12643 // Mark the frames as special (note: marking for inlineFrame is handled by
12644 // MoveFramesToEndOfIBSplit). That way if any of the append/insert/remove
12645 // methods try to fiddle with the children, the containing block will be
12646 // reframed instead.
12647 SetFrameIsSpecial(aNewFrame
, blockFrame
);
12648 SetFrameIsSpecial(blockFrame
, inlineFrame
);
12649 MarkIBSpecialPrevSibling(blockFrame
, aNewFrame
);
12651 MarkIBSpecialPrevSibling(inlineFrame
, blockFrame
);
12655 if (gNoisyInlineConstruction
) {
12656 nsIFrameDebug
* frameDebug
;
12658 printf("nsCSSFrameConstructor::ConstructInline:\n");
12659 if (NS_SUCCEEDED(CallQueryInterface(aNewFrame
, &frameDebug
))) {
12660 printf(" ==> leading inline frame:\n");
12661 frameDebug
->List(stdout
, 2);
12663 if (NS_SUCCEEDED(CallQueryInterface(blockFrame
, &frameDebug
))) {
12664 printf(" ==> block frame:\n");
12665 frameDebug
->List(stdout
, 2);
12668 NS_SUCCEEDED(CallQueryInterface(inlineFrame
, &frameDebug
))) {
12669 printf(" ==> trailing inline frame:\n");
12670 frameDebug
->List(stdout
, 2);
12679 nsCSSFrameConstructor::MoveFramesToEndOfIBSplit(nsFrameConstructorState
& aState
,
12680 nsIFrame
* aExistingEndFrame
,
12681 PRBool aIsPositioned
,
12682 nsIContent
* aContent
,
12683 nsStyleContext
* aStyleContext
,
12684 nsIFrame
* aFramesToMove
,
12685 nsIFrame
* aBlockPart
,
12686 nsFrameConstructorState
* aTargetState
)
12688 NS_PRECONDITION(aFramesToMove
, "Must have frames to move");
12689 NS_PRECONDITION(aBlockPart
, "Must have a block part");
12691 nsIFrame
* inlineFrame
= aExistingEndFrame
;
12692 if (!inlineFrame
) {
12693 if (aIsPositioned
) {
12694 inlineFrame
= NS_NewPositionedInlineFrame(mPresShell
, aStyleContext
);
12697 inlineFrame
= NS_NewInlineFrame(mPresShell
, aStyleContext
);
12700 InitAndRestoreFrame(aState
, aContent
, aBlockPart
->GetParent(), nsnull
,
12701 inlineFrame
, PR_FALSE
);
12703 // Any frame might need a view
12704 // XXXbz should we be passing in a non-null aContentParentFrame?
12705 nsHTMLContainerFrame::CreateViewForFrame(inlineFrame
, nsnull
, PR_FALSE
);
12708 if (inlineFrame
->HasView() || aFramesToMove
->GetParent()->HasView()) {
12709 // Move list3's frames into the new view
12710 nsHTMLContainerFrame::ReparentFrameViewList(aState
.mPresContext
,
12712 aFramesToMove
->GetParent(),
12716 // Reparent (cheaply) the frames in list3
12717 nsIFrame
* existingFirstChild
= inlineFrame
->GetFirstChild(nsnull
);
12718 if (!existingFirstChild
&&
12719 (inlineFrame
->GetStateBits() & NS_FRAME_FIRST_REFLOW
)) {
12720 inlineFrame
->SetInitialChildList(nsnull
, aFramesToMove
);
12722 inlineFrame
->InsertFrames(nsnull
, nsnull
, aFramesToMove
);
12724 nsFrameConstructorState
* startState
= aTargetState
? &aState
: nsnull
;
12725 MoveChildrenTo(aState
.mFrameManager
, inlineFrame
, aFramesToMove
,
12726 existingFirstChild
, aTargetState
, startState
);
12727 SetFrameIsSpecial(inlineFrame
, nsnull
);
12728 return inlineFrame
;
12732 nsCSSFrameConstructor::ProcessInlineChildren(nsFrameConstructorState
& aState
,
12733 nsIContent
* aContent
,
12735 PRBool aCanHaveGeneratedContent
,
12736 nsFrameItems
& aFrameItems
,
12737 PRBool
* aKidsAllInline
)
12739 nsresult rv
= NS_OK
;
12740 nsStyleContext
* styleContext
= nsnull
;
12742 // save the pseudo frame state
12743 nsPseudoFrames prevPseudoFrames
;
12744 aState
.mPseudoFrames
.Reset(&prevPseudoFrames
);
12746 if (aCanHaveGeneratedContent
) {
12747 // Probe for generated content before
12748 styleContext
= aFrame
->GetStyleContext();
12749 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
12750 styleContext
, nsCSSPseudoElements::before
,
12754 // Iterate the child content objects and construct frames
12755 PRBool allKidsInline
= PR_TRUE
;
12756 ChildIterator iter
, last
;
12757 for (ChildIterator::Init(aContent
, &iter
, &last
);
12760 // Construct a child frame
12761 nsIFrame
* oldLastChild
= aFrameItems
.lastChild
;
12762 rv
= ConstructFrame(aState
, nsCOMPtr
<nsIContent
>(*iter
),
12763 aFrame
, aFrameItems
);
12765 if (NS_FAILED(rv
)) {
12769 // Examine newly added children (we may have added more than one
12770 // child if the child was another inline frame that ends up
12771 // being carved in 3 pieces) to maintain the allKidsInline flag.
12772 if (allKidsInline
) {
12774 if (oldLastChild
) {
12775 kid
= oldLastChild
->GetNextSibling();
12778 kid
= aFrameItems
.childList
;
12781 if (!IsInlineOutside(kid
)) {
12782 allKidsInline
= PR_FALSE
;
12785 kid
= kid
->GetNextSibling();
12790 if (aCanHaveGeneratedContent
) {
12791 // Probe for generated content after
12792 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
12793 styleContext
, nsCSSPseudoElements::after
,
12797 // process the current pseudo frame state
12798 if (!aState
.mPseudoFrames
.IsEmpty()) {
12799 ProcessPseudoFrames(aState
, aFrameItems
);
12800 // recompute allKidsInline to take into account new child frames
12801 // XXX we DON'T do this yet because anonymous table children should
12802 // be accepted as inline children, until we turn on inline-table.
12804 // allKidsInline = AreAllKidsInline(aFrameItems.childList);
12806 // restore the pseudo frame state
12807 aState
.mPseudoFrames
= prevPseudoFrames
;
12809 *aKidsAllInline
= allKidsInline
;
12815 DestroyNewlyCreatedFrames(nsFrameConstructorState
& aState
,
12816 nsIFrame
* aParentFrame
,
12817 const nsFrameItems
& aFrameList
)
12819 // Ok, reverse tracks: wipe out the frames we just created
12820 nsFrameManager
*frameManager
= aState
.mFrameManager
;
12822 // Destroy the frames. As we do make sure any content to frame mappings
12823 // or entries in the undisplayed content map are removed
12824 frameManager
->ClearAllUndisplayedContentIn(aParentFrame
->GetContent());
12826 CleanupFrameReferences(frameManager
, aFrameList
.childList
);
12827 if (aState
.mAbsoluteItems
.childList
) {
12828 CleanupFrameReferences(frameManager
, aState
.mAbsoluteItems
.childList
);
12830 if (aState
.mFixedItems
.childList
) {
12831 CleanupFrameReferences(frameManager
, aState
.mFixedItems
.childList
);
12833 if (aState
.mFloatedItems
.childList
) {
12834 CleanupFrameReferences(frameManager
, aState
.mFloatedItems
.childList
);
12837 if (aState
.mPopupItems
.childList
) {
12838 CleanupFrameReferences(frameManager
, aState
.mPopupItems
.childList
);
12841 nsFrameList
tmp(aFrameList
.childList
);
12842 tmp
.DestroyFrames();
12844 tmp
.SetFrames(aState
.mAbsoluteItems
.childList
);
12845 tmp
.DestroyFrames();
12846 aState
.mAbsoluteItems
.childList
= nsnull
;
12848 tmp
.SetFrames(aState
.mFixedItems
.childList
);
12849 tmp
.DestroyFrames();
12850 aState
.mFixedItems
.childList
= nsnull
;
12852 tmp
.SetFrames(aState
.mFloatedItems
.childList
);
12853 tmp
.DestroyFrames();
12854 aState
.mFloatedItems
.childList
= nsnull
;
12857 tmp
.SetFrames(aState
.mPopupItems
.childList
);
12858 tmp
.DestroyFrames();
12859 aState
.mPopupItems
.childList
= nsnull
;
12864 nsCSSFrameConstructor::WipeContainingBlock(nsFrameConstructorState
& aState
,
12865 nsIFrame
* aContainingBlock
,
12867 const nsFrameItems
& aFrameList
,
12869 nsIFrame
* aPrevSibling
)
12871 if (!aFrameList
.childList
) {
12875 // Before we go and append the frames, we must check for two
12876 // special situations.
12878 // Situation #1 is a XUL frame that contains frames that are required
12879 // to be wrapped in blocks.
12880 if (aFrame
->IsBoxFrame() &&
12881 !(aFrame
->GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK
) &&
12882 AnyKidsNeedBlockParent(aFrameList
.childList
)) {
12883 DestroyNewlyCreatedFrames(aState
, aFrame
, aFrameList
);
12884 RecreateFramesForContent(aFrame
->GetContent());
12888 // Situation #2 is an inline frame that will now contain block
12889 // frames. This is a no-no and the frame construction logic knows
12890 // how to fix this. See defition of IsInlineFrame() for what "an
12891 // inline" is. Whether we have "a block" is tested for by
12892 // AreAllKidsInline.
12894 // We also need to check for an append of content ending in an
12895 // inline to the block in an {ib} split or an insert of content
12896 // starting with an inline to the start of that block. If that
12897 // happens, we also need to reframe, since that content needs to go
12898 // into the following or preceding inline in the split.
12900 if (IsInlineFrame(aFrame
)) {
12901 // Nothing to do if all kids are inline
12902 if (AreAllKidsInline(aFrameList
.childList
)) {
12905 } else if (!IsFrameSpecial(aFrame
)) {
12908 // aFrame is the block in an {ib} split. Check that we're not
12909 // messing up either end of it.
12911 // Will be handled in AppendFrames(), unless we have floats that we can't
12912 // move out because there might be no float containing block to move them
12914 if (!aState
.mFloatedItems
.childList
) {
12918 // Walk up until we get a float containing block that's not part of an
12919 // {ib} split, since otherwise we might have to ship floats out of it
12921 nsIFrame
* floatContainer
= aFrame
;
12923 floatContainer
= GetFloatContainingBlock(
12924 GetIBSplitSpecialPrevSiblingForAnonymousBlock(floatContainer
));
12925 if (!floatContainer
) {
12928 if (!IsFrameSpecial(floatContainer
)) {
12934 if (aPrevSibling
&& !aPrevSibling
->GetNextSibling()) {
12935 // This is an append that won't go through AppendFrames. We can bail out
12936 // if the last frame we're appending is not inline
12937 if (!aFrameList
.lastChild
->GetStyleDisplay()->IsInlineOutside()) {
12941 // We can bail out if we're not inserting at the beginning or if
12942 // the first frame we're inserting is not inline.
12943 if (aPrevSibling
||
12944 !aFrameList
.childList
->GetStyleDisplay()->IsInlineOutside()) {
12950 DestroyNewlyCreatedFrames(aState
, aFrame
, aFrameList
);
12952 // If we don't have a containing block, start with aFrame and look for one.
12953 if (!aContainingBlock
) {
12954 aContainingBlock
= aFrame
;
12957 // To find the right block to reframe, just walk up the tree until we find a
12959 // 1) Not part of an IB split (not special)
12960 // 2) Not a pseudo-frame
12961 // 3) Not an inline frame
12962 // We're guaranteed to find one, since nsStyleContext::ApplyStyleFixups
12963 // enforces that the root is display:none, display:table, or display:block.
12964 // Note that walking up "too far" is OK in terms of correctness, even if it
12965 // might be a little inefficient. This is why we walk out of all
12966 // pseudo-frames -- telling which ones are or are not OK to walk out of is
12967 // too hard (and I suspect that we do in fact need to walk out of all of
12969 while (IsFrameSpecial(aContainingBlock
) || IsInlineOutside(aContainingBlock
) ||
12970 aContainingBlock
->GetStyleContext()->GetPseudoType()) {
12971 aContainingBlock
= aContainingBlock
->GetParent();
12972 NS_ASSERTION(aContainingBlock
,
12973 "Must have non-inline, non-special, non-pseudo frame as root "
12974 "(or child of root, for a table root)!");
12977 // Tell parent of the containing block to reformulate the
12978 // entire block. This is painful and definitely not optimal
12979 // but it will *always* get the right answer.
12981 nsIContent
*blockContent
= aContainingBlock
->GetContent();
12982 nsCOMPtr
<nsIContent
> parentContainer
= blockContent
->GetParent();
12984 if (gNoisyContentUpdates
) {
12985 printf("nsCSSFrameConstructor::WipeContainingBlock: blockContent=%p parentContainer=%p\n",
12986 static_cast<void*>(blockContent
),
12987 static_cast<void*>(parentContainer
));
12990 if (parentContainer
) {
12991 ReinsertContent(parentContainer
, blockContent
);
12993 else if (blockContent
->GetCurrentDoc() == mDocument
) {
12994 ReconstructDocElementHierarchyInternal();
13000 nsCSSFrameConstructor::ReframeContainingBlock(nsIFrame
* aFrame
)
13004 // ReframeContainingBlock is a NASTY routine, it causes terrible performance problems
13005 // so I want to see when it is happening! Unfortunately, it is happening way to often because
13006 // so much content on the web causes 'special' block-in-inline frame situations and we handle them
13008 if (gNoisyContentUpdates
) {
13009 printf("nsCSSFrameConstructor::ReframeContainingBlock frame=%p\n",
13010 static_cast<void*>(aFrame
));
13014 PRBool isReflowing
;
13015 mPresShell
->IsReflowLocked(&isReflowing
);
13017 // don't ReframeContainingBlock, this will result in a crash
13018 // if we remove a tree that's in reflow - see bug 121368 for testcase
13019 NS_ASSERTION(0, "Atemptted to nsCSSFrameConstructor::ReframeContainingBlock during a Reflow!!!");
13023 // Get the first "normal" ancestor of the target frame.
13024 nsIFrame
* containingBlock
= GetIBContainingBlockFor(aFrame
);
13025 if (containingBlock
) {
13026 // From here we look for the containing block in case the target
13027 // frame is already a block (which can happen when an inline frame
13028 // wraps some of its content in an anonymous block; see
13029 // ConstructInline)
13031 // NOTE: We used to get the FloatContainingBlock here, but it was often wrong.
13032 // GetIBContainingBlock works much better and provides the correct container in all cases
13033 // so GetFloatContainingBlock(aFrame) has been removed
13035 // And get the containingBlock's content
13036 nsCOMPtr
<nsIContent
> blockContent
= containingBlock
->GetContent();
13037 if (blockContent
) {
13038 // Now find the containingBlock's content's parent
13039 nsCOMPtr
<nsIContent
> parentContainer
= blockContent
->GetParent();
13040 if (parentContainer
) {
13042 if (gNoisyContentUpdates
) {
13043 printf(" ==> blockContent=%p, parentContainer=%p\n",
13044 static_cast<void*>(blockContent
),
13045 static_cast<void*>(parentContainer
));
13048 return ReinsertContent(parentContainer
, blockContent
);
13053 // If we get here, we're screwed!
13054 return ReconstructDocElementHierarchyInternal();
13058 nsCSSFrameConstructor::RemoveFixedItems(const nsFrameConstructorState
& aState
,
13059 nsIFrame
*aRootElementFrame
)
13063 if (mFixedContainingBlock
) {
13064 nsIFrame
*fixedChild
= nsnull
;
13066 fixedChild
= mFixedContainingBlock
->GetFirstChild(nsGkAtoms::fixedList
);
13067 if (fixedChild
&& fixedChild
== aRootElementFrame
) {
13068 // Skip the root element frame, if it happens to be fixed-positioned
13069 // It will be explicitly removed later in
13070 // ReconstructDocElementHierarchyInternal
13071 fixedChild
= fixedChild
->GetNextSibling();
13074 // Remove the placeholder so it doesn't end up sitting about pointing
13075 // to the removed fixed frame.
13076 nsPlaceholderFrame
*placeholderFrame
=
13077 aState
.mFrameManager
->GetPlaceholderFrameFor(fixedChild
);
13078 NS_ASSERTION(placeholderFrame
, "no placeholder for fixed-pos frame");
13079 NS_ASSERTION(placeholderFrame
->GetType() ==
13080 nsGkAtoms::placeholderFrame
,
13082 UnregisterPlaceholderChain(aState
.mFrameManager
, placeholderFrame
);
13083 nsIFrame
* placeholderParent
= placeholderFrame
->GetParent();
13084 ::DeletingFrameSubtree(aState
.mFrameManager
, placeholderFrame
);
13085 rv
= aState
.mFrameManager
->RemoveFrame(placeholderParent
, nsnull
,
13087 if (NS_FAILED(rv
)) {
13088 NS_WARNING("Error removing placeholder for fixed frame in RemoveFixedItems");
13092 ::DeletingFrameSubtree(aState
.mFrameManager
, fixedChild
);
13093 rv
= aState
.mFrameManager
->RemoveFrame(mFixedContainingBlock
,
13094 nsGkAtoms::fixedList
,
13096 if (NS_FAILED(rv
)) {
13097 NS_WARNING("Error removing frame from fixed containing block in RemoveFixedItems");
13101 } while(fixedChild
);
13103 NS_WARNING( "RemoveFixedItems called with no FixedContainingBlock data member set");
13109 nsCSSFrameConstructor::RestyleForAppend(nsIContent
* aContainer
,
13110 PRInt32 aNewIndexInContainer
)
13112 NS_ASSERTION(aContainer
, "must have container for append");
13115 for (PRInt32 index
= aNewIndexInContainer
;; ++index
) {
13116 nsIContent
*content
= aContainer
->GetChildAt(index
);
13118 NS_ASSERTION(index
!= aNewIndexInContainer
, "yikes, nothing appended");
13121 NS_ASSERTION(!content
->IsRootOfAnonymousSubtree(),
13122 "anonymous nodes should not be in child lists");
13126 PRUint32 selectorFlags
=
13127 aContainer
->GetFlags() & (NODE_ALL_SELECTOR_FLAGS
&
13128 ~NODE_HAS_SLOW_SELECTOR_NOAPPEND
);
13129 if (selectorFlags
== 0)
13132 if (selectorFlags
& NODE_HAS_SLOW_SELECTOR
) {
13133 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13134 // Restyling the container is the most we can do here, so we're done.
13138 if (selectorFlags
& NODE_HAS_EMPTY_SELECTOR
) {
13139 // see whether we need to restyle the container
13140 PRBool wasEmpty
= PR_TRUE
; // :empty or :-moz-only-whitespace
13141 for (PRInt32 index
= 0; index
< aNewIndexInContainer
; ++index
) {
13142 // We don't know whether we're testing :empty or :-moz-only-whitespace,
13143 // so be conservative and assume :-moz-only-whitespace (i.e., make
13144 // IsSignificantChild less likely to be true, and thus make us more
13145 // likely to restyle).
13146 if (nsStyleUtil::IsSignificantChild(aContainer
->GetChildAt(index
),
13147 PR_TRUE
, PR_FALSE
)) {
13148 wasEmpty
= PR_FALSE
;
13153 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13154 // Restyling the container is the most we can do here, so we're done.
13158 if (selectorFlags
& NODE_HAS_EDGE_CHILD_SELECTOR
) {
13159 // restyle the last element child before this node
13160 for (PRInt32 index
= aNewIndexInContainer
- 1; index
>= 0; --index
) {
13161 nsIContent
*content
= aContainer
->GetChildAt(index
);
13162 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
13163 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13170 // Restyling for a ContentInserted or CharacterDataChanged notification.
13171 // This could be used for ContentRemoved as well if we got the
13172 // notification before the removal happened (and sometimes
13173 // CharacterDataChanged is more like a removal than an addition).
13174 // The comments are written and variables are named in terms of it being
13175 // a ContentInserted notification.
13177 nsCSSFrameConstructor::RestyleForInsertOrChange(nsIContent
* aContainer
,
13178 nsIContent
* aChild
)
13180 NS_ASSERTION(!aChild
->IsRootOfAnonymousSubtree(),
13181 "anonymous nodes should not be in child lists");
13182 PRUint32 selectorFlags
=
13183 aContainer
? (aContainer
->GetFlags() & NODE_ALL_SELECTOR_FLAGS
) : 0;
13184 if (selectorFlags
== 0)
13187 if (selectorFlags
& (NODE_HAS_SLOW_SELECTOR
|
13188 NODE_HAS_SLOW_SELECTOR_NOAPPEND
)) {
13189 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13190 // Restyling the container is the most we can do here, so we're done.
13194 if (selectorFlags
& NODE_HAS_EMPTY_SELECTOR
) {
13195 // see whether we need to restyle the container
13196 PRBool wasEmpty
= PR_TRUE
; // :empty or :-moz-only-whitespace
13197 for (PRInt32 index
= 0; ; ++index
) {
13198 nsIContent
*child
= aContainer
->GetChildAt(index
);
13199 if (!child
) // last child
13201 if (child
== aChild
)
13203 // We don't know whether we're testing :empty or :-moz-only-whitespace,
13204 // so be conservative and assume :-moz-only-whitespace (i.e., make
13205 // IsSignificantChild less likely to be true, and thus make us more
13206 // likely to restyle).
13207 if (nsStyleUtil::IsSignificantChild(child
, PR_TRUE
, PR_FALSE
)) {
13208 wasEmpty
= PR_FALSE
;
13213 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13214 // Restyling the container is the most we can do here, so we're done.
13219 if (selectorFlags
& NODE_HAS_EDGE_CHILD_SELECTOR
) {
13220 // restyle the previously-first element child if it is after this node
13221 PRBool passedChild
= PR_FALSE
;
13222 for (PRInt32 index
= 0; ; ++index
) {
13223 nsIContent
*content
= aContainer
->GetChildAt(index
);
13225 break; // went through all children
13226 if (content
== aChild
) {
13227 passedChild
= PR_TRUE
;
13230 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
13232 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13237 // restyle the previously-last element child if it is before this node
13238 passedChild
= PR_FALSE
;
13239 for (PRInt32 index
= aContainer
->GetChildCount() - 1;
13240 index
>= 0; --index
) {
13241 nsIContent
*content
= aContainer
->GetChildAt(index
);
13242 if (content
== aChild
) {
13243 passedChild
= PR_TRUE
;
13246 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
13248 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13257 nsCSSFrameConstructor::RestyleForRemove(nsIContent
* aContainer
,
13258 nsIContent
* aOldChild
,
13259 PRInt32 aIndexInContainer
)
13261 NS_ASSERTION(!aOldChild
->IsRootOfAnonymousSubtree(),
13262 "anonymous nodes should not be in child lists");
13263 PRUint32 selectorFlags
=
13264 aContainer
? (aContainer
->GetFlags() & NODE_ALL_SELECTOR_FLAGS
) : 0;
13265 if (selectorFlags
== 0)
13268 if (selectorFlags
& (NODE_HAS_SLOW_SELECTOR
|
13269 NODE_HAS_SLOW_SELECTOR_NOAPPEND
)) {
13270 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13271 // Restyling the container is the most we can do here, so we're done.
13275 if (selectorFlags
& NODE_HAS_EMPTY_SELECTOR
) {
13276 // see whether we need to restyle the container
13277 PRBool isEmpty
= PR_TRUE
; // :empty or :-moz-only-whitespace
13278 for (PRInt32 index
= 0; ; ++index
) {
13279 nsIContent
*child
= aContainer
->GetChildAt(index
);
13280 if (!child
) // last child
13282 // We don't know whether we're testing :empty or :-moz-only-whitespace,
13283 // so be conservative and assume :-moz-only-whitespace (i.e., make
13284 // IsSignificantChild less likely to be true, and thus make us more
13285 // likely to restyle).
13286 if (nsStyleUtil::IsSignificantChild(child
, PR_TRUE
, PR_FALSE
)) {
13287 isEmpty
= PR_FALSE
;
13292 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13293 // Restyling the container is the most we can do here, so we're done.
13298 if (selectorFlags
& NODE_HAS_EDGE_CHILD_SELECTOR
) {
13299 // restyle the previously-first element child if it is after aOldChild
13300 for (PRInt32 index
= 0; ; ++index
) {
13301 nsIContent
*content
= aContainer
->GetChildAt(index
);
13303 break; // went through all children
13304 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
13305 if (index
>= aIndexInContainer
) {
13306 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13311 // restyle the previously-last element child if it is before aOldChild
13312 for (PRInt32 index
= aContainer
->GetChildCount() - 1;
13313 index
>= 0; --index
) {
13314 nsIContent
*content
= aContainer
->GetChildAt(index
);
13315 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
13316 if (index
< aIndexInContainer
) {
13317 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
13326 static PLDHashOperator
13327 CollectRestyles(nsISupports
* aContent
,
13328 nsCSSFrameConstructor::RestyleData
& aData
,
13329 void* aRestyleArrayPtr
)
13331 nsCSSFrameConstructor::RestyleEnumerateData
** restyleArrayPtr
=
13332 static_cast<nsCSSFrameConstructor::RestyleEnumerateData
**>
13333 (aRestyleArrayPtr
);
13334 nsCSSFrameConstructor::RestyleEnumerateData
* currentRestyle
=
13336 currentRestyle
->mContent
= static_cast<nsIContent
*>(aContent
);
13337 currentRestyle
->mRestyleHint
= aData
.mRestyleHint
;
13338 currentRestyle
->mChangeHint
= aData
.mChangeHint
;
13340 // Increment to the next slot in the array
13341 *restyleArrayPtr
= currentRestyle
+ 1;
13343 return PL_DHASH_NEXT
;
13347 nsCSSFrameConstructor::ProcessOneRestyle(nsIContent
* aContent
,
13348 nsReStyleHint aRestyleHint
,
13349 nsChangeHint aChangeHint
)
13351 NS_PRECONDITION(aContent
, "Must have content node");
13353 if (!aContent
->IsInDoc() ||
13354 aContent
->GetCurrentDoc() != mDocument
) {
13355 // Content node has been removed from our document; nothing else
13360 nsIFrame
* primaryFrame
= mPresShell
->GetPrimaryFrameFor(aContent
);
13361 if (aRestyleHint
& eReStyle_Self
) {
13362 RestyleElement(aContent
, primaryFrame
, aChangeHint
);
13363 } else if (aChangeHint
&&
13365 (aChangeHint
& nsChangeHint_ReconstructFrame
))) {
13366 // Don't need to recompute style; just apply the hint
13367 nsStyleChangeList changeList
;
13368 changeList
.AppendChange(primaryFrame
, aContent
, aChangeHint
);
13369 ProcessRestyledFrames(changeList
);
13372 if (aRestyleHint
& eReStyle_LaterSiblings
) {
13373 RestyleLaterSiblings(aContent
);
13377 #define RESTYLE_ARRAY_STACKSIZE 128
13380 nsCSSFrameConstructor::RebuildAllStyleData(nsChangeHint aExtraHint
)
13382 NS_ASSERTION(!(aExtraHint
& nsChangeHint_ReconstructFrame
),
13383 "Should not reconstruct the root of the frame tree. "
13384 "Use ReconstructDocElementHierarchy instead.");
13386 mRebuildAllStyleData
= PR_FALSE
;
13387 NS_UpdateHint(aExtraHint
, mRebuildAllExtraHint
);
13388 mRebuildAllExtraHint
= nsChangeHint(0);
13390 if (!mPresShell
|| !mPresShell
->GetRootFrame())
13393 // Processing the style changes could cause a flush that propagates to
13394 // the parent frame and thus destroys the pres shell.
13395 nsCOMPtr
<nsIPresShell
> kungFuDeathGrip(mPresShell
);
13397 // Tell the style set to get the old rule tree out of the way
13398 // so we can recalculate while maintaining rule tree immutability
13399 nsresult rv
= mPresShell
->StyleSet()->BeginReconstruct();
13403 // Recalculate all of the style contexts for the document
13404 // Note that we can ignore the return value of ComputeStyleChangeFor
13405 // because we never need to reframe the root frame
13406 // XXX This could be made faster by not rerunning rule matching
13407 // (but note that nsPresShell::SetPreferenceStyleRules currently depends
13408 // on us re-running rule matching here
13409 nsStyleChangeList changeList
;
13410 // XXX Does it matter that we're passing aExtraHint to the real root
13411 // frame and not the root node's primary frame?
13412 mPresShell
->FrameManager()->ComputeStyleChangeFor(mPresShell
->GetRootFrame(),
13413 &changeList
, aExtraHint
);
13414 // Process the required changes
13415 ProcessRestyledFrames(changeList
);
13416 // Tell the style set it's safe to destroy the old rule tree. We
13417 // must do this after the ProcessRestyledFrames call in case the
13418 // change list has frame reconstructs in it (since frames to be
13419 // reconstructed will still have their old style context pointers
13420 // until they are destroyed).
13421 mPresShell
->StyleSet()->EndReconstruct();
13425 nsCSSFrameConstructor::ProcessPendingRestyles()
13427 NS_PRECONDITION(mDocument
, "No document? Pshaw!\n");
13429 PRUint32 count
= mPendingRestyles
.Count();
13432 // Use the stack if we can, otherwise fall back on heap-allocation.
13433 nsAutoTArray
<RestyleEnumerateData
, RESTYLE_ARRAY_STACKSIZE
> restyleArr
;
13434 RestyleEnumerateData
* restylesToProcess
= restyleArr
.AppendElements(count
);
13436 if (!restylesToProcess
) {
13440 RestyleEnumerateData
* lastRestyle
= restylesToProcess
;
13441 mPendingRestyles
.Enumerate(CollectRestyles
, &lastRestyle
);
13443 NS_ASSERTION(lastRestyle
- restylesToProcess
== PRInt32(count
),
13444 "Enumeration screwed up somehow");
13446 // Clear the hashtable so we don't end up trying to process a restyle we're
13447 // already processing, sending us into an infinite loop.
13448 mPendingRestyles
.Clear();
13450 // Make sure to not rebuild quote or counter lists while we're
13451 // processing restyles
13454 for (RestyleEnumerateData
* currentRestyle
= restylesToProcess
;
13455 currentRestyle
!= lastRestyle
;
13456 ++currentRestyle
) {
13457 ProcessOneRestyle(currentRestyle
->mContent
,
13458 currentRestyle
->mRestyleHint
,
13459 currentRestyle
->mChangeHint
);
13465 mPresShell
->VerifyStyleTree();
13469 if (mRebuildAllStyleData
) {
13470 // We probably wasted a lot of work up above, but this seems safest
13471 // and it should be rarely used.
13472 RebuildAllStyleData(nsChangeHint(0));
13477 nsCSSFrameConstructor::PostRestyleEvent(nsIContent
* aContent
,
13478 nsReStyleHint aRestyleHint
,
13479 nsChangeHint aMinChangeHint
)
13481 if (NS_UNLIKELY(mIsDestroyingFrameTree
)) {
13482 NS_NOTREACHED("PostRestyleEvent after the shell is destroyed (bug 279505)");
13486 if (aRestyleHint
== 0 && !aMinChangeHint
) {
13487 // Nothing to do here
13491 NS_ASSERTION(aContent
->IsNodeOfType(nsINode::eELEMENT
),
13492 "Shouldn't be trying to restyle non-elements directly");
13494 RestyleData existingData
;
13495 existingData
.mRestyleHint
= nsReStyleHint(0);
13496 existingData
.mChangeHint
= NS_STYLE_HINT_NONE
;
13498 mPendingRestyles
.Get(aContent
, &existingData
);
13499 existingData
.mRestyleHint
=
13500 nsReStyleHint(existingData
.mRestyleHint
| aRestyleHint
);
13501 NS_UpdateHint(existingData
.mChangeHint
, aMinChangeHint
);
13503 mPendingRestyles
.Put(aContent
, existingData
);
13505 PostRestyleEventInternal();
13509 nsCSSFrameConstructor::PostRestyleEventInternal()
13511 if (!mRestyleEvent
.IsPending()) {
13512 nsRefPtr
<RestyleEvent
> ev
= new RestyleEvent(this);
13513 if (NS_FAILED(NS_DispatchToCurrentThread(ev
))) {
13514 NS_WARNING("failed to dispatch restyle event");
13517 mRestyleEvent
= ev
;
13523 nsCSSFrameConstructor::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint
)
13525 NS_ASSERTION(!(aExtraHint
& nsChangeHint_ReconstructFrame
),
13526 "Should not reconstruct the root of the frame tree. "
13527 "Use ReconstructDocElementHierarchy instead.");
13529 mRebuildAllStyleData
= PR_TRUE
;
13530 NS_UpdateHint(mRebuildAllExtraHint
, aExtraHint
);
13531 // Get a restyle event posted if necessary
13532 PostRestyleEventInternal();
13535 NS_IMETHODIMP
nsCSSFrameConstructor::RestyleEvent::Run()
13538 return NS_OK
; // event was revoked
13540 // Make sure that any restyles that happen from now on will go into
13542 mConstructor
->mRestyleEvent
.Forget();
13544 return mConstructor
->mPresShell
->FlushPendingNotifications(Flush_Style
);
13548 nsCSSFrameConstructor::LazyGenerateChildrenEvent::Run()
13550 mPresShell
->GetDocument()->FlushPendingNotifications(Flush_Layout
);
13552 // this is hard-coded to handle only menu popup frames
13553 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(mContent
);
13554 if (frame
&& frame
->GetType() == nsGkAtoms::menuPopupFrame
) {
13556 // it is possible that the frame is different than the one that requested
13557 // the lazy generation, but as long as it's a popup frame that hasn't
13558 // generated its children yet, that's OK.
13559 nsMenuPopupFrame
* menuPopupFrame
= static_cast<nsMenuPopupFrame
*>(frame
);
13560 if (menuPopupFrame
->HasGeneratedChildren()) {
13562 mCallback(mContent
, frame
, mArg
);
13567 // indicate that the children have been generated
13568 menuPopupFrame
->SetGeneratedChildren();
13571 nsCSSFrameConstructor
* fc
= mPresShell
->FrameConstructor();
13574 nsFrameItems childItems
;
13575 nsFrameConstructorState
state(mPresShell
, nsnull
, nsnull
, nsnull
);
13576 nsresult rv
= fc
->ProcessChildren(state
, mContent
, frame
, PR_FALSE
,
13577 childItems
, PR_FALSE
);
13581 fc
->CreateAnonymousFrames(mContent
->Tag(), state
, mContent
, frame
,
13582 PR_FALSE
, childItems
);
13583 frame
->SetInitialChildList(nsnull
, childItems
.childList
);
13588 mCallback(mContent
, frame
, mArg
);
13590 // call XBL constructors after the frames are created
13591 mPresShell
->GetDocument()->BindingManager()->ProcessAttachedQueue();