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"
126 #include "nsTArray.h"
129 #include "nsIRootBox.h"
130 #include "nsIDOMXULCommandDispatcher.h"
131 #include "nsIDOMXULDocument.h"
132 #include "nsIXULDocument.h"
135 #include "nsIAccessibilityService.h"
136 #include "nsIAccessibleEvent.h"
139 #include "nsInlineFrame.h"
140 #include "nsBlockFrame.h"
142 #include "nsIScrollableFrame.h"
144 #include "nsIXBLService.h"
146 #undef NOISY_FIRST_LETTER
149 #include "nsMathMLParts.h"
152 #include "nsSVGEffects.h"
153 #include "nsSVGUtils.h"
154 #include "nsSVGOuterSVGFrame.h"
158 NS_NewHTMLCanvasFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
160 #if defined(MOZ_MEDIA)
162 NS_NewHTMLVideoFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
166 #include "nsISVGTextContentMetrics.h"
171 NS_NewSVGOuterSVGFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
173 NS_NewSVGInnerSVGFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
175 NS_NewSVGPathGeometryFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
177 NS_NewSVGGFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
179 NS_NewSVGGenericContainerFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
181 NS_NewSVGForeignObjectFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
183 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
185 NS_NewSVGGlyphFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
187 NS_NewSVGSwitchFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
189 NS_NewSVGTextFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
191 NS_NewSVGTSpanFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
193 NS_NewSVGContainerFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
195 NS_NewSVGUseFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
197 NS_SVG_PassesConditionalProcessingTests(nsIContent
*aContent
);
199 NS_NewSVGLinearGradientFrame(nsIPresShell
*aPresShell
, nsStyleContext
* aContext
);
201 NS_NewSVGRadialGradientFrame(nsIPresShell
*aPresShell
, nsStyleContext
* aContext
);
203 NS_NewSVGStopFrame(nsIPresShell
*aPresShell
, nsStyleContext
* aContext
);
205 NS_NewSVGMarkerFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
207 NS_NewSVGImageFrame(nsIPresShell
*aPresShell
, nsStyleContext
* aContext
);
209 NS_NewSVGClipPathFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
211 NS_NewSVGTextPathFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
213 NS_NewSVGFilterFrame(nsIPresShell
*aPresShell
, nsStyleContext
* aContext
);
215 NS_NewSVGPatternFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
217 NS_NewSVGMaskFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
219 NS_NewSVGLeafFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
222 #include "nsIDocument.h"
223 #include "nsIDOMElement.h"
224 #include "nsIDOMNodeList.h"
225 #include "nsIDOMDocument.h"
226 #include "nsIDOMDocumentXBL.h"
227 #include "nsIScrollable.h"
228 #include "nsINodeInfo.h"
230 #include "nsWidgetsCID.h"
231 #include "nsNodeInfoManager.h"
232 #include "nsContentCreatorFunctions.h"
233 #include "nsIServiceManager.h"
235 // Global object maintenance
236 nsIXBLService
* nsCSSFrameConstructor::gXBLService
= nsnull
;
239 // Set the environment variable GECKO_FRAMECTOR_DEBUG_FLAGS to one or
240 // more of the following flags (comma separated) for handy debug
242 static PRBool gNoisyContentUpdates
= PR_FALSE
;
243 static PRBool gReallyNoisyContentUpdates
= PR_FALSE
;
244 static PRBool gNoisyInlineConstruction
= PR_FALSE
;
245 static PRBool gVerifyFastFindFrame
= PR_FALSE
;
246 static PRBool gTablePseudoFrame
= PR_FALSE
;
248 struct FrameCtorDebugFlags
{
253 static FrameCtorDebugFlags gFlags
[] = {
254 { "content-updates", &gNoisyContentUpdates
},
255 { "really-noisy-content-updates", &gReallyNoisyContentUpdates
},
256 { "noisy-inline", &gNoisyInlineConstruction
},
257 { "fast-find-frame", &gVerifyFastFindFrame
},
258 { "table-pseudo", &gTablePseudoFrame
},
261 #define NUM_DEBUG_FLAGS (sizeof(gFlags) / sizeof(gFlags[0]))
266 #include "nsMenuFrame.h"
267 #include "nsPopupSetFrame.h"
268 #include "nsTreeColFrame.h"
269 #include "nsIBoxObject.h"
270 #include "nsPIListBoxObject.h"
271 #include "nsListBoxBodyFrame.h"
272 #include "nsListItemFrame.h"
273 #include "nsXULLabelFrame.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
);
293 NS_NewLeafBoxFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
296 NS_NewStackFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
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_NewGridRowLeafFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
337 NS_NewGridRowGroupFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
342 NS_NewTitleBarFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
345 NS_NewResizerFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
351 NS_NewHTMLScrollFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRBool aIsRoot
);
354 NS_NewXULScrollFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRBool aIsRoot
);
357 NS_NewSliderFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
360 NS_NewScrollbarFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
363 NS_NewScrollbarButtonFrame (nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
366 #ifdef NOISY_FINDFRAME
367 static PRInt32 FFWC_totalCount
=0;
368 static PRInt32 FFWC_doLoop
=0;
369 static PRInt32 FFWC_doSibling
=0;
370 static PRInt32 FFWC_recursions
=0;
371 static PRInt32 FFWC_nextInFlows
=0;
375 DeletingFrameSubtree(nsFrameManager
* aFrameManager
,
378 static inline nsIFrame
*
379 GetFieldSetBlockFrame(nsIFrame
* aFieldsetFrame
)
381 // Depends on the fieldset child frame order - see ConstructFieldSetFrame() below.
382 nsIFrame
* firstChild
= aFieldsetFrame
->GetFirstChild(nsnull
);
383 return firstChild
&& firstChild
->GetNextSibling() ? firstChild
->GetNextSibling() : firstChild
;
386 //----------------------------------------------------------------------
389 IsInlineOutside(nsIFrame
* aFrame
)
391 return aFrame
->GetStyleDisplay()->IsInlineOutside();
395 * True if aFrame is an actual inline frame in the sense of non-replaced
396 * display:inline CSS boxes. In other words, it can be affected by {ib}
397 * splitting and can contain first-letter frames. Basically, this is either an
398 * inline frame (positioned or otherwise) or an line frame (this last because
399 * it can contain first-letter and because inserting blocks in the middle of it
400 * needs to terminate it).
403 IsInlineFrame(const nsIFrame
* aFrame
)
405 return aFrame
->IsFrameOfType(nsIFrame::eLineParticipant
);
409 * If any children require a block parent, return the first such child.
410 * Otherwise return null.
413 AnyKidsNeedBlockParent(nsIFrame
*aFrameList
)
415 for (nsIFrame
*k
= aFrameList
; k
; k
= k
->GetNextSibling()) {
416 // Line participants, such as text and inline frames, can't be
417 // directly inside a XUL box; they must be wrapped in an
418 // intermediate block.
419 if (k
->IsFrameOfType(nsIFrame::eLineParticipant
)) {
420 return k
->GetContent();
426 // Reparent a frame into a wrapper frame that is a child of its old parent.
428 ReparentFrame(nsFrameManager
* aFrameManager
,
429 nsIFrame
* aNewParentFrame
,
432 aFrame
->SetParent(aNewParentFrame
);
433 aFrameManager
->ReParentStyleContext(aFrame
);
434 if (aFrame
->GetStateBits() &
435 (NS_FRAME_HAS_VIEW
| NS_FRAME_HAS_CHILD_WITH_VIEW
)) {
436 // No need to walk up the tree, since the bits are already set
437 // right on the parent of aNewParentFrame.
438 NS_ASSERTION(aNewParentFrame
->GetParent()->GetStateBits() &
439 NS_FRAME_HAS_CHILD_WITH_VIEW
,
440 "aNewParentFrame's parent should have this bit set!");
441 aNewParentFrame
->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW
);
445 //----------------------------------------------------------------------
447 // When inline frames get weird and have block frames in them, we
448 // annotate them to help us respond to incremental content changes
452 IsFrameSpecial(nsIFrame
* aFrame
)
454 return (aFrame
->GetStateBits() & NS_FRAME_IS_SPECIAL
) != 0;
457 static nsIFrame
* GetSpecialSibling(nsIFrame
* aFrame
)
459 // We only store the "special sibling" annotation with the first
460 // frame in the continuation chain. Walk back to find that frame now.
461 aFrame
= aFrame
->GetFirstContinuation();
463 void* value
= aFrame
->GetProperty(nsGkAtoms::IBSplitSpecialSibling
);
465 return static_cast<nsIFrame
*>(value
);
469 GetIBSplitSpecialPrevSiblingForAnonymousBlock(nsIFrame
* aFrame
)
471 NS_PRECONDITION(IsFrameSpecial(aFrame
) && !IsInlineFrame(aFrame
),
472 "Shouldn't call this");
474 // We only store the "special sibling" annotation with the first
475 // frame in the continuation chain. Walk back to find that frame now.
477 static_cast<nsIFrame
*>
478 (aFrame
->GetFirstContinuation()->
479 GetProperty(nsGkAtoms::IBSplitSpecialPrevSibling
));
483 GetLastSpecialSibling(nsIFrame
* aFrame
)
485 for (nsIFrame
*frame
= aFrame
, *next
; ; frame
= next
) {
486 next
= GetSpecialSibling(frame
);
490 NS_NOTREACHED("unreachable code");
495 SetFrameIsSpecial(nsIFrame
* aFrame
, nsIFrame
* aSpecialSibling
)
497 NS_PRECONDITION(aFrame
, "bad args!");
499 // Mark the frame and all of its siblings as "special".
500 for (nsIFrame
* frame
= aFrame
; frame
!= nsnull
; frame
= frame
->GetNextContinuation()) {
501 frame
->AddStateBits(NS_FRAME_IS_SPECIAL
);
504 if (aSpecialSibling
) {
505 // We should be the first-in-flow
506 NS_ASSERTION(!aFrame
->GetPrevInFlow(),
507 "assigning special sibling to other than first-in-flow!");
509 // Store the "special sibling" (if we were given one) with the
510 // first frame in the flow.
511 aFrame
->SetProperty(nsGkAtoms::IBSplitSpecialSibling
, aSpecialSibling
);
516 GetIBContainingBlockFor(nsIFrame
* aFrame
)
518 NS_PRECONDITION(IsFrameSpecial(aFrame
),
519 "GetIBContainingBlockFor() should only be called on known IB frames");
521 // Get the first "normal" ancestor of the target frame.
522 nsIFrame
* parentFrame
;
524 parentFrame
= aFrame
->GetParent();
527 NS_ERROR("no unsplit block frame in IB hierarchy");
531 // Note that we ignore non-special frames which have a pseudo on their
532 // style context -- they're not the frames we're looking for! In
533 // particular, they may be hiding a real parent that _is_ special.
534 if (!IsFrameSpecial(parentFrame
) &&
535 !parentFrame
->GetStyleContext()->GetPseudoType())
538 aFrame
= parentFrame
;
542 NS_ASSERTION(parentFrame
, "no normal ancestor found for special frame in GetIBContainingBlockFor");
543 NS_ASSERTION(parentFrame
!= aFrame
, "parentFrame is actually the child frame - bogus reslt");
548 //----------------------------------------------------------------------
550 // Block/inline frame construction logic. We maintain a few invariants here:
552 // 1. Block frames contain block and inline frames.
554 // 2. Inline frames only contain inline frames. If an inline parent has a block
555 // child then the block child is migrated upward until it lands in a block
556 // parent (the inline frames containing block is where it will end up).
559 FindFirstBlock(nsIFrame
* aKid
, nsIFrame
** aPrevKid
)
561 nsIFrame
* prevKid
= nsnull
;
563 if (!IsInlineOutside(aKid
)) {
568 aKid
= aKid
->GetNextSibling();
575 FindLastBlock(nsIFrame
* aKid
)
577 nsIFrame
* lastBlock
= nsnull
;
579 if (!IsInlineOutside(aKid
)) {
582 aKid
= aKid
->GetNextSibling();
588 * The special-prev-sibling is useful for
589 * finding the "special parent" of a frame (i.e., a frame from which a
590 * good parent style context can be obtained), one looks at the
591 * special previous sibling annotation of the real parent of the frame
592 * (if the real parent has NS_FRAME_IS_SPECIAL).
595 MarkIBSpecialPrevSibling(nsIFrame
*aAnonymousFrame
,
596 nsIFrame
*aSpecialParent
)
598 aAnonymousFrame
->SetProperty(nsGkAtoms::IBSplitSpecialPrevSibling
,
599 aSpecialParent
, nsnull
, nsnull
);
602 // -----------------------------------------------------------
605 IsOutOfFlowList(nsIAtom
* aListName
)
608 aListName
== nsGkAtoms::floatList
||
609 aListName
== nsGkAtoms::absoluteList
||
610 aListName
== nsGkAtoms::overflowOutOfFlowList
||
611 aListName
== nsGkAtoms::fixedList
;
614 // Helper function that recursively removes content to frame mappings and
615 // undisplayed content mappings.
616 // This differs from DeletingFrameSubtree() because the frames have not yet been
617 // added to the frame hierarchy.
618 // XXXbz it would really help if we merged the two methods somehow... :(
620 DoCleanupFrameReferences(nsFrameManager
* aFrameManager
,
623 nsIContent
* content
= aFrameIn
->GetContent();
625 if (aFrameIn
->GetType() == nsGkAtoms::placeholderFrame
) {
626 nsPlaceholderFrame
* placeholder
= static_cast<nsPlaceholderFrame
*>
628 // if the frame is a placeholder use the out of flow frame
629 aFrameIn
= nsPlaceholderFrame::GetRealFrameForPlaceholder(placeholder
);
631 // And don't forget to unregister the placeholder mapping. Note that this
632 // means it's the caller's responsibility to actually destroy the
633 // out-of-flow pointed to by the placeholder, since after this point the
634 // out-of-flow is not reachable via the placeholder.
635 aFrameManager
->UnregisterPlaceholderFrame(placeholder
);
638 // Remove the mapping from the content object to its frame
639 aFrameManager
->RemoveAsPrimaryFrame(content
, aFrameIn
);
640 aFrameManager
->ClearAllUndisplayedContentIn(content
);
642 // Recursively walk the child frames.
643 nsIAtom
* childListName
= nsnull
;
644 PRInt32 childListIndex
= 0;
646 nsIFrame
* childFrame
= aFrameIn
->GetFirstChild(childListName
);
648 DoCleanupFrameReferences(aFrameManager
, childFrame
);
650 // Get the next sibling child frame
651 childFrame
= childFrame
->GetNextSibling();
654 childListName
= aFrameIn
->GetAdditionalChildListName(childListIndex
++);
655 } while (childListName
);
658 // Helper function that walks a frame list and calls DoCleanupFrameReference()
660 CleanupFrameReferences(nsFrameManager
* aFrameManager
,
661 nsIFrame
* aFrameList
)
664 DoCleanupFrameReferences(aFrameManager
, aFrameList
);
666 // Get the sibling frame
667 aFrameList
= aFrameList
->GetNextSibling();
671 // -----------------------------------------------------------
673 // Structure used when constructing formatting object trees.
674 struct nsFrameItems
{
678 nsFrameItems(nsIFrame
* aFrame
= nsnull
);
680 // Appends the frame to the end of the list
681 void AddChild(nsIFrame
* aChild
);
683 // Inserts the frame somewhere in the list
684 void InsertChildAfter(nsIFrame
* aChild
, nsIFrame
* aAfter
);
686 // Remove the frame from the list, return PR_FALSE if not found. If
687 // aPrevSibling is given, it must have aChild as its GetNextSibling().
688 // aPrevSibling may be null to indicate that the list should be searched.
689 PRBool
RemoveChild(nsIFrame
* aChild
, nsIFrame
* aPrevSibling
);
692 nsFrameItems::nsFrameItems(nsIFrame
* aFrame
)
693 : childList(aFrame
), lastChild(aFrame
)
698 nsFrameItems::AddChild(nsIFrame
* aChild
)
701 nsIFrame
* oldLastChild
= lastChild
;
704 if (childList
== nsnull
) {
705 childList
= lastChild
= aChild
;
709 NS_ASSERTION(aChild
!= lastChild
,
710 "Same frame being added to frame list twice?");
711 lastChild
->SetNextSibling(aChild
);
714 // if aChild has siblings, lastChild needs to be the last one
715 for (nsIFrame
* sib
= lastChild
->GetNextSibling(); sib
;
716 sib
= sib
->GetNextSibling()) {
717 NS_ASSERTION(oldLastChild
!= sib
, "Loop in frame list");
723 nsFrameItems::InsertChildAfter(nsIFrame
* aChild
, nsIFrame
* aAfter
)
725 if (!childList
|| (aAfter
&& !aAfter
->GetNextSibling())) {
726 // Appending to the end of the list
731 // Inserting at beginning of list
732 aChild
->SetNextSibling(childList
);
736 aChild
->SetNextSibling(aAfter
->GetNextSibling());
737 aAfter
->SetNextSibling(aChild
);
741 nsFrameItems::RemoveChild(nsIFrame
* aFrame
, nsIFrame
* aPrevSibling
)
743 NS_PRECONDITION(aFrame
, "null ptr");
751 for (sib
= childList
; sib
&& sib
!= aFrame
; sib
= sib
->GetNextSibling()) {
759 NS_ASSERTION(!prev
|| prev
->GetNextSibling() == aFrame
,
760 "Unexpected prevsibling");
762 if (aFrame
== childList
) {
763 childList
= aFrame
->GetNextSibling();
765 prev
->SetNextSibling(aFrame
->GetNextSibling());
767 if (aFrame
== lastChild
) {
770 aFrame
->SetNextSibling(nsnull
);
774 // -----------------------------------------------------------
776 // Structure used when constructing formatting object trees. Contains
777 // state information needed for absolutely positioned elements
778 struct nsAbsoluteItems
: nsFrameItems
{
779 // containing block for absolutely positioned elements
780 nsIFrame
* containingBlock
;
782 nsAbsoluteItems(nsIFrame
* aContainingBlock
);
784 // XXXbz Does this need a debug-only assignment operator that nulls out the
785 // childList in the nsAbsoluteItems we're copying? Introducing a difference
786 // between debug and non-debug behavior seems bad, so I guess not...
788 NS_ASSERTION(!childList
,
789 "Dangling child list. Someone forgot to insert it?");
793 // Appends the frame to the end of the list
794 void AddChild(nsIFrame
* aChild
);
797 nsAbsoluteItems::nsAbsoluteItems(nsIFrame
* aContainingBlock
)
798 : containingBlock(aContainingBlock
)
802 // Additional behavior is that it sets the frame's NS_FRAME_OUT_OF_FLOW flag
804 nsAbsoluteItems::AddChild(nsIFrame
* aChild
)
806 NS_ASSERTION(aChild
->PresContext()->FrameManager()->
807 GetPlaceholderFrameFor(aChild
),
808 "Child without placeholder being added to nsAbsoluteItems?");
809 aChild
->AddStateBits(NS_FRAME_OUT_OF_FLOW
);
810 nsFrameItems::AddChild(aChild
);
813 // Structures used to record the creation of pseudo table frames where
814 // the content belongs to some ancestor.
815 // PseudoFrames are necessary when the childframe cannot be the direct
816 // ancestor of the content based parent frame. The amount of necessary pseudo
817 // frames is limited as the worst case would be table frame nested directly
818 // into another table frame. So the member structures of nsPseudoFrames can be
819 // viewed as a ring buffer where you start with the necessary frame type and
820 // add higher frames as long as necessary to fit into the initial parent frame.
821 // mLowestType is some sort of stack pointer which shows the start of the
822 // ringbuffer. The insertion of pseudo frames can happen between every
823 // two frames so we need to push and pop the pseudo frame data when children
824 // of a frame are created.
825 // The colgroup frame is special as it can harbour only col children.
826 // Once all children of given frame are known, the pseudo frames can be
827 // processed that means attached to the corresponding parent frames.
828 // The behaviour is in general described at
829 // http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes
830 // however there are implementation details that extend the CSS 2.1
832 // 1. every table frame is wrapped in an outer table frame, which is always a
834 // 2. the outer table frame will be also created to hold a caption.
835 // 3. each table cell will have a pseudo inner table cell frame.
836 // 4. a colgroup frame is created between a column and a table
837 // 5. a rowgroup frame is created between a row and a table
838 // A table frame can only have rowgroups or column groups as children.
839 // A outer table frame can only have one caption and one table frame
841 // Every table even if all table frames are specified will require the
842 // creation of two types of pseudo frames: the outer table frame and the inner
843 // table cell frames.
845 struct nsPseudoFrameData
{
846 nsIFrame
* mFrame
; // created pseudo frame
847 nsFrameItems mChildList
; // child frames pending to be added to the pseudo
848 nsFrameItems mChildList2
; // child frames pending to be added to the pseudo
851 nsPseudoFrameData(nsPseudoFrameData
& aOther
);
858 struct nsPseudoFrames
{
859 nsPseudoFrameData mTableOuter
;
860 nsPseudoFrameData mTableInner
;
861 nsPseudoFrameData mRowGroup
;
862 nsPseudoFrameData mColGroup
;
863 nsPseudoFrameData mRow
;
864 nsPseudoFrameData mCellOuter
;
865 nsPseudoFrameData mCellInner
;
867 // the frame type of the most descendant pseudo frame, no AddRef
868 nsIAtom
* mLowestType
;
871 nsPseudoFrames
& operator=(const nsPseudoFrames
& aOther
);
872 void Reset(nsPseudoFrames
* aSave
= nsnull
);
873 PRBool
IsEmpty() { return (!mLowestType
&& !mColGroup
.mFrame
); }
879 nsPseudoFrameData::nsPseudoFrameData()
880 : mFrame(nsnull
), mChildList(), mChildList2()
883 nsPseudoFrameData::nsPseudoFrameData(nsPseudoFrameData
& aOther
)
884 : mFrame(aOther
.mFrame
), mChildList(aOther
.mChildList
),
885 mChildList2(aOther
.mChildList2
)
889 nsPseudoFrameData::Reset()
892 mChildList
.childList
= mChildList
.lastChild
= nsnull
;
893 mChildList2
.childList
= mChildList2
.lastChild
= nsnull
;
898 nsPseudoFrameData::Dump()
900 nsIFrame
* main
= nsnull
;
901 nsIFrame
* second
= nsnull
;
902 printf(" %p\n", static_cast<void*>(mFrame
));
903 main
= mChildList
.childList
;
906 second
= mChildList2
.childList
;
907 while (main
|| second
) {
908 printf(" %p %p\n", static_cast<void*>(main
),
909 static_cast<void*>(second
));
911 main
= main
->GetNextSibling();
913 second
= second
->GetNextSibling();
917 nsPseudoFrames::nsPseudoFrames()
918 : mTableOuter(), mTableInner(), mRowGroup(), mColGroup(),
919 mRow(), mCellOuter(), mCellInner(), mLowestType(nsnull
)
922 nsPseudoFrames
& nsPseudoFrames::operator=(const nsPseudoFrames
& aOther
)
924 mTableOuter
= aOther
.mTableOuter
;
925 mTableInner
= aOther
.mTableInner
;
926 mColGroup
= aOther
.mColGroup
;
927 mRowGroup
= aOther
.mRowGroup
;
929 mCellOuter
= aOther
.mCellOuter
;
930 mCellInner
= aOther
.mCellInner
;
931 mLowestType
= aOther
.mLowestType
;
936 nsPseudoFrames::Reset(nsPseudoFrames
* aSave
)
949 mLowestType
= nsnull
;
954 nsPseudoFrames::Dump()
957 // check that it is really empty, warn otherwise
958 NS_ASSERTION(!mTableOuter
.mFrame
, "Pseudo Outer Table Frame not empty");
959 NS_ASSERTION(!mTableOuter
.mChildList
.childList
, "Pseudo Outer Table Frame has primary children");
960 NS_ASSERTION(!mTableOuter
.mChildList2
.childList
,"Pseudo Outer Table Frame has secondary children");
961 NS_ASSERTION(!mTableInner
.mFrame
, "Pseudo Inner Table Frame not empty");
962 NS_ASSERTION(!mTableInner
.mChildList
.childList
, "Pseudo Inner Table Frame has primary children");
963 NS_ASSERTION(!mTableInner
.mChildList2
.childList
,"Pseudo Inner Table Frame has secondary children");
964 NS_ASSERTION(!mColGroup
.mFrame
, "Pseudo Colgroup Frame not empty");
965 NS_ASSERTION(!mColGroup
.mChildList
.childList
, "Pseudo Colgroup Table Frame has primary children");
966 NS_ASSERTION(!mColGroup
.mChildList2
.childList
, "Pseudo Colgroup Table Frame has secondary children");
967 NS_ASSERTION(!mRowGroup
.mFrame
, "Pseudo Rowgroup Frame not empty");
968 NS_ASSERTION(!mRowGroup
.mChildList
.childList
, "Pseudo Rowgroup Frame has primary children");
969 NS_ASSERTION(!mRowGroup
.mChildList2
.childList
, "Pseudo Rowgroup Frame has secondary children");
970 NS_ASSERTION(!mRow
.mFrame
, "Pseudo Row Frame not empty");
971 NS_ASSERTION(!mRow
.mChildList
.childList
, "Pseudo Row Frame has primary children");
972 NS_ASSERTION(!mRow
.mChildList2
.childList
, "Pseudo Row Frame has secondary children");
973 NS_ASSERTION(!mCellOuter
.mFrame
, "Pseudo Outer Cell Frame not empty");
974 NS_ASSERTION(!mCellOuter
.mChildList
.childList
, "Pseudo Outer Cell Frame has primary children");
975 NS_ASSERTION(!mCellOuter
.mChildList2
.childList
, "Pseudo Outer Cell Frame has secondary children");
976 NS_ASSERTION(!mCellInner
.mFrame
, "Pseudo Inner Cell Frame not empty");
977 NS_ASSERTION(!mCellInner
.mChildList
.childList
, "Pseudo Inner Cell Frame has primary children");
978 NS_ASSERTION(!mCellInner
.mChildList2
.childList
, "Pseudo inner Cell Frame has secondary children");
981 if (mTableOuter
.mFrame
|| mTableOuter
.mChildList
.childList
|| mTableOuter
.mChildList2
.childList
) {
982 if (nsGkAtoms::tableOuterFrame
== mLowestType
) {
983 printf("LOW OuterTable\n");
986 printf(" OuterTable\n");
990 if (mTableInner
.mFrame
|| mTableInner
.mChildList
.childList
|| mTableInner
.mChildList2
.childList
) {
991 if (nsGkAtoms::tableFrame
== mLowestType
) {
992 printf("LOW InnerTable\n");
995 printf(" InnerTable\n");
999 if (mColGroup
.mFrame
|| mColGroup
.mChildList
.childList
|| mColGroup
.mChildList2
.childList
) {
1000 if (nsGkAtoms::tableColGroupFrame
== mLowestType
) {
1001 printf("LOW ColGroup\n");
1004 printf(" ColGroup\n");
1008 if (mRowGroup
.mFrame
|| mRowGroup
.mChildList
.childList
|| mRowGroup
.mChildList2
.childList
) {
1009 if (nsGkAtoms::tableRowGroupFrame
== mLowestType
) {
1010 printf("LOW RowGroup\n");
1013 printf(" RowGroup\n");
1017 if (mRow
.mFrame
|| mRow
.mChildList
.childList
|| mRow
.mChildList2
.childList
) {
1018 if (nsGkAtoms::tableRowFrame
== mLowestType
) {
1019 printf("LOW Row\n");
1027 if (mCellOuter
.mFrame
|| mCellOuter
.mChildList
.childList
|| mCellOuter
.mChildList2
.childList
) {
1028 if (IS_TABLE_CELL(mLowestType
)) {
1029 printf("LOW OuterCell\n");
1032 printf(" OuterCell\n");
1036 if (mCellInner
.mFrame
|| mCellInner
.mChildList
.childList
|| mCellInner
.mChildList2
.childList
) {
1037 printf(" InnerCell\n");
1043 // -----------------------------------------------------------
1045 // Structure for saving the existing state when pushing/poping containing
1046 // blocks. The destructor restores the state to its previous state
1047 class nsFrameConstructorSaveState
{
1049 nsFrameConstructorSaveState();
1050 ~nsFrameConstructorSaveState();
1053 nsAbsoluteItems
* mItems
; // pointer to struct whose data we save/restore
1054 PRBool
* mFixedPosIsAbsPos
;
1056 nsAbsoluteItems mSavedItems
; // copy of original data
1057 PRBool mSavedFixedPosIsAbsPos
;
1059 // The name of the child list in which our frames would belong
1060 nsIAtom
* mChildListName
;
1061 nsFrameConstructorState
* mState
;
1063 friend class nsFrameConstructorState
;
1066 // Structure used for maintaining state information during the
1067 // frame construction process
1068 class NS_STACK_CLASS nsFrameConstructorState
{
1070 nsPresContext
*mPresContext
;
1071 nsIPresShell
*mPresShell
;
1072 nsFrameManager
*mFrameManager
;
1075 // Frames destined for the nsGkAtoms::popupList.
1076 nsAbsoluteItems mPopupItems
;
1079 // Containing block information for out-of-flow frames.
1080 nsAbsoluteItems mFixedItems
;
1081 nsAbsoluteItems mAbsoluteItems
;
1082 nsAbsoluteItems mFloatedItems
;
1084 // When working with the -moz-transform property, we want to hook
1085 // the abs-pos and fixed-pos lists together, since transformed
1086 // elements are fixed-pos containing blocks. This flag determines
1087 // whether or not we want to wire the fixed-pos and abs-pos lists
1089 PRBool mFixedPosIsAbsPos
;
1091 nsCOMPtr
<nsILayoutHistoryState
> mFrameState
;
1092 nsPseudoFrames mPseudoFrames
;
1093 // These bits will be added to the state bits of any frame we construct
1094 // using this state.
1095 nsFrameState mAdditionalStateBits
;
1098 // Use the passed-in history state.
1099 nsFrameConstructorState(nsIPresShell
* aPresShell
,
1100 nsIFrame
* aFixedContainingBlock
,
1101 nsIFrame
* aAbsoluteContainingBlock
,
1102 nsIFrame
* aFloatContainingBlock
,
1103 nsILayoutHistoryState
* aHistoryState
);
1104 // Get the history state from the pres context's pres shell.
1105 nsFrameConstructorState(nsIPresShell
* aPresShell
,
1106 nsIFrame
* aFixedContainingBlock
,
1107 nsIFrame
* aAbsoluteContainingBlock
,
1108 nsIFrame
* aFloatContainingBlock
);
1110 ~nsFrameConstructorState();
1112 // Function to push the existing absolute containing block state and
1113 // create a new scope. Code that uses this function should get matching
1114 // logic in GetAbsoluteContainingBlock.
1115 void PushAbsoluteContainingBlock(nsIFrame
* aNewAbsoluteContainingBlock
,
1116 nsFrameConstructorSaveState
& aSaveState
);
1118 // Function to push the existing float containing block state and
1119 // create a new scope. Code that uses this function should get matching
1120 // logic in GetFloatContainingBlock.
1121 // Pushing a null float containing block forbids any frames from being
1122 // floated until a new float containing block is pushed.
1123 // XXX we should get rid of null float containing blocks and teach the
1124 // various frame classes to deal with floats instead.
1125 void PushFloatContainingBlock(nsIFrame
* aNewFloatContainingBlock
,
1126 nsFrameConstructorSaveState
& aSaveState
);
1128 // Function to return the proper geometric parent for a frame with display
1129 // struct given by aStyleDisplay and parent's frame given by
1130 // aContentParentFrame.
1131 nsIFrame
* GetGeometricParent(const nsStyleDisplay
* aStyleDisplay
,
1132 nsIFrame
* aContentParentFrame
);
1135 * Function to add a new frame to the right frame list. This MUST be called
1136 * on frames before their children have been processed if the frames might
1137 * conceivably be out-of-flow; otherwise cleanup in error cases won't work
1138 * right. Also, this MUST be called on frames after they have been
1140 * @param aNewFrame the frame to add
1141 * @param aFrameItems the list to add in-flow frames to
1142 * @param aContent the content pointer for aNewFrame
1143 * @param aStyleContext the style context resolved for aContent
1144 * @param aParentFrame the parent frame for the content if it were in-flow
1145 * @param aCanBePositioned pass false if the frame isn't allowed to be
1147 * @param aCanBeFloated pass false if the frame isn't allowed to be
1149 * @param aIsOutOfFlowPopup pass true if the frame is an out-of-flow popup
1151 * @throws NS_ERROR_OUT_OF_MEMORY if it happens.
1152 * @note If this method throws, that means that aNewFrame was not inserted
1153 * into any frame lists. Furthermore, this method will handle cleanup
1154 * of aNewFrame (via calling CleanupFrameReferences() and Destroy() on
1157 nsresult
AddChild(nsIFrame
* aNewFrame
,
1158 nsFrameItems
& aFrameItems
,
1159 nsIContent
* aContent
,
1160 nsStyleContext
* aStyleContext
,
1161 nsIFrame
* aParentFrame
,
1162 PRBool aCanBePositioned
= PR_TRUE
,
1163 PRBool aCanBeFloated
= PR_TRUE
,
1164 PRBool aIsOutOfFlowPopup
= PR_FALSE
,
1165 PRBool aInsertAfter
= PR_FALSE
,
1166 nsIFrame
* aInsertAfterFrame
= nsnull
);
1169 * Function to return the fixed-pos element list. Normally this will just hand back the
1170 * fixed-pos element list, but in case we're dealing with a transformed element that's
1171 * acting as an abs-pos and fixed-pos container, we'll hand back the abs-pos list. Callers should
1172 * use this function if they want to get the list acting as the fixed-pos item parent.
1174 nsAbsoluteItems
& GetFixedItems()
1176 return mFixedPosIsAbsPos
? mAbsoluteItems
: mFixedItems
;
1178 const nsAbsoluteItems
& GetFixedItems() const
1180 return mFixedPosIsAbsPos
? mAbsoluteItems
: mFixedItems
;
1184 friend class nsFrameConstructorSaveState
;
1187 * ProcessFrameInsertions takes the frames in aFrameItems and adds them as
1188 * kids to the aChildListName child list of |aFrameItems.containingBlock|.
1190 void ProcessFrameInsertions(nsAbsoluteItems
& aFrameItems
,
1191 nsIAtom
* aChildListName
);
1194 nsFrameConstructorState::nsFrameConstructorState(nsIPresShell
* aPresShell
,
1195 nsIFrame
* aFixedContainingBlock
,
1196 nsIFrame
* aAbsoluteContainingBlock
,
1197 nsIFrame
* aFloatContainingBlock
,
1198 nsILayoutHistoryState
* aHistoryState
)
1199 : mPresContext(aPresShell
->GetPresContext()),
1200 mPresShell(aPresShell
),
1201 mFrameManager(aPresShell
->FrameManager()),
1203 mPopupItems(nsnull
),
1205 mFixedItems(aFixedContainingBlock
),
1206 mAbsoluteItems(aAbsoluteContainingBlock
),
1207 mFloatedItems(aFloatContainingBlock
),
1208 // See PushAbsoluteContaningBlock below
1209 mFixedPosIsAbsPos(aAbsoluteContainingBlock
&&
1210 aAbsoluteContainingBlock
->GetStyleDisplay()->
1212 mFrameState(aHistoryState
),
1214 mAdditionalStateBits(0)
1217 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(aPresShell
);
1219 mPopupItems
.containingBlock
= rootBox
->GetPopupSetFrame();
1222 MOZ_COUNT_CTOR(nsFrameConstructorState
);
1225 nsFrameConstructorState::nsFrameConstructorState(nsIPresShell
* aPresShell
,
1226 nsIFrame
* aFixedContainingBlock
,
1227 nsIFrame
* aAbsoluteContainingBlock
,
1228 nsIFrame
* aFloatContainingBlock
)
1229 : mPresContext(aPresShell
->GetPresContext()),
1230 mPresShell(aPresShell
),
1231 mFrameManager(aPresShell
->FrameManager()),
1233 mPopupItems(nsnull
),
1235 mFixedItems(aFixedContainingBlock
),
1236 mAbsoluteItems(aAbsoluteContainingBlock
),
1237 mFloatedItems(aFloatContainingBlock
),
1238 // See PushAbsoluteContaningBlock below
1239 mFixedPosIsAbsPos(aAbsoluteContainingBlock
&&
1240 aAbsoluteContainingBlock
->GetStyleDisplay()->
1243 mAdditionalStateBits(0)
1246 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(aPresShell
);
1248 mPopupItems
.containingBlock
= rootBox
->GetPopupSetFrame();
1251 MOZ_COUNT_CTOR(nsFrameConstructorState
);
1252 mFrameState
= aPresShell
->GetDocument()->GetLayoutHistoryState();
1255 nsFrameConstructorState::~nsFrameConstructorState()
1257 // Frame order comparison functions only work properly when the placeholders
1258 // have been inserted into the frame tree. So for example if we have a new float
1259 // containing the placeholder for a new abs-pos frame, and we process the abs-pos
1260 // insertion first, then we won't be able to find the right place to insert in
1261 // in the abs-pos list. So put floats in first, because they can contain placeholders
1262 // for abs-pos and fixed-pos items whose containing blocks are outside the floats.
1263 // Then put abs-pos frames in, because they can contain placeholders for fixed-pos
1264 // items whose containing block is outside the abs-pos frames.
1265 MOZ_COUNT_DTOR(nsFrameConstructorState
);
1266 ProcessFrameInsertions(mFloatedItems
, nsGkAtoms::floatList
);
1267 ProcessFrameInsertions(mAbsoluteItems
, nsGkAtoms::absoluteList
);
1268 ProcessFrameInsertions(mFixedItems
, nsGkAtoms::fixedList
);
1270 ProcessFrameInsertions(mPopupItems
, nsGkAtoms::popupList
);
1275 AdjustAbsoluteContainingBlock(nsIFrame
* aContainingBlockIn
)
1277 if (!aContainingBlockIn
) {
1281 // Always use the container's first continuation. (Inline frames can have
1282 // non-fluid bidi continuations...)
1283 return aContainingBlockIn
->GetFirstContinuation();
1287 nsFrameConstructorState::PushAbsoluteContainingBlock(nsIFrame
* aNewAbsoluteContainingBlock
,
1288 nsFrameConstructorSaveState
& aSaveState
)
1290 aSaveState
.mItems
= &mAbsoluteItems
;
1291 aSaveState
.mSavedItems
= mAbsoluteItems
;
1292 aSaveState
.mChildListName
= nsGkAtoms::absoluteList
;
1293 aSaveState
.mState
= this;
1295 /* Store whether we're wiring the abs-pos and fixed-pos lists together. */
1296 aSaveState
.mFixedPosIsAbsPos
= &mFixedPosIsAbsPos
;
1297 aSaveState
.mSavedFixedPosIsAbsPos
= mFixedPosIsAbsPos
;
1300 nsAbsoluteItems(AdjustAbsoluteContainingBlock(aNewAbsoluteContainingBlock
));
1302 /* See if we're wiring the fixed-pos and abs-pos lists together. This happens iff
1303 * we're a transformed element.
1305 mFixedPosIsAbsPos
= (aNewAbsoluteContainingBlock
&&
1306 aNewAbsoluteContainingBlock
->GetStyleDisplay()->HasTransform());
1310 nsFrameConstructorState::PushFloatContainingBlock(nsIFrame
* aNewFloatContainingBlock
,
1311 nsFrameConstructorSaveState
& aSaveState
)
1313 NS_PRECONDITION(!aNewFloatContainingBlock
||
1314 aNewFloatContainingBlock
->IsFloatContainingBlock(),
1315 "Please push a real float containing block!");
1316 aSaveState
.mItems
= &mFloatedItems
;
1317 aSaveState
.mSavedItems
= mFloatedItems
;
1318 aSaveState
.mChildListName
= nsGkAtoms::floatList
;
1319 aSaveState
.mState
= this;
1320 mFloatedItems
= nsAbsoluteItems(aNewFloatContainingBlock
);
1324 nsFrameConstructorState::GetGeometricParent(const nsStyleDisplay
* aStyleDisplay
,
1325 nsIFrame
* aContentParentFrame
)
1327 NS_PRECONDITION(aStyleDisplay
, "Must have display struct!");
1329 // If there is no container for a fixed, absolute, or floating root
1330 // frame, we will ignore the positioning. This hack is originally
1331 // brought to you by the letter T: tables, since other roots don't
1332 // even call into this code. See bug 178855.
1334 // XXX Disabling positioning in this case is a hack. If one was so inclined,
1335 // one could support this either by (1) inserting a dummy block between the
1336 // table and the canvas or (2) teaching the canvas how to reflow positioned
1337 // elements. (1) has the usual problems when multiple frames share the same
1338 // content (notice all the special cases in this file dealing with inner
1339 // tables and outer tables which share the same content). (2) requires some
1340 // work and possible factoring.
1342 // XXXbz couldn't we just force position to "static" on roots and
1343 // float to "none"? That's OK per CSS 2.1, as far as I can tell.
1345 if (aStyleDisplay
->IsFloating() && mFloatedItems
.containingBlock
) {
1346 NS_ASSERTION(!aStyleDisplay
->IsAbsolutelyPositioned(),
1347 "Absolutely positioned _and_ floating?");
1348 return mFloatedItems
.containingBlock
;
1351 if (aStyleDisplay
->mPosition
== NS_STYLE_POSITION_ABSOLUTE
&&
1352 mAbsoluteItems
.containingBlock
) {
1353 return mAbsoluteItems
.containingBlock
;
1356 if (aStyleDisplay
->mPosition
== NS_STYLE_POSITION_FIXED
&&
1357 GetFixedItems().containingBlock
) {
1358 return GetFixedItems().containingBlock
;
1361 return aContentParentFrame
;
1365 nsFrameConstructorState::AddChild(nsIFrame
* aNewFrame
,
1366 nsFrameItems
& aFrameItems
,
1367 nsIContent
* aContent
,
1368 nsStyleContext
* aStyleContext
,
1369 nsIFrame
* aParentFrame
,
1370 PRBool aCanBePositioned
,
1371 PRBool aCanBeFloated
,
1372 PRBool aIsOutOfFlowPopup
,
1373 PRBool aInsertAfter
,
1374 nsIFrame
* aInsertAfterFrame
)
1376 const nsStyleDisplay
* disp
= aNewFrame
->GetStyleDisplay();
1378 // The comments in GetGeometricParent regarding root table frames
1379 // all apply here, unfortunately.
1381 PRBool needPlaceholder
= PR_FALSE
;
1382 nsFrameItems
* frameItems
= &aFrameItems
;
1384 if (NS_UNLIKELY(aIsOutOfFlowPopup
)) {
1385 NS_ASSERTION(aNewFrame
->GetParent() == mPopupItems
.containingBlock
,
1386 "Popup whose parent is not the popup containing block?");
1387 NS_ASSERTION(mPopupItems
.containingBlock
, "Must have a popup set frame!");
1388 needPlaceholder
= PR_TRUE
;
1389 frameItems
= &mPopupItems
;
1393 if (aCanBeFloated
&& disp
->IsFloating() &&
1394 mFloatedItems
.containingBlock
) {
1395 NS_ASSERTION(aNewFrame
->GetParent() == mFloatedItems
.containingBlock
,
1396 "Float whose parent is not the float containing block?");
1397 needPlaceholder
= PR_TRUE
;
1398 frameItems
= &mFloatedItems
;
1400 else if (aCanBePositioned
) {
1401 if (disp
->mPosition
== NS_STYLE_POSITION_ABSOLUTE
&&
1402 mAbsoluteItems
.containingBlock
) {
1403 NS_ASSERTION(aNewFrame
->GetParent() == mAbsoluteItems
.containingBlock
,
1404 "Abs pos whose parent is not the abs pos containing block?");
1405 needPlaceholder
= PR_TRUE
;
1406 frameItems
= &mAbsoluteItems
;
1408 if (disp
->mPosition
== NS_STYLE_POSITION_FIXED
&&
1409 GetFixedItems().containingBlock
) {
1410 NS_ASSERTION(aNewFrame
->GetParent() == GetFixedItems().containingBlock
,
1411 "Fixed pos whose parent is not the fixed pos containing block?");
1412 needPlaceholder
= PR_TRUE
;
1413 frameItems
= &GetFixedItems();
1417 if (needPlaceholder
) {
1418 NS_ASSERTION(frameItems
!= &aFrameItems
,
1419 "Putting frame in-flow _and_ want a placeholder?");
1420 nsIFrame
* placeholderFrame
;
1422 nsCSSFrameConstructor::CreatePlaceholderFrameFor(mPresShell
,
1429 if (NS_FAILED(rv
)) {
1430 // Note that aNewFrame could be the top frame for a scrollframe setup,
1431 // hence already set as the primary frame. So we have to clean up here.
1432 // But it shouldn't have any out-of-flow kids.
1433 // XXXbz Maybe add a utility function to assert that?
1434 CleanupFrameReferences(mFrameManager
, aNewFrame
);
1435 aNewFrame
->Destroy();
1439 placeholderFrame
->AddStateBits(mAdditionalStateBits
);
1440 // Add the placeholder frame to the flow
1441 aFrameItems
.AddChild(placeholderFrame
);
1445 NS_ASSERTION(aNewFrame
->GetParent() == aParentFrame
,
1446 "In-flow frame has wrong parent");
1451 frameItems
->InsertChildAfter(aNewFrame
, aInsertAfterFrame
);
1453 frameItems
->AddChild(aNewFrame
);
1456 // Now add the special siblings too.
1457 nsIFrame
* specialSibling
= aNewFrame
;
1458 while (specialSibling
&& IsFrameSpecial(specialSibling
)) {
1459 specialSibling
= GetSpecialSibling(specialSibling
);
1460 if (specialSibling
) {
1461 NS_ASSERTION(frameItems
== &aFrameItems
,
1462 "IB split ending up in an out-of-flow childlist?");
1463 frameItems
->AddChild(specialSibling
);
1471 nsFrameConstructorState::ProcessFrameInsertions(nsAbsoluteItems
& aFrameItems
,
1472 nsIAtom
* aChildListName
)
1474 #define NS_NONXUL_LIST_TEST (&aFrameItems == &mFloatedItems && \
1475 aChildListName == nsGkAtoms::floatList) || \
1476 (&aFrameItems == &mAbsoluteItems && \
1477 aChildListName == nsGkAtoms::absoluteList) || \
1478 (&aFrameItems == &mFixedItems && \
1479 aChildListName == nsGkAtoms::fixedList)
1481 NS_PRECONDITION(NS_NONXUL_LIST_TEST
||
1482 (&aFrameItems
== &mPopupItems
&&
1483 aChildListName
== nsGkAtoms::popupList
),
1484 "Unexpected aFrameItems/aChildListName combination");
1486 NS_PRECONDITION(NS_NONXUL_LIST_TEST
,
1487 "Unexpected aFrameItems/aChildListName combination");
1490 nsIFrame
* firstNewFrame
= aFrameItems
.childList
;
1492 if (!firstNewFrame
) {
1496 nsIFrame
* containingBlock
= aFrameItems
.containingBlock
;
1498 NS_ASSERTION(containingBlock
,
1499 "Child list without containing block?");
1501 // Insert the frames hanging out in aItems. We can use SetInitialChildList()
1502 // if the containing block hasn't been reflown yet (so NS_FRAME_FIRST_REFLOW
1503 // is set) and doesn't have any frames in the aChildListName child list yet.
1504 nsIFrame
* firstChild
= containingBlock
->GetFirstChild(aChildListName
);
1505 nsresult rv
= NS_OK
;
1506 if (!firstChild
&& (containingBlock
->GetStateBits() & NS_FRAME_FIRST_REFLOW
)) {
1507 rv
= containingBlock
->SetInitialChildList(aChildListName
, firstNewFrame
);
1509 // Note that whether the frame construction context is doing an append or
1510 // not is not helpful here, since it could be appending to some frame in
1511 // the middle of the document, which means we're not necessarily
1512 // appending to the children of the containing block.
1514 // We need to make sure the 'append to the end of document' case is fast.
1515 // So first test the last child of the containing block
1516 nsIFrame
* lastChild
= nsLayoutUtils::GetLastSibling(firstChild
);
1518 // CompareTreePosition uses placeholder hierarchy for out of flow frames,
1519 // so this will make out-of-flows respect the ordering of placeholders,
1520 // which is great because it takes care of anonymous content.
1522 nsLayoutUtils::CompareTreePosition(lastChild
, firstNewFrame
, containingBlock
) < 0) {
1523 // no lastChild, or lastChild comes before the new children, so just append
1524 rv
= containingBlock
->AppendFrames(aChildListName
, firstNewFrame
);
1526 nsIFrame
* insertionPoint
= nsnull
;
1527 // try the other children
1528 for (nsIFrame
* f
= firstChild
; f
!= lastChild
; f
= f
->GetNextSibling()) {
1530 nsLayoutUtils::CompareTreePosition(f
, firstNewFrame
, containingBlock
);
1532 // f comes after the new children, so stop here and insert after
1533 // the previous frame
1539 rv
= containingBlock
->InsertFrames(aChildListName
, insertionPoint
,
1543 aFrameItems
.childList
= nsnull
;
1544 // XXXbz And if NS_FAILED(rv), what? I guess we need to clean up the list
1545 // and deal with all the placeholders... but what if the placeholders aren't
1546 // in the document yet? Could that happen?
1547 NS_ASSERTION(NS_SUCCEEDED(rv
), "Frames getting lost!");
1551 nsFrameConstructorSaveState::nsFrameConstructorSaveState()
1553 mFixedPosIsAbsPos(nsnull
),
1554 mSavedItems(nsnull
),
1555 mSavedFixedPosIsAbsPos(PR_FALSE
),
1556 mChildListName(nsnull
),
1561 nsFrameConstructorSaveState::~nsFrameConstructorSaveState()
1563 // Restore the state
1565 NS_ASSERTION(mState
, "Can't have mItems set without having a state!");
1566 mState
->ProcessFrameInsertions(*mItems
, mChildListName
);
1567 *mItems
= mSavedItems
;
1569 // We've transferred the child list, so drop the pointer we held to it.
1570 // Note that this only matters for the assert in ~nsAbsoluteItems.
1571 mSavedItems
.childList
= nsnull
;
1574 if (mFixedPosIsAbsPos
) {
1575 *mFixedPosIsAbsPos
= mSavedFixedPosIsAbsPos
;
1580 PRBool
IsBorderCollapse(nsIFrame
* aFrame
)
1582 for (nsIFrame
* frame
= aFrame
; frame
; frame
= frame
->GetParent()) {
1583 if (nsGkAtoms::tableFrame
== frame
->GetType()) {
1584 return ((nsTableFrame
*)frame
)->IsBorderCollapse();
1587 NS_ASSERTION(PR_FALSE
, "program error");
1592 * Utility method, called from MoveChildrenTo(), that recursively
1593 * descends down the frame hierarchy looking for floating frames that
1594 * need parent pointer adjustments to account for the containment block
1595 * changes that could occur as the result of the reparenting done in
1599 AdjustFloatParentPtrs(nsIFrame
* aFrame
,
1600 nsFrameConstructorState
& aState
,
1601 nsFrameConstructorState
& aOuterState
)
1603 NS_PRECONDITION(aFrame
, "must have frame to work with");
1605 nsIFrame
*outOfFlowFrame
= nsPlaceholderFrame::GetRealFrameFor(aFrame
);
1606 if (outOfFlowFrame
!= aFrame
) {
1607 if (outOfFlowFrame
->GetStyleDisplay()->IsFloating()) {
1608 // Update the parent pointer for outOfFlowFrame since its
1609 // containing block has changed as the result of reparenting
1610 // and move it from the outer state to the inner, bug 307277.
1612 nsIFrame
*parent
= aState
.mFloatedItems
.containingBlock
;
1613 NS_ASSERTION(parent
, "Should have float containing block here!");
1614 NS_ASSERTION(outOfFlowFrame
->GetParent() == aOuterState
.mFloatedItems
.containingBlock
,
1615 "expected the float to be a child of the outer CB");
1617 if (aOuterState
.mFloatedItems
.RemoveChild(outOfFlowFrame
, nsnull
)) {
1618 aState
.mFloatedItems
.AddChild(outOfFlowFrame
);
1620 NS_NOTREACHED("float wasn't in the outer state float list");
1623 outOfFlowFrame
->SetParent(parent
);
1624 if (outOfFlowFrame
->GetStateBits() &
1625 (NS_FRAME_HAS_VIEW
| NS_FRAME_HAS_CHILD_WITH_VIEW
)) {
1626 // We don't need to walk up the tree, since we're doing this
1628 parent
->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW
);
1632 // All out-of-flows are automatically float containing blocks, so we're
1637 if (aFrame
->IsFloatContainingBlock()) {
1638 // No need to recurse further; floats whose placeholders are
1639 // inside a block already have the right parent.
1643 // Dive down into children to see if any of their
1644 // placeholders need adjusting.
1645 nsIFrame
*childFrame
= aFrame
->GetFirstChild(nsnull
);
1646 while (childFrame
) {
1647 // XXX_kin: Do we need to prevent descent into anonymous content here?
1649 AdjustFloatParentPtrs(childFrame
, aState
, aOuterState
);
1650 childFrame
= childFrame
->GetNextSibling();
1655 * Moves frames to a new parent, updating the style context and propagating
1656 * relevant frame state bits. |aState| may be null, in which case the parent
1657 * pointers of out-of-flow frames will remain untouched.
1660 MoveChildrenTo(nsFrameManager
* aFrameManager
,
1661 nsIFrame
* aNewParent
,
1662 nsIFrame
* aFrameList
,
1663 nsIFrame
* aFrameListEnd
,
1664 nsFrameConstructorState
* aState
,
1665 nsFrameConstructorState
* aOuterState
)
1667 PRBool setHasChildWithView
= PR_FALSE
;
1669 while (aFrameList
&& aFrameList
!= aFrameListEnd
) {
1670 if (!setHasChildWithView
1671 && (aFrameList
->GetStateBits() & (NS_FRAME_HAS_VIEW
| NS_FRAME_HAS_CHILD_WITH_VIEW
))) {
1672 setHasChildWithView
= PR_TRUE
;
1675 aFrameList
->SetParent(aNewParent
);
1677 // If aState is not null, the caller expects us to make adjustments so that
1678 // floats whose placeholders are descendants of frames in aFrameList point
1679 // to the correct parent.
1681 NS_ASSERTION(aOuterState
, "need an outer state too");
1682 AdjustFloatParentPtrs(aFrameList
, *aState
, *aOuterState
);
1685 aFrameList
= aFrameList
->GetNextSibling();
1688 if (setHasChildWithView
) {
1690 aNewParent
->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW
);
1691 aNewParent
= aNewParent
->GetParent();
1692 } while (aNewParent
&&
1693 !(aNewParent
->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW
));
1697 // -----------------------------------------------------------
1700 // Structure used to ensure that bindings are properly enqueued in the
1701 // binding manager's attached queue.
1702 struct NS_STACK_CLASS nsAutoEnqueueBinding
1704 nsAutoEnqueueBinding(nsIDocument
* aDocument
) :
1705 mDocument(aDocument
)
1708 ~nsAutoEnqueueBinding();
1710 nsRefPtr
<nsXBLBinding
> mBinding
;
1712 nsIDocument
* mDocument
;
1715 nsAutoEnqueueBinding::~nsAutoEnqueueBinding()
1718 mDocument
->BindingManager()->AddToAttachedQueue(mBinding
);
1723 // Helper function that determines the child list name that aChildFrame
1726 GetChildListNameFor(nsIFrame
* aChildFrame
)
1730 if (aChildFrame
->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER
) {
1731 listName
= nsGkAtoms::overflowContainersList
;
1733 // See if the frame is moved out of the flow
1734 else if (aChildFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
1735 // Look at the style information to tell
1736 const nsStyleDisplay
* disp
= aChildFrame
->GetStyleDisplay();
1738 if (NS_STYLE_POSITION_ABSOLUTE
== disp
->mPosition
) {
1739 listName
= nsGkAtoms::absoluteList
;
1740 } else if (NS_STYLE_POSITION_FIXED
== disp
->mPosition
) {
1741 if (nsLayoutUtils::IsReallyFixedPos(aChildFrame
)) {
1742 listName
= nsGkAtoms::fixedList
;
1744 listName
= nsGkAtoms::absoluteList
;
1747 } else if (NS_STYLE_DISPLAY_POPUP
== disp
->mDisplay
) {
1748 // Out-of-flows that are DISPLAY_POPUP must be kids of the root popup set
1750 nsIFrame
* parent
= aChildFrame
->GetParent();
1751 NS_ASSERTION(parent
&& parent
->GetType() == nsGkAtoms::popupSetFrame
,
1752 "Unexpected parent");
1755 // XXX FIXME: Bug 350740
1756 // Return here, because the postcondition for this function actually
1757 // fails for this case, since the popups are not in a "real" frame list
1758 // in the popup set.
1759 return nsGkAtoms::popupList
;
1762 NS_ASSERTION(aChildFrame
->GetStyleDisplay()->IsFloating(),
1763 "not a floated frame");
1764 listName
= nsGkAtoms::floatList
;
1772 // Verify that the frame is actually in that child list or in the
1773 // corresponding overflow list.
1774 nsIFrame
* parent
= aChildFrame
->GetParent();
1775 PRBool found
= nsFrameList(parent
->GetFirstChild(listName
))
1776 .ContainsFrame(aChildFrame
);
1778 if (!(aChildFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)) {
1779 found
= nsFrameList(parent
->GetFirstChild(nsGkAtoms::overflowList
))
1780 .ContainsFrame(aChildFrame
);
1782 else if (aChildFrame
->GetStyleDisplay()->IsFloating()) {
1783 found
= nsFrameList(parent
->GetFirstChild(nsGkAtoms::overflowOutOfFlowList
))
1784 .ContainsFrame(aChildFrame
);
1786 // else it's positioned and should have been on the 'listName' child list.
1787 NS_POSTCONDITION(found
, "not in child list");
1794 //----------------------------------------------------------------------
1796 nsCSSFrameConstructor::nsCSSFrameConstructor(nsIDocument
*aDocument
,
1797 nsIPresShell
*aPresShell
)
1798 : mDocument(aDocument
)
1799 , mPresShell(aPresShell
)
1800 , mRootElementFrame(nsnull
)
1801 , mRootElementStyleFrame(nsnull
)
1802 , mFixedContainingBlock(nsnull
)
1803 , mDocElementContainingBlock(nsnull
)
1804 , mGfxScrollFrame(nsnull
)
1805 , mPageSequenceFrame(nsnull
)
1807 , mFocusSuppressCount(0)
1808 , mQuotesDirty(PR_FALSE
)
1809 , mCountersDirty(PR_FALSE
)
1810 , mIsDestroyingFrameTree(PR_FALSE
)
1811 , mRebuildAllStyleData(PR_FALSE
)
1812 , mHasRootAbsPosContainingBlock(PR_FALSE
)
1813 , mHoverGeneration(0)
1814 , mRebuildAllExtraHint(nsChangeHint(0))
1816 // XXXbz this should be in Init() or something!
1817 if (!mPendingRestyles
.Init()) {
1822 static PRBool gFirstTime
= PR_TRUE
;
1824 gFirstTime
= PR_FALSE
;
1825 char* flags
= PR_GetEnv("GECKO_FRAMECTOR_DEBUG_FLAGS");
1827 PRBool error
= PR_FALSE
;
1829 char* comma
= PL_strchr(flags
, ',');
1833 PRBool found
= PR_FALSE
;
1834 FrameCtorDebugFlags
* flag
= gFlags
;
1835 FrameCtorDebugFlags
* limit
= gFlags
+ NUM_DEBUG_FLAGS
;
1836 while (flag
< limit
) {
1837 if (PL_strcasecmp(flag
->name
, flags
) == 0) {
1838 *(flag
->on
) = PR_TRUE
;
1839 printf("nsCSSFrameConstructor: setting %s debug flag on\n", flag
->name
);
1857 printf("Here are the available GECKO_FRAMECTOR_DEBUG_FLAGS:\n");
1858 FrameCtorDebugFlags
* flag
= gFlags
;
1859 FrameCtorDebugFlags
* limit
= gFlags
+ NUM_DEBUG_FLAGS
;
1860 while (flag
< limit
) {
1861 printf(" %s\n", flag
->name
);
1864 printf("Note: GECKO_FRAMECTOR_DEBUG_FLAGS is a comma separated list of flag\n");
1865 printf("names (no whitespace)\n");
1872 nsIXBLService
* nsCSSFrameConstructor::GetXBLService()
1875 nsresult rv
= CallGetService("@mozilla.org/xbl;1", &gXBLService
);
1877 gXBLService
= nsnull
;
1884 nsCSSFrameConstructor::NotifyDestroyingFrame(nsIFrame
* aFrame
)
1886 NS_PRECONDITION(mUpdateCount
!= 0,
1887 "Should be in an update while destroying frames");
1889 if (aFrame
->GetStateBits() & NS_FRAME_GENERATED_CONTENT
) {
1890 if (mQuoteList
.DestroyNodesFor(aFrame
))
1894 if (mCounterManager
.DestroyNodesFor(aFrame
)) {
1895 // Technically we don't need to update anything if we destroyed only
1896 // USE nodes. However, this is unlikely to happen in the real world
1897 // since USE nodes generally go along with INCREMENT nodes.
1902 struct nsGenConInitializer
{
1903 nsAutoPtr
<nsGenConNode
> mNode
;
1904 nsGenConList
* mList
;
1905 void (nsCSSFrameConstructor::*mDirtyAll
)();
1907 nsGenConInitializer(nsGenConNode
* aNode
, nsGenConList
* aList
,
1908 void (nsCSSFrameConstructor::*aDirtyAll
)())
1909 : mNode(aNode
), mList(aList
), mDirtyAll(aDirtyAll
) {}
1913 DestroyGenConInitializer(void* aFrame
,
1914 nsIAtom
* aPropertyName
,
1915 void* aPropertyValue
,
1918 delete static_cast<nsGenConInitializer
*>(aPropertyValue
);
1921 already_AddRefed
<nsIContent
>
1922 nsCSSFrameConstructor::CreateGenConTextNode(const nsString
& aString
,
1923 nsCOMPtr
<nsIDOMCharacterData
>* aText
,
1924 nsGenConInitializer
* aInitializer
)
1926 nsCOMPtr
<nsIContent
> content
;
1927 NS_NewTextNode(getter_AddRefs(content
), mDocument
->NodeInfoManager());
1929 // XXX The quotes/counters code doesn't like the text pointer
1930 // being null in case of dynamic changes!
1931 NS_ASSERTION(!aText
, "this OOM case isn't handled very well");
1934 content
->SetText(aString
, PR_FALSE
);
1936 *aText
= do_QueryInterface(content
);
1939 content
->SetProperty(nsGkAtoms::genConInitializerProperty
, aInitializer
,
1940 DestroyGenConInitializer
);
1942 return content
.forget();
1945 already_AddRefed
<nsIContent
>
1946 nsCSSFrameConstructor::CreateGeneratedContent(nsIContent
* aParentContent
,
1947 nsStyleContext
* aStyleContext
,
1948 PRUint32 aContentIndex
)
1950 // Get the content value
1951 const nsStyleContentData
&data
=
1952 aStyleContext
->GetStyleContent()->ContentAt(aContentIndex
);
1953 nsStyleContentType type
= data
.mType
;
1955 if (eStyleContentType_Image
== type
) {
1956 if (!data
.mContent
.mImage
) {
1957 // CSS had something specified that couldn't be converted to an
1962 // Create an image content object and pass it the image request.
1963 // XXX Check if it's an image type we can handle...
1965 nsCOMPtr
<nsINodeInfo
> nodeInfo
;
1966 nodeInfo
= mDocument
->NodeInfoManager()->GetNodeInfo(nsGkAtoms::mozgeneratedcontentimage
, nsnull
,
1967 kNameSpaceID_XHTML
);
1969 nsCOMPtr
<nsIContent
> content
;
1970 NS_NewGenConImageContent(getter_AddRefs(content
), nodeInfo
,
1971 data
.mContent
.mImage
);
1972 return content
.forget();
1976 case eStyleContentType_String
:
1977 return CreateGenConTextNode(nsDependentString(data
.mContent
.mString
), nsnull
,
1980 case eStyleContentType_Attr
:
1982 nsCOMPtr
<nsIAtom
> attrName
;
1983 PRInt32 attrNameSpace
= kNameSpaceID_None
;
1984 nsAutoString
contentString(data
.mContent
.mString
);
1985 PRInt32 barIndex
= contentString
.FindChar('|'); // CSS namespace delimiter
1986 if (-1 != barIndex
) {
1987 nsAutoString nameSpaceVal
;
1988 contentString
.Left(nameSpaceVal
, barIndex
);
1990 attrNameSpace
= nameSpaceVal
.ToInteger(&error
, 10);
1991 contentString
.Cut(0, barIndex
+ 1);
1992 if (contentString
.Length()) {
1993 attrName
= do_GetAtom(contentString
);
1997 attrName
= do_GetAtom(contentString
);
2004 nsCOMPtr
<nsIContent
> content
;
2005 NS_NewAttributeContent(mDocument
->NodeInfoManager(),
2006 attrNameSpace
, attrName
, getter_AddRefs(content
));
2007 return content
.forget();
2010 case eStyleContentType_Counter
:
2011 case eStyleContentType_Counters
:
2013 nsCSSValue::Array
* counters
= data
.mContent
.mCounters
;
2014 nsCounterList
* counterList
= mCounterManager
.CounterListFor(
2015 nsDependentString(counters
->Item(0).GetStringBufferValue()));
2019 nsCounterUseNode
* node
=
2020 new nsCounterUseNode(counters
, aContentIndex
,
2021 type
== eStyleContentType_Counters
);
2025 nsGenConInitializer
* initializer
=
2026 new nsGenConInitializer(node
, counterList
,
2027 &nsCSSFrameConstructor::CountersDirty
);
2028 return CreateGenConTextNode(EmptyString(), &node
->mText
, initializer
);
2031 case eStyleContentType_Image
:
2032 NS_NOTREACHED("handled by if above");
2035 case eStyleContentType_OpenQuote
:
2036 case eStyleContentType_CloseQuote
:
2037 case eStyleContentType_NoOpenQuote
:
2038 case eStyleContentType_NoCloseQuote
:
2041 new nsQuoteNode(type
, aContentIndex
);
2045 nsGenConInitializer
* initializer
=
2046 new nsGenConInitializer(node
, &mQuoteList
,
2047 &nsCSSFrameConstructor::QuotesDirty
);
2048 return CreateGenConTextNode(EmptyString(), &node
->mText
, initializer
);
2051 case eStyleContentType_AltContent
:
2053 // Use the "alt" attribute; if that fails and the node is an HTML
2054 // <input>, try the value attribute and then fall back to some default
2055 // localized text we have.
2056 // XXX what if the 'alt' attribute is added later, how will we
2057 // detect that and do the right thing here?
2058 if (aParentContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::alt
)) {
2059 nsCOMPtr
<nsIContent
> content
;
2060 NS_NewAttributeContent(mDocument
->NodeInfoManager(),
2061 kNameSpaceID_None
, nsGkAtoms::alt
, getter_AddRefs(content
));
2062 return content
.forget();
2065 if (aParentContent
->IsNodeOfType(nsINode::eHTML
) &&
2066 aParentContent
->NodeInfo()->Equals(nsGkAtoms::input
)) {
2067 if (aParentContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::value
)) {
2068 nsCOMPtr
<nsIContent
> content
;
2069 NS_NewAttributeContent(mDocument
->NodeInfoManager(),
2070 kNameSpaceID_None
, nsGkAtoms::value
, getter_AddRefs(content
));
2071 return content
.forget();
2075 nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES
,
2077 return CreateGenConTextNode(temp
, nsnull
, nsnull
);
2087 static void DestroyContent(void *aObject
,
2088 nsIAtom
*aPropertyName
,
2089 void *aPropertyValue
,
2092 nsIContent
* content
= static_cast<nsIContent
*>(aPropertyValue
);
2093 content
->UnbindFromTree();
2094 NS_RELEASE(content
);
2098 * aParentFrame - the frame that should be the parent of the generated
2099 * content. This is the frame for the corresponding content node,
2100 * which must not be a leaf frame.
2102 * Any frames created are added to aFrameItems (or possibly left
2103 * in the table pseudoframe state in aState).
2105 * We create an XML element (tag _moz_generated_content_before or
2106 * _moz_generated_content_after) representing the pseudoelement. We
2107 * create a DOM node for each 'content' item and make those nodes the
2108 * children of the XML element. Then we create a frame subtree for
2109 * the XML element as if it were a regular child of
2110 * aParentFrame/aParentContent, giving the XML element the ::before or
2114 nsCSSFrameConstructor::CreateGeneratedContentFrame(nsFrameConstructorState
& aState
,
2115 nsIFrame
* aParentFrame
,
2116 nsIContent
* aParentContent
,
2117 nsStyleContext
* aStyleContext
,
2118 nsIAtom
* aPseudoElement
,
2119 nsFrameItems
& aFrameItems
)
2121 if (!aParentContent
->IsNodeOfType(nsINode::eELEMENT
))
2124 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
2126 // Probe for the existence of the pseudo-element
2127 nsRefPtr
<nsStyleContext
> pseudoStyleContext
;
2128 pseudoStyleContext
= styleSet
->ProbePseudoStyleFor(aParentContent
,
2131 if (!pseudoStyleContext
)
2133 // |ProbePseudoStyleFor| checked the 'display' property and the
2134 // |ContentCount()| of the 'content' property for us.
2135 nsCOMPtr
<nsINodeInfo
> nodeInfo
;
2136 nsIAtom
* elemName
= aPseudoElement
== nsCSSPseudoElements::before
?
2137 nsGkAtoms::mozgeneratedcontentbefore
: nsGkAtoms::mozgeneratedcontentafter
;
2138 nodeInfo
= mDocument
->NodeInfoManager()->GetNodeInfo(elemName
, nsnull
,
2140 nsIContent
* container
;
2141 nsresult rv
= NS_NewXMLElement(&container
, nodeInfo
);
2144 container
->SetNativeAnonymous();
2145 // Transfer ownership to the frame
2146 aParentFrame
->SetProperty(aPseudoElement
, container
, DestroyContent
);
2148 rv
= container
->BindToTree(mDocument
, aParentContent
, aParentContent
, PR_TRUE
);
2149 if (NS_FAILED(rv
)) {
2150 container
->UnbindFromTree();
2154 PRUint32 contentCount
= pseudoStyleContext
->GetStyleContent()->ContentCount();
2155 for (PRUint32 contentIndex
= 0; contentIndex
< contentCount
; contentIndex
++) {
2156 nsCOMPtr
<nsIContent
> content
=
2157 CreateGeneratedContent(aParentContent
, pseudoStyleContext
, contentIndex
);
2159 container
->AppendChildTo(content
, PR_FALSE
);
2163 nsFrameState savedStateBits
= aState
.mAdditionalStateBits
;
2164 // Ensure that frames created here are all tagged with
2165 // NS_FRAME_GENERATED_CONTENT.
2166 aState
.mAdditionalStateBits
|= NS_FRAME_GENERATED_CONTENT
;
2168 // XXXbz should we actually allow page-break frames here?
2169 ConstructFrameInternal(aState
, container
, aParentFrame
,
2170 elemName
, kNameSpaceID_None
, pseudoStyleContext
,
2171 aFrameItems
, PR_FALSE
, PR_FALSE
);
2172 aState
.mAdditionalStateBits
= savedStateBits
;
2176 TextIsOnlyWhitespace(nsIContent
* aContent
)
2178 return aContent
->IsNodeOfType(nsINode::eTEXT
) &&
2179 aContent
->TextIsOnlyWhitespace();
2182 /****************************************************
2183 ** BEGIN TABLE SECTION
2184 ****************************************************/
2186 // The term pseudo frame is being used instead of anonymous frame, since anonymous
2187 // frame has been used elsewhere to refer to frames that have generated content
2189 // aIncludeSpecial applies to captions, col groups, cols and cells.
2190 // These do not generate pseudo frame wrappers for foreign children.
2191 // In fact, colgroups never have any children that are not cols and
2192 // cols never have any children at all.
2195 IsTableRelated(nsIAtom
* aParentType
,
2196 PRBool aIncludeSpecial
)
2198 if ((nsGkAtoms::tableFrame
== aParentType
) ||
2199 (nsGkAtoms::tableRowGroupFrame
== aParentType
) ||
2200 (nsGkAtoms::tableRowFrame
== aParentType
)) {
2203 else if (aIncludeSpecial
&&
2204 ((nsGkAtoms::tableCaptionFrame
== aParentType
) ||
2205 (nsGkAtoms::tableColGroupFrame
== aParentType
) ||
2206 (nsGkAtoms::tableColFrame
== aParentType
) ||
2207 IS_TABLE_CELL(aParentType
))) {
2210 else return PR_FALSE
;
2214 AdjustCaptionParentFrame(nsIFrame
* aParentFrame
)
2216 if (nsGkAtoms::tableFrame
== aParentFrame
->GetType()) {
2217 return aParentFrame
->GetParent();;
2219 return aParentFrame
;
2223 * If the parent frame is a |tableFrame| and the child is a
2224 * |captionFrame|, then we want to insert the frames beneath the
2225 * |tableFrame|'s parent frame. Returns |PR_TRUE| if the parent frame
2226 * needed to be fixed up.
2229 GetCaptionAdjustedParent(nsIFrame
* aParentFrame
,
2230 const nsIFrame
* aChildFrame
,
2231 nsIFrame
** aAdjParentFrame
)
2233 *aAdjParentFrame
= aParentFrame
;
2234 PRBool haveCaption
= PR_FALSE
;
2236 if (nsGkAtoms::tableCaptionFrame
== aChildFrame
->GetType()) {
2237 haveCaption
= PR_TRUE
;
2238 *aAdjParentFrame
= AdjustCaptionParentFrame(aParentFrame
);
2244 ProcessPseudoFrame(nsPseudoFrameData
& aPseudoData
,
2247 nsresult rv
= NS_OK
;
2249 aParent
= aPseudoData
.mFrame
;
2250 nsFrameItems
* items
= &aPseudoData
.mChildList
;
2251 if (items
&& items
->childList
) {
2252 rv
= aParent
->SetInitialChildList(nsnull
, items
->childList
);
2253 if (NS_FAILED(rv
)) return rv
;
2255 aPseudoData
.Reset();
2260 ProcessPseudoRowGroupFrame(nsPseudoFrameData
& aPseudoData
,
2263 nsresult rv
= NS_OK
;
2265 aParent
= aPseudoData
.mFrame
;
2266 nsFrameItems
* items
= &aPseudoData
.mChildList
;
2267 if (items
&& items
->childList
) {
2268 nsTableRowGroupFrame
* rgFrame
= nsTableFrame::GetRowGroupFrame(aParent
);
2269 rv
= rgFrame
->SetInitialChildList(nsnull
, items
->childList
);
2270 if (NS_FAILED(rv
)) return rv
;
2272 aPseudoData
.Reset();
2277 ProcessPseudoTableFrame(nsPseudoFrames
& aPseudoFrames
,
2280 nsresult rv
= NS_OK
;
2282 // process the col group frame, if it exists
2283 if (aPseudoFrames
.mColGroup
.mFrame
) {
2284 rv
= ProcessPseudoFrame(aPseudoFrames
.mColGroup
, aParent
);
2287 // process the inner table frame
2288 rv
= ProcessPseudoFrame(aPseudoFrames
.mTableInner
, aParent
);
2290 // process the outer table frame
2291 aParent
= aPseudoFrames
.mTableOuter
.mFrame
;
2292 nsFrameItems
* items
= &aPseudoFrames
.mTableOuter
.mChildList
;
2293 if (items
&& items
->childList
) {
2294 rv
= aParent
->SetInitialChildList(nsnull
, items
->childList
);
2295 if (NS_FAILED(rv
)) return rv
;
2297 nsFrameItems
* captions
= &aPseudoFrames
.mTableOuter
.mChildList2
;
2298 if (captions
&& captions
->childList
) {
2299 rv
= aParent
->SetInitialChildList(nsGkAtoms::captionList
, captions
->childList
);
2301 aPseudoFrames
.mTableOuter
.Reset();
2306 ProcessPseudoCellFrame(nsPseudoFrames
& aPseudoFrames
,
2309 nsresult rv
= NS_OK
;
2311 rv
= ProcessPseudoFrame(aPseudoFrames
.mCellInner
, aParent
);
2312 if (NS_FAILED(rv
)) return rv
;
2313 rv
= ProcessPseudoFrame(aPseudoFrames
.mCellOuter
, aParent
);
2317 // limit the processing up to the frame type indicated by aHighestType.
2318 // make a complete processing when aHighestType is null
2320 ProcessPseudoFrames(nsFrameConstructorState
& aState
,
2321 nsIAtom
* aHighestType
,
2322 nsIFrame
*& aHighestFrame
)
2324 nsresult rv
= NS_OK
;
2326 aHighestFrame
= nsnull
;
2329 if (gTablePseudoFrame
) {
2330 printf("*** ProcessPseudoFrames enter***\n");
2331 aState
.mPseudoFrames
.Dump();
2335 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2337 if (nsGkAtoms::tableFrame
== pseudoFrames
.mLowestType
) {
2338 if (pseudoFrames
.mColGroup
.mFrame
) {
2339 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, aHighestFrame
);
2340 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2342 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2343 if (nsGkAtoms::tableOuterFrame
== aHighestType
) return rv
;
2345 if (pseudoFrames
.mCellOuter
.mFrame
) {
2346 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2347 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2349 if (pseudoFrames
.mRow
.mFrame
) {
2350 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2351 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2353 if (pseudoFrames
.mRowGroup
.mFrame
) {
2354 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2355 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2358 else if (nsGkAtoms::tableRowGroupFrame
== pseudoFrames
.mLowestType
) {
2359 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2360 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2361 if (pseudoFrames
.mColGroup
.mFrame
) {
2362 nsIFrame
* colGroupHigh
;
2363 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, colGroupHigh
);
2364 if (aHighestFrame
&&
2365 nsGkAtoms::tableRowGroupFrame
== aHighestFrame
->GetType() &&
2366 !pseudoFrames
.mTableInner
.mFrame
) {
2367 // table frames are special they can have two types of pseudo frames as
2368 // children that need to be processed in one pass, we only need to link
2369 // them if the parent is not a pseudo where the link is already done
2370 // We sort this later out inside nsTableFrame.
2371 colGroupHigh
->SetNextSibling(aHighestFrame
);
2373 aHighestFrame
= colGroupHigh
;
2374 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2376 if (pseudoFrames
.mTableOuter
.mFrame
) {
2377 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2378 if (nsGkAtoms::tableOuterFrame
== aHighestType
) return rv
;
2380 if (pseudoFrames
.mCellOuter
.mFrame
) {
2381 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2382 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2384 if (pseudoFrames
.mRow
.mFrame
) {
2385 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2386 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2389 else if (nsGkAtoms::tableRowFrame
== pseudoFrames
.mLowestType
) {
2390 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2391 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2393 if (pseudoFrames
.mRowGroup
.mFrame
) {
2394 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2395 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2397 if (pseudoFrames
.mColGroup
.mFrame
) {
2398 nsIFrame
* colGroupHigh
;
2399 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, colGroupHigh
);
2400 if (aHighestFrame
&&
2401 nsGkAtoms::tableRowGroupFrame
== aHighestFrame
->GetType() &&
2402 !pseudoFrames
.mTableInner
.mFrame
) {
2403 // table frames are special they can have two types of pseudo frames as
2404 // children that need to be processed in one pass, we only need to link
2405 // them if the parent is not a pseudo where the link is already done
2406 // We sort this later out inside nsTableFrame.
2407 colGroupHigh
->SetNextSibling(aHighestFrame
);
2409 aHighestFrame
= colGroupHigh
;
2410 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2412 if (pseudoFrames
.mTableOuter
.mFrame
) {
2413 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2414 if (nsGkAtoms::tableOuterFrame
== aHighestType
) return rv
;
2416 if (pseudoFrames
.mCellOuter
.mFrame
) {
2417 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2418 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2421 else if (IS_TABLE_CELL(pseudoFrames
.mLowestType
)) {
2422 rv
= ProcessPseudoCellFrame(pseudoFrames
, aHighestFrame
);
2423 if (IS_TABLE_CELL(aHighestType
)) return rv
;
2425 if (pseudoFrames
.mRow
.mFrame
) {
2426 rv
= ProcessPseudoFrame(pseudoFrames
.mRow
, aHighestFrame
);
2427 if (nsGkAtoms::tableRowFrame
== aHighestType
) return rv
;
2429 if (pseudoFrames
.mRowGroup
.mFrame
) {
2430 rv
= ProcessPseudoRowGroupFrame(pseudoFrames
.mRowGroup
, aHighestFrame
);
2431 if (nsGkAtoms::tableRowGroupFrame
== aHighestType
) return rv
;
2433 if (pseudoFrames
.mColGroup
.mFrame
) {
2434 nsIFrame
* colGroupHigh
;
2435 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, colGroupHigh
);
2436 if (aHighestFrame
&&
2437 nsGkAtoms::tableRowGroupFrame
== aHighestFrame
->GetType() &&
2438 !pseudoFrames
.mTableInner
.mFrame
) {
2439 // table frames are special they can have two types of pseudo frames as
2440 // children that need to be processed in one pass, we only need to link
2441 // them if the parent is not a pseudo where the link is already done
2442 // We sort this later out inside nsTableFrame.
2443 colGroupHigh
->SetNextSibling(aHighestFrame
);
2445 aHighestFrame
= colGroupHigh
;
2446 if (nsGkAtoms::tableColGroupFrame
== aHighestType
) return rv
;
2448 if (pseudoFrames
.mTableOuter
.mFrame
) {
2449 rv
= ProcessPseudoTableFrame(pseudoFrames
, aHighestFrame
);
2452 else if (pseudoFrames
.mColGroup
.mFrame
) {
2453 // process the col group frame
2454 rv
= ProcessPseudoFrame(pseudoFrames
.mColGroup
, aHighestFrame
);
2461 ProcessPseudoFrames(nsFrameConstructorState
& aState
,
2462 nsFrameItems
& aItems
)
2466 if (gTablePseudoFrame
) {
2467 printf("*** ProcessPseudoFrames complete enter***\n");
2468 aState
.mPseudoFrames
.Dump();
2472 nsIFrame
* highestFrame
;
2473 nsresult rv
= ProcessPseudoFrames(aState
, nsnull
, highestFrame
);
2475 aItems
.AddChild(highestFrame
);
2479 if (gTablePseudoFrame
) {
2480 printf("*** ProcessPseudoFrames complete leave, highestframe:%p***\n",
2481 static_cast<void*>(highestFrame
));
2482 aState
.mPseudoFrames
.Dump();
2485 aState
.mPseudoFrames
.Reset();
2490 ProcessPseudoFrames(nsFrameConstructorState
& aState
,
2491 nsIAtom
* aHighestType
)
2494 if (gTablePseudoFrame
) {
2495 printf("*** ProcessPseudoFrames limited enter highest:");
2496 if (nsGkAtoms::tableOuterFrame
== aHighestType
)
2497 printf("OuterTable");
2498 else if (nsGkAtoms::tableFrame
== aHighestType
)
2499 printf("InnerTable");
2500 else if (nsGkAtoms::tableColGroupFrame
== aHighestType
)
2502 else if (nsGkAtoms::tableRowGroupFrame
== aHighestType
)
2504 else if (nsGkAtoms::tableRowFrame
== aHighestType
)
2506 else if (IS_TABLE_CELL(aHighestType
))
2509 NS_ASSERTION(PR_FALSE
, "invalid call to ProcessPseudoFrames ");
2511 aState
.mPseudoFrames
.Dump();
2515 nsIFrame
* highestFrame
;
2516 nsresult rv
= ProcessPseudoFrames(aState
, aHighestType
, highestFrame
);
2519 if (gTablePseudoFrame
) {
2520 printf("*** ProcessPseudoFrames limited leave:%p***\n",
2521 static_cast<void*>(highestFrame
));
2522 aState
.mPseudoFrames
.Dump();
2529 nsCSSFrameConstructor::CreatePseudoTableFrame(PRInt32 aNameSpaceID
,
2530 nsFrameConstructorState
& aState
,
2531 nsIFrame
* aParentFrameIn
)
2533 nsresult rv
= NS_OK
;
2535 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mCellInner
.mFrame
)
2536 ? aState
.mPseudoFrames
.mCellInner
.mFrame
: aParentFrameIn
;
2537 if (!parentFrame
) return rv
;
2539 nsStyleContext
*parentStyle
;
2540 nsRefPtr
<nsStyleContext
> childStyle
;
2542 parentStyle
= parentFrame
->GetStyleContext();
2543 nsIContent
* parentContent
= parentFrame
->GetContent();
2545 // Thankfully, the parent can't change display type without causing
2546 // frame reconstruction, so this won't need to change.
2547 nsIAtom
*pseudoType
;
2548 if (parentStyle
->GetStyleDisplay()->mDisplay
== NS_STYLE_DISPLAY_INLINE
)
2549 pseudoType
= nsCSSAnonBoxes::inlineTable
;
2551 pseudoType
= nsCSSAnonBoxes::table
;
2553 // create the SC for the inner table which will be the parent of the outer table's SC
2554 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2558 nsPseudoFrameData
& pseudoOuter
= aState
.mPseudoFrames
.mTableOuter
;
2559 nsPseudoFrameData
& pseudoInner
= aState
.mPseudoFrames
.mTableInner
;
2561 // construct the pseudo outer and inner as part of the pseudo frames
2563 rv
= ConstructTableFrame(aState
, parentContent
,
2564 parentFrame
, childStyle
, aNameSpaceID
,
2565 PR_TRUE
, items
, pseudoOuter
.mFrame
,
2566 pseudoInner
.mFrame
);
2568 if (NS_FAILED(rv
)) return rv
;
2570 // set pseudo data for the newly created frames
2571 pseudoOuter
.mChildList
.AddChild(pseudoInner
.mFrame
);
2572 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableFrame
;
2574 // set pseudo data for the parent
2575 if (aState
.mPseudoFrames
.mCellInner
.mFrame
) {
2576 aState
.mPseudoFrames
.mCellInner
.mChildList
.AddChild(pseudoOuter
.mFrame
);
2579 if (gTablePseudoFrame
) {
2580 printf("*** CreatePseudoTableFrame ***\n");
2581 aState
.mPseudoFrames
.Dump();
2588 nsCSSFrameConstructor::CreatePseudoRowGroupFrame(PRInt32 aNameSpaceID
,
2589 nsFrameConstructorState
& aState
,
2590 nsIFrame
* aParentFrameIn
)
2592 nsresult rv
= NS_OK
;
2594 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mTableInner
.mFrame
)
2595 ? aState
.mPseudoFrames
.mTableInner
.mFrame
: aParentFrameIn
;
2596 if (!parentFrame
) return rv
;
2598 nsStyleContext
*parentStyle
;
2599 nsRefPtr
<nsStyleContext
> childStyle
;
2601 parentStyle
= parentFrame
->GetStyleContext();
2602 nsIContent
* parentContent
= parentFrame
->GetContent();
2604 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2605 nsCSSAnonBoxes::tableRowGroup
,
2608 nsPseudoFrameData
& pseudo
= aState
.mPseudoFrames
.mRowGroup
;
2610 // construct the pseudo row group as part of the pseudo frames
2611 PRBool pseudoParent
;
2613 rv
= ConstructTableRowGroupFrame(aState
, parentContent
,
2614 parentFrame
, childStyle
, aNameSpaceID
,
2615 PR_TRUE
, items
, pseudo
.mFrame
, &pseudoParent
);
2616 if (NS_FAILED(rv
)) return rv
;
2618 // set pseudo data for the newly created frames
2619 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableRowGroupFrame
;
2621 // set pseudo data for the parent
2622 if (aState
.mPseudoFrames
.mTableInner
.mFrame
) {
2623 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(pseudo
.mFrame
);
2626 if (gTablePseudoFrame
) {
2627 printf("*** CreatePseudoRowGroupFrame ***\n");
2628 aState
.mPseudoFrames
.Dump();
2635 nsCSSFrameConstructor::CreatePseudoColGroupFrame(PRInt32 aNameSpaceID
,
2636 nsFrameConstructorState
& aState
,
2637 nsIFrame
* aParentFrameIn
)
2639 nsresult rv
= NS_OK
;
2641 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mTableInner
.mFrame
)
2642 ? aState
.mPseudoFrames
.mTableInner
.mFrame
: aParentFrameIn
;
2643 if (!parentFrame
) return rv
;
2645 nsStyleContext
*parentStyle
;
2646 nsRefPtr
<nsStyleContext
> childStyle
;
2648 parentStyle
= parentFrame
->GetStyleContext();
2649 nsIContent
* parentContent
= parentFrame
->GetContent();
2651 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2652 nsCSSAnonBoxes::tableColGroup
,
2655 nsPseudoFrameData
& pseudo
= aState
.mPseudoFrames
.mColGroup
;
2657 // construct the pseudo col group as part of the pseudo frames
2658 PRBool pseudoParent
;
2660 rv
= ConstructTableColGroupFrame(aState
, parentContent
,
2661 parentFrame
, childStyle
, aNameSpaceID
,
2662 PR_TRUE
, items
, pseudo
.mFrame
, &pseudoParent
);
2663 if (NS_FAILED(rv
)) return rv
;
2664 ((nsTableColGroupFrame
*)pseudo
.mFrame
)->SetColType(eColGroupAnonymousCol
);
2666 // Do not set aState.mPseudoFrames.mLowestType here as colgroup frame will
2667 // be always below a table frame but we can not descent any further as col
2668 // frames can not have children and will not wrap table foreign frames.
2670 // set pseudo data for the parent
2671 if (aState
.mPseudoFrames
.mTableInner
.mFrame
) {
2672 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(pseudo
.mFrame
);
2675 if (gTablePseudoFrame
) {
2676 printf("*** CreatePseudoColGroupFrame ***\n");
2677 aState
.mPseudoFrames
.Dump();
2684 nsCSSFrameConstructor::CreatePseudoRowFrame(PRInt32 aNameSpaceID
,
2685 nsFrameConstructorState
& aState
,
2686 nsIFrame
* aParentFrameIn
)
2688 nsresult rv
= NS_OK
;
2690 nsIFrame
* parentFrame
= aParentFrameIn
;
2691 if (aState
.mPseudoFrames
.mRowGroup
.mFrame
) {
2692 parentFrame
= (nsIFrame
*) nsTableFrame::GetRowGroupFrame(aState
.mPseudoFrames
.mRowGroup
.mFrame
);
2694 if (!parentFrame
) return rv
;
2696 nsStyleContext
*parentStyle
;
2697 nsRefPtr
<nsStyleContext
> childStyle
;
2699 parentStyle
= parentFrame
->GetStyleContext();
2700 nsIContent
* parentContent
= parentFrame
->GetContent();
2702 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2703 nsCSSAnonBoxes::tableRow
,
2706 nsPseudoFrameData
& pseudo
= aState
.mPseudoFrames
.mRow
;
2708 // construct the pseudo row as part of the pseudo frames
2709 PRBool pseudoParent
;
2711 rv
= ConstructTableRowFrame(aState
, parentContent
,
2712 parentFrame
, childStyle
, aNameSpaceID
,
2713 PR_TRUE
, items
, pseudo
.mFrame
, &pseudoParent
);
2714 if (NS_FAILED(rv
)) return rv
;
2716 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableRowFrame
;
2718 // set pseudo data for the parent
2719 if (aState
.mPseudoFrames
.mRowGroup
.mFrame
) {
2720 aState
.mPseudoFrames
.mRowGroup
.mChildList
.AddChild(pseudo
.mFrame
);
2723 if (gTablePseudoFrame
) {
2724 printf("*** CreatePseudoRowFrame ***\n");
2725 aState
.mPseudoFrames
.Dump();
2732 nsCSSFrameConstructor::CreatePseudoCellFrame(PRInt32 aNameSpaceID
,
2733 nsFrameConstructorState
& aState
,
2734 nsIFrame
* aParentFrameIn
)
2736 nsresult rv
= NS_OK
;
2738 nsIFrame
* parentFrame
= (aState
.mPseudoFrames
.mRow
.mFrame
)
2739 ? aState
.mPseudoFrames
.mRow
.mFrame
: aParentFrameIn
;
2740 if (!parentFrame
) return rv
;
2742 nsStyleContext
*parentStyle
;
2743 nsRefPtr
<nsStyleContext
> childStyle
;
2745 parentStyle
= parentFrame
->GetStyleContext();
2746 nsIContent
* parentContent
= parentFrame
->GetContent();
2748 childStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(parentContent
,
2749 nsCSSAnonBoxes::tableCell
,
2752 nsPseudoFrameData
& pseudoOuter
= aState
.mPseudoFrames
.mCellOuter
;
2753 nsPseudoFrameData
& pseudoInner
= aState
.mPseudoFrames
.mCellInner
;
2755 // construct the pseudo outer and inner as part of the pseudo frames
2756 PRBool pseudoParent
;
2758 rv
= ConstructTableCellFrame(aState
, parentContent
, parentFrame
, childStyle
,
2759 aNameSpaceID
, PR_TRUE
, items
,
2760 pseudoOuter
.mFrame
, pseudoInner
.mFrame
,
2762 if (NS_FAILED(rv
)) return rv
;
2764 // set pseudo data for the newly created frames
2765 pseudoOuter
.mChildList
.AddChild(pseudoInner
.mFrame
);
2766 // give it nsGkAtoms::tableCellFrame, if it is really nsGkAtoms::bcTableCellFrame, it will match later
2767 aState
.mPseudoFrames
.mLowestType
= nsGkAtoms::tableCellFrame
;
2769 // set pseudo data for the parent
2770 if (aState
.mPseudoFrames
.mRow
.mFrame
) {
2771 aState
.mPseudoFrames
.mRow
.mChildList
.AddChild(pseudoOuter
.mFrame
);
2774 if (gTablePseudoFrame
) {
2775 printf("*** CreatePseudoCellFrame ***\n");
2776 aState
.mPseudoFrames
.Dump();
2782 // called if the parent is not a table
2784 nsCSSFrameConstructor::GetPseudoTableFrame(PRInt32 aNameSpaceID
,
2785 nsFrameConstructorState
& aState
,
2786 nsIFrame
& aParentFrameIn
)
2788 nsresult rv
= NS_OK
;
2790 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2791 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2793 if (pseudoFrames
.IsEmpty()) {
2794 PRBool created
= PR_FALSE
;
2795 if (nsGkAtoms::tableRowGroupFrame
== parentFrameType
) { // row group parent
2796 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2797 if (NS_FAILED(rv
)) return rv
;
2800 if (created
|| (nsGkAtoms::tableRowFrame
== parentFrameType
)) { // row parent
2801 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2802 if (NS_FAILED(rv
)) return rv
;
2804 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2807 if (!pseudoFrames
.mTableInner
.mFrame
) {
2808 if (pseudoFrames
.mRowGroup
.mFrame
&& !(pseudoFrames
.mRow
.mFrame
)) {
2809 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
2810 if (NS_FAILED(rv
)) return rv
;
2812 if (pseudoFrames
.mRow
.mFrame
&& !(pseudoFrames
.mCellOuter
.mFrame
)) {
2813 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
2814 if (NS_FAILED(rv
)) return rv
;
2816 CreatePseudoTableFrame(aNameSpaceID
, aState
);
2822 // called if the parent is not a col group
2824 nsCSSFrameConstructor::GetPseudoColGroupFrame(PRInt32 aNameSpaceID
,
2825 nsFrameConstructorState
& aState
,
2826 nsIFrame
& aParentFrameIn
)
2828 nsresult rv
= NS_OK
;
2830 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2831 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2833 if (pseudoFrames
.IsEmpty()) {
2834 PRBool created
= PR_FALSE
;
2835 if (nsGkAtoms::tableRowGroupFrame
== parentFrameType
) { // row group parent
2836 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2839 if (created
|| (nsGkAtoms::tableRowFrame
== parentFrameType
)) { // row parent
2840 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2843 if (created
|| IS_TABLE_CELL(parentFrameType
) || // cell parent
2844 (nsGkAtoms::tableCaptionFrame
== parentFrameType
) || // caption parent
2845 !IsTableRelated(parentFrameType
, PR_TRUE
)) { // block parent
2846 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2848 rv
= CreatePseudoColGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2851 if (!pseudoFrames
.mColGroup
.mFrame
) {
2852 if (!pseudoFrames
.mTableInner
.mFrame
) {
2853 if (pseudoFrames
.mRowGroup
.mFrame
&& !(pseudoFrames
.mRow
.mFrame
)) {
2854 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
2856 if (pseudoFrames
.mRow
.mFrame
&& !(pseudoFrames
.mCellOuter
.mFrame
)) {
2857 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
2859 if (pseudoFrames
.mCellOuter
.mFrame
&& !(pseudoFrames
.mTableOuter
.mFrame
)) {
2860 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
);
2863 rv
= CreatePseudoColGroupFrame(aNameSpaceID
, aState
);
2869 // called if the parent is not a row group
2871 nsCSSFrameConstructor::GetPseudoRowGroupFrame(PRInt32 aNameSpaceID
,
2872 nsFrameConstructorState
& aState
,
2873 nsIFrame
& aParentFrameIn
)
2875 nsresult rv
= NS_OK
;
2877 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2878 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2880 if (!pseudoFrames
.mLowestType
) {
2881 PRBool created
= PR_FALSE
;
2882 if (nsGkAtoms::tableRowFrame
== parentFrameType
) { // row parent
2883 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2886 if (created
|| IS_TABLE_CELL(parentFrameType
) || // cell parent
2887 (nsGkAtoms::tableCaptionFrame
== parentFrameType
) || // caption parent
2888 !IsTableRelated(parentFrameType
, PR_TRUE
)) { // block parent
2889 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2891 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2894 if (!pseudoFrames
.mRowGroup
.mFrame
) {
2895 if (pseudoFrames
.mRow
.mFrame
&& !(pseudoFrames
.mCellOuter
.mFrame
)) {
2896 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
2898 if (pseudoFrames
.mCellOuter
.mFrame
&& !(pseudoFrames
.mTableOuter
.mFrame
)) {
2899 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
);
2901 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
);
2907 // called if the parent is not a row
2909 nsCSSFrameConstructor::GetPseudoRowFrame(PRInt32 aNameSpaceID
,
2910 nsFrameConstructorState
& aState
,
2911 nsIFrame
& aParentFrameIn
)
2913 nsresult rv
= NS_OK
;
2915 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2916 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2918 if (!pseudoFrames
.mLowestType
) {
2919 PRBool created
= PR_FALSE
;
2920 if (IS_TABLE_CELL(parentFrameType
) || // cell parent
2921 (nsGkAtoms::tableCaptionFrame
== parentFrameType
) || // caption parent
2922 !IsTableRelated(parentFrameType
, PR_TRUE
)) { // block parent
2923 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2926 if (created
|| (nsGkAtoms::tableFrame
== parentFrameType
)) { // table parent
2927 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2929 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2932 if (!pseudoFrames
.mRow
.mFrame
) {
2933 if (pseudoFrames
.mCellOuter
.mFrame
&& !pseudoFrames
.mTableOuter
.mFrame
) {
2934 rv
= CreatePseudoTableFrame(aNameSpaceID
, aState
);
2936 if (pseudoFrames
.mTableInner
.mFrame
&& !(pseudoFrames
.mRowGroup
.mFrame
)) {
2937 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
);
2939 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
2945 // called if the parent is not a cell or block
2947 nsCSSFrameConstructor::GetPseudoCellFrame(PRInt32 aNameSpaceID
,
2948 nsFrameConstructorState
& aState
,
2949 nsIFrame
& aParentFrameIn
)
2951 nsresult rv
= NS_OK
;
2953 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2954 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2956 if (!pseudoFrames
.mLowestType
) {
2957 PRBool created
= PR_FALSE
;
2958 if (nsGkAtoms::tableFrame
== parentFrameType
) { // table parent
2959 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2962 if (created
|| (nsGkAtoms::tableRowGroupFrame
== parentFrameType
)) { // row group parent
2963 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2966 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
, &aParentFrameIn
);
2968 else if (!pseudoFrames
.mCellOuter
.mFrame
) {
2969 if (pseudoFrames
.mTableInner
.mFrame
&& !(pseudoFrames
.mRowGroup
.mFrame
)) {
2970 rv
= CreatePseudoRowGroupFrame(aNameSpaceID
, aState
);
2972 if (pseudoFrames
.mRowGroup
.mFrame
&& !(pseudoFrames
.mRow
.mFrame
)) {
2973 rv
= CreatePseudoRowFrame(aNameSpaceID
, aState
);
2975 rv
= CreatePseudoCellFrame(aNameSpaceID
, aState
);
2981 nsCSSFrameConstructor::CreateRequiredPseudoFrames(PRInt32 aNameSpaceID
,
2982 nsIFrame
& aParentFrameIn
,
2983 nsIAtom
* aChildFrameType
,
2984 nsFrameConstructorState
& aState
,
2985 nsIFrame
*& aParentFrame
,
2986 PRBool
& aIsPseudoParent
)
2988 nsresult rv
= NS_OK
;
2990 nsIAtom
* parentFrameType
= aParentFrameIn
.GetType();
2991 nsIFrame
* pseudoParentFrame
= nsnull
;
2992 nsPseudoFrames
& pseudoFrames
= aState
.mPseudoFrames
;
2993 aParentFrame
= &aParentFrameIn
;
2994 aIsPseudoParent
= PR_FALSE
;
2996 nsFrameState savedStateBits
= aState
.mAdditionalStateBits
;
2997 aState
.mAdditionalStateBits
&= ~NS_FRAME_GENERATED_CONTENT
;
2999 if (nsGkAtoms::tableCaptionFrame
== aChildFrameType
) { // caption child
3000 if (nsGkAtoms::tableOuterFrame
!= parentFrameType
) { // need pseudo table parent
3001 rv
= GetPseudoTableFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3002 if (NS_FAILED(rv
)) return rv
;
3003 pseudoParentFrame
= pseudoFrames
.mTableOuter
.mFrame
;
3006 else if (nsGkAtoms::tableColGroupFrame
== aChildFrameType
) { // col group child
3007 if (nsGkAtoms::tableFrame
!= parentFrameType
) { // need pseudo table parent
3008 rv
= GetPseudoTableFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3009 if (NS_FAILED(rv
)) return rv
;
3010 pseudoParentFrame
= pseudoFrames
.mTableInner
.mFrame
;
3013 else if (nsGkAtoms::tableColFrame
== aChildFrameType
) { // col child
3014 if (nsGkAtoms::tableColGroupFrame
!= parentFrameType
) { // need pseudo col group parent
3015 rv
= GetPseudoColGroupFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3016 if (NS_FAILED(rv
)) return rv
;
3017 pseudoParentFrame
= pseudoFrames
.mColGroup
.mFrame
;
3020 else if (nsGkAtoms::tableRowGroupFrame
== aChildFrameType
) { // row group child
3021 // XXX can this go away?
3022 if (nsGkAtoms::tableFrame
!= parentFrameType
) {
3023 // trees allow row groups to contain row groups, so don't create pseudo frames
3024 rv
= GetPseudoTableFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3025 if (NS_FAILED(rv
)) return rv
;
3026 pseudoParentFrame
= pseudoFrames
.mTableInner
.mFrame
;
3029 else if (nsGkAtoms::tableRowFrame
== aChildFrameType
) { // row child
3030 if (nsGkAtoms::tableRowGroupFrame
!= parentFrameType
) { // need pseudo row group parent
3031 rv
= GetPseudoRowGroupFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3032 if (NS_FAILED(rv
)) return rv
;
3033 pseudoParentFrame
= pseudoFrames
.mRowGroup
.mFrame
;
3036 else if (IS_TABLE_CELL(aChildFrameType
)) { // cell child
3037 if (nsGkAtoms::tableRowFrame
!= parentFrameType
) { // need pseudo row parent
3038 rv
= GetPseudoRowFrame(aNameSpaceID
, aState
, aParentFrameIn
);
3039 if (NS_FAILED(rv
)) return rv
;
3040 pseudoParentFrame
= pseudoFrames
.mRow
.mFrame
;
3045 NS_ERROR("Unexpected frame type in CreateRequiredPseudoFrames");
3049 if (pseudoParentFrame
) {
3050 aParentFrame
= pseudoParentFrame
;
3051 aIsPseudoParent
= PR_TRUE
;
3054 aState
.mAdditionalStateBits
= savedStateBits
;
3059 nsCSSFrameConstructor::AdjustParentFrame(nsFrameConstructorState
& aState
,
3060 nsIContent
* aChildContent
,
3061 nsIFrame
* & aParentFrame
,
3062 const FrameConstructionData
* aFCData
,
3063 PRInt32 aNameSpaceID
,
3064 const nsStyleDisplay
* aDisplay
,
3065 nsFrameItems
* & aFrameItems
,
3066 nsFrameConstructorSaveState
& aSaveState
,
3067 PRBool
& aSuppressFrame
,
3068 PRBool
& aCreatedPseudo
)
3070 NS_PRECONDITION(aDisplay
, "Must have child's style context");
3071 NS_PRECONDITION(aFrameItems
, "Must have frame items to work with");
3072 NS_PRECONDITION(aFCData
, "Must have frame construction data");
3074 aSuppressFrame
= PR_FALSE
;
3075 aCreatedPseudo
= PR_FALSE
;
3076 if (!aParentFrame
) {
3077 // Nothing to do here
3081 PRBool tablePart
= ((aFCData
->mBits
& FCDATA_IS_TABLE_PART
) != 0);
3083 // Only use the outer table frame as parent if the child is going to use a
3084 // tableCaptionFrame, otherwise the inner table frame is the parent
3086 nsIAtom
* parentType
= aParentFrame
->GetType();
3087 NS_ASSERTION(parentType
!= nsGkAtoms::tableOuterFrame
,
3088 "Shouldn't be happening");
3089 if (parentType
== nsGkAtoms::tableColGroupFrame
) {
3090 if (!tablePart
|| aDisplay
->mDisplay
!= NS_STYLE_DISPLAY_TABLE_COLUMN
) {
3091 aSuppressFrame
= PR_TRUE
;
3096 // If our parent is a table, table-row-group, or table-row, and
3097 // we're not table-related in any way, we have to create table
3098 // pseudo-frames so that we have a table cell to live in.
3099 if (IsTableRelated(aParentFrame
->GetType(), PR_FALSE
) && !tablePart
) {
3100 nsFrameState savedStateBits
= aState
.mAdditionalStateBits
;
3101 aState
.mAdditionalStateBits
&= ~NS_FRAME_GENERATED_CONTENT
;
3102 nsresult rv
= GetPseudoCellFrame(aNameSpaceID
, aState
, *aParentFrame
);
3103 if (NS_FAILED(rv
)) {
3106 aState
.mAdditionalStateBits
= savedStateBits
;
3108 NS_ASSERTION(aState
.mPseudoFrames
.mCellInner
.mFrame
,
3109 "Must have inner cell frame now!");
3111 aParentFrame
= aState
.mPseudoFrames
.mCellInner
.mFrame
;
3112 aFrameItems
= &aState
.mPseudoFrames
.mCellInner
.mChildList
;
3113 // We pushed an anonymous table cell. The inner block of this
3114 // needs to become the float containing block.
3115 aState
.PushFloatContainingBlock(aParentFrame
, aSaveState
);
3116 aCreatedPseudo
= PR_TRUE
;
3118 // Now it might be that we had existing pseudo-frames and in particular an
3119 // existing pseudo-cell (so that the pseudo cell we just got is not the
3120 // lowest pseudo-frame). If that's the case, we need to process everythign
3121 // below that cell, so that our later siblings don't see those
3123 if (aState
.mPseudoFrames
.mTableOuter
.mFrame
) {
3124 ProcessPseudoFrames(aState
, nsGkAtoms::tableOuterFrame
);
3130 // Pull all the captions present in aItems out into aCaptions
3132 PullOutCaptionFrames(nsFrameItems
& aItems
, nsFrameItems
& aCaptions
)
3134 nsIFrame
*child
= aItems
.childList
;
3135 nsIFrame
* prev
= nsnull
;
3137 nsIFrame
*nextSibling
= child
->GetNextSibling();
3138 if (nsGkAtoms::tableCaptionFrame
== child
->GetType()) {
3139 aItems
.RemoveChild(child
, prev
);
3140 aCaptions
.AddChild(child
);
3144 child
= nextSibling
;
3149 // Construct the outer, inner table frames and the children frames for the table.
3150 // XXX Page break frames for pseudo table frames are not constructed to avoid the risk
3151 // associated with revising the pseudo frame mechanism. The long term solution
3152 // of having frames handle page-break-before/after will solve the problem.
3154 nsCSSFrameConstructor::ConstructTableFrame(nsFrameConstructorState
& aState
,
3155 nsIContent
* aContent
,
3156 nsIFrame
* aContentParent
,
3157 nsStyleContext
* aStyleContext
,
3158 PRInt32 aNameSpaceID
,
3160 nsFrameItems
& aChildItems
,
3161 nsIFrame
*& aNewOuterFrame
,
3162 nsIFrame
*& aNewInnerFrame
)
3164 nsresult rv
= NS_OK
;
3167 // create the pseudo SC for the outer table as a child of the inner SC
3168 nsRefPtr
<nsStyleContext
> outerStyleContext
;
3169 outerStyleContext
= mPresShell
->StyleSet()->
3170 ResolvePseudoStyleFor(aContent
, nsCSSAnonBoxes::tableOuter
, aStyleContext
);
3172 // Create the outer table frame which holds the caption and inner table frame
3174 if (kNameSpaceID_MathML
== aNameSpaceID
)
3175 aNewOuterFrame
= NS_NewMathMLmtableOuterFrame(mPresShell
,
3179 aNewOuterFrame
= NS_NewTableOuterFrame(mPresShell
, outerStyleContext
);
3181 NS_ASSERTION(!IsTableRelated(aContentParent
->GetType(), PR_TRUE
) ||
3182 aContentParent
->GetType() == nsGkAtoms::tableCaptionFrame
,
3183 "Unexpected parent frame for table");
3185 nsIFrame
* geometricParent
= aState
.GetGeometricParent
3186 (outerStyleContext
->GetStyleDisplay(),
3189 // Init the table outer frame and see if we need to create a view, e.g.
3190 // the frame is absolutely positioned
3191 InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
, aNewOuterFrame
);
3192 nsHTMLContainerFrame::CreateViewForFrame(aNewOuterFrame
, PR_FALSE
);
3194 // Create the inner table frame
3196 if (kNameSpaceID_MathML
== aNameSpaceID
)
3197 aNewInnerFrame
= NS_NewMathMLmtableFrame(mPresShell
, aStyleContext
);
3200 aNewInnerFrame
= NS_NewTableFrame(mPresShell
, aStyleContext
);
3202 InitAndRestoreFrame(aState
, aContent
, aNewOuterFrame
, nsnull
,
3206 // Put the newly created frames into the right child list
3207 aNewOuterFrame
->SetInitialChildList(nsnull
, aNewInnerFrame
);
3209 rv
= aState
.AddChild(aNewOuterFrame
, aChildItems
, aContent
,
3210 aStyleContext
, aContentParent
);
3211 if (NS_FAILED(rv
)) {
3215 if (!mRootElementFrame
) {
3216 // The frame we're constructing will be the root element frame.
3217 // Set mRootElementFrame before processing children.
3218 mRootElementFrame
= aNewOuterFrame
;
3221 nsFrameItems childItems
;
3222 rv
= ProcessChildren(aState
, aContent
, aStyleContext
, aNewInnerFrame
,
3223 PR_TRUE
, childItems
, PR_FALSE
);
3224 // XXXbz what about cleaning up?
3225 if (NS_FAILED(rv
)) return rv
;
3227 nsFrameItems captionItems
;
3228 PullOutCaptionFrames(childItems
, captionItems
);
3230 // Set the inner table frame's initial primary list
3231 aNewInnerFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3233 // Set the outer table frame's secondary childlist lists
3234 if (captionItems
.childList
) {
3235 aNewOuterFrame
->SetInitialChildList(nsGkAtoms::captionList
,
3236 captionItems
.childList
);
3244 nsCSSFrameConstructor::ConstructTableCaptionFrame(nsFrameConstructorState
& aState
,
3245 nsIContent
* aContent
,
3246 nsIFrame
* aParentFrameIn
,
3247 nsStyleContext
* aStyleContext
,
3248 PRInt32 aNameSpaceID
,
3249 nsFrameItems
& aChildItems
,
3250 nsIFrame
*& aNewFrame
,
3251 PRBool
* aHasPseudoParent
)
3254 if (!aParentFrameIn
) return NS_ERROR_UNEXPECTED
;
3256 nsIFrame
* parentFrame
= aParentFrameIn
;
3257 *aHasPseudoParent
= PR_FALSE
;
3258 // this frame may have a pseudo parent
3259 CreateRequiredPseudoFrames(aNameSpaceID
, *aParentFrameIn
,
3260 nsGkAtoms::tableCaptionFrame
, aState
, parentFrame
,
3262 if (!*aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3263 ProcessPseudoFrames(aState
, aChildItems
);
3266 aNewFrame
= NS_NewTableCaptionFrame(mPresShell
, aStyleContext
);
3267 if (NS_UNLIKELY(!aNewFrame
)) {
3268 return NS_ERROR_OUT_OF_MEMORY
;
3270 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3271 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, PR_FALSE
);
3273 nsFrameItems childItems
;
3274 nsresult rv
= ProcessChildren(aState
, aContent
, aStyleContext
, aNewFrame
,
3275 PR_TRUE
, childItems
, PR_TRUE
);
3276 if (NS_FAILED(rv
)) return rv
;
3277 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3278 if (*aHasPseudoParent
) {
3279 aState
.mPseudoFrames
.mTableOuter
.mChildList2
.AddChild(aNewFrame
);
3287 nsCSSFrameConstructor::ConstructTableRowGroupFrame(nsFrameConstructorState
& aState
,
3288 nsIContent
* aContent
,
3289 nsIFrame
* aParentFrameIn
,
3290 nsStyleContext
* aStyleContext
,
3291 PRInt32 aNameSpaceID
,
3293 nsFrameItems
& aChildItems
,
3294 nsIFrame
*& aNewFrame
,
3295 PRBool
* aHasPseudoParent
)
3297 if (!aParentFrameIn
) return NS_ERROR_UNEXPECTED
;
3299 nsIFrame
* parentFrame
= aParentFrameIn
;
3300 *aHasPseudoParent
= PR_FALSE
;
3302 // this frame may have a pseudo parent
3303 CreateRequiredPseudoFrames(aNameSpaceID
, *aParentFrameIn
,
3304 nsGkAtoms::tableRowGroupFrame
, aState
,
3305 parentFrame
, *aHasPseudoParent
);
3306 if (!*aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3307 ProcessPseudoFrames(aState
, aChildItems
);
3309 if (!aIsPseudo
&& *aHasPseudoParent
&&
3310 aState
.mPseudoFrames
.mRowGroup
.mFrame
) {
3311 ProcessPseudoFrames(aState
, nsGkAtoms::tableRowGroupFrame
);
3315 const nsStyleDisplay
* styleDisplay
= aStyleContext
->GetStyleDisplay();
3317 aNewFrame
= NS_NewTableRowGroupFrame(mPresShell
, aStyleContext
);
3319 nsIFrame
* scrollFrame
= nsnull
;
3320 if (styleDisplay
->IsScrollableOverflow()) {
3321 // Create an area container for the frame
3322 BuildScrollFrame(aState
, aContent
, aStyleContext
, aNewFrame
, parentFrame
,
3327 if (NS_UNLIKELY(!aNewFrame
)) {
3328 return NS_ERROR_OUT_OF_MEMORY
;
3330 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3331 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, PR_FALSE
);
3335 nsFrameItems childItems
;
3336 nsresult rv
= ProcessChildren(aState
, aContent
, aStyleContext
, aNewFrame
,
3337 PR_TRUE
, childItems
, PR_FALSE
);
3339 if (NS_FAILED(rv
)) return rv
;
3341 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3342 if (*aHasPseudoParent
) {
3343 nsIFrame
* child
= (scrollFrame
) ? scrollFrame
: aNewFrame
;
3344 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(child
);
3348 // if there is a scroll frame, use it as the one constructed
3350 aNewFrame
= scrollFrame
;
3357 nsCSSFrameConstructor::ConstructTableColGroupFrame(nsFrameConstructorState
& aState
,
3358 nsIContent
* aContent
,
3359 nsIFrame
* aParentFrameIn
,
3360 nsStyleContext
* aStyleContext
,
3361 PRInt32 aNameSpaceID
,
3363 nsFrameItems
& aChildItems
,
3364 nsIFrame
*& aNewFrame
,
3365 PRBool
* aHasPseudoParent
)
3367 if (!aParentFrameIn
) return NS_ERROR_UNEXPECTED
;
3369 nsIFrame
* parentFrame
= aParentFrameIn
;
3370 *aHasPseudoParent
= PR_FALSE
;
3372 // this frame may have a pseudo parent
3373 CreateRequiredPseudoFrames(aNameSpaceID
, *aParentFrameIn
,
3374 nsGkAtoms::tableColGroupFrame
, aState
,
3375 parentFrame
, *aHasPseudoParent
);
3376 if (!*aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3377 ProcessPseudoFrames(aState
, aChildItems
);
3379 if (!aIsPseudo
&& *aHasPseudoParent
&&
3380 aState
.mPseudoFrames
.mColGroup
.mFrame
) {
3381 ProcessPseudoFrames(aState
, nsGkAtoms::tableColGroupFrame
);
3385 aNewFrame
= NS_NewTableColGroupFrame(mPresShell
, aStyleContext
);
3386 if (NS_UNLIKELY(!aNewFrame
)) {
3387 return NS_ERROR_OUT_OF_MEMORY
;
3389 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3392 nsFrameItems childItems
;
3393 nsresult rv
= ProcessChildren(aState
, aContent
, aStyleContext
, aNewFrame
,
3394 PR_TRUE
, childItems
, PR_FALSE
);
3395 if (NS_FAILED(rv
)) return rv
;
3396 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3397 if (*aHasPseudoParent
) {
3398 aState
.mPseudoFrames
.mTableInner
.mChildList
.AddChild(aNewFrame
);
3406 nsCSSFrameConstructor::ConstructTableRowFrame(nsFrameConstructorState
& aState
,
3407 nsIContent
* aContent
,
3408 nsIFrame
* aParentFrameIn
,
3409 nsStyleContext
* aStyleContext
,
3410 PRInt32 aNameSpaceID
,
3412 nsFrameItems
& aChildItems
,
3413 nsIFrame
*& aNewFrame
,
3414 PRBool
* aHasPseudoParent
)
3416 if (!aParentFrameIn
) return NS_ERROR_UNEXPECTED
;
3418 nsIFrame
* parentFrame
= aParentFrameIn
;
3419 *aHasPseudoParent
= PR_FALSE
;
3421 // this frame may have a pseudo parent
3422 CreateRequiredPseudoFrames(aNameSpaceID
, *aParentFrameIn
,
3423 nsGkAtoms::tableRowFrame
, aState
, parentFrame
,
3425 if (!*aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3426 ProcessPseudoFrames(aState
, aChildItems
);
3428 if (!aIsPseudo
&& *aHasPseudoParent
&& aState
.mPseudoFrames
.mRow
.mFrame
) {
3429 ProcessPseudoFrames(aState
, nsGkAtoms::tableRowFrame
);
3434 if (kNameSpaceID_MathML
== aNameSpaceID
)
3435 aNewFrame
= NS_NewMathMLmtrFrame(mPresShell
, aStyleContext
);
3438 aNewFrame
= NS_NewTableRowFrame(mPresShell
, aStyleContext
);
3440 if (NS_UNLIKELY(!aNewFrame
)) {
3441 return NS_ERROR_OUT_OF_MEMORY
;
3443 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3444 nsHTMLContainerFrame::CreateViewForFrame(aNewFrame
, PR_FALSE
);
3446 nsFrameItems childItems
;
3447 nsresult rv
= ProcessChildren(aState
, aContent
, aStyleContext
, aNewFrame
,
3448 PR_TRUE
, childItems
, PR_FALSE
);
3449 if (NS_FAILED(rv
)) return rv
;
3451 aNewFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3452 if (*aHasPseudoParent
) {
3453 aState
.mPseudoFrames
.mRowGroup
.mChildList
.AddChild(aNewFrame
);
3461 nsCSSFrameConstructor::ConstructTableColFrame(nsFrameConstructorState
& aState
,
3462 nsIContent
* aContent
,
3463 nsIFrame
* aParentFrameIn
,
3464 nsStyleContext
* aStyleContext
,
3465 PRInt32 aNameSpaceID
,
3467 nsFrameItems
& aChildItems
,
3468 nsIFrame
*& aNewFrame
,
3469 PRBool
* aHasPseudoParent
)
3471 if (!aParentFrameIn
|| !aStyleContext
) return NS_ERROR_UNEXPECTED
;
3473 nsIFrame
* parentFrame
= aParentFrameIn
;
3474 *aHasPseudoParent
= PR_FALSE
;
3476 // this frame may have a pseudo parent
3477 CreateRequiredPseudoFrames(aNameSpaceID
, *aParentFrameIn
,
3478 nsGkAtoms::tableColFrame
, aState
, parentFrame
,
3480 if (!*aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3481 ProcessPseudoFrames(aState
, aChildItems
);
3485 nsTableColFrame
* colFrame
= NS_NewTableColFrame(mPresShell
, aStyleContext
);
3486 aNewFrame
= colFrame
;
3487 if (NS_UNLIKELY(!aNewFrame
)) {
3488 return NS_ERROR_OUT_OF_MEMORY
;
3490 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewFrame
);
3492 // construct additional col frames if the col frame has a span > 1
3493 PRInt32 span
= colFrame
->GetSpan();
3494 nsIFrame
* lastCol
= aNewFrame
;
3495 nsStyleContext
* styleContext
= nsnull
;
3496 for (PRInt32 spanX
= 1; spanX
< span
; spanX
++) {
3497 // The same content node should always resolve to the same style context.
3499 styleContext
= aNewFrame
->GetStyleContext();
3500 nsTableColFrame
* newCol
= NS_NewTableColFrame(mPresShell
, styleContext
);
3501 if (NS_UNLIKELY(!newCol
)) {
3502 return NS_ERROR_OUT_OF_MEMORY
;
3504 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, newCol
, PR_FALSE
);
3505 lastCol
->SetNextSibling(newCol
);
3506 lastCol
->SetNextContinuation(newCol
);
3507 newCol
->SetPrevContinuation(lastCol
);
3508 newCol
->SetColType(eColAnonymousCol
);
3512 if (!aIsPseudo
&& *aHasPseudoParent
) {
3513 aState
.mPseudoFrames
.mColGroup
.mChildList
.AddChild(aNewFrame
);
3520 nsCSSFrameConstructor::ConstructTableCellFrame(nsFrameConstructorState
& aState
,
3521 nsIContent
* aContent
,
3522 nsIFrame
* aParentFrameIn
,
3523 nsStyleContext
* aStyleContext
,
3524 PRInt32 aNameSpaceID
,
3526 nsFrameItems
& aChildItems
,
3527 nsIFrame
*& aNewCellOuterFrame
,
3528 nsIFrame
*& aNewCellInnerFrame
,
3529 PRBool
* aHasPseudoParent
)
3531 if (!aParentFrameIn
) return NS_ERROR_UNEXPECTED
;
3533 nsIFrame
* parentFrame
= aParentFrameIn
;
3534 *aHasPseudoParent
= PR_FALSE
;
3536 // this frame may have a pseudo parent
3537 // use nsGkAtoms::tableCellFrame which will match if it is really nsGkAtoms::bcTableCellFrame
3538 CreateRequiredPseudoFrames(aNameSpaceID
, *aParentFrameIn
,
3539 nsGkAtoms::tableCellFrame
, aState
, parentFrame
,
3541 if (!*aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty()) {
3542 ProcessPseudoFrames(aState
, aChildItems
);
3544 if (!aIsPseudo
&& *aHasPseudoParent
&& aState
.mPseudoFrames
.mCellOuter
.mFrame
) {
3545 ProcessPseudoFrames(aState
, nsGkAtoms::tableCellFrame
);
3549 // <mtable> is border separate in mathml.css and the MathML code doesn't implement
3550 // border collapse. For those users who style <mtable> with border collapse,
3551 // give them the default non-MathML table frames that understand border collpase.
3552 // This won't break us because MathML table frames are all subclasses of the default
3553 // table code, and so we can freely mix <mtable> with <mtr> or <tr>, <mtd> or <td>.
3554 // What will happen is just that non-MathML frames won't understand MathML attributes
3555 // and will therefore miss the special handling that the MathML code does.
3556 if (kNameSpaceID_MathML
== aNameSpaceID
&& !IsBorderCollapse(parentFrame
))
3557 aNewCellOuterFrame
= NS_NewMathMLmtdFrame(mPresShell
, aStyleContext
);
3560 // Warning: If you change this and add a wrapper frame around table cell
3561 // frames, make sure Bug 368554 doesn't regress!
3562 // See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp.
3563 aNewCellOuterFrame
= NS_NewTableCellFrame(mPresShell
, aStyleContext
,
3564 IsBorderCollapse(parentFrame
));
3566 if (NS_UNLIKELY(!aNewCellOuterFrame
)) {
3567 return NS_ERROR_OUT_OF_MEMORY
;
3570 // Initialize the table cell frame
3571 InitAndRestoreFrame(aState
, aContent
, parentFrame
, nsnull
, aNewCellOuterFrame
);
3572 nsHTMLContainerFrame::CreateViewForFrame(aNewCellOuterFrame
, PR_FALSE
);
3574 // Resolve pseudo style and initialize the body cell frame
3575 nsRefPtr
<nsStyleContext
> innerPseudoStyle
;
3576 innerPseudoStyle
= mPresShell
->StyleSet()->
3577 ResolvePseudoStyleFor(aContent
,
3578 nsCSSAnonBoxes::cellContent
, aStyleContext
);
3580 // Create a block frame that will format the cell's content
3583 if (kNameSpaceID_MathML
== aNameSpaceID
) {
3584 aNewCellInnerFrame
= NS_NewMathMLmtdInnerFrame(mPresShell
, innerPseudoStyle
);
3590 aNewCellInnerFrame
= NS_NewBlockFormattingContext(mPresShell
,
3596 if (NS_UNLIKELY(!aNewCellInnerFrame
)) {
3597 aNewCellOuterFrame
->Destroy();
3598 aNewCellOuterFrame
= nsnull
;
3599 return NS_ERROR_OUT_OF_MEMORY
;
3602 InitAndRestoreFrame(aState
, aContent
, aNewCellOuterFrame
, nsnull
, aNewCellInnerFrame
);
3605 // Process the child content
3606 nsFrameItems childItems
;
3607 nsresult rv
= ProcessChildren(aState
, aContent
, aStyleContext
,
3608 aNewCellInnerFrame
, PR_TRUE
, childItems
, isBlock
);
3610 if (NS_FAILED(rv
)) {
3612 // XXXbz kids of this stuff need to be cleaned up too!
3613 aNewCellInnerFrame
->Destroy();
3614 aNewCellInnerFrame
= nsnull
;
3615 aNewCellOuterFrame
->Destroy();
3616 aNewCellOuterFrame
= nsnull
;
3620 aNewCellInnerFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3621 aNewCellOuterFrame
->SetInitialChildList(nsnull
, aNewCellInnerFrame
);
3622 if (*aHasPseudoParent
) {
3623 aState
.mPseudoFrames
.mRow
.mChildList
.AddChild(aNewCellOuterFrame
);
3631 NeedFrameFor(nsIFrame
* aParentFrame
,
3632 nsIContent
* aChildContent
)
3634 // don't create a whitespace frame if aParentFrame doesn't want it.
3635 // always create frames for children in generated content. counter(),
3636 // quotes, and attr() content can easily change dynamically and we don't
3637 // want to be reconstructing frames. It's not even clear that these
3638 // should be considered ignorable just because they evaluate to
3640 return !aParentFrame
->IsFrameOfType(nsIFrame::eExcludesIgnorableWhitespace
)
3641 || !TextIsOnlyWhitespace(aChildContent
)
3642 || aParentFrame
->IsGeneratedContentFrame();
3645 /***********************************************
3647 ***********************************************/
3649 static PRBool
CheckOverflow(nsPresContext
* aPresContext
,
3650 const nsStyleDisplay
* aDisplay
)
3652 if (aDisplay
->mOverflowX
== NS_STYLE_OVERFLOW_VISIBLE
)
3655 if (aDisplay
->mOverflowX
== NS_STYLE_OVERFLOW_CLIP
)
3656 aPresContext
->SetViewportOverflowOverride(NS_STYLE_OVERFLOW_HIDDEN
,
3657 NS_STYLE_OVERFLOW_HIDDEN
);
3659 aPresContext
->SetViewportOverflowOverride(aDisplay
->mOverflowX
,
3660 aDisplay
->mOverflowY
);
3665 * This checks the root element and the HTML BODY, if any, for an "overflow" property
3666 * that should be applied to the viewport. If one is found then we return the
3667 * element that we took the overflow from (which should then be treated as
3668 * "overflow:visible"), and we store the overflow style in the prescontext.
3669 * @return if scroll was propagated from some content node, the content node it
3670 * was propagated from.
3673 nsCSSFrameConstructor::PropagateScrollToViewport()
3676 nsPresContext
* presContext
= mPresShell
->GetPresContext();
3677 presContext
->SetViewportOverflowOverride(NS_STYLE_OVERFLOW_AUTO
,
3678 NS_STYLE_OVERFLOW_AUTO
);
3680 // We never mess with the viewport scroll state
3681 // when printing or in print preview
3682 if (presContext
->IsPaginated()) {
3686 nsIContent
* docElement
= mDocument
->GetRootContent();
3688 // Check the style on the document root element
3689 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
3690 nsRefPtr
<nsStyleContext
> rootStyle
;
3691 rootStyle
= styleSet
->ResolveStyleFor(docElement
, nsnull
);
3695 if (CheckOverflow(presContext
, rootStyle
->GetStyleDisplay())) {
3696 // tell caller we stole the overflow style from the root element
3700 // Don't look in the BODY for non-HTML documents or HTML documents
3701 // with non-HTML roots
3702 // XXX this should be earlier; we shouldn't even look at the document root
3703 // for non-HTML documents. Fix this once we support explicit CSS styling
3705 // XXX what about XHTML?
3706 nsCOMPtr
<nsIDOMHTMLDocument
> htmlDoc(do_QueryInterface(mDocument
));
3707 if (!htmlDoc
|| !docElement
->IsNodeOfType(nsINode::eHTML
)) {
3711 nsCOMPtr
<nsIDOMHTMLElement
> body
;
3712 htmlDoc
->GetBody(getter_AddRefs(body
));
3713 nsCOMPtr
<nsIContent
> bodyElement
= do_QueryInterface(body
);
3716 !bodyElement
->NodeInfo()->Equals(nsGkAtoms::body
)) {
3717 // The body is not a <body> tag, it's a <frameset>.
3721 nsRefPtr
<nsStyleContext
> bodyStyle
;
3722 bodyStyle
= styleSet
->ResolveStyleFor(bodyElement
, rootStyle
);
3727 if (CheckOverflow(presContext
, bodyStyle
->GetStyleDisplay())) {
3728 // tell caller we stole the overflow style from the body element
3739 nsCSSFrameConstructor::ConstructDocElementFrame(nsFrameConstructorState
& aState
,
3740 nsIContent
* aDocElement
,
3741 nsIFrame
* aParentFrame
,
3742 nsIFrame
** aNewFrame
)
3744 *aNewFrame
= nsnull
;
3746 if (!mTempFrameTreeState
)
3747 aState
.mPresShell
->CaptureHistoryState(getter_AddRefs(mTempFrameTreeState
));
3749 // ----- reattach gfx scrollbars ------
3750 // Gfx scrollframes were created in the root frame but the primary frame map may have been destroyed if a
3751 // new style sheet was loaded so lets reattach the frames to their content.
3752 // XXX this seems truly bogus, we wipe out mGfxScrollFrame below
3753 if (mGfxScrollFrame
) {
3754 nsIFrame
* gfxScrollbarFrame1
= mGfxScrollFrame
->GetFirstChild(nsnull
);
3755 // Check the frame type because when there aren't scrollbars, we'll
3757 if (gfxScrollbarFrame1
&&
3758 gfxScrollbarFrame1
->GetType() == nsGkAtoms::scrollbarFrame
) {
3759 // XXX This works, but why?
3760 aState
.mFrameManager
->
3761 SetPrimaryFrameFor(gfxScrollbarFrame1
->GetContent(), gfxScrollbarFrame1
);
3763 nsIFrame
* gfxScrollbarFrame2
= gfxScrollbarFrame1
->GetNextSibling();
3764 if (gfxScrollbarFrame2
&&
3765 gfxScrollbarFrame2
->GetType() == nsGkAtoms::scrollbarFrame
) {
3766 // XXX This works, but why?
3767 aState
.mFrameManager
->
3768 SetPrimaryFrameFor(gfxScrollbarFrame2
->GetContent(), gfxScrollbarFrame2
);
3773 // --------- CREATE AREA OR BOX FRAME -------
3774 nsRefPtr
<nsStyleContext
> styleContext
;
3775 styleContext
= mPresShell
->StyleSet()->ResolveStyleFor(aDocElement
,
3778 const nsStyleDisplay
* display
= styleContext
->GetStyleDisplay();
3780 // Ensure that our XBL bindings are installed.
3781 if (display
->mBinding
) {
3782 // Get the XBL loader.
3784 PRBool resolveStyle
;
3786 nsIXBLService
* xblService
= GetXBLService();
3788 return NS_ERROR_FAILURE
;
3790 nsRefPtr
<nsXBLBinding
> binding
;
3791 rv
= xblService
->LoadBindings(aDocElement
, display
->mBinding
->mURI
,
3792 display
->mBinding
->mOriginPrincipal
,
3793 PR_FALSE
, getter_AddRefs(binding
),
3796 return NS_OK
; // Binding will load asynchronously.
3799 mDocument
->BindingManager()->AddToAttachedQueue(binding
);
3803 styleContext
= mPresShell
->StyleSet()->ResolveStyleFor(aDocElement
,
3805 display
= styleContext
->GetStyleDisplay();
3809 // --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------
3812 PRBool propagatedScrollToViewport
=
3813 PropagateScrollToViewport() == aDocElement
;
3815 NS_ASSERTION(!display
->IsScrollableOverflow() ||
3816 aState
.mPresContext
->IsPaginated() ||
3817 propagatedScrollToViewport
,
3818 "Scrollbars should have been propagated to the viewport");
3821 if (NS_UNLIKELY(display
->mDisplay
== NS_STYLE_DISPLAY_NONE
)) {
3822 aState
.mFrameManager
->SetUndisplayedContent(aDocElement
, styleContext
);
3823 mRootElementFrame
= nsnull
;
3824 mRootElementStyleFrame
= nsnull
;
3828 nsFrameConstructorSaveState absoluteSaveState
;
3829 if (mHasRootAbsPosContainingBlock
) {
3830 // Push the absolute containing block now so we can absolutely position
3832 aState
.PushAbsoluteContainingBlock(mDocElementContainingBlock
, absoluteSaveState
);
3837 // The rules from CSS 2.1, section 9.2.4, have already been applied
3838 // by the style system, so we can assume that display->mDisplay is
3839 // either NONE, BLOCK, or TABLE.
3841 // contentFrame is the primary frame for the root element. *aNewFrame
3842 // is the frame that will be the child of the initial containing block.
3843 // These are usually the same frame but they can be different, in
3844 // particular if the root frame is positioned, in which case
3845 // contentFrame is the out-of-flow frame and *aNewFrame is the
3847 nsIFrame
* contentFrame
;
3848 PRBool processChildren
= PR_FALSE
;
3850 // Check whether we need to build a XUL box or SVG root frame
3852 if (aDocElement
->IsNodeOfType(nsINode::eXUL
)) {
3853 contentFrame
= NS_NewDocElementBoxFrame(mPresShell
, styleContext
);
3854 if (NS_UNLIKELY(!contentFrame
)) {
3855 return NS_ERROR_OUT_OF_MEMORY
;
3857 InitAndRestoreFrame(aState
, aDocElement
, aParentFrame
, nsnull
, contentFrame
);
3858 *aNewFrame
= contentFrame
;
3859 processChildren
= PR_TRUE
;
3864 if (aDocElement
->GetNameSpaceID() == kNameSpaceID_SVG
) {
3865 if (aDocElement
->Tag() == nsGkAtoms::svg
&& NS_SVGEnabled()) {
3866 contentFrame
= NS_NewSVGOuterSVGFrame(mPresShell
, styleContext
);
3867 if (NS_UNLIKELY(!contentFrame
)) {
3868 return NS_ERROR_OUT_OF_MEMORY
;
3870 InitAndRestoreFrame(aState
, aDocElement
,
3871 aState
.GetGeometricParent(display
, aParentFrame
),
3872 nsnull
, contentFrame
);
3874 // AddChild takes care of transforming the frame tree for fixed-pos
3875 // or abs-pos situations
3876 nsFrameItems frameItems
;
3877 rv
= aState
.AddChild(contentFrame
, frameItems
, aDocElement
,
3878 styleContext
, aParentFrame
);
3879 if (NS_FAILED(rv
) || !frameItems
.childList
) {
3882 *aNewFrame
= frameItems
.childList
;
3883 processChildren
= PR_TRUE
;
3885 // See if we need to create a view
3886 nsHTMLContainerFrame::CreateViewForFrame(contentFrame
, PR_FALSE
);
3888 return NS_ERROR_FAILURE
;
3894 PRBool docElemIsTable
= (display
->mDisplay
== NS_STYLE_DISPLAY_TABLE
);
3895 if (docElemIsTable
) {
3896 nsIFrame
* innerTableFrame
;
3897 nsFrameItems frameItems
;
3898 // if the document is a table then just populate it.
3899 rv
= ConstructTableFrame(aState
, aDocElement
,
3900 aParentFrame
, styleContext
,
3901 kNameSpaceID_None
, PR_FALSE
, frameItems
,
3902 contentFrame
, innerTableFrame
);
3905 if (!contentFrame
|| !frameItems
.childList
)
3906 return NS_ERROR_FAILURE
;
3907 *aNewFrame
= frameItems
.childList
;
3908 NS_ASSERTION(!frameItems
.childList
->GetNextSibling(),
3909 "multiple root element frames");
3911 contentFrame
= NS_NewBlockFrame(mPresShell
, styleContext
,
3912 NS_BLOCK_FLOAT_MGR
|NS_BLOCK_MARGIN_ROOT
);
3914 return NS_ERROR_OUT_OF_MEMORY
;
3915 nsFrameItems frameItems
;
3916 rv
= ConstructBlock(aState
, display
, aDocElement
,
3917 aState
.GetGeometricParent(display
, aParentFrame
),
3918 aParentFrame
, styleContext
, &contentFrame
,
3919 frameItems
, display
->IsPositioned());
3920 if (NS_FAILED(rv
) || !frameItems
.childList
)
3922 *aNewFrame
= frameItems
.childList
;
3923 NS_ASSERTION(!frameItems
.childList
->GetNextSibling(),
3924 "multiple root element frames");
3928 // set the primary frame
3929 aState
.mFrameManager
->SetPrimaryFrameFor(aDocElement
, contentFrame
);
3931 NS_ASSERTION(processChildren
? !mRootElementFrame
:
3932 mRootElementFrame
== contentFrame
,
3933 "unexpected mRootElementFrame");
3934 mRootElementFrame
= contentFrame
;
3936 // Figure out which frame has the main style for the document element,
3937 // assigning it to mRootElementStyleFrame.
3938 // Backgrounds should be propagated from that frame to the viewport.
3940 contentFrame
->GetParentStyleContextFrame(aState
.mPresContext
,
3941 &mRootElementStyleFrame
, &isChild
);
3943 mRootElementStyleFrame
= mRootElementFrame
;
3946 if (processChildren
) {
3947 // Still need to process the child content
3948 nsFrameItems childItems
;
3950 NS_ASSERTION(!nsLayoutUtils::GetAsBlock(contentFrame
),
3951 "Only XUL and SVG frames should reach here");
3952 ProcessChildren(aState
, aDocElement
, styleContext
, contentFrame
, PR_TRUE
,
3953 childItems
, PR_FALSE
);
3955 // Set the initial child lists
3956 contentFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
3964 nsCSSFrameConstructor::ConstructRootFrame(nsIContent
* aDocElement
,
3965 nsIFrame
** aNewFrame
)
3967 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
3968 NS_PRECONDITION(aNewFrame
, "null out param");
3971 how the root frame hierarchy should look
3973 Galley presentation, non-XUL, with scrolling (i.e. not a frameset):
3975 ViewportFrame [fixed-cb]
3977 CanvasFrame [abs-cb]
3978 root element frame (nsBlockFrame, nsSVGOuterSVGFrame,
3979 nsTableOuterFrame, nsPlaceholderFrame)
3981 Galley presentation, non-XUL, without scrolling (i.e. a frameset):
3983 ViewportFrame [fixed-cb]
3984 CanvasFrame [abs-cb]
3985 root element frame (nsBlockFrame)
3987 Galley presentation, XUL
3989 ViewportFrame [fixed-cb]
3991 root element frame (nsDocElementBoxFrame)
3993 Print presentation, non-XUL
3996 nsSimplePageSequenceFrame
3997 nsPageFrame [fixed-cb]
3999 CanvasFrame [abs-cb]
4000 root element frame (nsBlockFrame, nsSVGOuterSVGFrame,
4001 nsTableOuterFrame, nsPlaceholderFrame)
4003 Print-preview presentation, non-XUL
4007 nsSimplePageSequenceFrame
4008 nsPageFrame [fixed-cb]
4010 CanvasFrame [abs-cb]
4011 root element frame (nsBlockFrame, nsSVGOuterSVGFrame,
4012 nsTableOuterFrame, nsPlaceholderFrame)
4014 Print/print preview of XUL is not supported.
4015 [fixed-cb]: the default containing block for fixed-pos content
4016 [abs-cb]: the default containing block for abs-pos content
4018 Meaning of nsCSSFrameConstructor fields:
4019 mRootElementFrame is "root element frame".
4020 mDocElementContainingBlock is the parent of mRootElementFrame
4021 (i.e. CanvasFrame or nsRootBoxFrame)
4022 mFixedContainingBlock is the [fixed-cb]
4023 mGfxScrollFrame is the nsHTMLScrollFrame mentioned above, or null if there isn't one
4024 mPageSequenceFrame is the nsSimplePageSequenceFrame, or null if there isn't one
4027 // Set up our style rule observer.
4029 mPresShell
->StyleSet()->SetBindingManager(mDocument
->BindingManager());
4032 // --------- BUILD VIEWPORT -----------
4033 nsIFrame
* viewportFrame
= nsnull
;
4034 nsRefPtr
<nsStyleContext
> viewportPseudoStyle
;
4035 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
4037 viewportPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4038 nsCSSAnonBoxes::viewport
,
4041 viewportFrame
= NS_NewViewportFrame(mPresShell
, viewportPseudoStyle
);
4043 nsPresContext
* presContext
= mPresShell
->GetPresContext();
4045 // XXXbz do we _have_ to pass a null content pointer to that frame?
4046 // Would it really kill us to pass in the root element or something?
4047 // What would that break?
4048 viewportFrame
->Init(nsnull
, nsnull
, nsnull
);
4050 // Bind the viewport frame to the root view
4051 nsIViewManager
* viewManager
= mPresShell
->GetViewManager();
4054 viewManager
->GetRootView(rootView
);
4055 viewportFrame
->SetView(rootView
);
4057 nsContainerFrame::SyncFrameViewProperties(presContext
, viewportFrame
,
4058 viewportPseudoStyle
, rootView
);
4060 // The viewport is the containing block for 'fixed' elements
4061 mFixedContainingBlock
= viewportFrame
;
4063 // --------- CREATE ROOT FRAME -------
4066 // Create the root frame. The document element's frame is a child of the
4069 // The root frame serves two purposes:
4070 // - reserves space for any margins needed for the document element's frame
4071 // - renders the document element's background. This ensures the background covers
4072 // the entire canvas as specified by the CSS2 spec
4074 PRBool isPaginated
= presContext
->IsRootPaginatedDocument();
4076 nsIFrame
* rootFrame
= nsnull
;
4077 nsIAtom
* rootPseudo
;
4081 if (aDocElement
->IsNodeOfType(nsINode::eXUL
))
4083 // pass a temporary stylecontext, the correct one will be set later
4084 rootFrame
= NS_NewRootBoxFrame(mPresShell
, viewportPseudoStyle
);
4088 // pass a temporary stylecontext, the correct one will be set later
4089 rootFrame
= NS_NewCanvasFrame(mPresShell
, viewportPseudoStyle
);
4090 mHasRootAbsPosContainingBlock
= PR_TRUE
;
4093 rootPseudo
= nsCSSAnonBoxes::canvas
;
4094 mDocElementContainingBlock
= rootFrame
;
4096 // Create a page sequence frame
4097 rootFrame
= NS_NewSimplePageSequenceFrame(mPresShell
, viewportPseudoStyle
);
4098 mPageSequenceFrame
= rootFrame
;
4099 rootPseudo
= nsCSSAnonBoxes::pageSequence
;
4103 // --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------
4105 // If the device supports scrolling (e.g., in galley mode on the screen and
4106 // for print-preview, but not when printing), then create a scroll frame that
4107 // will act as the scrolling mechanism for the viewport.
4108 // XXX Do we even need a viewport when printing to a printer?
4110 // As long as the webshell doesn't prohibit it, and the device supports
4111 // it, create a scroll frame that will act as the scolling mechanism for
4114 // Threre are three possible values stored in the docshell:
4115 // 1) nsIScrollable::Scrollbar_Never = no scrollbars
4116 // 2) nsIScrollable::Scrollbar_Auto = scrollbars appear if needed
4117 // 3) nsIScrollable::Scrollbar_Always = scrollbars always
4118 // Only need to create a scroll frame/view for cases 2 and 3.
4120 PRBool isHTML
= aDocElement
->IsNodeOfType(nsINode::eHTML
);
4121 PRBool isXUL
= PR_FALSE
;
4124 isXUL
= aDocElement
->IsNodeOfType(nsINode::eXUL
);
4127 // Never create scrollbars for XUL documents
4128 PRBool isScrollable
= !isXUL
;
4130 // Never create scrollbars for frameset documents.
4132 nsCOMPtr
<nsIHTMLDocument
> htmlDoc
= do_QueryInterface(mDocument
);
4133 if (htmlDoc
&& htmlDoc
->GetIsFrameset())
4134 isScrollable
= PR_FALSE
;
4138 isScrollable
= presContext
->HasPaginatedScrolling();
4141 // We no longer need to do overflow propagation here. It's taken care of
4142 // when we construct frames for the element whose overflow might be
4144 NS_ASSERTION(!isScrollable
|| !isXUL
,
4145 "XUL documents should never be scrollable - see above");
4147 nsIFrame
* newFrame
= rootFrame
;
4148 nsRefPtr
<nsStyleContext
> rootPseudoStyle
;
4149 // we must create a state because if the scrollbars are GFX it needs the
4150 // state to build the scrollbar frames.
4151 nsFrameConstructorState
state(mPresShell
, nsnull
, nsnull
, nsnull
);
4153 nsIFrame
* parentFrame
= viewportFrame
;
4155 // If paginated, make sure we don't put scrollbars in
4156 if (!isScrollable
) {
4157 rootPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4159 viewportPseudoStyle
);
4161 if (rootPseudo
== nsCSSAnonBoxes::canvas
) {
4162 rootPseudo
= nsCSSAnonBoxes::scrolledCanvas
;
4164 NS_ASSERTION(rootPseudo
== nsCSSAnonBoxes::pageSequence
,
4165 "Unknown root pseudo");
4166 rootPseudo
= nsCSSAnonBoxes::scrolledPageSequence
;
4169 // Build the frame. We give it the content we are wrapping which is the document,
4170 // the root frame, the parent view port frame, and we should get back the new
4171 // frame and the scrollable view if one was created.
4173 // resolve a context for the scrollframe
4174 nsRefPtr
<nsStyleContext
> styleContext
;
4175 styleContext
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4176 nsCSSAnonBoxes::viewportScroll
,
4177 viewportPseudoStyle
);
4179 // Note that the viewport scrollframe is always built with
4180 // overflow:auto style. This forces the scroll frame to create
4181 // anonymous content for both scrollbars. This is necessary even
4182 // if the HTML or BODY elements are overriding the viewport
4183 // scroll style to 'hidden' --- dynamic style changes might put
4184 // scrollbars back on the viewport and we don't want to have to
4185 // reframe the viewport to create the scrollbar content.
4187 rootPseudoStyle
= BeginBuildingScrollFrame( state
,
4195 nsIScrollableFrame
* scrollable
= do_QueryFrame(newFrame
);
4196 NS_ENSURE_TRUE(scrollable
, NS_ERROR_FAILURE
);
4198 nsIScrollableView
* scrollableView
= scrollable
->GetScrollableView();
4199 NS_ENSURE_TRUE(scrollableView
, NS_ERROR_FAILURE
);
4201 viewManager
->SetRootScrollableView(scrollableView
);
4202 parentFrame
= newFrame
;
4204 mGfxScrollFrame
= newFrame
;
4207 rootFrame
->SetStyleContextWithoutNotification(rootPseudoStyle
);
4208 rootFrame
->Init(aDocElement
, parentFrame
, nsnull
);
4211 FinishBuildingScrollFrame(parentFrame
, rootFrame
);
4214 if (isPaginated
) { // paginated
4215 // Create the first page
4216 // Set the initial child lists
4217 nsIFrame
*pageFrame
, *canvasFrame
;
4218 ConstructPageFrame(mPresShell
, presContext
, rootFrame
, nsnull
,
4219 pageFrame
, canvasFrame
);
4220 rootFrame
->SetInitialChildList(nsnull
, pageFrame
);
4222 // The eventual parent of the document element frame.
4223 // XXX should this be set for every new page (in ConstructPageFrame)?
4224 mDocElementContainingBlock
= canvasFrame
;
4225 mHasRootAbsPosContainingBlock
= PR_TRUE
;
4228 viewportFrame
->SetInitialChildList(nsnull
, newFrame
);
4230 *aNewFrame
= viewportFrame
;
4236 nsCSSFrameConstructor::ConstructPageFrame(nsIPresShell
* aPresShell
,
4237 nsPresContext
* aPresContext
,
4238 nsIFrame
* aParentFrame
,
4239 nsIFrame
* aPrevPageFrame
,
4240 nsIFrame
*& aPageFrame
,
4241 nsIFrame
*& aCanvasFrame
)
4243 nsStyleContext
* parentStyleContext
= aParentFrame
->GetStyleContext();
4244 nsStyleSet
*styleSet
= aPresShell
->StyleSet();
4246 nsRefPtr
<nsStyleContext
> pagePseudoStyle
;
4247 pagePseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4248 nsCSSAnonBoxes::page
,
4249 parentStyleContext
);
4251 aPageFrame
= NS_NewPageFrame(aPresShell
, pagePseudoStyle
);
4252 if (NS_UNLIKELY(!aPageFrame
))
4253 return NS_ERROR_OUT_OF_MEMORY
;
4255 // Initialize the page frame and force it to have a view. This makes printing of
4256 // the pages easier and faster.
4257 aPageFrame
->Init(nsnull
, aParentFrame
, aPrevPageFrame
);
4259 nsRefPtr
<nsStyleContext
> pageContentPseudoStyle
;
4260 pageContentPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4261 nsCSSAnonBoxes::pageContent
,
4264 nsIFrame
* pageContentFrame
= NS_NewPageContentFrame(aPresShell
, pageContentPseudoStyle
);
4265 if (NS_UNLIKELY(!pageContentFrame
))
4266 return NS_ERROR_OUT_OF_MEMORY
;
4268 // Initialize the page content frame and force it to have a view. Also make it the
4269 // containing block for fixed elements which are repeated on every page.
4270 nsIFrame
* prevPageContentFrame
= nsnull
;
4271 if (aPrevPageFrame
) {
4272 prevPageContentFrame
= aPrevPageFrame
->GetFirstChild(nsnull
);
4273 NS_ASSERTION(prevPageContentFrame
, "missing page content frame");
4275 pageContentFrame
->Init(nsnull
, aPageFrame
, prevPageContentFrame
);
4276 aPageFrame
->SetInitialChildList(nsnull
, pageContentFrame
);
4277 mFixedContainingBlock
= pageContentFrame
;
4279 nsRefPtr
<nsStyleContext
> canvasPseudoStyle
;
4280 canvasPseudoStyle
= styleSet
->ResolvePseudoStyleFor(nsnull
,
4281 nsCSSAnonBoxes::canvas
,
4282 pageContentPseudoStyle
);
4284 aCanvasFrame
= NS_NewCanvasFrame(aPresShell
, canvasPseudoStyle
);
4285 if (NS_UNLIKELY(!aCanvasFrame
))
4286 return NS_ERROR_OUT_OF_MEMORY
;
4288 nsIFrame
* prevCanvasFrame
= nsnull
;
4289 if (prevPageContentFrame
) {
4290 prevCanvasFrame
= prevPageContentFrame
->GetFirstChild(nsnull
);
4291 NS_ASSERTION(prevCanvasFrame
, "missing canvas frame");
4293 aCanvasFrame
->Init(nsnull
, pageContentFrame
, prevCanvasFrame
);
4294 pageContentFrame
->SetInitialChildList(nsnull
, aCanvasFrame
);
4301 nsCSSFrameConstructor::CreatePlaceholderFrameFor(nsIPresShell
* aPresShell
,
4302 nsIContent
* aContent
,
4304 nsStyleContext
* aStyleContext
,
4305 nsIFrame
* aParentFrame
,
4306 nsIFrame
* aPrevInFlow
,
4307 nsIFrame
** aPlaceholderFrame
)
4309 nsRefPtr
<nsStyleContext
> placeholderStyle
= aPresShell
->StyleSet()->
4310 ResolveStyleForNonElement(aStyleContext
->GetParent());
4312 // The placeholder frame gets a pseudo style context
4313 nsPlaceholderFrame
* placeholderFrame
=
4314 (nsPlaceholderFrame
*)NS_NewPlaceholderFrame(aPresShell
, placeholderStyle
);
4316 if (placeholderFrame
) {
4317 placeholderFrame
->Init(aContent
, aParentFrame
, aPrevInFlow
);
4319 // The placeholder frame has a pointer back to the out-of-flow frame
4320 placeholderFrame
->SetOutOfFlowFrame(aFrame
);
4322 aFrame
->AddStateBits(NS_FRAME_OUT_OF_FLOW
);
4324 // Add mapping from absolutely positioned frame to its placeholder frame
4325 aPresShell
->FrameManager()->RegisterPlaceholderFrame(placeholderFrame
);
4327 *aPlaceholderFrame
= static_cast<nsIFrame
*>(placeholderFrame
);
4332 return NS_ERROR_OUT_OF_MEMORY
;
4337 nsCSSFrameConstructor::ConstructButtonFrame(nsFrameConstructorState
& aState
,
4338 nsIContent
* aContent
,
4339 nsIFrame
* aParentFrame
,
4341 PRInt32 aNameSpaceID
,
4342 nsStyleContext
* aStyleContext
,
4343 const nsStyleDisplay
* aStyleDisplay
,
4344 nsFrameItems
& aFrameItems
,
4345 nsIFrame
** aNewFrame
)
4347 *aNewFrame
= nsnull
;
4348 nsIFrame
* buttonFrame
= nsnull
;
4350 if (nsGkAtoms::button
== aTag
) {
4351 buttonFrame
= NS_NewHTMLButtonControlFrame(mPresShell
, aStyleContext
);
4354 buttonFrame
= NS_NewGfxButtonControlFrame(mPresShell
, aStyleContext
);
4356 if (NS_UNLIKELY(!buttonFrame
)) {
4357 return NS_ERROR_OUT_OF_MEMORY
;
4359 // Initialize the button frame
4360 nsresult rv
= InitAndRestoreFrame(aState
, aContent
,
4361 aState
.GetGeometricParent(aStyleDisplay
, aParentFrame
),
4362 nsnull
, buttonFrame
);
4363 if (NS_FAILED(rv
)) {
4364 buttonFrame
->Destroy();
4367 // See if we need to create a view
4368 nsHTMLContainerFrame::CreateViewForFrame(buttonFrame
, PR_FALSE
);
4372 nsRefPtr
<nsStyleContext
> styleContext
;
4373 styleContext
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4374 nsCSSAnonBoxes::buttonContent
,
4377 nsIFrame
* blockFrame
= NS_NewBlockFrame(mPresShell
, styleContext
,
4378 NS_BLOCK_FLOAT_MGR
);
4380 if (NS_UNLIKELY(!blockFrame
)) {
4381 buttonFrame
->Destroy();
4382 return NS_ERROR_OUT_OF_MEMORY
;
4384 rv
= InitAndRestoreFrame(aState
, aContent
, buttonFrame
, nsnull
, blockFrame
);
4385 if (NS_FAILED(rv
)) {
4386 blockFrame
->Destroy();
4387 buttonFrame
->Destroy();
4391 rv
= aState
.AddChild(buttonFrame
, aFrameItems
, aContent
, aStyleContext
,
4393 if (NS_FAILED(rv
)) {
4394 blockFrame
->Destroy();
4395 buttonFrame
->Destroy();
4399 PRBool isLeaf
= buttonFrame
->IsLeaf();
4401 // Make sure that we're an anonymous content creator exactly when we're a
4403 nsIAnonymousContentCreator
* creator
= do_QueryFrame(buttonFrame
);
4404 NS_ASSERTION(!creator
== !isLeaf
,
4405 "Should be creator exactly when we're a leaf");
4410 nsFrameConstructorSaveState absoluteSaveState
;
4411 nsFrameItems childItems
;
4413 if (aStyleDisplay
->IsPositioned()) {
4414 // The area frame becomes a container for child frames that are
4415 // absolutely positioned
4416 aState
.PushAbsoluteContainingBlock(blockFrame
, absoluteSaveState
);
4420 // Make sure that anonymous child creation will have no effect in this case
4421 nsIAnonymousContentCreator
* creator
= do_QueryFrame(blockFrame
);
4422 NS_ASSERTION(!creator
, "Shouldn't be an anonymous content creator!");
4425 rv
= ProcessChildren(aState
, aContent
, aStyleContext
, blockFrame
, PR_TRUE
,
4427 buttonFrame
->GetStyleDisplay()->IsBlockOutside());
4428 if (NS_FAILED(rv
)) return rv
;
4430 // Set the areas frame's initial child lists
4431 blockFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4434 buttonFrame
->SetInitialChildList(nsnull
, blockFrame
);
4437 nsFrameItems anonymousChildItems
;
4438 // if there are any anonymous children create frames for them. Note that
4439 // we're doing this using a different parent frame from the one we pass to
4441 CreateAnonymousFrames(aState
, aContent
, buttonFrame
, anonymousChildItems
);
4442 if (anonymousChildItems
.childList
) {
4443 // the anonymous content is already parented to the area frame
4444 aState
.mFrameManager
->AppendFrames(blockFrame
, nsnull
,
4445 anonymousChildItems
.childList
);
4449 // our new button frame returned is the top frame.
4450 *aNewFrame
= buttonFrame
;
4456 nsCSSFrameConstructor::ConstructSelectFrame(nsFrameConstructorState
& aState
,
4457 nsIContent
* aContent
,
4458 nsIFrame
* aParentFrame
,
4460 PRInt32 aNameSpaceID
,
4461 nsStyleContext
* aStyleContext
,
4462 const nsStyleDisplay
* aStyleDisplay
,
4463 nsFrameItems
& aFrameItems
,
4464 nsIFrame
** aNewFrame
)
4466 nsresult rv
= NS_OK
;
4467 const PRInt32 kNoSizeSpecified
= -1;
4469 // Construct a frame-based listbox or combobox
4470 nsCOMPtr
<nsIDOMHTMLSelectElement
> sel(do_QueryInterface(aContent
));
4473 sel
->GetSize(&size
);
4474 PRBool multipleSelect
= PR_FALSE
;
4475 sel
->GetMultiple(&multipleSelect
);
4476 // Construct a combobox if size=1 or no size is specified and its multiple select
4477 if (((1 == size
|| 0 == size
) || (kNoSizeSpecified
== size
)) && (PR_FALSE
== multipleSelect
)) {
4478 // Construct a frame-based combo box.
4479 // The frame-based combo box is built out of three parts. A display area, a button and
4480 // a dropdown list. The display area and button are created through anonymous content.
4481 // The drop-down list's frame is created explicitly. The combobox frame shares its content
4482 // with the drop-down list.
4483 PRUint32 flags
= NS_BLOCK_FLOAT_MGR
;
4484 nsIFrame
* comboboxFrame
= NS_NewComboboxControlFrame(mPresShell
, aStyleContext
, flags
);
4486 // Save the history state so we don't restore during construction
4487 // since the complete tree is required before we restore.
4488 nsILayoutHistoryState
*historyState
= aState
.mFrameState
;
4489 aState
.mFrameState
= nsnull
;
4490 // Initialize the combobox frame
4491 InitAndRestoreFrame(aState
, aContent
,
4492 aState
.GetGeometricParent(aStyleDisplay
, aParentFrame
),
4493 nsnull
, comboboxFrame
);
4495 nsHTMLContainerFrame::CreateViewForFrame(comboboxFrame
, PR_FALSE
);
4497 rv
= aState
.AddChild(comboboxFrame
, aFrameItems
, aContent
, aStyleContext
,
4499 if (NS_FAILED(rv
)) {
4503 ///////////////////////////////////////////////////////////////////
4504 // Combobox - Old Native Implementation
4505 ///////////////////////////////////////////////////////////////////
4506 nsIComboboxControlFrame
* comboBox
= do_QueryFrame(comboboxFrame
);
4507 NS_ASSERTION(comboBox
, "NS_NewComboboxControlFrame returned frame that "
4508 "doesn't implement nsIComboboxControlFrame");
4510 // Resolve pseudo element style for the dropdown list
4511 nsRefPtr
<nsStyleContext
> listStyle
;
4512 listStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4513 nsCSSAnonBoxes::dropDownList
,
4517 nsIFrame
* listFrame
= NS_NewListControlFrame(mPresShell
, listStyle
);
4519 // Notify the listbox that it is being used as a dropdown list.
4520 nsIListControlFrame
* listControlFrame
= do_QueryFrame(listFrame
);
4521 if (listControlFrame
) {
4522 listControlFrame
->SetComboboxFrame(comboboxFrame
);
4524 // Notify combobox that it should use the listbox as it's popup
4525 comboBox
->SetDropDown(listFrame
);
4527 NS_ASSERTION(!listStyle
->GetStyleDisplay()->IsPositioned(),
4528 "Ended up with positioned dropdown list somehow.");
4529 NS_ASSERTION(!listStyle
->GetStyleDisplay()->IsFloating(),
4530 "Ended up with floating dropdown list somehow.");
4532 // Initialize the scroll frame positioned. Note that it is NOT
4533 // initialized as absolutely positioned.
4534 nsIFrame
* scrolledFrame
= NS_NewSelectsAreaFrame(mPresShell
, aStyleContext
, flags
);
4536 InitializeSelectFrame(aState
, listFrame
, scrolledFrame
, aContent
,
4537 comboboxFrame
, listStyle
, PR_TRUE
, aFrameItems
);
4539 // Set flag so the events go to the listFrame not child frames.
4540 // XXX: We should replace this with a real widget manager similar
4541 // to how the nsFormControlFrame works. Re-directing events is a temporary Kludge.
4542 NS_ASSERTION(listFrame
->GetView(), "ListFrame's view is nsnull");
4543 //listFrame->GetView()->SetViewFlags(NS_VIEW_PUBLIC_FLAG_DONT_CHECK_CHILDREN);
4545 // Create display and button frames from the combobox's anonymous content.
4546 // The anonymous content is appended to existing anonymous content for this
4547 // element (the scrollbars).
4549 nsFrameItems childItems
;
4550 CreateAnonymousFrames(aState
, aContent
, comboboxFrame
, childItems
);
4552 comboboxFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4554 // Initialize the additional popup child list which contains the
4555 // dropdown list frame.
4556 nsFrameItems popupItems
;
4557 popupItems
.AddChild(listFrame
);
4558 comboboxFrame
->SetInitialChildList(nsGkAtoms::selectPopupList
,
4559 popupItems
.childList
);
4561 *aNewFrame
= comboboxFrame
;
4562 aState
.mFrameState
= historyState
;
4563 if (aState
.mFrameState
&& aState
.mFrameManager
) {
4564 // Restore frame state for the entire subtree of |comboboxFrame|.
4565 aState
.mFrameManager
->RestoreFrameState(comboboxFrame
,
4566 aState
.mFrameState
);
4569 ///////////////////////////////////////////////////////////////////
4570 // ListBox - Old Native Implementation
4571 ///////////////////////////////////////////////////////////////////
4572 nsIFrame
* listFrame
= NS_NewListControlFrame(mPresShell
, aStyleContext
);
4577 rv
= NS_ERROR_OUT_OF_MEMORY
;
4580 nsIFrame
* scrolledFrame
= NS_NewSelectsAreaFrame(
4581 mPresShell
, aStyleContext
, NS_BLOCK_FLOAT_MGR
);
4583 // ******* this code stolen from Initialze ScrollFrame ********
4584 // please adjust this code to use BuildScrollFrame.
4586 InitializeSelectFrame(aState
, listFrame
, scrolledFrame
, aContent
,
4587 aParentFrame
, aStyleContext
, PR_FALSE
, aFrameItems
);
4589 *aNewFrame
= listFrame
;
4597 * Used to be InitializeScrollFrame but now it's only used for the select tag
4598 * But the select tag should really be fixed to use GFX scrollbars that can
4599 * be create with BuildScrollFrame.
4602 nsCSSFrameConstructor::InitializeSelectFrame(nsFrameConstructorState
& aState
,
4603 nsIFrame
* scrollFrame
,
4604 nsIFrame
* scrolledFrame
,
4605 nsIContent
* aContent
,
4606 nsIFrame
* aParentFrame
,
4607 nsStyleContext
* aStyleContext
,
4608 PRBool aBuildCombobox
,
4609 nsFrameItems
& aFrameItems
)
4611 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
4614 nsIFrame
* geometricParent
= aState
.GetGeometricParent(display
, aParentFrame
);
4616 // We don't call InitAndRestoreFrame for scrollFrame because we can only
4617 // restore the frame state after its parts have been created (in particular,
4618 // the scrollable view). So we have to split Init and Restore.
4620 // Initialize the frame
4621 scrollFrame
->Init(aContent
, geometricParent
, nsnull
);
4623 if (!aBuildCombobox
) {
4624 nsresult rv
= aState
.AddChild(scrollFrame
, aFrameItems
, aContent
,
4625 aStyleContext
, aParentFrame
);
4626 if (NS_FAILED(rv
)) {
4631 nsHTMLContainerFrame::CreateViewForFrame(scrollFrame
, aBuildCombobox
);
4632 if (aBuildCombobox
) {
4633 // Give the drop-down list a popup widget
4634 nsIView
* view
= scrollFrame
->GetView();
4635 NS_ASSERTION(view
, "We asked for a view but didn't get one");
4637 view
->GetViewManager()->SetViewFloating(view
, PR_TRUE
);
4639 nsWidgetInitData widgetData
;
4640 widgetData
.mWindowType
= eWindowType_popup
;
4641 widgetData
.mBorderStyle
= eBorderStyle_default
;
4643 #if defined(XP_MACOSX) || defined(XP_BEOS)
4644 static NS_DEFINE_IID(kCPopUpCID
, NS_POPUP_CID
);
4645 view
->CreateWidget(kCPopUpCID
, &widgetData
, nsnull
);
4647 static NS_DEFINE_IID(kCChildCID
, NS_CHILD_CID
);
4648 view
->CreateWidget(kCChildCID
, &widgetData
, nsnull
);
4653 BuildScrollFrame(aState
, aContent
, aStyleContext
, scrolledFrame
,
4654 geometricParent
, scrollFrame
);
4656 if (aState
.mFrameState
&& aState
.mFrameManager
) {
4657 // Restore frame state for the scroll frame
4658 aState
.mFrameManager
->RestoreFrameStateFor(scrollFrame
, aState
.mFrameState
);
4662 nsFrameConstructorSaveState absoluteSaveState
;
4663 nsFrameItems childItems
;
4665 if (display
->IsPositioned()) {
4666 // The area frame becomes a container for child frames that are
4667 // absolutely positioned
4668 aState
.PushAbsoluteContainingBlock(scrolledFrame
, absoluteSaveState
);
4671 ProcessChildren(aState
, aContent
, aStyleContext
, scrolledFrame
, PR_FALSE
,
4672 childItems
, PR_TRUE
);
4674 // Set the scrolled frame's initial child lists
4675 scrolledFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4680 nsCSSFrameConstructor::ConstructFieldSetFrame(nsFrameConstructorState
& aState
,
4681 nsIContent
* aContent
,
4682 nsIFrame
* aParentFrame
,
4684 PRInt32 aNameSpaceID
,
4685 nsStyleContext
* aStyleContext
,
4686 const nsStyleDisplay
* aStyleDisplay
,
4687 nsFrameItems
& aFrameItems
,
4688 nsIFrame
** aNewFrame
)
4690 nsIFrame
* newFrame
= NS_NewFieldSetFrame(mPresShell
, aStyleContext
);
4691 if (NS_UNLIKELY(!newFrame
)) {
4692 return NS_ERROR_OUT_OF_MEMORY
;
4696 InitAndRestoreFrame(aState
, aContent
,
4697 aState
.GetGeometricParent(aStyleDisplay
, aParentFrame
),
4700 // See if we need to create a view, e.g. the frame is absolutely
4702 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
4704 // Resolve style and initialize the frame
4705 nsRefPtr
<nsStyleContext
> styleContext
;
4706 styleContext
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(aContent
,
4707 nsCSSAnonBoxes::fieldsetContent
,
4710 nsIFrame
* blockFrame
= NS_NewBlockFrame(mPresShell
, styleContext
,
4711 NS_BLOCK_FLOAT_MGR
|
4712 NS_BLOCK_MARGIN_ROOT
);
4713 InitAndRestoreFrame(aState
, aContent
, newFrame
, nsnull
, blockFrame
);
4715 nsresult rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
4717 if (NS_FAILED(rv
)) {
4722 nsFrameConstructorSaveState absoluteSaveState
;
4723 nsFrameItems childItems
;
4725 if (aStyleDisplay
->IsPositioned()) {
4726 // The area frame becomes a container for child frames that are
4727 // absolutely positioned
4728 // XXXbz this is probably wrong, and once arbitrary frames can be absolute
4729 // containing blocks we should fix this..
4730 aState
.PushAbsoluteContainingBlock(blockFrame
, absoluteSaveState
);
4733 ProcessChildren(aState
, aContent
, aStyleContext
, blockFrame
, PR_TRUE
,
4734 childItems
, PR_TRUE
);
4736 nsIFrame
* child
= childItems
.childList
;
4737 nsIFrame
* previous
= nsnull
;
4738 nsLegendFrame
* legendFrame
= nsnull
;
4739 while (nsnull
!= child
) {
4740 legendFrame
= do_QueryFrame(child
);
4742 // We want the legend to be the first frame in the fieldset child list.
4743 // That way the EventStateManager will do the right thing when tabbing
4744 // from a selection point within the legend (bug 236071), which is
4745 // used for implementing legend access keys (bug 81481).
4746 // GetAdjustedParentFrame() below depends on this frame order.
4747 if (nsnull
!= previous
) {
4748 previous
->SetNextSibling(legendFrame
->GetNextSibling());
4750 childItems
.childList
= legendFrame
->GetNextSibling();
4752 legendFrame
->SetNextSibling(blockFrame
);
4753 legendFrame
->SetParent(newFrame
);
4757 child
= child
->GetNextSibling();
4760 // Set the scrolled frame's initial child lists
4761 blockFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
4763 // Set the scroll frame's initial child list
4764 newFrame
->SetInitialChildList(nsnull
, legendFrame
? legendFrame
: blockFrame
);
4766 // our new frame returned is the top frame which is the list frame.
4767 *aNewFrame
= newFrame
;
4773 FindAncestorWithGeneratedContentPseudo(nsIFrame
* aFrame
)
4775 for (nsIFrame
* f
= aFrame
->GetParent(); f
; f
= f
->GetParent()) {
4776 NS_ASSERTION(f
->IsGeneratedContentFrame(),
4777 "should not have exited generated content");
4778 nsIAtom
* pseudo
= f
->GetStyleContext()->GetPseudoType();
4779 if (pseudo
== nsCSSPseudoElements::before
||
4780 pseudo
== nsCSSPseudoElements::after
)
4786 #define FCDATA_DECL(_flags, _func) \
4787 { _flags, { (FrameCreationFunc)_func } }
4788 #define SIMPLE_FCDATA(_func) FCDATA_DECL(0, _func)
4789 #define FULL_CTOR_FCDATA(_flags, _func) \
4790 { _flags | FCDATA_FUNC_IS_FULL_CTOR, { nsnull }, _func }
4793 const nsCSSFrameConstructor::FrameConstructionData
*
4794 nsCSSFrameConstructor::FindTextData(nsIFrame
* aParentFrame
)
4797 if (aParentFrame
->IsFrameOfType(nsIFrame::eSVG
)) {
4798 nsIFrame
*ancestorFrame
=
4799 nsSVGUtils::GetFirstNonAAncestorFrame(aParentFrame
);
4800 if (ancestorFrame
) {
4801 nsISVGTextContentMetrics
* metrics
= do_QueryFrame(ancestorFrame
);
4803 static const FrameConstructionData sSVGGlyphData
=
4804 SIMPLE_FCDATA(NS_NewSVGGlyphFrame
);
4805 return &sSVGGlyphData
;
4812 static const FrameConstructionData sTextData
= SIMPLE_FCDATA(NS_NewTextFrame
);
4817 nsCSSFrameConstructor::ConstructTextFrame(const FrameConstructionData
* aData
,
4818 nsFrameConstructorState
& aState
,
4819 nsIContent
* aContent
,
4820 nsIFrame
* aParentFrame
,
4821 nsStyleContext
* aStyleContext
,
4822 nsFrameItems
& aFrameItems
,
4823 PRBool aPseudoParent
)
4825 NS_PRECONDITION(aData
, "Must have frame construction data");
4827 // process pending pseudo frames. whitespace doesn't have an effect.
4828 if (!aPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty() &&
4829 !TextIsOnlyWhitespace(aContent
))
4830 ProcessPseudoFrames(aState
, aFrameItems
);
4832 nsIFrame
* newFrame
= (*aData
->mFunc
.mCreationFunc
)(mPresShell
, aStyleContext
);
4834 if (NS_UNLIKELY(!newFrame
))
4835 return NS_ERROR_OUT_OF_MEMORY
;
4837 nsresult rv
= InitAndRestoreFrame(aState
, aContent
, aParentFrame
,
4840 if (NS_FAILED(rv
)) {
4841 newFrame
->Destroy();
4845 // We never need to create a view for a text frame.
4847 if (newFrame
->IsGeneratedContentFrame()) {
4848 nsAutoPtr
<nsGenConInitializer
> initializer
;
4850 static_cast<nsGenConInitializer
*>(
4851 aContent
->UnsetProperty(nsGkAtoms::genConInitializerProperty
));
4853 if (initializer
->mNode
->InitTextFrame(initializer
->mList
,
4854 FindAncestorWithGeneratedContentPseudo(newFrame
), newFrame
)) {
4855 (this->*(initializer
->mDirtyAll
))();
4857 initializer
->mNode
.forget();
4861 // Add the newly constructed frame to the flow
4862 aFrameItems
.AddChild(newFrame
);
4864 // Text frames don't go in the content->frame hash table, because
4865 // they're anonymous. This keeps the hash table smaller
4871 const nsCSSFrameConstructor::FrameConstructionData
*
4872 nsCSSFrameConstructor::FindDataByInt(PRInt32 aInt
,
4873 nsIContent
* aContent
,
4874 nsStyleContext
* aStyleContext
,
4875 const FrameConstructionDataByInt
* aDataPtr
,
4876 PRUint32 aDataLength
)
4878 for (const FrameConstructionDataByInt
*curData
= aDataPtr
,
4879 *endData
= aDataPtr
+ aDataLength
;
4882 if (curData
->mInt
== aInt
) {
4883 const FrameConstructionData
* data
= &curData
->mData
;
4884 if (data
->mBits
& FCDATA_FUNC_IS_DATA_GETTER
) {
4885 return data
->mFunc
.mDataGetter(aContent
, aStyleContext
);
4896 const nsCSSFrameConstructor::FrameConstructionData
*
4897 nsCSSFrameConstructor::FindDataByTag(nsIAtom
* aTag
,
4898 nsIContent
* aContent
,
4899 nsStyleContext
* aStyleContext
,
4900 const FrameConstructionDataByTag
* aDataPtr
,
4901 PRUint32 aDataLength
)
4903 for (const FrameConstructionDataByTag
*curData
= aDataPtr
,
4904 *endData
= aDataPtr
+ aDataLength
;
4907 if (*curData
->mTag
== aTag
) {
4908 const FrameConstructionData
* data
= &curData
->mData
;
4909 if (data
->mBits
& FCDATA_FUNC_IS_DATA_GETTER
) {
4910 return data
->mFunc
.mDataGetter(aContent
, aStyleContext
);
4920 #define SUPPRESS_FCDATA() FCDATA_DECL(FCDATA_SUPPRESS_FRAME, nsnull)
4921 #define SIMPLE_INT_CREATE(_int, _func) { _int, SIMPLE_FCDATA(_func) }
4922 #define SIMPLE_INT_CHAIN(_int, _func) \
4923 { _int, FCDATA_DECL(FCDATA_FUNC_IS_DATA_GETTER, _func) }
4924 #define COMPLEX_INT_CREATE(_int, _func) \
4925 { _int, FULL_CTOR_FCDATA(0, _func) }
4927 #define SIMPLE_TAG_CREATE(_tag, _func) \
4928 { &nsGkAtoms::_tag, SIMPLE_FCDATA(_func) }
4929 #define SIMPLE_TAG_CHAIN(_tag, _func) \
4930 { &nsGkAtoms::_tag, FCDATA_DECL(FCDATA_FUNC_IS_DATA_GETTER, _func) }
4931 #define COMPLEX_TAG_CREATE(_tag, _func) \
4932 { &nsGkAtoms::_tag, FULL_CTOR_FCDATA(0, _func) }
4935 const nsCSSFrameConstructor::FrameConstructionData
*
4936 nsCSSFrameConstructor::FindHTMLData(nsIContent
* aContent
,
4938 PRInt32 aNameSpaceID
,
4939 nsIFrame
* aParentFrame
,
4940 nsStyleContext
* aStyleContext
)
4942 // Ignore the tag if it's not HTML content and if it doesn't extend (via XBL)
4943 // a valid HTML namespace. This check must match the one in
4944 // ShouldHaveFirstLineStyle.
4945 if (!aContent
->IsNodeOfType(nsINode::eHTML
) &&
4946 aNameSpaceID
!= kNameSpaceID_XHTML
) {
4950 NS_ASSERTION(!aParentFrame
||
4951 aParentFrame
->GetStyleContext()->GetPseudoType() !=
4952 nsCSSAnonBoxes::fieldsetContent
||
4953 aParentFrame
->GetParent()->GetType() == nsGkAtoms::fieldSetFrame
,
4954 "Unexpected parent for fieldset content anon box");
4955 if (aTag
== nsGkAtoms::legend
&&
4957 (aParentFrame
->GetType() != nsGkAtoms::fieldSetFrame
&&
4958 aParentFrame
->GetStyleContext()->GetPseudoType() !=
4959 nsCSSAnonBoxes::fieldsetContent
))) {
4960 // <legend> is only special inside fieldset frames
4961 // XXXbz it would be nice if we could just decide this based on the parent
4962 // tag, and hence just use a SIMPLE_TAG_CHAIN for legend below, but the
4963 // fact that with XBL we could end up with this legend element in some
4964 // totally weird insertion point makes that chancy, I think.
4968 static const FrameConstructionDataByTag sHTMLData
[] = {
4969 SIMPLE_TAG_CHAIN(img
, nsCSSFrameConstructor::FindImgData
),
4970 SIMPLE_TAG_CHAIN(mozgeneratedcontentimage
,
4971 nsCSSFrameConstructor::FindImgData
),
4972 { &nsGkAtoms::br
, FCDATA_DECL(FCDATA_SKIP_FRAMEMAP
, NS_NewBRFrame
) },
4973 SIMPLE_TAG_CREATE(wbr
, NS_NewWBRFrame
),
4974 SIMPLE_TAG_CHAIN(input
, nsCSSFrameConstructor::FindInputData
),
4975 SIMPLE_TAG_CREATE(textarea
, NS_NewTextControlFrame
),
4976 COMPLEX_TAG_CREATE(select
, &nsCSSFrameConstructor::ConstructSelectFrame
),
4977 SIMPLE_TAG_CHAIN(object
, nsCSSFrameConstructor::FindObjectData
),
4978 SIMPLE_TAG_CHAIN(applet
, nsCSSFrameConstructor::FindObjectData
),
4979 SIMPLE_TAG_CHAIN(embed
, nsCSSFrameConstructor::FindObjectData
),
4980 COMPLEX_TAG_CREATE(fieldset
,
4981 &nsCSSFrameConstructor::ConstructFieldSetFrame
),
4982 SIMPLE_TAG_CREATE(legend
, NS_NewLegendFrame
),
4983 SIMPLE_TAG_CREATE(frameset
, NS_NewHTMLFramesetFrame
),
4984 SIMPLE_TAG_CREATE(iframe
, NS_NewSubDocumentFrame
),
4985 SIMPLE_TAG_CREATE(spacer
, NS_NewSpacerFrame
),
4986 COMPLEX_TAG_CREATE(button
, &nsCSSFrameConstructor::ConstructButtonFrame
),
4987 SIMPLE_TAG_CREATE(canvas
, NS_NewHTMLCanvasFrame
),
4988 #if defined(MOZ_MEDIA)
4989 SIMPLE_TAG_CREATE(video
, NS_NewHTMLVideoFrame
),
4990 SIMPLE_TAG_CREATE(audio
, NS_NewHTMLVideoFrame
),
4992 SIMPLE_TAG_CREATE(isindex
, NS_NewIsIndexFrame
)
4995 return FindDataByTag(aTag
, aContent
, aStyleContext
, sHTMLData
,
4996 NS_ARRAY_LENGTH(sHTMLData
));
5000 const nsCSSFrameConstructor::FrameConstructionData
*
5001 nsCSSFrameConstructor::FindImgData(nsIContent
* aContent
,
5002 nsStyleContext
* aStyleContext
)
5004 if (!nsImageFrame::ShouldCreateImageFrameFor(aContent
, aStyleContext
)) {
5008 static const FrameConstructionData sImgData
= SIMPLE_FCDATA(NS_NewImageFrame
);
5013 const nsCSSFrameConstructor::FrameConstructionData
*
5014 nsCSSFrameConstructor::FindImgControlData(nsIContent
* aContent
,
5015 nsStyleContext
* aStyleContext
)
5017 if (!nsImageFrame::ShouldCreateImageFrameFor(aContent
, aStyleContext
)) {
5021 static const FrameConstructionData sImgControlData
=
5022 SIMPLE_FCDATA(NS_NewImageControlFrame
);
5023 return &sImgControlData
;
5027 const nsCSSFrameConstructor::FrameConstructionData
*
5028 nsCSSFrameConstructor::FindInputData(nsIContent
* aContent
,
5029 nsStyleContext
* aStyleContext
)
5031 static const FrameConstructionDataByInt sInputData
[] = {
5032 SIMPLE_INT_CREATE(NS_FORM_INPUT_CHECKBOX
, NS_NewGfxCheckboxControlFrame
),
5033 SIMPLE_INT_CREATE(NS_FORM_INPUT_RADIO
, NS_NewGfxRadioControlFrame
),
5034 SIMPLE_INT_CREATE(NS_FORM_INPUT_FILE
, NS_NewFileControlFrame
),
5035 SIMPLE_INT_CHAIN(NS_FORM_INPUT_IMAGE
,
5036 nsCSSFrameConstructor::FindImgControlData
),
5037 SIMPLE_INT_CREATE(NS_FORM_INPUT_TEXT
, NS_NewTextControlFrame
),
5038 SIMPLE_INT_CREATE(NS_FORM_INPUT_PASSWORD
, NS_NewTextControlFrame
),
5039 COMPLEX_INT_CREATE(NS_FORM_INPUT_SUBMIT
,
5040 &nsCSSFrameConstructor::ConstructButtonFrame
),
5041 COMPLEX_INT_CREATE(NS_FORM_INPUT_RESET
,
5042 &nsCSSFrameConstructor::ConstructButtonFrame
),
5043 COMPLEX_INT_CREATE(NS_FORM_INPUT_BUTTON
,
5044 &nsCSSFrameConstructor::ConstructButtonFrame
)
5045 // Keeping hidden inputs out of here on purpose for so they get frames by
5046 // display (in practice, none).
5049 nsCOMPtr
<nsIFormControl
> control
= do_QueryInterface(aContent
);
5050 NS_ASSERTION(control
, "input doesn't implement nsIFormControl?");
5052 return FindDataByInt(control
->GetType(), aContent
, aStyleContext
,
5053 sInputData
, NS_ARRAY_LENGTH(sInputData
));
5057 const nsCSSFrameConstructor::FrameConstructionData
*
5058 nsCSSFrameConstructor::FindObjectData(nsIContent
* aContent
,
5059 nsStyleContext
* aStyleContext
)
5061 // GetDisplayedType isn't necessarily nsIObjectLoadingContent::TYPE_NULL for
5062 // cases when the object is broken/suppressed/etc (e.g. a broken image), but
5063 // we want to treat those cases as TYPE_NULL
5065 if (aContent
->IntrinsicState() &
5066 (NS_EVENT_STATE_BROKEN
| NS_EVENT_STATE_USERDISABLED
|
5067 NS_EVENT_STATE_SUPPRESSED
)) {
5068 type
= nsIObjectLoadingContent::TYPE_NULL
;
5070 nsCOMPtr
<nsIObjectLoadingContent
> objContent(do_QueryInterface(aContent
));
5071 NS_ASSERTION(objContent
,
5072 "applet, embed and object must implement "
5073 "nsIObjectLoadingContent!");
5075 objContent
->GetDisplayedType(&type
);
5078 static const FrameConstructionDataByInt sObjectData
[] = {
5079 SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_LOADING
,
5081 SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_PLUGIN
,
5083 SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_IMAGE
,
5085 SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_DOCUMENT
,
5086 NS_NewSubDocumentFrame
)
5087 // Nothing for TYPE_NULL so we'll construct frames by display there
5090 return FindDataByInt((PRInt32
)type
, aContent
, aStyleContext
,
5091 sObjectData
, NS_ARRAY_LENGTH(sObjectData
));
5095 nsCSSFrameConstructor::ConstructFrameFromData(const FrameConstructionData
* aData
,
5096 nsFrameConstructorState
& aState
,
5097 nsIContent
* aContent
,
5098 nsIFrame
* aParentFrame
,
5100 PRInt32 aNameSpaceID
,
5101 nsStyleContext
* aStyleContext
,
5102 nsFrameItems
& aFrameItems
,
5103 PRBool aHasPseudoParent
)
5105 PRUint32 bits
= aData
->mBits
;
5107 NS_ASSERTION(!(bits
& FCDATA_FUNC_IS_DATA_GETTER
),
5108 "Should have dealt with this inside the data finder");
5110 // Some sets of bits are not compatible with each other
5111 #define CHECK_ONLY_ONE_BIT(_bit1, _bit2) \
5112 NS_ASSERTION(!(bits & _bit1) || !(bits & _bit2), \
5113 "Only one of these bits should be set")
5114 CHECK_ONLY_ONE_BIT(FCDATA_SKIP_FRAMEMAP
, FCDATA_MAY_NEED_SCROLLFRAME
);
5115 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_DISALLOW_OUT_OF_FLOW
);
5116 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_FORCE_NULL_ABSPOS_CONTAINER
);
5118 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_WRAP_KIDS_IN_BLOCKS
);
5120 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_MAY_NEED_SCROLLFRAME
);
5121 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_IS_POPUP
);
5122 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_SKIP_ABSPOS_PUSH
);
5123 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
, FCDATA_FORCE_VIEW
);
5124 CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR
,
5125 FCDATA_DISALLOW_GENERATED_CONTENT
);
5126 CHECK_ONLY_ONE_BIT(FCDATA_MAY_NEED_SCROLLFRAME
, FCDATA_FORCE_VIEW
);
5127 #undef CHECK_ONLY_ONE_BIT
5129 // Process pseudo-frames now if this is not a table part.
5130 if (!aHasPseudoParent
&& !aState
.mPseudoFrames
.IsEmpty() &&
5131 !(bits
& FCDATA_IS_TABLE_PART
)) {
5132 ProcessPseudoFrames(aState
, aFrameItems
);
5135 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
5138 if (bits
& FCDATA_FUNC_IS_FULL_CTOR
) {
5140 (this->*(aData
->mFullConstructor
))(aState
, aContent
, aParentFrame
,
5141 aTag
, aNameSpaceID
, aStyleContext
,
5142 display
, aFrameItems
, &newFrame
);
5143 if (NS_FAILED(rv
)) {
5148 (*aData
->mFunc
.mCreationFunc
)(mPresShell
, aStyleContext
);
5150 return NS_ERROR_OUT_OF_MEMORY
;
5153 PRBool allowOutOfFlow
= !(bits
& FCDATA_DISALLOW_OUT_OF_FLOW
);
5155 PRBool isPopup
= (bits
& FCDATA_IS_POPUP
) &&
5156 aParentFrame
->GetType() != nsGkAtoms::menuFrame
;
5158 PRBool isPopup
= PR_FALSE
;
5160 NS_ASSERTION(!isPopup
||
5161 (aState
.mPopupItems
.containingBlock
&&
5162 aState
.mPopupItems
.containingBlock
->GetType() ==
5163 nsGkAtoms::popupSetFrame
),
5164 "Should have a containing block here!");
5166 PRBool isXUL
= (aNameSpaceID
== kNameSpaceID_XUL
);
5168 nsIFrame
* geometricParent
=
5169 isPopup
? aState
.mPopupItems
.containingBlock
:
5170 (allowOutOfFlow
? aState
.GetGeometricParent(display
, aParentFrame
)
5173 nsresult rv
= NS_OK
;
5175 // Must init frameToAddToList to null, since it's inout
5176 nsIFrame
* frameToAddToList
= nsnull
;
5177 if ((bits
& FCDATA_MAY_NEED_SCROLLFRAME
) &&
5178 display
->IsScrollableOverflow()) {
5179 BuildScrollFrame(aState
, aContent
, aStyleContext
, newFrame
,
5180 geometricParent
, frameToAddToList
);
5181 // No need to add to frame map later, since BuildScrollFrame did it
5183 bits
|= FCDATA_SKIP_FRAMEMAP
;
5185 rv
= InitAndRestoreFrame(aState
, aContent
, geometricParent
, nsnull
,
5187 NS_ASSERTION(NS_SUCCEEDED(rv
), "InitAndRestoreFrame failed");
5188 // See whether we need to create a view
5189 nsHTMLContainerFrame::CreateViewForFrame(newFrame
,
5190 (bits
& FCDATA_FORCE_VIEW
) != 0);
5191 frameToAddToList
= newFrame
;
5194 rv
= aState
.AddChild(frameToAddToList
, aFrameItems
, aContent
, aStyleContext
,
5195 aParentFrame
, allowOutOfFlow
, allowOutOfFlow
, isPopup
);
5196 if (NS_FAILED(rv
)) {
5201 // Icky XUL stuff, sadly
5202 if (isXUL
&& aTag
== nsGkAtoms::popupgroup
&&
5203 aContent
->IsRootOfNativeAnonymousSubtree()) {
5204 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(mPresShell
);
5206 NS_ASSERTION(rootBox
->GetPopupSetFrame() == newFrame
,
5207 "Unexpected PopupSetFrame");
5208 aState
.mPopupItems
.containingBlock
= rootBox
->GetPopupSetFrame();
5211 #endif /* MOZ_XUL */
5213 // Process the child content if requested
5214 nsFrameItems childItems
;
5215 nsFrameConstructorSaveState absoluteSaveState
;
5217 if (bits
& FCDATA_FORCE_NULL_ABSPOS_CONTAINER
) {
5218 aState
.PushAbsoluteContainingBlock(nsnull
, absoluteSaveState
);
5219 } else if (!(bits
& FCDATA_SKIP_ABSPOS_PUSH
) && display
->IsPositioned()) {
5220 aState
.PushAbsoluteContainingBlock(newFrame
, absoluteSaveState
);
5223 // Process the child frames. Don't allow block styles; anything that's a
5224 // special HTML or MathML or XUL frame but wants those should do its own
5226 rv
= ProcessChildren(aState
, aContent
, aStyleContext
, newFrame
,
5227 !(bits
& FCDATA_DISALLOW_GENERATED_CONTENT
),
5228 childItems
, PR_FALSE
);
5231 // More icky XUL stuff
5233 (aTag
== nsGkAtoms::treechildren
|| // trees always need titletips
5234 aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::tooltiptext
) ||
5235 aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::tooltip
))) {
5236 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(mPresShell
);
5238 rootBox
->AddTooltipSupport(aContent
);
5244 if (NS_SUCCEEDED(rv
) && (bits
& FCDATA_WRAP_KIDS_IN_BLOCKS
)) {
5245 nsFrameItems newItems
;
5246 nsFrameItems currentBlock
;
5248 while ((f
= childItems
.childList
) != nsnull
) {
5249 PRBool wrapFrame
= IsInlineFrame(f
) || IsFrameSpecial(f
);
5251 rv
= FlushAccumulatedBlock(aState
, aContent
, newFrame
, ¤tBlock
, &newItems
);
5256 childItems
.RemoveChild(f
, nsnull
);
5258 currentBlock
.AddChild(f
);
5260 newItems
.AddChild(f
);
5263 rv
= FlushAccumulatedBlock(aState
, aContent
, newFrame
, ¤tBlock
, &newItems
);
5265 if (childItems
.childList
) {
5266 // an error must have occurred, delete unprocessed frames
5267 CleanupFrameReferences(aState
.mFrameManager
, childItems
.childList
);
5268 nsFrameList(childItems
.childList
).DestroyFrames();
5271 childItems
= newItems
;
5275 // Set the frame's initial child list
5276 // Note that MathML depends on this being called even if
5277 // childItems.childList is null!
5278 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
5281 if (!(bits
& FCDATA_SKIP_FRAMEMAP
)) {
5282 aState
.mFrameManager
->SetPrimaryFrameFor(aContent
, newFrame
);
5288 // after the node has been constructed and initialized create any
5289 // anonymous content a node needs.
5291 nsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState
& aState
,
5292 nsIContent
* aParent
,
5293 nsIFrame
* aParentFrame
,
5294 nsFrameItems
& aChildItems
)
5296 nsIAnonymousContentCreator
* creator
= do_QueryFrame(aParentFrame
);
5302 nsAutoTArray
<nsIContent
*, 4> newAnonymousItems
;
5303 rv
= creator
->CreateAnonymousContent(newAnonymousItems
);
5304 NS_ENSURE_SUCCESS(rv
, rv
);
5306 PRUint32 count
= newAnonymousItems
.Length();
5311 // save the incoming pseudo frame state, so that we don't end up
5312 // with those pseudoframes in aChildItems
5313 nsPseudoFrames priorPseudoFrames
;
5314 aState
.mPseudoFrames
.Reset(&priorPseudoFrames
);
5316 for (PRUint32 i
=0; i
< count
; i
++) {
5317 // get our child's content and set its parent to our content
5318 nsIContent
* content
= newAnonymousItems
[i
];
5319 NS_ASSERTION(content
, "null anonymous content?");
5322 // least-surprise CSS binding until we do the SVG specified
5323 // cascading rules for <svg:use> - bug 265894
5325 aParent
->NodeInfo()->Equals(nsGkAtoms::use
, kNameSpaceID_SVG
)) {
5326 content
->SetFlags(NODE_IS_ANONYMOUS
);
5330 content
->SetNativeAnonymous();
5333 rv
= content
->BindToTree(mDocument
, aParent
, aParent
, PR_TRUE
);
5334 if (NS_FAILED(rv
)) {
5335 content
->UnbindFromTree();
5339 nsIFrame
* newFrame
= creator
->CreateFrameFor(content
);
5341 aChildItems
.AddChild(newFrame
);
5344 // create the frame and attach it to our frame
5345 ConstructFrame(aState
, content
, aParentFrame
, aChildItems
);
5349 // process the current pseudo frame state
5350 if (!aState
.mPseudoFrames
.IsEmpty()) {
5351 ProcessPseudoFrames(aState
, aChildItems
);
5354 // restore the incoming pseudo frame state
5355 aState
.mPseudoFrames
= priorPseudoFrames
;
5361 PRBool
IsXULDisplayType(const nsStyleDisplay
* aDisplay
)
5363 return (aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_BOX
||
5365 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_GRID
||
5366 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_STACK
||
5368 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_BOX
5370 || aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GRID
||
5371 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_STACK
||
5372 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GRID_GROUP
||
5373 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GRID_LINE
||
5374 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_DECK
||
5375 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_POPUP
||
5376 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_GROUPBOX
5382 // XUL frames are not allowed to be out of flow.
5383 #define SIMPLE_XUL_FCDATA(_func) \
5384 FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | FCDATA_SKIP_ABSPOS_PUSH, \
5386 #define SCROLLABLE_XUL_FCDATA(_func) \
5387 FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | FCDATA_SKIP_ABSPOS_PUSH | \
5388 FCDATA_MAY_NEED_SCROLLFRAME, _func)
5389 #define SIMPLE_XUL_CREATE(_tag, _func) \
5390 { &nsGkAtoms::_tag, SIMPLE_XUL_FCDATA(_func) }
5391 #define SCROLLABLE_XUL_CREATE(_tag, _func) \
5392 { &nsGkAtoms::_tag, SCROLLABLE_XUL_FCDATA(_func) }
5393 #define SIMPLE_XUL_INT_CREATE(_int, _func) \
5394 { _int, SIMPLE_XUL_FCDATA(_func) }
5395 #define SCROLLABLE_XUL_INT_CREATE(_int, _func) \
5396 { _int, SCROLLABLE_XUL_FCDATA(_func) }
5399 nsIFrame
* NS_NewGridBoxFrame(nsIPresShell
* aPresShell
,
5400 nsStyleContext
* aStyleContext
)
5402 nsCOMPtr
<nsIBoxLayout
> layout
;
5403 NS_NewGridLayout2(aPresShell
, getter_AddRefs(layout
));
5408 return NS_NewBoxFrame(aPresShell
, aStyleContext
, PR_FALSE
, layout
);
5412 const nsCSSFrameConstructor::FrameConstructionData
*
5413 nsCSSFrameConstructor::FindXULTagData(nsIContent
* aContent
,
5415 PRInt32 aNameSpaceID
,
5416 nsStyleContext
* aStyleContext
)
5418 if (aNameSpaceID
!= kNameSpaceID_XUL
) {
5422 static const FrameConstructionDataByTag sXULTagData
[] = {
5424 SCROLLABLE_XUL_CREATE(button
, NS_NewButtonBoxFrame
),
5425 SCROLLABLE_XUL_CREATE(checkbox
, NS_NewButtonBoxFrame
),
5426 SCROLLABLE_XUL_CREATE(radio
, NS_NewButtonBoxFrame
),
5427 SCROLLABLE_XUL_CREATE(autorepeatbutton
, NS_NewAutoRepeatBoxFrame
),
5428 SCROLLABLE_XUL_CREATE(titlebar
, NS_NewTitleBarFrame
),
5429 SCROLLABLE_XUL_CREATE(resizer
, NS_NewResizerFrame
),
5430 SIMPLE_XUL_CREATE(image
, NS_NewImageBoxFrame
),
5431 SIMPLE_XUL_CREATE(spring
, NS_NewLeafBoxFrame
),
5432 SIMPLE_XUL_CREATE(spacer
, NS_NewLeafBoxFrame
),
5433 SIMPLE_XUL_CREATE(treechildren
, NS_NewTreeBodyFrame
),
5434 SIMPLE_XUL_CREATE(treecol
, NS_NewTreeColFrame
),
5435 SIMPLE_XUL_CREATE(text
, NS_NewTextBoxFrame
),
5436 SIMPLE_TAG_CHAIN(label
, nsCSSFrameConstructor::FindXULLabelData
),
5437 SIMPLE_TAG_CHAIN(description
, nsCSSFrameConstructor::FindXULDescriptionData
),
5438 SIMPLE_XUL_CREATE(menu
, NS_NewMenuFrame
),
5439 SIMPLE_XUL_CREATE(menubutton
, NS_NewMenuFrame
),
5440 SIMPLE_XUL_CREATE(menuitem
, NS_NewMenuItemFrame
),
5442 SIMPLE_TAG_CHAIN(menubar
, nsCSSFrameConstructor::FindXULMenubarData
),
5444 SIMPLE_XUL_CREATE(menubar
, NS_NewMenuBarFrame
),
5445 #endif /* XP_MACOSX */
5446 SIMPLE_TAG_CHAIN(popupgroup
, nsCSSFrameConstructor::FindPopupGroupData
),
5447 SIMPLE_XUL_CREATE(iframe
, NS_NewSubDocumentFrame
),
5448 SIMPLE_XUL_CREATE(editor
, NS_NewSubDocumentFrame
),
5449 SIMPLE_XUL_CREATE(browser
, NS_NewSubDocumentFrame
),
5450 SIMPLE_XUL_CREATE(progressmeter
, NS_NewProgressMeterFrame
),
5451 SIMPLE_XUL_CREATE(splitter
, NS_NewSplitterFrame
),
5452 SIMPLE_TAG_CHAIN(listboxbody
,
5453 nsCSSFrameConstructor::FindXULListBoxBodyData
),
5454 SIMPLE_TAG_CHAIN(listitem
, nsCSSFrameConstructor::FindXULListItemData
),
5455 #endif /* MOZ_XUL */
5456 SIMPLE_XUL_CREATE(slider
, NS_NewSliderFrame
),
5457 SIMPLE_XUL_CREATE(scrollbar
, NS_NewScrollbarFrame
),
5458 SIMPLE_XUL_CREATE(scrollbarbutton
, NS_NewScrollbarButtonFrame
)
5461 return FindDataByTag(aTag
, aContent
, aStyleContext
, sXULTagData
,
5462 NS_ARRAY_LENGTH(sXULTagData
));
5467 const nsCSSFrameConstructor::FrameConstructionData
*
5468 nsCSSFrameConstructor::FindPopupGroupData(nsIContent
* aContent
,
5469 nsStyleContext
* /* unused */)
5471 if (!aContent
->IsRootOfNativeAnonymousSubtree()) {
5475 static const FrameConstructionData sPopupSetData
=
5476 SIMPLE_XUL_FCDATA(NS_NewPopupSetFrame
);
5477 return &sPopupSetData
;
5481 const nsCSSFrameConstructor::FrameConstructionData
5482 nsCSSFrameConstructor::sXULTextBoxData
= SIMPLE_XUL_FCDATA(NS_NewTextBoxFrame
);
5485 const nsCSSFrameConstructor::FrameConstructionData
*
5486 nsCSSFrameConstructor::FindXULLabelData(nsIContent
* aContent
,
5487 nsStyleContext
* /* unused */)
5489 if (aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::value
)) {
5490 return &sXULTextBoxData
;
5493 static const FrameConstructionData sLabelData
=
5494 SIMPLE_XUL_FCDATA(NS_NewXULLabelFrame
);
5499 NS_NewXULDescriptionFrame(nsIPresShell
* aPresShell
, nsStyleContext
*aContext
)
5501 // XXXbz do we really need to set those flags? If the parent is not
5502 // a block we'll get them anyway, and if it is, do we want them?
5503 return NS_NewBlockFrame(aPresShell
, aContext
,
5504 NS_BLOCK_FLOAT_MGR
| NS_BLOCK_MARGIN_ROOT
);
5508 const nsCSSFrameConstructor::FrameConstructionData
*
5509 nsCSSFrameConstructor::FindXULDescriptionData(nsIContent
* aContent
,
5510 nsStyleContext
* /* unused */)
5512 if (aContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::value
)) {
5513 return &sXULTextBoxData
;
5516 static const FrameConstructionData sDescriptionData
=
5517 SIMPLE_XUL_FCDATA(NS_NewXULDescriptionFrame
);
5518 return &sDescriptionData
;
5523 const nsCSSFrameConstructor::FrameConstructionData
*
5524 nsCSSFrameConstructor::FindXULMenubarData(nsIContent
* aContent
,
5525 nsStyleContext
* aStyleContext
)
5527 nsCOMPtr
<nsISupports
> container
=
5528 aStyleContext
->PresContext()->GetContainer();
5530 nsCOMPtr
<nsIDocShellTreeItem
> treeItem(do_QueryInterface(container
));
5533 treeItem
->GetItemType(&type
);
5534 if (nsIDocShellTreeItem::typeChrome
== type
) {
5535 nsCOMPtr
<nsIDocShellTreeItem
> parent
;
5536 treeItem
->GetParent(getter_AddRefs(parent
));
5538 // This is the root. Suppress the menubar, since on Mac
5539 // window menus are not attached to the window.
5540 static const FrameConstructionData sSuppressData
= SUPPRESS_FCDATA();
5541 return &sSuppressData
;
5547 static const FrameConstructionData sMenubarData
=
5548 SIMPLE_XUL_FCDATA(NS_NewMenuBarFrame
);
5549 return &sMenubarData
;
5551 #endif /* XP_MACOSX */
5554 const nsCSSFrameConstructor::FrameConstructionData
*
5555 nsCSSFrameConstructor::FindXULListBoxBodyData(nsIContent
* aContent
,
5556 nsStyleContext
* aStyleContext
)
5558 if (aStyleContext
->GetStyleDisplay()->mDisplay
!=
5559 NS_STYLE_DISPLAY_GRID_GROUP
) {
5563 static const FrameConstructionData sListBoxBodyData
=
5564 SCROLLABLE_XUL_FCDATA(NS_NewListBoxBodyFrame
);
5565 return &sListBoxBodyData
;
5569 const nsCSSFrameConstructor::FrameConstructionData
*
5570 nsCSSFrameConstructor::FindXULListItemData(nsIContent
* aContent
,
5571 nsStyleContext
* aStyleContext
)
5573 if (aStyleContext
->GetStyleDisplay()->mDisplay
!=
5574 NS_STYLE_DISPLAY_GRID_LINE
) {
5578 static const FrameConstructionData sListItemData
=
5579 SCROLLABLE_XUL_FCDATA(NS_NewListItemFrame
);
5580 return &sListItemData
;
5583 #endif /* MOZ_XUL */
5586 const nsCSSFrameConstructor::FrameConstructionData
*
5587 nsCSSFrameConstructor::FindXULDisplayData(const nsStyleDisplay
* aDisplay
,
5588 nsIContent
* aContent
,
5589 nsStyleContext
* aStyleContext
)
5591 static const FrameConstructionDataByInt sXULDisplayData
[] = {
5592 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_INLINE_BOX
, NS_NewBoxFrame
),
5593 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_BOX
, NS_NewBoxFrame
),
5595 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_INLINE_GRID
, NS_NewGridBoxFrame
),
5596 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_GRID
, NS_NewGridBoxFrame
),
5597 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_GRID_GROUP
,
5598 NS_NewGridRowGroupFrame
),
5599 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_GRID_LINE
,
5600 NS_NewGridRowLeafFrame
),
5601 SIMPLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_DECK
, NS_NewDeckFrame
),
5602 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_GROUPBOX
, NS_NewGroupBoxFrame
),
5603 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_INLINE_STACK
, NS_NewStackFrame
),
5604 SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_STACK
, NS_NewStackFrame
),
5605 { NS_STYLE_DISPLAY_POPUP
,
5606 FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW
| FCDATA_IS_POPUP
|
5607 FCDATA_SKIP_ABSPOS_PUSH
, NS_NewMenuPopupFrame
) }
5608 #endif /* MOZ_XUL */
5611 // Processing by display here:
5612 return FindDataByInt(aDisplay
->mDisplay
, aContent
, aStyleContext
,
5613 sXULDisplayData
, NS_ARRAY_LENGTH(sXULDisplayData
));
5617 nsCSSFrameConstructor::AddLazyChildren(nsIContent
* aContent
,
5618 nsLazyFrameConstructionCallback
* aCallback
,
5619 void* aArg
, PRBool aIsSynch
)
5621 nsCOMPtr
<nsIRunnable
> event
=
5622 new LazyGenerateChildrenEvent(aContent
, mPresShell
, aCallback
, aArg
);
5623 return aIsSynch
? event
->Run() :
5624 NS_DispatchToCurrentThread(event
);
5627 already_AddRefed
<nsStyleContext
>
5628 nsCSSFrameConstructor::BeginBuildingScrollFrame(nsFrameConstructorState
& aState
,
5629 nsIContent
* aContent
,
5630 nsStyleContext
* aContentStyle
,
5631 nsIFrame
* aParentFrame
,
5632 nsIAtom
* aScrolledPseudo
,
5634 nsIFrame
*& aNewFrame
)
5636 nsIFrame
* gfxScrollFrame
= aNewFrame
;
5638 nsFrameItems anonymousItems
;
5640 nsRefPtr
<nsStyleContext
> contentStyle
= aContentStyle
;
5642 if (!gfxScrollFrame
) {
5643 // Build a XULScrollFrame when the child is a box, otherwise an
5645 // XXXbz this is the lone remaining consumer of IsXULDisplayType.
5646 // I wonder whether we can eliminate that somehow.
5647 if (IsXULDisplayType(aContentStyle
->GetStyleDisplay())) {
5648 gfxScrollFrame
= NS_NewXULScrollFrame(mPresShell
, contentStyle
, aIsRoot
);
5650 gfxScrollFrame
= NS_NewHTMLScrollFrame(mPresShell
, contentStyle
, aIsRoot
);
5653 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, gfxScrollFrame
);
5656 nsHTMLContainerFrame::CreateViewForFrame(gfxScrollFrame
, PR_FALSE
);
5659 // if there are any anonymous children for the scroll frame, create
5661 CreateAnonymousFrames(aState
, aContent
, gfxScrollFrame
, anonymousItems
);
5663 aNewFrame
= gfxScrollFrame
;
5665 // we used the style that was passed in. So resolve another one.
5666 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
5667 nsStyleContext
* aScrolledChildStyle
= styleSet
->ResolvePseudoStyleFor(aContent
,
5669 contentStyle
).get();
5671 if (gfxScrollFrame
) {
5672 gfxScrollFrame
->SetInitialChildList(nsnull
, anonymousItems
.childList
);
5675 return aScrolledChildStyle
;
5679 nsCSSFrameConstructor::FinishBuildingScrollFrame(nsIFrame
* aScrollFrame
,
5680 nsIFrame
* aScrolledFrame
)
5682 aScrollFrame
->AppendFrames(nsnull
, aScrolledFrame
);
5684 // force the scrolled frame to have a view. The view will be parented to
5685 // the correct anonymous inner view because the scrollframes override
5686 // nsIFrame::GetParentViewForChildFrame.
5687 nsHTMLContainerFrame::CreateViewForFrame(aScrolledFrame
, PR_TRUE
);
5689 // XXXbz what's the point of the code after this in this method?
5690 nsIView
* view
= aScrolledFrame
->GetView();
5697 * Called to wrap a gfx scrollframe around a frame. The hierarchy will look like this
5699 * ------- for gfx scrollbars ------
5705 * Frame (scrolled frame you passed in)
5708 *-----------------------------------
5711 * ScrollFrame: This is a frame that manages gfx cross platform frame based scrollbars.
5713 * @param aContent the content node of the child to wrap.
5714 * @param aScrolledFrame The frame of the content to wrap. This should not be
5715 * Initialized. This method will initialize it with a scrolled pseudo
5716 * and no nsIContent. The content will be attached to the scrollframe
5718 * @param aContentStyle the style context that has already been resolved for the content being passed in.
5720 * @param aParentFrame The parent to attach the scroll frame to
5722 * @param aNewFrame The new scrollframe or gfx scrollframe that we create. It will contain the
5723 * scrolled frame you passed in. (returned)
5724 * If this is not null, we'll just use it
5725 * @param aScrolledContentStyle the style that was resolved for the scrolled frame. (returned)
5728 nsCSSFrameConstructor::BuildScrollFrame(nsFrameConstructorState
& aState
,
5729 nsIContent
* aContent
,
5730 nsStyleContext
* aContentStyle
,
5731 nsIFrame
* aScrolledFrame
,
5732 nsIFrame
* aParentFrame
,
5733 nsIFrame
*& aNewFrame
)
5735 nsRefPtr
<nsStyleContext
> scrolledContentStyle
=
5736 BeginBuildingScrollFrame(aState
, aContent
, aContentStyle
, aParentFrame
,
5737 nsCSSAnonBoxes::scrolledContent
,
5738 PR_FALSE
, aNewFrame
);
5740 aScrolledFrame
->SetStyleContextWithoutNotification(scrolledContentStyle
);
5741 InitAndRestoreFrame(aState
, aContent
, aNewFrame
, nsnull
, aScrolledFrame
);
5743 FinishBuildingScrollFrame(aNewFrame
, aScrolledFrame
);
5745 // now set the primary frame to the ScrollFrame
5746 aState
.mFrameManager
->SetPrimaryFrameFor( aContent
, aNewFrame
);
5751 const nsCSSFrameConstructor::FrameConstructionData
*
5752 nsCSSFrameConstructor::FindDisplayData(const nsStyleDisplay
* aDisplay
,
5753 nsIContent
* aContent
)
5755 // The style system ensures that floated and positioned frames are
5757 NS_ASSERTION(!(aDisplay
->IsFloating() ||
5758 aDisplay
->IsAbsolutelyPositioned()) ||
5759 aDisplay
->IsBlockOutside(),
5760 "Style system did not apply CSS2.1 section 9.7 fixups");
5762 // If this is "body", try propagating its scroll style to the viewport
5763 // Note that we need to do this even if the body is NOT scrollable;
5764 // it might have dynamically changed from scrollable to not scrollable,
5765 // and that might need to be propagated.
5766 // XXXbz is this the right place to do this? If this code moves,
5767 // make this function static.
5768 PRBool propagatedScrollToViewport
= PR_FALSE
;
5769 if (aContent
->NodeInfo()->Equals(nsGkAtoms::body
) &&
5770 aContent
->IsNodeOfType(nsINode::eHTML
)) {
5771 propagatedScrollToViewport
=
5772 PropagateScrollToViewport() == aContent
;
5775 // If the frame is a block-level frame and is scrollable, then wrap it
5776 // in a scroll frame.
5777 // XXX Ignore tables for the time being
5778 // XXXbz it would be nice to combine this with the other block
5779 // case... Think about how do do this?
5780 if (aDisplay
->IsBlockInside() &&
5781 aDisplay
->IsScrollableOverflow() &&
5782 !propagatedScrollToViewport
) {
5783 static const FrameConstructionData sScrollableBlockData
=
5784 FULL_CTOR_FCDATA(0, &nsCSSFrameConstructor::ConstructScrollableBlock
);
5785 return &sScrollableBlockData
;
5788 // Handle various non-scrollable blocks
5789 if (aDisplay
->IsBlockInside() ||
5790 NS_STYLE_DISPLAY_RUN_IN
== aDisplay
->mDisplay
||
5791 NS_STYLE_DISPLAY_COMPACT
== aDisplay
->mDisplay
) {
5792 static const FrameConstructionData sNonScrollableBlockData
=
5793 FULL_CTOR_FCDATA(0, &nsCSSFrameConstructor::ConstructNonScrollableBlock
);
5794 return &sNonScrollableBlockData
;
5797 // Handle various inlines
5798 if (NS_STYLE_DISPLAY_INLINE
== aDisplay
->mDisplay
||
5799 NS_STYLE_DISPLAY_MARKER
== aDisplay
->mDisplay
) {
5800 // To keep the hash table small don't add inline frames (they're
5801 // typically things like FONT and B), because we can quickly
5802 // find them if we need to.
5803 // XXXbz the "quickly" part is a bald-faced lie!
5804 static const FrameConstructionData sInlineData
=
5805 FULL_CTOR_FCDATA(FCDATA_SKIP_FRAMEMAP
,
5806 &nsCSSFrameConstructor::ConstructInline
);
5807 return &sInlineData
;
5810 if (NS_STYLE_DISPLAY_TABLE
== aDisplay
->mDisplay
||
5811 NS_STYLE_DISPLAY_INLINE_TABLE
== aDisplay
->mDisplay
) {
5812 static const FrameConstructionData sTableData
=
5813 FULL_CTOR_FCDATA(0, &nsCSSFrameConstructor::ConstructTable
);
5817 static const FrameConstructionData sTablePartData
=
5818 FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART
| FCDATA_SKIP_FRAMEMAP
,
5819 &nsCSSFrameConstructor::ConstructTablePart
);
5820 return &sTablePartData
;
5825 nsCSSFrameConstructor::ConstructScrollableBlock(nsFrameConstructorState
& aState
,
5826 nsIContent
* aContent
,
5827 nsIFrame
* aParentFrame
,
5829 PRInt32 aNameSpaceID
,
5830 nsStyleContext
* aStyleContext
,
5831 const nsStyleDisplay
* aDisplay
,
5832 nsFrameItems
& aFrameItems
,
5833 nsIFrame
** aNewFrame
)
5835 *aNewFrame
= nsnull
;
5836 nsRefPtr
<nsStyleContext
> scrolledContentStyle
5837 = BeginBuildingScrollFrame(aState
, aContent
, aStyleContext
,
5838 aState
.GetGeometricParent(aDisplay
, aParentFrame
),
5839 nsCSSAnonBoxes::scrolledContent
,
5840 PR_FALSE
, *aNewFrame
);
5842 // Create our block frame
5843 // pass a temporary stylecontext, the correct one will be set later
5844 nsIFrame
* scrolledFrame
=
5845 NS_NewBlockFormattingContext(mPresShell
, aStyleContext
);
5847 nsFrameItems blockItem
;
5848 nsresult rv
= ConstructBlock(aState
,
5849 scrolledContentStyle
->GetStyleDisplay(), aContent
,
5850 *aNewFrame
, *aNewFrame
, scrolledContentStyle
,
5851 &scrolledFrame
, blockItem
, aDisplay
->IsPositioned());
5852 if (NS_UNLIKELY(NS_FAILED(rv
))) {
5853 // XXXbz any cleanup needed here?
5857 NS_ASSERTION(blockItem
.childList
== scrolledFrame
,
5858 "Scrollframe's frameItems should be exactly the scrolled frame");
5859 FinishBuildingScrollFrame(*aNewFrame
, scrolledFrame
);
5861 rv
= aState
.AddChild(*aNewFrame
, aFrameItems
, aContent
, aStyleContext
,
5867 nsCSSFrameConstructor::ConstructNonScrollableBlock(nsFrameConstructorState
& aState
,
5868 nsIContent
* aContent
,
5869 nsIFrame
* aParentFrame
,
5871 PRInt32 aNameSpaceID
,
5872 nsStyleContext
* aStyleContext
,
5873 const nsStyleDisplay
* aDisplay
,
5874 nsFrameItems
& aFrameItems
,
5875 nsIFrame
** aNewFrame
)
5877 if (aDisplay
->IsAbsolutelyPositioned() ||
5878 aDisplay
->IsFloating() ||
5879 NS_STYLE_DISPLAY_INLINE_BLOCK
== aDisplay
->mDisplay
) {
5880 *aNewFrame
= NS_NewBlockFormattingContext(mPresShell
, aStyleContext
);
5882 *aNewFrame
= NS_NewBlockFrame(mPresShell
, aStyleContext
);
5885 return ConstructBlock(aState
, aDisplay
, aContent
,
5886 aState
.GetGeometricParent(aDisplay
, aParentFrame
),
5887 aParentFrame
, aStyleContext
, aNewFrame
,
5888 aFrameItems
, aDisplay
->IsPositioned());
5893 nsCSSFrameConstructor::ConstructTable(nsFrameConstructorState
& aState
,
5894 nsIContent
* aContent
,
5895 nsIFrame
* aParentFrame
,
5897 PRInt32 aNameSpaceID
,
5898 nsStyleContext
* aStyleContext
,
5899 const nsStyleDisplay
* aDisplay
,
5900 nsFrameItems
& aFrameItems
,
5901 nsIFrame
** aNewFrame
)
5903 NS_PRECONDITION(aDisplay
->mDisplay
== NS_STYLE_DISPLAY_TABLE
||
5904 aDisplay
->mDisplay
== NS_STYLE_DISPLAY_INLINE_TABLE
,
5907 nsIFrame
* innerTable
;
5908 return ConstructTableFrame(aState
, aContent
, aParentFrame
, aStyleContext
,
5909 aNameSpaceID
, PR_FALSE
, aFrameItems
, *aNewFrame
,
5914 nsCSSFrameConstructor::ConstructTablePart(nsFrameConstructorState
& aState
,
5915 nsIContent
* aContent
,
5916 nsIFrame
* aParentFrame
,
5918 PRInt32 aNameSpaceID
,
5919 nsStyleContext
* aStyleContext
,
5920 const nsStyleDisplay
* aDisplay
,
5921 nsFrameItems
& aFrameItems
,
5922 nsIFrame
** aNewFrame
)
5924 nsresult rv
= NS_ERROR_UNEXPECTED
;
5925 PRBool hasPseudoParent
;
5927 // Use the 'display' property to choose a frame type
5928 switch (aDisplay
->mDisplay
) {
5929 case NS_STYLE_DISPLAY_TABLE_CAPTION
:
5931 // aParentFrame may be an inner table frame rather than an outer frame
5932 // In this case we need to get the outer frame.
5933 nsIFrame
* parentFrame
= AdjustCaptionParentFrame(aParentFrame
);
5934 rv
= ConstructTableCaptionFrame(aState
, aContent
, parentFrame
,
5935 aStyleContext
, aNameSpaceID
, aFrameItems
,
5936 *aNewFrame
, &hasPseudoParent
);
5940 case NS_STYLE_DISPLAY_TABLE_ROW_GROUP
:
5941 case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
:
5942 case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
:
5943 rv
= ConstructTableRowGroupFrame(aState
, aContent
, aParentFrame
,
5944 aStyleContext
, aNameSpaceID
, PR_FALSE
,
5945 aFrameItems
, *aNewFrame
, &hasPseudoParent
);
5948 case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
:
5949 rv
= ConstructTableColGroupFrame(aState
, aContent
, aParentFrame
,
5950 aStyleContext
, aNameSpaceID
,
5951 PR_FALSE
, aFrameItems
, *aNewFrame
,
5955 case NS_STYLE_DISPLAY_TABLE_COLUMN
:
5956 rv
= ConstructTableColFrame(aState
, aContent
, aParentFrame
,
5957 aStyleContext
, aNameSpaceID
, PR_FALSE
,
5958 aFrameItems
, *aNewFrame
, &hasPseudoParent
);
5961 case NS_STYLE_DISPLAY_TABLE_ROW
:
5962 rv
= ConstructTableRowFrame(aState
, aContent
, aParentFrame
,
5963 aStyleContext
, aNameSpaceID
, PR_FALSE
,
5964 aFrameItems
, *aNewFrame
, &hasPseudoParent
);
5967 case NS_STYLE_DISPLAY_TABLE_CELL
:
5969 nsIFrame
* innerTable
;
5970 rv
= ConstructTableCellFrame(aState
, aContent
, aParentFrame
,
5971 aStyleContext
, aNameSpaceID
,
5972 PR_FALSE
, aFrameItems
, *aNewFrame
,
5973 innerTable
, &hasPseudoParent
);
5978 NS_NOTREACHED("How did we get here?");
5982 if (NS_SUCCEEDED(rv
) && !hasPseudoParent
) {
5983 aFrameItems
.AddChild(*aNewFrame
);
5990 nsCSSFrameConstructor::InitAndRestoreFrame(const nsFrameConstructorState
& aState
,
5991 nsIContent
* aContent
,
5992 nsIFrame
* aParentFrame
,
5993 nsIFrame
* aPrevInFlow
,
5994 nsIFrame
* aNewFrame
,
5995 PRBool aAllowCounters
)
5997 NS_PRECONDITION(mUpdateCount
!= 0,
5998 "Should be in an update while creating frames");
6000 nsresult rv
= NS_OK
;
6002 NS_ASSERTION(aNewFrame
, "Null frame cannot be initialized");
6004 return NS_ERROR_NULL_POINTER
;
6006 // Initialize the frame
6007 rv
= aNewFrame
->Init(aContent
, aParentFrame
, aPrevInFlow
);
6008 aNewFrame
->AddStateBits(aState
.mAdditionalStateBits
);
6010 if (aState
.mFrameState
&& aState
.mFrameManager
) {
6011 // Restore frame state for just the newly created frame.
6012 aState
.mFrameManager
->RestoreFrameStateFor(aNewFrame
, aState
.mFrameState
);
6015 if (aAllowCounters
&& !aPrevInFlow
&&
6016 mCounterManager
.AddCounterResetsAndIncrements(aNewFrame
)) {
6023 already_AddRefed
<nsStyleContext
>
6024 nsCSSFrameConstructor::ResolveStyleContext(nsIFrame
* aParentFrame
,
6025 nsIContent
* aContent
)
6027 nsStyleContext
* parentStyleContext
= nsnull
;
6028 if (aContent
->GetParent()) {
6029 aParentFrame
= nsFrame::CorrectStyleParentFrame(aParentFrame
, nsnull
);
6032 // Resolve the style context based on the content object and the parent
6034 parentStyleContext
= aParentFrame
->GetStyleContext();
6036 // Perhaps aParentFrame is a canvasFrame and we're replicating
6037 // fixed-pos frames.
6038 // XXX should we create a way to tell ConstructFrame which style
6039 // context to use, and pass it the style context for the
6040 // previous page's fixed-pos frame?
6043 // This has got to be a call from ConstructDocElementTableFrame.
6044 // Not sure how best to assert that here.
6047 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
6049 if (aContent
->IsNodeOfType(nsINode::eELEMENT
)) {
6050 return styleSet
->ResolveStyleFor(aContent
, parentStyleContext
);
6053 NS_ASSERTION(aContent
->IsNodeOfType(nsINode::eTEXT
),
6054 "shouldn't waste time creating style contexts for "
6055 "comments and processing instructions");
6057 return styleSet
->ResolveStyleForNonElement(parentStyleContext
);
6064 nsCSSFrameConstructor::FlushAccumulatedBlock(nsFrameConstructorState
& aState
,
6065 nsIContent
* aContent
,
6066 nsIFrame
* aParentFrame
,
6067 nsFrameItems
* aBlockItems
,
6068 nsFrameItems
* aNewItems
)
6070 if (!aBlockItems
->childList
) {
6075 nsStyleContext
* parentContext
=
6076 nsFrame::CorrectStyleParentFrame(aParentFrame
,
6077 nsCSSAnonBoxes::mozMathMLAnonymousBlock
)->GetStyleContext();
6078 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
6079 nsRefPtr
<nsStyleContext
> blockContext
;
6080 blockContext
= styleSet
->ResolvePseudoStyleFor(aContent
,
6081 nsCSSAnonBoxes::mozMathMLAnonymousBlock
,
6084 // then, create a block frame that will wrap the child frames. Make it a
6085 // MathML frame so that Get(Absolute/Float)ContainingBlockFor know that this
6086 // is not a suitable block.
6087 nsIFrame
* blockFrame
= NS_NewMathMLmathBlockFrame(mPresShell
, blockContext
,
6088 NS_BLOCK_FLOAT_MGR
| NS_BLOCK_MARGIN_ROOT
);
6089 if (NS_UNLIKELY(!blockFrame
))
6090 return NS_ERROR_OUT_OF_MEMORY
;
6092 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, blockFrame
);
6093 for (nsIFrame
* f
= aBlockItems
->childList
; f
; f
= f
->GetNextSibling()) {
6094 ReparentFrame(aState
.mFrameManager
, blockFrame
, f
);
6096 // abs-pos and floats are disabled in MathML children so we don't have to
6097 // worry about messing up those.
6098 blockFrame
->SetInitialChildList(nsnull
, aBlockItems
->childList
);
6099 *aBlockItems
= nsFrameItems();
6100 aNewItems
->AddChild(blockFrame
);
6104 // Only <math> elements can be floated or positioned. All other MathML
6105 // should be in-flow.
6106 #define SIMPLE_MATHML_CREATE(_tag, _func) \
6107 { &nsGkAtoms::_tag, \
6108 FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | \
6109 FCDATA_FORCE_NULL_ABSPOS_CONTAINER | \
6110 FCDATA_WRAP_KIDS_IN_BLOCKS | \
6111 FCDATA_SKIP_FRAMEMAP, _func) }
6114 const nsCSSFrameConstructor::FrameConstructionData
*
6115 nsCSSFrameConstructor::FindMathMLData(nsIContent
* aContent
,
6117 PRInt32 aNameSpaceID
,
6118 nsStyleContext
* aStyleContext
)
6120 // Make sure that we remain confined in the MathML world
6121 if (aNameSpaceID
!= kNameSpaceID_MathML
)
6124 static const FrameConstructionDataByTag sMathMLData
[] = {
6125 SIMPLE_MATHML_CREATE(mi_
, NS_NewMathMLTokenFrame
),
6126 SIMPLE_MATHML_CREATE(mn_
, NS_NewMathMLTokenFrame
),
6127 SIMPLE_MATHML_CREATE(ms_
, NS_NewMathMLTokenFrame
),
6128 SIMPLE_MATHML_CREATE(mtext_
, NS_NewMathMLTokenFrame
),
6129 SIMPLE_MATHML_CREATE(mo_
, NS_NewMathMLmoFrame
),
6130 SIMPLE_MATHML_CREATE(mfrac_
, NS_NewMathMLmfracFrame
),
6131 SIMPLE_MATHML_CREATE(msup_
, NS_NewMathMLmsupFrame
),
6132 SIMPLE_MATHML_CREATE(msub_
, NS_NewMathMLmsubFrame
),
6133 SIMPLE_MATHML_CREATE(msubsup_
, NS_NewMathMLmsubsupFrame
),
6134 SIMPLE_MATHML_CREATE(munder_
, NS_NewMathMLmunderFrame
),
6135 SIMPLE_MATHML_CREATE(mover_
, NS_NewMathMLmoverFrame
),
6136 SIMPLE_MATHML_CREATE(munderover_
, NS_NewMathMLmunderoverFrame
),
6137 SIMPLE_MATHML_CREATE(mphantom_
, NS_NewMathMLmphantomFrame
),
6138 SIMPLE_MATHML_CREATE(mpadded_
, NS_NewMathMLmpaddedFrame
),
6139 SIMPLE_MATHML_CREATE(mspace_
, NS_NewMathMLmspaceFrame
),
6140 SIMPLE_MATHML_CREATE(none
, NS_NewMathMLmspaceFrame
),
6141 SIMPLE_MATHML_CREATE(mprescripts_
, NS_NewMathMLmspaceFrame
),
6142 SIMPLE_MATHML_CREATE(mfenced_
, NS_NewMathMLmfencedFrame
),
6143 SIMPLE_MATHML_CREATE(mmultiscripts_
, NS_NewMathMLmmultiscriptsFrame
),
6144 SIMPLE_MATHML_CREATE(mstyle_
, NS_NewMathMLmstyleFrame
),
6145 SIMPLE_MATHML_CREATE(msqrt_
, NS_NewMathMLmsqrtFrame
),
6146 SIMPLE_MATHML_CREATE(mroot_
, NS_NewMathMLmrootFrame
),
6147 SIMPLE_MATHML_CREATE(maction_
, NS_NewMathMLmactionFrame
),
6148 SIMPLE_MATHML_CREATE(mrow_
, NS_NewMathMLmrowFrame
),
6149 SIMPLE_MATHML_CREATE(merror_
, NS_NewMathMLmrowFrame
),
6151 FCDATA_DECL(FCDATA_FORCE_NULL_ABSPOS_CONTAINER
|
6152 FCDATA_WRAP_KIDS_IN_BLOCKS
|
6153 FCDATA_SKIP_FRAMEMAP
,
6154 NS_NewMathMLmathFrame
) }
6157 return FindDataByTag(aTag
, aContent
, aStyleContext
, sMathMLData
,
6158 NS_ARRAY_LENGTH(sMathMLData
));
6160 #endif // MOZ_MATHML
6163 // Only outer <svg> elements can be floated or positioned. All other SVG
6164 // should be in-flow.
6165 #define SIMPLE_SVG_FCDATA(_func) \
6166 FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | \
6167 FCDATA_SKIP_ABSPOS_PUSH | FCDATA_SKIP_FRAMEMAP | \
6168 FCDATA_DISALLOW_GENERATED_CONTENT, _func)
6169 #define SIMPLE_SVG_CREATE(_tag, _func) \
6170 { &nsGkAtoms::_tag, SIMPLE_SVG_FCDATA(_func) }
6173 const nsCSSFrameConstructor::FrameConstructionData
*
6174 nsCSSFrameConstructor::FindSVGData(nsIContent
* aContent
,
6176 PRInt32 aNameSpaceID
,
6177 nsIFrame
* aParentFrame
,
6178 nsStyleContext
* aStyleContext
)
6180 if (aNameSpaceID
!= kNameSpaceID_SVG
|| !NS_SVGEnabled()) {
6184 static const FrameConstructionData sSuppressData
= SUPPRESS_FCDATA();
6185 static const FrameConstructionData sGenericContainerData
=
6186 SIMPLE_SVG_FCDATA(NS_NewSVGGenericContainerFrame
);
6188 PRBool parentIsSVG
= PR_FALSE
;
6189 nsIContent
* parentContent
=
6190 aParentFrame
? aParentFrame
->GetContent() : nsnull
;
6191 // XXXbz should this really be based on the XBL-resolved tag of the parent
6192 // frame's content? Should it not be based on the type of the parent frame
6193 // (e.g. whether it's an SVG frame)?
6194 if (parentContent
) {
6196 nsIAtom
* parentTag
=
6197 parentContent
->GetOwnerDoc()->BindingManager()->
6198 ResolveTag(aParentFrame
->GetContent(), &parentNSID
);
6200 // It's not clear whether the SVG spec intends to allow any SVG
6201 // content within svg:foreignObject at all (SVG 1.1, section
6202 // 23.2), but if it does, it better be svg:svg. So given that
6203 // we're allowing it, treat it as a non-SVG parent.
6204 parentIsSVG
= parentNSID
== kNameSpaceID_SVG
&&
6205 parentTag
!= nsGkAtoms::foreignObject
;
6208 if ((aTag
!= nsGkAtoms::svg
&& !parentIsSVG
) ||
6209 (aTag
== nsGkAtoms::desc
|| aTag
== nsGkAtoms::title
)) {
6210 // Sections 5.1 and G.4 of SVG 1.1 say that SVG elements other than
6211 // svg:svg not contained within svg:svg are incorrect, although they
6212 // don't seem to specify error handling. Ignore them, since many of
6213 // our frame classes can't deal. It *may* be that the document
6214 // should at that point be considered in error according to F.2, but
6215 // it's hard to tell.
6217 // Style mutation can't change this situation, so don't bother
6218 // adding to the undisplayed content map.
6219 // XXXbz except of course that this makes GetPrimaryFrameFor for this stuff
6220 // that much slower.
6222 // We don't currently handle any UI for desc/title
6223 return &sSuppressData
;
6226 // Reduce the number of frames we create unnecessarily. Note that this is not
6227 // where we select which frame in a <switch> to render! That happens in
6228 // nsSVGSwitchFrame::PaintSVG.
6229 if (!NS_SVG_PassesConditionalProcessingTests(aContent
)) {
6230 // Note that just returning is probably not right. According
6231 // to the spec, <use> is allowed to use an element that fails its
6232 // conditional, but because we never actually create the frame when
6233 // a conditional fails and when we use GetReferencedFrame to find the
6234 // references, things don't work right.
6236 return &sSuppressData
;
6239 // Special case for aTag == nsGkAtoms::svg because we don't want to
6240 // have to recompute parentIsSVG for it.
6241 if (aTag
== nsGkAtoms::svg
) {
6243 static const FrameConstructionData sInnerSVGData
=
6244 SIMPLE_SVG_FCDATA(NS_NewSVGInnerSVGFrame
);
6245 return &sInnerSVGData
;
6248 static const FrameConstructionData sOuterSVGData
=
6249 FCDATA_DECL(FCDATA_FORCE_VIEW
| FCDATA_SKIP_ABSPOS_PUSH
|
6250 FCDATA_SKIP_FRAMEMAP
| FCDATA_DISALLOW_GENERATED_CONTENT
,
6251 NS_NewSVGOuterSVGFrame
);
6252 return &sOuterSVGData
;
6255 // Special cases for text/tspan/textpath, because the kind of frame
6256 // they get depends on the parent frame.
6257 if (aTag
== nsGkAtoms::text
) {
6258 nsIFrame
*ancestorFrame
=
6259 nsSVGUtils::GetFirstNonAAncestorFrame(aParentFrame
);
6260 if (ancestorFrame
) {
6261 nsISVGTextContentMetrics
* metrics
= do_QueryFrame(ancestorFrame
);
6262 // Text cannot be nested
6264 return &sGenericContainerData
;
6268 else if (aTag
== nsGkAtoms::tspan
) {
6269 nsIFrame
*ancestorFrame
=
6270 nsSVGUtils::GetFirstNonAAncestorFrame(aParentFrame
);
6271 if (ancestorFrame
) {
6272 nsISVGTextContentMetrics
* metrics
= do_QueryFrame(ancestorFrame
);
6274 return &sGenericContainerData
;
6278 else if (aTag
== nsGkAtoms::textPath
) {
6279 nsIFrame
*ancestorFrame
=
6280 nsSVGUtils::GetFirstNonAAncestorFrame(aParentFrame
);
6281 if (!ancestorFrame
||
6282 ancestorFrame
->GetType() != nsGkAtoms::svgTextFrame
) {
6283 return &sGenericContainerData
;
6287 static const FrameConstructionDataByTag sSVGData
[] = {
6288 SIMPLE_SVG_CREATE(g
, NS_NewSVGGFrame
),
6289 SIMPLE_SVG_CREATE(svgSwitch
, NS_NewSVGSwitchFrame
),
6290 SIMPLE_SVG_CREATE(polygon
, NS_NewSVGPathGeometryFrame
),
6291 SIMPLE_SVG_CREATE(polyline
, NS_NewSVGPathGeometryFrame
),
6292 SIMPLE_SVG_CREATE(circle
, NS_NewSVGPathGeometryFrame
),
6293 SIMPLE_SVG_CREATE(ellipse
, NS_NewSVGPathGeometryFrame
),
6294 SIMPLE_SVG_CREATE(line
, NS_NewSVGPathGeometryFrame
),
6295 SIMPLE_SVG_CREATE(rect
, NS_NewSVGPathGeometryFrame
),
6296 SIMPLE_SVG_CREATE(path
, NS_NewSVGPathGeometryFrame
),
6297 SIMPLE_SVG_CREATE(defs
, NS_NewSVGContainerFrame
),
6298 COMPLEX_TAG_CREATE(foreignObject
,
6299 &nsCSSFrameConstructor::ConstructSVGForeignObjectFrame
),
6300 SIMPLE_SVG_CREATE(a
, NS_NewSVGAFrame
),
6301 SIMPLE_SVG_CREATE(text
, NS_NewSVGTextFrame
),
6302 SIMPLE_SVG_CREATE(tspan
, NS_NewSVGTSpanFrame
),
6303 SIMPLE_SVG_CREATE(linearGradient
, NS_NewSVGLinearGradientFrame
),
6304 SIMPLE_SVG_CREATE(radialGradient
, NS_NewSVGRadialGradientFrame
),
6305 SIMPLE_SVG_CREATE(stop
, NS_NewSVGStopFrame
),
6306 SIMPLE_SVG_CREATE(use
, NS_NewSVGUseFrame
),
6307 SIMPLE_SVG_CREATE(marker
, NS_NewSVGMarkerFrame
),
6308 SIMPLE_SVG_CREATE(image
, NS_NewSVGImageFrame
),
6309 SIMPLE_SVG_CREATE(clipPath
, NS_NewSVGClipPathFrame
),
6310 SIMPLE_SVG_CREATE(textPath
, NS_NewSVGTextPathFrame
),
6311 SIMPLE_SVG_CREATE(filter
, NS_NewSVGFilterFrame
),
6312 SIMPLE_SVG_CREATE(pattern
, NS_NewSVGPatternFrame
),
6313 SIMPLE_SVG_CREATE(mask
, NS_NewSVGMaskFrame
),
6314 SIMPLE_SVG_CREATE(feDistantLight
, NS_NewSVGLeafFrame
),
6315 SIMPLE_SVG_CREATE(fePointLight
, NS_NewSVGLeafFrame
),
6316 SIMPLE_SVG_CREATE(feSpotLight
, NS_NewSVGLeafFrame
),
6317 SIMPLE_SVG_CREATE(feBlend
, NS_NewSVGLeafFrame
),
6318 SIMPLE_SVG_CREATE(feColorMatrix
, NS_NewSVGLeafFrame
),
6319 SIMPLE_SVG_CREATE(feFuncR
, NS_NewSVGLeafFrame
),
6320 SIMPLE_SVG_CREATE(feFuncG
, NS_NewSVGLeafFrame
),
6321 SIMPLE_SVG_CREATE(feFuncB
, NS_NewSVGLeafFrame
),
6322 SIMPLE_SVG_CREATE(feFuncA
, NS_NewSVGLeafFrame
),
6323 SIMPLE_SVG_CREATE(feComposite
, NS_NewSVGLeafFrame
),
6324 SIMPLE_SVG_CREATE(feConvolveMatrix
, NS_NewSVGLeafFrame
),
6325 SIMPLE_SVG_CREATE(feDisplacementMap
, NS_NewSVGLeafFrame
),
6326 SIMPLE_SVG_CREATE(feFlood
, NS_NewSVGLeafFrame
),
6327 SIMPLE_SVG_CREATE(feGaussianBlur
, NS_NewSVGLeafFrame
),
6328 SIMPLE_SVG_CREATE(feImage
, NS_NewSVGLeafFrame
),
6329 SIMPLE_SVG_CREATE(feMergeNode
, NS_NewSVGLeafFrame
),
6330 SIMPLE_SVG_CREATE(feMorphology
, NS_NewSVGLeafFrame
),
6331 SIMPLE_SVG_CREATE(feOffset
, NS_NewSVGLeafFrame
),
6332 SIMPLE_SVG_CREATE(feTile
, NS_NewSVGLeafFrame
),
6333 SIMPLE_SVG_CREATE(feTurbulence
, NS_NewSVGLeafFrame
)
6336 const FrameConstructionData
* data
=
6337 FindDataByTag(aTag
, aContent
, aStyleContext
, sSVGData
,
6338 NS_ARRAY_LENGTH(sSVGData
));
6341 data
= &sGenericContainerData
;
6348 nsCSSFrameConstructor::ConstructSVGForeignObjectFrame(nsFrameConstructorState
& aState
,
6349 nsIContent
* aContent
,
6350 nsIFrame
* aParentFrame
,
6352 PRInt32 aNameSpaceID
,
6353 nsStyleContext
* aStyleContext
,
6354 const nsStyleDisplay
* aStyleDisplay
,
6355 nsFrameItems
& aFrameItems
,
6356 nsIFrame
** aNewFrame
)
6358 nsIFrame
* newFrame
= NS_NewSVGForeignObjectFrame(mPresShell
, aStyleContext
);
6359 if (NS_UNLIKELY(!newFrame
)) {
6360 return NS_ERROR_OUT_OF_MEMORY
;
6363 // We don't allow this frame to be out of flow
6364 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, newFrame
);
6365 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
6367 nsresult rv
= aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
,
6368 aParentFrame
, PR_FALSE
, PR_FALSE
);
6369 if (NS_FAILED(rv
)) {
6373 nsRefPtr
<nsStyleContext
> innerPseudoStyle
;
6374 innerPseudoStyle
= mPresShell
->StyleSet()->
6375 ResolvePseudoStyleFor(aContent
,
6376 nsCSSAnonBoxes::mozSVGForeignContent
, aStyleContext
);
6378 nsIFrame
* blockFrame
= NS_NewBlockFrame(mPresShell
, innerPseudoStyle
,
6379 NS_BLOCK_FLOAT_MGR
|
6380 NS_BLOCK_MARGIN_ROOT
);
6381 if (NS_UNLIKELY(!blockFrame
)) {
6382 newFrame
->Destroy();
6383 return NS_ERROR_OUT_OF_MEMORY
;
6386 nsFrameItems childItems
;
6387 // Claim to be relatively positioned so that we end up being the
6388 // absolute containing block.
6389 rv
= ConstructBlock(aState
, innerPseudoStyle
->GetStyleDisplay(), aContent
,
6390 newFrame
, newFrame
, innerPseudoStyle
,
6391 &blockFrame
, childItems
, PR_TRUE
);
6393 // Give the blockFrame a view so that GetOffsetTo works for descendants
6394 // of blockFrame with views...
6395 nsHTMLContainerFrame::CreateViewForFrame(blockFrame
, PR_TRUE
);
6397 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
6399 *aNewFrame
= newFrame
;
6406 // If page-break-before is set, this function constructs a page break frame,
6407 // EXCEPT for on these types of elements:
6408 // * row groups, rows, cells (these are handled internally by tables)
6409 // * fixed- and absolutely-positioned elements (currently, our positioning
6410 // code doesn't expect positioned frames to have nsPageBreakFrame siblings)
6412 // Returns true iff we should construct a page break frame after this element.
6413 // aStyleContext is the style context of the frame for which we're
6414 // constructing the page break
6416 nsCSSFrameConstructor::PageBreakBefore(nsFrameConstructorState
& aState
,
6417 nsIContent
* aContent
,
6418 nsIFrame
* aParentFrame
,
6419 nsStyleContext
* aStyleContext
,
6420 const FrameConstructionData
* aFCData
,
6421 nsFrameItems
& aFrameItems
)
6423 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
6425 if (!aStyleContext
->GetStyleDisplay()->IsAbsolutelyPositioned() &&
6426 !(aFCData
->mBits
& FCDATA_IS_TABLE_PART
)) {
6427 if (display
->mBreakBefore
) {
6428 ConstructPageBreakFrame(aState
, aContent
, aParentFrame
, aStyleContext
,
6431 return display
->mBreakAfter
;
6436 // aStyleContext is the style context of the frame for which we're
6437 // constructing the page break
6439 nsCSSFrameConstructor::ConstructPageBreakFrame(nsFrameConstructorState
& aState
,
6440 nsIContent
* aContent
,
6441 nsIFrame
* aParentFrame
,
6442 nsStyleContext
* aStyleContext
,
6443 nsFrameItems
& aFrameItems
)
6445 nsRefPtr
<nsStyleContext
> pseudoStyle
;
6446 // Use the same parent style context that |aStyleContext| has, since
6447 // that's easier to re-resolve and it doesn't matter in practice.
6448 // (Getting different parents can result in framechange hints, e.g.,
6449 // for user-modify.)
6450 pseudoStyle
= mPresShell
->StyleSet()->ResolvePseudoStyleFor(nsnull
,
6451 nsCSSAnonBoxes::pageBreak
, aStyleContext
->GetParent());
6452 nsIFrame
* pageBreakFrame
= NS_NewPageBreakFrame(mPresShell
, pseudoStyle
);
6453 if (pageBreakFrame
) {
6454 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, pageBreakFrame
);
6455 aFrameItems
.AddChild(pageBreakFrame
);
6460 return NS_ERROR_OUT_OF_MEMORY
;
6465 nsCSSFrameConstructor::ConstructFrame(nsFrameConstructorState
& aState
,
6466 nsIContent
* aContent
,
6467 nsIFrame
* aParentFrame
,
6468 nsFrameItems
& aFrameItems
)
6471 NS_PRECONDITION(nsnull
!= aParentFrame
, "no parent frame");
6473 nsresult rv
= NS_OK
;
6475 // don't create a whitespace frame if aParent doesn't want it
6476 if (!NeedFrameFor(aParentFrame
, aContent
)) {
6480 // never create frames for comments or PIs
6481 if (aContent
->IsNodeOfType(nsINode::eCOMMENT
) ||
6482 aContent
->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION
))
6485 nsRefPtr
<nsStyleContext
> styleContext
;
6486 styleContext
= ResolveStyleContext(aParentFrame
, aContent
);
6488 // construct the frame
6489 return ConstructFrameInternal(aState
, aContent
, aParentFrame
,
6490 aContent
->Tag(), aContent
->GetNameSpaceID(),
6491 styleContext
, aFrameItems
, PR_TRUE
, PR_TRUE
);
6496 nsCSSFrameConstructor::ConstructFrameInternal(nsFrameConstructorState
& aState
,
6497 nsIContent
* aContent
,
6498 nsIFrame
* aParentFrame
,
6500 PRInt32 aNameSpaceID
,
6501 nsStyleContext
* aStyleContext
,
6502 nsFrameItems
& aFrameItems
,
6503 PRBool aAllowXBLBase
,
6504 PRBool aAllowPageBreaks
)
6506 // The following code allows the user to specify the base tag
6507 // of an element using XBL. XUL and HTML objects (like boxes, menus, etc.)
6508 // can then be extended arbitrarily.
6509 const nsStyleDisplay
* display
= aStyleContext
->GetStyleDisplay();
6510 nsRefPtr
<nsStyleContext
> styleContext(aStyleContext
);
6511 nsAutoEnqueueBinding
binding(mDocument
);
6512 if (aAllowXBLBase
&& display
->mBinding
)
6514 // Ensure that our XBL bindings are installed.
6516 nsIXBLService
* xblService
= GetXBLService();
6518 return NS_ERROR_FAILURE
;
6520 PRBool resolveStyle
;
6522 nsresult rv
= xblService
->LoadBindings(aContent
, display
->mBinding
->mURI
,
6523 display
->mBinding
->mOriginPrincipal
,
6525 getter_AddRefs(binding
.mBinding
),
6531 styleContext
= ResolveStyleContext(aParentFrame
, aContent
);
6532 display
= styleContext
->GetStyleDisplay();
6533 aStyleContext
= styleContext
;
6536 aTag
= mDocument
->BindingManager()->ResolveTag(aContent
, &aNameSpaceID
);
6539 // Pre-check for display "none" - if we find that, don't create
6541 if (NS_STYLE_DISPLAY_NONE
== display
->mDisplay
) {
6542 aState
.mFrameManager
->SetUndisplayedContent(aContent
, styleContext
);
6546 PRBool isText
= aContent
->IsNodeOfType(nsINode::eTEXT
);
6547 // Try to find frame construction data for this content
6548 const FrameConstructionData
* data
;
6550 data
= FindTextData(aParentFrame
);
6553 // Nothing to do here; suppressed text inside SVG
6556 #endif /* MOZ_SVG */
6559 // Don't create frames for non-SVG element children of SVG elements.
6560 if (aNameSpaceID
!= kNameSpaceID_SVG
&&
6562 aParentFrame
->IsFrameOfType(nsIFrame::eSVG
) &&
6563 !aParentFrame
->IsFrameOfType(nsIFrame::eSVGForeignObject
)
6567 #endif /* MOZ_SVG */
6569 data
= FindHTMLData(aContent
, aTag
, aNameSpaceID
, aParentFrame
,
6572 data
= FindXULTagData(aContent
, aTag
, aNameSpaceID
, styleContext
);
6576 data
= FindMathMLData(aContent
, aTag
, aNameSpaceID
, styleContext
);
6581 data
= FindSVGData(aContent
, aTag
, aNameSpaceID
, aParentFrame
,
6584 #endif /* MOZ_SVG */
6586 // Now check for XUL display types
6588 data
= FindXULDisplayData(display
, aContent
, styleContext
);
6591 // And general display types
6593 data
= FindDisplayData(display
, aContent
);
6596 NS_ASSERTION(data
, "Should have frame construction data now");
6598 if (data
->mBits
& FCDATA_SUPPRESS_FRAME
) {
6603 if ((data
->mBits
& FCDATA_IS_POPUP
) &&
6604 aParentFrame
->GetType() != nsGkAtoms::menuFrame
&&
6605 !aState
.mPopupItems
.containingBlock
) {
6608 #endif /* MOZ_XUL */
6611 nsIFrame
* adjParentFrame
= aParentFrame
;
6612 nsFrameItems
* frameItems
= &aFrameItems
;
6613 PRBool pseudoParent
= PR_FALSE
;
6614 PRBool suppressFrame
= PR_FALSE
;
6615 nsFrameConstructorSaveState pseudoSaveState
;
6616 nsresult rv
= AdjustParentFrame(aState
, aContent
, adjParentFrame
,
6617 data
, aNameSpaceID
, display
, frameItems
,
6618 pseudoSaveState
, suppressFrame
, pseudoParent
);
6619 if (NS_FAILED(rv
) || suppressFrame
) {
6624 return ConstructTextFrame(data
, aState
, aContent
, adjParentFrame
,
6625 styleContext
, *frameItems
, pseudoParent
);
6628 // If the page contains markup that overrides text direction, and
6629 // does not contain any characters that would activate the Unicode
6630 // bidi algorithm, we need to call |SetBidiEnabled| on the pres
6631 // context before reflow starts. This requires us to resolve some
6632 // style information now. See bug 115921.
6634 if (styleContext
->GetStyleVisibility()->mDirection
==
6635 NS_STYLE_DIRECTION_RTL
)
6636 aState
.mPresContext
->SetBidiEnabled();
6638 // Start background loads during frame construction. This is just
6639 // a hint; the paint code will do the right thing in any case.
6641 styleContext
->GetStyleBackground();
6644 // Construct a page break frame for page-break-before, if needed, and
6645 // remember whether we need one for page-break-after.
6646 PRBool pageBreakAfter
=
6648 aState
.mPresContext
->IsPaginated() &&
6649 PageBreakBefore(aState
, aContent
, adjParentFrame
, styleContext
, data
,
6652 rv
= ConstructFrameFromData(data
, aState
, aContent
, adjParentFrame
, aTag
,
6653 aNameSpaceID
, styleContext
, *frameItems
,
6656 if (NS_SUCCEEDED(rv
) && pageBreakAfter
) {
6657 // Construct the page break after
6658 ConstructPageBreakFrame(aState
, aContent
, adjParentFrame
, styleContext
,
6667 IsRootBoxFrame(nsIFrame
*aFrame
)
6669 return (aFrame
->GetType() == nsGkAtoms::rootFrame
);
6673 nsCSSFrameConstructor::ReconstructDocElementHierarchy()
6675 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
6676 return ReconstructDocElementHierarchyInternal();
6680 nsCSSFrameConstructor::ReconstructDocElementHierarchyInternal()
6683 if (gNoisyContentUpdates
) {
6684 printf("nsCSSFrameConstructor::ReconstructDocElementHierarchy\n");
6688 nsresult rv
= NS_OK
;
6690 // XXXbz is that null-check needed? Why?
6691 if (mDocument
&& mPresShell
) {
6692 nsIContent
*rootContent
= mDocument
->GetRootContent();
6695 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
6696 nsnull
, nsnull
, mTempFrameTreeState
);
6698 // Before removing the frames associated with the content object, ask them to save their
6699 // state onto a temporary state object.
6700 CaptureStateFor(state
.mFrameManager
->GetRootFrame(), mTempFrameTreeState
);
6702 // Get the frame that corresponds to the document element
6703 nsIFrame
* docElementFrame
=
6704 state
.mFrameManager
->GetPrimaryFrameFor(rootContent
, -1);
6706 if (docElementFrame
) {
6707 // Destroy out-of-flow frames that might not be in the frame subtree
6708 // rooted at docElementFrame
6709 ::DeletingFrameSubtree(state
.mFrameManager
, docElementFrame
);
6711 state
.mFrameManager
->ClearUndisplayedContentIn(rootContent
, nsnull
);
6714 // Remove any existing fixed items: they are always on the
6715 // FixedContainingBlock. Note that this has to be done before we call
6716 // ClearPlaceholderFrameMap(), since RemoveFixedItems uses the
6717 // placeholder frame map.
6718 rv
= RemoveFixedItems(state
, docElementFrame
);
6720 if (NS_SUCCEEDED(rv
)) {
6721 nsPlaceholderFrame
* placeholderFrame
= nsnull
;
6722 if (docElementFrame
&&
6723 (docElementFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)) {
6724 // Get the placeholder frame now, before we tear down the
6725 // placeholder frame map
6727 state
.mFrameManager
->GetPlaceholderFrameFor(docElementFrame
);
6728 NS_ASSERTION(placeholderFrame
, "No placeholder for out-of-flow?");
6731 // Clear the hash tables that map from content to frame and out-of-flow
6732 // frame to placeholder frame
6733 state
.mFrameManager
->ClearPrimaryFrameMap();
6734 state
.mFrameManager
->ClearPlaceholderFrameMap();
6735 state
.mFrameManager
->ClearUndisplayedContentMap();
6737 if (docElementFrame
) {
6738 // Take the docElementFrame, and remove it from its parent.
6739 // XXXbz So why can't we reuse ContentRemoved?
6741 // Notify self that we will destroy the entire frame tree, this blocks
6742 // RemoveMappingsForFrameSubtree() which would otherwise lead to a
6743 // crash since we cleared the placeholder map above (bug 398982).
6744 PRBool wasDestroyingFrameTree
= mIsDestroyingFrameTree
;
6745 WillDestroyFrameTree(PR_FALSE
);
6747 rv
= state
.mFrameManager
->RemoveFrame(docElementFrame
->GetParent(),
6748 GetChildListNameFor(docElementFrame
), docElementFrame
);
6750 if (placeholderFrame
) {
6751 // Remove the placeholder frame first (XXX second for now) (so
6752 // that it doesn't retain a dangling pointer to memory)
6753 rv
|= state
.mFrameManager
->RemoveFrame(placeholderFrame
->GetParent(),
6754 nsnull
, placeholderFrame
);
6757 mIsDestroyingFrameTree
= wasDestroyingFrameTree
;
6758 if (NS_FAILED(rv
)) {
6765 if (rootContent
&& NS_SUCCEEDED(rv
)) {
6766 mRootElementFrame
= nsnull
;
6767 mRootElementStyleFrame
= nsnull
;
6769 // We don't reuse the old frame constructor state because,
6770 // for example, its mPopupItems may be stale
6771 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
6772 nsnull
, nsnull
, mTempFrameTreeState
);
6774 // Create the new document element hierarchy
6776 rv
= ConstructDocElementFrame(state
, rootContent
,
6777 mDocElementContainingBlock
, &newChild
);
6779 // newChild could be null even if |rv| is success, thanks to XBL.
6780 if (NS_SUCCEEDED(rv
) && newChild
) {
6781 rv
= state
.mFrameManager
->InsertFrames(mDocElementContainingBlock
,
6782 nsnull
, nsnull
, newChild
);
6792 nsCSSFrameConstructor::GetFrameFor(nsIContent
* aContent
)
6794 // Get the primary frame associated with the content
6795 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
6800 nsIFrame
* insertionFrame
= frame
->GetContentInsertionFrame();
6802 NS_ASSERTION(insertionFrame
== frame
|| !frame
->IsLeaf(),
6803 "The insertion frame is the primary frame or the primary frame isn't a leaf");
6805 return insertionFrame
;
6809 nsCSSFrameConstructor::GetAbsoluteContainingBlock(nsIFrame
* aFrame
)
6811 NS_PRECONDITION(nsnull
!= mRootElementFrame
, "no root element frame");
6813 // Starting with aFrame, look for a frame that is absolutely positioned or
6814 // relatively positioned
6815 nsIFrame
* containingBlock
= nsnull
;
6816 for (nsIFrame
* frame
= aFrame
; frame
&& !containingBlock
;
6817 frame
= frame
->GetParent()) {
6818 if (frame
->IsFrameOfType(nsIFrame::eMathML
)) {
6819 // If it's mathml, bail out -- no absolute positioning out from inside
6820 // mathml frames. Note that we don't make this part of the loop
6821 // condition because of the stuff at the end of this method...
6825 // Is it positioned?
6826 // If it's table-related then ignore it, because for the time
6827 // being table-related frames are not containers for absolutely
6828 // positioned child frames.
6829 const nsStyleDisplay
* disp
= frame
->GetStyleDisplay();
6831 if (disp
->IsPositioned() && !IsTableRelated(frame
->GetType(), PR_TRUE
)) {
6832 // Find the outermost wrapped block under this frame
6833 for (nsIFrame
* wrappedFrame
= aFrame
; wrappedFrame
!= frame
->GetParent();
6834 wrappedFrame
= wrappedFrame
->GetParent()) {
6835 nsIAtom
* frameType
= wrappedFrame
->GetType();
6836 if (nsGkAtoms::blockFrame
== frameType
||
6838 nsGkAtoms::XULLabelFrame
== frameType
||
6840 nsGkAtoms::positionedInlineFrame
== frameType
) {
6841 containingBlock
= wrappedFrame
;
6842 } else if (nsGkAtoms::fieldSetFrame
== frameType
) {
6843 // If the positioned frame is a fieldset, use the area frame inside it.
6844 // We don't use GetContentInsertionFrame for fieldsets yet.
6845 containingBlock
= GetFieldSetBlockFrame(wrappedFrame
);
6850 if (!containingBlock
)
6851 NS_WARNING("Positioned frame that does not handle positioned kids; looking further up the parent chain");
6856 // If we found an absolutely positioned containing block, then use the
6857 // first-continuation.
6858 if (containingBlock
)
6859 return AdjustAbsoluteContainingBlock(containingBlock
);
6861 // If we didn't find it, then use the document element containing block
6862 return mHasRootAbsPosContainingBlock
? mDocElementContainingBlock
: nsnull
;
6866 nsCSSFrameConstructor::GetFloatContainingBlock(nsIFrame
* aFrame
)
6868 NS_PRECONDITION(mRootElementFrame
, "no root element frame");
6870 // Starting with aFrame, look for a frame that is a float containing block.
6871 // IF we hit a mathml frame, bail out; we don't allow floating out of mathml
6872 // frames, because they don't seem to be able to deal.
6873 // The logic here needs to match the logic in ProcessChildren()
6874 for (nsIFrame
* containingBlock
= aFrame
;
6875 containingBlock
&& !containingBlock
->IsFrameOfType(nsIFrame::eMathML
) &&
6876 !containingBlock
->IsBoxFrame();
6877 containingBlock
= containingBlock
->GetParent()) {
6878 if (containingBlock
->IsFloatContainingBlock()) {
6879 return containingBlock
;
6883 // If we didn't find a containing block, then there just isn't
6884 // one.... return null
6889 * This function will check whether aContainer has :after generated content.
6890 * If so, appending to it should actually insert. The return value is the
6891 * parent to use for newly-appended content. *aAfterFrame points to the :after
6892 * frame before which appended content should go, if there is one.
6895 AdjustAppendParentForAfterContent(nsPresContext
* aPresContext
,
6896 nsIContent
* aContainer
,
6897 nsIFrame
* aParentFrame
,
6898 nsIFrame
** aAfterFrame
)
6900 // See if the parent has an :after pseudo-element. Check for the presence
6901 // of style first, since nsLayoutUtils::GetAfterFrame is sorta expensive.
6902 nsStyleContext
* parentStyle
= aParentFrame
->GetStyleContext();
6903 if (nsLayoutUtils::HasPseudoStyle(aContainer
, parentStyle
,
6904 nsCSSPseudoElements::after
,
6906 nsIFrame
* afterFrame
= nsLayoutUtils::GetAfterFrame(aParentFrame
);
6908 *aAfterFrame
= afterFrame
;
6909 return afterFrame
->GetParent();
6913 *aAfterFrame
= nsnull
;
6914 return aParentFrame
;
6918 * This function is called by ContentAppended() and ContentInserted()
6919 * when appending flowed frames to a parent's principal child list. It
6920 * handles the case where the parent frame has :after pseudo-element
6921 * generated content.
6924 nsCSSFrameConstructor::AppendFrames(nsFrameConstructorState
& aState
,
6925 nsIContent
* aContainer
,
6926 nsIFrame
* aParentFrame
,
6927 nsFrameItems
& aFrameList
,
6928 nsIFrame
* aAfterFrame
)
6931 nsIFrame
* debugAfterFrame
;
6932 nsIFrame
* debugNewParent
=
6933 ::AdjustAppendParentForAfterContent(aState
.mPresContext
, aContainer
,
6934 aParentFrame
, &debugAfterFrame
);
6935 NS_ASSERTION(debugNewParent
== aParentFrame
, "Incorrect parent");
6936 NS_ASSERTION(debugAfterFrame
== aAfterFrame
, "Incorrect after frame");
6939 nsFrameManager
* frameManager
= aState
.mFrameManager
;
6941 NS_ASSERTION(!IsFrameSpecial(aParentFrame
) ||
6942 IsInlineFrame(aParentFrame
) ||
6943 !IsInlineOutside(aAfterFrame
),
6944 "Shouldn't have inline :after content on the block in an "
6946 nsFrameList
frames(aParentFrame
->GetFirstChild(nsnull
));
6948 // Insert the frames before the :after pseudo-element.
6949 return frameManager
->InsertFrames(aParentFrame
, nsnull
,
6950 frames
.GetPrevSiblingFor(aAfterFrame
),
6951 aFrameList
.childList
);
6954 if (IsFrameSpecial(aParentFrame
) &&
6955 !IsInlineFrame(aParentFrame
) &&
6956 IsInlineOutside(aFrameList
.lastChild
)) {
6957 NS_ASSERTION(!aParentFrame
->GetNextContinuation() ||
6958 !aParentFrame
->GetNextContinuation()->GetFirstChild(nsnull
),
6959 "Shouldn't happen");
6961 // We want to put some of the frames into the following inline frame.
6962 nsIFrame
* lastBlock
= FindLastBlock(aFrameList
.childList
);
6963 nsIFrame
* firstTrailingInline
;
6965 firstTrailingInline
= lastBlock
->GetNextSibling();
6966 lastBlock
->SetNextSibling(nsnull
);
6967 aFrameList
.lastChild
= lastBlock
;
6969 firstTrailingInline
= aFrameList
.childList
;
6970 aFrameList
= nsFrameItems();
6973 NS_ASSERTION(firstTrailingInline
, "How did that happen?");
6974 nsIFrame
* parentFrame
= aParentFrame
;
6976 // As we go up the tree creating trailing inlines, we have to move floats
6977 // up to ancestor blocks. This means that at any given time we'll be
6978 // working with two frame constructor states, and aState is one of the two
6979 // only at the first step. Create some space to do this so we don't have
6980 // to allocate as we go.
6981 char stateBuf
[2 * sizeof(nsFrameConstructorState
)];
6982 nsFrameConstructorState
* sourceState
= &aState
;
6983 nsFrameConstructorState
* targetState
=
6984 reinterpret_cast<nsFrameConstructorState
*>(stateBuf
);
6986 // Now we loop, because it might be the case that the parent of our special
6987 // block is another special block, and that we're at the very end of it,
6988 // and in that case if we create a new special inline we'll have to create
6989 // a parent for it too.
6991 NS_ASSERTION(IsFrameSpecial(parentFrame
) && !IsInlineFrame(parentFrame
),
6992 "Shouldn't be in this code");
6993 nsIFrame
* inlineSibling
= GetSpecialSibling(parentFrame
);
6994 PRBool isPositioned
= PR_FALSE
;
6995 nsIContent
* content
= nsnull
;
6996 nsStyleContext
* styleContext
= nsnull
;
6997 if (!inlineSibling
) {
6998 nsIFrame
* firstInline
=
6999 GetIBSplitSpecialPrevSiblingForAnonymousBlock(parentFrame
);
7000 NS_ASSERTION(firstInline
, "How did that happen?");
7002 content
= firstInline
->GetContent();
7003 styleContext
= firstInline
->GetStyleContext();
7004 isPositioned
= (styleContext
->GetStyleDisplay()->mPosition
==
7005 NS_STYLE_POSITION_RELATIVE
);
7008 nsIFrame
* stateParent
=
7009 inlineSibling
? inlineSibling
->GetParent() : parentFrame
->GetParent();
7012 nsFrameConstructorState(mPresShell
, mFixedContainingBlock
,
7013 GetAbsoluteContainingBlock(stateParent
),
7014 GetFloatContainingBlock(stateParent
));
7015 nsIFrame
* newInlineSibling
=
7016 MoveFramesToEndOfIBSplit(*sourceState
, inlineSibling
,
7017 isPositioned
, content
,
7018 styleContext
, firstTrailingInline
,
7019 parentFrame
, targetState
);
7021 if (sourceState
== &aState
) {
7022 NS_ASSERTION(targetState
==
7023 reinterpret_cast<nsFrameConstructorState
*>(stateBuf
),
7024 "Bogus target state?");
7025 // Set sourceState to the value targetState should have next.
7026 sourceState
= targetState
+ 1;
7028 // Go ahead and process whatever insertions we didn't move out
7029 sourceState
->~nsFrameConstructorState();
7032 // We're done with the source state. The target becomes the new source,
7033 // and we point the target pointer to the available memory.
7034 nsFrameConstructorState
* temp
= sourceState
;
7035 sourceState
= targetState
;
7036 targetState
= temp
;;
7038 if (inlineSibling
) {
7039 // we're all set -- we just moved things to a frame that was already
7041 NS_ASSERTION(newInlineSibling
== inlineSibling
, "What happened?");
7045 SetFrameIsSpecial(parentFrame
->GetFirstContinuation(), newInlineSibling
);
7047 // We had to create a frame for this new inline sibling. Figure out
7048 // the right parentage for it.
7049 // XXXbz add a test for this?
7050 nsIFrame
* newParentFrame
= parentFrame
->GetParent();
7051 NS_ASSERTION(!IsInlineFrame(newParentFrame
),
7052 "The block in an {ib} split shouldn't be living inside "
7054 if (!IsFrameSpecial(newParentFrame
) ||
7055 newParentFrame
->GetNextContinuation() ||
7056 parentFrame
->GetNextSibling()) {
7057 // Just insert after parentFrame
7058 frameManager
->InsertFrames(newParentFrame
, nsnull
, parentFrame
,
7060 firstTrailingInline
= nsnull
;
7062 // recurse up the tree
7063 parentFrame
= newParentFrame
;
7064 firstTrailingInline
= newInlineSibling
;
7066 } while (firstTrailingInline
);
7068 // Process the float insertions on the last target state we had.
7069 sourceState
->~nsFrameConstructorState();
7072 if (!aFrameList
.childList
) {
7073 // It all got eaten by the special inline
7077 return frameManager
->AppendFrames(aParentFrame
, nsnull
,
7078 aFrameList
.childList
);
7081 #define UNSET_DISPLAY 255
7083 // This gets called to see if the frames corresponding to aSiblingDisplay and aDisplay
7084 // should be siblings in the frame tree. Although (1) rows and cols, (2) row groups
7085 // and col groups, (3) row groups and captions, (4) legends and content inside fieldsets, (5) popups and other kids of the menu
7086 // are siblings from a content perspective, they are not considered siblings in the
7089 nsCSSFrameConstructor::IsValidSibling(nsIFrame
* aSibling
,
7090 nsIContent
* aContent
,
7093 nsIFrame
* parentFrame
= aSibling
->GetParent();
7094 nsIAtom
* parentType
= nsnull
;
7095 nsIAtom
* grandparentType
= nsnull
;
7097 parentType
= parentFrame
->GetType();
7098 nsIFrame
* grandparentFrame
= parentFrame
->GetParent();
7099 if (grandparentFrame
) {
7100 grandparentType
= grandparentFrame
->GetType();
7104 PRUint8 siblingDisplay
= aSibling
->GetStyleDisplay()->mDisplay
;
7105 if ((NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
== siblingDisplay
) ||
7106 (NS_STYLE_DISPLAY_TABLE_COLUMN
== siblingDisplay
) ||
7107 (NS_STYLE_DISPLAY_TABLE_CAPTION
== siblingDisplay
) ||
7108 (NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
== siblingDisplay
) ||
7109 (NS_STYLE_DISPLAY_TABLE_ROW_GROUP
== siblingDisplay
) ||
7110 (NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
== siblingDisplay
) ||
7111 nsGkAtoms::menuFrame
== parentType
) {
7112 // if we haven't already, construct a style context to find the display type of aContent
7113 if (UNSET_DISPLAY
== aDisplay
) {
7114 nsRefPtr
<nsStyleContext
> styleContext
;
7115 nsIFrame
* styleParent
;
7116 PRBool providerIsChild
;
7117 if (NS_FAILED(aSibling
->
7118 GetParentStyleContextFrame(aSibling
->PresContext(),
7120 &providerIsChild
)) ||
7122 NS_NOTREACHED("Shouldn't happen");
7125 styleContext
= ResolveStyleContext(styleParent
, aContent
);
7126 if (!styleContext
) return PR_FALSE
;
7127 const nsStyleDisplay
* display
= styleContext
->GetStyleDisplay();
7128 aDisplay
= display
->mDisplay
;
7130 if (nsGkAtoms::menuFrame
== parentType
) {
7132 (NS_STYLE_DISPLAY_POPUP
== aDisplay
) ==
7133 (NS_STYLE_DISPLAY_POPUP
== siblingDisplay
);
7135 switch (siblingDisplay
) {
7136 case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
:
7137 return (NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP
== aDisplay
);
7138 case NS_STYLE_DISPLAY_TABLE_COLUMN
:
7139 return (NS_STYLE_DISPLAY_TABLE_COLUMN
== aDisplay
);
7140 case NS_STYLE_DISPLAY_TABLE_CAPTION
:
7141 return (NS_STYLE_DISPLAY_TABLE_CAPTION
== aDisplay
);
7142 default: // all of the row group types
7143 return (NS_STYLE_DISPLAY_TABLE_HEADER_GROUP
== aDisplay
) ||
7144 (NS_STYLE_DISPLAY_TABLE_ROW_GROUP
== aDisplay
) ||
7145 (NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP
== aDisplay
) ||
7146 (NS_STYLE_DISPLAY_TABLE_CAPTION
== aDisplay
);
7149 else if (nsGkAtoms::fieldSetFrame
== parentType
||
7150 (nsGkAtoms::fieldSetFrame
== grandparentType
&&
7151 nsGkAtoms::blockFrame
== parentType
)) {
7152 // Legends can be sibling of legends but not of other content in the fieldset
7153 nsIAtom
* sibType
= aSibling
->GetType();
7154 nsCOMPtr
<nsIDOMHTMLLegendElement
> legendContent(do_QueryInterface(aContent
));
7156 if ((legendContent
&& (nsGkAtoms::legendFrame
!= sibType
)) ||
7157 (!legendContent
&& (nsGkAtoms::legendFrame
== sibType
)))
7165 nsCSSFrameConstructor::FindFrameForContentSibling(nsIContent
* aContent
,
7166 nsIContent
* aTargetContent
,
7167 PRUint8
& aTargetContentDisplay
,
7168 PRBool aPrevSibling
)
7170 nsIFrame
* sibling
= mPresShell
->GetPrimaryFrameFor(aContent
);
7175 // If the frame is out-of-flow, GPFF() will have returned the
7176 // out-of-flow frame; we want the placeholder.
7177 if (sibling
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
7178 nsIFrame
* placeholderFrame
;
7179 mPresShell
->GetPlaceholderFrameFor(sibling
, &placeholderFrame
);
7180 NS_ASSERTION(placeholderFrame
, "no placeholder for out-of-flow frame");
7181 sibling
= placeholderFrame
;
7184 // The frame we have now should never be a continuation
7185 NS_ASSERTION(!sibling
->GetPrevContinuation(), "How did that happen?");
7188 // The frame may be a special frame (a split inline frame that
7189 // contains a block). Get the last part of that split.
7190 if (IsFrameSpecial(sibling
)) {
7191 sibling
= GetLastSpecialSibling(sibling
);
7194 // The frame may have a continuation. If so, we want the last
7195 // non-overflow-container continuation as our previous sibling.
7196 sibling
= sibling
->GetTailContinuation();
7199 if (aTargetContent
&&
7200 !IsValidSibling(sibling
, aTargetContent
, aTargetContentDisplay
)) {
7208 nsCSSFrameConstructor::FindPreviousSibling(const ChildIterator
& aFirst
,
7209 ChildIterator aIter
)
7211 nsIContent
* child
= *aIter
;
7213 PRUint8 childDisplay
= UNSET_DISPLAY
;
7214 // Note: not all content objects are associated with a frame (e.g., if it's
7215 // `display: none') so keep looking until we find a previous frame
7216 while (aIter
-- != aFirst
) {
7217 nsIFrame
* prevSibling
=
7218 FindFrameForContentSibling(*aIter
, child
, childDisplay
, PR_TRUE
);
7221 // Found a previous sibling, we're done!
7230 nsCSSFrameConstructor::FindNextSibling(ChildIterator aIter
,
7231 const ChildIterator
& aLast
)
7233 if (aIter
== aLast
) {
7234 // XXXbz Can happen when XBL lies to us about insertion points. This check
7235 // might be able to go away once bug 474324 is fixed.
7239 nsIContent
* child
= *aIter
;
7240 PRUint8 childDisplay
= UNSET_DISPLAY
;
7242 while (++aIter
!= aLast
) {
7243 nsIFrame
* nextSibling
=
7244 FindFrameForContentSibling(*aIter
, child
, childDisplay
, PR_FALSE
);
7247 // We found a next sibling, we're done!
7255 // For fieldsets, returns the area frame, if the child is not a legend.
7257 GetAdjustedParentFrame(nsIFrame
* aParentFrame
,
7258 nsIAtom
* aParentFrameType
,
7259 nsIContent
* aChildContent
)
7261 NS_PRECONDITION(nsGkAtoms::tableOuterFrame
!= aParentFrameType
,
7262 "Shouldn't be happening!");
7264 nsIFrame
* newParent
= nsnull
;
7266 if (nsGkAtoms::fieldSetFrame
== aParentFrameType
) {
7267 // If the parent is a fieldSet, use the fieldSet's area frame as the
7268 // parent unless the new content is a legend.
7269 nsCOMPtr
<nsIDOMHTMLLegendElement
> legendContent(do_QueryInterface(aChildContent
));
7270 if (!legendContent
) {
7271 newParent
= GetFieldSetBlockFrame(aParentFrame
);
7274 return (newParent
) ? newParent
: aParentFrame
;
7278 InvalidateCanvasIfNeeded(nsIFrame
* aFrame
);
7281 IsSpecialFramesetChild(nsIContent
* aContent
)
7283 // IMPORTANT: This must match the conditions in nsHTMLFramesetFrame::Init.
7284 return aContent
->IsNodeOfType(nsINode::eHTML
) &&
7285 (aContent
->Tag() == nsGkAtoms::frameset
||
7286 aContent
->Tag() == nsGkAtoms::frame
);
7290 nsCSSFrameConstructor::ContentAppended(nsIContent
* aContainer
,
7291 PRInt32 aNewIndexInContainer
)
7293 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
7294 NS_PRECONDITION(mUpdateCount
!= 0,
7295 "Should be in an update while creating frames");
7298 if (gNoisyContentUpdates
) {
7299 printf("nsCSSFrameConstructor::ContentAppended container=%p index=%d\n",
7300 static_cast<void*>(aContainer
), aNewIndexInContainer
);
7301 if (gReallyNoisyContentUpdates
&& aContainer
) {
7302 aContainer
->List(stdout
, 0);
7309 PRInt32 namespaceID
;
7311 mDocument
->BindingManager()->ResolveTag(aContainer
, &namespaceID
);
7313 // Just ignore tree tags, anyway we don't create any frames for them.
7314 if (tag
== nsGkAtoms::treechildren
||
7315 tag
== nsGkAtoms::treeitem
||
7316 tag
== nsGkAtoms::treerow
)
7322 // Get the frame associated with the content
7323 nsIFrame
* parentFrame
= GetFrameFor(aContainer
);
7327 // See if we have an XBL insertion point. If so, then that's our
7328 // real parent frame; if not, then the frame hasn't been built yet
7329 // and we just bail.
7331 nsIFrame
* insertionPoint
;
7332 PRBool multiple
= PR_FALSE
;
7333 GetInsertionPoint(parentFrame
, nsnull
, &insertionPoint
, &multiple
);
7334 if (! insertionPoint
)
7335 return NS_OK
; // Don't build the frames.
7337 PRBool hasInsertion
= PR_FALSE
;
7339 nsIDocument
* document
= nsnull
;
7340 nsIContent
*firstAppendedChild
=
7341 aContainer
->GetChildAt(aNewIndexInContainer
);
7342 if (firstAppendedChild
) {
7343 document
= firstAppendedChild
->GetDocument();
7346 document
->BindingManager()->GetInsertionParent(firstAppendedChild
)) {
7347 hasInsertion
= PR_TRUE
;
7351 if (multiple
|| hasInsertion
) {
7352 // We have an insertion point. There are some additional tests we need to do
7353 // in order to ensure that an append is a safe operation.
7354 PRUint32 childCount
= 0;
7357 // We may need to make multiple ContentInserted calls instead. A
7358 // reasonable heuristic to employ (in order to maintain good performance)
7359 // is to find out if the insertion point's content node contains any
7360 // explicit children. If it does not, then it is highly likely that
7361 // an append is occurring. (Note it is not definite, and there are insane
7362 // cases we will not deal with by employing this heuristic, but it beats
7363 // always falling back to multiple ContentInserted calls).
7365 // In the multiple insertion point case, we know we're going to need to do
7366 // multiple ContentInserted calls anyway.
7367 childCount
= insertionPoint
->GetContent()->GetChildCount();
7370 if (multiple
|| childCount
> 0) {
7371 // Now comes the fun part. For each appended child, make a
7372 // ContentInserted call as if it had just gotten inserted at the index
7373 // it's at in aContainer and let ContentInserted handle the mess. If our
7374 // insertion point is non-XBL that's the correct index, and otherwise
7375 // ContentInserted will ignore the passed-in index.
7376 PRUint32 containerCount
= aContainer
->GetChildCount();
7377 for (PRUint32 i
= aNewIndexInContainer
; i
< containerCount
; i
++) {
7378 LAYOUT_PHASE_TEMP_EXIT();
7379 // Call ContentInserted with this index.
7380 ContentInserted(aContainer
, aContainer
->GetChildAt(i
), i
,
7381 mTempFrameTreeState
);
7382 LAYOUT_PHASE_TEMP_REENTER();
7389 parentFrame
= insertionPoint
;
7391 if (parentFrame
->GetType() == nsGkAtoms::frameSetFrame
) {
7392 // Check whether we have any kids we care about.
7393 PRUint32 count
= aContainer
->GetChildCount();
7394 for (PRUint32 i
= aNewIndexInContainer
; i
< count
; ++i
) {
7395 if (IsSpecialFramesetChild(aContainer
->GetChildAt(i
))) {
7396 // Just reframe the parent, since framesets are weird like that.
7397 return RecreateFramesForContent(parentFrame
->GetContent());
7402 if (parentFrame
->IsLeaf()) {
7403 // Nothing to do here; we shouldn't be constructing kids of leaves
7408 if (parentFrame
->IsFrameOfType(nsIFrame::eMathML
))
7409 return RecreateFramesForContent(parentFrame
->GetContent());
7412 // If the frame we are manipulating is a ``special'' frame (that is, one
7413 // that's been created as a result of a block-in-inline situation) then we
7414 // need to append to the last special sibling, not to the frame itself.
7415 if (IsFrameSpecial(parentFrame
)) {
7417 if (gNoisyContentUpdates
) {
7418 printf("nsCSSFrameConstructor::ContentAppended: parentFrame=");
7419 nsFrame::ListTag(stdout
, parentFrame
);
7420 printf(" is special\n");
7424 // Since we're appending, we'll walk to the last anonymous frame
7425 // that was created for the broken inline frame.
7426 parentFrame
= GetLastSpecialSibling(parentFrame
);
7429 // Get continuation that parents the last child
7430 parentFrame
= nsLayoutUtils::GetLastContinuationWithChild(parentFrame
);
7432 nsIAtom
* frameType
= parentFrame
->GetType();
7433 // We should never get here with fieldsets, since they have multiple
7434 // insertion points.
7435 NS_ASSERTION(frameType
!= nsGkAtoms::fieldSetFrame
,
7436 "Unexpected parent");
7438 // Deal with possible :after generated content on the parent
7439 nsIFrame
* parentAfterFrame
;
7441 ::AdjustAppendParentForAfterContent(mPresShell
->GetPresContext(),
7442 aContainer
, parentFrame
,
7445 // Create some new frames
7447 nsFrameItems frameItems
;
7448 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
7449 GetAbsoluteContainingBlock(parentFrame
),
7450 GetFloatContainingBlock(parentFrame
));
7452 // See if the containing block has :first-letter style applied.
7453 PRBool haveFirstLetterStyle
= PR_FALSE
, haveFirstLineStyle
= PR_FALSE
;
7454 nsIFrame
* containingBlock
= state
.mFloatedItems
.containingBlock
;
7455 if (containingBlock
) {
7456 haveFirstLetterStyle
= HasFirstLetterStyle(containingBlock
);
7457 haveFirstLineStyle
=
7458 ShouldHaveFirstLineStyle(containingBlock
->GetContent(),
7459 containingBlock
->GetStyleContext());
7462 if (haveFirstLetterStyle
) {
7463 // Before we get going, remove the current letter frames
7464 RemoveLetterFrames(state
.mPresContext
, state
.mPresShell
,
7465 state
.mFrameManager
, containingBlock
);
7468 // if the container is a table and a caption was appended, it needs to be put in
7469 // the outer table frame's additional child list.
7470 nsFrameItems captionItems
;
7472 // The last frame that we added to the list.
7473 nsIFrame
* oldNewFrame
= nsnull
;
7476 count
= aContainer
->GetChildCount();
7477 for (i
= aNewIndexInContainer
; i
< count
; i
++) {
7478 nsIFrame
* newFrame
= nsnull
;
7479 nsIContent
*childContent
= aContainer
->GetChildAt(i
);
7481 ConstructFrame(state
, childContent
, parentFrame
, frameItems
);
7482 newFrame
= frameItems
.lastChild
;
7484 if (newFrame
&& newFrame
!= oldNewFrame
) {
7485 InvalidateCanvasIfNeeded(newFrame
);
7486 oldNewFrame
= newFrame
;
7490 if (nsGkAtoms::tableFrame
== frameType
) {
7491 // Pull out the captions. Note that we don't want to do that as we go,
7492 // because processing a single caption can add a whole bunch of things to
7493 // the frame items due to pseudoframe processing. So we'd have to pull
7494 // captions from a list anyway; might as well do that here.
7495 PullOutCaptionFrames(frameItems
, captionItems
);
7499 // process the current pseudo frame state
7500 if (!state
.mPseudoFrames
.IsEmpty()) {
7501 ProcessPseudoFrames(state
, frameItems
);
7504 if (haveFirstLineStyle
&& parentFrame
== containingBlock
) {
7505 // It's possible that some of the new frames go into a
7506 // first-line frame. Look at them and see...
7507 AppendFirstLineFrames(state
, containingBlock
->GetContent(),
7508 containingBlock
, frameItems
);
7511 nsresult result
= NS_OK
;
7513 // Notify the parent frame passing it the list of new frames
7514 if (NS_SUCCEEDED(result
) &&
7515 (frameItems
.childList
|| captionItems
.childList
)) {
7516 // Perform special check for diddling around with the frames in
7517 // a special inline frame.
7519 // If we're appending before :after content, then we're not really
7520 // appending, so let WipeContainingBlock know that.
7521 if (WipeContainingBlock(state
, containingBlock
, parentFrame
, frameItems
,
7522 !parentAfterFrame
, nsnull
)) {
7526 // Append the flowed frames to the principal child list, tables need special treatment
7527 if (nsGkAtoms::tableFrame
== frameType
) {
7528 if (captionItems
.childList
) { // append the caption to the outer table
7529 nsIFrame
* outerTable
= parentFrame
->GetParent();
7531 state
.mFrameManager
->AppendFrames(outerTable
,
7532 nsGkAtoms::captionList
,
7533 captionItems
.childList
);
7536 if (frameItems
.childList
) { // append children of the inner table
7537 AppendFrames(state
, aContainer
, parentFrame
, frameItems
,
7542 AppendFrames(state
, aContainer
, parentFrame
, frameItems
,
7547 // Recover first-letter frames
7548 if (haveFirstLetterStyle
) {
7549 RecoverLetterFrames(containingBlock
);
7553 if (gReallyNoisyContentUpdates
) {
7554 nsIFrameDebug
* fdbg
= do_QueryFrame(parentFrame
);
7556 printf("nsCSSFrameConstructor::ContentAppended: resulting frame model:\n");
7557 fdbg
->List(stdout
, 0);
7567 enum content_operation
7573 // Helper function to lookup the listbox body frame and send a notification
7574 // for insertion or removal of content
7576 PRBool
NotifyListBoxBody(nsPresContext
* aPresContext
,
7577 nsIContent
* aContainer
,
7579 PRInt32 aIndexInContainer
,
7580 nsIDocument
* aDocument
,
7581 nsIFrame
* aChildFrame
,
7582 content_operation aOperation
)
7587 if (aContainer
->IsNodeOfType(nsINode::eXUL
) &&
7588 aChild
->IsNodeOfType(nsINode::eXUL
) &&
7589 aContainer
->Tag() == nsGkAtoms::listbox
&&
7590 aChild
->Tag() == nsGkAtoms::listitem
) {
7591 nsCOMPtr
<nsIDOMXULElement
> xulElement
= do_QueryInterface(aContainer
);
7592 nsCOMPtr
<nsIBoxObject
> boxObject
;
7593 xulElement
->GetBoxObject(getter_AddRefs(boxObject
));
7594 nsCOMPtr
<nsPIListBoxObject
> listBoxObject
= do_QueryInterface(boxObject
);
7595 if (listBoxObject
) {
7596 nsListBoxBodyFrame
* listBoxBodyFrame
= listBoxObject
->GetListBoxBody(PR_FALSE
);
7597 if (listBoxBodyFrame
) {
7598 if (aOperation
== CONTENT_REMOVED
) {
7599 // Except if we have an aChildFrame and its parent is not the right
7600 // thing, then we don't do this. Pseudo frames are so much fun....
7601 if (!aChildFrame
|| aChildFrame
->GetParent() == listBoxBodyFrame
) {
7602 listBoxBodyFrame
->OnContentRemoved(aPresContext
, aChildFrame
,
7607 // If this codepath ever starts using aIndexInContainer, need to
7608 // change ContentInserted to pass in something resembling a correct
7609 // one in the XBL cases.
7610 listBoxBodyFrame
->OnContentInserted(aPresContext
, aChild
);
7622 nsCSSFrameConstructor::ContentInserted(nsIContent
* aContainer
,
7624 PRInt32 aIndexInContainer
,
7625 nsILayoutHistoryState
* aFrameState
)
7627 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
7628 NS_PRECONDITION(mUpdateCount
!= 0,
7629 "Should be in an update while creating frames");
7631 // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and
7632 // the :empty pseudo-class?
7634 if (gNoisyContentUpdates
) {
7635 printf("nsCSSFrameConstructor::ContentInserted container=%p child=%p index=%d\n",
7636 static_cast<void*>(aContainer
),
7637 static_cast<void*>(aChild
),
7639 if (gReallyNoisyContentUpdates
) {
7640 (aContainer
? aContainer
: aChild
)->List(stdout
, 0);
7645 nsresult rv
= NS_OK
;
7648 // aIndexInContainer might be bogus here, but it's not used by
7649 // NotifyListBoxBody's CONTENT_INSERTED handling in any case.
7650 if (NotifyListBoxBody(mPresShell
->GetPresContext(), aContainer
, aChild
,
7652 mDocument
, nsnull
, CONTENT_INSERTED
))
7656 // If we have a null parent, then this must be the document element
7659 nsIContent
*docElement
= mDocument
->GetRootContent();
7661 if (aChild
== docElement
) {
7662 NS_PRECONDITION(nsnull
== mRootElementFrame
, "root element frame already created");
7664 if (!mDocElementContainingBlock
)
7665 return NS_OK
; // We get into this situation when an XBL binding is asynchronously
7666 // applied to the root tag (e.g., <window> in XUL). It's ok. We can
7667 // just bail here because the root will really be built later during
7670 // Create frames for the document element and its child elements
7671 nsIFrame
* docElementFrame
;
7672 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
, nsnull
,
7673 nsnull
, aFrameState
);
7674 rv
= ConstructDocElementFrame(state
,
7676 mDocElementContainingBlock
,
7679 if (NS_SUCCEEDED(rv
) && docElementFrame
) {
7680 if (mDocElementContainingBlock
->GetStateBits() & NS_FRAME_FIRST_REFLOW
) {
7681 // Set the initial child list for the parent and wait on the initial
7683 mDocElementContainingBlock
->SetInitialChildList(nsnull
,
7686 // Whoops, we've already received our initial reflow! Insert the doc.
7687 // element as a child so it reflows (note that containing block is
7688 // empty, so we can simply append).
7689 NS_ASSERTION(mDocElementContainingBlock
->GetFirstChild(nsnull
) == nsnull
,
7690 "Unexpected child of document element containing block");
7691 mDocElementContainingBlock
->AppendFrames(nsnull
, docElementFrame
);
7693 InvalidateCanvasIfNeeded(docElementFrame
);
7695 if (gReallyNoisyContentUpdates
) {
7696 nsIFrameDebug
* fdbg
= do_QueryFrame(docElementFrame
);
7698 printf("nsCSSFrameConstructor::ContentInserted: resulting frame model:\n");
7699 fdbg
->List(stdout
, 0);
7706 // otherwise this is not a child of the root element, and we
7707 // won't let it have a frame.
7711 // Otherwise, we've got parent content. Find its frame.
7712 nsIFrame
* parentFrame
= GetFrameFor(aContainer
);
7714 return NS_OK
; // XXXwaterson will this break selects? (See ``Here
7715 // we have been notified...'' below.)
7717 // See if we have an XBL insertion point. If so, then that's our
7718 // real parent frame; if not, then the frame hasn't been built yet
7719 // and we just bail.
7720 nsIFrame
* insertionPoint
;
7721 GetInsertionPoint(parentFrame
, aChild
, &insertionPoint
);
7722 if (! insertionPoint
)
7723 return NS_OK
; // Don't build the frames.
7725 parentFrame
= insertionPoint
;
7727 // Find the frame that precedes the insertion point. Walk backwards
7728 // from the parent frame to get the parent content, because if an
7729 // XBL insertion point is involved, we'll need to use _that_ to find
7730 // the preceding frame.
7731 nsIContent
* container
= parentFrame
->GetContent();
7733 ChildIterator first
, last
;
7734 ChildIterator::Init(container
, &first
, &last
);
7735 ChildIterator
iter(first
);
7736 if (iter
.XBLInvolved() || container
!= aContainer
) {
7738 // Don't touch our aIndexInContainer, though it's almost certainly bogus in
7739 // this case. If someone wants to use an index below, they should make
7740 // sure to use the right index (aIndexInContainer vs iter.position()) with
7741 // the right parent node.
7742 } else if (aIndexInContainer
!= -1) {
7743 // Do things the fast way if we can. The check for -1 is because editor is
7744 // severely broken and calls us directly for native anonymous nodes that it
7746 iter
.seek(aIndexInContainer
);
7747 NS_ASSERTION(*iter
== aChild
, "Someone screwed up the indexing");
7751 NS_WARNING("Someone passed native anonymous content directly into frame "
7752 "construction. Stop doing that!");
7756 nsIFrame
* prevSibling
= FindPreviousSibling(first
, iter
);
7758 PRBool isAppend
= PR_FALSE
;
7759 nsIFrame
* appendAfterFrame
; // This is only looked at when isAppend is true
7761 // Now, find the geometric parent so that we can handle
7762 // continuations properly. Use the prev sibling if we have it;
7763 // otherwise use the next sibling.
7765 parentFrame
= prevSibling
->GetParent()->GetContentInsertionFrame();
7768 // If there is no previous sibling, then find the frame that follows
7769 nsIFrame
* nextSibling
= FindNextSibling(iter
, last
);
7772 parentFrame
= nextSibling
->GetParent()->GetContentInsertionFrame();
7775 // No previous or next sibling, so treat this like an appended frame.
7777 // Get continuation that parents the last child
7778 parentFrame
= nsLayoutUtils::GetLastContinuationWithChild(parentFrame
);
7779 // Deal with fieldsets
7780 parentFrame
= ::GetAdjustedParentFrame(parentFrame
,
7781 parentFrame
->GetType(),
7784 ::AdjustAppendParentForAfterContent(mPresShell
->GetPresContext(),
7785 aContainer
, parentFrame
,
7790 if (parentFrame
->GetType() == nsGkAtoms::frameSetFrame
&&
7791 IsSpecialFramesetChild(aChild
)) {
7792 // Just reframe the parent, since framesets are weird like that.
7793 return RecreateFramesForContent(parentFrame
->GetContent());
7796 // Don't construct kids of leaves
7797 if (parentFrame
->IsLeaf()) {
7802 if (parentFrame
->IsFrameOfType(nsIFrame::eMathML
))
7803 return RecreateFramesForContent(parentFrame
->GetContent());
7806 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
7807 GetAbsoluteContainingBlock(parentFrame
),
7808 GetFloatContainingBlock(parentFrame
),
7812 // Recover state for the containing block - we need to know if
7813 // it has :first-letter or :first-line style applied to it. The
7814 // reason we care is that the internal structure in these cases
7815 // is not the normal structure and requires custom updating
7817 nsIFrame
* containingBlock
= state
.mFloatedItems
.containingBlock
;
7818 PRBool haveFirstLetterStyle
= PR_FALSE
;
7819 PRBool haveFirstLineStyle
= PR_FALSE
;
7821 // In order to shave off some cycles, we only dig up the
7822 // containing block haveFirst* flags if the parent frame where
7823 // the insertion/append is occurring is an inline or block
7824 // container. For other types of containers this isn't relevant.
7825 const nsStyleDisplay
* parentDisplay
= parentFrame
->GetStyleDisplay();
7827 // Examine the parentFrame where the insertion is taking
7828 // place. If it's a certain kind of container then some special
7829 // processing is done.
7830 if ((NS_STYLE_DISPLAY_BLOCK
== parentDisplay
->mDisplay
) ||
7831 (NS_STYLE_DISPLAY_LIST_ITEM
== parentDisplay
->mDisplay
) ||
7832 (NS_STYLE_DISPLAY_INLINE
== parentDisplay
->mDisplay
) ||
7833 (NS_STYLE_DISPLAY_INLINE_BLOCK
== parentDisplay
->mDisplay
)) {
7834 // Recover the special style flags for the containing block
7835 if (containingBlock
) {
7836 haveFirstLetterStyle
= HasFirstLetterStyle(containingBlock
);
7837 haveFirstLineStyle
=
7838 ShouldHaveFirstLineStyle(containingBlock
->GetContent(),
7839 containingBlock
->GetStyleContext());
7842 if (haveFirstLetterStyle
) {
7843 // Get the correct parentFrame and prevSibling - if a
7844 // letter-frame is present, use its parent.
7845 if (parentFrame
->GetType() == nsGkAtoms::letterFrame
) {
7846 parentFrame
= parentFrame
->GetParent();
7847 container
= parentFrame
->GetContent();
7850 // Remove the old letter frames before doing the insertion
7851 RemoveLetterFrames(state
.mPresContext
, mPresShell
,
7852 state
.mFrameManager
,
7853 state
.mFloatedItems
.containingBlock
);
7855 // Removing the letterframes messes around with the frame tree, removing
7856 // and creating frames. We need to reget our prevsibling.
7857 ChildIterator::Init(container
, &first
, &last
);
7858 if (last
.XBLInvolved() || container
!= aContainer
) {
7860 } else if (aIndexInContainer
!= -1) {
7861 last
.seek(aIndexInContainer
);
7862 NS_ASSERTION(*iter
== aChild
, "Someone screwed up the indexing");
7865 prevSibling
= FindPreviousSibling(first
, last
);
7870 // We're inserting the new frame as the first child. See if the
7871 // parent has a :before pseudo-element
7872 nsIFrame
* firstChild
= parentFrame
->GetFirstChild(nsnull
);
7875 nsLayoutUtils::IsGeneratedContentFor(aContainer
, firstChild
,
7876 nsCSSPseudoElements::before
)) {
7877 // Insert the new frames after the last continuation of the :before
7878 prevSibling
= firstChild
->GetTailContinuation();
7879 parentFrame
= prevSibling
->GetParent();
7880 // We perhaps could leave this true and take the AppendFrames path
7881 // below, but we'd have to update appendAfterFrame and it seems safer
7882 // to force all insert-after-:before cases to take these to take the
7883 // InsertFrames path
7884 isAppend
= PR_FALSE
;
7888 // if the container is a table and a caption will be appended, it needs to be
7889 // put in the outer table frame's additional child list.
7891 nsFrameItems frameItems
, captionItems
;
7893 ConstructFrame(state
, aChild
, parentFrame
, frameItems
);
7894 if (frameItems
.childList
) {
7895 InvalidateCanvasIfNeeded(frameItems
.childList
);
7897 if (nsGkAtoms::tableCaptionFrame
== frameItems
.childList
->GetType()) {
7898 NS_ASSERTION(frameItems
.childList
== frameItems
.lastChild
,
7899 "adding a non caption frame to the caption childlist?");
7900 captionItems
.AddChild(frameItems
.childList
);
7901 frameItems
= nsFrameItems();
7905 // process the current pseudo frame state
7906 if (!state
.mPseudoFrames
.IsEmpty())
7907 ProcessPseudoFrames(state
, frameItems
);
7909 // If the parent of our current prevSibling is different from the frame we'll
7910 // actually use as the parent, then the calculated insertion point is now
7911 // invalid and as it is unknown where to insert correctly we append instead
7913 if (prevSibling
&& frameItems
.childList
&&
7914 frameItems
.childList
->GetParent() != prevSibling
->GetParent()) {
7915 prevSibling
= nsnull
;
7918 ::AdjustAppendParentForAfterContent(mPresShell
->GetPresContext(),
7920 frameItems
.childList
->GetParent(),
7924 // Perform special check for diddling around with the frames in
7925 // a special inline frame.
7927 // If we're appending before :after content, then we're not really
7928 // appending, so let WipeContainingBlock know that.
7929 if (WipeContainingBlock(state
, containingBlock
, parentFrame
, frameItems
,
7930 isAppend
&& !appendAfterFrame
, prevSibling
))
7933 if (haveFirstLineStyle
&& parentFrame
== containingBlock
) {
7934 // It's possible that the new frame goes into a first-line
7935 // frame. Look at it and see...
7937 // Use append logic when appending
7938 AppendFirstLineFrames(state
, containingBlock
->GetContent(),
7939 containingBlock
, frameItems
);
7942 // Use more complicated insert logic when inserting
7943 InsertFirstLineFrames(state
, aContainer
, containingBlock
, &parentFrame
,
7944 prevSibling
, frameItems
);
7948 nsIFrame
* const newFrame
= frameItems
.childList
;
7949 if (NS_SUCCEEDED(rv
) && newFrame
) {
7950 NS_ASSERTION(!captionItems
.childList
, "leaking caption frames");
7951 // Notify the parent frame
7953 AppendFrames(state
, aContainer
, parentFrame
, frameItems
,
7956 state
.mFrameManager
->InsertFrames(parentFrame
,
7957 nsnull
, prevSibling
, newFrame
);
7961 // we might have a caption treat it here
7962 nsIFrame
* newCaptionFrame
= captionItems
.childList
;
7963 if (NS_SUCCEEDED(rv
) && newCaptionFrame
) {
7964 nsIFrame
* outerTableFrame
;
7965 if (GetCaptionAdjustedParent(parentFrame
, newCaptionFrame
, &outerTableFrame
)) {
7966 // If the parent of our current prevSibling is different from the frame
7967 // we'll actually use as the parent, then the calculated insertion
7968 // point is now invalid (bug 341382).
7969 if (prevSibling
&& prevSibling
->GetParent() != outerTableFrame
) {
7970 prevSibling
= nsnull
;
7972 // If the parent is not a outer table frame we will try to add frames
7973 // to a named child list that the parent does not honour and the frames
7975 NS_ASSERTION(nsGkAtoms::tableOuterFrame
== outerTableFrame
->GetType(),
7976 "Pseudo frame construction failure, "
7977 "a caption can be only a child of a outer table frame");
7979 state
.mFrameManager
->AppendFrames(outerTableFrame
,
7980 nsGkAtoms::captionList
,
7984 state
.mFrameManager
->InsertFrames(outerTableFrame
,
7985 nsGkAtoms::captionList
,
7986 prevSibling
, newCaptionFrame
);
7992 if (haveFirstLetterStyle
) {
7993 // Recover the letter frames for the containing block when
7994 // it has first-letter style.
7995 RecoverLetterFrames(state
.mFloatedItems
.containingBlock
);
7999 if (gReallyNoisyContentUpdates
&& parentFrame
) {
8000 nsIFrameDebug
* fdbg
= do_QueryFrame(parentFrame
);
8002 printf("nsCSSFrameConstructor::ContentInserted: resulting frame model:\n");
8003 fdbg
->List(stdout
, 0);
8012 nsCSSFrameConstructor::ReinsertContent(nsIContent
* aContainer
,
8015 PRInt32 ix
= aContainer
->IndexOf(aChild
);
8016 // XXX For now, do a brute force remove and insert.
8017 // XXXbz this probably doesn't work so well with anonymous content
8018 // XXXbz doesn't this need to do the state-saving stuff that
8019 // RecreateFramesForContent does?
8020 PRBool didReconstruct
;
8021 nsresult res
= ContentRemoved(aContainer
, aChild
, ix
, &didReconstruct
);
8023 if (NS_SUCCEEDED(res
) && !didReconstruct
) {
8024 // If ContentRemoved just reconstructed everything, there is no need to
8025 // reinsert the content here
8026 res
= ContentInserted(aContainer
, aChild
, ix
, nsnull
);
8033 DoDeletingFrameSubtree(nsFrameManager
* aFrameManager
,
8034 nsTArray
<nsIFrame
*>& aDestroyQueue
,
8035 nsIFrame
* aRemovedFrame
,
8039 DoDeletingOverflowContainers(nsFrameManager
* aFrameManager
,
8040 nsTArray
<nsIFrame
*>& aDestroyQueue
,
8041 nsIFrame
* aRemovedFrame
,
8044 // The invariant that "continuing frames should be found as part of the
8045 // walk over the top-most frame's continuing frames" does not hold for
8046 // out-of-flow overflow containers, so we need to walk them too.
8047 // Note that DoDeletingFrameSubtree() skips the child lists where
8048 // overflow containers live so we won't process them twice.
8049 const PRBool orphanSubtree
= aRemovedFrame
== aFrame
;
8050 for (nsIFrame
* next
= aFrame
->GetNextContinuation();
8051 next
&& (next
->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER
);
8052 next
= next
->GetNextContinuation()) {
8053 DoDeletingFrameSubtree(aFrameManager
, aDestroyQueue
,
8054 orphanSubtree
? next
: aRemovedFrame
,
8060 * Called when a frame subtree is about to be deleted. Two important
8063 * 1. For each frame in the subtree, we remove the mapping from the
8064 * content object to its frame
8066 * 2. For child frames that have been moved out of the flow, we enqueue
8067 * the out-of-flow frame for deletion *if* the out-of-flow frame's
8068 * geometric parent is not in |aRemovedFrame|'s hierarchy (e.g., an
8069 * absolutely positioned element that has been promoted to be a direct
8070 * descendant of an area frame).
8072 * Note: this function should only be called by DeletingFrameSubtree()
8074 * @param aRemovedFrame this is the frame that was removed from the
8075 * content model. As we recurse we need to remember this so we
8076 * can check if out-of-flow frames are a descendant of the frame
8078 * @param aFrame the local subtree that is being deleted. This is initially
8079 * the same as aRemovedFrame, but as we recurse down the tree
8083 DoDeletingFrameSubtree(nsFrameManager
* aFrameManager
,
8084 nsTArray
<nsIFrame
*>& aDestroyQueue
,
8085 nsIFrame
* aRemovedFrame
,
8089 #define RECURSE(top, child) \
8090 DoDeletingFrameSubtree(aFrameManager, aDestroyQueue, (top), (child)); \
8091 DoDeletingOverflowContainers(aFrameManager, aDestroyQueue, (top), (child));
8093 // Remove the mapping from the content object to its frame.
8094 nsIContent
* content
= aFrame
->GetContent();
8096 aFrameManager
->RemoveAsPrimaryFrame(content
, aFrame
);
8097 aFrameManager
->ClearAllUndisplayedContentIn(content
);
8100 nsIAtom
* childListName
= nsnull
;
8101 PRInt32 childListIndex
= 0;
8104 // Walk aFrame's normal flow child frames looking for placeholder frames.
8105 nsIFrame
* childFrame
= aFrame
->GetFirstChild(childListName
);
8106 for (; childFrame
; childFrame
= childFrame
->GetNextSibling()) {
8107 NS_ASSERTION(!(childFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
),
8108 "out-of-flow on wrong child list");
8109 if (NS_LIKELY(nsGkAtoms::placeholderFrame
!= childFrame
->GetType())) {
8110 RECURSE(aRemovedFrame
, childFrame
);
8112 nsIFrame
* outOfFlowFrame
=
8113 nsPlaceholderFrame::GetRealFrameForPlaceholder(childFrame
);
8115 // Remove the mapping from the out-of-flow frame to its placeholder.
8116 aFrameManager
->UnregisterPlaceholderFrame((nsPlaceholderFrame
*)childFrame
);
8117 // Don't SetOutOfFlowFrame(nsnull) here because the float cache depends
8118 // on it when the float is removed later on, see bug 348688 comment 6.
8120 // Queue the out-of-flow frame to be destroyed only if aRemovedFrame is _not_
8121 // one of its ancestor frames or if it is a popup frame.
8122 // If aRemovedFrame is an ancestor of the out-of-flow frame, then
8123 // the out-of-flow frame will be destroyed by aRemovedFrame.
8124 if (outOfFlowFrame
->GetStyleDisplay()->mDisplay
== NS_STYLE_DISPLAY_POPUP
||
8125 !nsLayoutUtils::IsProperAncestorFrame(aRemovedFrame
, outOfFlowFrame
)) {
8126 NS_ASSERTION(aDestroyQueue
.IndexOf(outOfFlowFrame
) == kNotFound
,
8127 "out-of-flow is already in the destroy queue");
8128 aDestroyQueue
.AppendElement(outOfFlowFrame
);
8129 // Recurse into the out-of-flow, it is now the aRemovedFrame.
8130 RECURSE(outOfFlowFrame
, outOfFlowFrame
);
8133 // Also recurse into the out-of-flow when it's a descendant of aRemovedFrame
8134 // since we don't walk those lists, see |childListName| increment below.
8135 RECURSE(aRemovedFrame
, outOfFlowFrame
);
8140 // Move to next child list but skip lists with frames we should have
8141 // a placeholder for or that contains only next-in-flow overflow containers
8142 // (which we walk explicitly above).
8144 childListName
= aFrame
->GetAdditionalChildListName(childListIndex
++);
8145 } while (IsOutOfFlowList(childListName
) ||
8146 childListName
== nsGkAtoms::overflowContainersList
||
8147 childListName
== nsGkAtoms::excessOverflowContainersList
);
8148 } while (childListName
);
8152 * Called when a frame is about to be deleted. Calls DoDeletingFrameSubtree()
8153 * for aFrame and each of its continuing frames
8156 DeletingFrameSubtree(nsFrameManager
* aFrameManager
,
8159 NS_ENSURE_TRUE(aFrame
, NS_OK
); // XXXldb Remove this sometime in the future.
8161 // If there's no frame manager it's probably because the pres shell is
8163 if (NS_UNLIKELY(!aFrameManager
)) {
8167 nsAutoTArray
<nsIFrame
*, 8> destroyQueue
;
8169 // If it's a "special" block-in-inline frame, then we can't really deal.
8170 // That really shouldn't be happening.
8171 NS_ASSERTION(!IsFrameSpecial(aFrame
),
8172 "DeletingFrameSubtree on a special frame. Prepare to crash.");
8175 DoDeletingFrameSubtree(aFrameManager
, destroyQueue
, aFrame
, aFrame
);
8177 // If it's split, then get the continuing frame. Note that we only do
8178 // this for the top-most frame being deleted. Don't do it if we're
8179 // recursing over a subtree, because those continuing frames should be
8180 // found as part of the walk over the top-most frame's continuing frames.
8181 // Walking them again will make this an N^2/2 algorithm.
8182 // The above is true for normal child next-in-flows but not overflow
8183 // containers which we do walk because they *can* escape the subtree
8184 // we're deleting. We skip [excess]overflowContainersList where
8185 // they live to avoid processing them more than once.
8186 aFrame
= aFrame
->GetNextContinuation();
8189 // Now destroy any out-of-flow frames that have been enqueued for
8191 for (PRInt32 i
= destroyQueue
.Length() - 1; i
>= 0; --i
) {
8192 nsIFrame
* outOfFlowFrame
= destroyQueue
[i
];
8194 // Ask the out-of-flow's parent to delete the out-of-flow
8195 // frame from the right list.
8196 aFrameManager
->RemoveFrame(outOfFlowFrame
->GetParent(),
8197 GetChildListNameFor(outOfFlowFrame
),
8205 nsCSSFrameConstructor::RemoveMappingsForFrameSubtree(nsIFrame
* aRemovedFrame
)
8207 NS_ASSERTION(!(aRemovedFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
),
8208 "RemoveMappingsForFrameSubtree doesn't handle out-of-flows");
8210 if (NS_UNLIKELY(mIsDestroyingFrameTree
)) {
8211 // The frame tree might not be in a consistent state after
8212 // WillDestroyFrameTree() has been called. Most likely we're destroying
8213 // the pres shell which means the frame manager takes care of clearing all
8214 // mappings so there is no need to walk the frame tree here, bug 372576.
8218 nsFrameManager
*frameManager
= mPresShell
->FrameManager();
8219 if (nsGkAtoms::placeholderFrame
== aRemovedFrame
->GetType()) {
8220 nsIFrame
*placeholderFrame
= aRemovedFrame
;
8222 NS_ASSERTION(placeholderFrame
->GetType() == nsGkAtoms::placeholderFrame
,
8223 "continuation must be of same type");
8224 nsIFrame
* outOfFlowFrame
=
8225 nsPlaceholderFrame::GetRealFrameForPlaceholder(placeholderFrame
);
8226 // Remove the mapping from the out-of-flow frame to its placeholder.
8227 frameManager
->UnregisterPlaceholderFrame(
8228 static_cast<nsPlaceholderFrame
*>(placeholderFrame
));
8229 ::DeletingFrameSubtree(frameManager
, outOfFlowFrame
);
8230 frameManager
->RemoveFrame(outOfFlowFrame
->GetParent(),
8231 GetChildListNameFor(outOfFlowFrame
),
8233 placeholderFrame
= placeholderFrame
->GetNextContinuation();
8234 } while (placeholderFrame
);
8237 // Save the frame tree's state before deleting it
8238 CaptureStateFor(aRemovedFrame
, mTempFrameTreeState
);
8240 return ::DeletingFrameSubtree(frameManager
, aRemovedFrame
);
8243 static void UnregisterPlaceholderChain(nsFrameManager
* frameManager
,
8244 nsPlaceholderFrame
* placeholderFrame
)
8246 // Remove the mapping from the frame to its placeholder
8247 nsPlaceholderFrame
* curFrame
= placeholderFrame
;
8249 frameManager
->UnregisterPlaceholderFrame(curFrame
);
8250 curFrame
->SetOutOfFlowFrame(nsnull
);
8251 curFrame
= static_cast<nsPlaceholderFrame
*>(curFrame
->GetNextContinuation());
8256 nsCSSFrameConstructor::ContentRemoved(nsIContent
* aContainer
,
8258 PRInt32 aIndexInContainer
,
8259 PRBool
* aDidReconstruct
)
8261 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
8262 NS_PRECONDITION(mUpdateCount
!= 0,
8263 "Should be in an update while destroying frames");
8265 *aDidReconstruct
= PR_FALSE
;
8267 // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and
8268 // the :empty pseudo-class?
8271 if (gNoisyContentUpdates
) {
8272 printf("nsCSSFrameConstructor::ContentRemoved container=%p child=%p index=%d\n",
8273 static_cast<void*>(aContainer
),
8274 static_cast<void*>(aChild
),
8276 if (gReallyNoisyContentUpdates
) {
8277 aContainer
->List(stdout
, 0);
8282 nsFrameManager
*frameManager
= mPresShell
->FrameManager();
8283 nsPresContext
*presContext
= mPresShell
->GetPresContext();
8284 nsresult rv
= NS_OK
;
8286 // Find the child frame that maps the content
8287 nsIFrame
* childFrame
=
8288 mPresShell
->FrameManager()->GetPrimaryFrameFor(aChild
, aIndexInContainer
);
8290 if (!childFrame
|| childFrame
->GetContent() != aChild
) {
8291 // XXXbz the GetContent() != aChild check is needed due to bug 135040.
8292 // Remove it once that's fixed.
8293 frameManager
->ClearUndisplayedContentIn(aChild
, aContainer
);
8297 if (NotifyListBoxBody(presContext
, aContainer
, aChild
, aIndexInContainer
,
8298 mDocument
, childFrame
, CONTENT_REMOVED
))
8304 InvalidateCanvasIfNeeded(childFrame
);
8306 // If the frame we are manipulating is a special frame then do
8307 // something different instead of just inserting newly created
8309 // NOTE: if we are in ReinsertContent,
8310 // then do not reframe as we are already doing just that!
8311 if (MaybeRecreateContainerForIBSplitterFrame(childFrame
, &rv
)) {
8312 *aDidReconstruct
= PR_TRUE
;
8316 // Get the childFrame's parent frame
8317 nsIFrame
* parentFrame
= childFrame
->GetParent();
8318 nsIAtom
* parentType
= parentFrame
->GetType();
8320 if (parentType
== nsGkAtoms::frameSetFrame
&&
8321 IsSpecialFramesetChild(aChild
)) {
8322 // Just reframe the parent, since framesets are weird like that.
8323 *aDidReconstruct
= PR_TRUE
;
8324 return RecreateFramesForContent(parentFrame
->GetContent());
8328 // If we're a child of MathML, then we should reframe the MathML content.
8329 // If we're non-MathML, then we would be wrapped in a block so we need to
8330 // check our grandparent in that case.
8331 nsIFrame
* possibleMathMLAncestor
= parentType
== nsGkAtoms::blockFrame
?
8332 parentFrame
->GetParent() : parentFrame
;
8333 if (possibleMathMLAncestor
->IsFrameOfType(nsIFrame::eMathML
)) {
8334 *aDidReconstruct
= PR_TRUE
;
8335 return RecreateFramesForContent(possibleMathMLAncestor
->GetContent());
8339 // Undo XUL wrapping if it's no longer needed.
8340 // (If we're in the XUL block-wrapping situation, parentFrame is the
8342 nsIFrame
* grandparentFrame
= parentFrame
->GetParent();
8343 if (grandparentFrame
&& grandparentFrame
->IsBoxFrame() &&
8344 (grandparentFrame
->GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK
) &&
8345 // check if this frame is the only one needing wrapping
8346 aChild
== AnyKidsNeedBlockParent(parentFrame
->GetFirstChild(nsnull
)) &&
8347 !AnyKidsNeedBlockParent(childFrame
->GetNextSibling())) {
8348 *aDidReconstruct
= PR_TRUE
;
8349 return RecreateFramesForContent(grandparentFrame
->GetContent());
8352 // Examine the containing-block for the removed content and see if
8353 // :first-letter style applies.
8354 nsIFrame
* containingBlock
= GetFloatContainingBlock(parentFrame
);
8355 PRBool haveFLS
= containingBlock
&& HasFirstLetterStyle(containingBlock
);
8357 // Trap out to special routine that handles adjusting a blocks
8358 // frame tree when first-letter style is present.
8359 #ifdef NOISY_FIRST_LETTER
8360 printf("ContentRemoved: containingBlock=");
8361 nsFrame::ListTag(stdout
, containingBlock
);
8362 printf(" parentFrame=");
8363 nsFrame::ListTag(stdout
, parentFrame
);
8364 printf(" childFrame=");
8365 nsFrame::ListTag(stdout
, childFrame
);
8369 // First update the containing blocks structure by removing the
8370 // existing letter frames. This makes the subsequent logic
8372 RemoveLetterFrames(presContext
, mPresShell
, frameManager
,
8375 // Recover childFrame and parentFrame
8376 childFrame
= mPresShell
->GetPrimaryFrameFor(aChild
);
8377 if (!childFrame
|| childFrame
->GetContent() != aChild
) {
8378 // XXXbz the GetContent() != aChild check is needed due to bug 135040.
8379 // Remove it once that's fixed.
8380 frameManager
->ClearUndisplayedContentIn(aChild
, aContainer
);
8383 parentFrame
= childFrame
->GetParent();
8385 #ifdef NOISY_FIRST_LETTER
8386 printf(" ==> revised parentFrame=");
8387 nsFrame::ListTag(stdout
, parentFrame
);
8388 printf(" childFrame=");
8389 nsFrame::ListTag(stdout
, childFrame
);
8395 if (gReallyNoisyContentUpdates
) {
8396 printf("nsCSSFrameConstructor::ContentRemoved: childFrame=");
8397 nsFrame::ListTag(stdout
, childFrame
);
8400 nsIFrameDebug
* fdbg
= do_QueryFrame(parentFrame
);
8402 fdbg
->List(stdout
, 0);
8406 // Walk the frame subtree deleting any out-of-flow frames, and
8407 // remove the mapping from content objects to frames
8408 ::DeletingFrameSubtree(frameManager
, childFrame
);
8410 // See if the child frame is an out-of-flow
8411 if (childFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
8412 nsPlaceholderFrame
* placeholderFrame
=
8413 frameManager
->GetPlaceholderFrameFor(childFrame
);
8414 NS_ASSERTION(placeholderFrame
, "No placeholder for out-of-flow?");
8416 UnregisterPlaceholderChain(frameManager
, placeholderFrame
);
8418 // Now we remove the out-of-flow frame
8419 // XXX has to be done first for now: for floats, the block's line list
8420 // contains an array of pointers to the placeholder - we have to
8421 // remove the float first (which gets rid of the lines
8422 // reference to the placeholder and float) and then remove the
8424 rv
= frameManager
->RemoveFrame(parentFrame
,
8425 GetChildListNameFor(childFrame
),
8428 // Remove the placeholder frame first (XXX second for now) (so
8429 // that it doesn't retain a dangling pointer to memory)
8430 nsIFrame
* placeholderParent
= placeholderFrame
->GetParent();
8431 ::DeletingFrameSubtree(frameManager
, placeholderFrame
);
8432 rv
|= frameManager
->RemoveFrame(placeholderParent
,
8433 nsnull
, placeholderFrame
);
8435 // Notify the parent frame that it should delete the frame
8436 // check for a table caption which goes on an additional child list with a different parent
8437 nsIFrame
* outerTableFrame
;
8438 if (GetCaptionAdjustedParent(parentFrame
, childFrame
, &outerTableFrame
)) {
8439 rv
= frameManager
->RemoveFrame(outerTableFrame
,
8440 nsGkAtoms::captionList
,
8444 rv
= frameManager
->RemoveFrame(parentFrame
, nsnull
, childFrame
);
8448 if (mRootElementFrame
== childFrame
) {
8449 mRootElementFrame
= nsnull
;
8450 mRootElementStyleFrame
= nsnull
;
8453 if (haveFLS
&& mRootElementFrame
) {
8454 NS_ASSERTION(containingBlock
== GetFloatContainingBlock(parentFrame
),
8455 "What happened here?");
8456 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
8457 GetAbsoluteContainingBlock(parentFrame
),
8459 RecoverLetterFrames(containingBlock
);
8463 if (gReallyNoisyContentUpdates
&& parentFrame
) {
8464 nsIFrameDebug
* fdbg
= do_QueryFrame(parentFrame
);
8466 printf("nsCSSFrameConstructor::ContentRemoved: resulting frame model:\n");
8467 fdbg
->List(stdout
, 0);
8477 // To ensure that the functions below are only called within
8478 // |ApplyRenderingChangeToTree|.
8479 static PRBool gInApplyRenderingChangeToTree
= PR_FALSE
;
8483 DoApplyRenderingChangeToTree(nsIFrame
* aFrame
,
8484 nsIViewManager
* aViewManager
,
8485 nsFrameManager
* aFrameManager
,
8486 nsChangeHint aChange
);
8489 * @param aBoundsRect returns the bounds enclosing the areas covered by aFrame and its childre
8490 * This rect is relative to aFrame's parent
8493 UpdateViewsForTree(nsIFrame
* aFrame
, nsIViewManager
* aViewManager
,
8494 nsFrameManager
* aFrameManager
,
8495 nsChangeHint aChange
)
8497 NS_PRECONDITION(gInApplyRenderingChangeToTree
,
8498 "should only be called within ApplyRenderingChangeToTree");
8500 nsIView
* view
= aFrame
->GetView();
8502 if (aChange
& nsChangeHint_SyncFrameView
) {
8503 nsContainerFrame::SyncFrameViewProperties(aFrame
->PresContext(),
8504 aFrame
, nsnull
, view
);
8508 // now do children of frame
8509 PRInt32 listIndex
= 0;
8510 nsIAtom
* childList
= nsnull
;
8513 nsIFrame
* child
= aFrame
->GetFirstChild(childList
);
8515 if (!(child
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)
8516 || (child
->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER
)) {
8517 // only do frames that don't have placeholders
8518 if (nsGkAtoms::placeholderFrame
== child
->GetType()) { // placeholder
8519 // get out of flow frame and start over there
8520 nsIFrame
* outOfFlowFrame
=
8521 nsPlaceholderFrame::GetRealFrameForPlaceholder(child
);
8523 DoApplyRenderingChangeToTree(outOfFlowFrame
, aViewManager
,
8524 aFrameManager
, aChange
);
8526 else { // regular frame
8527 UpdateViewsForTree(child
, aViewManager
, aFrameManager
, aChange
);
8530 child
= child
->GetNextSibling();
8532 childList
= aFrame
->GetAdditionalChildListName(listIndex
++);
8533 } while (childList
);
8537 DoApplyRenderingChangeToTree(nsIFrame
* aFrame
,
8538 nsIViewManager
* aViewManager
,
8539 nsFrameManager
* aFrameManager
,
8540 nsChangeHint aChange
)
8542 NS_PRECONDITION(gInApplyRenderingChangeToTree
,
8543 "should only be called within ApplyRenderingChangeToTree");
8545 for ( ; aFrame
; aFrame
= nsLayoutUtils::GetNextContinuationOrSpecialSibling(aFrame
)) {
8546 // Get view if this frame has one and trigger an update. If the
8547 // frame doesn't have a view, find the nearest containing view
8548 // (adjusting r's coordinate system to reflect the nesting) and
8550 UpdateViewsForTree(aFrame
, aViewManager
, aFrameManager
, aChange
);
8552 // if frame has view, will already be invalidated
8553 if (aChange
& nsChangeHint_RepaintFrame
) {
8554 if (aFrame
->IsFrameOfType(nsIFrame::eSVG
)) {
8556 if (!(aFrame
->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD
)) {
8557 nsSVGOuterSVGFrame
*outerSVGFrame
= nsSVGUtils::GetOuterSVGFrame(aFrame
);
8558 if (outerSVGFrame
) {
8559 // marker changes can change the covered region
8560 outerSVGFrame
->UpdateAndInvalidateCoveredRegion(aFrame
);
8565 aFrame
->Invalidate(aFrame
->GetOverflowRect());
8572 ApplyRenderingChangeToTree(nsPresContext
* aPresContext
,
8574 nsChangeHint aChange
)
8576 nsIPresShell
*shell
= aPresContext
->PresShell();
8577 PRBool isPaintingSuppressed
= PR_FALSE
;
8578 shell
->IsPaintingSuppressed(&isPaintingSuppressed
);
8579 if (isPaintingSuppressed
) {
8580 // Don't allow synchronous rendering changes when painting is turned off.
8581 aChange
= NS_SubtractHint(aChange
, nsChangeHint_RepaintFrame
);
8587 // If the frame's background is propagated to an ancestor, walk up to
8589 const nsStyleBackground
*bg
;
8590 while (!nsCSSRendering::FindBackground(aPresContext
, aFrame
, &bg
)) {
8591 aFrame
= aFrame
->GetParent();
8592 NS_ASSERTION(aFrame
, "root frame must paint");
8595 nsIViewManager
* viewManager
= aPresContext
->GetViewManager();
8597 // Trigger rendering updates by damaging this frame and any
8598 // continuations of this frame.
8600 // XXX this needs to detect the need for a view due to an opacity change and deal with it...
8602 nsIViewManager::UpdateViewBatch
batch(viewManager
);
8605 gInApplyRenderingChangeToTree
= PR_TRUE
;
8607 DoApplyRenderingChangeToTree(aFrame
, viewManager
, shell
->FrameManager(),
8610 gInApplyRenderingChangeToTree
= PR_FALSE
;
8613 batch
.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC
);
8617 * This method invalidates the canvas when frames are removed or added for a
8618 * node that might have its background propagated to the canvas, i.e., a
8619 * document root node or an HTML BODY which is a child of the root node.
8621 * @param aFrame a frame for a content node about to be removed or a frme that
8622 * was just created for a content node that was inserted.
8625 InvalidateCanvasIfNeeded(nsIFrame
* aFrame
)
8627 NS_ASSERTION(aFrame
, "Must have frame!");
8629 // Note that for both in ContentRemoved and ContentInserted the content node
8630 // will still have the right parent pointer, so looking at that is ok.
8632 nsIContent
* node
= aFrame
->GetContent();
8633 nsIContent
* parent
= node
->GetParent();
8635 // Has a parent; might not be what we want
8636 nsIContent
* grandParent
= parent
->GetParent();
8638 // Has a grandparent, so not what we want
8642 // Check whether it's an HTML body
8643 if (node
->Tag() != nsGkAtoms::body
||
8644 !node
->IsNodeOfType(nsINode::eHTML
)) {
8649 // At this point the node has no parent or it's an HTML <body> child of the
8650 // root. We might not need to invalidate in this case (eg we might be in
8651 // XHTML or something), but chances are we want to. Play it safe. Find the
8652 // frame to invalidate and do it.
8653 nsIFrame
*ancestor
= aFrame
;
8654 const nsStyleBackground
*bg
;
8655 nsPresContext
* presContext
= aFrame
->PresContext();
8656 while (!nsCSSRendering::FindBackground(presContext
, ancestor
, &bg
)) {
8657 ancestor
= ancestor
->GetParent();
8658 NS_ASSERTION(ancestor
, "canvas must paint");
8661 if (ancestor
->GetType() == nsGkAtoms::canvasFrame
) {
8662 // The canvas frame's dimensions are not meaningful; invalidate the
8663 // viewport instead.
8664 ancestor
= ancestor
->GetParent();
8667 if (ancestor
!= aFrame
) {
8668 // Wrap this in a DEFERRED view update batch so we don't try to
8669 // flush out layout here
8671 nsIViewManager::UpdateViewBatch
batch(presContext
->GetViewManager());
8672 ApplyRenderingChangeToTree(presContext
, ancestor
,
8673 nsChangeHint_RepaintFrame
);
8674 batch
.EndUpdateViewBatch(NS_VMREFRESH_DEFERRED
);
8679 nsCSSFrameConstructor::StyleChangeReflow(nsIFrame
* aFrame
)
8681 // If the frame hasn't even received an initial reflow, then don't
8682 // send it a style-change reflow!
8683 if (aFrame
->GetStateBits() & NS_FRAME_FIRST_REFLOW
)
8687 if (gNoisyContentUpdates
) {
8688 printf("nsCSSFrameConstructor::StyleChangeReflow: aFrame=");
8689 nsFrame::ListTag(stdout
, aFrame
);
8694 // If the frame is part of a split block-in-inline hierarchy, then
8695 // target the style-change reflow at the first ``normal'' ancestor
8696 // so we're sure that the style change will propagate to any
8697 // anonymously created siblings.
8698 if (IsFrameSpecial(aFrame
))
8699 aFrame
= GetIBContainingBlockFor(aFrame
);
8702 mPresShell
->FrameNeedsReflow(aFrame
, nsIPresShell::eStyleChange
,
8704 aFrame
= aFrame
->GetNextContinuation();
8711 nsCSSFrameConstructor::CharacterDataChanged(nsIContent
* aContent
,
8714 AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell
->GetPresContext(), FrameC
);
8715 nsresult rv
= NS_OK
;
8717 // Find the child frame
8718 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
8720 // Notify the first frame that maps the content. It will generate a reflow
8723 // It's possible the frame whose content changed isn't inserted into the
8724 // frame hierarchy yet, or that there is no frame that maps the content
8725 if (nsnull
!= frame
) {
8727 NS_FRAME_LOG(NS_FRAME_TRACE_CALLS
,
8728 ("nsCSSFrameConstructor::CharacterDataChanged: content=%p[%s] subcontent=%p frame=%p",
8729 aContent
, ContentTag(aContent
, 0),
8730 aSubContent
, frame
));
8733 // Special check for text content that is a child of a letter frame. If
8734 // this happens, we should remove the letter frame, do whatever we're
8735 // planning to do with this notification, then put the letter frame back.
8736 // Note that this is basically what ReinsertContent ends up doing; the
8737 // reason we dont' want to call that here is that our text content could be
8738 // native anonymous, in which case ReinsertContent would completely barf on
8739 // it. And reinserting the non-anonymous ancestor would just lead us to
8740 // come back into this notification (e.g. if quotes or counters are
8741 // involved), leading to a loop.
8742 nsIFrame
* block
= GetFloatContainingBlock(frame
);
8743 PRBool haveFirstLetterStyle
= PR_FALSE
;
8745 // See if the block has first-letter style applied to it.
8746 haveFirstLetterStyle
= HasFirstLetterStyle(block
);
8747 if (haveFirstLetterStyle
) {
8748 RemoveLetterFrames(mPresShell
->GetPresContext(), mPresShell
,
8749 mPresShell
->FrameManager(), block
);
8750 // Reget |frame|, since we might have killed it.
8751 // Do we really need to call CharacterDataChanged in this case, though?
8752 frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
8753 NS_ASSERTION(frame
, "Should have frame here!");
8757 frame
->CharacterDataChanged(mPresShell
->GetPresContext(), aContent
,
8760 if (haveFirstLetterStyle
) {
8761 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
8762 GetAbsoluteContainingBlock(frame
),
8764 RecoverLetterFrames(block
);
8772 nsCSSFrameConstructor::ProcessRestyledFrames(nsStyleChangeList
& aChangeList
)
8774 NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
8775 "Someone forgot a script blocker");
8776 PRInt32 count
= aChangeList
.Count();
8780 // Make sure to not rebuild quote or counter lists while we're
8781 // processing restyles
8784 nsPropertyTable
*propTable
= mPresShell
->GetPresContext()->PropertyTable();
8786 // Mark frames so that we skip frames that die along the way, bug 123049.
8787 // A frame can be in the list multiple times with different hints. Further
8788 // optmization is possible if nsStyleChangeList::AppendChange could coalesce
8789 PRInt32 index
= count
;
8791 while (0 <= --index
) {
8792 const nsStyleChangeData
* changeData
;
8793 aChangeList
.ChangeAt(index
, &changeData
);
8794 if (changeData
->mFrame
) {
8795 propTable
->SetProperty(changeData
->mFrame
,
8796 nsGkAtoms::changeListProperty
,
8797 nsnull
, nsnull
, nsnull
);
8802 while (0 <= --index
) {
8804 nsIContent
* content
;
8806 aChangeList
.ChangeAt(index
, frame
, content
, hint
);
8807 if (frame
&& frame
->GetContent() != content
) {
8808 // XXXbz this is due to image maps messing with the primary frame map.
8809 // See bug 135040. Remove this block once that's fixed.
8811 if (!(hint
& nsChangeHint_ReconstructFrame
)) {
8816 // skip any frame that has been destroyed due to a ripple effect
8820 propTable
->GetProperty(frame
, nsGkAtoms::changeListProperty
, &res
);
8822 if (NS_PROPTABLE_PROP_NOT_THERE
== res
)
8826 if (hint
& nsChangeHint_ReconstructFrame
) {
8827 RecreateFramesForContent(content
);
8829 NS_ASSERTION(frame
, "This shouldn't happen");
8831 if (hint
& nsChangeHint_UpdateEffects
) {
8832 nsSVGEffects::UpdateEffects(frame
);
8835 if (hint
& nsChangeHint_ReflowFrame
) {
8836 StyleChangeReflow(frame
);
8838 if (hint
& (nsChangeHint_RepaintFrame
| nsChangeHint_SyncFrameView
)) {
8839 ApplyRenderingChangeToTree(mPresShell
->GetPresContext(), frame
, hint
);
8841 if (hint
& nsChangeHint_UpdateCursor
) {
8842 nsIViewManager
* viewMgr
= mPresShell
->GetViewManager();
8844 viewMgr
->SynthesizeMouseMove(PR_FALSE
);
8851 // cleanup references and verify the style tree. Note that the latter needs
8852 // to happen once we've processed the whole list, since until then the tree
8853 // is not in fact in a consistent state.
8855 while (0 <= --index
) {
8856 const nsStyleChangeData
* changeData
;
8857 aChangeList
.ChangeAt(index
, &changeData
);
8858 if (changeData
->mFrame
) {
8859 propTable
->DeleteProperty(changeData
->mFrame
,
8860 nsGkAtoms::changeListProperty
);
8864 // reget frame from content since it may have been regenerated...
8865 if (changeData
->mContent
) {
8866 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(changeData
->mContent
);
8868 mPresShell
->FrameManager()->DebugVerifyStyleTree(frame
);
8871 NS_WARNING("Unable to test style tree integrity -- no content node");
8876 aChangeList
.Clear();
8881 nsCSSFrameConstructor::RestyleElement(nsIContent
*aContent
,
8882 nsIFrame
*aPrimaryFrame
,
8883 nsChangeHint aMinHint
)
8885 NS_ASSERTION(aPrimaryFrame
== mPresShell
->GetPrimaryFrameFor(aContent
),
8886 "frame/content mismatch");
8887 if (aPrimaryFrame
&& aPrimaryFrame
->GetContent() != aContent
) {
8888 // XXXbz this is due to image maps messing with the primary frame mapping.
8889 // See bug 135040. We can remove this block once that's fixed.
8890 aPrimaryFrame
= nsnull
;
8892 NS_ASSERTION(!aPrimaryFrame
|| aPrimaryFrame
->GetContent() == aContent
,
8893 "frame/content mismatch");
8895 if (aMinHint
& nsChangeHint_ReconstructFrame
) {
8896 RecreateFramesForContent(aContent
);
8897 } else if (aPrimaryFrame
) {
8898 nsStyleChangeList changeList
;
8899 mPresShell
->FrameManager()->
8900 ComputeStyleChangeFor(aPrimaryFrame
, &changeList
, aMinHint
);
8901 ProcessRestyledFrames(changeList
);
8903 // no frames, reconstruct for content
8904 MaybeRecreateFramesForContent(aContent
);
8909 nsCSSFrameConstructor::RestyleLaterSiblings(nsIContent
*aContent
)
8911 nsIContent
*parent
= aContent
->GetParent();
8913 return; // root element has no later siblings
8915 for (PRInt32 index
= parent
->IndexOf(aContent
) + 1,
8916 index_end
= parent
->GetChildCount();
8917 index
!= index_end
; ++index
) {
8918 nsIContent
*child
= parent
->GetChildAt(index
);
8919 if (!child
->IsNodeOfType(nsINode::eELEMENT
))
8922 nsIFrame
* primaryFrame
= mPresShell
->GetPrimaryFrameFor(child
);
8923 RestyleElement(child
, primaryFrame
, NS_STYLE_HINT_NONE
);
8928 nsCSSFrameConstructor::ContentStatesChanged(nsIContent
* aContent1
,
8929 nsIContent
* aContent2
,
8932 DoContentStateChanged(aContent1
, aStateMask
);
8933 DoContentStateChanged(aContent2
, aStateMask
);
8938 nsCSSFrameConstructor::DoContentStateChanged(nsIContent
* aContent
,
8941 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
8942 nsPresContext
*presContext
= mPresShell
->GetPresContext();
8943 NS_ASSERTION(styleSet
, "couldn't get style set");
8946 nsChangeHint hint
= NS_STYLE_HINT_NONE
;
8947 // Any change to a content state that affects which frames we construct
8948 // must lead to a frame reconstruct here if we already have a frame.
8949 // Note that we never decide through non-CSS means to not create frames
8950 // based on content states, so if we already don't have a frame we don't
8951 // need to force a reframe -- if it's needed, the HasStateDependentStyle
8952 // call will handle things.
8953 nsIFrame
* primaryFrame
= mPresShell
->GetPrimaryFrameFor(aContent
);
8955 // If it's generated content, ignore LOADING/etc state changes on it.
8956 if (!primaryFrame
->IsGeneratedContentFrame() &&
8957 (aStateMask
& (NS_EVENT_STATE_BROKEN
| NS_EVENT_STATE_USERDISABLED
|
8958 NS_EVENT_STATE_SUPPRESSED
| NS_EVENT_STATE_LOADING
))) {
8959 hint
= nsChangeHint_ReconstructFrame
;
8961 PRUint8 app
= primaryFrame
->GetStyleDisplay()->mAppearance
;
8963 nsITheme
*theme
= presContext
->GetTheme();
8964 if (theme
&& theme
->ThemeSupportsWidget(presContext
,
8965 primaryFrame
, app
)) {
8966 PRBool repaint
= PR_FALSE
;
8967 theme
->WidgetStateChanged(primaryFrame
, app
, nsnull
, &repaint
);
8969 NS_UpdateHint(hint
, nsChangeHint_RepaintFrame
);
8976 nsReStyleHint rshint
=
8977 styleSet
->HasStateDependentStyle(presContext
, aContent
, aStateMask
);
8979 if ((aStateMask
& NS_EVENT_STATE_HOVER
) && rshint
!= 0) {
8983 PostRestyleEvent(aContent
, rshint
, hint
);
8988 nsCSSFrameConstructor::AttributeChanged(nsIContent
* aContent
,
8989 PRInt32 aNameSpaceID
,
8990 nsIAtom
* aAttribute
,
8992 PRUint32 aStateMask
)
8994 nsresult result
= NS_OK
;
8996 // Hold onto the PresShell to prevent ourselves from being destroyed.
8997 // XXXbz how, exactly, would this attribute change cause us to be
8998 // destroyed from inside this function?
8999 nsCOMPtr
<nsIPresShell
> shell
= mPresShell
;
9001 // Get the frame associated with the content which is the highest in the frame tree
9002 nsIFrame
* primaryFrame
= shell
->GetPrimaryFrameFor(aContent
);
9005 NS_FRAME_LOG(NS_FRAME_TRACE_CALLS
,
9006 ("HTMLStyleSheet::AttributeChanged: content=%p[%s] frame=%p",
9007 aContent
, ContentTag(aContent
, 0), frame
));
9010 // the style tag has its own interpretation based on aHint
9011 nsChangeHint hint
= aContent
->GetAttributeChangeHint(aAttribute
, aModType
);
9013 PRBool reframe
= (hint
& nsChangeHint_ReconstructFrame
) != 0;
9016 // The following listbox widget trap prevents offscreen listbox widget
9017 // content from being removed and re-inserted (which is what would
9018 // happen otherwise).
9019 if (!primaryFrame
&& !reframe
) {
9020 PRInt32 namespaceID
;
9022 mDocument
->BindingManager()->ResolveTag(aContent
, &namespaceID
);
9024 if (namespaceID
== kNameSpaceID_XUL
&&
9025 (tag
== nsGkAtoms::listitem
||
9026 tag
== nsGkAtoms::listcell
))
9030 if (aAttribute
== nsGkAtoms::tooltiptext
||
9031 aAttribute
== nsGkAtoms::tooltip
)
9033 nsIRootBox
* rootBox
= nsIRootBox::GetRootBox(mPresShell
);
9035 if (aModType
== nsIDOMMutationEvent::REMOVAL
)
9036 rootBox
->RemoveTooltipSupport(aContent
);
9037 if (aModType
== nsIDOMMutationEvent::ADDITION
)
9038 rootBox
->AddTooltipSupport(aContent
);
9045 // See if we have appearance information for a theme.
9046 const nsStyleDisplay
* disp
= primaryFrame
->GetStyleDisplay();
9047 if (disp
->mAppearance
) {
9048 nsPresContext
* presContext
= mPresShell
->GetPresContext();
9049 nsITheme
*theme
= presContext
->GetTheme();
9050 if (theme
&& theme
->ThemeSupportsWidget(presContext
, primaryFrame
, disp
->mAppearance
)) {
9051 PRBool repaint
= PR_FALSE
;
9052 theme
->WidgetStateChanged(primaryFrame
, disp
->mAppearance
, aAttribute
, &repaint
);
9054 NS_UpdateHint(hint
, nsChangeHint_RepaintFrame
);
9058 // let the frame deal with it now, so we don't have to deal later
9059 result
= primaryFrame
->AttributeChanged(aNameSpaceID
, aAttribute
,
9061 // XXXwaterson should probably check for special IB siblings
9062 // here, and propagate the AttributeChanged notification to
9063 // them, as well. Currently, inline frames don't do anything on
9064 // this notification, so it's not that big a deal.
9067 // See if we can optimize away the style re-resolution -- must be called after
9068 // the frame's AttributeChanged() in case it does something that affects the style
9069 nsFrameManager
*frameManager
= shell
->FrameManager();
9070 nsReStyleHint rshint
= frameManager
->HasAttributeDependentStyle(aContent
,
9075 PostRestyleEvent(aContent
, rshint
, hint
);
9081 nsCSSFrameConstructor::BeginUpdate() {
9082 NS_SuppressFocusEvent();
9083 ++mFocusSuppressCount
;
9088 nsCSSFrameConstructor::EndUpdate()
9090 if (mUpdateCount
== 1) {
9091 // This is the end of our last update. Before we decrement
9092 // mUpdateCount, recalc quotes and counters as needed.
9094 RecalcQuotesAndCounters();
9095 NS_ASSERTION(mUpdateCount
== 1, "Odd update count");
9098 if (mFocusSuppressCount
) {
9099 NS_UnsuppressFocusEvent();
9100 --mFocusSuppressCount
;
9105 nsCSSFrameConstructor::RecalcQuotesAndCounters()
9108 mQuotesDirty
= PR_FALSE
;
9109 mQuoteList
.RecalcAll();
9112 if (mCountersDirty
) {
9113 mCountersDirty
= PR_FALSE
;
9114 mCounterManager
.RecalcAll();
9117 NS_ASSERTION(!mQuotesDirty
, "Quotes updates will be lost");
9118 NS_ASSERTION(!mCountersDirty
, "Counter updates will be lost");
9121 class nsFocusUnsuppressEvent
: public nsRunnable
{
9124 nsFocusUnsuppressEvent(PRUint32 aCount
) : mCount(aCount
) {}
9129 NS_IMETHODIMP
nsFocusUnsuppressEvent::Run()
9133 NS_UnsuppressFocusEvent();
9139 nsCSSFrameConstructor::WillDestroyFrameTree(PRBool aDestroyingPresShell
)
9141 #if defined(DEBUG_dbaron_off)
9142 mCounterManager
.Dump();
9145 mIsDestroyingFrameTree
= PR_TRUE
;
9147 // Prevent frame tree destruction from being O(N^2)
9149 mCounterManager
.Clear();
9151 // Cancel all pending re-resolves
9152 mRestyleEvent
.Revoke();
9154 if (mFocusSuppressCount
&& aDestroyingPresShell
) {
9155 nsRefPtr
<nsFocusUnsuppressEvent
> ev
=
9156 new nsFocusUnsuppressEvent(mFocusSuppressCount
);
9157 if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev
))) {
9158 mFocusSuppressCount
= 0;
9165 // XXXbz I'd really like this method to go away. Once we have inline-block and
9166 // I can just use that for sized broken images, that can happen, maybe.
9167 void nsCSSFrameConstructor::GetAlternateTextFor(nsIContent
* aContent
,
9168 nsIAtom
* aTag
, // content object's tag
9169 nsXPIDLString
& aAltText
)
9171 // The "alt" attribute specifies alternate text that is rendered
9172 // when the image can not be displayed
9174 // If there's no "alt" attribute, and aContent is an input
9175 // element, then use the value of the "value" attribute
9176 if (!aContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::alt
, aAltText
) &&
9177 nsGkAtoms::input
== aTag
) {
9178 // If there's no "value" attribute either, then use the localized string
9179 // for "Submit" as the alternate text.
9180 if (!aContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::value
, aAltText
)) {
9181 nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES
,
9182 "Submit", aAltText
);
9188 nsCSSFrameConstructor::CreateContinuingOuterTableFrame(nsIPresShell
* aPresShell
,
9189 nsPresContext
* aPresContext
,
9191 nsIFrame
* aParentFrame
,
9192 nsIContent
* aContent
,
9193 nsStyleContext
* aStyleContext
,
9194 nsIFrame
** aContinuingFrame
)
9196 nsIFrame
* newFrame
= NS_NewTableOuterFrame(aPresShell
, aStyleContext
);
9199 newFrame
->Init(aContent
, aParentFrame
, aFrame
);
9200 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9202 // Create a continuing inner table frame, and if there's a caption then
9203 // replicate the caption
9204 nsFrameItems newChildFrames
;
9206 nsIFrame
* childFrame
= aFrame
->GetFirstChild(nsnull
);
9208 nsIFrame
* continuingTableFrame
;
9209 nsresult rv
= CreateContinuingFrame(aPresContext
, childFrame
, newFrame
,
9210 &continuingTableFrame
);
9211 if (NS_FAILED(rv
)) {
9212 newFrame
->Destroy();
9213 *aContinuingFrame
= nsnull
;
9216 newChildFrames
.AddChild(continuingTableFrame
);
9218 NS_ASSERTION(!childFrame
->GetNextSibling(),"there can be only one inner table frame");
9221 // Set the outer table's initial child list
9222 newFrame
->SetInitialChildList(nsnull
, newChildFrames
.childList
);
9224 *aContinuingFrame
= newFrame
;
9228 *aContinuingFrame
= nsnull
;
9229 return NS_ERROR_OUT_OF_MEMORY
;
9234 nsCSSFrameConstructor::CreateContinuingTableFrame(nsIPresShell
* aPresShell
,
9235 nsPresContext
* aPresContext
,
9237 nsIFrame
* aParentFrame
,
9238 nsIContent
* aContent
,
9239 nsStyleContext
* aStyleContext
,
9240 nsIFrame
** aContinuingFrame
)
9242 nsIFrame
* newFrame
= NS_NewTableFrame(aPresShell
, aStyleContext
);
9245 newFrame
->Init(aContent
, aParentFrame
, aFrame
);
9246 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9248 // Replicate any header/footer frames
9249 nsFrameItems childFrames
;
9250 nsIFrame
* childFrame
= aFrame
->GetFirstChild(nsnull
);
9251 for ( ; childFrame
; childFrame
= childFrame
->GetNextSibling()) {
9252 // See if it's a header/footer, possibly wrapped in a scroll frame.
9253 nsTableRowGroupFrame
* rowGroupFrame
=
9254 nsTableFrame::GetRowGroupFrame(childFrame
);
9255 if (rowGroupFrame
) {
9256 // If the row group was continued, then don't replicate it.
9257 nsIFrame
* rgNextInFlow
= rowGroupFrame
->GetNextInFlow();
9259 rowGroupFrame
->SetRepeatable(PR_FALSE
);
9261 else if (rowGroupFrame
->IsRepeatable()) {
9262 // Replicate the header/footer frame.
9263 nsTableRowGroupFrame
* headerFooterFrame
;
9264 nsFrameItems childItems
;
9265 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
9266 GetAbsoluteContainingBlock(newFrame
),
9269 headerFooterFrame
= static_cast<nsTableRowGroupFrame
*>
9270 (NS_NewTableRowGroupFrame(aPresShell
, rowGroupFrame
->GetStyleContext()));
9271 nsIContent
* headerFooter
= rowGroupFrame
->GetContent();
9272 headerFooterFrame
->Init(headerFooter
, newFrame
, nsnull
);
9273 ProcessChildren(state
, headerFooter
, rowGroupFrame
->GetStyleContext(),
9274 headerFooterFrame
, PR_TRUE
, childItems
, PR_FALSE
);
9275 NS_ASSERTION(!state
.mFloatedItems
.childList
, "unexpected floated element");
9276 headerFooterFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
9277 headerFooterFrame
->SetRepeatable(PR_TRUE
);
9279 // Table specific initialization
9280 headerFooterFrame
->InitRepeatedFrame(aPresContext
, rowGroupFrame
);
9282 // XXX Deal with absolute and fixed frames...
9283 childFrames
.AddChild(headerFooterFrame
);
9288 // Set the table frame's initial child list
9289 newFrame
->SetInitialChildList(nsnull
, childFrames
.childList
);
9291 *aContinuingFrame
= newFrame
;
9295 *aContinuingFrame
= nsnull
;
9296 return NS_ERROR_OUT_OF_MEMORY
;
9301 nsCSSFrameConstructor::CreateContinuingFrame(nsPresContext
* aPresContext
,
9303 nsIFrame
* aParentFrame
,
9304 nsIFrame
** aContinuingFrame
,
9307 nsIPresShell
* shell
= aPresContext
->PresShell();
9308 nsStyleContext
* styleContext
= aFrame
->GetStyleContext();
9309 nsIFrame
* newFrame
= nsnull
;
9310 nsresult rv
= NS_OK
;
9311 nsIFrame
* nextContinuation
= aFrame
->GetNextContinuation();
9312 nsIFrame
* nextInFlow
= aFrame
->GetNextInFlow();
9314 // Use the frame type to determine what type of frame to create
9315 nsIAtom
* frameType
= aFrame
->GetType();
9316 nsIContent
* content
= aFrame
->GetContent();
9318 NS_ASSERTION(aFrame
->GetSplittableType() != NS_FRAME_NOT_SPLITTABLE
,
9319 "why CreateContinuingFrame for a non-splittable frame?");
9321 if (nsGkAtoms::textFrame
== frameType
) {
9322 newFrame
= NS_NewContinuingTextFrame(shell
, styleContext
);
9325 newFrame
->Init(content
, aParentFrame
, aFrame
);
9326 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9329 } else if (nsGkAtoms::inlineFrame
== frameType
) {
9330 newFrame
= NS_NewInlineFrame(shell
, styleContext
);
9333 newFrame
->Init(content
, aParentFrame
, aFrame
);
9334 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9337 } else if (nsGkAtoms::blockFrame
== frameType
) {
9338 newFrame
= NS_NewBlockFrame(shell
, styleContext
);
9341 newFrame
->Init(content
, aParentFrame
, aFrame
);
9342 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9346 } else if (nsGkAtoms::XULLabelFrame
== frameType
) {
9347 newFrame
= NS_NewXULLabelFrame(shell
, styleContext
);
9350 newFrame
->Init(content
, aParentFrame
, aFrame
);
9351 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9354 } else if (nsGkAtoms::columnSetFrame
== frameType
) {
9355 newFrame
= NS_NewColumnSetFrame(shell
, styleContext
, 0);
9358 newFrame
->Init(content
, aParentFrame
, aFrame
);
9359 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9362 } else if (nsGkAtoms::positionedInlineFrame
== frameType
) {
9363 newFrame
= NS_NewPositionedInlineFrame(shell
, styleContext
);
9366 newFrame
->Init(content
, aParentFrame
, aFrame
);
9367 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9370 } else if (nsGkAtoms::pageFrame
== frameType
) {
9371 nsIFrame
* canvasFrame
;
9372 rv
= ConstructPageFrame(shell
, aPresContext
, aParentFrame
, aFrame
,
9373 newFrame
, canvasFrame
);
9374 } else if (nsGkAtoms::tableOuterFrame
== frameType
) {
9375 rv
= CreateContinuingOuterTableFrame(shell
, aPresContext
, aFrame
, aParentFrame
,
9376 content
, styleContext
, &newFrame
);
9378 } else if (nsGkAtoms::tableFrame
== frameType
) {
9379 rv
= CreateContinuingTableFrame(shell
, aPresContext
, aFrame
, aParentFrame
,
9380 content
, styleContext
, &newFrame
);
9382 } else if (nsGkAtoms::tableRowGroupFrame
== frameType
) {
9383 newFrame
= NS_NewTableRowGroupFrame(shell
, styleContext
);
9386 newFrame
->Init(content
, aParentFrame
, aFrame
);
9387 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9390 } else if (nsGkAtoms::tableRowFrame
== frameType
) {
9391 newFrame
= NS_NewTableRowFrame(shell
, styleContext
);
9394 newFrame
->Init(content
, aParentFrame
, aFrame
);
9395 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9397 // Create a continuing frame for each table cell frame
9398 nsFrameItems newChildList
;
9399 nsIFrame
* cellFrame
= aFrame
->GetFirstChild(nsnull
);
9401 // See if it's a table cell frame
9402 if (IS_TABLE_CELL(cellFrame
->GetType())) {
9403 nsIFrame
* continuingCellFrame
;
9404 rv
= CreateContinuingFrame(aPresContext
, cellFrame
, newFrame
,
9405 &continuingCellFrame
);
9406 if (NS_FAILED(rv
)) {
9407 nsFrameList
tmp(newChildList
.childList
);
9408 tmp
.DestroyFrames();
9409 newFrame
->Destroy();
9410 *aContinuingFrame
= nsnull
;
9411 return NS_ERROR_OUT_OF_MEMORY
;
9413 newChildList
.AddChild(continuingCellFrame
);
9415 cellFrame
= cellFrame
->GetNextSibling();
9418 // Set the table cell's initial child list
9419 newFrame
->SetInitialChildList(nsnull
, newChildList
.childList
);
9422 } else if (IS_TABLE_CELL(frameType
)) {
9423 // Warning: If you change this and add a wrapper frame around table cell
9424 // frames, make sure Bug 368554 doesn't regress!
9425 // See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp.
9426 newFrame
= NS_NewTableCellFrame(shell
, styleContext
, IsBorderCollapse(aParentFrame
));
9429 newFrame
->Init(content
, aParentFrame
, aFrame
);
9430 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9432 // Create a continuing area frame
9433 nsIFrame
* continuingBlockFrame
;
9434 nsIFrame
* blockFrame
= aFrame
->GetFirstChild(nsnull
);
9435 rv
= CreateContinuingFrame(aPresContext
, blockFrame
, newFrame
,
9436 &continuingBlockFrame
);
9437 if (NS_FAILED(rv
)) {
9438 newFrame
->Destroy();
9439 *aContinuingFrame
= nsnull
;
9443 // Set the table cell's initial child list
9444 newFrame
->SetInitialChildList(nsnull
, continuingBlockFrame
);
9447 } else if (nsGkAtoms::lineFrame
== frameType
) {
9448 newFrame
= NS_NewFirstLineFrame(shell
, styleContext
);
9451 newFrame
->Init(content
, aParentFrame
, aFrame
);
9452 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9455 } else if (nsGkAtoms::letterFrame
== frameType
) {
9456 newFrame
= NS_NewFirstLetterFrame(shell
, styleContext
);
9459 newFrame
->Init(content
, aParentFrame
, aFrame
);
9460 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9463 } else if (nsGkAtoms::imageFrame
== frameType
) {
9464 newFrame
= NS_NewImageFrame(shell
, styleContext
);
9467 newFrame
->Init(content
, aParentFrame
, aFrame
);
9469 } else if (nsGkAtoms::imageControlFrame
== frameType
) {
9470 newFrame
= NS_NewImageControlFrame(shell
, styleContext
);
9473 newFrame
->Init(content
, aParentFrame
, aFrame
);
9475 } else if (nsGkAtoms::placeholderFrame
== frameType
) {
9476 // create a continuing out of flow frame
9477 nsIFrame
* oofFrame
= nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame
);
9478 nsIFrame
* oofContFrame
;
9479 rv
= CreateContinuingFrame(aPresContext
, oofFrame
, aParentFrame
, &oofContFrame
);
9480 if (NS_FAILED(rv
)) {
9481 *aContinuingFrame
= nsnull
;
9484 // create a continuing placeholder frame
9485 rv
= CreatePlaceholderFrameFor(shell
, content
, oofContFrame
, styleContext
,
9486 aParentFrame
, aFrame
, &newFrame
);
9487 if (NS_FAILED(rv
)) {
9488 oofContFrame
->Destroy();
9489 *aContinuingFrame
= nsnull
;
9492 } else if (nsGkAtoms::fieldSetFrame
== frameType
) {
9493 newFrame
= NS_NewFieldSetFrame(shell
, styleContext
);
9496 newFrame
->Init(content
, aParentFrame
, aFrame
);
9498 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9500 // Create a continuing area frame
9501 // XXXbz we really shouldn't have to do this by hand!
9502 nsIFrame
* continuingBlockFrame
;
9503 nsIFrame
* blockFrame
= GetFieldSetBlockFrame(aFrame
);
9504 rv
= CreateContinuingFrame(aPresContext
, blockFrame
, newFrame
,
9505 &continuingBlockFrame
);
9506 if (NS_FAILED(rv
)) {
9507 newFrame
->Destroy();
9508 *aContinuingFrame
= nsnull
;
9511 // Set the fieldset's initial child list
9512 newFrame
->SetInitialChildList(nsnull
, continuingBlockFrame
);
9514 } else if (nsGkAtoms::legendFrame
== frameType
) {
9515 newFrame
= NS_NewLegendFrame(shell
, styleContext
);
9518 newFrame
->Init(content
, aParentFrame
, aFrame
);
9519 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
9522 NS_NOTREACHED("unexpected frame type");
9523 *aContinuingFrame
= nsnull
;
9524 return NS_ERROR_UNEXPECTED
;
9527 *aContinuingFrame
= newFrame
;
9530 return NS_ERROR_OUT_OF_MEMORY
;
9533 // Init() set newFrame to be a fluid continuation of aFrame.
9534 // If we want a non-fluid continuation, we need to call SetPrevContinuation()
9535 // to reset NS_FRAME_IS_FLUID_CONTINUATION.
9537 newFrame
->SetPrevContinuation(aFrame
);
9540 // A continuation of generated content is also generated content
9541 if (aFrame
->GetStateBits() & NS_FRAME_GENERATED_CONTENT
) {
9542 newFrame
->AddStateBits(NS_FRAME_GENERATED_CONTENT
);
9545 // A continuation of an out-of-flow is also an out-of-flow
9546 if (aFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
) {
9547 newFrame
->AddStateBits(NS_FRAME_OUT_OF_FLOW
);
9551 nextInFlow
->SetPrevInFlow(newFrame
);
9552 newFrame
->SetNextInFlow(nextInFlow
);
9553 } else if (nextContinuation
) {
9554 nextContinuation
->SetPrevContinuation(newFrame
);
9555 newFrame
->SetNextContinuation(nextContinuation
);
9561 nsCSSFrameConstructor::ReplicateFixedFrames(nsPageContentFrame
* aParentFrame
)
9563 // Now deal with fixed-pos things.... They should appear on all pages,
9564 // so we want to move over the placeholders when processing the child
9565 // of the pageContentFrame.
9567 nsIFrame
* prevPageContentFrame
= aParentFrame
->GetPrevInFlow();
9568 if (!prevPageContentFrame
) {
9571 nsIFrame
* canvasFrame
= aParentFrame
->GetFirstChild(nsnull
);
9572 nsIFrame
* prevCanvasFrame
= prevPageContentFrame
->GetFirstChild(nsnull
);
9573 if (!canvasFrame
|| !prevCanvasFrame
) {
9574 // document's root element frame missing
9575 return NS_ERROR_UNEXPECTED
;
9578 nsFrameItems fixedPlaceholders
;
9579 nsIFrame
* firstFixed
= prevPageContentFrame
->GetFirstChild(nsGkAtoms::fixedList
);
9584 // Don't allow abs-pos descendants of the fixed content to escape the content.
9585 // This should not normally be possible (because fixed-pos elements should
9586 // be absolute containers) but fixed-pos tables currently aren't abs-pos
9588 nsFrameConstructorState
state(mPresShell
, aParentFrame
,
9592 // Iterate across fixed frames and replicate each whose placeholder is a
9593 // descendant of aFrame. (We don't want to explicitly copy placeholders that
9594 // are within fixed frames, because that would cause duplicates on the new
9595 // page - bug 389619)
9596 for (nsIFrame
* fixed
= firstFixed
; fixed
; fixed
= fixed
->GetNextSibling()) {
9597 nsIFrame
* prevPlaceholder
= nsnull
;
9598 mPresShell
->GetPlaceholderFrameFor(fixed
, &prevPlaceholder
);
9599 if (prevPlaceholder
&&
9600 nsLayoutUtils::IsProperAncestorFrame(prevCanvasFrame
, prevPlaceholder
)) {
9601 nsresult rv
= ConstructFrame(state
, fixed
->GetContent(),
9602 canvasFrame
, fixedPlaceholders
);
9603 NS_ENSURE_SUCCESS(rv
, rv
);
9607 // Add the placeholders to our primary child list.
9608 // XXXbz this is a little screwed up, since the fixed frames will have
9609 // broken auto-positioning. Oh, well.
9610 NS_ASSERTION(!canvasFrame
->GetFirstChild(nsnull
),
9611 "leaking frames; doc root continuation must be empty");
9612 canvasFrame
->SetInitialChildList(nsnull
, fixedPlaceholders
.childList
);
9617 IsBindingAncestor(nsIContent
* aContent
, nsIContent
* aBindingRoot
)
9620 // Native-anonymous content doesn't contain insertion points, so
9621 // we don't need to search through it.
9622 if (aContent
->IsRootOfNativeAnonymousSubtree())
9624 nsIContent
* bindingParent
= aContent
->GetBindingParent();
9627 if (bindingParent
== aBindingRoot
)
9629 aContent
= bindingParent
;
9633 // Helper function that searches the immediate child frames
9634 // (and their children if the frames are "special")
9635 // for a frame that maps the specified content object
9637 nsCSSFrameConstructor::FindFrameWithContent(nsFrameManager
* aFrameManager
,
9638 nsIFrame
* aParentFrame
,
9639 nsIContent
* aParentContent
,
9640 nsIContent
* aContent
,
9641 nsFindFrameHint
* aHint
)
9643 NS_PRECONDITION(aParentFrame
, "Must have a frame");
9645 #ifdef NOISY_FINDFRAME
9647 printf("looking for content=%p, given aParentFrame %p parentContent %p, hint is %s\n",
9648 aContent
, aParentFrame
, aParentContent
, aHint
? "set" : "NULL");
9651 // Search for the frame in each child list that aParentFrame supports.
9652 nsIAtom
* listName
= nsnull
;
9653 PRInt32 listIndex
= 0;
9657 #ifdef NOISY_FINDFRAME
9660 nsIFrame
* kidFrame
= nsnull
;
9662 searchAgain
= PR_FALSE
;
9664 // if we were given an hint, try to use it here to find a good
9665 // previous frame to start our search (|kidFrame|).
9667 #ifdef NOISY_FINDFRAME
9668 printf(" hint frame is %p\n", aHint
->mPrimaryFrameForPrevSibling
);
9670 // start with the primary frame for aContent's previous sibling
9671 kidFrame
= aHint
->mPrimaryFrameForPrevSibling
;
9672 // But if it's out of flow, start from its placeholder.
9673 if (kidFrame
&& (kidFrame
->GetStateBits() & NS_FRAME_OUT_OF_FLOW
)) {
9674 kidFrame
= aFrameManager
->GetPlaceholderFrameFor(kidFrame
);
9678 // then use the next sibling frame as our starting point
9679 if (kidFrame
->GetNextSibling()) {
9680 kidFrame
= kidFrame
->GetNextSibling();
9683 // The hint frame had no next sibling. Try the next-in-flow or
9684 // special sibling of the parent of the hint frame (or its
9685 // associated placeholder).
9686 nsIFrame
*parentFrame
= kidFrame
->GetParent();
9689 parentFrame
= nsLayoutUtils::GetNextContinuationOrSpecialSibling(parentFrame
);
9692 // Found it, continue the search with its first child.
9693 kidFrame
= parentFrame
->GetFirstChild(listName
);
9694 // Leave |aParentFrame| as-is, since the only time we'll
9695 // reuse it is if the hint fails.
9698 #ifdef NOISY_FINDFRAME
9699 printf(" hint gives us kidFrame=%p with parent frame %p content %p\n",
9700 kidFrame
, aParentFrame
, aParentContent
);
9704 if (!kidFrame
) { // we didn't have enough info to prune, start searching from the beginning
9705 kidFrame
= aParentFrame
->GetFirstChild(listName
);
9708 // See if the child frame points to the content object we're
9710 nsIContent
* kidContent
= kidFrame
->GetContent();
9711 if (kidContent
== aContent
) {
9712 // We found a match. Return the out-of-flow if it's a placeholder.
9713 return nsPlaceholderFrame::GetRealFrameFor(kidFrame
);
9716 // only do this if there is content
9718 // We search the immediate children only, but if the child frame has
9719 // the same content pointer as its parent then we need to search its
9720 // child frames, too.
9721 // We also need to search if the child content is anonymous and scoped
9722 // to the parent content.
9723 // XXXldb What makes us continue the search once we're inside
9724 // the anonymous subtree?
9725 if (aParentContent
== kidContent
||
9726 (aParentContent
&& IsBindingAncestor(kidContent
, aParentContent
))) {
9727 #ifdef NOISY_FINDFRAME
9729 printf(" recursing with new parent set to kidframe=%p, parentContent=%p\n",
9730 kidFrame
, aParentContent
);
9732 nsIFrame
* matchingFrame
=
9733 FindFrameWithContent(aFrameManager
,
9734 nsPlaceholderFrame::GetRealFrameFor(kidFrame
),
9735 aParentContent
, aContent
, nsnull
);
9737 if (matchingFrame
) {
9738 return matchingFrame
;
9743 kidFrame
= kidFrame
->GetNextSibling();
9745 #ifdef NOISY_FINDFRAME
9748 printf(" searching sibling frame %p\n", kidFrame
);
9754 // If we get here, and we had a hint, then we didn't find a frame.
9755 // The hint may have been a frame whose location in the frame tree
9756 // doesn't match the location of its corresponding element in the
9757 // DOM tree, e.g. a floated or absolutely positioned frame, or e.g.
9758 // a <col> frame, in which case we'd be off in the weeds looking
9759 // through something other than the primary frame list.
9760 // Reboot the search from scratch, without the hint, but using the
9761 // null child list again.
9763 searchAgain
= PR_TRUE
;
9767 listName
= aParentFrame
->GetAdditionalChildListName(listIndex
++);
9768 } while (IsOutOfFlowList(listName
));
9770 } while (listName
|| searchAgain
);
9775 // Request to find the primary frame associated with a given content object.
9776 // This is typically called by the pres shell when there is no mapping in
9777 // the pres shell hash table
9779 nsCSSFrameConstructor::FindPrimaryFrameFor(nsFrameManager
* aFrameManager
,
9780 nsIContent
* aContent
,
9782 nsFindFrameHint
* aHint
)
9784 NS_ASSERTION(aFrameManager
&& aContent
&& aFrame
, "bad arg");
9786 *aFrame
= nsnull
; // initialize OUT parameter
9788 // We want to be able to quickly map from a content object to its frame,
9789 // but we also want to keep the hash table small. Therefore, many frames
9790 // are not added to the hash table when they're first created:
9792 // - inline frames (often things like FONT and B)
9794 // - internal table frames (row-group, row, cell, col-group, col)
9796 // That means we need to need to search for the frame
9797 nsIFrame
* parentFrame
; // this pointer is used to iterate across all frames that map to parentContent
9799 // Get the frame that corresponds to the parent content object.
9800 // Note that this may recurse indirectly, because the pres shell will
9801 // call us back if there is no mapping in the hash table
9802 nsCOMPtr
<nsIContent
> parentContent
= aContent
->GetParent(); // Get this once
9803 if (parentContent
) {
9804 parentFrame
= aFrameManager
->GetPrimaryFrameFor(parentContent
, -1);
9805 while (parentFrame
) {
9806 // Search the child frames for a match
9807 *aFrame
= FindFrameWithContent(aFrameManager
, parentFrame
,
9808 parentContent
, aContent
, aHint
);
9809 #ifdef NOISY_FINDFRAME
9810 printf("FindFrameWithContent returned %p\n", *aFrame
);
9814 // if we're given a hint and we were told to verify, then compare the resulting frame with
9815 // the frame we get by calling FindFrameWithContent *without* the hint.
9816 // Assert if they do not match
9817 // Note that this makes finding frames *slower* than it was before the fix.
9818 if (gVerifyFastFindFrame
&& aHint
) {
9819 #ifdef NOISY_FINDFRAME
9820 printf("VERIFYING...\n");
9822 nsIFrame
*verifyTestFrame
=
9823 FindFrameWithContent(aFrameManager
, parentFrame
,
9824 parentContent
, aContent
, nsnull
);
9825 #ifdef NOISY_FINDFRAME
9826 printf("VERIFY returned %p\n", verifyTestFrame
);
9828 NS_ASSERTION(verifyTestFrame
== *aFrame
, "hint shortcut found wrong frame");
9831 // If we found a match, then add a mapping to the hash table so
9832 // next time this will be quick
9834 aFrameManager
->SetPrimaryFrameFor(aContent
, *aFrame
);
9838 // We didn't find a matching frame. If parentFrame has a next-in-flow
9839 // or special sibling, then continue looking there.
9840 parentFrame
= nsLayoutUtils::GetNextContinuationOrSpecialSibling(parentFrame
);
9841 #ifdef NOISY_FINDFRAME
9844 printf(" searching NIF frame %p\n", parentFrame
);
9850 #ifdef NOISY_FINDFRAME
9851 printf("%10s %10s %10s %10s %10s\n",
9852 "total", "doLoop", "doSibling", "recur", "nextIF");
9853 printf("%10d %10d %10d %10d %10d\n",
9854 FFWC_totalCount
, FFWC_doLoop
, FFWC_doSibling
, FFWC_recursions
,
9862 nsCSSFrameConstructor::GetInsertionPoint(nsIFrame
* aParentFrame
,
9863 nsIContent
* aChildContent
,
9864 nsIFrame
** aInsertionPoint
,
9867 // Make the insertion point be the parent frame by default, in case
9868 // we have to bail early.
9869 *aInsertionPoint
= aParentFrame
;
9871 nsIContent
* container
= aParentFrame
->GetContent();
9875 nsBindingManager
*bindingManager
= mDocument
->BindingManager();
9877 nsIContent
* insertionElement
;
9878 if (aChildContent
) {
9879 // We've got an explicit insertion child. Check to see if it's
9881 if (aChildContent
->GetBindingParent() == container
) {
9882 // This child content is anonymous. Don't use the insertion
9883 // point, since that's only for the explicit kids.
9888 insertionElement
= bindingManager
->GetInsertionPoint(container
,
9895 insertionElement
= bindingManager
->GetSingleInsertionPoint(container
,
9898 if (multiple
&& aMultiple
)
9899 *aMultiple
= multiple
; // Record the fact that filters are in use.
9902 if (insertionElement
) {
9903 nsIFrame
* insertionPoint
= mPresShell
->GetPrimaryFrameFor(insertionElement
);
9904 if (insertionPoint
) {
9905 // Use the content insertion frame of the insertion point.
9906 insertionPoint
= insertionPoint
->GetContentInsertionFrame();
9907 if (insertionPoint
&& insertionPoint
!= aParentFrame
)
9908 GetInsertionPoint(insertionPoint
, aChildContent
, aInsertionPoint
, aMultiple
);
9911 // There was no frame created yet for the insertion point.
9912 *aInsertionPoint
= nsnull
;
9916 // fieldsets have multiple insertion points. Note that we might
9917 // have to look at insertionElement here...
9918 if (aMultiple
&& !*aMultiple
) {
9919 nsIContent
* content
= insertionElement
? insertionElement
: container
;
9920 if (content
->IsNodeOfType(nsINode::eHTML
) &&
9921 content
->Tag() == nsGkAtoms::fieldset
) {
9922 *aMultiple
= PR_TRUE
;
9929 // Capture state for the frame tree rooted at the frame associated with the
9930 // content object, aContent
9932 nsCSSFrameConstructor::CaptureStateForFramesOf(nsIContent
* aContent
,
9933 nsILayoutHistoryState
* aHistoryState
)
9935 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
9937 CaptureStateFor(frame
, aHistoryState
);
9942 // Capture state for the frame tree rooted at aFrame.
9944 nsCSSFrameConstructor::CaptureStateFor(nsIFrame
* aFrame
,
9945 nsILayoutHistoryState
* aHistoryState
)
9947 if (aFrame
&& aHistoryState
) {
9948 mPresShell
->FrameManager()->CaptureFrameState(aFrame
, aHistoryState
);
9954 nsCSSFrameConstructor::MaybeRecreateFramesForContent(nsIContent
* aContent
)
9956 nsresult result
= NS_OK
;
9957 nsFrameManager
*frameManager
= mPresShell
->FrameManager();
9959 nsStyleContext
*oldContext
= frameManager
->GetUndisplayedContent(aContent
);
9961 // The parent has a frame, so try resolving a new context.
9962 nsRefPtr
<nsStyleContext
> newContext
= mPresShell
->StyleSet()->
9963 ResolveStyleFor(aContent
, oldContext
->GetParent());
9965 frameManager
->ChangeUndisplayedContent(aContent
, newContext
);
9966 if (newContext
->GetStyleDisplay()->mDisplay
!= NS_STYLE_DISPLAY_NONE
) {
9967 result
= RecreateFramesForContent(aContent
);
9974 nsCSSFrameConstructor::MaybeRecreateContainerForIBSplitterFrame(nsIFrame
* aFrame
,
9977 NS_PRECONDITION(aFrame
, "Must have a frame");
9978 NS_PRECONDITION(aFrame
->GetParent(), "Frame shouldn't be root");
9979 NS_PRECONDITION(aResult
, "Null out param?");
9980 NS_PRECONDITION(aFrame
== aFrame
->GetFirstContinuation(),
9981 "aFrame not the result of GetPrimaryFrameFor()?");
9983 if (IsFrameSpecial(aFrame
)) {
9984 // The removal functions can't handle removal of an {ib} split directly; we
9985 // need to rebuild the containing block.
9987 if (gNoisyContentUpdates
) {
9988 printf("nsCSSFrameConstructor::MaybeRecreateContainerForIBSplitterFrame: "
9990 nsFrame::ListTag(stdout
, aFrame
);
9991 printf(" is special\n");
9995 *aResult
= ReframeContainingBlock(aFrame
);
9999 // We might still need to reconstruct things if the parent of aFrame is
10000 // special, since in that case the removal of aFrame might affect the
10001 // splitting of its parent.
10002 nsIFrame
* parent
= aFrame
->GetParent();
10003 if (!IsFrameSpecial(parent
)) {
10007 // If aFrame is an inline, then it cannot possibly have caused the splitting.
10008 // If the frame is being reconstructed and being changed to a block, the
10009 // ContentInserted call will handle the containing block reframe. So in this
10010 // case, try to be conservative about whether we need to reframe. The only
10011 // case when it's needed is if the inline is the only child of the tail end
10012 // of an {ib} split, because the splitting code doesn't produce this tail end
10013 // if it would have no kids. If that ever changes, this code should change.
10014 if (IsInlineOutside(aFrame
) &&
10016 // Not a kid of the third part of the IB split
10017 GetSpecialSibling(parent
) || !IsInlineOutside(parent
) ||
10018 // Or not the only child
10019 aFrame
->GetTailContinuation()->GetNextSibling() ||
10020 aFrame
!= parent
->GetFirstContinuation()->GetFirstChild(nsnull
)
10026 if (gNoisyContentUpdates
) {
10027 printf("nsCSSFrameConstructor::MaybeRecreateContainerForIBSplitterFrame: "
10029 nsFrame::ListTag(stdout
, parent
);
10030 printf(" is special\n");
10034 *aResult
= ReframeContainingBlock(parent
);
10039 nsCSSFrameConstructor::RecreateFramesForContent(nsIContent
* aContent
)
10041 // If there is no document, we don't want to recreate frames for it. (You
10042 // shouldn't generally be giving this method content without a document
10044 // Rebuilding the frame tree can have bad effects, especially if it's the
10045 // frame tree for chrome (see bug 157322).
10046 NS_ENSURE_TRUE(aContent
->GetDocument(), NS_ERROR_FAILURE
);
10048 // Is the frame `special'? If so, we need to reframe the containing
10049 // block *here*, rather than trying to remove and re-insert the
10050 // content (which would otherwise result in *two* nested reframe
10051 // containing block from ContentRemoved() and ContentInserted(),
10052 // below!). We'd really like to optimize away one of those
10053 // containing block reframes, hence the code here.
10055 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(aContent
);
10056 if (frame
&& frame
->IsFrameOfType(nsIFrame::eMathML
)) {
10057 // Reframe the topmost MathML element to prevent exponential blowup
10058 // (see bug 397518)
10060 nsIContent
* parentContent
= aContent
->GetParent();
10061 nsIFrame
* parentContentFrame
= mPresShell
->GetPrimaryFrameFor(parentContent
);
10062 if (!parentContentFrame
|| !parentContentFrame
->IsFrameOfType(nsIFrame::eMathML
))
10064 aContent
= parentContent
;
10065 frame
= parentContentFrame
;
10070 nsIFrame
* nonGeneratedAncestor
= nsLayoutUtils::GetNonGeneratedAncestor(frame
);
10071 if (nonGeneratedAncestor
->GetContent() != aContent
) {
10072 return RecreateFramesForContent(nonGeneratedAncestor
->GetContent());
10076 nsresult rv
= NS_OK
;
10078 if (frame
&& MaybeRecreateContainerForIBSplitterFrame(frame
, &rv
)) {
10082 nsCOMPtr
<nsIContent
> container
= aContent
->GetParent();
10084 // XXXbz what if this is anonymous content?
10085 PRInt32 indexInContainer
= container
->IndexOf(aContent
);
10086 // Before removing the frames associated with the content object,
10087 // ask them to save their state onto a temporary state object.
10088 CaptureStateForFramesOf(aContent
, mTempFrameTreeState
);
10090 // Remove the frames associated with the content object on which
10091 // the attribute change occurred.
10092 PRBool didReconstruct
;
10093 rv
= ContentRemoved(container
, aContent
, indexInContainer
, &didReconstruct
);
10095 if (NS_SUCCEEDED(rv
) && !didReconstruct
) {
10096 // Now, recreate the frames associated with this content object. If
10097 // ContentRemoved triggered reconstruction, then we don't need to do this
10098 // because the frames will already have been built.
10099 rv
= ContentInserted(container
, aContent
,
10100 indexInContainer
, mTempFrameTreeState
);
10103 // The content is the root node, so just rebuild the world.
10104 ReconstructDocElementHierarchy();
10107 #ifdef ACCESSIBILITY
10108 if (mPresShell
->IsAccessibilityActive()) {
10111 nsIFrame
*newFrame
= mPresShell
->GetPrimaryFrameFor(aContent
);
10112 event
= newFrame
? PRUint32(nsIAccessibleEvent::EVENT_ASYNCH_SIGNIFICANT_CHANGE
) :
10113 PRUint32(nsIAccessibleEvent::EVENT_ASYNCH_HIDE
);
10116 event
= nsIAccessibleEvent::EVENT_ASYNCH_SHOW
;
10119 // A significant enough change occured that this part
10120 // of the accessible tree is no longer valid.
10121 nsCOMPtr
<nsIAccessibilityService
> accService
=
10122 do_GetService("@mozilla.org/accessibilityService;1");
10124 accService
->InvalidateSubtreeFor(mPresShell
, aContent
, event
);
10132 //////////////////////////////////////////////////////////////////////
10134 // Block frame construction code
10136 already_AddRefed
<nsStyleContext
>
10137 nsCSSFrameConstructor::GetFirstLetterStyle(nsIContent
* aContent
,
10138 nsStyleContext
* aStyleContext
)
10141 return mPresShell
->StyleSet()->
10142 ResolvePseudoStyleFor(aContent
,
10143 nsCSSPseudoElements::firstLetter
, aStyleContext
);
10148 already_AddRefed
<nsStyleContext
>
10149 nsCSSFrameConstructor::GetFirstLineStyle(nsIContent
* aContent
,
10150 nsStyleContext
* aStyleContext
)
10153 return mPresShell
->StyleSet()->
10154 ResolvePseudoStyleFor(aContent
,
10155 nsCSSPseudoElements::firstLine
, aStyleContext
);
10160 // Predicate to see if a given content (block element) has
10161 // first-letter style applied to it.
10163 nsCSSFrameConstructor::ShouldHaveFirstLetterStyle(nsIContent
* aContent
,
10164 nsStyleContext
* aStyleContext
)
10166 return nsLayoutUtils::HasPseudoStyle(aContent
, aStyleContext
,
10167 nsCSSPseudoElements::firstLetter
,
10168 mPresShell
->GetPresContext());
10172 nsCSSFrameConstructor::HasFirstLetterStyle(nsIFrame
* aBlockFrame
)
10174 NS_PRECONDITION(aBlockFrame
, "Need a frame");
10175 NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlockFrame
),
10176 "Not a block frame?");
10178 return (aBlockFrame
->GetStateBits() & NS_BLOCK_HAS_FIRST_LETTER_STYLE
) != 0;
10182 nsCSSFrameConstructor::ShouldHaveFirstLineStyle(nsIContent
* aContent
,
10183 nsStyleContext
* aStyleContext
)
10185 PRBool hasFirstLine
=
10186 nsLayoutUtils::HasPseudoStyle(aContent
, aStyleContext
,
10187 nsCSSPseudoElements::firstLine
,
10188 mPresShell
->GetPresContext());
10189 if (hasFirstLine
) {
10190 // But disable for fieldsets
10191 PRInt32 namespaceID
;
10192 nsIAtom
* tag
= mDocument
->BindingManager()->ResolveTag(aContent
,
10194 // This check must match the one in FindHTMLData.
10195 hasFirstLine
= tag
!= nsGkAtoms::fieldset
||
10196 (namespaceID
!= kNameSpaceID_XHTML
&&
10197 !aContent
->IsNodeOfType(nsINode::eHTML
));
10200 return hasFirstLine
;
10204 nsCSSFrameConstructor::ShouldHaveSpecialBlockStyle(nsIContent
* aContent
,
10205 nsStyleContext
* aStyleContext
,
10206 PRBool
* aHaveFirstLetterStyle
,
10207 PRBool
* aHaveFirstLineStyle
)
10209 *aHaveFirstLetterStyle
=
10210 ShouldHaveFirstLetterStyle(aContent
, aStyleContext
);
10211 *aHaveFirstLineStyle
=
10212 ShouldHaveFirstLineStyle(aContent
, aStyleContext
);
10216 * Request to process the child content elements and create frames.
10218 * @param aContent the content object whose child elements to process
10219 * @param aFrame the frame associated with aContent. This will be the
10220 * parent frame (both content and geometric) for the flowed
10224 nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState
& aState
,
10225 nsIContent
* aContent
,
10226 nsStyleContext
* aStyleContext
,
10228 PRBool aCanHaveGeneratedContent
,
10229 nsFrameItems
& aFrameItems
,
10230 PRBool aAllowBlockStyles
)
10232 NS_PRECONDITION(aFrame
, "Must have parent frame here");
10233 NS_PRECONDITION(aFrame
->GetContentInsertionFrame() == aFrame
,
10234 "Parent frame in ProcessChildren should be its own "
10235 "content insertion frame");
10237 // XXXbz ideally, this would do all the pushing of various
10238 // containing blocks as needed, so callers don't have to do it...
10240 PRBool haveFirstLetterStyle
= PR_FALSE
, haveFirstLineStyle
= PR_FALSE
;
10241 if (aAllowBlockStyles
) {
10242 ShouldHaveSpecialBlockStyle(aContent
, aStyleContext
, &haveFirstLetterStyle
,
10243 &haveFirstLineStyle
);
10246 // The logic here needs to match the logic in GetFloatContainingBlock()
10247 nsFrameConstructorSaveState floatSaveState
;
10248 if (aFrame
->IsFrameOfType(nsIFrame::eMathML
) ||
10249 aFrame
->IsBoxFrame()) {
10250 aState
.PushFloatContainingBlock(nsnull
, floatSaveState
);
10251 } else if (aFrame
->IsFloatContainingBlock()) {
10252 aState
.PushFloatContainingBlock(aFrame
, floatSaveState
);
10255 // save the incoming pseudo frame state
10256 nsPseudoFrames priorPseudoFrames
;
10257 aState
.mPseudoFrames
.Reset(&priorPseudoFrames
);
10259 if (aFrame
== mRootElementFrame
) {
10260 // Create any anonymous frames the initial containing block frame requires.
10261 // This must happen before the rest of ProcessChildren to ensure that
10262 // popups are never constructed before the popupset.
10263 CreateAnonymousFrames(aState
, aContent
, aFrame
, aFrameItems
);
10266 nsresult rv
= NS_OK
;
10267 if (!aFrame
->IsLeaf() &&
10268 mDocument
->BindingManager()->ShouldBuildChildFrames(aContent
)) {
10269 // :before/:after content should have the same style context parent
10271 // Note that we don't use this style context for looking up things like
10272 // special block styles because in some cases involving table pseudo-frames
10273 // it has nothing to do with the parent frame's desired behavior.
10274 nsStyleContext
* styleContext
=
10275 nsFrame::CorrectStyleParentFrame(aFrame
, nsnull
)->GetStyleContext();
10277 if (aCanHaveGeneratedContent
) {
10278 // Probe for generated content before
10279 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
10280 styleContext
, nsCSSPseudoElements::before
,
10284 ChildIterator iter
, last
;
10285 for (ChildIterator::Init(aContent
, &iter
, &last
);
10288 rv
= ConstructFrame(aState
, *iter
, aFrame
, aFrameItems
);
10293 if (aCanHaveGeneratedContent
) {
10294 // Probe for generated content after
10295 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
10296 styleContext
, nsCSSPseudoElements::after
,
10301 if (aFrame
!= mRootElementFrame
) {
10302 CreateAnonymousFrames(aState
, aContent
, aFrame
, aFrameItems
);
10305 // process the current pseudo frame state
10306 if (!aState
.mPseudoFrames
.IsEmpty()) {
10307 ProcessPseudoFrames(aState
, aFrameItems
);
10310 // restore the incoming pseudo frame state
10311 aState
.mPseudoFrames
= priorPseudoFrames
;
10313 NS_ASSERTION(!aAllowBlockStyles
|| !aFrame
->IsBoxFrame(),
10314 "can't be both block and box");
10316 if (haveFirstLetterStyle
) {
10317 rv
= WrapFramesInFirstLetterFrame(aContent
, aFrame
, aFrameItems
);
10319 if (haveFirstLineStyle
) {
10320 rv
= WrapFramesInFirstLineFrame(aState
, aContent
, aFrame
, aFrameItems
);
10323 nsIContent
*badKid
;
10324 if (aFrame
->IsBoxFrame() &&
10325 (badKid
= AnyKidsNeedBlockParent(aFrameItems
.childList
))) {
10326 nsAutoString parentTag
, kidTag
;
10327 aContent
->Tag()->ToString(parentTag
);
10328 badKid
->Tag()->ToString(kidTag
);
10329 const PRUnichar
* params
[] = { parentTag
.get(), kidTag
.get() };
10330 nsStyleContext
*frameStyleContext
= aFrame
->GetStyleContext();
10331 const nsStyleDisplay
*display
= frameStyleContext
->GetStyleDisplay();
10332 const char *message
=
10333 (display
->mDisplay
== NS_STYLE_DISPLAY_INLINE_BOX
)
10334 ? "NeededToWrapXULInlineBox" : "NeededToWrapXUL";
10335 nsContentUtils::ReportToConsole(nsContentUtils::eXUL_PROPERTIES
,
10337 params
, NS_ARRAY_LENGTH(params
),
10338 mDocument
->GetDocumentURI(),
10339 EmptyString(), 0, 0, // not useful
10340 nsIScriptError::warningFlag
,
10341 "FrameConstructor");
10343 nsRefPtr
<nsStyleContext
> blockSC
= mPresShell
->StyleSet()->
10344 ResolvePseudoStyleFor(aContent
,
10345 nsCSSAnonBoxes::mozXULAnonymousBlock
,
10346 frameStyleContext
);
10347 nsIFrame
*blockFrame
= NS_NewBlockFrame(mPresShell
, blockSC
);
10348 // We might, in theory, want to set NS_BLOCK_FLOAT_MGR and
10349 // NS_BLOCK_MARGIN_ROOT, but I think it's a bad idea given that
10350 // a real block placed here wouldn't get those set on it.
10352 InitAndRestoreFrame(aState
, aContent
, aFrame
, nsnull
,
10353 blockFrame
, PR_FALSE
);
10355 NS_ASSERTION(!blockFrame
->HasView(), "need to do view reparenting");
10356 for (nsIFrame
*f
= aFrameItems
.childList
; f
; f
= f
->GetNextSibling()) {
10357 ReparentFrame(aState
.mFrameManager
, blockFrame
, f
);
10360 blockFrame
->AppendFrames(nsnull
, aFrameItems
.childList
);
10361 aFrameItems
= nsFrameItems();
10362 aFrameItems
.AddChild(blockFrame
);
10364 aFrame
->AddStateBits(NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK
);
10370 //----------------------------------------------------------------------
10372 // Support for :first-line style
10374 // Special routine to handle placing a list of frames into a block
10375 // frame that has first-line style. The routine ensures that the first
10376 // collection of inline frames end up in a first-line frame.
10377 // NOTE: aState may have containing block information related to a
10378 // different part of the frame tree than where the first line occurs.
10379 // In particular aState may be set up for where ContentInserted or
10380 // ContentAppended is inserting content, which may be some
10381 // non-first-in-flow continuation of the block to which the first-line
10382 // belongs. So this function needs to be careful about how it uses
10385 nsCSSFrameConstructor::WrapFramesInFirstLineFrame(
10386 nsFrameConstructorState
& aState
,
10387 nsIContent
* aBlockContent
,
10388 nsIFrame
* aBlockFrame
,
10389 nsFrameItems
& aFrameItems
)
10391 nsresult rv
= NS_OK
;
10393 // Find the first and last inline frame in aFrameItems
10394 nsIFrame
* kid
= aFrameItems
.childList
;
10395 nsIFrame
* firstInlineFrame
= nsnull
;
10396 nsIFrame
* lastInlineFrame
= nsnull
;
10398 if (IsInlineOutside(kid
)) {
10399 if (!firstInlineFrame
) firstInlineFrame
= kid
;
10400 lastInlineFrame
= kid
;
10405 kid
= kid
->GetNextSibling();
10408 // If we don't find any inline frames, then there is nothing to do
10409 if (!firstInlineFrame
) {
10413 // Create line frame
10414 nsStyleContext
* parentStyle
=
10415 nsFrame::CorrectStyleParentFrame(aBlockFrame
,
10416 nsCSSPseudoElements::firstLine
)->
10418 nsRefPtr
<nsStyleContext
> firstLineStyle
= GetFirstLineStyle(aBlockContent
,
10421 nsIFrame
* lineFrame
= NS_NewFirstLineFrame(mPresShell
, firstLineStyle
);
10424 // Initialize the line frame
10425 rv
= InitAndRestoreFrame(aState
, aBlockContent
, aBlockFrame
, nsnull
,
10428 // Mangle the list of frames we are giving to the block: first
10429 // chop the list in two after lastInlineFrame
10430 nsIFrame
* secondBlockFrame
= lastInlineFrame
->GetNextSibling();
10431 lastInlineFrame
->SetNextSibling(nsnull
);
10433 // The lineFrame will be the block's first child; the rest of the
10434 // frame list (after lastInlineFrame) will be the second and
10435 // subsequent children; join the list together and reset
10436 // aFrameItems appropriately.
10437 if (secondBlockFrame
) {
10438 lineFrame
->SetNextSibling(secondBlockFrame
);
10440 if (aFrameItems
.childList
== lastInlineFrame
) {
10441 // Just in case the block had exactly one inline child
10442 aFrameItems
.lastChild
= lineFrame
;
10444 aFrameItems
.childList
= lineFrame
;
10446 // Give the inline frames to the lineFrame <b>after</b> reparenting them
10447 kid
= firstInlineFrame
;
10448 NS_ASSERTION(lineFrame
->GetStyleContext() == firstLineStyle
,
10449 "Bogus style context on line frame");
10451 ReparentFrame(aState
.mFrameManager
, lineFrame
, kid
);
10452 kid
= kid
->GetNextSibling();
10454 lineFrame
->SetInitialChildList(nsnull
, firstInlineFrame
);
10457 rv
= NS_ERROR_OUT_OF_MEMORY
;
10463 // Special routine to handle appending a new frame to a block frame's
10464 // child list. Takes care of placing the new frame into the right
10465 // place when first-line style is present.
10467 nsCSSFrameConstructor::AppendFirstLineFrames(
10468 nsFrameConstructorState
& aState
,
10469 nsIContent
* aBlockContent
,
10470 nsIFrame
* aBlockFrame
,
10471 nsFrameItems
& aFrameItems
)
10473 // It's possible that aBlockFrame needs to have a first-line frame
10474 // created because it doesn't currently have any children.
10475 nsIFrame
* blockKid
= aBlockFrame
->GetFirstChild(nsnull
);
10477 return WrapFramesInFirstLineFrame(aState
, aBlockContent
,
10478 aBlockFrame
, aFrameItems
);
10481 // Examine the last block child - if it's a first-line frame then
10482 // appended frames need special treatment.
10483 nsresult rv
= NS_OK
;
10484 nsFrameList
blockFrames(blockKid
);
10485 nsIFrame
* lastBlockKid
= blockFrames
.LastChild();
10486 if (lastBlockKid
->GetType() != nsGkAtoms::lineFrame
) {
10487 // No first-line frame at the end of the list, therefore there is
10488 // an interveening block between any first-line frame the frames
10489 // we are appending. Therefore, we don't need any special
10490 // treatment of the appended frames.
10493 nsIFrame
* lineFrame
= lastBlockKid
;
10495 // Find the first and last inline frame in aFrameItems
10496 nsIFrame
* kid
= aFrameItems
.childList
;
10497 nsIFrame
* firstInlineFrame
= nsnull
;
10498 nsIFrame
* lastInlineFrame
= nsnull
;
10500 if (IsInlineOutside(kid
)) {
10501 if (!firstInlineFrame
) firstInlineFrame
= kid
;
10502 lastInlineFrame
= kid
;
10507 kid
= kid
->GetNextSibling();
10510 // If we don't find any inline frames, then there is nothing to do
10511 if (!firstInlineFrame
) {
10515 // The inline frames get appended to the lineFrame. Make sure they
10516 // are reparented properly.
10517 nsIFrame
* remainingFrames
= lastInlineFrame
->GetNextSibling();
10518 lastInlineFrame
->SetNextSibling(nsnull
);
10519 kid
= firstInlineFrame
;
10521 ReparentFrame(aState
.mFrameManager
, lineFrame
, kid
);
10522 kid
= kid
->GetNextSibling();
10524 aState
.mFrameManager
->AppendFrames(lineFrame
, nsnull
, firstInlineFrame
);
10526 // The remaining frames get appended to the block frame
10527 if (remainingFrames
) {
10528 aFrameItems
.childList
= remainingFrames
;
10531 aFrameItems
.childList
= nsnull
;
10532 aFrameItems
.lastChild
= nsnull
;
10538 // Special routine to handle inserting a new frame into a block
10539 // frame's child list. Takes care of placing the new frame into the
10540 // right place when first-line style is present.
10542 nsCSSFrameConstructor::InsertFirstLineFrames(
10543 nsFrameConstructorState
& aState
,
10544 nsIContent
* aContent
,
10545 nsIFrame
* aBlockFrame
,
10546 nsIFrame
** aParentFrame
,
10547 nsIFrame
* aPrevSibling
,
10548 nsFrameItems
& aFrameItems
)
10550 nsresult rv
= NS_OK
;
10551 // XXXbz If you make this method actually do something, check to make sure
10552 // that the caller is passing what you expect. In particular, which content
10555 nsIFrame
* parentFrame
= *aParentFrame
;
10556 nsIFrame
* newFrame
= aFrameItems
.childList
;
10557 PRBool isInline
= IsInlineOutside(newFrame
);
10559 if (!aPrevSibling
) {
10560 // Insertion will become the first frame. Two cases: we either
10561 // already have a first-line frame or we don't.
10562 nsIFrame
* firstBlockKid
= aBlockFrame
->GetFirstChild(nsnull
);
10563 if (firstBlockKid
->GetType() == nsGkAtoms::lineFrame
) {
10564 // We already have a first-line frame
10565 nsIFrame
* lineFrame
= firstBlockKid
;
10568 // Easy case: the new inline frame will go into the lineFrame.
10569 ReparentFrame(aState
.mFrameManager
, lineFrame
, newFrame
);
10570 aState
.mFrameManager
->InsertFrames(lineFrame
, nsnull
, nsnull
,
10573 // Since the frame is going into the lineFrame, don't let it
10574 // go into the block too.
10575 aFrameItems
.childList
= nsnull
;
10576 aFrameItems
.lastChild
= nsnull
;
10579 // Harder case: We are about to insert a block level element
10580 // before the first-line frame.
10581 // XXX need a method to steal away frames from the line-frame
10585 // We do not have a first-line frame
10587 // We now need a first-line frame to contain the inline frame.
10588 nsIFrame
* lineFrame
= NS_NewFirstLineFrame(firstLineStyle
);
10590 rv
= NS_ERROR_OUT_OF_MEMORY
;
10593 if (NS_SUCCEEDED(rv
)) {
10594 // Lookup first-line style context
10595 nsStyleContext
* parentStyle
=
10596 nsFrame::CorrectStyleParentFrame(aBlockFrame
,
10597 nsCSSPseudoElements::firstLine
)->
10599 nsRefPtr
<nsStyleContext
> firstLineStyle
=
10600 GetFirstLineStyle(aContent
, parentStyle
);
10602 // Initialize the line frame
10603 rv
= InitAndRestoreFrame(aState
, aContent
, aBlockFrame
,
10604 nsnull
, lineFrame
);
10606 // Make sure the caller inserts the lineFrame into the
10607 // blocks list of children.
10608 aFrameItems
.childList
= lineFrame
;
10609 aFrameItems
.lastChild
= lineFrame
;
10611 // Give the inline frames to the lineFrame <b>after</b>
10612 // reparenting them
10613 NS_ASSERTION(lineFrame
->GetStyleContext() == firstLineStyle
,
10614 "Bogus style context on line frame");
10615 ReparentFrame(aPresContext
, lineFrame
, newFrame
);
10616 lineFrame
->SetInitialChildList(nsnull
, newFrame
);
10620 // Easy case: the regular insertion logic can insert the new
10621 // frame because it's a block frame.
10626 // Insertion will not be the first frame.
10627 nsIFrame
* prevSiblingParent
= aPrevSibling
->GetParent();
10628 if (prevSiblingParent
== aBlockFrame
) {
10629 // Easy case: The prev-siblings parent is the block
10630 // frame. Therefore the prev-sibling is not currently in a
10631 // line-frame. Therefore the new frame which is going after it,
10632 // regardless of type, is not going into a line-frame.
10635 // If the prevSiblingParent is not the block-frame then it must
10636 // be a line-frame (if it were a letter-frame, that logic would
10637 // already have adjusted the prev-sibling to be the
10640 // Easy case: the insertion can go where the caller thinks it
10641 // should go (which is into prevSiblingParent).
10644 // Block elements don't end up in line-frames, therefore
10645 // change the insertion point to aBlockFrame. However, there
10646 // might be more inline elements following aPrevSibling that
10647 // need to be pulled out of the line-frame and become children
10649 nsIFrame
* nextSibling
= aPrevSibling
->GetNextSibling();
10650 nsIFrame
* nextLineFrame
= prevSiblingParent
->GetNextInFlow();
10651 if (nextSibling
|| nextLineFrame
) {
10652 // Oy. We have work to do. Create a list of the new frames
10653 // that are going into the block by stripping them away from
10654 // the line-frame(s).
10655 nsFrameList
list(nextSibling
);
10657 nsLineFrame
* lineFrame
= (nsLineFrame
*) prevSiblingParent
;
10658 lineFrame
->StealFramesFrom(nextSibling
);
10661 nsLineFrame
* nextLineFrame
= (nsLineFrame
*) lineFrame
;
10663 nextLineFrame
= nextLineFrame
->GetNextInFlow();
10664 if (!nextLineFrame
) {
10667 nsIFrame
* kids
= nextLineFrame
->GetFirstChild(nsnull
);
10671 // We got lucky: aPrevSibling was the last inline frame in
10673 ReparentFrame(aState
.mFrameManager
, aBlockFrame
, newFrame
);
10674 aState
.mFrameManager
->InsertFrames(aBlockFrame
, nsnull
,
10675 prevSiblingParent
, newFrame
);
10676 aFrameItems
.childList
= nsnull
;
10677 aFrameItems
.lastChild
= nsnull
;
10687 //----------------------------------------------------------------------
10689 // First-letter support
10691 // Determine how many characters in the text fragment apply to the
10694 FirstLetterCount(const nsTextFragment
* aFragment
)
10697 PRInt32 firstLetterLength
= 0;
10698 PRBool done
= PR_FALSE
;
10700 PRInt32 i
, n
= aFragment
->GetLength();
10701 for (i
= 0; i
< n
; i
++) {
10702 PRUnichar ch
= aFragment
->CharAt(i
);
10703 if (XP_IS_SPACE(ch
)) {
10704 if (firstLetterLength
) {
10712 if ((ch
== '\'') || (ch
== '\"')) {
10713 if (firstLetterLength
) {
10718 firstLetterLength
= 1;
10731 NeedFirstLetterContinuation(nsIContent
* aContent
)
10733 NS_PRECONDITION(aContent
, "null ptr");
10735 PRBool result
= PR_FALSE
;
10737 const nsTextFragment
* frag
= aContent
->GetText();
10739 PRInt32 flc
= FirstLetterCount(frag
);
10740 PRInt32 tl
= frag
->GetLength();
10749 static PRBool
IsFirstLetterContent(nsIContent
* aContent
)
10751 return aContent
->TextLength() &&
10752 !aContent
->TextIsOnlyWhitespace();
10756 * Create a letter frame, only make it a floating frame.
10759 nsCSSFrameConstructor::CreateFloatingLetterFrame(
10760 nsFrameConstructorState
& aState
,
10761 nsIFrame
* aBlockFrame
,
10762 nsIContent
* aTextContent
,
10763 nsIFrame
* aTextFrame
,
10764 nsIContent
* aBlockContent
,
10765 nsIFrame
* aParentFrame
,
10766 nsStyleContext
* aStyleContext
,
10767 nsFrameItems
& aResult
)
10769 // Create the first-letter-frame
10771 nsIFrame
* letterFrame
;
10772 nsStyleSet
*styleSet
= mPresShell
->StyleSet();
10774 letterFrame
= NS_NewFirstLetterFrame(mPresShell
, aStyleContext
);
10775 // We don't want to use a text content for a non-text frame (because we want
10776 // its primary frame to be a text frame). So use its parent for the
10778 nsIContent
* letterContent
= aTextContent
->GetParent();
10779 InitAndRestoreFrame(aState
, letterContent
,
10780 aState
.GetGeometricParent(aStyleContext
->GetStyleDisplay(),
10782 nsnull
, letterFrame
);
10784 // Init the text frame to refer to the letter frame. Make sure we
10785 // get a proper style context for it (the one passed in is for the
10786 // letter frame and will have the float property set on it; the text
10787 // frame shouldn't have that set).
10788 nsRefPtr
<nsStyleContext
> textSC
;
10789 textSC
= styleSet
->ResolveStyleForNonElement(aStyleContext
);
10790 aTextFrame
->SetStyleContextWithoutNotification(textSC
);
10791 InitAndRestoreFrame(aState
, aTextContent
, letterFrame
, nsnull
, aTextFrame
);
10793 // And then give the text frame to the letter frame
10794 letterFrame
->SetInitialChildList(nsnull
, aTextFrame
);
10796 // See if we will need to continue the text frame (does it contain
10797 // more than just the first-letter text or not?) If it does, then we
10798 // create (in advance) a continuation frame for it.
10799 nsIFrame
* nextTextFrame
= nsnull
;
10800 if (NeedFirstLetterContinuation(aTextContent
)) {
10801 // Create continuation
10802 rv
= CreateContinuingFrame(aState
.mPresContext
, aTextFrame
, aParentFrame
,
10804 if (NS_FAILED(rv
)) {
10805 letterFrame
->Destroy();
10808 // Repair the continuations style context
10809 nsStyleContext
* parentStyleContext
= aStyleContext
->GetParent();
10810 if (parentStyleContext
) {
10811 nsRefPtr
<nsStyleContext
> newSC
;
10812 newSC
= styleSet
->ResolveStyleForNonElement(parentStyleContext
);
10814 nextTextFrame
->SetStyleContext(newSC
);
10819 NS_ASSERTION(aResult
.childList
== nsnull
,
10820 "aResult should be an empty nsFrameItems!");
10821 nsIFrame
* insertAfter
= nsnull
;
10823 // Put the new float before any of the floats in the block we're
10824 // doing first-letter for, that is, before any floats whose parent is aBlockFrame
10825 for (f
= aState
.mFloatedItems
.childList
; f
; f
= f
->GetNextSibling()) {
10826 if (f
->GetParent() == aBlockFrame
)
10831 rv
= aState
.AddChild(letterFrame
, aResult
, letterContent
, aStyleContext
,
10832 aParentFrame
, PR_FALSE
, PR_TRUE
, PR_FALSE
, PR_TRUE
,
10835 if (nextTextFrame
) {
10836 if (NS_FAILED(rv
)) {
10837 nextTextFrame
->Destroy();
10839 aResult
.AddChild(nextTextFrame
);
10845 * Create a new letter frame for aTextFrame. The letter frame will be
10846 * a child of aParentFrame.
10849 nsCSSFrameConstructor::CreateLetterFrame(nsIFrame
* aBlockFrame
,
10850 nsIContent
* aTextContent
,
10851 nsIFrame
* aParentFrame
,
10852 nsFrameItems
& aResult
)
10854 NS_PRECONDITION(aTextContent
->IsNodeOfType(nsINode::eTEXT
),
10855 "aTextContent isn't text");
10856 NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlockFrame
),
10857 "Not a block frame?");
10859 // Get style context for the first-letter-frame
10860 nsStyleContext
* parentStyleContext
=
10861 nsFrame::CorrectStyleParentFrame(aParentFrame
,
10862 nsCSSPseudoElements::firstLetter
)->
10865 // Use content from containing block so that we can actually
10866 // find a matching style rule.
10867 nsIContent
* blockContent
= aBlockFrame
->GetContent();
10869 // Create first-letter style rule
10870 nsRefPtr
<nsStyleContext
> sc
= GetFirstLetterStyle(blockContent
,
10871 parentStyleContext
);
10873 nsRefPtr
<nsStyleContext
> textSC
;
10874 textSC
= mPresShell
->StyleSet()->ResolveStyleForNonElement(sc
);
10876 // Create a new text frame (the original one will be discarded)
10877 // pass a temporary stylecontext, the correct one will be set later
10878 nsIFrame
* textFrame
= NS_NewTextFrame(mPresShell
, textSC
);
10880 NS_ASSERTION(aBlockFrame
== GetFloatContainingBlock(aParentFrame
),
10881 "Containing block is confused");
10882 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
10883 GetAbsoluteContainingBlock(aParentFrame
),
10886 // Create the right type of first-letter frame
10887 const nsStyleDisplay
* display
= sc
->GetStyleDisplay();
10888 if (display
->IsFloating()) {
10889 // Make a floating first-letter frame
10890 CreateFloatingLetterFrame(state
, aBlockFrame
, aTextContent
, textFrame
,
10891 blockContent
, aParentFrame
,
10895 // Make an inflow first-letter frame
10896 nsIFrame
* letterFrame
= NS_NewFirstLetterFrame(mPresShell
, sc
);
10899 // Initialize the first-letter-frame. We don't want to use a text
10900 // content for a non-text frame (because we want its primary frame to
10901 // be a text frame). So use its parent for the first-letter.
10902 nsIContent
* letterContent
= aTextContent
->GetParent();
10903 letterFrame
->Init(letterContent
, aParentFrame
, nsnull
);
10905 InitAndRestoreFrame(state
, aTextContent
, letterFrame
, nsnull
,
10908 letterFrame
->SetInitialChildList(nsnull
, textFrame
);
10909 aResult
.childList
= aResult
.lastChild
= letterFrame
;
10910 aBlockFrame
->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_CHILD
);
10919 nsCSSFrameConstructor::WrapFramesInFirstLetterFrame(
10920 nsIContent
* aBlockContent
,
10921 nsIFrame
* aBlockFrame
,
10922 nsFrameItems
& aBlockFrames
)
10924 nsresult rv
= NS_OK
;
10926 aBlockFrame
->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_STYLE
);
10928 nsIFrame
* parentFrame
= nsnull
;
10929 nsIFrame
* textFrame
= nsnull
;
10930 nsIFrame
* prevFrame
= nsnull
;
10931 nsFrameItems letterFrames
;
10932 PRBool stopLooking
= PR_FALSE
;
10933 rv
= WrapFramesInFirstLetterFrame(aBlockFrame
, aBlockFrame
,
10934 aBlockFrames
.childList
,
10935 &parentFrame
, &textFrame
, &prevFrame
,
10936 letterFrames
, &stopLooking
);
10937 if (NS_FAILED(rv
)) {
10941 if (parentFrame
== aBlockFrame
) {
10942 // Text textFrame out of the blocks frame list and substitute the
10943 // letter frame(s) instead.
10944 nsIFrame
* nextSibling
= textFrame
->GetNextSibling();
10945 textFrame
->SetNextSibling(nsnull
);
10947 prevFrame
->SetNextSibling(letterFrames
.childList
);
10950 aBlockFrames
.childList
= letterFrames
.childList
;
10952 letterFrames
.lastChild
->SetNextSibling(nextSibling
);
10954 // Destroy the old textFrame
10955 textFrame
->Destroy();
10957 // Repair lastChild; the only time this needs to happen is when
10958 // the block had one child (the text frame).
10959 if (!nextSibling
) {
10960 aBlockFrames
.lastChild
= letterFrames
.lastChild
;
10964 // Take the old textFrame out of the inline parents child list
10965 ::DeletingFrameSubtree(mPresShell
->FrameManager(), textFrame
);
10966 parentFrame
->RemoveFrame(nsnull
, textFrame
);
10968 // Insert in the letter frame(s)
10969 parentFrame
->InsertFrames(nsnull
, prevFrame
, letterFrames
.childList
);
10977 nsCSSFrameConstructor::WrapFramesInFirstLetterFrame(
10978 nsIFrame
* aBlockFrame
,
10979 nsIFrame
* aParentFrame
,
10980 nsIFrame
* aParentFrameList
,
10981 nsIFrame
** aModifiedParent
,
10982 nsIFrame
** aTextFrame
,
10983 nsIFrame
** aPrevFrame
,
10984 nsFrameItems
& aLetterFrames
,
10985 PRBool
* aStopLooking
)
10987 nsresult rv
= NS_OK
;
10989 nsIFrame
* prevFrame
= nsnull
;
10990 nsIFrame
* frame
= aParentFrameList
;
10993 nsIFrame
* nextFrame
= frame
->GetNextSibling();
10995 nsIAtom
* frameType
= frame
->GetType();
10996 if (nsGkAtoms::textFrame
== frameType
) {
10997 // Wrap up first-letter content in a letter frame
10998 nsIContent
* textContent
= frame
->GetContent();
10999 if (IsFirstLetterContent(textContent
)) {
11000 // Create letter frame to wrap up the text
11001 rv
= CreateLetterFrame(aBlockFrame
, textContent
,
11002 aParentFrame
, aLetterFrames
);
11003 if (NS_FAILED(rv
)) {
11007 // Provide adjustment information for parent
11008 *aModifiedParent
= aParentFrame
;
11009 *aTextFrame
= frame
;
11010 *aPrevFrame
= prevFrame
;
11011 *aStopLooking
= PR_TRUE
;
11015 else if (IsInlineFrame(frame
) && frameType
!= nsGkAtoms::brFrame
) {
11016 nsIFrame
* kids
= frame
->GetFirstChild(nsnull
);
11017 WrapFramesInFirstLetterFrame(aBlockFrame
, frame
, kids
,
11018 aModifiedParent
, aTextFrame
,
11019 aPrevFrame
, aLetterFrames
, aStopLooking
);
11020 if (*aStopLooking
) {
11025 // This will stop us looking to create more letter frames. For
11026 // example, maybe the frame-type is "letterFrame" or
11027 // "placeholderFrame". This keeps us from creating extra letter
11028 // frames, and also prevents us from creating letter frames when
11029 // the first real content child of a block is not text (e.g. an
11030 // image, hr, etc.)
11031 *aStopLooking
= PR_TRUE
;
11043 nsCSSFrameConstructor::RemoveFloatingFirstLetterFrames(
11044 nsPresContext
* aPresContext
,
11045 nsIPresShell
* aPresShell
,
11046 nsFrameManager
* aFrameManager
,
11047 nsIFrame
* aBlockFrame
,
11048 PRBool
* aStopLooking
)
11050 // First look for the float frame that is a letter frame
11051 nsIFrame
* floatFrame
= aBlockFrame
->GetFirstChild(nsGkAtoms::floatList
);
11052 while (floatFrame
) {
11053 // See if we found a floating letter frame
11054 if (nsGkAtoms::letterFrame
== floatFrame
->GetType()) {
11057 floatFrame
= floatFrame
->GetNextSibling();
11064 // Take the text frame away from the letter frame (so it isn't
11065 // destroyed when we destroy the letter frame).
11066 nsIFrame
* textFrame
= floatFrame
->GetFirstChild(nsnull
);
11071 // Discover the placeholder frame for the letter frame
11072 nsIFrame
* parentFrame
;
11073 nsPlaceholderFrame
* placeholderFrame
=
11074 aFrameManager
->GetPlaceholderFrameFor(floatFrame
);
11076 if (!placeholderFrame
) {
11077 // Somethings really wrong
11080 parentFrame
= placeholderFrame
->GetParent();
11081 if (!parentFrame
) {
11082 // Somethings really wrong
11086 // Create a new text frame with the right style context that maps
11087 // all of the content that was previously part of the letter frame
11088 // (and probably continued elsewhere).
11089 nsStyleContext
* parentSC
= parentFrame
->GetStyleContext();
11093 nsIContent
* textContent
= textFrame
->GetContent();
11094 if (!textContent
) {
11097 nsRefPtr
<nsStyleContext
> newSC
;
11098 newSC
= aPresShell
->StyleSet()->ResolveStyleForNonElement(parentSC
);
11102 nsIFrame
* newTextFrame
= NS_NewTextFrame(aPresShell
, newSC
);
11103 if (NS_UNLIKELY(!newTextFrame
)) {
11104 return NS_ERROR_OUT_OF_MEMORY
;;
11106 newTextFrame
->Init(textContent
, parentFrame
, nsnull
);
11108 // Destroy the old text frame's continuations (the old text frame
11109 // will be destroyed when its letter frame is destroyed).
11110 nsIFrame
* nextTextFrame
= textFrame
->GetNextContinuation();
11111 while (nextTextFrame
) {
11112 nsIFrame
* nextTextParent
= nextTextFrame
->GetParent();
11113 if (nextTextParent
) {
11114 nsSplittableFrame::RemoveFromFlow(nextTextFrame
);
11115 ::DeletingFrameSubtree(aFrameManager
, nextTextFrame
);
11116 aFrameManager
->RemoveFrame(nextTextParent
, nsnull
, nextTextFrame
);
11118 nextTextFrame
= textFrame
->GetNextContinuation();
11121 // First find out where (in the content) the placeholder frames
11122 // text is and its previous sibling frame, if any. Note that:
11123 // 1) The placeholder had better be in the principal child list of
11125 // 2) It's probably near the beginning (since we're a first-letter frame),
11126 // so just doing a linear search for the prevSibling is ok.
11127 // 3) Trying to use FindPreviousSibling will fail if the first-letter is in
11128 // anonymous content (eg generated content).
11129 nsFrameList
siblingList(parentFrame
->GetFirstChild(nsnull
));
11130 NS_ASSERTION(siblingList
.ContainsFrame(placeholderFrame
),
11131 "Placeholder not in parent's principal child list?");
11132 nsIFrame
* prevSibling
= siblingList
.GetPrevSiblingFor(placeholderFrame
);
11134 // Now that everything is set...
11135 #ifdef NOISY_FIRST_LETTER
11136 printf("RemoveFloatingFirstLetterFrames: textContent=%p oldTextFrame=%p newTextFrame=%p\n",
11137 textContent
.get(), textFrame
, newTextFrame
);
11140 UnregisterPlaceholderChain(aFrameManager
, placeholderFrame
);
11142 // Remove the float frame
11143 ::DeletingFrameSubtree(aFrameManager
, floatFrame
);
11144 aFrameManager
->RemoveFrame(aBlockFrame
, nsGkAtoms::floatList
,
11147 // Remove placeholder frame
11148 ::DeletingFrameSubtree(aFrameManager
, placeholderFrame
);
11149 aFrameManager
->RemoveFrame(parentFrame
, nsnull
, placeholderFrame
);
11151 // Insert text frame in its place
11152 aFrameManager
->InsertFrames(parentFrame
, nsnull
,
11153 prevSibling
, newTextFrame
);
11159 nsCSSFrameConstructor::RemoveFirstLetterFrames(nsPresContext
* aPresContext
,
11160 nsIPresShell
* aPresShell
,
11161 nsFrameManager
* aFrameManager
,
11163 PRBool
* aStopLooking
)
11165 nsIFrame
* prevSibling
= nsnull
;
11166 nsIFrame
* kid
= aFrame
->GetFirstChild(nsnull
);
11169 if (nsGkAtoms::letterFrame
== kid
->GetType()) {
11170 // Bingo. Found it. First steal away the text frame.
11171 nsIFrame
* textFrame
= kid
->GetFirstChild(nsnull
);
11176 // Create a new textframe
11177 nsStyleContext
* parentSC
= aFrame
->GetStyleContext();
11181 nsIContent
* textContent
= textFrame
->GetContent();
11182 if (!textContent
) {
11185 nsRefPtr
<nsStyleContext
> newSC
;
11186 newSC
= aPresShell
->StyleSet()->ResolveStyleForNonElement(parentSC
);
11190 textFrame
= NS_NewTextFrame(aPresShell
, newSC
);
11191 textFrame
->Init(textContent
, aFrame
, nsnull
);
11193 // Next rip out the kid and replace it with the text frame
11194 ::DeletingFrameSubtree(aFrameManager
, kid
);
11195 aFrameManager
->RemoveFrame(aFrame
, nsnull
, kid
);
11197 // Insert text frame in its place
11198 aFrameManager
->InsertFrames(aFrame
, nsnull
, prevSibling
, textFrame
);
11200 *aStopLooking
= PR_TRUE
;
11201 aFrame
->RemoveStateBits(NS_BLOCK_HAS_FIRST_LETTER_CHILD
);
11204 else if (IsInlineFrame(kid
)) {
11205 // Look inside child inline frame for the letter frame
11206 RemoveFirstLetterFrames(aPresContext
, aPresShell
, aFrameManager
, kid
,
11208 if (*aStopLooking
) {
11213 kid
= kid
->GetNextSibling();
11220 nsCSSFrameConstructor::RemoveLetterFrames(nsPresContext
* aPresContext
,
11221 nsIPresShell
* aPresShell
,
11222 nsFrameManager
* aFrameManager
,
11223 nsIFrame
* aBlockFrame
)
11225 aBlockFrame
= aBlockFrame
->GetFirstContinuation();
11227 PRBool stopLooking
= PR_FALSE
;
11230 rv
= RemoveFloatingFirstLetterFrames(aPresContext
, aPresShell
,
11232 aBlockFrame
, &stopLooking
);
11233 if (NS_SUCCEEDED(rv
) && !stopLooking
) {
11234 rv
= RemoveFirstLetterFrames(aPresContext
, aPresShell
, aFrameManager
,
11235 aBlockFrame
, &stopLooking
);
11240 aBlockFrame
= aBlockFrame
->GetNextContinuation();
11241 } while (aBlockFrame
);
11245 // Fixup the letter frame situation for the given block
11247 nsCSSFrameConstructor::RecoverLetterFrames(nsIFrame
* aBlockFrame
)
11249 aBlockFrame
= aBlockFrame
->GetFirstContinuation();
11251 nsIFrame
* parentFrame
= nsnull
;
11252 nsIFrame
* textFrame
= nsnull
;
11253 nsIFrame
* prevFrame
= nsnull
;
11254 nsFrameItems letterFrames
;
11255 PRBool stopLooking
= PR_FALSE
;
11258 // XXX shouldn't this bit be set already (bug 408493), assert instead?
11259 aBlockFrame
->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_STYLE
);
11260 rv
= WrapFramesInFirstLetterFrame(aBlockFrame
, aBlockFrame
,
11261 aBlockFrame
->GetFirstChild(nsnull
),
11262 &parentFrame
, &textFrame
, &prevFrame
,
11263 letterFrames
, &stopLooking
);
11264 if (NS_FAILED(rv
)) {
11270 aBlockFrame
= aBlockFrame
->GetNextContinuation();
11271 } while (aBlockFrame
);
11274 // Take the old textFrame out of the parents child list
11275 ::DeletingFrameSubtree(mPresShell
->FrameManager(), textFrame
);
11276 parentFrame
->RemoveFrame(nsnull
, textFrame
);
11278 // Insert in the letter frame(s)
11279 parentFrame
->InsertFrames(nsnull
, prevFrame
, letterFrames
.childList
);
11284 //----------------------------------------------------------------------
11286 // listbox Widget Routines
11289 nsCSSFrameConstructor::CreateListBoxContent(nsPresContext
* aPresContext
,
11290 nsIFrame
* aParentFrame
,
11291 nsIFrame
* aPrevFrame
,
11292 nsIContent
* aChild
,
11293 nsIFrame
** aNewFrame
,
11295 PRBool aIsScrollbar
,
11296 nsILayoutHistoryState
* aFrameState
)
11299 nsresult rv
= NS_OK
;
11301 // Construct a new frame
11302 if (nsnull
!= aParentFrame
) {
11303 nsFrameItems frameItems
;
11304 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
11305 GetAbsoluteContainingBlock(aParentFrame
),
11306 GetFloatContainingBlock(aParentFrame
),
11307 mTempFrameTreeState
);
11309 nsRefPtr
<nsStyleContext
> styleContext
;
11310 styleContext
= ResolveStyleContext(aParentFrame
, aChild
);
11312 // Pre-check for display "none" - only if we find that, do we create
11313 // any frame at all
11314 const nsStyleDisplay
* display
= styleContext
->GetStyleDisplay();
11316 if (NS_STYLE_DISPLAY_NONE
== display
->mDisplay
) {
11317 *aNewFrame
= nsnull
;
11323 rv
= ConstructFrameInternal(state
, aChild
, aParentFrame
, aChild
->Tag(),
11324 aChild
->GetNameSpaceID(), styleContext
,
11325 frameItems
, PR_TRUE
, PR_FALSE
);
11326 if (!state
.mPseudoFrames
.IsEmpty()) {
11327 ProcessPseudoFrames(state
, frameItems
);
11330 nsIFrame
* newFrame
= frameItems
.childList
;
11331 *aNewFrame
= newFrame
;
11333 if (NS_SUCCEEDED(rv
) && (nsnull
!= newFrame
)) {
11334 // Notify the parent frame
11336 rv
= ((nsListBoxBodyFrame
*)aParentFrame
)->ListBoxAppendFrames(newFrame
);
11338 rv
= ((nsListBoxBodyFrame
*)aParentFrame
)->ListBoxInsertFrames(aPrevFrame
, newFrame
);
11346 return NS_ERROR_FAILURE
;
11350 //----------------------------------------
11353 nsCSSFrameConstructor::ConstructBlock(nsFrameConstructorState
& aState
,
11354 const nsStyleDisplay
* aDisplay
,
11355 nsIContent
* aContent
,
11356 nsIFrame
* aParentFrame
,
11357 nsIFrame
* aContentParentFrame
,
11358 nsStyleContext
* aStyleContext
,
11359 nsIFrame
** aNewFrame
,
11360 nsFrameItems
& aFrameItems
,
11361 PRBool aAbsPosContainer
)
11363 // Create column wrapper if necessary
11364 nsIFrame
* blockFrame
= *aNewFrame
;
11365 nsIFrame
* parent
= aParentFrame
;
11366 nsRefPtr
<nsStyleContext
> blockStyle
= aStyleContext
;
11367 const nsStyleColumn
* columns
= aStyleContext
->GetStyleColumn();
11369 if (columns
->mColumnCount
!= NS_STYLE_COLUMN_COUNT_AUTO
11370 || columns
->mColumnWidth
.GetUnit() != eStyleUnit_Auto
) {
11371 nsIFrame
* columnSetFrame
= nsnull
;
11372 columnSetFrame
= NS_NewColumnSetFrame(mPresShell
, aStyleContext
, 0);
11373 if (!columnSetFrame
) {
11374 return NS_ERROR_OUT_OF_MEMORY
;
11377 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, columnSetFrame
);
11378 // See if we need to create a view
11379 nsHTMLContainerFrame::CreateViewForFrame(columnSetFrame
, PR_FALSE
);
11380 blockStyle
= mPresShell
->StyleSet()->
11381 ResolvePseudoStyleFor(aContent
, nsCSSAnonBoxes::columnContent
,
11383 parent
= columnSetFrame
;
11384 *aNewFrame
= columnSetFrame
;
11386 columnSetFrame
->SetInitialChildList(nsnull
, blockFrame
);
11389 blockFrame
->SetStyleContextWithoutNotification(blockStyle
);
11390 InitAndRestoreFrame(aState
, aContent
, parent
, nsnull
, blockFrame
);
11392 nsresult rv
= aState
.AddChild(*aNewFrame
, aFrameItems
, aContent
,
11394 aContentParentFrame
? aContentParentFrame
:
11396 if (NS_FAILED(rv
)) {
11400 // See if we need to create a view, e.g. the frame is absolutely positioned
11401 nsHTMLContainerFrame::CreateViewForFrame(blockFrame
, PR_FALSE
);
11403 if (!mRootElementFrame
) {
11404 // The frame we're constructing will be the root element frame.
11405 // Set mRootElementFrame before processing children.
11406 mRootElementFrame
= *aNewFrame
;
11409 // We should make the outer frame be the absolute containing block,
11410 // if one is required. We have to do this because absolute
11411 // positioning must be computed with respect to the CSS dimensions
11412 // of the element, which are the dimensions of the outer block. But
11413 // we can't really do that because only blocks can have absolute
11414 // children. So use the block and try to compensate with hacks
11415 // in nsBlockFrame::CalculateContainingBlockSizeForAbsolutes.
11416 nsFrameConstructorSaveState absoluteSaveState
;
11417 if (aAbsPosContainer
) {
11418 // NS_ASSERTION(aRelPos, "should have made area frame for this");
11419 aState
.PushAbsoluteContainingBlock(blockFrame
, absoluteSaveState
);
11422 // Process the child content
11423 nsFrameItems childItems
;
11424 rv
= ProcessChildren(aState
, aContent
, aStyleContext
, blockFrame
, PR_TRUE
,
11425 childItems
, PR_TRUE
);
11427 // Set the frame's initial child list
11428 blockFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
11434 AreAllKidsInline(nsIFrame
* aFrameList
)
11436 nsIFrame
* kid
= aFrameList
;
11438 if (!IsInlineOutside(kid
)) {
11441 kid
= kid
->GetNextSibling();
11447 nsCSSFrameConstructor::ConstructInline(nsFrameConstructorState
& aState
,
11448 nsIContent
* aContent
,
11449 nsIFrame
* aParentFrame
,
11451 PRInt32 aNameSpaceID
,
11452 nsStyleContext
* aStyleContext
,
11453 const nsStyleDisplay
* aDisplay
,
11454 nsFrameItems
& aFrameItems
,
11455 nsIFrame
** aNewFrame
)
11457 nsIFrame
*newFrame
;
11459 PRBool positioned
=
11460 NS_STYLE_DISPLAY_INLINE
== aDisplay
->mDisplay
&&
11461 (NS_STYLE_POSITION_RELATIVE
== aDisplay
->mPosition
||
11462 aDisplay
->HasTransform());
11464 newFrame
= NS_NewPositionedInlineFrame(mPresShell
, aStyleContext
);
11466 newFrame
= NS_NewInlineFrame(mPresShell
, aStyleContext
);
11469 // Initialize the frame
11470 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, newFrame
);
11472 nsFrameConstructorSaveState absoluteSaveState
; // definition cannot be inside next block
11473 // because the object's destructor is significant
11474 // this is part of the fix for bug 42372
11476 // Any inline frame might need a view (because of opacity, or fixed background)
11477 nsHTMLContainerFrame::CreateViewForFrame(newFrame
, PR_FALSE
);
11480 // Relatively positioned frames becomes a container for child
11481 // frames that are positioned
11482 aState
.PushAbsoluteContainingBlock(newFrame
, absoluteSaveState
);
11485 // Process the child content
11486 nsFrameItems childItems
;
11487 PRBool kidsAllInline
;
11488 nsresult rv
= ProcessInlineChildren(aState
, aContent
, newFrame
, PR_TRUE
,
11489 childItems
, &kidsAllInline
);
11490 if (kidsAllInline
) {
11491 // Set the inline frame's initial child list
11492 CreateAnonymousFrames(aState
, aContent
, newFrame
, childItems
);
11494 newFrame
->SetInitialChildList(nsnull
, childItems
.childList
);
11495 if (NS_SUCCEEDED(rv
)) {
11496 aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
, aParentFrame
);
11497 *aNewFrame
= newFrame
;
11502 // This inline frame contains several types of children. Therefore
11503 // this frame has to be chopped into several pieces. We will produce
11504 // as a result of this 3 lists of children. The first list contains
11505 // all of the inline children that precede the first block child
11506 // (and may be empty). The second list contains all of the block
11507 // children and any inlines that are between them (and must not be
11508 // empty, otherwise - why are we here?). The final list contains all
11509 // of the inline children that follow the final block child.
11511 // Find the first block child which defines list1 and list2
11512 nsIFrame
* list1
= childItems
.childList
;
11513 nsIFrame
* prevToFirstBlock
;
11514 nsIFrame
* list2
= FindFirstBlock(list1
, &prevToFirstBlock
);
11515 if (prevToFirstBlock
) {
11516 prevToFirstBlock
->SetNextSibling(nsnull
);
11522 // Find the last block child which defines the end of list2 and the
11524 nsIFrame
* afterFirstBlock
= list2
->GetNextSibling();
11525 nsIFrame
* list3
= nsnull
;
11526 nsIFrame
* lastBlock
= FindLastBlock(afterFirstBlock
);
11530 list3
= lastBlock
->GetNextSibling();
11531 lastBlock
->SetNextSibling(nsnull
);
11533 // list1's frames belong to this inline frame so go ahead and take them
11534 newFrame
->SetInitialChildList(nsnull
, list1
);
11536 // list2's frames belong to an anonymous block that we create right
11537 // now. The anonymous block will be the parent of the block children
11539 nsIAtom
* blockStyle
;
11540 nsRefPtr
<nsStyleContext
> blockSC
;
11541 nsIFrame
* blockFrame
;
11543 blockStyle
= nsCSSAnonBoxes::mozAnonymousPositionedBlock
;
11545 blockSC
= mPresShell
->StyleSet()->
11546 ResolvePseudoStyleFor(aContent
, blockStyle
, aStyleContext
);
11549 blockStyle
= nsCSSAnonBoxes::mozAnonymousBlock
;
11551 blockSC
= mPresShell
->StyleSet()->
11552 ResolvePseudoStyleFor(aContent
, blockStyle
, aStyleContext
);
11554 blockFrame
= NS_NewBlockFrame(mPresShell
, blockSC
);
11556 InitAndRestoreFrame(aState
, aContent
, aParentFrame
, nsnull
, blockFrame
, PR_FALSE
);
11558 // Any inline frame could have a view (e.g., opacity)
11559 nsHTMLContainerFrame::CreateViewForFrame(blockFrame
, PR_FALSE
);
11561 if (blockFrame
->HasView() || newFrame
->HasView()) {
11562 // Move list2's frames into the new view
11563 nsHTMLContainerFrame::ReparentFrameViewList(aState
.mPresContext
, list2
,
11564 list2
->GetParent(), blockFrame
);
11567 blockFrame
->SetInitialChildList(nsnull
, list2
);
11569 nsFrameConstructorState
state(mPresShell
, mFixedContainingBlock
,
11570 GetAbsoluteContainingBlock(blockFrame
),
11571 GetFloatContainingBlock(blockFrame
));
11573 // If we have an inline between two blocks all inside an inline and the inner
11574 // inline contains a float, the float will end up in the float list of the
11575 // parent block of the inline, but its parent pointer will be the anonymous
11576 // block we create... AdjustFloatParentPtrs() deals with this by moving the
11577 // float from the outer state |aState| to the inner |state|.
11578 MoveChildrenTo(state
.mFrameManager
, blockFrame
, list2
, nsnull
, &state
,
11581 // list3's frames belong to another inline frame
11582 nsIFrame
* inlineFrame
= nsnull
;
11584 // If we ever start constructing a second inline in the split even when
11585 // list3 is null, the logic in MaybeRecreateContainerForIBSplitterFrame
11586 // needs to be adjusted. Also, if you're changing this code also change
11589 inlineFrame
= MoveFramesToEndOfIBSplit(aState
, nsnull
,
11590 positioned
, aContent
,
11591 aStyleContext
, list3
,
11592 blockFrame
, nsnull
);
11596 // Mark the frames as special (note: marking for inlineFrame is handled by
11597 // MoveFramesToEndOfIBSplit). That way if any of the append/insert/remove
11598 // methods try to fiddle with the children, the containing block will be
11599 // reframed instead.
11600 SetFrameIsSpecial(newFrame
, blockFrame
);
11601 SetFrameIsSpecial(blockFrame
, inlineFrame
);
11602 MarkIBSpecialPrevSibling(blockFrame
, newFrame
);
11604 MarkIBSpecialPrevSibling(inlineFrame
, blockFrame
);
11608 if (gNoisyInlineConstruction
) {
11609 nsIFrameDebug
* frameDebug
;
11611 printf("nsCSSFrameConstructor::ConstructInline:\n");
11612 if ( (frameDebug
= do_QueryFrame(*aNewFrame
)) ) {
11613 printf(" ==> leading inline frame:\n");
11614 frameDebug
->List(stdout
, 2);
11616 if ( (frameDebug
= do_QueryFrame(blockFrame
)) ) {
11617 printf(" ==> block frame:\n");
11618 frameDebug
->List(stdout
, 2);
11620 if ( (frameDebug
= do_QueryFrame(inlineFrame
)) ) {
11621 printf(" ==> trailing inline frame:\n");
11622 frameDebug
->List(stdout
, 2);
11627 if (NS_SUCCEEDED(rv
)) {
11628 aState
.AddChild(newFrame
, aFrameItems
, aContent
, aStyleContext
, aParentFrame
);
11629 *aNewFrame
= newFrame
;
11635 nsCSSFrameConstructor::MoveFramesToEndOfIBSplit(nsFrameConstructorState
& aState
,
11636 nsIFrame
* aExistingEndFrame
,
11637 PRBool aIsPositioned
,
11638 nsIContent
* aContent
,
11639 nsStyleContext
* aStyleContext
,
11640 nsIFrame
* aFramesToMove
,
11641 nsIFrame
* aBlockPart
,
11642 nsFrameConstructorState
* aTargetState
)
11644 NS_PRECONDITION(aFramesToMove
, "Must have frames to move");
11645 NS_PRECONDITION(aBlockPart
, "Must have a block part");
11647 nsIFrame
* inlineFrame
= aExistingEndFrame
;
11648 if (!inlineFrame
) {
11649 if (aIsPositioned
) {
11650 inlineFrame
= NS_NewPositionedInlineFrame(mPresShell
, aStyleContext
);
11653 inlineFrame
= NS_NewInlineFrame(mPresShell
, aStyleContext
);
11656 InitAndRestoreFrame(aState
, aContent
, aBlockPart
->GetParent(), nsnull
,
11657 inlineFrame
, PR_FALSE
);
11659 // Any frame might need a view
11660 nsHTMLContainerFrame::CreateViewForFrame(inlineFrame
, PR_FALSE
);
11663 if (inlineFrame
->HasView() || aFramesToMove
->GetParent()->HasView()) {
11664 // Move list3's frames into the new view
11665 nsHTMLContainerFrame::ReparentFrameViewList(aState
.mPresContext
,
11667 aFramesToMove
->GetParent(),
11671 // Reparent (cheaply) the frames in list3
11672 nsIFrame
* existingFirstChild
= inlineFrame
->GetFirstChild(nsnull
);
11673 if (!existingFirstChild
&&
11674 (inlineFrame
->GetStateBits() & NS_FRAME_FIRST_REFLOW
)) {
11675 inlineFrame
->SetInitialChildList(nsnull
, aFramesToMove
);
11677 inlineFrame
->InsertFrames(nsnull
, nsnull
, aFramesToMove
);
11679 nsFrameConstructorState
* startState
= aTargetState
? &aState
: nsnull
;
11680 MoveChildrenTo(aState
.mFrameManager
, inlineFrame
, aFramesToMove
,
11681 existingFirstChild
, aTargetState
, startState
);
11682 SetFrameIsSpecial(inlineFrame
, nsnull
);
11683 return inlineFrame
;
11687 nsCSSFrameConstructor::ProcessInlineChildren(nsFrameConstructorState
& aState
,
11688 nsIContent
* aContent
,
11690 PRBool aCanHaveGeneratedContent
,
11691 nsFrameItems
& aFrameItems
,
11692 PRBool
* aKidsAllInline
)
11694 nsresult rv
= NS_OK
;
11695 nsStyleContext
* styleContext
= nsnull
;
11697 // save the pseudo frame state
11698 nsPseudoFrames prevPseudoFrames
;
11699 aState
.mPseudoFrames
.Reset(&prevPseudoFrames
);
11701 if (aCanHaveGeneratedContent
) {
11702 // Probe for generated content before
11703 styleContext
= aFrame
->GetStyleContext();
11704 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
11705 styleContext
, nsCSSPseudoElements::before
,
11709 // Iterate the child content objects and construct frames
11710 PRBool allKidsInline
= PR_TRUE
;
11711 ChildIterator iter
, last
;
11712 for (ChildIterator::Init(aContent
, &iter
, &last
);
11715 // Construct a child frame
11716 nsIFrame
* oldLastChild
= aFrameItems
.lastChild
;
11717 rv
= ConstructFrame(aState
, *iter
, aFrame
, aFrameItems
);
11719 if (NS_FAILED(rv
)) {
11723 // Examine newly added children (we may have added more than one
11724 // child if the child was another inline frame that ends up
11725 // being carved in 3 pieces) to maintain the allKidsInline flag.
11726 if (allKidsInline
) {
11728 if (oldLastChild
) {
11729 kid
= oldLastChild
->GetNextSibling();
11732 kid
= aFrameItems
.childList
;
11735 if (!IsInlineOutside(kid
)) {
11736 allKidsInline
= PR_FALSE
;
11739 kid
= kid
->GetNextSibling();
11744 if (aCanHaveGeneratedContent
) {
11745 // Probe for generated content after
11746 CreateGeneratedContentFrame(aState
, aFrame
, aContent
,
11747 styleContext
, nsCSSPseudoElements::after
,
11751 // process the current pseudo frame state
11752 if (!aState
.mPseudoFrames
.IsEmpty()) {
11753 ProcessPseudoFrames(aState
, aFrameItems
);
11754 // recompute allKidsInline to take into account new child frames
11755 // XXX we DON'T do this yet because anonymous table children should
11756 // be accepted as inline children, until we turn on inline-table.
11758 // allKidsInline = AreAllKidsInline(aFrameItems.childList);
11760 // restore the pseudo frame state
11761 aState
.mPseudoFrames
= prevPseudoFrames
;
11763 *aKidsAllInline
= allKidsInline
;
11769 DestroyNewlyCreatedFrames(nsFrameConstructorState
& aState
,
11770 nsIFrame
* aParentFrame
,
11771 const nsFrameItems
& aFrameList
)
11773 // Ok, reverse tracks: wipe out the frames we just created
11774 nsFrameManager
*frameManager
= aState
.mFrameManager
;
11776 // Destroy the frames. As we do make sure any content to frame mappings
11777 // or entries in the undisplayed content map are removed
11778 frameManager
->ClearAllUndisplayedContentIn(aParentFrame
->GetContent());
11780 CleanupFrameReferences(frameManager
, aFrameList
.childList
);
11781 if (aState
.mAbsoluteItems
.childList
) {
11782 CleanupFrameReferences(frameManager
, aState
.mAbsoluteItems
.childList
);
11784 if (aState
.mFixedItems
.childList
) {
11785 CleanupFrameReferences(frameManager
, aState
.mFixedItems
.childList
);
11787 if (aState
.mFloatedItems
.childList
) {
11788 CleanupFrameReferences(frameManager
, aState
.mFloatedItems
.childList
);
11791 if (aState
.mPopupItems
.childList
) {
11792 CleanupFrameReferences(frameManager
, aState
.mPopupItems
.childList
);
11795 nsFrameList
tmp(aFrameList
.childList
);
11796 tmp
.DestroyFrames();
11798 tmp
.SetFrames(aState
.mAbsoluteItems
.childList
);
11799 tmp
.DestroyFrames();
11800 aState
.mAbsoluteItems
.childList
= nsnull
;
11802 tmp
.SetFrames(aState
.mFixedItems
.childList
);
11803 tmp
.DestroyFrames();
11804 aState
.mFixedItems
.childList
= nsnull
;
11806 tmp
.SetFrames(aState
.mFloatedItems
.childList
);
11807 tmp
.DestroyFrames();
11808 aState
.mFloatedItems
.childList
= nsnull
;
11811 tmp
.SetFrames(aState
.mPopupItems
.childList
);
11812 tmp
.DestroyFrames();
11813 aState
.mPopupItems
.childList
= nsnull
;
11818 nsCSSFrameConstructor::WipeContainingBlock(nsFrameConstructorState
& aState
,
11819 nsIFrame
* aContainingBlock
,
11821 const nsFrameItems
& aFrameList
,
11823 nsIFrame
* aPrevSibling
)
11825 if (!aFrameList
.childList
) {
11829 // Before we go and append the frames, we must check for two
11830 // special situations.
11832 // Situation #1 is a XUL frame that contains frames that are required
11833 // to be wrapped in blocks.
11834 if (aFrame
->IsBoxFrame() &&
11835 !(aFrame
->GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK
) &&
11836 AnyKidsNeedBlockParent(aFrameList
.childList
)) {
11837 DestroyNewlyCreatedFrames(aState
, aFrame
, aFrameList
);
11838 RecreateFramesForContent(aFrame
->GetContent());
11842 // Situation #2 is an inline frame that will now contain block
11843 // frames. This is a no-no and the frame construction logic knows
11844 // how to fix this. See defition of IsInlineFrame() for what "an
11845 // inline" is. Whether we have "a block" is tested for by
11846 // AreAllKidsInline.
11848 // We also need to check for an append of content ending in an
11849 // inline to the block in an {ib} split or an insert of content
11850 // starting with an inline to the start of that block. If that
11851 // happens, we also need to reframe, since that content needs to go
11852 // into the following or preceding inline in the split.
11854 if (IsInlineFrame(aFrame
)) {
11855 // Nothing to do if all kids are inline
11856 if (AreAllKidsInline(aFrameList
.childList
)) {
11859 } else if (!IsFrameSpecial(aFrame
)) {
11862 // aFrame is the block in an {ib} split. Check that we're not
11863 // messing up either end of it.
11865 // Will be handled in AppendFrames(), unless we have floats that we can't
11866 // move out because there might be no float containing block to move them
11868 if (!aState
.mFloatedItems
.childList
) {
11872 // Walk up until we get a float containing block that's not part of an
11873 // {ib} split, since otherwise we might have to ship floats out of it
11875 nsIFrame
* floatContainer
= aFrame
;
11877 floatContainer
= GetFloatContainingBlock(
11878 GetIBSplitSpecialPrevSiblingForAnonymousBlock(floatContainer
));
11879 if (!floatContainer
) {
11882 if (!IsFrameSpecial(floatContainer
)) {
11888 if (aPrevSibling
&& !aPrevSibling
->GetNextSibling()) {
11889 // This is an append that won't go through AppendFrames. We can bail out
11890 // if the last frame we're appending is not inline
11891 if (!aFrameList
.lastChild
->GetStyleDisplay()->IsInlineOutside()) {
11895 // We can bail out if we're not inserting at the beginning or if
11896 // the first frame we're inserting is not inline.
11897 if (aPrevSibling
||
11898 !aFrameList
.childList
->GetStyleDisplay()->IsInlineOutside()) {
11904 DestroyNewlyCreatedFrames(aState
, aFrame
, aFrameList
);
11906 // If we don't have a containing block, start with aFrame and look for one.
11907 if (!aContainingBlock
) {
11908 aContainingBlock
= aFrame
;
11911 // To find the right block to reframe, just walk up the tree until we find a
11913 // 1) Not part of an IB split (not special)
11914 // 2) Not a pseudo-frame
11915 // 3) Not an inline frame
11916 // We're guaranteed to find one, since nsStyleContext::ApplyStyleFixups
11917 // enforces that the root is display:none, display:table, or display:block.
11918 // Note that walking up "too far" is OK in terms of correctness, even if it
11919 // might be a little inefficient. This is why we walk out of all
11920 // pseudo-frames -- telling which ones are or are not OK to walk out of is
11921 // too hard (and I suspect that we do in fact need to walk out of all of
11923 while (IsFrameSpecial(aContainingBlock
) || IsInlineOutside(aContainingBlock
) ||
11924 aContainingBlock
->GetStyleContext()->GetPseudoType()) {
11925 aContainingBlock
= aContainingBlock
->GetParent();
11926 NS_ASSERTION(aContainingBlock
,
11927 "Must have non-inline, non-special, non-pseudo frame as root "
11928 "(or child of root, for a table root)!");
11931 // Tell parent of the containing block to reformulate the
11932 // entire block. This is painful and definitely not optimal
11933 // but it will *always* get the right answer.
11935 nsIContent
*blockContent
= aContainingBlock
->GetContent();
11936 nsCOMPtr
<nsIContent
> parentContainer
= blockContent
->GetParent();
11938 if (gNoisyContentUpdates
) {
11939 printf("nsCSSFrameConstructor::WipeContainingBlock: blockContent=%p parentContainer=%p\n",
11940 static_cast<void*>(blockContent
),
11941 static_cast<void*>(parentContainer
));
11944 if (parentContainer
) {
11945 ReinsertContent(parentContainer
, blockContent
);
11947 else if (blockContent
->GetCurrentDoc() == mDocument
) {
11948 ReconstructDocElementHierarchyInternal();
11954 nsCSSFrameConstructor::ReframeContainingBlock(nsIFrame
* aFrame
)
11958 // ReframeContainingBlock is a NASTY routine, it causes terrible performance problems
11959 // so I want to see when it is happening! Unfortunately, it is happening way to often because
11960 // so much content on the web causes 'special' block-in-inline frame situations and we handle them
11962 if (gNoisyContentUpdates
) {
11963 printf("nsCSSFrameConstructor::ReframeContainingBlock frame=%p\n",
11964 static_cast<void*>(aFrame
));
11968 PRBool isReflowing
;
11969 mPresShell
->IsReflowLocked(&isReflowing
);
11971 // don't ReframeContainingBlock, this will result in a crash
11972 // if we remove a tree that's in reflow - see bug 121368 for testcase
11973 NS_ASSERTION(0, "Atemptted to nsCSSFrameConstructor::ReframeContainingBlock during a Reflow!!!");
11977 // Get the first "normal" ancestor of the target frame.
11978 nsIFrame
* containingBlock
= GetIBContainingBlockFor(aFrame
);
11979 if (containingBlock
) {
11980 // From here we look for the containing block in case the target
11981 // frame is already a block (which can happen when an inline frame
11982 // wraps some of its content in an anonymous block; see
11983 // ConstructInline)
11985 // NOTE: We used to get the FloatContainingBlock here, but it was often wrong.
11986 // GetIBContainingBlock works much better and provides the correct container in all cases
11987 // so GetFloatContainingBlock(aFrame) has been removed
11989 // And get the containingBlock's content
11990 nsCOMPtr
<nsIContent
> blockContent
= containingBlock
->GetContent();
11991 if (blockContent
) {
11992 // Now find the containingBlock's content's parent
11993 nsCOMPtr
<nsIContent
> parentContainer
= blockContent
->GetParent();
11994 if (parentContainer
) {
11996 if (gNoisyContentUpdates
) {
11997 printf(" ==> blockContent=%p, parentContainer=%p\n",
11998 static_cast<void*>(blockContent
),
11999 static_cast<void*>(parentContainer
));
12002 return ReinsertContent(parentContainer
, blockContent
);
12007 // If we get here, we're screwed!
12008 return ReconstructDocElementHierarchyInternal();
12012 nsCSSFrameConstructor::RemoveFixedItems(const nsFrameConstructorState
& aState
,
12013 nsIFrame
*aRootElementFrame
)
12017 if (mFixedContainingBlock
) {
12018 nsIFrame
*fixedChild
= nsnull
;
12020 fixedChild
= mFixedContainingBlock
->GetFirstChild(nsGkAtoms::fixedList
);
12021 if (fixedChild
&& fixedChild
== aRootElementFrame
) {
12022 // Skip the root element frame, if it happens to be fixed-positioned
12023 // It will be explicitly removed later in
12024 // ReconstructDocElementHierarchyInternal
12025 fixedChild
= fixedChild
->GetNextSibling();
12028 // Remove the placeholder so it doesn't end up sitting about pointing
12029 // to the removed fixed frame.
12030 nsPlaceholderFrame
*placeholderFrame
=
12031 aState
.mFrameManager
->GetPlaceholderFrameFor(fixedChild
);
12032 NS_ASSERTION(placeholderFrame
, "no placeholder for fixed-pos frame");
12033 NS_ASSERTION(placeholderFrame
->GetType() ==
12034 nsGkAtoms::placeholderFrame
,
12036 UnregisterPlaceholderChain(aState
.mFrameManager
, placeholderFrame
);
12037 nsIFrame
* placeholderParent
= placeholderFrame
->GetParent();
12038 ::DeletingFrameSubtree(aState
.mFrameManager
, placeholderFrame
);
12039 rv
= aState
.mFrameManager
->RemoveFrame(placeholderParent
, nsnull
,
12041 if (NS_FAILED(rv
)) {
12042 NS_WARNING("Error removing placeholder for fixed frame in RemoveFixedItems");
12046 ::DeletingFrameSubtree(aState
.mFrameManager
, fixedChild
);
12047 rv
= aState
.mFrameManager
->RemoveFrame(mFixedContainingBlock
,
12048 nsGkAtoms::fixedList
,
12050 if (NS_FAILED(rv
)) {
12051 NS_WARNING("Error removing frame from fixed containing block in RemoveFixedItems");
12055 } while(fixedChild
);
12057 NS_WARNING( "RemoveFixedItems called with no FixedContainingBlock data member set");
12063 nsCSSFrameConstructor::RestyleForAppend(nsIContent
* aContainer
,
12064 PRInt32 aNewIndexInContainer
)
12066 NS_ASSERTION(aContainer
, "must have container for append");
12069 for (PRInt32 index
= aNewIndexInContainer
;; ++index
) {
12070 nsIContent
*content
= aContainer
->GetChildAt(index
);
12072 NS_ASSERTION(index
!= aNewIndexInContainer
, "yikes, nothing appended");
12075 NS_ASSERTION(!content
->IsRootOfAnonymousSubtree(),
12076 "anonymous nodes should not be in child lists");
12080 PRUint32 selectorFlags
=
12081 aContainer
->GetFlags() & (NODE_ALL_SELECTOR_FLAGS
&
12082 ~NODE_HAS_SLOW_SELECTOR_NOAPPEND
);
12083 if (selectorFlags
== 0)
12086 if (selectorFlags
& NODE_HAS_SLOW_SELECTOR
) {
12087 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12088 // Restyling the container is the most we can do here, so we're done.
12092 if (selectorFlags
& NODE_HAS_EMPTY_SELECTOR
) {
12093 // see whether we need to restyle the container
12094 PRBool wasEmpty
= PR_TRUE
; // :empty or :-moz-only-whitespace
12095 for (PRInt32 index
= 0; index
< aNewIndexInContainer
; ++index
) {
12096 // We don't know whether we're testing :empty or :-moz-only-whitespace,
12097 // so be conservative and assume :-moz-only-whitespace (i.e., make
12098 // IsSignificantChild less likely to be true, and thus make us more
12099 // likely to restyle).
12100 if (nsStyleUtil::IsSignificantChild(aContainer
->GetChildAt(index
),
12101 PR_TRUE
, PR_FALSE
)) {
12102 wasEmpty
= PR_FALSE
;
12107 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12108 // Restyling the container is the most we can do here, so we're done.
12112 if (selectorFlags
& NODE_HAS_EDGE_CHILD_SELECTOR
) {
12113 // restyle the last element child before this node
12114 for (PRInt32 index
= aNewIndexInContainer
- 1; index
>= 0; --index
) {
12115 nsIContent
*content
= aContainer
->GetChildAt(index
);
12116 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
12117 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12124 // Restyling for a ContentInserted or CharacterDataChanged notification.
12125 // This could be used for ContentRemoved as well if we got the
12126 // notification before the removal happened (and sometimes
12127 // CharacterDataChanged is more like a removal than an addition).
12128 // The comments are written and variables are named in terms of it being
12129 // a ContentInserted notification.
12131 nsCSSFrameConstructor::RestyleForInsertOrChange(nsIContent
* aContainer
,
12132 nsIContent
* aChild
)
12134 NS_ASSERTION(!aChild
->IsRootOfAnonymousSubtree(),
12135 "anonymous nodes should not be in child lists");
12136 PRUint32 selectorFlags
=
12137 aContainer
? (aContainer
->GetFlags() & NODE_ALL_SELECTOR_FLAGS
) : 0;
12138 if (selectorFlags
== 0)
12141 if (selectorFlags
& (NODE_HAS_SLOW_SELECTOR
|
12142 NODE_HAS_SLOW_SELECTOR_NOAPPEND
)) {
12143 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12144 // Restyling the container is the most we can do here, so we're done.
12148 if (selectorFlags
& NODE_HAS_EMPTY_SELECTOR
) {
12149 // see whether we need to restyle the container
12150 PRBool wasEmpty
= PR_TRUE
; // :empty or :-moz-only-whitespace
12151 for (PRInt32 index
= 0; ; ++index
) {
12152 nsIContent
*child
= aContainer
->GetChildAt(index
);
12153 if (!child
) // last child
12155 if (child
== aChild
)
12157 // We don't know whether we're testing :empty or :-moz-only-whitespace,
12158 // so be conservative and assume :-moz-only-whitespace (i.e., make
12159 // IsSignificantChild less likely to be true, and thus make us more
12160 // likely to restyle).
12161 if (nsStyleUtil::IsSignificantChild(child
, PR_TRUE
, PR_FALSE
)) {
12162 wasEmpty
= PR_FALSE
;
12167 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12168 // Restyling the container is the most we can do here, so we're done.
12173 if (selectorFlags
& NODE_HAS_EDGE_CHILD_SELECTOR
) {
12174 // restyle the previously-first element child if it is after this node
12175 PRBool passedChild
= PR_FALSE
;
12176 for (PRInt32 index
= 0; ; ++index
) {
12177 nsIContent
*content
= aContainer
->GetChildAt(index
);
12179 break; // went through all children
12180 if (content
== aChild
) {
12181 passedChild
= PR_TRUE
;
12184 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
12186 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12191 // restyle the previously-last element child if it is before this node
12192 passedChild
= PR_FALSE
;
12193 for (PRInt32 index
= aContainer
->GetChildCount() - 1;
12194 index
>= 0; --index
) {
12195 nsIContent
*content
= aContainer
->GetChildAt(index
);
12196 if (content
== aChild
) {
12197 passedChild
= PR_TRUE
;
12200 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
12202 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12211 nsCSSFrameConstructor::RestyleForRemove(nsIContent
* aContainer
,
12212 nsIContent
* aOldChild
,
12213 PRInt32 aIndexInContainer
)
12215 NS_ASSERTION(!aOldChild
->IsRootOfAnonymousSubtree(),
12216 "anonymous nodes should not be in child lists");
12217 PRUint32 selectorFlags
=
12218 aContainer
? (aContainer
->GetFlags() & NODE_ALL_SELECTOR_FLAGS
) : 0;
12219 if (selectorFlags
== 0)
12222 if (selectorFlags
& (NODE_HAS_SLOW_SELECTOR
|
12223 NODE_HAS_SLOW_SELECTOR_NOAPPEND
)) {
12224 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12225 // Restyling the container is the most we can do here, so we're done.
12229 if (selectorFlags
& NODE_HAS_EMPTY_SELECTOR
) {
12230 // see whether we need to restyle the container
12231 PRBool isEmpty
= PR_TRUE
; // :empty or :-moz-only-whitespace
12232 for (PRInt32 index
= 0; ; ++index
) {
12233 nsIContent
*child
= aContainer
->GetChildAt(index
);
12234 if (!child
) // last child
12236 // We don't know whether we're testing :empty or :-moz-only-whitespace,
12237 // so be conservative and assume :-moz-only-whitespace (i.e., make
12238 // IsSignificantChild less likely to be true, and thus make us more
12239 // likely to restyle).
12240 if (nsStyleUtil::IsSignificantChild(child
, PR_TRUE
, PR_FALSE
)) {
12241 isEmpty
= PR_FALSE
;
12246 PostRestyleEvent(aContainer
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12247 // Restyling the container is the most we can do here, so we're done.
12252 if (selectorFlags
& NODE_HAS_EDGE_CHILD_SELECTOR
) {
12253 // restyle the previously-first element child if it is after aOldChild
12254 for (PRInt32 index
= 0; ; ++index
) {
12255 nsIContent
*content
= aContainer
->GetChildAt(index
);
12257 break; // went through all children
12258 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
12259 if (index
>= aIndexInContainer
) {
12260 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12265 // restyle the previously-last element child if it is before aOldChild
12266 for (PRInt32 index
= aContainer
->GetChildCount() - 1;
12267 index
>= 0; --index
) {
12268 nsIContent
*content
= aContainer
->GetChildAt(index
);
12269 if (content
->IsNodeOfType(nsINode::eELEMENT
)) {
12270 if (index
< aIndexInContainer
) {
12271 PostRestyleEvent(content
, eReStyle_Self
, NS_STYLE_HINT_NONE
);
12280 static PLDHashOperator
12281 CollectRestyles(nsISupports
* aContent
,
12282 nsCSSFrameConstructor::RestyleData
& aData
,
12283 void* aRestyleArrayPtr
)
12285 nsCSSFrameConstructor::RestyleEnumerateData
** restyleArrayPtr
=
12286 static_cast<nsCSSFrameConstructor::RestyleEnumerateData
**>
12287 (aRestyleArrayPtr
);
12288 nsCSSFrameConstructor::RestyleEnumerateData
* currentRestyle
=
12290 currentRestyle
->mContent
= static_cast<nsIContent
*>(aContent
);
12291 currentRestyle
->mRestyleHint
= aData
.mRestyleHint
;
12292 currentRestyle
->mChangeHint
= aData
.mChangeHint
;
12294 // Increment to the next slot in the array
12295 *restyleArrayPtr
= currentRestyle
+ 1;
12297 return PL_DHASH_NEXT
;
12301 nsCSSFrameConstructor::ProcessOneRestyle(nsIContent
* aContent
,
12302 nsReStyleHint aRestyleHint
,
12303 nsChangeHint aChangeHint
)
12305 NS_PRECONDITION(aContent
, "Must have content node");
12307 if (!aContent
->IsInDoc() ||
12308 aContent
->GetCurrentDoc() != mDocument
) {
12309 // Content node has been removed from our document; nothing else
12314 nsIFrame
* primaryFrame
= mPresShell
->GetPrimaryFrameFor(aContent
);
12315 if (aRestyleHint
& eReStyle_Self
) {
12316 RestyleElement(aContent
, primaryFrame
, aChangeHint
);
12317 } else if (aChangeHint
&&
12319 (aChangeHint
& nsChangeHint_ReconstructFrame
))) {
12320 // Don't need to recompute style; just apply the hint
12321 nsStyleChangeList changeList
;
12322 changeList
.AppendChange(primaryFrame
, aContent
, aChangeHint
);
12323 ProcessRestyledFrames(changeList
);
12326 if (aRestyleHint
& eReStyle_LaterSiblings
) {
12327 RestyleLaterSiblings(aContent
);
12331 #define RESTYLE_ARRAY_STACKSIZE 128
12334 nsCSSFrameConstructor::RebuildAllStyleData(nsChangeHint aExtraHint
)
12336 NS_ASSERTION(!(aExtraHint
& nsChangeHint_ReconstructFrame
),
12337 "Should not reconstruct the root of the frame tree. "
12338 "Use ReconstructDocElementHierarchy instead.");
12340 mRebuildAllStyleData
= PR_FALSE
;
12341 NS_UpdateHint(aExtraHint
, mRebuildAllExtraHint
);
12342 mRebuildAllExtraHint
= nsChangeHint(0);
12344 if (!mPresShell
|| !mPresShell
->GetRootFrame())
12347 nsAutoScriptBlocker scriptBlocker
;
12349 // Make sure that the viewmanager will outlive the presshell
12350 nsIViewManager::UpdateViewBatch
batch(mPresShell
->GetViewManager());
12352 // Processing the style changes could cause a flush that propagates to
12353 // the parent frame and thus destroys the pres shell.
12354 nsCOMPtr
<nsIPresShell
> kungFuDeathGrip(mPresShell
);
12356 // Tell the style set to get the old rule tree out of the way
12357 // so we can recalculate while maintaining rule tree immutability
12358 nsresult rv
= mPresShell
->StyleSet()->BeginReconstruct();
12359 if (NS_FAILED(rv
)) {
12360 batch
.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC
);
12364 // Recalculate all of the style contexts for the document
12365 // Note that we can ignore the return value of ComputeStyleChangeFor
12366 // because we never need to reframe the root frame
12367 // XXX This could be made faster by not rerunning rule matching
12368 // (but note that nsPresShell::SetPreferenceStyleRules currently depends
12369 // on us re-running rule matching here
12370 nsStyleChangeList changeList
;
12371 // XXX Does it matter that we're passing aExtraHint to the real root
12372 // frame and not the root node's primary frame?
12373 mPresShell
->FrameManager()->ComputeStyleChangeFor(mPresShell
->GetRootFrame(),
12374 &changeList
, aExtraHint
);
12375 // Process the required changes
12376 ProcessRestyledFrames(changeList
);
12377 // Tell the style set it's safe to destroy the old rule tree. We
12378 // must do this after the ProcessRestyledFrames call in case the
12379 // change list has frame reconstructs in it (since frames to be
12380 // reconstructed will still have their old style context pointers
12381 // until they are destroyed).
12382 mPresShell
->StyleSet()->EndReconstruct();
12383 batch
.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC
);
12387 nsCSSFrameConstructor::ProcessPendingRestyles()
12389 NS_PRECONDITION(mDocument
, "No document? Pshaw!\n");
12390 NS_PRECONDITION(!nsContentUtils::IsSafeToRunScript(),
12391 "Missing a script blocker!");
12393 PRUint32 count
= mPendingRestyles
.Count();
12396 // Use the stack if we can, otherwise fall back on heap-allocation.
12397 nsAutoTArray
<RestyleEnumerateData
, RESTYLE_ARRAY_STACKSIZE
> restyleArr
;
12398 RestyleEnumerateData
* restylesToProcess
= restyleArr
.AppendElements(count
);
12400 if (!restylesToProcess
) {
12404 RestyleEnumerateData
* lastRestyle
= restylesToProcess
;
12405 mPendingRestyles
.Enumerate(CollectRestyles
, &lastRestyle
);
12407 NS_ASSERTION(lastRestyle
- restylesToProcess
== PRInt32(count
),
12408 "Enumeration screwed up somehow");
12410 // Clear the hashtable so we don't end up trying to process a restyle we're
12411 // already processing, sending us into an infinite loop.
12412 mPendingRestyles
.Clear();
12414 // Make sure to not rebuild quote or counter lists while we're
12415 // processing restyles
12418 for (RestyleEnumerateData
* currentRestyle
= restylesToProcess
;
12419 currentRestyle
!= lastRestyle
;
12420 ++currentRestyle
) {
12421 ProcessOneRestyle(currentRestyle
->mContent
,
12422 currentRestyle
->mRestyleHint
,
12423 currentRestyle
->mChangeHint
);
12429 mPresShell
->VerifyStyleTree();
12433 if (mRebuildAllStyleData
) {
12434 // We probably wasted a lot of work up above, but this seems safest
12435 // and it should be rarely used.
12436 RebuildAllStyleData(nsChangeHint(0));
12441 nsCSSFrameConstructor::PostRestyleEvent(nsIContent
* aContent
,
12442 nsReStyleHint aRestyleHint
,
12443 nsChangeHint aMinChangeHint
)
12445 if (NS_UNLIKELY(mIsDestroyingFrameTree
)) {
12446 NS_NOTREACHED("PostRestyleEvent after the shell is destroyed (bug 279505)");
12450 if (aRestyleHint
== 0 && !aMinChangeHint
) {
12451 // Nothing to do here
12455 NS_ASSERTION(aContent
->IsNodeOfType(nsINode::eELEMENT
),
12456 "Shouldn't be trying to restyle non-elements directly");
12458 RestyleData existingData
;
12459 existingData
.mRestyleHint
= nsReStyleHint(0);
12460 existingData
.mChangeHint
= NS_STYLE_HINT_NONE
;
12462 mPendingRestyles
.Get(aContent
, &existingData
);
12463 existingData
.mRestyleHint
=
12464 nsReStyleHint(existingData
.mRestyleHint
| aRestyleHint
);
12465 NS_UpdateHint(existingData
.mChangeHint
, aMinChangeHint
);
12467 mPendingRestyles
.Put(aContent
, existingData
);
12469 PostRestyleEventInternal();
12473 nsCSSFrameConstructor::PostRestyleEventInternal()
12475 if (!mRestyleEvent
.IsPending()) {
12476 nsRefPtr
<RestyleEvent
> ev
= new RestyleEvent(this);
12477 if (NS_FAILED(NS_DispatchToCurrentThread(ev
))) {
12478 NS_WARNING("failed to dispatch restyle event");
12481 mRestyleEvent
= ev
;
12487 nsCSSFrameConstructor::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint
)
12489 NS_ASSERTION(!(aExtraHint
& nsChangeHint_ReconstructFrame
),
12490 "Should not reconstruct the root of the frame tree. "
12491 "Use ReconstructDocElementHierarchy instead.");
12493 mRebuildAllStyleData
= PR_TRUE
;
12494 NS_UpdateHint(mRebuildAllExtraHint
, aExtraHint
);
12495 // Get a restyle event posted if necessary
12496 PostRestyleEventInternal();
12499 NS_IMETHODIMP
nsCSSFrameConstructor::RestyleEvent::Run()
12502 return NS_OK
; // event was revoked
12504 // Make sure that any restyles that happen from now on will go into
12506 mConstructor
->mRestyleEvent
.Forget();
12508 return mConstructor
->mPresShell
->FlushPendingNotifications(Flush_Style
);
12512 nsCSSFrameConstructor::LazyGenerateChildrenEvent::Run()
12514 mPresShell
->GetDocument()->FlushPendingNotifications(Flush_Layout
);
12516 // this is hard-coded to handle only menu popup frames
12517 nsIFrame
* frame
= mPresShell
->GetPrimaryFrameFor(mContent
);
12518 if (frame
&& frame
->GetType() == nsGkAtoms::menuPopupFrame
) {
12520 // it is possible that the frame is different than the one that requested
12521 // the lazy generation, but as long as it's a popup frame that hasn't
12522 // generated its children yet, that's OK.
12523 nsMenuPopupFrame
* menuPopupFrame
= static_cast<nsMenuPopupFrame
*>(frame
);
12524 if (menuPopupFrame
->HasGeneratedChildren()) {
12526 mCallback(mContent
, frame
, mArg
);
12531 // indicate that the children have been generated
12532 menuPopupFrame
->SetGeneratedChildren();
12536 nsAutoScriptBlocker scriptBlocker
;
12537 nsCSSFrameConstructor
* fc
= mPresShell
->FrameConstructor();
12540 nsFrameItems childItems
;
12541 nsFrameConstructorState
state(mPresShell
, nsnull
, nsnull
, nsnull
);
12542 nsresult rv
= fc
->ProcessChildren(state
, mContent
, frame
->GetStyleContext(),
12543 frame
, PR_FALSE
, childItems
, PR_FALSE
);
12544 if (NS_FAILED(rv
)) {
12549 frame
->SetInitialChildList(nsnull
, childItems
.childList
);
12555 mCallback(mContent
, frame
, mArg
);
12557 // call XBL constructors after the frames are created
12558 mPresShell
->GetDocument()->BindingManager()->ProcessAttachedQueue();