Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles, a=lizzard
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */// vim:cindent:ts=2:et:sw=2:/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *//* * construction of a frame tree that is nearly isomorphic to the content * tree and updating of that tree in response to dynamic changes */#include"nsCSSFrameConstructor.h"#include"mozilla/AutoRestore.h"#include"mozilla/DebugOnly.h"#include"mozilla/dom/HTMLSelectElement.h"#include"mozilla/EventStates.h"#include"mozilla/Likely.h"#include"mozilla/LinkedList.h"#include"nsAbsoluteContainingBlock.h"#include"nsIAtom.h"#include"nsIFrameInlines.h"#include"nsGkAtoms.h"#include"nsPresContext.h"#include"nsIDocument.h"#include"nsTableFrame.h"#include"nsTableColFrame.h"#include"nsTableRowFrame.h"#include"nsTableCellFrame.h"#include"nsIDOMHTMLDocument.h"#include"nsHTMLParts.h"#include"nsPresShell.h"#include"nsIPresShell.h"#include"nsUnicharUtils.h"#include"nsStyleSet.h"#include"nsViewManager.h"#include"nsStyleConsts.h"#include"nsIDOMXULElement.h"#include"nsContainerFrame.h"#include"nsNameSpaceManager.h"#include"nsIComboboxControlFrame.h"#include"nsIListControlFrame.h"#include"nsIDOMCharacterData.h"#include"nsPlaceholderFrame.h"#include"nsTableRowGroupFrame.h"#include"nsIFormControl.h"#include"nsCSSAnonBoxes.h"#include"nsTextFragment.h"#include"nsIAnonymousContentCreator.h"#include"nsBindingManager.h"#include"nsXBLBinding.h"#include"nsContentUtils.h"#include"nsIScriptError.h"#ifdef XP_MACOSX#include"nsIDocShell.h"#endif#include"ChildIterator.h"#include"nsError.h"#include"nsLayoutUtils.h"#include"nsAutoPtr.h"#include"nsBoxFrame.h"#include"nsBoxLayout.h"#include"nsFlexContainerFrame.h"#include"nsGridContainerFrame.h"#include"nsRubyFrame.h"#include"nsRubyBaseFrame.h"#include"nsRubyBaseContainerFrame.h"#include"nsRubyTextFrame.h"#include"nsRubyTextContainerFrame.h"#include"nsImageFrame.h"#include"nsIObjectLoadingContent.h"#include"nsTArray.h"#include"nsGenericDOMDataNode.h"#include"mozilla/dom/Element.h"#include"nsAutoLayoutPhase.h"#include"nsStyleStructInlines.h"#include"nsPageContentFrame.h"#include"RestyleManager.h"#include"StickyScrollContainer.h"#include"nsFieldSetFrame.h"#include"nsInlineFrame.h"#include"nsBlockFrame.h"#include"nsCanvasFrame.h"#include"nsFirstLetterFrame.h"#include"nsGfxScrollFrame.h"#include"nsPageFrame.h"#include"nsSimplePageSequenceFrame.h"#include"nsTableOuterFrame.h"#include"nsIScrollableFrame.h"#include"nsTransitionManager.h"#ifdef MOZ_XUL#include"nsIRootBox.h"#endif#ifdef ACCESSIBILITY#include"nsAccessibilityService.h"#endif#include"nsXBLService.h"#undef NOISY_FIRST_LETTER#include"nsMathMLParts.h"#include"mozilla/dom/SVGTests.h"#include"nsSVGUtils.h"#include"nsRefreshDriver.h"#include"nsRuleProcessorData.h"#include"nsTextNode.h"#include"ActiveLayerTracker.h"usingnamespacemozilla;usingnamespacemozilla::dom;// An alias for convenience.staticconstnsIFrame::ChildListIDkPrincipalList=nsIFrame::kPrincipalList;nsIFrame*NS_NewHTMLCanvasFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewHTMLVideoFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewSVGOuterSVGFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewSVGOuterSVGAnonChildFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGInnerSVGFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGPathGeometryFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGGFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGGenericContainerFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewSVGForeignObjectFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGAFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGSwitchFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGTextFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGContainerFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGUseFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGViewFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);externnsIFrame*NS_NewSVGLinearGradientFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);externnsIFrame*NS_NewSVGRadialGradientFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);externnsIFrame*NS_NewSVGStopFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewSVGMarkerFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewSVGMarkerAnonChildFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);externnsIFrame*NS_NewSVGImageFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGClipPathFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGFilterFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGPatternFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGMaskFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGFEContainerFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGFELeafFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGFEImageFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSVGFEUnstyledLeafFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);#include"mozilla/dom/NodeInfo.h"#include"prenv.h"#include"nsNodeInfoManager.h"#include"nsContentCreatorFunctions.h"#ifdef DEBUG// Set the environment variable GECKO_FRAMECTOR_DEBUG_FLAGS to one or// more of the following flags (comma separated) for handy debug// output.staticboolgNoisyContentUpdates=false;staticboolgReallyNoisyContentUpdates=false;staticboolgNoisyInlineConstruction=false;structFrameCtorDebugFlags{constchar*name;bool*on;};staticFrameCtorDebugFlagsgFlags[]={{"content-updates",&gNoisyContentUpdates},{"really-noisy-content-updates",&gReallyNoisyContentUpdates},{"noisy-inline",&gNoisyInlineConstruction}};#define NUM_DEBUG_FLAGS (sizeof(gFlags) / sizeof(gFlags[0]))#endif#ifdef MOZ_XUL#include"nsMenuFrame.h"#include"nsPopupSetFrame.h"#include"nsTreeColFrame.h"#include"nsIBoxObject.h"#include"nsPIListBoxObject.h"#include"nsListBoxBodyFrame.h"#include"nsListItemFrame.h"#include"nsXULLabelFrame.h"//------------------------------------------------------------------nsIFrame*NS_NewAutoRepeatBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewRootBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsContainerFrame*NS_NewDocElementBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewThumbFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewDeckFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewLeafBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewStackFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewProgressMeterFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewRangeFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewImageBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewTextBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewGroupBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewButtonBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewSplitterFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewMenuPopupFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewPopupSetFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewMenuFrame(nsIPresShell*aPresShell,nsStyleContext*aContext,uint32_taFlags);nsIFrame*NS_NewMenuBarFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewTreeBodyFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);// gridnsresultNS_NewGridLayout2(nsIPresShell*aPresShell,nsBoxLayout**aNewLayout);nsIFrame*NS_NewGridRowLeafFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewGridRowGroupFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);// end gridnsIFrame*NS_NewTitleBarFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewResizerFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);#endifnsHTMLScrollFrame*NS_NewHTMLScrollFrame(nsIPresShell*aPresShell,nsStyleContext*aContext,boolaIsRoot);nsXULScrollFrame*NS_NewXULScrollFrame(nsIPresShell*aPresShell,nsStyleContext*aContext,boolaIsRoot,boolaClipAllDescendants);nsIFrame*NS_NewSliderFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewScrollbarFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);nsIFrame*NS_NewScrollbarButtonFrame(nsIPresShell*aPresShell,nsStyleContext*aContext);#ifdef NOISY_FINDFRAMEstaticint32_tFFWC_totalCount=0;staticint32_tFFWC_doLoop=0;staticint32_tFFWC_doSibling=0;staticint32_tFFWC_recursions=0;staticint32_tFFWC_nextInFlows=0;#endif// Returns true if aFrame is an anonymous flex/grid item.staticinlineboolIsAnonymousFlexOrGridItem(constnsIFrame*aFrame){constnsIAtom*pseudoType=aFrame->StyleContext()->GetPseudo();returnpseudoType==nsCSSAnonBoxes::anonymousFlexItem||pseudoType==nsCSSAnonBoxes::anonymousGridItem;}// Returns true if aFrame is a flex/grid container.staticinlineboolIsFlexOrGridContainer(constnsIFrame*aFrame){constnsIAtom*t=aFrame->GetType();returnt==nsGkAtoms::flexContainerFrame||t==nsGkAtoms::gridContainerFrame;}#if DEBUGstaticvoidAssertAnonymousFlexOrGridItemParent(constnsIFrame*aChild,constnsIFrame*aParent){MOZ_ASSERT(IsAnonymousFlexOrGridItem(aChild),"expected an anonymous flex or grid item child frame");MOZ_ASSERT(aParent,"expected a parent frame");constnsIAtom*pseudoType=aChild->StyleContext()->GetPseudo();if(pseudoType==nsCSSAnonBoxes::anonymousFlexItem){MOZ_ASSERT(aParent->GetType()==nsGkAtoms::flexContainerFrame,"anonymous flex items should only exist as children ""of flex container frames");}else{MOZ_ASSERT(aParent->GetType()==nsGkAtoms::gridContainerFrame,"anonymous grid items should only exist as children ""of grid container frames");}}#else#define AssertAnonymousFlexOrGridItemParent(x, y) do { /* nothing */ } while(0)#endifstaticinlinensContainerFrame*GetFieldSetBlockFrame(nsIFrame*aFieldsetFrame){// Depends on the fieldset child frame order - see ConstructFieldSetFrame() below.nsIFrame*firstChild=aFieldsetFrame->GetFirstPrincipalChild();nsIFrame*inner=firstChild&&firstChild->GetNextSibling()?firstChild->GetNextSibling():firstChild;returninner?inner->GetContentInsertionFrame():nullptr;}#define FCDATA_DECL(_flags, _func) \ { _flags, { (FrameCreationFunc)_func }, nullptr, nullptr }#define FCDATA_WITH_WRAPPING_BLOCK(_flags, _func, _anon_box) \ { _flags | FCDATA_CREATE_BLOCK_WRAPPER_FOR_ALL_KIDS, \ { (FrameCreationFunc)_func }, nullptr, &_anon_box }//----------------------------------------------------------------------/** * True if aFrame is an actual inline frame in the sense of non-replaced * display:inline CSS boxes. In other words, it can be affected by {ib} * splitting and can contain first-letter frames. Basically, this is either an * inline frame (positioned or otherwise) or an line frame (this last because * it can contain first-letter and because inserting blocks in the middle of it * needs to terminate it). */staticboolIsInlineFrame(constnsIFrame*aFrame){returnaFrame->IsFrameOfType(nsIFrame::eLineParticipant);}/** * True if aFrame is an instance of an SVG frame class or is an inline/block * frame being used for SVG text. */staticboolIsFrameForSVG(constnsIFrame*aFrame){returnaFrame->IsFrameOfType(nsIFrame::eSVG)||aFrame->IsSVGText();}/** * Returns true iff aFrame explicitly prevents its descendants from floating * (at least, down to the level of descendants which themselves are * float-containing blocks -- those will manage the floating status of any * lower-level descendents inside them, of course). */staticboolShouldSuppressFloatingOfDescendants(nsIFrame*aFrame){returnaFrame->IsFrameOfType(nsIFrame::eMathML)||aFrame->IsBoxFrame()||::IsFlexOrGridContainer(aFrame);}/** * If any children require a block parent, return the first such child. * Otherwise return null. */staticnsIContent*AnyKidsNeedBlockParent(nsIFrame*aFrameList){for(nsIFrame*k=aFrameList;k;k=k->GetNextSibling()){// Line participants, such as text and inline frames, can't be// directly inside a XUL box; they must be wrapped in an// intermediate block.if(k->IsFrameOfType(nsIFrame::eLineParticipant)){returnk->GetContent();}}returnnullptr;}// Reparent a frame into a wrapper frame that is a child of its old parent.staticvoidReparentFrame(RestyleManager*aRestyleManager,nsContainerFrame*aNewParentFrame,nsIFrame*aFrame){aFrame->SetParent(aNewParentFrame);aRestyleManager->ReparentStyleContext(aFrame);}staticvoidReparentFrames(nsCSSFrameConstructor*aFrameConstructor,nsContainerFrame*aNewParentFrame,constnsFrameList&aFrameList){RestyleManager*restyleManager=aFrameConstructor->RestyleManager();for(nsFrameList::Enumeratore(aFrameList);!e.AtEnd();e.Next()){ReparentFrame(restyleManager,aNewParentFrame,e.get());}}//----------------------------------------------------------------------//// When inline frames get weird and have block frames in them, we// annotate them to help us respond to incremental content changes// more easily.staticinlineboolIsFramePartOfIBSplit(nsIFrame*aFrame){return(aFrame->GetStateBits()&NS_FRAME_PART_OF_IBSPLIT)!=0;}staticnsContainerFrame*GetIBSplitSibling(nsIFrame*aFrame){NS_PRECONDITION(IsFramePartOfIBSplit(aFrame),"Shouldn't call this");// We only store the "ib-split sibling" annotation with the first// frame in the continuation chain. Walk back to find that frame now.returnstatic_cast<nsContainerFrame*>(aFrame->FirstContinuation()->Properties().Get(nsIFrame::IBSplitSibling()));}staticnsContainerFrame*GetIBSplitPrevSibling(nsIFrame*aFrame){NS_PRECONDITION(IsFramePartOfIBSplit(aFrame),"Shouldn't call this");// We only store the ib-split sibling annotation with the first// frame in the continuation chain. Walk back to find that frame now.returnstatic_cast<nsContainerFrame*>(aFrame->FirstContinuation()->Properties().Get(nsIFrame::IBSplitPrevSibling()));}staticnsContainerFrame*GetLastIBSplitSibling(nsIFrame*aFrame,boolaReturnEmptyTrailingInline){for(nsIFrame*frame=aFrame,*next;;frame=next){next=GetIBSplitSibling(frame);if(!next||(!aReturnEmptyTrailingInline&&!next->GetFirstPrincipalChild()&&!GetIBSplitSibling(next))){NS_ASSERTION(!next||!frame->IsInlineOutside(),"Should have a block here!");returnstatic_cast<nsContainerFrame*>(frame);}}NS_NOTREACHED("unreachable code");returnnullptr;}staticvoidSetFrameIsIBSplit(nsContainerFrame*aFrame,nsIFrame*aIBSplitSibling){NS_PRECONDITION(aFrame,"bad args!");// We should be the only continuationNS_ASSERTION(!aFrame->GetPrevContinuation(),"assigning ib-split sibling to other than first continuation!");NS_ASSERTION(!aFrame->GetNextContinuation()||IsFramePartOfIBSplit(aFrame->GetNextContinuation()),"should have no non-ib-split continuations here");// Mark the frame as ib-split.aFrame->AddStateBits(NS_FRAME_PART_OF_IBSPLIT);if(aIBSplitSibling){NS_ASSERTION(!aIBSplitSibling->GetPrevContinuation(),"assigning something other than the first continuation as the ""ib-split sibling");// Store the ib-split sibling (if we were given one) with the// first frame in the flow.FramePropertyTable*props=aFrame->PresContext()->PropertyTable();props->Set(aFrame,nsIFrame::IBSplitSibling(),aIBSplitSibling);props->Set(aIBSplitSibling,nsIFrame::IBSplitPrevSibling(),aFrame);}}staticnsIFrame*GetIBContainingBlockFor(nsIFrame*aFrame){NS_PRECONDITION(IsFramePartOfIBSplit(aFrame),"GetIBContainingBlockFor() should only be called on known IB frames");// Get the first "normal" ancestor of the target frame.nsIFrame*parentFrame;do{parentFrame=aFrame->GetParent();if(!parentFrame){NS_ERROR("no unsplit block frame in IB hierarchy");returnaFrame;}// Note that we ignore non-ib-split frames which have a pseudo on their// style context -- they're not the frames we're looking for! In// particular, they may be hiding a real parent that _is_ in an ib-split.if(!IsFramePartOfIBSplit(parentFrame)&&!parentFrame->StyleContext()->GetPseudo())break;aFrame=parentFrame;}while(1);// post-conditionsNS_ASSERTION(parentFrame,"no normal ancestor found for ib-split frame ""in GetIBContainingBlockFor");NS_ASSERTION(parentFrame!=aFrame,"parentFrame is actually the child frame - bogus reslt");returnparentFrame;}//----------------------------------------------------------------------// Block/inline frame construction logic. We maintain a few invariants here://// 1. Block frames contain block and inline frames.//// 2. Inline frames only contain inline frames. If an inline parent has a block// child then the block child is migrated upward until it lands in a block// parent (the inline frames containing block is where it will end up).// After this function returns, aLink is pointing to the first link at or// after its starting position for which the next frame is a block. If there// is no such link, it points to the end of the list.staticvoidFindFirstBlock(nsFrameList::FrameLinkEnumerator&aLink){for(;!aLink.AtEnd();aLink.Next()){if(!aLink.NextFrame()->IsInlineOutside()){return;}}}// This function returns a frame link enumerator pointing to the first link in// the list for which the next frame is not block. If there is no such link,// it points to the end of the list.staticnsFrameList::FrameLinkEnumeratorFindFirstNonBlock(constnsFrameList&aList){nsFrameList::FrameLinkEnumeratorlink(aList);for(;!link.AtEnd();link.Next()){if(link.NextFrame()->IsInlineOutside()){break;}}returnlink;}inlinevoidSetInitialSingleChild(nsContainerFrame*aParent,nsIFrame*aFrame){NS_PRECONDITION(!aFrame->GetNextSibling(),"Should be using a frame list");nsFrameListtemp(aFrame,aFrame);aParent->SetInitialChildList(kPrincipalList,temp);}// -----------------------------------------------------------// Structure used when constructing formatting object trees.structnsFrameItems:publicnsFrameList{// Appends the frame to the end of the listvoidAddChild(nsIFrame*aChild);};voidnsFrameItems::AddChild(nsIFrame*aChild){NS_PRECONDITION(aChild,"nsFrameItems::AddChild");// It'd be really nice if we could just AppendFrames(kPrincipalList, aChild) here,// but some of our callers put frames that have different// parents (caption, I'm looking at you) on the same framelist, and// nsFrameList asserts if you try to do that.if(IsEmpty()){SetFrames(aChild);}else{NS_ASSERTION(aChild!=mLastChild,"Same frame being added to frame list twice?");mLastChild->SetNextSibling(aChild);mLastChild=nsLayoutUtils::GetLastSibling(aChild);}}// -----------------------------------------------------------// Structure used when constructing formatting object trees. Contains// state information needed for absolutely positioned elementsstructnsAbsoluteItems:nsFrameItems{// containing block for absolutely positioned elementsnsContainerFrame*containingBlock;explicitnsAbsoluteItems(nsContainerFrame*aContainingBlock);#ifdef DEBUG// XXXbz Does this need a debug-only assignment operator that nulls out the// childList in the nsAbsoluteItems we're copying? Introducing a difference// between debug and non-debug behavior seems bad, so I guess not...~nsAbsoluteItems(){NS_ASSERTION(!FirstChild(),"Dangling child list. Someone forgot to insert it?");}#endif// Appends the frame to the end of the listvoidAddChild(nsIFrame*aChild);};nsAbsoluteItems::nsAbsoluteItems(nsContainerFrame*aContainingBlock):containingBlock(aContainingBlock){}// Additional behavior is that it sets the frame's NS_FRAME_OUT_OF_FLOW flagvoidnsAbsoluteItems::AddChild(nsIFrame*aChild){NS_ASSERTION(aChild->PresContext()->FrameManager()->GetPlaceholderFrameFor(aChild),"Child without placeholder being added to nsAbsoluteItems?");aChild->AddStateBits(NS_FRAME_OUT_OF_FLOW);nsFrameItems::AddChild(aChild);}// -----------------------------------------------------------// Structure for saving the existing state when pushing/poping containing// blocks. The destructor restores the state to its previous stateclassMOZ_STACK_CLASSnsFrameConstructorSaveState{public:typedefnsIFrame::ChildListIDChildListID;nsFrameConstructorSaveState();~nsFrameConstructorSaveState();private:nsAbsoluteItems*mItems;// pointer to struct whose data we save/restorensAbsoluteItemsmSavedItems;// copy of original data// The name of the child list in which our frames would belongChildListIDmChildListID;nsFrameConstructorState*mState;// State used only when we're saving the abs-pos state for a transformed// element.nsAbsoluteItemsmSavedFixedItems;boolmSavedFixedPosIsAbsPos;friendclassnsFrameConstructorState;};// Structure used to keep track of a list of bindings we need to call// AddToAttachedQueue on. These should be in post-order depth-first// flattened tree traversal order.structPendingBinding:publicLinkedListElement<PendingBinding>{#ifdef NS_BUILD_REFCNT_LOGGINGPendingBinding(){MOZ_COUNT_CTOR(PendingBinding);}~PendingBinding(){MOZ_COUNT_DTOR(PendingBinding);}#endifnsRefPtr<nsXBLBinding>mBinding;};// Structure used for maintaining state information during the// frame construction processclassMOZ_STACK_CLASSnsFrameConstructorState{public:typedefnsIFrame::ChildListIDChildListID;nsPresContext*mPresContext;nsIPresShell*mPresShell;nsFrameManager*mFrameManager;#ifdef MOZ_XUL// Frames destined for the kPopupList.nsAbsoluteItemsmPopupItems;#endif// Containing block information for out-of-flow frames.nsAbsoluteItemsmFixedItems;nsAbsoluteItemsmAbsoluteItems;nsAbsoluteItemsmFloatedItems;nsCOMPtr<nsILayoutHistoryState>mFrameState;// These bits will be added to the state bits of any frame we construct// using this state.nsFrameStatemAdditionalStateBits;// When working with the transform and filter properties, we want to hook// the abs-pos and fixed-pos lists together, since such// elements are fixed-pos containing blocks. This flag determines// whether or not we want to wire the fixed-pos and abs-pos lists// together.boolmFixedPosIsAbsPos;// A boolean to indicate whether we have a "pending" popupgroup. That is, we// have already created the FrameConstructionItem for the root popupgroup but// we have not yet created the relevant frame.boolmHavePendingPopupgroup;// If false (which is the default) then call SetPrimaryFrame() as needed// during frame construction. If true, don't make any SetPrimaryFrame()// calls, except for generated content which doesn't have a primary frame// yet. The mCreatingExtraFrames == true mode is meant to be used for// construction of random "extra" frames for elements via normal frame// construction APIs (e.g. replication of things across pages in paginated// mode).boolmCreatingExtraFrames;nsCOMArray<nsIContent>mGeneratedTextNodesWithInitializer;TreeMatchContextmTreeMatchContext;// Constructor// Use the passed-in history state.nsFrameConstructorState(nsIPresShell*aPresShell,nsContainerFrame*aFixedContainingBlock,nsContainerFrame*aAbsoluteContainingBlock,nsContainerFrame*aFloatContainingBlock,nsILayoutHistoryState*aHistoryState);// Get the history state from the pres context's pres shell.nsFrameConstructorState(nsIPresShell*aPresShell,nsContainerFrame*aFixedContainingBlock,nsContainerFrame*aAbsoluteContainingBlock,nsContainerFrame*aFloatContainingBlock);~nsFrameConstructorState();// Function to push the existing absolute containing block state and// create a new scope. Code that uses this function should get matching// logic in GetAbsoluteContainingBlock.// Also makes aNewAbsoluteContainingBlock the containing block for// fixed-pos elements if necessary.// aPositionedFrame is the frame whose style actually makes// aNewAbsoluteContainingBlock a containing block. E.g. for a scrollable element// aPositionedFrame is the element's primary frame and// aNewAbsoluteContainingBlock is the scrolled frame.voidPushAbsoluteContainingBlock(nsContainerFrame*aNewAbsoluteContainingBlock,nsIFrame*aPositionedFrame,nsFrameConstructorSaveState&aSaveState);// Function to push the existing float containing block state and// create a new scope. Code that uses this function should get matching// logic in GetFloatContainingBlock.// Pushing a null float containing block forbids any frames from being// floated until a new float containing block is pushed.// XXX we should get rid of null float containing blocks and teach the// various frame classes to deal with floats instead.voidPushFloatContainingBlock(nsContainerFrame*aNewFloatContainingBlock,nsFrameConstructorSaveState&aSaveState);// Function to return the proper geometric parent for a frame with display// struct given by aStyleDisplay and parent's frame given by// aContentParentFrame.nsContainerFrame*GetGeometricParent(constnsStyleDisplay*aStyleDisplay,nsContainerFrame*aContentParentFrame)const;/** * Function to add a new frame to the right frame list. This MUST be called * on frames before their children have been processed if the frames might * conceivably be out-of-flow; otherwise cleanup in error cases won't work * right. Also, this MUST be called on frames after they have been * initialized. * @param aNewFrame the frame to add * @param aFrameItems the list to add in-flow frames to * @param aContent the content pointer for aNewFrame * @param aStyleContext the style context resolved for aContent * @param aParentFrame the parent frame for the content if it were in-flow * @param aCanBePositioned pass false if the frame isn't allowed to be * positioned * @param aCanBeFloated pass false if the frame isn't allowed to be * floated * @param aIsOutOfFlowPopup pass true if the frame is an out-of-flow popup * (XUL-only) */voidAddChild(nsIFrame*aNewFrame,nsFrameItems&aFrameItems,nsIContent*aContent,nsStyleContext*aStyleContext,nsContainerFrame*aParentFrame,boolaCanBePositioned=true,boolaCanBeFloated=true,boolaIsOutOfFlowPopup=false,boolaInsertAfter=false,nsIFrame*aInsertAfterFrame=nullptr);/** * Function to return the fixed-pos element list. Normally this will just hand back the * fixed-pos element list, but in case we're dealing with a transformed element that's * acting as an abs-pos and fixed-pos container, we'll hand back the abs-pos list. Callers should * use this function if they want to get the list acting as the fixed-pos item parent. */nsAbsoluteItems&GetFixedItems(){returnmFixedPosIsAbsPos?mAbsoluteItems:mFixedItems;}constnsAbsoluteItems&GetFixedItems()const{returnmFixedPosIsAbsPos?mAbsoluteItems:mFixedItems;}/** * class to automatically push and pop a pending binding in the frame * constructor state. See nsCSSFrameConstructor::FrameConstructionItem * mPendingBinding documentation. */classPendingBindingAutoPusher;friendclassPendingBindingAutoPusher;classMOZ_STACK_CLASSPendingBindingAutoPusher{public:PendingBindingAutoPusher(nsFrameConstructorState&aState,PendingBinding*aPendingBinding):mState(aState),mPendingBinding(aState.mCurrentPendingBindingInsertionPoint){if(aPendingBinding){aState.mCurrentPendingBindingInsertionPoint=aPendingBinding;}}~PendingBindingAutoPusher(){mState.mCurrentPendingBindingInsertionPoint=mPendingBinding;}private:nsFrameConstructorState&mState;PendingBinding*mPendingBinding;};/** * Add a new pending binding to the list */voidAddPendingBinding(PendingBinding*aPendingBinding){if(mCurrentPendingBindingInsertionPoint){mCurrentPendingBindingInsertionPoint->setPrevious(aPendingBinding);}else{mPendingBindings.insertBack(aPendingBinding);}}protected:friendclassnsFrameConstructorSaveState;/** * ProcessFrameInsertions takes the frames in aFrameItems and adds them as * kids to the aChildListID child list of |aFrameItems.containingBlock|. */voidProcessFrameInsertions(nsAbsoluteItems&aFrameItems,ChildListIDaChildListID);// Our list of all pending bindings. When we're done, we need to call// AddToAttachedQueue on all of them, in order.LinkedList<PendingBinding>mPendingBindings;PendingBinding*mCurrentPendingBindingInsertionPoint;};nsFrameConstructorState::nsFrameConstructorState(nsIPresShell*aPresShell,nsContainerFrame*aFixedContainingBlock,nsContainerFrame*aAbsoluteContainingBlock,nsContainerFrame*aFloatContainingBlock,nsILayoutHistoryState*aHistoryState):mPresContext(aPresShell->GetPresContext()),mPresShell(aPresShell),mFrameManager(aPresShell->FrameManager()),#ifdef MOZ_XULmPopupItems(nullptr),#endifmFixedItems(aFixedContainingBlock),mAbsoluteItems(aAbsoluteContainingBlock),mFloatedItems(aFloatContainingBlock),// See PushAbsoluteContaningBlock belowmFrameState(aHistoryState),mAdditionalStateBits(nsFrameState(0)),// If the fixed-pos containing block is equal to the abs-pos containing// block, use the abs-pos containing block's abs-pos list for fixed-pos// frames.mFixedPosIsAbsPos(aFixedContainingBlock==aAbsoluteContainingBlock),mHavePendingPopupgroup(false),mCreatingExtraFrames(false),mTreeMatchContext(true,nsRuleWalker::eRelevantLinkUnvisited,aPresShell->GetDocument()),mCurrentPendingBindingInsertionPoint(nullptr){#ifdef MOZ_XULnsIRootBox*rootBox=nsIRootBox::GetRootBox(aPresShell);if(rootBox){mPopupItems.containingBlock=rootBox->GetPopupSetFrame();}#endifMOZ_COUNT_CTOR(nsFrameConstructorState);}nsFrameConstructorState::nsFrameConstructorState(nsIPresShell*aPresShell,nsContainerFrame*aFixedContainingBlock,nsContainerFrame*aAbsoluteContainingBlock,nsContainerFrame*aFloatContainingBlock):mPresContext(aPresShell->GetPresContext()),mPresShell(aPresShell),mFrameManager(aPresShell->FrameManager()),#ifdef MOZ_XULmPopupItems(nullptr),#endifmFixedItems(aFixedContainingBlock),mAbsoluteItems(aAbsoluteContainingBlock),mFloatedItems(aFloatContainingBlock),// See PushAbsoluteContaningBlock belowmAdditionalStateBits(nsFrameState(0)),// If the fixed-pos containing block is equal to the abs-pos containing// block, use the abs-pos containing block's abs-pos list for fixed-pos// frames.mFixedPosIsAbsPos(aFixedContainingBlock==aAbsoluteContainingBlock),mHavePendingPopupgroup(false),mCreatingExtraFrames(false),mTreeMatchContext(true,nsRuleWalker::eRelevantLinkUnvisited,aPresShell->GetDocument()),mCurrentPendingBindingInsertionPoint(nullptr){#ifdef MOZ_XULnsIRootBox*rootBox=nsIRootBox::GetRootBox(aPresShell);if(rootBox){mPopupItems.containingBlock=rootBox->GetPopupSetFrame();}#endifMOZ_COUNT_CTOR(nsFrameConstructorState);mFrameState=aPresShell->GetDocument()->GetLayoutHistoryState();}nsFrameConstructorState::~nsFrameConstructorState(){// Frame order comparison functions only work properly when the placeholders// have been inserted into the frame tree. So for example if we have a new float// containing the placeholder for a new abs-pos frame, and we process the abs-pos// insertion first, then we won't be able to find the right place to insert in// in the abs-pos list. So put floats in first, because they can contain placeholders// for abs-pos and fixed-pos items whose containing blocks are outside the floats.// Then put abs-pos frames in, because they can contain placeholders for fixed-pos// items whose containing block is outside the abs-pos frames.MOZ_COUNT_DTOR(nsFrameConstructorState);ProcessFrameInsertions(mFloatedItems,nsIFrame::kFloatList);ProcessFrameInsertions(mAbsoluteItems,nsIFrame::kAbsoluteList);ProcessFrameInsertions(mFixedItems,nsIFrame::kFixedList);#ifdef MOZ_XULProcessFrameInsertions(mPopupItems,nsIFrame::kPopupList);#endiffor(int32_ti=mGeneratedTextNodesWithInitializer.Count()-1;i>=0;--i){mGeneratedTextNodesWithInitializer[i]->DeleteProperty(nsGkAtoms::genConInitializerProperty);}if(!mPendingBindings.isEmpty()){nsBindingManager*bindingManager=mPresShell->GetDocument()->BindingManager();do{nsAutoPtr<PendingBinding>pendingBinding;pendingBinding=mPendingBindings.popFirst();bindingManager->AddToAttachedQueue(pendingBinding->mBinding);}while(!mPendingBindings.isEmpty());mCurrentPendingBindingInsertionPoint=nullptr;}}staticnsContainerFrame*AdjustAbsoluteContainingBlock(nsContainerFrame*aContainingBlockIn){if(!aContainingBlockIn){returnnullptr;}// Always use the container's first continuation. (Inline frames can have// non-fluid bidi continuations...)returnstatic_cast<nsContainerFrame*>(aContainingBlockIn->FirstContinuation());}voidnsFrameConstructorState::PushAbsoluteContainingBlock(nsContainerFrame*aNewAbsoluteContainingBlock,nsIFrame*aPositionedFrame,nsFrameConstructorSaveState&aSaveState){aSaveState.mItems=&mAbsoluteItems;aSaveState.mSavedItems=mAbsoluteItems;aSaveState.mChildListID=nsIFrame::kAbsoluteList;aSaveState.mState=this;aSaveState.mSavedFixedPosIsAbsPos=mFixedPosIsAbsPos;if(mFixedPosIsAbsPos){// Since we're going to replace mAbsoluteItems, we need to save it into// mFixedItems now (and save the current value of mFixedItems).aSaveState.mSavedFixedItems=mFixedItems;mFixedItems=mAbsoluteItems;}mAbsoluteItems=nsAbsoluteItems(AdjustAbsoluteContainingBlock(aNewAbsoluteContainingBlock));/* See if we're wiring the fixed-pos and abs-pos lists together. This happens iff * we're a transformed element. */mFixedPosIsAbsPos=aPositionedFrame&&aPositionedFrame->StyleDisplay()->IsFixedPosContainingBlock(aPositionedFrame);if(aNewAbsoluteContainingBlock){aNewAbsoluteContainingBlock->MarkAsAbsoluteContainingBlock();}}voidnsFrameConstructorState::PushFloatContainingBlock(nsContainerFrame*aNewFloatContainingBlock,nsFrameConstructorSaveState&aSaveState){NS_PRECONDITION(!aNewFloatContainingBlock||aNewFloatContainingBlock->IsFloatContainingBlock(),"Please push a real float containing block!");NS_ASSERTION(!aNewFloatContainingBlock||!ShouldSuppressFloatingOfDescendants(aNewFloatContainingBlock),"We should not push a frame that is supposed to _suppress_ ""floats as a float containing block!");aSaveState.mItems=&mFloatedItems;aSaveState.mSavedItems=mFloatedItems;aSaveState.mChildListID=nsIFrame::kFloatList;aSaveState.mState=this;mFloatedItems=nsAbsoluteItems(aNewFloatContainingBlock);}nsContainerFrame*nsFrameConstructorState::GetGeometricParent(constnsStyleDisplay*aStyleDisplay,nsContainerFrame*aContentParentFrame)const{NS_PRECONDITION(aStyleDisplay,"Must have display struct!");// If there is no container for a fixed, absolute, or floating root// frame, we will ignore the positioning. This hack is originally// brought to you by the letter T: tables, since other roots don't// even call into this code. See bug 178855.//// XXX Disabling positioning in this case is a hack. If one was so inclined,// one could support this either by (1) inserting a dummy block between the// table and the canvas or (2) teaching the canvas how to reflow positioned// elements. (1) has the usual problems when multiple frames share the same// content (notice all the special cases in this file dealing with inner// tables and outer tables which share the same content). (2) requires some// work and possible factoring.//// XXXbz couldn't we just force position to "static" on roots and// float to "none"? That's OK per CSS 2.1, as far as I can tell.if(aContentParentFrame&&aContentParentFrame->IsSVGText()){returnaContentParentFrame;}if(aStyleDisplay->IsFloatingStyle()&&mFloatedItems.containingBlock){NS_ASSERTION(!aStyleDisplay->IsAbsolutelyPositionedStyle(),"Absolutely positioned _and_ floating?");returnmFloatedItems.containingBlock;}if(aStyleDisplay->mPosition==NS_STYLE_POSITION_ABSOLUTE&&mAbsoluteItems.containingBlock){returnmAbsoluteItems.containingBlock;}if(aStyleDisplay->mPosition==NS_STYLE_POSITION_FIXED&&GetFixedItems().containingBlock){returnGetFixedItems().containingBlock;}returnaContentParentFrame;}voidnsFrameConstructorState::AddChild(nsIFrame*aNewFrame,nsFrameItems&aFrameItems,nsIContent*aContent,nsStyleContext*aStyleContext,nsContainerFrame*aParentFrame,boolaCanBePositioned,boolaCanBeFloated,boolaIsOutOfFlowPopup,boolaInsertAfter,nsIFrame*aInsertAfterFrame){NS_PRECONDITION(!aNewFrame->GetNextSibling(),"Shouldn't happen");constnsStyleDisplay*disp=aNewFrame->StyleDisplay();// The comments in GetGeometricParent regarding root table frames// all apply here, unfortunately.boolneedPlaceholder=false;nsFrameStateplaceholderType;nsFrameItems*frameItems=&aFrameItems;#ifdef MOZ_XULif(MOZ_UNLIKELY(aIsOutOfFlowPopup)){NS_ASSERTION(aNewFrame->GetParent()==mPopupItems.containingBlock,"Popup whose parent is not the popup containing block?");NS_ASSERTION(mPopupItems.containingBlock,"Must have a popup set frame!");needPlaceholder=true;frameItems=&mPopupItems;placeholderType=PLACEHOLDER_FOR_POPUP;}else#endif // MOZ_XULif(aCanBeFloated&&aNewFrame->IsFloating()&&mFloatedItems.containingBlock){NS_ASSERTION(aNewFrame->GetParent()==mFloatedItems.containingBlock,"Float whose parent is not the float containing block?");needPlaceholder=true;frameItems=&mFloatedItems;placeholderType=PLACEHOLDER_FOR_FLOAT;}elseif(aCanBePositioned){if(disp->mPosition==NS_STYLE_POSITION_ABSOLUTE&&mAbsoluteItems.containingBlock){NS_ASSERTION(aNewFrame->GetParent()==mAbsoluteItems.containingBlock,"Abs pos whose parent is not the abs pos containing block?");needPlaceholder=true;frameItems=&mAbsoluteItems;placeholderType=PLACEHOLDER_FOR_ABSPOS;}if(disp->mPosition==NS_STYLE_POSITION_FIXED&&GetFixedItems().containingBlock){NS_ASSERTION(aNewFrame->GetParent()==GetFixedItems().containingBlock,"Fixed pos whose parent is not the fixed pos containing block?");needPlaceholder=true;frameItems=&GetFixedItems();placeholderType=PLACEHOLDER_FOR_FIXEDPOS;}}if(needPlaceholder){NS_ASSERTION(frameItems!=&aFrameItems,"Putting frame in-flow _and_ want a placeholder?");nsIFrame*placeholderFrame=nsCSSFrameConstructor::CreatePlaceholderFrameFor(mPresShell,aContent,aNewFrame,aStyleContext,aParentFrame,nullptr,placeholderType);placeholderFrame->AddStateBits(mAdditionalStateBits);// Add the placeholder frame to the flowaFrameItems.AddChild(placeholderFrame);}#ifdef DEBUGelse{NS_ASSERTION(aNewFrame->GetParent()==aParentFrame,"In-flow frame has wrong parent");}#endifif(aInsertAfter){frameItems->InsertFrame(nullptr,aInsertAfterFrame,aNewFrame);}else{frameItems->AddChild(aNewFrame);}}voidnsFrameConstructorState::ProcessFrameInsertions(nsAbsoluteItems&aFrameItems,ChildListIDaChildListID){#define NS_NONXUL_LIST_TEST (&aFrameItems == &mFloatedItems && \ aChildListID == nsIFrame::kFloatList) || \ (&aFrameItems == &mAbsoluteItems && \ aChildListID == nsIFrame::kAbsoluteList) || \ (&aFrameItems == &mFixedItems && \ aChildListID == nsIFrame::kFixedList)#ifdef MOZ_XULNS_PRECONDITION(NS_NONXUL_LIST_TEST||(&aFrameItems==&mPopupItems&&aChildListID==nsIFrame::kPopupList),"Unexpected aFrameItems/aChildListID combination");#elseNS_PRECONDITION(NS_NONXUL_LIST_TEST,"Unexpected aFrameItems/aChildListID combination");#endifif(aFrameItems.IsEmpty()){return;}nsContainerFrame*containingBlock=aFrameItems.containingBlock;NS_ASSERTION(containingBlock,"Child list without containing block?");if(aChildListID==nsIFrame::kFixedList){// Put this frame on the transformed-frame's abs-pos list instead, if// it has abs-pos children instead of fixed-pos children.aChildListID=containingBlock->GetAbsoluteListID();}// Insert the frames hanging out in aItems. We can use SetInitialChildList()// if the containing block hasn't been reflowed yet (so NS_FRAME_FIRST_REFLOW// is set) and doesn't have any frames in the aChildListID child list yet.constnsFrameList&childList=containingBlock->GetChildList(aChildListID);if(childList.IsEmpty()&&(containingBlock->GetStateBits()&NS_FRAME_FIRST_REFLOW)){// If we're injecting absolutely positioned frames, inject them on the// absolute containing blockif(aChildListID==containingBlock->GetAbsoluteListID()){containingBlock->GetAbsoluteContainingBlock()->SetInitialChildList(containingBlock,aChildListID,aFrameItems);}else{containingBlock->SetInitialChildList(aChildListID,aFrameItems);}}else{// Note that whether the frame construction context is doing an append or// not is not helpful here, since it could be appending to some frame in// the middle of the document, which means we're not necessarily// appending to the children of the containing block.//// We need to make sure the 'append to the end of document' case is fast.// So first test the last child of the containing blocknsIFrame*lastChild=childList.LastChild();// CompareTreePosition uses placeholder hierarchy for out of flow frames,// so this will make out-of-flows respect the ordering of placeholders,// which is great because it takes care of anonymous content.nsIFrame*firstNewFrame=aFrameItems.FirstChild();// Cache the ancestor chain so that we can reuse it if needed.nsAutoTArray<nsIFrame*,20>firstNewFrameAncestors;nsIFrame*notCommonAncestor=nullptr;if(lastChild){notCommonAncestor=nsLayoutUtils::FillAncestors(firstNewFrame,containingBlock,&firstNewFrameAncestors);}if(!lastChild||nsLayoutUtils::CompareTreePosition(lastChild,firstNewFrame,firstNewFrameAncestors,notCommonAncestor?containingBlock:nullptr)<0){// no lastChild, or lastChild comes before the new children, so just appendmFrameManager->AppendFrames(containingBlock,aChildListID,aFrameItems);}else{// Try the other children. First collect them to an array so that a// reasonable fast binary search can be used to find the insertion point.nsAutoTArray<nsIFrame*,128>children;for(nsIFrame*f=childList.FirstChild();f!=lastChild;f=f->GetNextSibling()){children.AppendElement(f);}nsIFrame*insertionPoint=nullptr;int32_timin=0;int32_tmax=children.Length();while(max>imin){int32_timid=imin+((max-imin)/2);nsIFrame*f=children[imid];int32_tcompare=nsLayoutUtils::CompareTreePosition(f,firstNewFrame,firstNewFrameAncestors,notCommonAncestor?containingBlock:nullptr);if(compare>0){// f is after the new frame.max=imid;insertionPoint=imid>0?children[imid-1]:nullptr;}elseif(compare<0){// f is before the new frame.imin=imid+1;insertionPoint=f;}else{// This is for the old behavior. Should be removed once it is// guaranteed that CompareTreePosition can't return 0!// See bug 928645.NS_WARNING("Something odd happening???");insertionPoint=nullptr;for(uint32_ti=0;i<children.Length();++i){nsIFrame*f=children[i];if(nsLayoutUtils::CompareTreePosition(f,firstNewFrame,firstNewFrameAncestors,notCommonAncestor?containingBlock:nullptr)>0){break;}insertionPoint=f;}break;}}mFrameManager->InsertFrames(containingBlock,aChildListID,insertionPoint,aFrameItems);}}NS_POSTCONDITION(aFrameItems.IsEmpty(),"How did that happen?");}nsFrameConstructorSaveState::nsFrameConstructorSaveState():mItems(nullptr),mSavedItems(nullptr),mChildListID(kPrincipalList),mState(nullptr),mSavedFixedItems(nullptr),mSavedFixedPosIsAbsPos(false){}nsFrameConstructorSaveState::~nsFrameConstructorSaveState(){// Restore the stateif(mItems){NS_ASSERTION(mState,"Can't have mItems set without having a state!");mState->ProcessFrameInsertions(*mItems,mChildListID);*mItems=mSavedItems;#ifdef DEBUG// We've transferred the child list, so drop the pointer we held to it.// Note that this only matters for the assert in ~nsAbsoluteItems.mSavedItems.Clear();#endifif(mItems==&mState->mAbsoluteItems){mState->mFixedPosIsAbsPos=mSavedFixedPosIsAbsPos;if(mSavedFixedPosIsAbsPos){// mAbsoluteItems was moved to mFixedItems, so move mFixedItems back// and repair the old mFixedItems now.mState->mAbsoluteItems=mState->mFixedItems;mState->mFixedItems=mSavedFixedItems;#ifdef DEBUGmSavedFixedItems.Clear();#endif}}NS_ASSERTION(!mItems->LastChild()||!mItems->LastChild()->GetNextSibling(),"Something corrupted our list");}}staticboolIsBorderCollapse(nsIFrame*aFrame){for(nsIFrame*frame=aFrame;frame;frame=frame->GetParent()){if(nsGkAtoms::tableFrame==frame->GetType()){return((nsTableFrame*)frame)->IsBorderCollapse();}}NS_ASSERTION(false,"program error");returnfalse;}/** * Moves aFrameList from aOldParent to aNewParent. This updates the parent * pointer of the frames in the list, and reparents their views as needed. * nsFrame::SetParent sets the NS_FRAME_HAS_VIEW bit on aNewParent and its * ancestors as needed. Then it sets the list as the initial child list * on aNewParent, unless aNewParent either already has kids or has been * reflowed; in that case it appends the new frames. Note that this * method differs from ReparentFrames in that it doesn't change the kids' * style contexts. */// XXXbz Since this is only used for {ib} splits, could we just copy the view// bits from aOldParent to aNewParent and then use the// nsFrameList::ApplySetParent? That would still leave us doing two passes// over the list, of course; if we really wanted to we could factor out the// relevant part of ReparentFrameViewList, I suppose... Or just get rid of// views, which would make most of this function go away.staticvoidMoveChildrenTo(nsPresContext*aPresContext,nsIFrame*aOldParent,nsContainerFrame*aNewParent,nsFrameList&aFrameList){boolsameGrandParent=aOldParent->GetParent()==aNewParent->GetParent();if(aNewParent->HasView()||aOldParent->HasView()||!sameGrandParent){// Move the frames into the new viewnsContainerFrame::ReparentFrameViewList(aFrameList,aOldParent,aNewParent);}for(nsFrameList::Enumeratore(aFrameList);!e.AtEnd();e.Next()){e.get()->SetParent(aNewParent);}if(aNewParent->PrincipalChildList().IsEmpty()&&(aNewParent->GetStateBits()&NS_FRAME_FIRST_REFLOW)){aNewParent->SetInitialChildList(kPrincipalList,aFrameList);}else{aNewParent->AppendFrames(kPrincipalList,aFrameList);}}//----------------------------------------------------------------------nsCSSFrameConstructor::nsCSSFrameConstructor(nsIDocument*aDocument,nsIPresShell*aPresShell,nsStyleSet*aStyleSet):nsFrameManager(aPresShell,aStyleSet),mDocument(aDocument),mRootElementFrame(nullptr),mRootElementStyleFrame(nullptr),mDocElementContainingBlock(nullptr),mGfxScrollFrame(nullptr),mPageSequenceFrame(nullptr),mCurrentDepth(0),mUpdateCount(0),mQuotesDirty(false),mCountersDirty(false),mIsDestroyingFrameTree(false),mHasRootAbsPosContainingBlock(false),mAlwaysCreateFramesForIgnorableWhitespace(false){#ifdef DEBUGstaticboolgFirstTime=true;if(gFirstTime){gFirstTime=false;char*flags=PR_GetEnv("GECKO_FRAMECTOR_DEBUG_FLAGS");if(flags){boolerror=false;for(;;){char*comma=PL_strchr(flags,',');if(comma)*comma='\0';boolfound=false;FrameCtorDebugFlags*flag=gFlags;FrameCtorDebugFlags*limit=gFlags+NUM_DEBUG_FLAGS;while(flag<limit){if(PL_strcasecmp(flag->name,flags)==0){*(flag->on)=true;printf("nsCSSFrameConstructor: setting %s debug flag on\n",flag->name);found=true;break;}++flag;}if(!found)error=true;if(!comma)break;*comma=',';flags=comma+1;}if(error){printf("Here are the available GECKO_FRAMECTOR_DEBUG_FLAGS:\n");FrameCtorDebugFlags*flag=gFlags;FrameCtorDebugFlags*limit=gFlags+NUM_DEBUG_FLAGS;while(flag<limit){printf(" %s\n",flag->name);++flag;}printf("Note: GECKO_FRAMECTOR_DEBUG_FLAGS is a comma separated list of flag\n");printf("names (no whitespace)\n");}}}#endif}voidnsCSSFrameConstructor::NotifyDestroyingFrame(nsIFrame*aFrame){NS_PRECONDITION(mUpdateCount!=0,"Should be in an update while destroying frames");if(aFrame->GetStateBits()&NS_FRAME_GENERATED_CONTENT){if(mQuoteList.DestroyNodesFor(aFrame))QuotesDirty();}if(mCounterManager.DestroyNodesFor(aFrame)){// Technically we don't need to update anything if we destroyed only// USE nodes. However, this is unlikely to happen in the real world// since USE nodes generally go along with INCREMENT nodes.CountersDirty();}RestyleManager()->NotifyDestroyingFrame(aFrame);nsFrameManager::NotifyDestroyingFrame(aFrame);}structnsGenConInitializer{nsAutoPtr<nsGenConNode>mNode;nsGenConList*mList;void(nsCSSFrameConstructor::*mDirtyAll)();nsGenConInitializer(nsGenConNode*aNode,nsGenConList*aList,void(nsCSSFrameConstructor::*aDirtyAll)()):mNode(aNode),mList(aList),mDirtyAll(aDirtyAll){}};already_AddRefed<nsIContent>nsCSSFrameConstructor::CreateGenConTextNode(nsFrameConstructorState&aState,constnsString&aString,nsRefPtr<nsTextNode>*aText,nsGenConInitializer*aInitializer){nsRefPtr<nsTextNode>content=newnsTextNode(mDocument->NodeInfoManager());content->SetText(aString,false);if(aText){*aText=content;}if(aInitializer){content->SetProperty(nsGkAtoms::genConInitializerProperty,aInitializer,nsINode::DeleteProperty<nsGenConInitializer>);aState.mGeneratedTextNodesWithInitializer.AppendObject(content);}returncontent.forget();}already_AddRefed<nsIContent>nsCSSFrameConstructor::CreateGeneratedContent(nsFrameConstructorState&aState,nsIContent*aParentContent,nsStyleContext*aStyleContext,uint32_taContentIndex){// Get the content valueconstnsStyleContentData&data=aStyleContext->StyleContent()->ContentAt(aContentIndex);nsStyleContentTypetype=data.mType;if(eStyleContentType_Image==type){if(!data.mContent.mImage){// CSS had something specified that couldn't be converted to an// image objectreturnnullptr;}// Create an image content object and pass it the image request.// XXX Check if it's an image type we can handle...nsRefPtr<NodeInfo>nodeInfo;nodeInfo=mDocument->NodeInfoManager()->GetNodeInfo(nsGkAtoms::mozgeneratedcontentimage,nullptr,kNameSpaceID_XHTML,nsIDOMNode::ELEMENT_NODE);nsCOMPtr<nsIContent>content;NS_NewGenConImageContent(getter_AddRefs(content),nodeInfo.forget(),data.mContent.mImage);returncontent.forget();}switch(type){caseeStyleContentType_String:returnCreateGenConTextNode(aState,nsDependentString(data.mContent.mString),nullptr,nullptr);caseeStyleContentType_Attr:{nsCOMPtr<nsIAtom>attrName;int32_tattrNameSpace=kNameSpaceID_None;nsAutoStringcontentString(data.mContent.mString);int32_tbarIndex=contentString.FindChar('|');// CSS namespace delimiterif(-1!=barIndex){nsAutoStringnameSpaceVal;contentString.Left(nameSpaceVal,barIndex);nsresulterror;attrNameSpace=nameSpaceVal.ToInteger(&error);contentString.Cut(0,barIndex+1);if(contentString.Length()){if(mDocument->IsHTMLDocument()&&aParentContent->IsHTMLElement()){ToLowerCase(contentString);}attrName=do_GetAtom(contentString);}}else{if(mDocument->IsHTMLDocument()&&aParentContent->IsHTMLElement()){ToLowerCase(contentString);}attrName=do_GetAtom(contentString);}if(!attrName){returnnullptr;}nsCOMPtr<nsIContent>content;NS_NewAttributeContent(mDocument->NodeInfoManager(),attrNameSpace,attrName,getter_AddRefs(content));returncontent.forget();}caseeStyleContentType_Counter:caseeStyleContentType_Counters:{nsCSSValue::Array*counters=data.mContent.mCounters;nsCounterList*counterList=mCounterManager.CounterListFor(nsDependentString(counters->Item(0).GetStringBufferValue()));nsCounterUseNode*node=newnsCounterUseNode(mPresShell->GetPresContext(),counters,aContentIndex,type==eStyleContentType_Counters);nsGenConInitializer*initializer=newnsGenConInitializer(node,counterList,&nsCSSFrameConstructor::CountersDirty);returnCreateGenConTextNode(aState,EmptyString(),&node->mText,initializer);}caseeStyleContentType_Image:NS_NOTREACHED("handled by if above");returnnullptr;caseeStyleContentType_OpenQuote:caseeStyleContentType_CloseQuote:caseeStyleContentType_NoOpenQuote:caseeStyleContentType_NoCloseQuote:{nsQuoteNode*node=newnsQuoteNode(type,aContentIndex);nsGenConInitializer*initializer=newnsGenConInitializer(node,&mQuoteList,&nsCSSFrameConstructor::QuotesDirty);returnCreateGenConTextNode(aState,EmptyString(),&node->mText,initializer);}caseeStyleContentType_AltContent:{// Use the "alt" attribute; if that fails and the node is an HTML// <input>, try the value attribute and then fall back to some default// localized text we have.// XXX what if the 'alt' attribute is added later, how will we// detect that and do the right thing here?if(aParentContent->HasAttr(kNameSpaceID_None,nsGkAtoms::alt)){nsCOMPtr<nsIContent>content;NS_NewAttributeContent(mDocument->NodeInfoManager(),kNameSpaceID_None,nsGkAtoms::alt,getter_AddRefs(content));returncontent.forget();}if(aParentContent->IsHTMLElement()&&aParentContent->NodeInfo()->Equals(nsGkAtoms::input)){if(aParentContent->HasAttr(kNameSpaceID_None,nsGkAtoms::value)){nsCOMPtr<nsIContent>content;NS_NewAttributeContent(mDocument->NodeInfoManager(),kNameSpaceID_None,nsGkAtoms::value,getter_AddRefs(content));returncontent.forget();}nsXPIDLStringtemp;nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,"Submit",temp);returnCreateGenConTextNode(aState,temp,nullptr,nullptr);}break;}caseeStyleContentType_Uninitialized:NS_NOTREACHED("uninitialized content type");returnnullptr;}// switchreturnnullptr;}/* * aParentFrame - the frame that should be the parent of the generated * content. This is the frame for the corresponding content node, * which must not be a leaf frame. * * Any items created are added to aItems. * * We create an XML element (tag _moz_generated_content_before or * _moz_generated_content_after) representing the pseudoelement. We * create a DOM node for each 'content' item and make those nodes the * children of the XML element. Then we create a frame subtree for * the XML element as if it were a regular child of * aParentFrame/aParentContent, giving the XML element the ::before or * ::after style. */voidnsCSSFrameConstructor::CreateGeneratedContentItem(nsFrameConstructorState&aState,nsContainerFrame*aParentFrame,nsIContent*aParentContent,nsStyleContext*aStyleContext,nsCSSPseudoElements::TypeaPseudoElement,FrameConstructionItemList&aItems){MOZ_ASSERT(aPseudoElement==nsCSSPseudoElements::ePseudo_before||aPseudoElement==nsCSSPseudoElements::ePseudo_after,"unexpected aPseudoElement");// XXXbz is this ever true?if(!aParentContent->IsElement()){NS_ERROR("Bogus generated content parent");return;}nsStyleSet*styleSet=mPresShell->StyleSet();// Probe for the existence of the pseudo-elementnsRefPtr<nsStyleContext>pseudoStyleContext;pseudoStyleContext=styleSet->ProbePseudoElementStyle(aParentContent->AsElement(),aPseudoElement,aStyleContext,aState.mTreeMatchContext);if(!pseudoStyleContext)return;boolisBefore=aPseudoElement==nsCSSPseudoElements::ePseudo_before;// |ProbePseudoStyleFor| checked the 'display' property and the// |ContentCount()| of the 'content' property for us.nsRefPtr<NodeInfo>nodeInfo;nsIAtom*elemName=isBefore?nsGkAtoms::mozgeneratedcontentbefore:nsGkAtoms::mozgeneratedcontentafter;nodeInfo=mDocument->NodeInfoManager()->GetNodeInfo(elemName,nullptr,kNameSpaceID_None,nsIDOMNode::ELEMENT_NODE);nsCOMPtr<Element>container;nsresultrv=NS_NewXMLElement(getter_AddRefs(container),nodeInfo.forget());if(NS_FAILED(rv))return;container->SetIsNativeAnonymousRoot();// If the parent is in a shadow tree, make sure we don't// bind with a document because shadow roots and its descendants// are not in document.nsIDocument*bindDocument=aParentContent->HasFlag(NODE_IS_IN_SHADOW_TREE)?nullptr:mDocument;rv=container->BindToTree(bindDocument,aParentContent,aParentContent,true);if(NS_FAILED(rv)){container->UnbindFromTree();return;}RestyleManager::ReframingStyleContexts*rsc=RestyleManager()->GetReframingStyleContexts();if(rsc){nsStyleContext*oldStyleContext=rsc->Get(container,aPseudoElement);if(oldStyleContext){RestyleManager::TryStartingTransition(aState.mPresContext,container,oldStyleContext,&pseudoStyleContext);}else{aState.mPresContext->TransitionManager()->PruneCompletedTransitions(container,aPseudoElement,pseudoStyleContext);}}uint32_tcontentCount=pseudoStyleContext->StyleContent()->ContentCount();for(uint32_tcontentIndex=0;contentIndex<contentCount;contentIndex++){nsCOMPtr<nsIContent>content=CreateGeneratedContent(aState,aParentContent,pseudoStyleContext,contentIndex);if(content){container->AppendChildTo(content,false);}}AddFrameConstructionItemsInternal(aState,container,aParentFrame,elemName,kNameSpaceID_None,true,pseudoStyleContext,ITEM_IS_GENERATED_CONTENT,nullptr,aItems);}/**************************************************** ** BEGIN TABLE SECTION ****************************************************/// The term pseudo frame is being used instead of anonymous frame, since anonymous// frame has been used elsewhere to refer to frames that have generated content// Return whether the given frame is a table pseudo-frame. Note that// cell-content and table-outer frames have pseudo-types, but are always// created, even for non-anonymous cells and tables respectively. So for those// we have to examine the cell or table frame to see whether it's a pseudo// frame. In particular, a lone table caption will have an outer table as its// parent, but will also trigger construction of an empty inner table, which// will be the one we can examine to see whether the outer was a pseudo-frame.staticboolIsTablePseudo(nsIFrame*aFrame){nsIAtom*pseudoType=aFrame->StyleContext()->GetPseudo();returnpseudoType&&(pseudoType==nsCSSAnonBoxes::table||pseudoType==nsCSSAnonBoxes::inlineTable||pseudoType==nsCSSAnonBoxes::tableColGroup||pseudoType==nsCSSAnonBoxes::tableRowGroup||pseudoType==nsCSSAnonBoxes::tableRow||pseudoType==nsCSSAnonBoxes::tableCell||(pseudoType==nsCSSAnonBoxes::cellContent&&aFrame->GetParent()->StyleContext()->GetPseudo()==nsCSSAnonBoxes::tableCell)||(pseudoType==nsCSSAnonBoxes::tableOuter&&(aFrame->GetFirstPrincipalChild()->StyleContext()->GetPseudo()==nsCSSAnonBoxes::table||aFrame->GetFirstPrincipalChild()->StyleContext()->GetPseudo()==nsCSSAnonBoxes::inlineTable)));}staticboolIsRubyPseudo(nsIFrame*aFrame){nsIAtom*pseudoType=aFrame->StyleContext()->GetPseudo();returnpseudoType&&(pseudoType==nsCSSAnonBoxes::ruby||pseudoType==nsCSSAnonBoxes::rubyBase||pseudoType==nsCSSAnonBoxes::rubyText||pseudoType==nsCSSAnonBoxes::rubyBaseContainer||pseudoType==nsCSSAnonBoxes::rubyTextContainer);}staticboolIsTableOrRubyPseudo(nsIFrame*aFrame){returnIsTablePseudo(aFrame)||IsRubyPseudo(aFrame);}/* static */nsCSSFrameConstructor::ParentTypensCSSFrameConstructor::GetParentType(nsIAtom*aFrameType){if(aFrameType==nsGkAtoms::tableFrame){returneTypeTable;}if(aFrameType==nsGkAtoms::tableRowGroupFrame){returneTypeRowGroup;}if(aFrameType==nsGkAtoms::tableRowFrame){returneTypeRow;}if(aFrameType==nsGkAtoms::tableColGroupFrame){returneTypeColGroup;}if(aFrameType==nsGkAtoms::rubyBaseContainerFrame){returneTypeRubyBaseContainer;}if(aFrameType==nsGkAtoms::rubyTextContainerFrame){returneTypeRubyTextContainer;}if(aFrameType==nsGkAtoms::rubyFrame){returneTypeRuby;}returneTypeBlock;}staticnsContainerFrame*AdjustCaptionParentFrame(nsContainerFrame*aParentFrame){if(nsGkAtoms::tableFrame==aParentFrame->GetType()){returnaParentFrame->GetParent();}returnaParentFrame;}/** * If the parent frame is a |tableFrame| and the child is a * |captionFrame|, then we want to insert the frames beneath the * |tableFrame|'s parent frame. Returns |true| if the parent frame * needed to be fixed up. */staticboolGetCaptionAdjustedParent(nsContainerFrame*aParentFrame,constnsIFrame*aChildFrame,nsContainerFrame**aAdjParentFrame){*aAdjParentFrame=aParentFrame;boolhaveCaption=false;if(aChildFrame->IsTableCaption()){haveCaption=true;*aAdjParentFrame=::AdjustCaptionParentFrame(aParentFrame);}returnhaveCaption;}voidnsCSSFrameConstructor::AdjustParentFrame(nsContainerFrame**aParentFrame,constFrameConstructionData*aFCData,nsStyleContext*aStyleContext){NS_PRECONDITION(aStyleContext,"Must have child's style context");NS_PRECONDITION(aFCData,"Must have frame construction data");booltablePart=((aFCData->mBits&FCDATA_IS_TABLE_PART)!=0);if(tablePart&&aStyleContext->StyleDisplay()->mDisplay==NS_STYLE_DISPLAY_TABLE_CAPTION){*aParentFrame=::AdjustCaptionParentFrame(*aParentFrame);}}// Pull all the captions present in aItems out into aCaptionsstaticvoidPullOutCaptionFrames(nsFrameItems&aItems,nsFrameItems&aCaptions){nsIFrame*child=aItems.FirstChild();while(child){nsIFrame*nextSibling=child->GetNextSibling();if(child->IsTableCaption()){aItems.RemoveFrame(child);aCaptions.AddChild(child);}child=nextSibling;}}// Construct the outer, inner table frames and the children frames for the table.// XXX Page break frames for pseudo table frames are not constructed to avoid the risk// associated with revising the pseudo frame mechanism. The long term solution// of having frames handle page-break-before/after will solve the problem.nsIFrame*nsCSSFrameConstructor::ConstructTable(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){NS_PRECONDITION(aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE||aDisplay->mDisplay==NS_STYLE_DISPLAY_INLINE_TABLE,"Unexpected call");nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;constuint32_tnameSpaceID=aItem.mNameSpaceID;// create the pseudo SC for the outer table as a child of the inner SCnsRefPtr<nsStyleContext>outerStyleContext;outerStyleContext=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::tableOuter,styleContext);// Create the outer table frame which holds the caption and inner table framensContainerFrame*newFrame;if(kNameSpaceID_MathML==nameSpaceID)newFrame=NS_NewMathMLmtableOuterFrame(mPresShell,outerStyleContext);elsenewFrame=NS_NewTableOuterFrame(mPresShell,outerStyleContext);nsContainerFrame*geometricParent=aState.GetGeometricParent(outerStyleContext->StyleDisplay(),aParentFrame);// Init the table outer frameInitAndRestoreFrame(aState,content,geometricParent,newFrame);// Create the inner table framensContainerFrame*innerFrame;if(kNameSpaceID_MathML==nameSpaceID)innerFrame=NS_NewMathMLmtableFrame(mPresShell,styleContext);elseinnerFrame=NS_NewTableFrame(mPresShell,styleContext);InitAndRestoreFrame(aState,content,newFrame,innerFrame);// Put the newly created frames into the right child listSetInitialSingleChild(newFrame,innerFrame);aState.AddChild(newFrame,aFrameItems,content,styleContext,aParentFrame);if(!mRootElementFrame){// The frame we're constructing will be the root element frame.// Set mRootElementFrame before processing children.mRootElementFrame=newFrame;}nsFrameItemschildItems;// Process childrennsFrameConstructorSaveStateabsoluteSaveState;constnsStyleDisplay*display=outerStyleContext->StyleDisplay();// Mark the table frame as an absolute container if needednewFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);if(display->IsAbsPosContainingBlock(newFrame)){aState.PushAbsoluteContainingBlock(newFrame,newFrame,absoluteSaveState);}NS_ASSERTION(aItem.mAnonChildren.IsEmpty(),"nsIAnonymousContentCreator::CreateAnonymousContent ""implementations for table frames are not currently expected ""to output a list where the items have their own children");if(aItem.mFCData->mBits&FCDATA_USE_CHILD_ITEMS){ConstructFramesFromItemList(aState,aItem.mChildItems,innerFrame,childItems);}else{ProcessChildren(aState,content,styleContext,innerFrame,true,childItems,false,aItem.mPendingBinding);}nsFrameItemscaptionItems;PullOutCaptionFrames(childItems,captionItems);// Set the inner table frame's initial primary listinnerFrame->SetInitialChildList(kPrincipalList,childItems);// Set the outer table frame's secondary childlist listsif(captionItems.NotEmpty()){newFrame->SetInitialChildList(nsIFrame::kCaptionList,captionItems);}returnnewFrame;}staticvoidMakeTablePartAbsoluteContainingBlockIfNeeded(nsFrameConstructorState&aState,constnsStyleDisplay*aDisplay,nsFrameConstructorSaveState&aAbsSaveState,nsContainerFrame*aFrame){// If we're positioned, then we need to become an absolute containing block// for any absolutely positioned children and register for post-reflow fixup.//// Note that usually if a frame type can be an absolute containing block, we// always set NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN, whether it actually is or not.// However, in this case flag serves the additional purpose of indicating that// the frame was registered with its table frame. This allows us to avoid the// overhead of unregistering the frame in most cases.if(aDisplay->IsAbsPosContainingBlock(aFrame)){aFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);aState.PushAbsoluteContainingBlock(aFrame,aFrame,aAbsSaveState);nsTableFrame::RegisterPositionedTablePart(aFrame);}}nsIFrame*nsCSSFrameConstructor::ConstructTableRowOrRowGroup(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){NS_PRECONDITION(aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_ROW||aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_ROW_GROUP||aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP||aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_HEADER_GROUP,"Unexpected call");MOZ_ASSERT(aItem.mStyleContext->StyleDisplay()==aDisplay,"Display style doesn't match style context");nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;constuint32_tnameSpaceID=aItem.mNameSpaceID;nsContainerFrame*newFrame;if(aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_ROW){if(kNameSpaceID_MathML==nameSpaceID)newFrame=NS_NewMathMLmtrFrame(mPresShell,styleContext);elsenewFrame=NS_NewTableRowFrame(mPresShell,styleContext);}else{newFrame=NS_NewTableRowGroupFrame(mPresShell,styleContext);}InitAndRestoreFrame(aState,content,aParentFrame,newFrame);nsFrameConstructorSaveStateabsoluteSaveState;MakeTablePartAbsoluteContainingBlockIfNeeded(aState,aDisplay,absoluteSaveState,newFrame);nsFrameItemschildItems;NS_ASSERTION(aItem.mAnonChildren.IsEmpty(),"nsIAnonymousContentCreator::CreateAnonymousContent ""implementations for table frames are not currently expected ""to output a list where the items have their own children");if(aItem.mFCData->mBits&FCDATA_USE_CHILD_ITEMS){ConstructFramesFromItemList(aState,aItem.mChildItems,newFrame,childItems);}else{ProcessChildren(aState,content,styleContext,newFrame,true,childItems,false,aItem.mPendingBinding);}newFrame->SetInitialChildList(kPrincipalList,childItems);aFrameItems.AddChild(newFrame);returnnewFrame;}nsIFrame*nsCSSFrameConstructor::ConstructTableCol(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aStyleDisplay,nsFrameItems&aFrameItems){nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;nsTableColFrame*colFrame=NS_NewTableColFrame(mPresShell,styleContext);InitAndRestoreFrame(aState,content,aParentFrame,colFrame);NS_ASSERTION(colFrame->StyleContext()==styleContext,"Unexpected style context");aFrameItems.AddChild(colFrame);// construct additional col frames if the col frame has a span > 1int32_tspan=colFrame->GetSpan();for(int32_tspanX=1;spanX<span;spanX++){nsTableColFrame*newCol=NS_NewTableColFrame(mPresShell,styleContext);InitAndRestoreFrame(aState,content,aParentFrame,newCol,false);aFrameItems.LastChild()->SetNextContinuation(newCol);newCol->SetPrevContinuation(aFrameItems.LastChild());aFrameItems.AddChild(newCol);newCol->SetColType(eColAnonymousCol);}returncolFrame;}nsIFrame*nsCSSFrameConstructor::ConstructTableCell(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){NS_PRECONDITION(aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_CELL,"Unexpected call");nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;constuint32_tnameSpaceID=aItem.mNameSpaceID;boolborderCollapse=IsBorderCollapse(aParentFrame);nsContainerFrame*newFrame;// <mtable> is border separate in mathml.css and the MathML code doesn't implement// border collapse. For those users who style <mtable> with border collapse,// give them the default non-MathML table frames that understand border collapse.// This won't break us because MathML table frames are all subclasses of the default// table code, and so we can freely mix <mtable> with <mtr> or <tr>, <mtd> or <td>.// What will happen is just that non-MathML frames won't understand MathML attributes// and will therefore miss the special handling that the MathML code does.if(kNameSpaceID_MathML==nameSpaceID&&!borderCollapse)newFrame=NS_NewMathMLmtdFrame(mPresShell,styleContext);else// Warning: If you change this and add a wrapper frame around table cell// frames, make sure Bug 368554 doesn't regress!// See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp.newFrame=NS_NewTableCellFrame(mPresShell,styleContext,borderCollapse);// Initialize the table cell frameInitAndRestoreFrame(aState,content,aParentFrame,newFrame);// Resolve pseudo style and initialize the body cell framensRefPtr<nsStyleContext>innerPseudoStyle;innerPseudoStyle=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::cellContent,styleContext);// Create a block frame that will format the cell's contentboolisBlock;nsContainerFrame*cellInnerFrame;if(kNameSpaceID_MathML==nameSpaceID){cellInnerFrame=NS_NewMathMLmtdInnerFrame(mPresShell,innerPseudoStyle);isBlock=false;}else{cellInnerFrame=NS_NewBlockFormattingContext(mPresShell,innerPseudoStyle);isBlock=true;}InitAndRestoreFrame(aState,content,newFrame,cellInnerFrame);nsFrameConstructorSaveStateabsoluteSaveState;MakeTablePartAbsoluteContainingBlockIfNeeded(aState,aDisplay,absoluteSaveState,newFrame);nsFrameItemschildItems;NS_ASSERTION(aItem.mAnonChildren.IsEmpty(),"nsIAnonymousContentCreator::CreateAnonymousContent ""implementations for table frames are not currently expected ""to output a list where the items have their own children");if(aItem.mFCData->mBits&FCDATA_USE_CHILD_ITEMS){// Need to push ourselves as a float containing block.// XXXbz it might be nice to work on getting the parent// FrameConstructionItem down into ProcessChildren and just making use of// the push there, but that's a bit of work.nsFrameConstructorSaveStatefloatSaveState;if(!isBlock){/* MathML case */aState.PushFloatContainingBlock(nullptr,floatSaveState);}else{aState.PushFloatContainingBlock(cellInnerFrame,floatSaveState);}ConstructFramesFromItemList(aState,aItem.mChildItems,cellInnerFrame,childItems);}else{// Process the child contentProcessChildren(aState,content,styleContext,cellInnerFrame,true,childItems,isBlock,aItem.mPendingBinding);}cellInnerFrame->SetInitialChildList(kPrincipalList,childItems);SetInitialSingleChild(newFrame,cellInnerFrame);aFrameItems.AddChild(newFrame);returnnewFrame;}staticinlineboolNeedFrameFor(constnsFrameConstructorState&aState,nsIFrame*aParentFrame,nsIContent*aChildContent){// XXX the GetContent() != aChildContent check is needed due to bug 135040.// Remove it once that's fixed.NS_PRECONDITION(!aChildContent->GetPrimaryFrame()||aState.mCreatingExtraFrames||aChildContent->GetPrimaryFrame()->GetContent()!=aChildContent,"Why did we get called?");// don't create a whitespace frame if aParentFrame doesn't want it.// always create frames for children in generated content. counter(),// quotes, and attr() content can easily change dynamically and we don't// want to be reconstructing frames. It's not even clear that these// should be considered ignorable just because they evaluate to// whitespace.// We could handle all this in CreateNeededPseudoContainers or some other// place after we build our frame construction items, but that would involve// creating frame construction items for whitespace kids of// eExcludesIgnorableWhitespace frames, where we know we'll be dropping them// all anyway, and involve an extra walk down the frame construction item// list.if((aParentFrame&&(!aParentFrame->IsFrameOfType(nsIFrame::eExcludesIgnorableWhitespace)||aParentFrame->IsGeneratedContentFrame()))||!aChildContent->IsNodeOfType(nsINode::eTEXT)){returntrue;}aChildContent->SetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE|NS_REFRAME_IF_WHITESPACE);return!aChildContent->TextIsOnlyWhitespace();}/*********************************************** * END TABLE SECTION ***********************************************/staticboolCheckOverflow(nsPresContext*aPresContext,constnsStyleDisplay*aDisplay){if(aDisplay->mOverflowX==NS_STYLE_OVERFLOW_VISIBLE&&aDisplay->mScrollBehavior==NS_STYLE_SCROLL_BEHAVIOR_AUTO&&aDisplay->mScrollSnapTypeX==NS_STYLE_SCROLL_SNAP_TYPE_NONE&&aDisplay->mScrollSnapTypeY==NS_STYLE_SCROLL_SNAP_TYPE_NONE&&aDisplay->mScrollSnapPointsX==nsStyleCoord(eStyleUnit_None)&&aDisplay->mScrollSnapPointsY==nsStyleCoord(eStyleUnit_None)&&!aDisplay->mScrollSnapDestination.mXPosition.mHasPercent&&!aDisplay->mScrollSnapDestination.mYPosition.mHasPercent&&aDisplay->mScrollSnapDestination.mXPosition.mLength==0&&aDisplay->mScrollSnapDestination.mYPosition.mLength==0){returnfalse;}if(aDisplay->mOverflowX==NS_STYLE_OVERFLOW_CLIP){aPresContext->SetViewportScrollbarStylesOverride(ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,NS_STYLE_OVERFLOW_HIDDEN,aDisplay));}else{aPresContext->SetViewportScrollbarStylesOverride(ScrollbarStyles(aDisplay));}returntrue;}/** * This checks the root element and the HTML BODY, if any, for an "overflow" property * that should be applied to the viewport. If one is found then we return the * element that we took the overflow from (which should then be treated as * "overflow:visible"), and we store the overflow style in the prescontext. * @return if scroll was propagated from some content node, the content node it * was propagated from. */nsIContent*nsCSSFrameConstructor::PropagateScrollToViewport(){// Set defaultnsPresContext*presContext=mPresShell->GetPresContext();presContext->SetViewportScrollbarStylesOverride(ScrollbarStyles(NS_STYLE_OVERFLOW_AUTO,NS_STYLE_OVERFLOW_AUTO));// We never mess with the viewport scroll state// when printing or in print previewif(presContext->IsPaginated()){returnnullptr;}Element*docElement=mDocument->GetRootElement();// Check the style on the document root elementnsStyleSet*styleSet=mPresShell->StyleSet();nsRefPtr<nsStyleContext>rootStyle;rootStyle=styleSet->ResolveStyleFor(docElement,nullptr);if(CheckOverflow(presContext,rootStyle->StyleDisplay())){// tell caller we stole the overflow style from the root elementreturndocElement;}// Don't look in the BODY for non-HTML documents or HTML documents// with non-HTML roots// XXX this should be earlier; we shouldn't even look at the document root// for non-HTML documents. Fix this once we support explicit CSS styling// of the viewport// XXX what about XHTML?nsCOMPtr<nsIDOMHTMLDocument>htmlDoc(do_QueryInterface(mDocument));if(!htmlDoc||!docElement->IsHTMLElement()){returnnullptr;}nsCOMPtr<nsIDOMHTMLElement>body;htmlDoc->GetBody(getter_AddRefs(body));nsCOMPtr<nsIContent>bodyElement=do_QueryInterface(body);if(!bodyElement||!bodyElement->NodeInfo()->Equals(nsGkAtoms::body)){// The body is not a <body> tag, it's a <frameset>.returnnullptr;}nsRefPtr<nsStyleContext>bodyStyle;bodyStyle=styleSet->ResolveStyleFor(bodyElement->AsElement(),rootStyle);if(CheckOverflow(presContext,bodyStyle->StyleDisplay())){// tell caller we stole the overflow style from the body elementreturnbodyElement;}returnnullptr;}nsIFrame*nsCSSFrameConstructor::ConstructDocElementFrame(Element*aDocElement,nsILayoutHistoryState*aFrameState){MOZ_ASSERT(GetRootFrame(),"No viewport? Someone forgot to call ConstructRootFrame!");MOZ_ASSERT(!mDocElementContainingBlock,"Shouldn't have a doc element containing block here");// Make sure to call PropagateScrollToViewport before// SetUpDocElementContainingBlock, since it sets up our scrollbar state// properly.#ifdef DEBUGnsIContent*propagatedScrollFrom=#endifPropagateScrollToViewport();SetUpDocElementContainingBlock(aDocElement);NS_ASSERTION(mDocElementContainingBlock,"Should have parent by now");nsFrameConstructorStatestate(mPresShell,GetAbsoluteContainingBlock(mDocElementContainingBlock,FIXED_POS),nullptr,nullptr,aFrameState);// Initialize the ancestor filter with null for now; we'll push// aDocElement once we finish resolving style for it.state.mTreeMatchContext.InitAncestors(nullptr);// XXXbz why, exactly?if(!mTempFrameTreeState)state.mPresShell->CaptureHistoryState(getter_AddRefs(mTempFrameTreeState));// Make sure that we'll handle restyles for this document element in// the future. We need this, because the document element might// have stale restyle bits from a previous frame constructor for// this document. Unlike in AddFrameConstructionItems, it's safe to// unset all element restyle flags, since we don't have any// siblings.aDocElement->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);// --------- CREATE AREA OR BOX FRAME -------// FIXME: Should this use ResolveStyleContext? (The calls in this// function are the only case in nsCSSFrameConstructor where we don't// do so for the construction of a style context for an element.)nsRefPtr<nsStyleContext>styleContext;styleContext=mPresShell->StyleSet()->ResolveStyleFor(aDocElement,nullptr);constnsStyleDisplay*display=styleContext->StyleDisplay();// Ensure that our XBL bindings are installed.if(display->mBinding){// Get the XBL loader.nsresultrv;boolresolveStyle;nsXBLService*xblService=nsXBLService::GetInstance();if(!xblService){returnnullptr;}nsRefPtr<nsXBLBinding>binding;rv=xblService->LoadBindings(aDocElement,display->mBinding->GetURI(),display->mBinding->mOriginPrincipal,getter_AddRefs(binding),&resolveStyle);if(NS_FAILED(rv)&&rv!=NS_ERROR_XBL_BLOCKED)returnnullptr;// Binding will load asynchronously.if(binding){// For backwards compat, keep firing the root's constructor// after all of its kids' constructors. So tell the binding// manager about it right now.mDocument->BindingManager()->AddToAttachedQueue(binding);}if(resolveStyle){// FIXME: Should this use ResolveStyleContext? (The calls in this// function are the only case in nsCSSFrameConstructor where we// don't do so for the construction of a style context for an// element.)styleContext=mPresShell->StyleSet()->ResolveStyleFor(aDocElement,nullptr);display=styleContext->StyleDisplay();}}// --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------#ifdef DEBUGNS_ASSERTION(!display->IsScrollableOverflow()||state.mPresContext->IsPaginated()||propagatedScrollFrom==aDocElement,"Scrollbars should have been propagated to the viewport");#endifif(MOZ_UNLIKELY(display->mDisplay==NS_STYLE_DISPLAY_NONE)){SetUndisplayedContent(aDocElement,styleContext);returnnullptr;}TreeMatchContext::AutoAncestorPusherancestorPusher(state.mTreeMatchContext);ancestorPusher.PushAncestorAndStyleScope(aDocElement);// Make sure to start any background image loads for the root element now.styleContext->StartBackgroundImageLoads();nsFrameConstructorSaveStateabsoluteSaveState;if(mHasRootAbsPosContainingBlock){// Push the absolute containing block now so we can absolutely position// the root elementmDocElementContainingBlock->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);state.PushAbsoluteContainingBlock(mDocElementContainingBlock,mDocElementContainingBlock,absoluteSaveState);}// The rules from CSS 2.1, section 9.2.4, have already been applied// by the style system, so we can assume that display->mDisplay is// either NONE, BLOCK, or TABLE.// contentFrame is the primary frame for the root element. newFrame// is the frame that will be the child of the initial containing block.// These are usually the same frame but they can be different, in// particular if the root frame is positioned, in which case// contentFrame is the out-of-flow frame and newFrame is the// placeholder.nsContainerFrame*contentFrame;nsIFrame*newFrame;boolprocessChildren=false;// Check whether we need to build a XUL box or SVG root frame#ifdef MOZ_XULif(aDocElement->IsXULElement()){contentFrame=NS_NewDocElementBoxFrame(mPresShell,styleContext);InitAndRestoreFrame(state,aDocElement,mDocElementContainingBlock,contentFrame);newFrame=contentFrame;processChildren=true;}else#endifif(aDocElement->IsSVGElement()){if(!aDocElement->IsSVGElement(nsGkAtoms::svg)){returnnullptr;}// We're going to call the right function ourselves, so no need to give a// function to this FrameConstructionData.// XXXbz on the other hand, if we converted this whole function to// FrameConstructionData/Item, then we'd need the right function// here... but would probably be able to get away with less code in this// function in general.// Use a null PendingBinding, since our binding is not in fact pending.staticconstFrameConstructionDatarootSVGData=FCDATA_DECL(0,nullptr);already_AddRefed<nsStyleContext>extraRef=nsRefPtr<nsStyleContext>(styleContext).forget();FrameConstructionItemitem(&rootSVGData,aDocElement,aDocElement->NodeInfo()->NameAtom(),kNameSpaceID_SVG,nullptr,extraRef,true,nullptr);nsFrameItemsframeItems;contentFrame=static_cast<nsContainerFrame*>(ConstructOuterSVG(state,item,mDocElementContainingBlock,styleContext->StyleDisplay(),frameItems));newFrame=frameItems.FirstChild();NS_ASSERTION(frameItems.OnlyChild(),"multiple root element frames");}elseif(display->mDisplay==NS_STYLE_DISPLAY_FLEX){contentFrame=NS_NewFlexContainerFrame(mPresShell,styleContext);InitAndRestoreFrame(state,aDocElement,mDocElementContainingBlock,contentFrame);newFrame=contentFrame;processChildren=true;}elseif(display->mDisplay==NS_STYLE_DISPLAY_GRID){contentFrame=NS_NewGridContainerFrame(mPresShell,styleContext);InitAndRestoreFrame(state,aDocElement,mDocElementContainingBlock,contentFrame);newFrame=contentFrame;processChildren=true;}elseif(display->mDisplay==NS_STYLE_DISPLAY_TABLE){// We're going to call the right function ourselves, so no need to give a// function to this FrameConstructionData.// XXXbz on the other hand, if we converted this whole function to// FrameConstructionData/Item, then we'd need the right function// here... but would probably be able to get away with less code in this// function in general.// Use a null PendingBinding, since our binding is not in fact pending.staticconstFrameConstructionDatarootTableData=FCDATA_DECL(0,nullptr);already_AddRefed<nsStyleContext>extraRef=nsRefPtr<nsStyleContext>(styleContext).forget();FrameConstructionItemitem(&rootTableData,aDocElement,aDocElement->NodeInfo()->NameAtom(),kNameSpaceID_None,nullptr,extraRef,true,nullptr);nsFrameItemsframeItems;// if the document is a table then just populate it.contentFrame=static_cast<nsContainerFrame*>(ConstructTable(state,item,mDocElementContainingBlock,styleContext->StyleDisplay(),frameItems));newFrame=frameItems.FirstChild();NS_ASSERTION(frameItems.OnlyChild(),"multiple root element frames");}else{MOZ_ASSERT(display->mDisplay==NS_STYLE_DISPLAY_BLOCK,"Unhandled display type for root element");contentFrame=NS_NewBlockFormattingContext(mPresShell,styleContext);nsFrameItemsframeItems;// Use a null PendingBinding, since our binding is not in fact pending.ConstructBlock(state,display,aDocElement,state.GetGeometricParent(display,mDocElementContainingBlock),mDocElementContainingBlock,styleContext,&contentFrame,frameItems,display->IsAbsPosContainingBlock(contentFrame)?contentFrame:nullptr,nullptr);newFrame=frameItems.FirstChild();NS_ASSERTION(frameItems.OnlyChild(),"multiple root element frames");}MOZ_ASSERT(newFrame);MOZ_ASSERT(contentFrame);NS_ASSERTION(processChildren?!mRootElementFrame:mRootElementFrame==contentFrame,"unexpected mRootElementFrame");mRootElementFrame=contentFrame;// Figure out which frame has the main style for the document element,// assigning it to mRootElementStyleFrame.// Backgrounds should be propagated from that frame to the viewport.contentFrame->GetParentStyleContext(&mRootElementStyleFrame);boolisChild=mRootElementStyleFrame&&mRootElementStyleFrame->GetParent()==contentFrame;if(!isChild){mRootElementStyleFrame=mRootElementFrame;}if(processChildren){// Still need to process the child contentnsFrameItemschildItems;NS_ASSERTION(!nsLayoutUtils::GetAsBlock(contentFrame)&&!contentFrame->IsFrameOfType(nsIFrame::eSVG),"Only XUL frames should reach here");// Use a null PendingBinding, since our binding is not in fact pending.ProcessChildren(state,aDocElement,styleContext,contentFrame,true,childItems,false,nullptr);// Set the initial child listscontentFrame->SetInitialChildList(kPrincipalList,childItems);}// set the primary frameaDocElement->SetPrimaryFrame(contentFrame);SetInitialSingleChild(mDocElementContainingBlock,newFrame);// Create touch caret frame if there is a canvas frameif(mDocElementContainingBlock->GetType()==nsGkAtoms::canvasFrame){ConstructAnonymousContentForCanvas(state,mDocElementContainingBlock,aDocElement);}returnnewFrame;}nsIFrame*nsCSSFrameConstructor::ConstructRootFrame(){AUTO_LAYOUT_PHASE_ENTRY_POINT(mPresShell->GetPresContext(),FrameC);nsStyleSet*styleSet=mPresShell->StyleSet();// Set up our style rule observer.// XXXbz wouldn't this make more sense as part of presshell init?{styleSet->SetBindingManager(mDocument->BindingManager());}// --------- BUILD VIEWPORT -----------nsRefPtr<nsStyleContext>viewportPseudoStyle=styleSet->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::viewport,nullptr);ViewportFrame*viewportFrame=NS_NewViewportFrame(mPresShell,viewportPseudoStyle);// XXXbz do we _have_ to pass a null content pointer to that frame?// Would it really kill us to pass in the root element or something?// What would that break?viewportFrame->Init(nullptr,nullptr,nullptr);// Bind the viewport frame to the root viewnsView*rootView=mPresShell->GetViewManager()->GetRootView();viewportFrame->SetView(rootView);nsContainerFrame::SyncFrameViewProperties(mPresShell->GetPresContext(),viewportFrame,viewportPseudoStyle,rootView);nsContainerFrame::SyncWindowProperties(mPresShell->GetPresContext(),viewportFrame,rootView);// Make it an absolute container for fixed-pos elementsviewportFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);viewportFrame->MarkAsAbsoluteContainingBlock();returnviewportFrame;}voidnsCSSFrameConstructor::SetUpDocElementContainingBlock(nsIContent*aDocElement){NS_PRECONDITION(aDocElement,"No element?");NS_PRECONDITION(!aDocElement->GetParent(),"Not root content?");NS_PRECONDITION(aDocElement->GetCurrentDoc(),"Not in a document?");NS_PRECONDITION(aDocElement->GetCurrentDoc()->GetRootElement()==aDocElement,"Not the root of the document?");/* how the root frame hierarchy should look Galley presentation, non-XUL, with scrolling: ViewportFrame [fixed-cb] nsHTMLScrollFrame nsCanvasFrame [abs-cb] root element frame (nsBlockFrame, nsSVGOuterSVGFrame, nsTableOuterFrame, nsPlaceholderFrame) Galley presentation, XUL ViewportFrame [fixed-cb] nsRootBoxFrame root element frame (nsDocElementBoxFrame) Print presentation, non-XUL ViewportFrame nsSimplePageSequenceFrame nsPageFrame nsPageContentFrame [fixed-cb] nsCanvasFrame [abs-cb] root element frame (nsBlockFrame, nsSVGOuterSVGFrame, nsTableOuterFrame, nsPlaceholderFrame) Print-preview presentation, non-XUL ViewportFrame nsHTMLScrollFrame nsSimplePageSequenceFrame nsPageFrame nsPageContentFrame [fixed-cb] nsCanvasFrame [abs-cb] root element frame (nsBlockFrame, nsSVGOuterSVGFrame, nsTableOuterFrame, nsPlaceholderFrame) Print/print preview of XUL is not supported. [fixed-cb]: the default containing block for fixed-pos content [abs-cb]: the default containing block for abs-pos content Meaning of nsCSSFrameConstructor fields: mRootElementFrame is "root element frame". This is the primary frame for the root element. mDocElementContainingBlock is the parent of mRootElementFrame (i.e. nsCanvasFrame or nsRootBoxFrame) mGfxScrollFrame is the nsHTMLScrollFrame mentioned above, or null if there isn't one mPageSequenceFrame is the nsSimplePageSequenceFrame, or null if there isn't one */// --------- CREATE ROOT FRAME -------// Create the root frame. The document element's frame is a child of the// root frame.//// The root frame serves two purposes:// - reserves space for any margins needed for the document element's frame// - renders the document element's background. This ensures the background covers// the entire canvas as specified by the CSS2 specnsPresContext*presContext=mPresShell->GetPresContext();boolisPaginated=presContext->IsRootPaginatedDocument();nsContainerFrame*viewportFrame=static_cast<nsContainerFrame*>(GetRootFrame());nsStyleContext*viewportPseudoStyle=viewportFrame->StyleContext();nsContainerFrame*rootFrame=nullptr;nsIAtom*rootPseudo;if(!isPaginated){#ifdef MOZ_XULif(aDocElement->IsXULElement()){// pass a temporary stylecontext, the correct one will be set laterrootFrame=NS_NewRootBoxFrame(mPresShell,viewportPseudoStyle);}else#endif{// pass a temporary stylecontext, the correct one will be set laterrootFrame=NS_NewCanvasFrame(mPresShell,viewportPseudoStyle);mHasRootAbsPosContainingBlock=true;}rootPseudo=nsCSSAnonBoxes::canvas;mDocElementContainingBlock=rootFrame;}else{// Create a page sequence framerootFrame=NS_NewSimplePageSequenceFrame(mPresShell,viewportPseudoStyle);mPageSequenceFrame=rootFrame;rootPseudo=nsCSSAnonBoxes::pageSequence;}// --------- IF SCROLLABLE WRAP IN SCROLLFRAME --------// If the device supports scrolling (e.g., in galley mode on the screen and// for print-preview, but not when printing), then create a scroll frame that// will act as the scrolling mechanism for the viewport.// XXX Do we even need a viewport when printing to a printer?boolisHTML=aDocElement->IsHTMLElement();boolisXUL=false;if(!isHTML){isXUL=aDocElement->IsXULElement();}// Never create scrollbars for XUL documentsboolisScrollable=isPaginated?presContext->HasPaginatedScrolling():!isXUL;// We no longer need to do overflow propagation here. It's taken care of// when we construct frames for the element whose overflow might be// propagatedNS_ASSERTION(!isScrollable||!isXUL,"XUL documents should never be scrollable - see above");nsContainerFrame*newFrame=rootFrame;nsRefPtr<nsStyleContext>rootPseudoStyle;// we must create a state because if the scrollbars are GFX it needs the// state to build the scrollbar frames.nsFrameConstructorStatestate(mPresShell,nullptr,nullptr,nullptr);// Start off with the viewport as parent; we'll adjust it as needed.nsContainerFrame*parentFrame=viewportFrame;nsStyleSet*styleSet=mPresShell->StyleSet();// If paginated, make sure we don't put scrollbars inif(!isScrollable){rootPseudoStyle=styleSet->ResolveAnonymousBoxStyle(rootPseudo,viewportPseudoStyle);}else{if(rootPseudo==nsCSSAnonBoxes::canvas){rootPseudo=nsCSSAnonBoxes::scrolledCanvas;}else{NS_ASSERTION(rootPseudo==nsCSSAnonBoxes::pageSequence,"Unknown root pseudo");rootPseudo=nsCSSAnonBoxes::scrolledPageSequence;}// Build the frame. We give it the content we are wrapping which is the// document element, the root frame, the parent view port frame, and we// should get back the new frame and the scrollable view if one was// created.// resolve a context for the scrollframensRefPtr<nsStyleContext>styleContext;styleContext=styleSet->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::viewportScroll,viewportPseudoStyle);// Note that the viewport scrollframe is always built with// overflow:auto style. This forces the scroll frame to create// anonymous content for both scrollbars. This is necessary even// if the HTML or BODY elements are overriding the viewport// scroll style to 'hidden' --- dynamic style changes might put// scrollbars back on the viewport and we don't want to have to// reframe the viewport to create the scrollbar content.newFrame=nullptr;rootPseudoStyle=BeginBuildingScrollFrame(state,aDocElement,styleContext,viewportFrame,rootPseudo,true,newFrame);parentFrame=newFrame;mGfxScrollFrame=newFrame;}rootFrame->SetStyleContextWithoutNotification(rootPseudoStyle);rootFrame->Init(aDocElement,parentFrame,nullptr);if(isScrollable){FinishBuildingScrollFrame(parentFrame,rootFrame);}if(isPaginated){// Create the first page// Set the initial child listsnsContainerFrame*canvasFrame;nsContainerFrame*pageFrame=ConstructPageFrame(mPresShell,presContext,rootFrame,nullptr,canvasFrame);SetInitialSingleChild(rootFrame,pageFrame);// The eventual parent of the document element frame.// XXX should this be set for every new page (in ConstructPageFrame)?mDocElementContainingBlock=canvasFrame;mHasRootAbsPosContainingBlock=true;}if(viewportFrame->GetStateBits()&NS_FRAME_FIRST_REFLOW){SetInitialSingleChild(viewportFrame,newFrame);}else{nsFrameListnewFrameList(newFrame,newFrame);viewportFrame->AppendFrames(kPrincipalList,newFrameList);}}voidnsCSSFrameConstructor::ConstructAnonymousContentForCanvas(nsFrameConstructorState&aState,nsIFrame*aFrame,nsIContent*aDocElement){NS_ASSERTION(aFrame->GetType()==nsGkAtoms::canvasFrame,"aFrame should be canvas frame!");nsAutoTArray<nsIAnonymousContentCreator::ContentInfo,4>anonymousItems;GetAnonymousContent(aDocElement,aFrame,anonymousItems);if(anonymousItems.IsEmpty()){// Touch caret is not enabled.return;}FrameConstructionItemListitemsToConstruct;nsContainerFrame*frameAsContainer=do_QueryFrame(aFrame);AddFCItemsForAnonymousContent(aState,frameAsContainer,anonymousItems,itemsToConstruct);nsFrameItemsframeItems;ConstructFramesFromItemList(aState,itemsToConstruct,frameAsContainer,frameItems);frameAsContainer->AppendFrames(kPrincipalList,frameItems);}nsContainerFrame*nsCSSFrameConstructor::ConstructPageFrame(nsIPresShell*aPresShell,nsPresContext*aPresContext,nsContainerFrame*aParentFrame,nsIFrame*aPrevPageFrame,nsContainerFrame*&aCanvasFrame){nsStyleContext*parentStyleContext=aParentFrame->StyleContext();nsStyleSet*styleSet=aPresShell->StyleSet();nsRefPtr<nsStyleContext>pagePseudoStyle;pagePseudoStyle=styleSet->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::page,parentStyleContext);nsContainerFrame*pageFrame=NS_NewPageFrame(aPresShell,pagePseudoStyle);// Initialize the page frame and force it to have a view. This makes printing of// the pages easier and faster.pageFrame->Init(nullptr,aParentFrame,aPrevPageFrame);nsRefPtr<nsStyleContext>pageContentPseudoStyle;pageContentPseudoStyle=styleSet->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::pageContent,pagePseudoStyle);nsContainerFrame*pageContentFrame=NS_NewPageContentFrame(aPresShell,pageContentPseudoStyle);// Initialize the page content frame and force it to have a view. Also make it the// containing block for fixed elements which are repeated on every page.nsIFrame*prevPageContentFrame=nullptr;if(aPrevPageFrame){prevPageContentFrame=aPrevPageFrame->GetFirstPrincipalChild();NS_ASSERTION(prevPageContentFrame,"missing page content frame");}pageContentFrame->Init(nullptr,pageFrame,prevPageContentFrame);SetInitialSingleChild(pageFrame,pageContentFrame);// Make it an absolute container for fixed-pos elementspageContentFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);pageContentFrame->MarkAsAbsoluteContainingBlock();nsRefPtr<nsStyleContext>canvasPseudoStyle;canvasPseudoStyle=styleSet->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::canvas,pageContentPseudoStyle);aCanvasFrame=NS_NewCanvasFrame(aPresShell,canvasPseudoStyle);nsIFrame*prevCanvasFrame=nullptr;if(prevPageContentFrame){prevCanvasFrame=prevPageContentFrame->GetFirstPrincipalChild();NS_ASSERTION(prevCanvasFrame,"missing canvas frame");}aCanvasFrame->Init(nullptr,pageContentFrame,prevCanvasFrame);SetInitialSingleChild(pageContentFrame,aCanvasFrame);returnpageFrame;}/* static */nsIFrame*nsCSSFrameConstructor::CreatePlaceholderFrameFor(nsIPresShell*aPresShell,nsIContent*aContent,nsIFrame*aFrame,nsStyleContext*aStyleContext,nsContainerFrame*aParentFrame,nsIFrame*aPrevInFlow,nsFrameStateaTypeBit){nsRefPtr<nsStyleContext>placeholderStyle=aPresShell->StyleSet()->ResolveStyleForNonElement(aStyleContext->GetParent());// The placeholder frame gets a pseudo style contextnsPlaceholderFrame*placeholderFrame=(nsPlaceholderFrame*)NS_NewPlaceholderFrame(aPresShell,placeholderStyle,aTypeBit);placeholderFrame->Init(aContent,aParentFrame,aPrevInFlow);// The placeholder frame has a pointer back to the out-of-flow frameplaceholderFrame->SetOutOfFlowFrame(aFrame);aFrame->AddStateBits(NS_FRAME_OUT_OF_FLOW);// Add mapping from absolutely positioned frame to its placeholder frameaPresShell->FrameManager()->RegisterPlaceholderFrame(placeholderFrame);returnplaceholderFrame;}// Clears any lazy bits set in the range [aStartContent, aEndContent). If// aEndContent is null, that means to clear bits in all siblings starting with// aStartContent. aStartContent must not be null unless aEndContent is also// null. We do this so that when new children are inserted under elements whose// frame is a leaf the new children don't cause us to try to construct frames// for the existing children again.staticinlinevoidClearLazyBits(nsIContent*aStartContent,nsIContent*aEndContent){NS_PRECONDITION(aStartContent||!aEndContent,"Must have start child if we have an end child");for(nsIContent*cur=aStartContent;cur!=aEndContent;cur=cur->GetNextSibling()){cur->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES|NODE_NEEDS_FRAME);}}nsIFrame*nsCSSFrameConstructor::ConstructSelectFrame(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aStyleDisplay,nsFrameItems&aFrameItems){nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;// Construct a frame-based listbox or comboboxdom::HTMLSelectElement*sel=dom::HTMLSelectElement::FromContent(content);MOZ_ASSERT(sel);if(sel->IsCombobox()){// Construct a frame-based combo box.// The frame-based combo box is built out of three parts. A display area, a button and// a dropdown list. The display area and button are created through anonymous content.// The drop-down list's frame is created explicitly. The combobox frame shares its content// with the drop-down list.nsFrameStateflags=NS_BLOCK_FLOAT_MGR;nsContainerFrame*comboboxFrame=NS_NewComboboxControlFrame(mPresShell,styleContext,flags);// Save the history state so we don't restore during construction// since the complete tree is required before we restore.nsILayoutHistoryState*historyState=aState.mFrameState;aState.mFrameState=nullptr;// Initialize the combobox frameInitAndRestoreFrame(aState,content,aState.GetGeometricParent(aStyleDisplay,aParentFrame),comboboxFrame);aState.AddChild(comboboxFrame,aFrameItems,content,styleContext,aParentFrame);nsIComboboxControlFrame*comboBox=do_QueryFrame(comboboxFrame);NS_ASSERTION(comboBox,"NS_NewComboboxControlFrame returned frame that ""doesn't implement nsIComboboxControlFrame");// Resolve pseudo element style for the dropdown listnsRefPtr<nsStyleContext>listStyle;listStyle=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::dropDownList,styleContext);// Create a listboxnsContainerFrame*listFrame=NS_NewListControlFrame(mPresShell,listStyle);// Notify the listbox that it is being used as a dropdown list.nsIListControlFrame*listControlFrame=do_QueryFrame(listFrame);if(listControlFrame){listControlFrame->SetComboboxFrame(comboboxFrame);}// Notify combobox that it should use the listbox as it's popupcomboBox->SetDropDown(listFrame);NS_ASSERTION(!listFrame->IsAbsPosContaininingBlock(),"Ended up with positioned dropdown list somehow.");NS_ASSERTION(!listFrame->IsFloating(),"Ended up with floating dropdown list somehow.");// Initialize the scroll frame positioned. Note that it is NOT// initialized as absolutely positioned.nsContainerFrame*scrolledFrame=NS_NewSelectsAreaFrame(mPresShell,styleContext,flags);InitializeSelectFrame(aState,listFrame,scrolledFrame,content,comboboxFrame,listStyle,true,aItem.mPendingBinding,aFrameItems);NS_ASSERTION(listFrame->GetView(),"ListFrame's view is nullptr");// Create display and button frames from the combobox's anonymous content.// The anonymous content is appended to existing anonymous content for this// element (the scrollbars).nsFrameItemschildItems;CreateAnonymousFrames(aState,content,comboboxFrame,aItem.mPendingBinding,childItems);comboboxFrame->SetInitialChildList(kPrincipalList,childItems);// Initialize the additional popup child list which contains the// dropdown list frame.nsFrameItemspopupItems;popupItems.AddChild(listFrame);comboboxFrame->SetInitialChildList(nsIFrame::kSelectPopupList,popupItems);aState.mFrameState=historyState;if(aState.mFrameState){// Restore frame state for the entire subtree of |comboboxFrame|.RestoreFrameState(comboboxFrame,aState.mFrameState);}returncomboboxFrame;}// Listbox, not comboboxnsContainerFrame*listFrame=NS_NewListControlFrame(mPresShell,styleContext);nsContainerFrame*scrolledFrame=NS_NewSelectsAreaFrame(mPresShell,styleContext,NS_BLOCK_FLOAT_MGR);// ******* this code stolen from Initialze ScrollFrame ********// please adjust this code to use BuildScrollFrame.InitializeSelectFrame(aState,listFrame,scrolledFrame,content,aParentFrame,styleContext,false,aItem.mPendingBinding,aFrameItems);returnlistFrame;}/** * Used to be InitializeScrollFrame but now it's only used for the select tag * But the select tag should really be fixed to use GFX scrollbars that can * be create with BuildScrollFrame. */nsresultnsCSSFrameConstructor::InitializeSelectFrame(nsFrameConstructorState&aState,nsContainerFrame*scrollFrame,nsContainerFrame*scrolledFrame,nsIContent*aContent,nsContainerFrame*aParentFrame,nsStyleContext*aStyleContext,boolaBuildCombobox,PendingBinding*aPendingBinding,nsFrameItems&aFrameItems){// Initialize itnsContainerFrame*geometricParent=aState.GetGeometricParent(aStyleContext->StyleDisplay(),aParentFrame);// We don't call InitAndRestoreFrame for scrollFrame because we can only// restore the frame state after its parts have been created (in particular,// the scrollable view). So we have to split Init and Restore.scrollFrame->Init(aContent,geometricParent,nullptr);if(!aBuildCombobox){aState.AddChild(scrollFrame,aFrameItems,aContent,aStyleContext,aParentFrame);}if(aBuildCombobox){nsContainerFrame::CreateViewForFrame(scrollFrame,true);}BuildScrollFrame(aState,aContent,aStyleContext,scrolledFrame,geometricParent,scrollFrame);if(aState.mFrameState){// Restore frame state for the scroll frameRestoreFrameStateFor(scrollFrame,aState.mFrameState);}// Process childrennsFrameItemschildItems;ProcessChildren(aState,aContent,aStyleContext,scrolledFrame,false,childItems,false,aPendingBinding);// Set the scrolled frame's initial child listsscrolledFrame->SetInitialChildList(kPrincipalList,childItems);returnNS_OK;}nsIFrame*nsCSSFrameConstructor::ConstructFieldSetFrame(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aStyleDisplay,nsFrameItems&aFrameItems){nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;nsContainerFrame*fieldsetFrame=NS_NewFieldSetFrame(mPresShell,styleContext);// Initialize itInitAndRestoreFrame(aState,content,aState.GetGeometricParent(aStyleDisplay,aParentFrame),fieldsetFrame);// Resolve style and initialize the framensRefPtr<nsStyleContext>fieldsetContentStyle;fieldsetContentStyle=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::fieldsetContent,styleContext);constnsStyleDisplay*fieldsetContentDisplay=fieldsetContentStyle->StyleDisplay();boolisScrollable=fieldsetContentDisplay->IsScrollableOverflow();nsContainerFrame*scrollFrame=nullptr;if(isScrollable){fieldsetContentStyle=BeginBuildingScrollFrame(aState,content,fieldsetContentStyle,fieldsetFrame,nsCSSAnonBoxes::scrolledContent,false,scrollFrame);}nsContainerFrame*blockFrame=NS_NewBlockFrame(mPresShell,fieldsetContentStyle,NS_BLOCK_FLOAT_MGR|NS_BLOCK_MARGIN_ROOT);InitAndRestoreFrame(aState,content,scrollFrame?scrollFrame:fieldsetFrame,blockFrame);aState.AddChild(fieldsetFrame,aFrameItems,content,styleContext,aParentFrame);// Process childrennsFrameConstructorSaveStateabsoluteSaveState;nsFrameItemschildItems;blockFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);if(fieldsetFrame->IsAbsPosContaininingBlock()){aState.PushAbsoluteContainingBlock(blockFrame,fieldsetFrame,absoluteSaveState);}ProcessChildren(aState,content,styleContext,blockFrame,true,childItems,true,aItem.mPendingBinding);nsFrameItemsfieldsetKids;fieldsetKids.AddChild(scrollFrame?scrollFrame:blockFrame);for(nsFrameList::Enumeratore(childItems);!e.AtEnd();e.Next()){nsIFrame*child=e.get();nsContainerFrame*cif=child->GetContentInsertionFrame();if(cif&&cif->GetType()==nsGkAtoms::legendFrame){// We want the legend to be the first frame in the fieldset child list.// That way the EventStateManager will do the right thing when tabbing// from a selection point within the legend (bug 236071), which is// used for implementing legend access keys (bug 81481).// GetAdjustedParentFrame() below depends on this frame order.childItems.RemoveFrame(child);// Make sure to reparent the legend so it has the fieldset as the parent.fieldsetKids.InsertFrame(fieldsetFrame,nullptr,child);if(scrollFrame){StickyScrollContainer::NotifyReparentedFrameAcrossScrollFrameBoundary(child,blockFrame);}break;}}if(isScrollable){FinishBuildingScrollFrame(scrollFrame,blockFrame);}// Set the inner frame's initial child listsblockFrame->SetInitialChildList(kPrincipalList,childItems);// Set the outer frame's initial child listfieldsetFrame->SetInitialChildList(kPrincipalList,fieldsetKids);fieldsetFrame->AddStateBits(NS_FRAME_MAY_HAVE_GENERATED_CONTENT);// Our new frame returned is the outer frame, which is the fieldset frame.returnfieldsetFrame;}staticnsIFrame*FindAncestorWithGeneratedContentPseudo(nsIFrame*aFrame){for(nsIFrame*f=aFrame->GetParent();f;f=f->GetParent()){NS_ASSERTION(f->IsGeneratedContentFrame(),"should not have exited generated content");nsIAtom*pseudo=f->StyleContext()->GetPseudo();if(pseudo==nsCSSPseudoElements::before||pseudo==nsCSSPseudoElements::after)returnf;}returnnullptr;}#define SIMPLE_FCDATA(_func) FCDATA_DECL(0, _func)#define FULL_CTOR_FCDATA(_flags, _func) \ { _flags | FCDATA_FUNC_IS_FULL_CTOR, { nullptr }, _func, nullptr }/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindTextData(nsIFrame*aParentFrame){if(aParentFrame&&IsFrameForSVG(aParentFrame)){nsIFrame*ancestorFrame=nsSVGUtils::GetFirstNonAAncestorFrame(aParentFrame);if(ancestorFrame){staticconstFrameConstructionDatasSVGTextData=FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT|FCDATA_IS_SVG_TEXT,NS_NewTextFrame);if(ancestorFrame->IsSVGText()){return&sSVGTextData;}}returnnullptr;}staticconstFrameConstructionDatasTextData=FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT,NS_NewTextFrame);return&sTextData;}voidnsCSSFrameConstructor::ConstructTextFrame(constFrameConstructionData*aData,nsFrameConstructorState&aState,nsIContent*aContent,nsContainerFrame*aParentFrame,nsStyleContext*aStyleContext,nsFrameItems&aFrameItems){NS_PRECONDITION(aData,"Must have frame construction data");nsIFrame*newFrame=(*aData->mFunc.mCreationFunc)(mPresShell,aStyleContext);InitAndRestoreFrame(aState,aContent,aParentFrame,newFrame);// We never need to create a view for a text frame.if(newFrame->IsGeneratedContentFrame()){nsAutoPtr<nsGenConInitializer>initializer;initializer=static_cast<nsGenConInitializer*>(aContent->UnsetProperty(nsGkAtoms::genConInitializerProperty));if(initializer){if(initializer->mNode->InitTextFrame(initializer->mList,FindAncestorWithGeneratedContentPseudo(newFrame),newFrame)){(this->*(initializer->mDirtyAll))();}initializer->mNode.forget();}}// Add the newly constructed frame to the flowaFrameItems.AddChild(newFrame);if(!aState.mCreatingExtraFrames)aContent->SetPrimaryFrame(newFrame);}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindDataByInt(int32_taInt,Element*aElement,nsStyleContext*aStyleContext,constFrameConstructionDataByInt*aDataPtr,uint32_taDataLength){for(constFrameConstructionDataByInt*curData=aDataPtr,*endData=aDataPtr+aDataLength;curData!=endData;++curData){if(curData->mInt==aInt){constFrameConstructionData*data=&curData->mData;if(data->mBits&FCDATA_FUNC_IS_DATA_GETTER){returndata->mFunc.mDataGetter(aElement,aStyleContext);}returndata;}}returnnullptr;}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindDataByTag(nsIAtom*aTag,Element*aElement,nsStyleContext*aStyleContext,constFrameConstructionDataByTag*aDataPtr,uint32_taDataLength){for(constFrameConstructionDataByTag*curData=aDataPtr,*endData=aDataPtr+aDataLength;curData!=endData;++curData){if(*curData->mTag==aTag){constFrameConstructionData*data=&curData->mData;if(data->mBits&FCDATA_FUNC_IS_DATA_GETTER){returndata->mFunc.mDataGetter(aElement,aStyleContext);}returndata;}}returnnullptr;}#define SUPPRESS_FCDATA() FCDATA_DECL(FCDATA_SUPPRESS_FRAME, nullptr)#define SIMPLE_INT_CREATE(_int, _func) { _int, SIMPLE_FCDATA(_func) }#define SIMPLE_INT_CHAIN(_int, _func) \ { _int, FCDATA_DECL(FCDATA_FUNC_IS_DATA_GETTER, _func) }#define COMPLEX_INT_CREATE(_int, _func) \ { _int, FULL_CTOR_FCDATA(0, _func) }#define SIMPLE_TAG_CREATE(_tag, _func) \ { &nsGkAtoms::_tag, SIMPLE_FCDATA(_func) }#define SIMPLE_TAG_CHAIN(_tag, _func) \ { &nsGkAtoms::_tag, FCDATA_DECL(FCDATA_FUNC_IS_DATA_GETTER, _func) }#define COMPLEX_TAG_CREATE(_tag, _func) \ { &nsGkAtoms::_tag, FULL_CTOR_FCDATA(0, _func) }staticboolIsFrameForFieldSet(nsIFrame*aFrame,nsIAtom*aFrameType){nsIAtom*pseudo=aFrame->StyleContext()->GetPseudo();if(pseudo==nsCSSAnonBoxes::fieldsetContent||pseudo==nsCSSAnonBoxes::scrolledContent){returnIsFrameForFieldSet(aFrame->GetParent(),aFrame->GetParent()->GetType());}returnaFrameType==nsGkAtoms::fieldSetFrame;}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindHTMLData(Element*aElement,nsIAtom*aTag,int32_taNameSpaceID,nsIFrame*aParentFrame,nsStyleContext*aStyleContext){// Ignore the tag if it's not HTML content and if it doesn't extend (via XBL)// a valid HTML namespace. This check must match the one in// ShouldHaveFirstLineStyle.if(aNameSpaceID!=kNameSpaceID_XHTML){returnnullptr;}NS_ASSERTION(!aParentFrame||aParentFrame->StyleContext()->GetPseudo()!=nsCSSAnonBoxes::fieldsetContent||aParentFrame->GetParent()->GetType()==nsGkAtoms::fieldSetFrame,"Unexpected parent for fieldset content anon box");if(aTag==nsGkAtoms::legend&&(!aParentFrame||!IsFrameForFieldSet(aParentFrame,aParentFrame->GetType())||aStyleContext->StyleDisplay()->IsFloatingStyle()||aStyleContext->StyleDisplay()->IsAbsolutelyPositionedStyle())){// <legend> is only special inside fieldset, we only check the frame tree// parent because the content tree parent may not be a <fieldset> due to// display:contents, Shadow DOM, or XBL. For floated or absolutely// positioned legends we want to construct by display type and// not do special legend stuff.returnnullptr;}staticconstFrameConstructionDataByTagsHTMLData[]={SIMPLE_TAG_CHAIN(img,nsCSSFrameConstructor::FindImgData),SIMPLE_TAG_CHAIN(mozgeneratedcontentimage,nsCSSFrameConstructor::FindImgData),{&nsGkAtoms::br,FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT|FCDATA_IS_LINE_BREAK,NS_NewBRFrame)},SIMPLE_TAG_CREATE(wbr,NS_NewWBRFrame),SIMPLE_TAG_CHAIN(input,nsCSSFrameConstructor::FindInputData),SIMPLE_TAG_CREATE(textarea,NS_NewTextControlFrame),COMPLEX_TAG_CREATE(select,&nsCSSFrameConstructor::ConstructSelectFrame),SIMPLE_TAG_CHAIN(object,nsCSSFrameConstructor::FindObjectData),SIMPLE_TAG_CHAIN(applet,nsCSSFrameConstructor::FindObjectData),SIMPLE_TAG_CHAIN(embed,nsCSSFrameConstructor::FindObjectData),COMPLEX_TAG_CREATE(fieldset,&nsCSSFrameConstructor::ConstructFieldSetFrame),{&nsGkAtoms::legend,FCDATA_DECL(FCDATA_ALLOW_BLOCK_STYLES|FCDATA_MAY_NEED_SCROLLFRAME,NS_NewLegendFrame)},SIMPLE_TAG_CREATE(frameset,NS_NewHTMLFramesetFrame),SIMPLE_TAG_CREATE(iframe,NS_NewSubDocumentFrame),{&nsGkAtoms::button,FCDATA_WITH_WRAPPING_BLOCK(FCDATA_ALLOW_BLOCK_STYLES,NS_NewHTMLButtonControlFrame,nsCSSAnonBoxes::buttonContent)},SIMPLE_TAG_CHAIN(canvas,nsCSSFrameConstructor::FindCanvasData),SIMPLE_TAG_CREATE(video,NS_NewHTMLVideoFrame),SIMPLE_TAG_CREATE(audio,NS_NewHTMLVideoFrame),SIMPLE_TAG_CREATE(progress,NS_NewProgressFrame),SIMPLE_TAG_CREATE(meter,NS_NewMeterFrame)};returnFindDataByTag(aTag,aElement,aStyleContext,sHTMLData,ArrayLength(sHTMLData));}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindImgData(Element*aElement,nsStyleContext*aStyleContext){if(!nsImageFrame::ShouldCreateImageFrameFor(aElement,aStyleContext)){returnnullptr;}staticconstFrameConstructionDatasImgData=SIMPLE_FCDATA(NS_NewImageFrame);return&sImgData;}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindImgControlData(Element*aElement,nsStyleContext*aStyleContext){if(!nsImageFrame::ShouldCreateImageFrameFor(aElement,aStyleContext)){returnnullptr;}staticconstFrameConstructionDatasImgControlData=SIMPLE_FCDATA(NS_NewImageControlFrame);return&sImgControlData;}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindInputData(Element*aElement,nsStyleContext*aStyleContext){staticconstFrameConstructionDataByIntsInputData[]={SIMPLE_INT_CREATE(NS_FORM_INPUT_CHECKBOX,NS_NewGfxCheckboxControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_RADIO,NS_NewGfxRadioControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_FILE,NS_NewFileControlFrame),SIMPLE_INT_CHAIN(NS_FORM_INPUT_IMAGE,nsCSSFrameConstructor::FindImgControlData),SIMPLE_INT_CREATE(NS_FORM_INPUT_EMAIL,NS_NewTextControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_SEARCH,NS_NewTextControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_TEXT,NS_NewTextControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_TEL,NS_NewTextControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_URL,NS_NewTextControlFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_RANGE,NS_NewRangeFrame),SIMPLE_INT_CREATE(NS_FORM_INPUT_PASSWORD,NS_NewTextControlFrame),{NS_FORM_INPUT_COLOR,FCDATA_WITH_WRAPPING_BLOCK(0,NS_NewColorControlFrame,nsCSSAnonBoxes::buttonContent)},// TODO: this is temporary until a frame is written: bug 635240.SIMPLE_INT_CREATE(NS_FORM_INPUT_NUMBER,NS_NewNumberControlFrame),// TODO: this is temporary until a frame is written: bug 773205.SIMPLE_INT_CREATE(NS_FORM_INPUT_DATE,NS_NewTextControlFrame),// TODO: this is temporary until a frame is written: bug 773205SIMPLE_INT_CREATE(NS_FORM_INPUT_TIME,NS_NewTextControlFrame),{NS_FORM_INPUT_SUBMIT,FCDATA_WITH_WRAPPING_BLOCK(0,NS_NewGfxButtonControlFrame,nsCSSAnonBoxes::buttonContent)},{NS_FORM_INPUT_RESET,FCDATA_WITH_WRAPPING_BLOCK(0,NS_NewGfxButtonControlFrame,nsCSSAnonBoxes::buttonContent)},{NS_FORM_INPUT_BUTTON,FCDATA_WITH_WRAPPING_BLOCK(0,NS_NewGfxButtonControlFrame,nsCSSAnonBoxes::buttonContent)}// Keeping hidden inputs out of here on purpose for so they get frames by// display (in practice, none).};nsCOMPtr<nsIFormControl>control=do_QueryInterface(aElement);NS_ASSERTION(control,"input doesn't implement nsIFormControl?");returnFindDataByInt(control->GetType(),aElement,aStyleContext,sInputData,ArrayLength(sInputData));}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindObjectData(Element*aElement,nsStyleContext*aStyleContext){// GetDisplayedType isn't necessarily nsIObjectLoadingContent::TYPE_NULL for// cases when the object is broken/suppressed/etc (e.g. a broken image), but// we want to treat those cases as TYPE_NULLuint32_ttype;if(aElement->State().HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN|NS_EVENT_STATE_USERDISABLED|NS_EVENT_STATE_SUPPRESSED)){type=nsIObjectLoadingContent::TYPE_NULL;}else{nsCOMPtr<nsIObjectLoadingContent>objContent(do_QueryInterface(aElement));NS_ASSERTION(objContent,"applet, embed and object must implement ""nsIObjectLoadingContent!");objContent->GetDisplayedType(&type);}staticconstFrameConstructionDataByIntsObjectData[]={SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_LOADING,NS_NewEmptyFrame),SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_PLUGIN,NS_NewObjectFrame),SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_IMAGE,NS_NewImageFrame),SIMPLE_INT_CREATE(nsIObjectLoadingContent::TYPE_DOCUMENT,NS_NewSubDocumentFrame)// Nothing for TYPE_NULL so we'll construct frames by display there};returnFindDataByInt((int32_t)type,aElement,aStyleContext,sObjectData,ArrayLength(sObjectData));}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindCanvasData(Element*aElement,nsStyleContext*aStyleContext){// We want to check whether script is enabled on the document that// could be painting to the canvas. That's the owner document of// the canvas, except when the owner document is a static document,// in which case it's the original document it was cloned from.nsIDocument*doc=aElement->OwnerDoc();if(doc->IsStaticDocument()){doc=doc->GetOriginalDocument();}if(!doc->IsScriptEnabled()){returnnullptr;}staticconstFrameConstructionDatasCanvasData=FCDATA_WITH_WRAPPING_BLOCK(0,NS_NewHTMLCanvasFrame,nsCSSAnonBoxes::htmlCanvasContent);return&sCanvasData;}voidnsCSSFrameConstructor::ConstructFrameFromItemInternal(FrameConstructionItem&aItem,nsFrameConstructorState&aState,nsContainerFrame*aParentFrame,nsFrameItems&aFrameItems){constFrameConstructionData*data=aItem.mFCData;NS_ASSERTION(data,"Must have frame construction data");uint32_tbits=data->mBits;NS_ASSERTION(!(bits&FCDATA_FUNC_IS_DATA_GETTER),"Should have dealt with this inside the data finder");// Some sets of bits are not compatible with each other#define CHECK_ONLY_ONE_BIT(_bit1, _bit2) \ NS_ASSERTION(!(bits & _bit1) || !(bits & _bit2), \ "Only one of these bits should be set")CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_FORCE_NULL_ABSPOS_CONTAINER);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_WRAP_KIDS_IN_BLOCKS);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_MAY_NEED_SCROLLFRAME);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_IS_POPUP);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_SKIP_ABSPOS_PUSH);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_DISALLOW_GENERATED_CONTENT);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_ALLOW_BLOCK_STYLES);CHECK_ONLY_ONE_BIT(FCDATA_FUNC_IS_FULL_CTOR,FCDATA_CREATE_BLOCK_WRAPPER_FOR_ALL_KIDS);CHECK_ONLY_ONE_BIT(FCDATA_WRAP_KIDS_IN_BLOCKS,FCDATA_CREATE_BLOCK_WRAPPER_FOR_ALL_KIDS);#undef CHECK_ONLY_ONE_BITNS_ASSERTION(!(bits&FCDATA_FORCED_NON_SCROLLABLE_BLOCK)||((bits&FCDATA_FUNC_IS_FULL_CTOR)&&data->mFullConstructor==&nsCSSFrameConstructor::ConstructNonScrollableBlock),"Unexpected FCDATA_FORCED_NON_SCROLLABLE_BLOCK flag");// Don't create a subdocument frame for iframes if we're creating extra framesif(aState.mCreatingExtraFrames&&aItem.mContent->IsHTMLElement(nsGkAtoms::iframe)){return;}nsIContent*constcontent=aItem.mContent;nsIContent*parent=content->GetParent();// Push display:contents ancestors.AutoDisplayContentsAncestorPusheradcp(aState.mTreeMatchContext,aState.mPresContext,parent);// Get the parent of the content and check if it is a XBL children element.// Push the children element as an ancestor here because it does// not have a frame and would not otherwise be pushed as an ancestor. It is// necessary to do so in order to correctly handle style resolution on// descendants. (If !adcp.IsEmpty() then it was already pushed by// AutoDisplayContentsAncestorPusher above.)TreeMatchContext::AutoAncestorPusherinsertionPointPusher(aState.mTreeMatchContext);if(adcp.IsEmpty()&&parent&&nsContentUtils::IsContentInsertionPoint(parent)){if(aState.mTreeMatchContext.mAncestorFilter.HasFilter()){insertionPointPusher.PushAncestorAndStyleScope(parent);}else{insertionPointPusher.PushStyleScope(parent);}}// Push the content as a style ancestor now, so we don't have to do// it in our various full-constructor functions. In particular,// since a number of full-constructor functions don't actually call// ProcessChildren in some cases (e.g. for CSS anonymous table boxes// or for situations where only anonymouse children are having// frames constructed), this is the best place to bottleneck the// pushing of the content instead of having to do it in multiple// places.TreeMatchContext::AutoAncestorPusherancestorPusher(aState.mTreeMatchContext);if(aState.mTreeMatchContext.mAncestorFilter.HasFilter()){ancestorPusher.PushAncestorAndStyleScope(content);}else{ancestorPusher.PushStyleScope(content);}nsIFrame*newFrame;nsIFrame*primaryFrame;nsStyleContext*conststyleContext=aItem.mStyleContext;constnsStyleDisplay*display=styleContext->StyleDisplay();if(bits&FCDATA_FUNC_IS_FULL_CTOR){newFrame=(this->*(data->mFullConstructor))(aState,aItem,aParentFrame,display,aFrameItems);MOZ_ASSERT(newFrame,"Full constructor failed");primaryFrame=newFrame;}else{newFrame=(*data->mFunc.mCreationFunc)(mPresShell,styleContext);boolallowOutOfFlow=!(bits&FCDATA_DISALLOW_OUT_OF_FLOW);boolisPopup=aItem.mIsPopup;NS_ASSERTION(!isPopup||(aState.mPopupItems.containingBlock&&aState.mPopupItems.containingBlock->GetType()==nsGkAtoms::popupSetFrame),"Should have a containing block here!");nsContainerFrame*geometricParent=isPopup?aState.mPopupItems.containingBlock:(allowOutOfFlow?aState.GetGeometricParent(display,aParentFrame):aParentFrame);// Must init frameToAddToList to null, since it's inoutnsIFrame*frameToAddToList=nullptr;if((bits&FCDATA_MAY_NEED_SCROLLFRAME)&&display->IsScrollableOverflow()){nsContainerFrame*scrollframe=nullptr;BuildScrollFrame(aState,content,styleContext,newFrame,geometricParent,scrollframe);frameToAddToList=scrollframe;}else{InitAndRestoreFrame(aState,content,geometricParent,newFrame);// See whether we need to create a viewnsContainerFrame::CreateViewForFrame(newFrame,false);frameToAddToList=newFrame;}// Use frameToAddToList as the primary frame. In the non-scrollframe case// they're equal, but in the scrollframe case newFrame is the scrolled// frame, while frameToAddToList is the scrollframe (and should be the// primary frame).primaryFrame=frameToAddToList;// If we need to create a block formatting context to wrap our// kids, do it now.constnsStyleDisplay*maybeAbsoluteContainingBlockDisplay=display;nsIFrame*maybeAbsoluteContainingBlockStyleFrame=primaryFrame;nsIFrame*maybeAbsoluteContainingBlock=newFrame;nsIFrame*possiblyLeafFrame=newFrame;if(bits&FCDATA_CREATE_BLOCK_WRAPPER_FOR_ALL_KIDS){nsRefPtr<nsStyleContext>blockContext;blockContext=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(*data->mAnonBoxPseudo,styleContext);nsIFrame*blockFrame=NS_NewBlockFormattingContext(mPresShell,blockContext);#ifdef DEBUGnsContainerFrame*containerFrame=do_QueryFrame(newFrame);MOZ_ASSERT(containerFrame);#endifnsContainerFrame*container=static_cast<nsContainerFrame*>(newFrame);InitAndRestoreFrame(aState,content,container,blockFrame);SetInitialSingleChild(container,blockFrame);// Now figure out whether newFrame or blockFrame should be the// absolute container. It should be the latter if it's// positioned, otherwise the former.constnsStyleDisplay*blockDisplay=blockContext->StyleDisplay();if(blockDisplay->IsAbsPosContainingBlock(blockFrame)){maybeAbsoluteContainingBlockDisplay=blockDisplay;maybeAbsoluteContainingBlock=blockFrame;maybeAbsoluteContainingBlockStyleFrame=blockFrame;}// Our kids should go into the blockFramenewFrame=blockFrame;}aState.AddChild(frameToAddToList,aFrameItems,content,styleContext,aParentFrame,allowOutOfFlow,allowOutOfFlow,isPopup);nsContainerFrame*newFrameAsContainer=do_QueryFrame(newFrame);if(newFrameAsContainer){#ifdef MOZ_XUL// Icky XUL stuff, sadlyif(aItem.mIsRootPopupgroup){NS_ASSERTION(nsIRootBox::GetRootBox(mPresShell)&&nsIRootBox::GetRootBox(mPresShell)->GetPopupSetFrame()==newFrame,"Unexpected PopupSetFrame");aState.mPopupItems.containingBlock=newFrameAsContainer;aState.mHavePendingPopupgroup=false;}#endif /* MOZ_XUL */// Process the child content if requestednsFrameItemschildItems;nsFrameConstructorSaveStateabsoluteSaveState;if(bits&FCDATA_FORCE_NULL_ABSPOS_CONTAINER){aState.PushAbsoluteContainingBlock(nullptr,nullptr,absoluteSaveState);}elseif(!(bits&FCDATA_SKIP_ABSPOS_PUSH)){maybeAbsoluteContainingBlock->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);// This check is identical to nsStyleDisplay::IsAbsPosContainingBlock// except without the assertion that the style display and frame match.// When constructing scroll frames we intentionally use the style// display for the outer, but make the inner the containing block.if((maybeAbsoluteContainingBlockDisplay->IsAbsolutelyPositionedStyle()||maybeAbsoluteContainingBlockDisplay->IsRelativelyPositionedStyle()||maybeAbsoluteContainingBlockDisplay->IsFixedPosContainingBlock(maybeAbsoluteContainingBlockStyleFrame))&&!maybeAbsoluteContainingBlockStyleFrame->IsSVGText()){nsContainerFrame*cf=static_cast<nsContainerFrame*>(maybeAbsoluteContainingBlock);aState.PushAbsoluteContainingBlock(cf,cf,absoluteSaveState);}}if(!aItem.mAnonChildren.IsEmpty()){NS_ASSERTION(!(bits&FCDATA_USE_CHILD_ITEMS),"We should not have both anonymous and non-anonymous ""children in a given FrameConstructorItem");AddFCItemsForAnonymousContent(aState,newFrameAsContainer,aItem.mAnonChildren,aItem.mChildItems);bits|=FCDATA_USE_CHILD_ITEMS;}if(bits&FCDATA_USE_CHILD_ITEMS){nsFrameConstructorSaveStatefloatSaveState;if(ShouldSuppressFloatingOfDescendants(newFrame)){aState.PushFloatContainingBlock(nullptr,floatSaveState);}elseif(newFrame->IsFloatContainingBlock()){aState.PushFloatContainingBlock(newFrameAsContainer,floatSaveState);}ConstructFramesFromItemList(aState,aItem.mChildItems,newFrameAsContainer,childItems);}else{// Process the child frames.ProcessChildren(aState,content,styleContext,newFrameAsContainer,!(bits&FCDATA_DISALLOW_GENERATED_CONTENT),childItems,(bits&FCDATA_ALLOW_BLOCK_STYLES)!=0,aItem.mPendingBinding,possiblyLeafFrame);}if(bits&FCDATA_WRAP_KIDS_IN_BLOCKS){nsFrameItemsnewItems;nsFrameItemscurrentBlockItems;nsIFrame*f;while((f=childItems.FirstChild())!=nullptr){boolwrapFrame=IsInlineFrame(f)||IsFramePartOfIBSplit(f);if(!wrapFrame){FlushAccumulatedBlock(aState,content,newFrameAsContainer,currentBlockItems,newItems);}childItems.RemoveFrame(f);if(wrapFrame){currentBlockItems.AddChild(f);}else{newItems.AddChild(f);}}FlushAccumulatedBlock(aState,content,newFrameAsContainer,currentBlockItems,newItems);if(childItems.NotEmpty()){// an error must have occurred, delete unprocessed frameschildItems.DestroyFrames();}childItems=newItems;}// Set the frame's initial child list// Note that MathML depends on this being called even if// childItems is empty!newFrameAsContainer->SetInitialChildList(kPrincipalList,childItems);}}#ifdef MOZ_XUL// More icky XUL stuffif(aItem.mNameSpaceID==kNameSpaceID_XUL&&(aItem.mTag==nsGkAtoms::treechildren||// trees always need titletipscontent->HasAttr(kNameSpaceID_None,nsGkAtoms::tooltiptext)||content->HasAttr(kNameSpaceID_None,nsGkAtoms::tooltip))){nsIRootBox*rootBox=nsIRootBox::GetRootBox(mPresShell);if(rootBox){rootBox->AddTooltipSupport(content);}}#endifNS_ASSERTION(newFrame->IsFrameOfType(nsIFrame::eLineParticipant)==((bits&FCDATA_IS_LINE_PARTICIPANT)!=0),"Incorrectly set FCDATA_IS_LINE_PARTICIPANT bits");if(aItem.mIsAnonymousContentCreatorContent){primaryFrame->AddStateBits(NS_FRAME_ANONYMOUSCONTENTCREATOR_CONTENT);}// Even if mCreatingExtraFrames is set, we may need to SetPrimaryFrame for// generated content that doesn't have one yet. Note that we have to examine// the frame bit, because by this point mIsGeneratedContent has been cleared// on aItem.if((!aState.mCreatingExtraFrames||((primaryFrame->GetStateBits()&NS_FRAME_GENERATED_CONTENT)&&!aItem.mContent->GetPrimaryFrame()))&&!(bits&FCDATA_SKIP_FRAMESET)){aItem.mContent->SetPrimaryFrame(primaryFrame);ActiveLayerTracker::TransferActivityToFrame(aItem.mContent,primaryFrame);}}// after the node has been constructed and initialized create any// anonymous content a node needs.nsresultnsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState&aState,nsIContent*aParent,nsContainerFrame*aParentFrame,PendingBinding*aPendingBinding,nsFrameItems&aChildItems){nsAutoTArray<nsIAnonymousContentCreator::ContentInfo,4>newAnonymousItems;nsresultrv=GetAnonymousContent(aParent,aParentFrame,newAnonymousItems);NS_ENSURE_SUCCESS(rv,rv);uint32_tcount=newAnonymousItems.Length();if(count==0){returnNS_OK;}nsFrameConstructorState::PendingBindingAutoPusherpusher(aState,aPendingBinding);TreeMatchContext::AutoAncestorPusherancestorPusher(aState.mTreeMatchContext);if(aState.mTreeMatchContext.mAncestorFilter.HasFilter()){ancestorPusher.PushAncestorAndStyleScope(aParent->AsElement());}else{ancestorPusher.PushStyleScope(aParent->AsElement());}nsIAnonymousContentCreator*creator=do_QueryFrame(aParentFrame);NS_ASSERTION(creator,"How can that happen if we have nodes to construct frames for?");InsertionPointinsertion(aParentFrame,aParent);for(uint32_ti=0;i<count;i++){nsIContent*content=newAnonymousItems[i].mContent;NS_ASSERTION(content,"null anonymous content?");NS_ASSERTION(!newAnonymousItems[i].mStyleContext,"Unexpected style context");NS_ASSERTION(newAnonymousItems[i].mChildren.IsEmpty(),"This method is not currently used with frames that implement ""nsIAnonymousContentCreator::CreateAnonymousContent to ""output a list where the items have their own children");nsIFrame*newFrame=creator->CreateFrameFor(content);if(newFrame){NS_ASSERTION(content->GetPrimaryFrame(),"Content must have a primary frame now");newFrame->AddStateBits(NS_FRAME_ANONYMOUSCONTENTCREATOR_CONTENT);aChildItems.AddChild(newFrame);}else{FrameConstructionItemListitems;{// Skip parent display based style-fixup during our // AddFrameConstructionItems() call:TreeMatchContext::AutoParentDisplayBasedStyleFixupSkipperparentDisplayBasedStyleFixupSkipper(aState.mTreeMatchContext);AddFrameConstructionItems(aState,content,true,insertion,items);}ConstructFramesFromItemList(aState,items,aParentFrame,aChildItems);}}returnNS_OK;}staticvoidSetFlagsOnSubtree(nsIContent*aNode,uintptr_taFlagsToSet){#ifdef DEBUG// Make sure that the node passed to us doesn't have any XBL children{FlattenedChildIteratoriter(aNode);NS_ASSERTION(!iter.XBLInvolved()||!iter.GetNextChild(),"The node should not have any XBL children");}#endif// Set the flag on the node itselfaNode->SetFlags(aFlagsToSet);// Set the flag on all of its children recursivelyuint32_tcount;nsIContent*const*children=aNode->GetChildArray(&count);for(uint32_tindex=0;index<count;++index){SetFlagsOnSubtree(children[index],aFlagsToSet);}}/** * This function takes a tree of nsIAnonymousContentCreator::ContentInfo * objects where the nsIContent nodes have just been created, and appends the * nsIContent children in the tree to their parent. The leaf nsIContent objects * are appended first to minimize the number of notifications that are sent * out (i.e. by appending as many descendants as posible while their parent is * not yet in the document tree). * * This function is used simply as a convenience so that implementations of * nsIAnonymousContentCreator::CreateAnonymousContent don't all have to have * their own code to connect the elements that they create. */staticvoidConnectAnonymousTreeDescendants(nsIContent*aParent,nsTArray<nsIAnonymousContentCreator::ContentInfo>&aContent){uint32_tcount=aContent.Length();for(uint32_ti=0;i<count;i++){nsIContent*content=aContent[i].mContent;NS_ASSERTION(content,"null anonymous content?");ConnectAnonymousTreeDescendants(content,aContent[i].mChildren);aParent->AppendChildTo(content,false);}}nsresultnsCSSFrameConstructor::GetAnonymousContent(nsIContent*aParent,nsIFrame*aParentFrame,nsTArray<nsIAnonymousContentCreator::ContentInfo>&aContent){nsIAnonymousContentCreator*creator=do_QueryFrame(aParentFrame);if(!creator)returnNS_OK;nsresultrv=creator->CreateAnonymousContent(aContent);NS_ENSURE_SUCCESS(rv,rv);uint32_tcount=aContent.Length();for(uint32_ti=0;i<count;i++){// get our child's content and set its parent to our contentnsIContent*content=aContent[i].mContent;NS_ASSERTION(content,"null anonymous content?");// least-surprise CSS binding until we do the SVG specified// cascading rules for <svg:use> - bug 265894if(aParentFrame->GetType()==nsGkAtoms::svgUseFrame){content->SetFlags(NODE_IS_ANONYMOUS_ROOT);}else{content->SetIsNativeAnonymousRoot();}ConnectAnonymousTreeDescendants(content,aContent[i].mChildren);boolanonContentIsEditable=content->HasFlag(NODE_IS_EDITABLE);// If the parent is in a shadow tree, make sure we don't// bind with a document because shadow roots and its descendants// are not in document.nsIDocument*bindDocument=aParent->HasFlag(NODE_IS_IN_SHADOW_TREE)?nullptr:mDocument;rv=content->BindToTree(bindDocument,aParent,aParent,true);// If the anonymous content creator requested that the content should be// editable, honor its request.// We need to set the flag on the whole subtree, because existing// children's flags have already been set as part of the BindToTree operation.if(anonContentIsEditable){NS_ASSERTION(aParentFrame->GetType()==nsGkAtoms::textInputFrame,"We only expect this for anonymous content under a text control frame");SetFlagsOnSubtree(content,NODE_IS_EDITABLE);}if(NS_FAILED(rv)){content->UnbindFromTree();returnrv;}}returnNS_OK;}staticboolIsXULDisplayType(constnsStyleDisplay*aDisplay){return(aDisplay->mDisplay==NS_STYLE_DISPLAY_INLINE_BOX||#ifdef MOZ_XULaDisplay->mDisplay==NS_STYLE_DISPLAY_INLINE_XUL_GRID||aDisplay->mDisplay==NS_STYLE_DISPLAY_INLINE_STACK||#endifaDisplay->mDisplay==NS_STYLE_DISPLAY_BOX#ifdef MOZ_XUL||aDisplay->mDisplay==NS_STYLE_DISPLAY_XUL_GRID||aDisplay->mDisplay==NS_STYLE_DISPLAY_STACK||aDisplay->mDisplay==NS_STYLE_DISPLAY_XUL_GRID_GROUP||aDisplay->mDisplay==NS_STYLE_DISPLAY_XUL_GRID_LINE||aDisplay->mDisplay==NS_STYLE_DISPLAY_DECK||aDisplay->mDisplay==NS_STYLE_DISPLAY_POPUP||aDisplay->mDisplay==NS_STYLE_DISPLAY_GROUPBOX#endif);}// XUL frames are not allowed to be out of flow.#define SIMPLE_XUL_FCDATA(_func) \ FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | FCDATA_SKIP_ABSPOS_PUSH, \ _func)#define SCROLLABLE_XUL_FCDATA(_func) \ FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | FCDATA_SKIP_ABSPOS_PUSH | \ FCDATA_MAY_NEED_SCROLLFRAME, _func)// .. but we allow some XUL frames to be _containers_ for out-of-flow content// (This is the same as SCROLLABLE_XUL_FCDATA, but w/o FCDATA_SKIP_ABSPOS_PUSH)#define SCROLLABLE_ABSPOS_CONTAINER_XUL_FCDATA(_func) \ FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | \ FCDATA_MAY_NEED_SCROLLFRAME, _func)#define SIMPLE_XUL_CREATE(_tag, _func) \ { &nsGkAtoms::_tag, SIMPLE_XUL_FCDATA(_func) }#define SCROLLABLE_XUL_CREATE(_tag, _func) \ { &nsGkAtoms::_tag, SCROLLABLE_XUL_FCDATA(_func) }#define SIMPLE_XUL_INT_CREATE(_int, _func) \ { _int, SIMPLE_XUL_FCDATA(_func) }#define SCROLLABLE_XUL_INT_CREATE(_int, _func) \ { _int, SCROLLABLE_XUL_FCDATA(_func) }#define SCROLLABLE_ABSPOS_CONTAINER_XUL_INT_CREATE(_int, _func) \ { _int, SCROLLABLE_ABSPOS_CONTAINER_XUL_FCDATA(_func) }staticnsIFrame*NS_NewGridBoxFrame(nsIPresShell*aPresShell,nsStyleContext*aStyleContext){nsCOMPtr<nsBoxLayout>layout;NS_NewGridLayout2(aPresShell,getter_AddRefs(layout));returnNS_NewBoxFrame(aPresShell,aStyleContext,false,layout);}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULTagData(Element*aElement,nsIAtom*aTag,int32_taNameSpaceID,nsStyleContext*aStyleContext){if(aNameSpaceID!=kNameSpaceID_XUL){returnnullptr;}staticconstFrameConstructionDataByTagsXULTagData[]={#ifdef MOZ_XULSCROLLABLE_XUL_CREATE(button,NS_NewButtonBoxFrame),SCROLLABLE_XUL_CREATE(checkbox,NS_NewButtonBoxFrame),SCROLLABLE_XUL_CREATE(radio,NS_NewButtonBoxFrame),SCROLLABLE_XUL_CREATE(autorepeatbutton,NS_NewAutoRepeatBoxFrame),SCROLLABLE_XUL_CREATE(titlebar,NS_NewTitleBarFrame),SCROLLABLE_XUL_CREATE(resizer,NS_NewResizerFrame),SIMPLE_XUL_CREATE(image,NS_NewImageBoxFrame),SIMPLE_XUL_CREATE(spring,NS_NewLeafBoxFrame),SIMPLE_XUL_CREATE(spacer,NS_NewLeafBoxFrame),SIMPLE_XUL_CREATE(treechildren,NS_NewTreeBodyFrame),SIMPLE_XUL_CREATE(treecol,NS_NewTreeColFrame),SIMPLE_XUL_CREATE(text,NS_NewTextBoxFrame),SIMPLE_TAG_CHAIN(label,nsCSSFrameConstructor::FindXULLabelData),SIMPLE_TAG_CHAIN(description,nsCSSFrameConstructor::FindXULDescriptionData),SIMPLE_XUL_CREATE(menu,NS_NewMenuFrame),SIMPLE_XUL_CREATE(menubutton,NS_NewMenuFrame),SIMPLE_XUL_CREATE(menuitem,NS_NewMenuItemFrame),#ifdef XP_MACOSXSIMPLE_TAG_CHAIN(menubar,nsCSSFrameConstructor::FindXULMenubarData),#elseSIMPLE_XUL_CREATE(menubar,NS_NewMenuBarFrame),#endif /* XP_MACOSX */SIMPLE_TAG_CHAIN(popupgroup,nsCSSFrameConstructor::FindPopupGroupData),SIMPLE_XUL_CREATE(iframe,NS_NewSubDocumentFrame),SIMPLE_XUL_CREATE(editor,NS_NewSubDocumentFrame),SIMPLE_XUL_CREATE(browser,NS_NewSubDocumentFrame),SIMPLE_XUL_CREATE(progressmeter,NS_NewProgressMeterFrame),SIMPLE_XUL_CREATE(splitter,NS_NewSplitterFrame),SIMPLE_TAG_CHAIN(listboxbody,nsCSSFrameConstructor::FindXULListBoxBodyData),SIMPLE_TAG_CHAIN(listitem,nsCSSFrameConstructor::FindXULListItemData),#endif /* MOZ_XUL */SIMPLE_XUL_CREATE(slider,NS_NewSliderFrame),SIMPLE_XUL_CREATE(scrollbar,NS_NewScrollbarFrame),SIMPLE_XUL_CREATE(scrollbarbutton,NS_NewScrollbarButtonFrame)};returnFindDataByTag(aTag,aElement,aStyleContext,sXULTagData,ArrayLength(sXULTagData));}#ifdef MOZ_XUL/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindPopupGroupData(Element*aElement,nsStyleContext*/* unused */){if(!aElement->IsRootOfNativeAnonymousSubtree()){returnnullptr;}staticconstFrameConstructionDatasPopupSetData=SIMPLE_XUL_FCDATA(NS_NewPopupSetFrame);return&sPopupSetData;}/* static */constnsCSSFrameConstructor::FrameConstructionDatansCSSFrameConstructor::sXULTextBoxData=SIMPLE_XUL_FCDATA(NS_NewTextBoxFrame);/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULLabelData(Element*aElement,nsStyleContext*/* unused */){if(aElement->HasAttr(kNameSpaceID_None,nsGkAtoms::value)){return&sXULTextBoxData;}staticconstFrameConstructionDatasLabelData=SIMPLE_XUL_FCDATA(NS_NewXULLabelFrame);return&sLabelData;}staticnsIFrame*NS_NewXULDescriptionFrame(nsIPresShell*aPresShell,nsStyleContext*aContext){// XXXbz do we really need to set those flags? If the parent is not// a block we'll get them anyway, and if it is, do we want them?returnNS_NewBlockFrame(aPresShell,aContext,NS_BLOCK_FLOAT_MGR|NS_BLOCK_MARGIN_ROOT);}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULDescriptionData(Element*aElement,nsStyleContext*/* unused */){if(aElement->HasAttr(kNameSpaceID_None,nsGkAtoms::value)){return&sXULTextBoxData;}staticconstFrameConstructionDatasDescriptionData=SIMPLE_XUL_FCDATA(NS_NewXULDescriptionFrame);return&sDescriptionData;}#ifdef XP_MACOSX/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULMenubarData(Element*aElement,nsStyleContext*aStyleContext){nsCOMPtr<nsIDocShell>treeItem=aStyleContext->PresContext()->GetDocShell();if(treeItem&&nsIDocShellTreeItem::typeChrome==treeItem->ItemType()){nsCOMPtr<nsIDocShellTreeItem>parent;treeItem->GetParent(getter_AddRefs(parent));if(!parent){// This is the root. Suppress the menubar, since on Mac// window menus are not attached to the window.staticconstFrameConstructionDatasSuppressData=SUPPRESS_FCDATA();return&sSuppressData;}}staticconstFrameConstructionDatasMenubarData=SIMPLE_XUL_FCDATA(NS_NewMenuBarFrame);return&sMenubarData;}#endif /* XP_MACOSX *//* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULListBoxBodyData(Element*aElement,nsStyleContext*aStyleContext){if(aStyleContext->StyleDisplay()->mDisplay!=NS_STYLE_DISPLAY_XUL_GRID_GROUP){returnnullptr;}staticconstFrameConstructionDatasListBoxBodyData=SCROLLABLE_XUL_FCDATA(NS_NewListBoxBodyFrame);return&sListBoxBodyData;}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULListItemData(Element*aElement,nsStyleContext*aStyleContext){if(aStyleContext->StyleDisplay()->mDisplay!=NS_STYLE_DISPLAY_XUL_GRID_LINE){returnnullptr;}staticconstFrameConstructionDatasListItemData=SCROLLABLE_XUL_FCDATA(NS_NewListItemFrame);return&sListItemData;}#endif /* MOZ_XUL *//* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindXULDisplayData(constnsStyleDisplay*aDisplay,Element*aElement,nsStyleContext*aStyleContext){staticconstFrameConstructionDataByIntsXULDisplayData[]={SCROLLABLE_ABSPOS_CONTAINER_XUL_INT_CREATE(NS_STYLE_DISPLAY_INLINE_BOX,NS_NewBoxFrame),SCROLLABLE_ABSPOS_CONTAINER_XUL_INT_CREATE(NS_STYLE_DISPLAY_BOX,NS_NewBoxFrame),#ifdef MOZ_XULSCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_INLINE_XUL_GRID,NS_NewGridBoxFrame),SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_XUL_GRID,NS_NewGridBoxFrame),SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_XUL_GRID_GROUP,NS_NewGridRowGroupFrame),SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_XUL_GRID_LINE,NS_NewGridRowLeafFrame),SIMPLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_DECK,NS_NewDeckFrame),SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_GROUPBOX,NS_NewGroupBoxFrame),SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_INLINE_STACK,NS_NewStackFrame),SCROLLABLE_XUL_INT_CREATE(NS_STYLE_DISPLAY_STACK,NS_NewStackFrame),{NS_STYLE_DISPLAY_POPUP,FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW|FCDATA_IS_POPUP|FCDATA_SKIP_ABSPOS_PUSH,NS_NewMenuPopupFrame)}#endif /* MOZ_XUL */};// Processing by display here:returnFindDataByInt(aDisplay->mDisplay,aElement,aStyleContext,sXULDisplayData,ArrayLength(sXULDisplayData));}already_AddRefed<nsStyleContext>nsCSSFrameConstructor::BeginBuildingScrollFrame(nsFrameConstructorState&aState,nsIContent*aContent,nsStyleContext*aContentStyle,nsContainerFrame*aParentFrame,nsIAtom*aScrolledPseudo,boolaIsRoot,nsContainerFrame*&aNewFrame){nsContainerFrame*gfxScrollFrame=aNewFrame;nsFrameItemsanonymousItems;nsRefPtr<nsStyleContext>contentStyle=aContentStyle;if(!gfxScrollFrame){// Build a XULScrollFrame when the child is a box, otherwise an// HTMLScrollFrame// XXXbz this is the lone remaining consumer of IsXULDisplayType.// I wonder whether we can eliminate that somehow.constnsStyleDisplay*displayStyle=aContentStyle->StyleDisplay();if(IsXULDisplayType(displayStyle)){gfxScrollFrame=NS_NewXULScrollFrame(mPresShell,contentStyle,aIsRoot,displayStyle->mDisplay==NS_STYLE_DISPLAY_STACK||displayStyle->mDisplay==NS_STYLE_DISPLAY_INLINE_STACK);}else{gfxScrollFrame=NS_NewHTMLScrollFrame(mPresShell,contentStyle,aIsRoot);}InitAndRestoreFrame(aState,aContent,aParentFrame,gfxScrollFrame);}// if there are any anonymous children for the scroll frame, create// frames for them.// Pass a null pending binding: we don't care how constructors for any of// this anonymous content order with anything else. It's never been// consistent anyway.CreateAnonymousFrames(aState,aContent,gfxScrollFrame,nullptr,anonymousItems);aNewFrame=gfxScrollFrame;// we used the style that was passed in. So resolve another one.nsStyleSet*styleSet=mPresShell->StyleSet();nsRefPtr<nsStyleContext>scrolledChildStyle=styleSet->ResolveAnonymousBoxStyle(aScrolledPseudo,contentStyle);if(gfxScrollFrame){gfxScrollFrame->SetInitialChildList(kPrincipalList,anonymousItems);}returnscrolledChildStyle.forget();}voidnsCSSFrameConstructor::FinishBuildingScrollFrame(nsContainerFrame*aScrollFrame,nsIFrame*aScrolledFrame){nsFrameListscrolled(aScrolledFrame,aScrolledFrame);aScrollFrame->AppendFrames(kPrincipalList,scrolled);}/** * Called to wrap a gfx scrollframe around a frame. The hierarchy will look like this * * ------- for gfx scrollbars ------ * * * ScrollFrame * ^ * | * Frame (scrolled frame you passed in) * * *----------------------------------- * LEGEND: * * ScrollFrame: This is a frame that manages gfx cross platform frame based scrollbars. * * @param aContent the content node of the child to wrap. * @param aScrolledFrame The frame of the content to wrap. This should not be * Initialized. This method will initialize it with a scrolled pseudo * and no nsIContent. The content will be attached to the scrollframe * returned. * @param aContentStyle the style context that has already been resolved for the content being passed in. * * @param aParentFrame The parent to attach the scroll frame to * * @param aNewFrame The new scrollframe or gfx scrollframe that we create. It will contain the * scrolled frame you passed in. (returned) * If this is not null, we'll just use it * @param aScrolledContentStyle the style that was resolved for the scrolled frame. (returned) */voidnsCSSFrameConstructor::BuildScrollFrame(nsFrameConstructorState&aState,nsIContent*aContent,nsStyleContext*aContentStyle,nsIFrame*aScrolledFrame,nsContainerFrame*aParentFrame,nsContainerFrame*&aNewFrame){nsRefPtr<nsStyleContext>scrolledContentStyle=BeginBuildingScrollFrame(aState,aContent,aContentStyle,aParentFrame,nsCSSAnonBoxes::scrolledContent,false,aNewFrame);aScrolledFrame->SetStyleContextWithoutNotification(scrolledContentStyle);InitAndRestoreFrame(aState,aContent,aNewFrame,aScrolledFrame);FinishBuildingScrollFrame(aNewFrame,aScrolledFrame);}constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindDisplayData(constnsStyleDisplay*aDisplay,Element*aElement,nsIFrame*aParentFrame,nsStyleContext*aStyleContext){PR_STATIC_ASSERT(eParentTypeCount<(1<<(32-FCDATA_PARENT_TYPE_OFFSET)));// The style system ensures that floated and positioned frames are// block-level.NS_ASSERTION(!(aDisplay->IsFloatingStyle()||aDisplay->IsAbsolutelyPositionedStyle())||aDisplay->IsBlockOutsideStyle()||aDisplay->mDisplay==NS_STYLE_DISPLAY_CONTENTS,"Style system did not apply CSS2.1 section 9.7 fixups");// If this is "body", try propagating its scroll style to the viewport// Note that we need to do this even if the body is NOT scrollable;// it might have dynamically changed from scrollable to not scrollable,// and that might need to be propagated.// XXXbz is this the right place to do this? If this code moves,// make this function static.boolpropagatedScrollToViewport=false;if(aElement->IsHTMLElement(nsGkAtoms::body)){propagatedScrollToViewport=PropagateScrollToViewport()==aElement;}NS_ASSERTION(!propagatedScrollToViewport||!mPresShell->GetPresContext()->IsPaginated(),"Shouldn't propagate scroll in paginated contexts");if(aDisplay->IsBlockInsideStyle()){// If the frame is a block-level frame and is scrollable, then wrap it in a// scroll frame. Except we don't want to do that for paginated contexts for// frames that are block-outside and aren't frames for native anonymous stuff.// XXX Ignore tables for the time being (except caption)constuint32_tkCaptionCtorFlags=FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeTable);boolcaption=aDisplay->mDisplay==NS_STYLE_DISPLAY_TABLE_CAPTION;boolsuppressScrollFrame=false;boolneedScrollFrame=aDisplay->IsScrollableOverflow()&&!propagatedScrollToViewport;if(needScrollFrame){suppressScrollFrame=mPresShell->GetPresContext()->IsPaginated()&&aDisplay->IsBlockOutsideStyle()&&!aElement->IsInNativeAnonymousSubtree();if(!suppressScrollFrame){staticconstFrameConstructionDatasScrollableBlockData[2]={FULL_CTOR_FCDATA(0,&nsCSSFrameConstructor::ConstructScrollableBlock),FULL_CTOR_FCDATA(kCaptionCtorFlags,&nsCSSFrameConstructor::ConstructScrollableBlock)};return&sScrollableBlockData[caption];}}// Handle various non-scrollable blocks.staticconstFrameConstructionDatasNonScrollableBlockData[2][2]={{FULL_CTOR_FCDATA(0,&nsCSSFrameConstructor::ConstructNonScrollableBlock),FULL_CTOR_FCDATA(kCaptionCtorFlags,&nsCSSFrameConstructor::ConstructNonScrollableBlock)},{FULL_CTOR_FCDATA(FCDATA_FORCED_NON_SCROLLABLE_BLOCK,&nsCSSFrameConstructor::ConstructNonScrollableBlock),FULL_CTOR_FCDATA(FCDATA_FORCED_NON_SCROLLABLE_BLOCK|kCaptionCtorFlags,&nsCSSFrameConstructor::ConstructNonScrollableBlock)}};return&sNonScrollableBlockData[suppressScrollFrame][caption];}// If this is for a <body> node and we've propagated the scroll-frame to the// viewport, we need to make sure not to add another layer of scrollbars, so// we use a different FCData struct without FCDATA_MAY_NEED_SCROLLFRAME.if(propagatedScrollToViewport&&aDisplay->IsScrollableOverflow()){if(aDisplay->mDisplay==NS_STYLE_DISPLAY_FLEX){staticconstFrameConstructionDatasNonScrollableFlexData=FCDATA_DECL(0,NS_NewFlexContainerFrame);return&sNonScrollableFlexData;}if(aDisplay->mDisplay==NS_STYLE_DISPLAY_GRID){staticconstFrameConstructionDatasNonScrollableGridData=FCDATA_DECL(0,NS_NewGridContainerFrame);return&sNonScrollableGridData;}}staticconstFrameConstructionDataByIntsDisplayData[]={// To keep the hash table small don't add inline frames (they're// typically things like FONT and B), because we can quickly// find them if we need to.// XXXbz the "quickly" part is a bald-faced lie!{NS_STYLE_DISPLAY_INLINE,FULL_CTOR_FCDATA(FCDATA_IS_INLINE|FCDATA_IS_LINE_PARTICIPANT,&nsCSSFrameConstructor::ConstructInline)},{NS_STYLE_DISPLAY_FLEX,FCDATA_DECL(FCDATA_MAY_NEED_SCROLLFRAME,NS_NewFlexContainerFrame)},{NS_STYLE_DISPLAY_INLINE_FLEX,FCDATA_DECL(FCDATA_MAY_NEED_SCROLLFRAME,NS_NewFlexContainerFrame)},{NS_STYLE_DISPLAY_GRID,FCDATA_DECL(FCDATA_MAY_NEED_SCROLLFRAME,NS_NewGridContainerFrame)},{NS_STYLE_DISPLAY_INLINE_GRID,FCDATA_DECL(FCDATA_MAY_NEED_SCROLLFRAME,NS_NewGridContainerFrame)},{NS_STYLE_DISPLAY_RUBY,FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT,NS_NewRubyFrame)},{NS_STYLE_DISPLAY_RUBY_BASE,FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeRubyBaseContainer),NS_NewRubyBaseFrame)},{NS_STYLE_DISPLAY_RUBY_BASE_CONTAINER,FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeRuby),NS_NewRubyBaseContainerFrame)},{NS_STYLE_DISPLAY_RUBY_TEXT,FCDATA_DECL(FCDATA_IS_LINE_PARTICIPANT|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeRubyTextContainer),NS_NewRubyTextFrame)},{NS_STYLE_DISPLAY_RUBY_TEXT_CONTAINER,FCDATA_DECL(FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeRuby),NS_NewRubyTextContainerFrame)},{NS_STYLE_DISPLAY_TABLE,FULL_CTOR_FCDATA(0,&nsCSSFrameConstructor::ConstructTable)},{NS_STYLE_DISPLAY_INLINE_TABLE,FULL_CTOR_FCDATA(0,&nsCSSFrameConstructor::ConstructTable)},// NOTE: In the unlikely event that we add another table-part here that has// a desired-parent-type (& hence triggers table fixup), we'll need to also// update the flexbox chunk in nsStyleContext::ApplyStyleFixups().{NS_STYLE_DISPLAY_TABLE_ROW_GROUP,FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeTable),&nsCSSFrameConstructor::ConstructTableRowOrRowGroup)},{NS_STYLE_DISPLAY_TABLE_HEADER_GROUP,FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeTable),&nsCSSFrameConstructor::ConstructTableRowOrRowGroup)},{NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP,FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeTable),&nsCSSFrameConstructor::ConstructTableRowOrRowGroup)},{NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP,FCDATA_DECL(FCDATA_IS_TABLE_PART|FCDATA_DISALLOW_OUT_OF_FLOW|FCDATA_SKIP_ABSPOS_PUSH|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeTable),NS_NewTableColGroupFrame)},{NS_STYLE_DISPLAY_TABLE_COLUMN,FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeColGroup),&nsCSSFrameConstructor::ConstructTableCol)},{NS_STYLE_DISPLAY_TABLE_ROW,FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeRowGroup),&nsCSSFrameConstructor::ConstructTableRowOrRowGroup)},{NS_STYLE_DISPLAY_TABLE_CELL,FULL_CTOR_FCDATA(FCDATA_IS_TABLE_PART|FCDATA_DESIRED_PARENT_TYPE_TO_BITS(eTypeRow),&nsCSSFrameConstructor::ConstructTableCell)},{NS_STYLE_DISPLAY_CONTENTS,FULL_CTOR_FCDATA(FCDATA_IS_CONTENTS,nullptr/*never called*/)}};// See the mDisplay fixup code in nsRuleNode::ComputeDisplayData.MOZ_ASSERT(aDisplay->mDisplay!=NS_STYLE_DISPLAY_CONTENTS||!aElement->IsRootOfNativeAnonymousSubtree(),"display:contents on anonymous content is unsupported");returnFindDataByInt(aDisplay->mDisplay,aElement,aStyleContext,sDisplayData,ArrayLength(sDisplayData));}nsIFrame*nsCSSFrameConstructor::ConstructScrollableBlock(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;nsContainerFrame*newFrame=nullptr;nsRefPtr<nsStyleContext>scrolledContentStyle=BeginBuildingScrollFrame(aState,content,styleContext,aState.GetGeometricParent(aDisplay,aParentFrame),nsCSSAnonBoxes::scrolledContent,false,newFrame);// Create our block frame// pass a temporary stylecontext, the correct one will be set laternsContainerFrame*scrolledFrame=NS_NewBlockFormattingContext(mPresShell,styleContext);// Make sure to AddChild before we call ConstructBlock so that we// end up before our descendants in fixed-pos lists as needed.aState.AddChild(newFrame,aFrameItems,content,styleContext,aParentFrame);nsFrameItemsblockItem;ConstructBlock(aState,scrolledContentStyle->StyleDisplay(),content,newFrame,newFrame,scrolledContentStyle,&scrolledFrame,blockItem,aDisplay->IsAbsPosContainingBlock(newFrame)?newFrame:nullptr,aItem.mPendingBinding);NS_ASSERTION(blockItem.FirstChild()==scrolledFrame,"Scrollframe's frameItems should be exactly the scrolled frame");FinishBuildingScrollFrame(newFrame,scrolledFrame);returnnewFrame;}nsIFrame*nsCSSFrameConstructor::ConstructNonScrollableBlock(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){nsStyleContext*conststyleContext=aItem.mStyleContext;// We want a block formatting context root in paginated contexts for// every block that would be scrollable in a non-paginated context.// We mark our blocks with a bit here if this condition is true, so// we can check it later in nsFrame::ApplyPaginatedOverflowClipping.boolclipPaginatedOverflow=(aItem.mFCData->mBits&FCDATA_FORCED_NON_SCROLLABLE_BLOCK)!=0;nsContainerFrame*newFrame;if((aDisplay->IsAbsolutelyPositionedStyle()||aDisplay->IsFloatingStyle()||NS_STYLE_DISPLAY_INLINE_BLOCK==aDisplay->mDisplay||clipPaginatedOverflow)&&!aParentFrame->IsSVGText()){newFrame=NS_NewBlockFormattingContext(mPresShell,styleContext);if(clipPaginatedOverflow){newFrame->AddStateBits(NS_BLOCK_CLIP_PAGINATED_OVERFLOW);}}else{newFrame=NS_NewBlockFrame(mPresShell,styleContext);}ConstructBlock(aState,aDisplay,aItem.mContent,aState.GetGeometricParent(aDisplay,aParentFrame),aParentFrame,styleContext,&newFrame,aFrameItems,aDisplay->IsAbsPosContainingBlock(newFrame)?newFrame:nullptr,aItem.mPendingBinding);returnnewFrame;}voidnsCSSFrameConstructor::InitAndRestoreFrame(constnsFrameConstructorState&aState,nsIContent*aContent,nsContainerFrame*aParentFrame,nsIFrame*aNewFrame,boolaAllowCounters){NS_PRECONDITION(mUpdateCount!=0,"Should be in an update while creating frames");MOZ_ASSERT(aNewFrame,"Null frame cannot be initialized");// Initialize the frameaNewFrame->Init(aContent,aParentFrame,nullptr);aNewFrame->AddStateBits(aState.mAdditionalStateBits);if(aState.mFrameState){// Restore frame state for just the newly created frame.RestoreFrameStateFor(aNewFrame,aState.mFrameState);}if(aAllowCounters&&mCounterManager.AddCounterResetsAndIncrements(aNewFrame)){CountersDirty();}}already_AddRefed<nsStyleContext>nsCSSFrameConstructor::ResolveStyleContext(nsIFrame*aParentFrame,nsIContent*aContainer,nsIContent*aChild,nsFrameConstructorState*aState){MOZ_ASSERT(aContainer,"Must have parent here");// XXX uncomment when bug 1089223 is fixed:// MOZ_ASSERT(aContainer == aChild->GetFlattenedTreeParent());nsStyleContext*parentStyleContext=GetDisplayContentsStyleFor(aContainer);if(MOZ_LIKELY(!parentStyleContext)){aParentFrame=nsFrame::CorrectStyleParentFrame(aParentFrame,nullptr);if(aParentFrame){MOZ_ASSERT(aParentFrame->GetContent()==aContainer);// Resolve the style context based on the content object and the parent// style contextparentStyleContext=aParentFrame->StyleContext();}else{// Perhaps aParentFrame is a canvasFrame and we're replicating// fixed-pos frames.// XXX should we create a way to tell ConstructFrame which style// context to use, and pass it the style context for the// previous page's fixed-pos frame?}}returnResolveStyleContext(parentStyleContext,aChild,aState);}already_AddRefed<nsStyleContext>nsCSSFrameConstructor::ResolveStyleContext(nsIFrame*aParentFrame,nsIContent*aChild,nsFrameConstructorState*aState){returnResolveStyleContext(aParentFrame,aChild->GetFlattenedTreeParent(),aChild,aState);}already_AddRefed<nsStyleContext>nsCSSFrameConstructor::ResolveStyleContext(constInsertionPoint&aInsertion,nsIContent*aChild,nsFrameConstructorState*aState){returnResolveStyleContext(aInsertion.mParentFrame,aInsertion.mContainer,aChild,aState);}already_AddRefed<nsStyleContext>nsCSSFrameConstructor::ResolveStyleContext(nsStyleContext*aParentStyleContext,nsIContent*aContent,nsFrameConstructorState*aState){nsStyleSet*styleSet=mPresShell->StyleSet();aContent->OwnerDoc()->FlushPendingLinkUpdates();nsRefPtr<nsStyleContext>result;if(aContent->IsElement()){if(aState){result=styleSet->ResolveStyleFor(aContent->AsElement(),aParentStyleContext,aState->mTreeMatchContext);}else{result=styleSet->ResolveStyleFor(aContent->AsElement(),aParentStyleContext);}}else{NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),"shouldn't waste time creating style contexts for ""comments and processing instructions");result=styleSet->ResolveStyleForNonElement(aParentStyleContext);}RestyleManager::ReframingStyleContexts*rsc=RestyleManager()->GetReframingStyleContexts();if(rsc){nsStyleContext*oldStyleContext=rsc->Get(aContent,nsCSSPseudoElements::ePseudo_NotPseudoElement);nsPresContext*presContext=mPresShell->GetPresContext();if(oldStyleContext){RestyleManager::TryStartingTransition(presContext,aContent,oldStyleContext,&result);}elseif(aContent->IsElement()){presContext->TransitionManager()->PruneCompletedTransitions(aContent->AsElement(),nsCSSPseudoElements::ePseudo_NotPseudoElement,result);}}returnresult.forget();}// MathML Mod - RBSvoidnsCSSFrameConstructor::FlushAccumulatedBlock(nsFrameConstructorState&aState,nsIContent*aContent,nsContainerFrame*aParentFrame,nsFrameItems&aBlockItems,nsFrameItems&aNewItems){if(aBlockItems.IsEmpty()){// Nothing to doreturn;}nsIAtom*anonPseudo=nsCSSAnonBoxes::mozMathMLAnonymousBlock;nsStyleContext*parentContext=nsFrame::CorrectStyleParentFrame(aParentFrame,anonPseudo)->StyleContext();nsStyleSet*styleSet=mPresShell->StyleSet();nsRefPtr<nsStyleContext>blockContext;blockContext=styleSet->ResolveAnonymousBoxStyle(anonPseudo,parentContext);// then, create a block frame that will wrap the child frames. Make it a// MathML frame so that Get(Absolute/Float)ContainingBlockFor know that this// is not a suitable block.nsContainerFrame*blockFrame=NS_NewMathMLmathBlockFrame(mPresShell,blockContext,NS_BLOCK_FLOAT_MGR|NS_BLOCK_MARGIN_ROOT);InitAndRestoreFrame(aState,aContent,aParentFrame,blockFrame);ReparentFrames(this,blockFrame,aBlockItems);// abs-pos and floats are disabled in MathML children so we don't have to// worry about messing up those.blockFrame->SetInitialChildList(kPrincipalList,aBlockItems);NS_ASSERTION(aBlockItems.IsEmpty(),"What happened?");aBlockItems.Clear();aNewItems.AddChild(blockFrame);}// Only <math> elements can be floated or positioned. All other MathML// should be in-flow.#define SIMPLE_MATHML_CREATE(_tag, _func) \ { &nsGkAtoms::_tag, \ FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | \ FCDATA_FORCE_NULL_ABSPOS_CONTAINER | \ FCDATA_WRAP_KIDS_IN_BLOCKS, _func) }/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindMathMLData(Element*aElement,nsIAtom*aTag,int32_taNameSpaceID,nsStyleContext*aStyleContext){// Make sure that we remain confined in the MathML worldif(aNameSpaceID!=kNameSpaceID_MathML)returnnullptr;// Handle <math> specially, because it sometimes produces inlinesif(aTag==nsGkAtoms::math){// This needs to match the test in EnsureBlockDisplay in// nsRuleNode.cpp. Though the behavior here for the display:table// case is pretty weird...if(aStyleContext->StyleDisplay()->IsBlockOutsideStyle()){staticconstFrameConstructionDatasBlockMathData=FCDATA_DECL(FCDATA_FORCE_NULL_ABSPOS_CONTAINER|FCDATA_WRAP_KIDS_IN_BLOCKS,NS_CreateNewMathMLmathBlockFrame);return&sBlockMathData;}staticconstFrameConstructionDatasInlineMathData=FCDATA_DECL(FCDATA_FORCE_NULL_ABSPOS_CONTAINER|FCDATA_IS_LINE_PARTICIPANT|FCDATA_WRAP_KIDS_IN_BLOCKS,NS_NewMathMLmathInlineFrame);return&sInlineMathData;}staticconstFrameConstructionDataByTagsMathMLData[]={SIMPLE_MATHML_CREATE(annotation_,NS_NewMathMLTokenFrame),SIMPLE_MATHML_CREATE(annotation_xml_,NS_NewMathMLmrowFrame),SIMPLE_MATHML_CREATE(mi_,NS_NewMathMLTokenFrame),SIMPLE_MATHML_CREATE(mn_,NS_NewMathMLTokenFrame),SIMPLE_MATHML_CREATE(ms_,NS_NewMathMLTokenFrame),SIMPLE_MATHML_CREATE(mtext_,NS_NewMathMLTokenFrame),SIMPLE_MATHML_CREATE(mo_,NS_NewMathMLmoFrame),SIMPLE_MATHML_CREATE(mfrac_,NS_NewMathMLmfracFrame),SIMPLE_MATHML_CREATE(msup_,NS_NewMathMLmmultiscriptsFrame),SIMPLE_MATHML_CREATE(msub_,NS_NewMathMLmmultiscriptsFrame),SIMPLE_MATHML_CREATE(msubsup_,NS_NewMathMLmmultiscriptsFrame),SIMPLE_MATHML_CREATE(munder_,NS_NewMathMLmunderoverFrame),SIMPLE_MATHML_CREATE(mover_,NS_NewMathMLmunderoverFrame),SIMPLE_MATHML_CREATE(munderover_,NS_NewMathMLmunderoverFrame),SIMPLE_MATHML_CREATE(mphantom_,NS_NewMathMLmrowFrame),SIMPLE_MATHML_CREATE(mpadded_,NS_NewMathMLmpaddedFrame),SIMPLE_MATHML_CREATE(mspace_,NS_NewMathMLmspaceFrame),SIMPLE_MATHML_CREATE(none,NS_NewMathMLmspaceFrame),SIMPLE_MATHML_CREATE(mprescripts_,NS_NewMathMLmspaceFrame),SIMPLE_MATHML_CREATE(mfenced_,NS_NewMathMLmfencedFrame),SIMPLE_MATHML_CREATE(mmultiscripts_,NS_NewMathMLmmultiscriptsFrame),SIMPLE_MATHML_CREATE(mstyle_,NS_NewMathMLmrowFrame),SIMPLE_MATHML_CREATE(msqrt_,NS_NewMathMLmsqrtFrame),SIMPLE_MATHML_CREATE(mroot_,NS_NewMathMLmrootFrame),SIMPLE_MATHML_CREATE(maction_,NS_NewMathMLmactionFrame),SIMPLE_MATHML_CREATE(mrow_,NS_NewMathMLmrowFrame),SIMPLE_MATHML_CREATE(merror_,NS_NewMathMLmrowFrame),SIMPLE_MATHML_CREATE(menclose_,NS_NewMathMLmencloseFrame),SIMPLE_MATHML_CREATE(semantics_,NS_NewMathMLsemanticsFrame)};returnFindDataByTag(aTag,aElement,aStyleContext,sMathMLData,ArrayLength(sMathMLData));}nsContainerFrame*nsCSSFrameConstructor::ConstructFrameWithAnonymousChild(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems,ContainerFrameCreationFuncaConstructor,ContainerFrameCreationFuncaInnerConstructor,nsICSSAnonBoxPseudo*aInnerPseudo,boolaCandidateRootFrame){nsIContent*constcontent=aItem.mContent;nsStyleContext*conststyleContext=aItem.mStyleContext;// Create the outer frame:nsContainerFrame*newFrame=aConstructor(mPresShell,styleContext);InitAndRestoreFrame(aState,content,aCandidateRootFrame?aState.GetGeometricParent(styleContext->StyleDisplay(),aParentFrame):aParentFrame,newFrame);// Create the pseudo SC for the anonymous wrapper child as a child of the SC:nsRefPtr<nsStyleContext>scForAnon;scForAnon=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(aInnerPseudo,styleContext);// Create the anonymous inner wrapper framensContainerFrame*innerFrame=aInnerConstructor(mPresShell,scForAnon);InitAndRestoreFrame(aState,content,newFrame,innerFrame);// Put the newly created frames into the right child listSetInitialSingleChild(newFrame,innerFrame);aState.AddChild(newFrame,aFrameItems,content,styleContext,aParentFrame,aCandidateRootFrame,aCandidateRootFrame);if(!mRootElementFrame&&aCandidateRootFrame){// The frame we're constructing will be the root element frame.// Set mRootElementFrame before processing children.mRootElementFrame=newFrame;}nsFrameItemschildItems;// Process childrenNS_ASSERTION(aItem.mAnonChildren.IsEmpty(),"nsIAnonymousContentCreator::CreateAnonymousContent should not ""be implemented for frames for which we explicitly create an ""anonymous child to wrap its child frames");if(aItem.mFCData->mBits&FCDATA_USE_CHILD_ITEMS){ConstructFramesFromItemList(aState,aItem.mChildItems,innerFrame,childItems);}else{ProcessChildren(aState,content,styleContext,innerFrame,true,childItems,false,aItem.mPendingBinding);}// Set the inner wrapper frame's initial primary listinnerFrame->SetInitialChildList(kPrincipalList,childItems);returnnewFrame;}nsIFrame*nsCSSFrameConstructor::ConstructOuterSVG(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){returnConstructFrameWithAnonymousChild(aState,aItem,aParentFrame,aDisplay,aFrameItems,NS_NewSVGOuterSVGFrame,NS_NewSVGOuterSVGAnonChildFrame,nsCSSAnonBoxes::mozSVGOuterSVGAnonChild,true);}nsIFrame*nsCSSFrameConstructor::ConstructMarker(nsFrameConstructorState&aState,FrameConstructionItem&aItem,nsContainerFrame*aParentFrame,constnsStyleDisplay*aDisplay,nsFrameItems&aFrameItems){returnConstructFrameWithAnonymousChild(aState,aItem,aParentFrame,aDisplay,aFrameItems,NS_NewSVGMarkerFrame,NS_NewSVGMarkerAnonChildFrame,nsCSSAnonBoxes::mozSVGMarkerAnonChild,false);}// Only outer <svg> elements can be floated or positioned. All other SVG// should be in-flow.#define SIMPLE_SVG_FCDATA(_func) \ FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW | \ FCDATA_SKIP_ABSPOS_PUSH | \ FCDATA_DISALLOW_GENERATED_CONTENT, _func)#define SIMPLE_SVG_CREATE(_tag, _func) \ { &nsGkAtoms::_tag, SIMPLE_SVG_FCDATA(_func) }staticboolIsFilterPrimitiveChildTag(constnsIAtom*aTag){returnaTag==nsGkAtoms::feDistantLight||aTag==nsGkAtoms::fePointLight||aTag==nsGkAtoms::feSpotLight||aTag==nsGkAtoms::feFuncR||aTag==nsGkAtoms::feFuncG||aTag==nsGkAtoms::feFuncB||aTag==nsGkAtoms::feFuncA||aTag==nsGkAtoms::feMergeNode;}/* static */constnsCSSFrameConstructor::FrameConstructionData*nsCSSFrameConstructor::FindSVGData(Element*aElement,nsIAtom*aTag,int32_taNameSpaceID,nsIFrame*aParentFrame,boolaIsWithinSVGText,boolaAllowsTextPathChild,nsStyleContext*aStyleContext){if(aNameSpaceID!=kNameSpaceID_SVG){returnnullptr;}staticconstFrameConstructionDatasSuppressData=SUPPRESS_FCDATA();staticconstFrameConstructionDatasContainerData=SIMPLE_SVG_FCDATA(NS_NewSVGContainerFrame);boolparentIsSVG=aIsWithinSVGText;nsIContent*parentContent=aParentFrame?aParentFrame->GetContent():nullptr;// XXXbz should this really be based on the XBL-resolved tag of the parent// frame's content? Should it not be based on the type of the parent frame// (e.g. whether it's an SVG frame)?if(parentContent){int32_tparentNSID;nsIAtom*parentTag=parentContent->OwnerDoc()->BindingManager()->ResolveTag(parentContent,&parentNSID);// It's not clear whether the SVG spec intends to allow any SVG// content within svg:foreignObject at all (SVG 1.1, section// 23.2), but if it does, it better be svg:svg. So given that// we're allowing it, treat it as a non-SVG parent.parentIsSVG=parentNSID==kNameSpaceID_SVG&&parentTag!=nsGkAtoms::foreignObject;}if((aTag!=nsGkAtoms::svg&&!parentIsSVG)||(aTag==nsGkAtoms::desc||aTag==nsGkAtoms::title)){// Sections 5.1 and G.4 of SVG 1.1 say that SVG elements other than// svg:svg not contained within svg:svg are incorrect, although they// don't seem to specify error handling. Ignore them, since many of// our frame classes can't deal. It *may* be that the document// should at that point be considered in error according to F.2, but// it's hard to tell.//// Style mutation can't change this situation, so don't bother// adding to the undisplayed content map.//// We don't currently handle any UI for desc/titlereturn&sSuppressData;}// We don't need frames for animation elementsif(aElement->IsNodeOfType(nsINode::eANIMATION)){return&sSuppressData;}if(aTag==nsGkAtoms::svg&&!parentIsSVG){// We need outer <svg> elements to have an nsSVGOuterSVGFrame regardless// of whether they fail conditional processing attributes, since various// SVG frames assume that one exists. We handle the non-rendering// of failing outer <svg> element contents like <switch> statements,// and do the PassesConditionalProcessingTests call in// nsSVGOuterSVGFrame::Init.staticconstFrameConstructionDatasOuterSVGData=FULL_CTOR_FCDATA(0,&nsCSSFrameConstructor::ConstructOuterSVG);return&sOuterSVGData;}if(aTag==nsGkAtoms::marker){staticconstFrameConstructionDatasMarkerSVGData=FULL_CTOR_FCDATA(0,&nsCSSFrameConstructor::ConstructMarker);return&sMarkerSVGData;}nsCOMPtr<SVGTests>tests(do_QueryInterface(aElement));if(tests&&!tests->PassesConditionalProcessingTests()){// Elements with failing conditional processing attributes never get// rendered. Note that this is not where we select which frame in a// <switch> to render! That happens in nsSVGSwitchFrame::PaintSVG.return&sContainerData;}// Ensure that a stop frame is a child of a gradient and that gradients// can only have stop children.boolparentIsGradient=aParentFrame&&(aParentFrame->GetType()==nsGkAtoms::svgLinearGradientFrame||aParentFrame->GetType()==nsGkAtoms::svgRadialGradientFrame);boolstop=(aTag==nsGkAtoms::stop);if((parentIsGradient&&!stop)||(!parentIsGradient&&stop)){return&sSuppressData;}// Prevent bad frame types being children of filters or parents of filter// primitives. If aParentFrame is null, we know that the frame that will// be created will be an nsInlineFrame, so it can never be a filter.boolparentIsFilter=aParentFrame&&aParentFrame->GetType()==nsGkAtoms::svgFilterFrame;boolfilterPrimitive=aElement->IsNodeOfType(nsINode::eFILTER);if((parentIsFilter&&!filterPrimitive)||(!parentIsFilter&&filterPrimitive)){return&sSuppressData;}// Prevent bad frame types being children of filter primitives or parents of// filter primitive children. If aParentFrame is null, we know that the frame// that will be created will be an nsInlineFrame, so it can never be a filter// primitive.boolparentIsFEContainerFrame=aParentFrame&&aParentFrame->GetType()==nsGkAtoms::svgFEContainerFrame;if((parentIsFEContainerFrame&&!IsFilterPrimitiveChildTag(aTag))||(!parentIsFEContainerFrame&&IsFilterPrimitiveChildTag(aTag))){return&sSuppressData;}// Special cases for text/tspan/textPath, because the kind of frame// they get depends on the parent frame. We ignore 'a' elements when// determining the parent, however.if(aIsWithinSVGText){// If aIsWithinSVGText is true, then we know that the "SVG text uses// CSS frames" pref was true when this SVG fragment was first constructed.// We don't use ConstructInline because we want different behavior// for generated content.staticconstFrameConstructionDatasTSpanData=FCDATA_DECL(FCDATA_DISALLOW_OUT_OF_FLOW|FCDATA_SKIP_ABSPOS_PUSH|FCDATA_DISALLOW_GENERATED_CONTENT|FCDATA_IS_LINE_PARTICIPANT|FCDATA_IS_INLINE|FCDATA_USE_CHILD_ITEMS,NS_NewInlineFrame);if(aTag==nsGkAtoms::textPath){if(aAllowsTextPathChild){return&sTSpanData;}}elseif(aTag==nsGkAtoms::tspan||aTag==nsGkAtoms::altGlyph||aTag==nsGkAtoms::a){return&sTSpanData;}return&sSuppressData;}elseif(aTag==nsGkAtoms::text){staticconstFrameConstructionDatasTextData=FCDATA_WITH_WRAPPING_BLOCK(FCDATA_DISALLOW_OUT_OF_FLOW|FCDATA_ALLOW_BLOCK_STYLES,NS_NewSVGTextFrame,nsCSSAnonBoxes::mozSVGText);return&sTextData;}elseif(aTag==nsGkAtoms::tspan||aTag==nsGkAtoms::altGlyph||aTag==nsGkAtoms::textPath){return&sSuppressData;}staticconstFrameConstructionDataByTagsSVGData[]={SIMPLE_SVG_CREATE(svg,NS_NewSVGInnerSVGFrame),SIMPLE_SVG_CREATE(g,NS_NewSVGGFrame),SIMPLE_SVG_CREATE(svgSwitch,NS_NewSVGSwitchFrame),SIMPLE_SVG_CREATE(polygon,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(polyline,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(circle,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(ellipse,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(line,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(rect,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(path,NS_NewSVGPathGeometryFrame),SIMPLE_SVG_CREATE(defs,NS_NewSVGContainerFrame),SIMPLE_SVG_CREATE(generic_,NS_NewSVGGenericContainerFrame),{&nsGkAtoms::foreignObject,FCDATA_WITH_WRAPPING_BLOCK(FCDATA_DISALLOW_OUT_OF_FLOW,NS_NewSVGForeignObjectFrame,nsCSSAnonBoxes::mozSVGForeignContent)},SIMPLE_SVG_CREATE(a,NS_NewSVGAFrame),SIMPLE_SVG_CREATE(linearGradient,NS_NewSVGLinearGradientFrame),SIMPLE_SVG_CREATE(radialGradient,NS_NewSVGRadialGradientFrame),SIMPLE_SVG_CREATE(stop,NS_NewSVGStopFrame),SIMPLE_SVG_CREATE(use,NS_NewSVGUseFrame),SIMPLE_SVG_CREATE(view,NS_NewSVGViewFrame),SIMPLE_SVG_CREATE(image,NS_NewSVGImageFrame),SIMPLE_SVG_CREATE(clipPath,NS_NewSVGClipPathFrame),SIMPLE_SVG_CREATE(filter,NS_NewSVGFilterFrame),SIMPLE_SVG_CREATE(pattern,NS_NewSVGPatternFrame),SIMPLE_SVG_CREATE(mask,NS_NewSVGMaskFrame),SIMPLE_SVG_CREATE(feDistantLight,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(fePointLight,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feSpotLight,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feBlend,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feColorMatrix,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feFuncR,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feFuncG,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feFuncB,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feFuncA,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feComposite,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feComponentTransfer,NS_NewSVGFEContainerFrame),SIMPLE_SVG_CREATE(feConvolveMatrix,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feDiffuseLighting,NS_NewSVGFEContainerFrame),SIMPLE_SVG_CREATE(feDisplacementMap,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feDropShadow,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feFlood,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feGaussianBlur,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feImage,NS_NewSVGFEImageFrame),SIMPLE_SVG_CREATE(feMerge,NS_NewSVGFEContainerFrame),SIMPLE_SVG_CREATE(feMergeNode,NS_NewSVGFEUnstyledLeafFrame),SIMPLE_SVG_CREATE(feMorphology,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feOffset,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feSpecularLighting,NS_NewSVGFEContainerFrame),SIMPLE_SVG_CREATE(feTile,NS_NewSVGFELeafFrame),SIMPLE_SVG_CREATE(feTurbulence,NS_NewSVGFELeafFrame)};constFrameConstructionData*data=FindDataByTag(aTag,aElement,aStyleContext,sSVGData,ArrayLength(sSVGData));if(!data){data=&sContainerData;}returndata;}voidnsCSSFrameConstructor::AddPageBreakItem(nsIContent*aContent,nsStyleContext*aMainStyleContext,FrameConstructionItemList&aItems){// Use the same parent style context that |aMainStyleContext| has, since// that's easier to re-resolve and it doesn't matter in practice.// (Getting different parents can result in framechange hints, e.g.,// for user-modify.)nsRefPtr<nsStyleContext>pseudoStyle=mPresShell->StyleSet()->ResolveAnonymousBoxStyle(nsCSSAnonBoxes::pageBreak,aMainStyleContext->GetParent());NS_ASSERTION(pseudoStyle->StyleDisplay()->mDisplay==NS_STYLE_DISPLAY_BLOCK,"Unexpected display");staticconstFrameConstructionDatasPageBreakData=FCDATA_DECL(FCDATA_SKIP_FRAMESET,NS_NewPageBreakFrame);// Lie about the tag and namespace so we don't trigger anything// interesting during frame construction.aItems.AppendItem(&sPageBreakData,aContent,nsCSSAnonBoxes::pageBreak,kNameSpaceID_None,nullptr,pseudoStyle.forget(),true,nullptr);}boolnsCSSFrameConstructor::ShouldCreateItemsForChild(nsFrameConstructorState&aState,nsIContent*aContent,nsContainerFrame*aParentFrame){aContent->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES|NODE_NEEDS_FRAME);if(aContent->IsElement()){// We can't just remove our pending restyle flags, since we may// have restyle-later-siblings set on us. But we _can_ remove the// "is possible restyle root" flags, and need to. Otherwise we can// end up with stale such flags (e.g. if we used to have a// display:none parent when our last restyle was posted and// processed and now no longer do).aContent->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS&~ELEMENT_PENDING_RESTYLE_FLAGS);}// XXX the GetContent() != aContent check is needed due to bug 135040.// Remove it once that's fixed.if(aContent->GetPrimaryFrame()&&aContent->GetPrimaryFrame()->GetContent()==aContent&&!aState.mCreatingExtraFrames){NS_ERROR("asked to create frame construction item for a node that already ""has a frame");returnfalse;}// don't create a whitespace frame if aParent doesn't want itif(!NeedFrameFor(aState,aParentFrame,aContent)){returnfalse;}// never create frames for comments or PIsif(aContent->IsNodeOfType(nsINode::eCOMMENT)||aContent->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)){returnfalse;}returntrue;}voidnsCSSFrameConstructor::DoAddFrameConstructionItems(nsFrameConstructorState&aState,nsIContent*aContent,nsStyleContext*aStyleContext,boolaSuppressWhiteSpaceOptimizations,nsContainerFrame*aParentFrame,nsTArray<nsIAnonymousContentCreator::ContentInfo>*aAnonChildren,FrameConstructionItemList&aItems){uint32_tflags=ITEM_ALLOW_XBL_BASE|ITEM_ALLOW_PAGE_BREAK;if(aParentFrame){if(aParentFrame->IsSVGText()){flags|=ITEM_IS_WITHIN_SVG_TEXT;}if(aParentFrame->GetType()==nsGkAtoms::blockFrame&&aParentFrame->GetParent()&&aParentFrame->GetParent()->GetType()==nsGkAtoms::svgTextFrame){flags|=ITEM_ALLOWS_TEXT_PATH_CHILD;}}AddFrameConstructionItemsInternal(aState,aContent,aParentFrame,aContent->NodeInfo()->NameAtom(),aContent->GetNameSpaceID(),aSuppressWhiteSpaceOptimizations,aStyleContext,flags,aAnonChildren,aItems);}voidnsCSSFrameConstructor::AddFrameConstructionItems(nsFrameConstructorState&aState,nsIContent*aContent,boolaSuppressWhiteSpaceOptimizations,constInsertionPoint&aInsertion,FrameConstructionItemList&aItems){nsContainerFrame*parentFrame=aInsertion.mParentFrame;if(!ShouldCreateItemsForChild(aState,aContent,parentFrame)){return;}nsRefPtr<nsStyleContext>styleContext=ResolveStyleContext(aInsertion,aContent,&aState);DoAddFrameConstructionItems(aState,aContent,styleContext,aSuppressWhiteSpaceOptimizations,parentFrame,nullptr,aItems);}voidnsCSSFrameConstructor::SetAsUndisplayedContent(nsFrameConstructorState&aState,FrameConstructionItemList&aList,nsIContent*aContent,nsStyleContext*aStyleContext,boolaIsGeneratedContent){if(aStyleContext->GetPseudo()){if(aIsGeneratedContent){aContent->UnbindFromTree();}return;}NS_ASSERTION(!aIsGeneratedContent,"Should have had pseudo type");if(aState.mCreatingExtraFrames){MOZ_ASSERT(GetUndisplayedContent(aContent),"should have called SetUndisplayedContent earlier");return;}aList.AppendUndisplayedItem(aContent,aStyleContext);}voidnsCSSFrameConstructor::AddFrameConstructionItemsInternal(nsFrameConstructorState&aState,nsIContent*aContent,nsContainerFrame*aParentFrame,nsIAtom*aTag,int32_taNameSpaceID,boolaSuppressWhiteSpaceOptimizations,nsStyleContext*aStyleContext,uint32_taFlags,nsTArray<nsIAnonymousContentCreator::ContentInfo>*aAnonChildren,FrameConstructionItemList&aItems){NS_PRECONDITION(aContent->IsNodeOfType(nsINode::eTEXT)||aContent->IsElement(),"Shouldn't get anything else here!");MOZ_ASSERT(!aContent->GetPrimaryFrame()||aState.mCreatingExtraFrames||aContent->NodeInfo()->NameAtom()==nsGkAtoms::area);// The following code allows the user to specify the base tag// of an element using XBL. XUL and HTML objects (like boxes, menus, etc.)// can then be extended arbitrarily.constnsStyleDisplay*display=aStyleContext->StyleDisplay();nsRefPtr<nsStyleContext>styleContext(aStyleContext);PendingBinding*pendingBinding=nullptr;if((aFlags&ITEM_ALLOW_XBL_BASE)&&display->mBinding){// Ensure that our XBL bindings are installed.nsXBLService*xblService=nsXBLService::GetInstance();if(!xblService)return;boolresolveStyle;nsAutoPtr<PendingBinding>newPendingBinding(newPendingBinding());nsresultrv=xblService->LoadBindings(aContent,display->mBinding->GetURI(),display->mBinding->mOriginPrincipal,getter_AddRefs(newPendingBinding->mBinding),&resolveStyle);if(NS_FAILED(rv)&&rv!=NS_ERROR_XBL_BLOCKED)return;if(newPendingBinding->mBinding){pendingBinding=newPendingBinding;// aState takes over owning newPendingBindingaState.AddPendingBinding(newPendingBinding.forget());}if(resolveStyle){styleContext=ResolveStyleContext(styleContext->GetParent(),aContent,&aState);display=styleContext->StyleDisplay();aStyleContext=styleContext;}aTag=mDocument->BindingManager()->ResolveTag(aContent,&aNameSpaceID);}boolisGeneratedContent=((aFlags&ITEM_IS_GENERATED_CONTENT)!=0);// Pre-check for display "none" - if we find that, don't create// any frame at allif(NS_STYLE_DISPLAY_NONE==display->mDisplay){SetAsUndisplayedContent(aState,aItems,aContent,styleContext,isGeneratedContent);return;}boolisText=!aContent->IsElement();// never create frames for non-option/optgroup kids of <select> and// non-option kids of <optgroup> inside a <select>.// XXXbz it's not clear how this should best work with XBL.nsIContent*parent=aContent->GetParent();if(parent){// Check tag first, since that check will usually failif(parent->IsAnyOfHTMLElements(nsGkAtoms::select,nsGkAtoms::optgroup)&&// <option> is ok no matter what!aContent->IsHTMLElement(nsGkAtoms::option)&&// <optgroup> is OK in <select> but not in <optgroup>(!aContent->IsHTMLElement(nsGkAtoms::optgroup)||!parent->IsHTMLElement(nsGkAtoms::select))&&// Allow native anonymous content no matter what!aContent->IsRootOfNativeAnonymousSubtree()){// No frame for aContentif(!isText){SetAsUndisplayedContent(aState,aItems,aContent,styleContext,isGeneratedContent);}return;}}boolisPopup=false;// Try to find frame construction data for this contentconstFrameConstructionData*data;if(isText){data=FindTextData(aParentFrame);if(!data){// Nothing to do here; suppressed text inside SVGreturn;}}else{Element*element=aContent->AsElement();// Don't create frames for non-SVG element children of SVG elements.if(aNameSpaceID!=kNameSpaceID_SVG&&((aParentFrame&&IsFrameForSVG(aParentFrame)&&!aParentFrame->IsFrameOfType(nsIFrame::eSVGForeignObject))||(aFlags&ITEM_IS_WITHIN_SVG_TEXT))){SetAsUndisplayedContent(aState,aItems,element,styleContext,isGeneratedContent);return;}data=FindHTMLData(element,aTag,aNameSpaceID,aParentFrame,styleContext);if(!data){data=FindXULTagData(element,aTag,aNameSpaceID,styleContext);}if(!data){data=FindMathMLData(element,aTag,aNameSpaceID,styleContext);}if(!data){data=FindSVGData(element,aTag,aNameSpaceID,aParentFrame,aFlags&ITEM_IS_WITHIN_SVG_TEXT,aFlags&ITEM_ALLOWS_TEXT_PATH_CHILD,styleContext);}// Now check for XUL display typesif(!data){data=FindXULDisplayData(display,element,styleContext);}// And general display typesif(!data){data=FindDisplayData(display,element,aParentFrame,styleContext);}NS_ASSERTION(data,"Should have frame construction data now");if(data->mBits&FCDATA_SUPPRESS_FRAME){SetAsUndisplayedContent(aState,aItems,element,styleContext,isGeneratedContent);return;}#ifdef MOZ_XULif((data->mBits&FCDATA_IS_POPUP)&&(!aParentFrame||// Parent is inlineaParentFrame->GetType()!=nsGkAtoms::menuFrame)){if(!aState.mPopupItems.containingBlock&&!aState.mHavePendingPopupgroup){SetAsUndisplayedContent(aState,aItems,element,styleContext,isGeneratedContent);return;}isPopup=true;}#endif /* MOZ_XUL */}uint32_tbits=data->mBits;// Inside colgroups, suppress everything except columns.if(aParentFrame&&aParentFrame->GetType()==nsGkAtoms::tableColGroupFrame&&(!(bits&FCDATA_IS_TABLE_PART)||display->mDisplay!=NS_STYLE_DISPLAY_TABLE_COLUMN)){SetAsUndisplayedContent(aState,aItems,aContent,styleContext,isGeneratedContent);return;}boolcanHavePageBreak=(aFlags&ITEM_ALLOW_PAGE_BREAK)&&aState.mPresContext->IsPaginated()&&!display->IsAbsolutelyPositionedStyle()&&!(bits&FCDATA_IS_TABLE_PART)&&!(bits&FCDATA_IS_SVG_TEXT);if(canHavePageBreak&&display->mBreakBefore){AddPageBreakItem(aContent,aStyleContext,aItems);}if(MOZ_UNLIKELY(bits&FCDATA_IS_CONTENTS)){if(!GetDisplayContentsStyleFor(aContent)){MOZ_ASSERT(styleContext->GetPseudo()||!isGeneratedContent,"Should have had pseudo type");aState.mFrameManager->SetDisplayContents(aContent,styleContext);}else{aState.mFrameManager->ChangeDisplayContents(aContent,styleContext);}TreeMatchContext::AutoAncestorPusherancestorPusher(aState.mTreeMatchContext);if(aState.mTreeMatchContext.mAncestorFilter.HasFilter()){ancestorPusher.PushAncestorAndStyleScope(aContent->AsElement());}else{ancestorPusher.PushStyleScope(aContent->AsElement());}if(aParentFrame){aParentFrame->AddStateBits(NS_FRAME_MAY_HAVE_GENERATED_CONTENT);}CreateGeneratedContentItem(aState,aParentFrame,aContent,styleContext,nsCSSPseudoElements::ePseudo_before,aItems);FlattenedChildIteratoriter(aContent);for(nsIContent*child=iter.GetNextChild();child;child=iter.GetNextChild()){if(!ShouldCreateItemsForChild(aState,child,aParentFrame)){continue;}// Get the parent of the content and check if it is a XBL children element// (if the content is a children element then parent != aContent because the// FlattenedChildIterator will transitively iterate through <xbl:children>// for default content). Push the children element as an ancestor here because// it does not have a frame and would not otherwise be pushed as an ancestor.nsIContent*parent=child->GetParent();MOZ_ASSERT(parent,"Parent must be non-null because we are iterating children.");TreeMatchContext::AutoAncestorPusherancestorPusher(aState.mTreeMatchContext);if(parent!=aContent&&parent->IsElement()){if(aState.mTreeMatchContext.mAncestorFilter.HasFilter()){ancestorPusher.PushAncestorAndStyleScope(parent->AsElement());}else{ancestorPusher.PushStyleScope(parent->AsElement());}}nsRefPtr<nsStyleContext>childContext=ResolveStyleContext(styleContext,child,&aState);DoAddFrameConstructionItems(aState,child,childContext,aSuppressWhiteSpaceOptimizations,aParentFrame,aAnonChildren,aItems);}aItems.SetParentHasNoXBLChildren(!iter.XBLInvolved());CreateGeneratedContentItem(aState,aParentFrame,aContent,styleContext,nsCSSPseudoElements::ePseudo_after,aItems);if(canHavePageBreak&&display->mBreakAfter){AddPageBreakItem(aContent,aStyleContext,aItems);}return;}FrameConstructionItem*item=aItems.AppendItem(data,aContent,aTag,aNameSpaceID,pendingBinding,styleContext.forget(),aSuppressWhiteSpaceOptimizations,aAnonChildren);item->mIsText=isText;item->mIsGeneratedContent=isGeneratedContent;item->mIsAnonymousContentCreatorContent=aFlags&ITEM_IS_ANONYMOUSCONTENTCREATOR_CONTENT;if(isGeneratedContent){NS_ADDREF(item->mContent);}item->mIsRootPopupgroup=aNameSpaceID==kNameSpaceID_XUL&&aTag==nsGkAtoms::popupgroup&&aContent->IsRootOfNativeAnonymousSubtree();if(item->mIsRootPopupgroup){aState.mHavePendingPopupgroup=true;}item->mIsPopup=isPopup;item->mIsForSVGAElement=aNameSpaceID==kNameSpaceID_SVG&&aTag==nsGkAtoms::a;if(canHavePageBreak&&display->mBreakAfter){AddPageBreakItem(aContent,aStyleContext,aItems);}if(bits&FCDATA_IS_INLINE){// To correctly set item->mIsAllInline we need to build up our child items// right now.BuildInlineChildItems(aState,*item,aFlags&ITEM_IS_WITHIN_SVG_TEXT,aFlags&ITEM_ALLOWS_TEXT_PATH_CHILD);item->mHasInlineEnds=true;item->mIsBlock=false;}else{// Compute a boolean isInline which is guaranteed to be false for blocks// (but may also be false for some inlines).boolisInline=// Table-internal things are inline-outside if and only if they're kids of// inlines, since they'll trigger construction of inline-table// pseudos.((bits&FCDATA_IS_TABLE_PART)&&(!aParentFrame||// No aParentFrame means inlineaParentFrame->StyleDisplay()->mDisplay==NS_STYLE_DISPLAY_INLINE))||// Things that are inline-outside but aren't inline frames are inlinedisplay->IsInlineOutsideStyle()||// Popups that are certainly out of flow.isPopup;// Set mIsAllInline conservatively. It just might be that even an inline// that has mIsAllInline false doesn't need an {ib} split. So this is just// an optimization to keep from doing too much work in cases when we can// show that mIsAllInline is true..item->mIsAllInline=item->mHasInlineEnds=isInline||// Figure out whether we're guaranteed this item will be out of flow.// This is not a precise test, since one of our ancestor inlines might add// an absolute containing block (if it's relatively positioned) when there// wasn't such a containing block before. But it's conservative in the// sense that anything that will really end up as an in-flow non-inline// will test false here. In other words, if this test is true we're// guaranteed to be inline; if it's false we don't know what we'll end up// as.//// If we make this test precise, we can remove some of the code dealing// with the imprecision in ConstructInline and adjust the comments on// mIsAllInline and mIsBlock in the header. And probably remove mIsBlock// altogether, since then it will always be equal to !mHasInlineEnds.(!(bits&FCDATA_DISALLOW_OUT_OF_FLOW)&&aState.GetGeometricParent(display,nullptr));// Set mIsBlock conservatively. It's OK to set it false for some real// blocks, but not OK to set it true for things that aren't blocks. Since// isOutOfFlow might be false even in cases when the frame will end up// out-of-flow, we can't use it here. But we _can_ say that the frame will// for sure end up in-flow if it's not floated or absolutely positioned.item->mIsBlock=!isInline&&!display->IsAbsolutelyPositionedStyle()&&!display->IsFloatingStyle()&&!(bits&FCDATA_IS_SVG_TEXT);}if(item->mIsAllInline){aItems.InlineItemAdded();}elseif(item->mIsBlock){aItems.BlockItemAdded();}// Our item should be treated as a line participant if we have the relevant// bit and are going to be in-flow. Note that this really only matters if// our ancestor is a box or some such, so the fact that we might have an// inline ancestor that might become a containing block is not relevant here.if((bits&FCDATA_IS_LINE_PARTICIPANT)&&((bits&FCDATA_DISALLOW_OUT_OF_FLOW)||!aState.GetGeometricParent(display,nullptr))){item->mIsLineParticipant=true;aItems.LineParticipantItemAdded();}}staticvoidAddGenConPseudoToFrame(nsIFrame*aOwnerFrame,nsIContent*aContent){NS_ASSERTION(nsLayoutUtils::IsFirstContinuationOrIBSplitSibling(aOwnerFrame),"property should only be set on first continuation/ib-sibling");typedefnsAutoTArray<nsIContent*,2>T;constFramePropertyDescriptor*prop=nsIFrame::GenConProperty();FramePropertiesprops=aOwnerFrame->Properties();T*value=static_cast<T*>(props.Get(prop));if(!value){value=newT;props.Set(prop,value);}value->AppendElement(aContent);}/** * Return true if the frame construction item pointed to by aIter will * create a frame adjacent to a line boundary in the frame tree, and that * line boundary is induced by a content node adjacent to the frame's * content node in the content tree. The latter condition is necessary so * that ContentAppended/ContentInserted/ContentRemoved can easily find any * text nodes that were suppressed here. */boolnsCSSFrameConstructor::AtLineBoundary(FCItemIterator&aIter){if(aIter.item().mSuppressWhiteSpaceOptimizations){returnfalse;}if(aIter.AtStart()){if(aIter.List()->HasLineBoundaryAtStart()&&!aIter.item().mContent->GetPreviousSibling())returntrue;}else{FCItemIteratorprev=aIter;prev.Prev();if(prev.item().IsLineBoundary()&&!prev.item().mSuppressWhiteSpaceOptimizations&&aIter.item().mContent->GetPreviousSibling()==prev.item().mContent)returntrue;}FCItemIteratornext=aIter;next.Next();if(next.IsDone()){if(aIter.List()->HasLineBoundaryAtEnd()&&!aIter.item().mContent->GetNextSibling())returntrue;}else{if(next.item().IsLineBoundary()&&!next.item().mSuppressWhiteSpaceOptimizations&&aIter.item().mContent->GetNextSibling()==next.item().mContent)returntrue;}returnfalse;}voidnsCSSFrameConstructor::ConstructFramesFromItem(nsFrameConstructorState&aState,FCItemIterator&aIter,nsContainerFrame*aParentFrame,nsFrameItems&aFrameItems){nsContainerFrame*adjParentFrame=aParentFrame;FrameConstructionItem&item=aIter.item();nsStyleContext*styleContext=item.mStyleContext;AdjustParentFrame(&adjParentFrame,item.mFCData,styleContext);if(item.mIsText){// If this is collapsible whitespace next to a line boundary,// don't create a frame. item.IsWhitespace() also sets the// NS_CREATE_FRAME_IF_NON_WHITESPACE flag in the text node. (If we// end up creating a frame, nsTextFrame::Init will clear the flag.)// We don't do this for generated content, because some generated// text content is empty text nodes that are about to be initialized.// (We check mAdditionalStateBits because only the generated content// container's frame construction item is marked with// mIsGeneratedContent, and we might not have an aParentFrame.)// We don't do it for content that may have XBL anonymous siblings,// because they make it difficult to correctly create the frame// due to dynamic changes.// We don't do it for SVG text, since we might need to position and// measure the white space glyphs due to x/y/dx/dy attributes.if(AtLineBoundary(aIter)&&!styleContext->StyleText()->WhiteSpaceOrNewlineIsSignificant()&&aIter.List()->ParentHasNoXBLChildren()&&!(aState.mAdditionalStateBits&NS_FRAME_GENERATED_CONTENT)&&(item.mFCData->mBits&FCDATA_IS_LINE_PARTICIPANT)&&!(item.mFCData->mBits&FCDATA_IS_SVG_TEXT)&&!mAlwaysCreateFramesForIgnorableWhitespace&&item.IsWhitespace(aState))return;ConstructTextFrame(item.mFCData,aState,item.mContent,adjParentFrame,styleContext,aFrameItems);return;}// Start background loads during frame construction so that we're// guaranteed that they will be started before onload fires.styleContext->StartBackgroundImageLoads();nsFrameStatesavedStateBits=aState.mAdditionalStateBits;if(item.mIsGeneratedContent){// Ensure that frames created here are all tagged with// NS_FRAME_GENERATED_CONTENT.aState.mAdditionalStateBits|=NS_FRAME_GENERATED_CONTENT;// Note that we're not necessarily setting this property on the primary// frame for the content for which this is generated content. We might be// setting it on a table pseudo-frame inserted under that instead. That's// OK, though; we just need to do the property set so that the content will// get cleaned up when the frame is destroyed.::AddGenConPseudoToFrame(aParentFrame,item.mContent);// Now that we've passed ownership of item.mContent to the frame, unset// our generated content flag so we don't release or unbind it ourselves.item.mIsGeneratedContent=false;}// XXXbz maybe just inline ConstructFrameFromItemInternal here or something?ConstructFrameFromItemInternal(item,aState,adjParentFrame,aFrameItems);aState.mAdditionalStateBits=savedStateBits;}inlineboolIsRootBoxFrame(nsIFrame*aFrame){return(aFrame->GetType()==nsGkAtoms::rootFrame);}nsresultnsCSSFrameConstructor::ReconstructDocElementHierarchy(){Element*rootElement=mDocument->GetRootElement();if(!rootElement){/* nothing to do */returnNS_OK;}returnRecreateFramesForContent(rootElement,false,REMOVE_FOR_RECONSTRUCTION,nullptr);}nsContainerFrame*nsCSSFrameConstructor::GetAbsoluteContainingBlock(nsIFrame*aFrame,ContainingBlockTypeaType){// Starting with aFrame, look for a frame that is absolutely positioned or// relatively positioned (and transformed, if aType is FIXED)for(nsIFrame*frame=aFrame;frame;frame=frame->GetParent()){if(frame->IsFrameOfType(nsIFrame::eMathML)){// If it's mathml, bail out -- no absolute positioning out from inside// mathml frames. Note that we don't make this part of the loop// condition because of the stuff at the end of this method...returnnullptr;}// Look for the ICB.if(aType==FIXED_POS){nsIAtom*t=frame->GetType();if(t==nsGkAtoms::viewportFrame||t==nsGkAtoms::pageContentFrame){returnstatic_cast<nsContainerFrame*>(frame);}}// If the frame is positioned, we will probably return it as the containing// block (see the exceptions below). Otherwise, we'll start looking at the// parent frame, unless we're dealing with a scrollframe.// Scrollframes are special since they're not positioned, but their// scrolledframe might be. So, we need to check this special case to return// the correct containing block (the scrolledframe) in that case.// If we're looking for a fixed-pos containing block and the frame is// not transformed, skip it.if(!frame->IsAbsPosContaininingBlock()||(aType==FIXED_POS&&!frame->StyleDisplay()->IsFixedPosContainingBlock(frame))){continue;}nsIFrame*absPosCBCandidate=frame;nsIAtom*type=absPosCBCandidate->GetType();if(type==nsGkAtoms::fieldSetFrame){absPosCBCandidate=static_cast<nsFieldSetFrame*>(absPosCBCandidate)->GetInner();if(!absPosCBCandidate){continue;}type=absPosCBCandidate->GetType();}if(type==nsGkAtoms::scrollFrame){nsIScrollableFrame*scrollFrame=do_QueryFrame(absPosCBCandidate);absPosCBCandidate=scrollFrame->GetScrolledFrame();if(!absPosCBCandidate){continue;}type=absPosCBCandidate->GetType();}// Only first continuations can be containing blocks.absPosCBCandidate=absPosCBCandidate->FirstContinuation();// Is the frame really an absolute container?if(!absPosCBCandidate->IsAbsoluteContainer()){continue;}// For tables, skip the inner frame and consider the outer table frame.if(type==nsGkAtoms::tableFrame){continue;}// For outer table frames, we can just return absPosCBCandidate.MOZ_ASSERT((nsContainerFrame*)do_QueryFrame(absPosCBCandidate),"abs.pos. containing block must be nsContainerFrame sub-class");returnstatic_cast<nsContainerFrame*>(absPosCBCandidate);}MOZ_ASSERT(aType!=FIXED_POS,"no ICB in this frame tree?");// It is possible for the search for the containing block to fail, because// no absolute container can be found in the parent chain. In those cases,// we fall back to the document element's containing block.returnmHasRootAbsPosContainingBlock?mDocElementContainingBlock:nullptr;}nsContainerFrame*nsCSSFrameConstructor::GetFloatContainingBlock(nsIFrame*aFrame){// Starting with aFrame, look for a frame that is a float containing block.// IF we hit a mathml frame, bail out; we don't allow floating out of mathml// frames, because they don't seem to be able to deal.// The logic here needs to match the logic in ProcessChildren()for(nsIFrame*containingBlock=aFrame;containingBlock&&!ShouldSuppressFloatingOfDescendants(containingBlock);containingBlock=containingBlock->GetParent()){if(containingBlock->IsFloatContainingBlock()){MOZ_ASSERT((nsContainerFrame*)do_QueryFrame(containingBlock),"float containing block must be nsContainerFrame sub-class");returnstatic_cast<nsContainerFrame*>(containingBlock);}}// If we didn't find a containing block, then there just isn't// one.... return nullreturnnullptr;}/** * This function will check whether aContainer has :after generated content. * If so, appending to it should actually insert. The return value is the * parent to use for newly-appended content. *aAfterFrame points to the :after * frame before which appended content should go, if there is one. */staticnsContainerFrame*AdjustAppendParentForAfterContent(nsFrameManager*aFrameManager,nsIContent*aContainer,nsContainerFrame*aParentFrame,nsIContent*aChild,nsIFrame**aAfterFrame){// If the parent frame has any pseudo-elements or aContainer is a// display:contents node then we need to walk through the child// frames to find the first one that is either a ::after frame for an// ancestor of aChild or a frame that is for a node later in the//