michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* rendering object for CSS display:inline objects */ michael@0: michael@0: #include "nsInlineFrame.h" michael@0: #include "nsLineLayout.h" michael@0: #include "nsBlockFrame.h" michael@0: #include "nsPlaceholderFrame.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsStyleContext.h" michael@0: #include "nsPresContext.h" michael@0: #include "nsRenderingContext.h" michael@0: #include "nsCSSAnonBoxes.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "RestyleManager.h" michael@0: #include "nsDisplayList.h" michael@0: #include "mozilla/Likely.h" michael@0: michael@0: #ifdef DEBUG michael@0: #undef NOISY_PUSHING michael@0: #endif michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::layout; michael@0: michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: // Basic nsInlineFrame methods michael@0: michael@0: nsIFrame* michael@0: NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsInlineFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsInlineFrame) michael@0: michael@0: NS_QUERYFRAME_HEAD(nsInlineFrame) michael@0: NS_QUERYFRAME_ENTRY(nsInlineFrame) michael@0: NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame) michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: nsresult michael@0: nsInlineFrame::GetFrameName(nsAString& aResult) const michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("Inline"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: nsIAtom* michael@0: nsInlineFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::inlineFrame; michael@0: } michael@0: michael@0: void michael@0: nsInlineFrame::InvalidateFrame(uint32_t aDisplayItemKey) michael@0: { michael@0: if (IsSVGText()) { michael@0: nsIFrame* svgTextFrame = michael@0: nsLayoutUtils::GetClosestFrameOfType(GetParent(), michael@0: nsGkAtoms::svgTextFrame); michael@0: svgTextFrame->InvalidateFrame(); michael@0: return; michael@0: } michael@0: nsInlineFrameBase::InvalidateFrame(aDisplayItemKey); michael@0: } michael@0: michael@0: void michael@0: nsInlineFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey) michael@0: { michael@0: if (IsSVGText()) { michael@0: nsIFrame* svgTextFrame = michael@0: nsLayoutUtils::GetClosestFrameOfType(GetParent(), michael@0: nsGkAtoms::svgTextFrame); michael@0: svgTextFrame->InvalidateFrame(); michael@0: return; michael@0: } michael@0: nsInlineFrameBase::InvalidateFrameWithRect(aRect, aDisplayItemKey); michael@0: } michael@0: michael@0: static inline bool michael@0: IsMarginZero(const nsStyleCoord &aCoord) michael@0: { michael@0: return aCoord.GetUnit() == eStyleUnit_Auto || michael@0: nsLayoutUtils::IsMarginZero(aCoord); michael@0: } michael@0: michael@0: /* virtual */ bool michael@0: nsInlineFrame::IsSelfEmpty() michael@0: { michael@0: #if 0 michael@0: // I used to think inline frames worked this way, but it seems they michael@0: // don't. At least not in our codebase. michael@0: if (GetPresContext()->CompatibilityMode() == eCompatibility_FullStandards) { michael@0: return false; michael@0: } michael@0: #endif michael@0: const nsStyleMargin* margin = StyleMargin(); michael@0: const nsStyleBorder* border = StyleBorder(); michael@0: const nsStylePadding* padding = StylePadding(); michael@0: // XXX Top and bottom removed, since they shouldn't affect things, but this michael@0: // doesn't really match with nsLineLayout.cpp's setting of michael@0: // ZeroEffectiveSpanBox, anymore, so what should this really be? michael@0: bool haveRight = michael@0: border->GetComputedBorderWidth(NS_SIDE_RIGHT) != 0 || michael@0: !nsLayoutUtils::IsPaddingZero(padding->mPadding.GetRight()) || michael@0: !IsMarginZero(margin->mMargin.GetRight()); michael@0: bool haveLeft = michael@0: border->GetComputedBorderWidth(NS_SIDE_LEFT) != 0 || michael@0: !nsLayoutUtils::IsPaddingZero(padding->mPadding.GetLeft()) || michael@0: !IsMarginZero(margin->mMargin.GetLeft()); michael@0: if (haveLeft || haveRight) { michael@0: if (GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) { michael@0: bool haveStart, haveEnd; michael@0: if (NS_STYLE_DIRECTION_LTR == StyleVisibility()->mDirection) { michael@0: haveStart = haveLeft; michael@0: haveEnd = haveRight; michael@0: } else { michael@0: haveStart = haveRight; michael@0: haveEnd = haveLeft; michael@0: } michael@0: // For ib-split frames, ignore things we know we'll skip in GetSkipSides. michael@0: // XXXbz should we be doing this for non-ib-split frames too, in a more michael@0: // general way? michael@0: michael@0: // Get the first continuation eagerly, as a performance optimization, to michael@0: // avoid having to get it twice.. michael@0: nsIFrame* firstCont = FirstContinuation(); michael@0: return michael@0: (!haveStart || firstCont->FrameIsNonFirstInIBSplit()) && michael@0: (!haveEnd || firstCont->FrameIsNonLastInIBSplit()); michael@0: } michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: nsInlineFrame::IsEmpty() michael@0: { michael@0: if (!IsSelfEmpty()) { michael@0: return false; michael@0: } michael@0: michael@0: for (nsIFrame *kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) { michael@0: if (!kid->IsEmpty()) michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: nsIFrame::FrameSearchResult michael@0: nsInlineFrame::PeekOffsetCharacter(bool aForward, int32_t* aOffset, michael@0: bool aRespectClusters) michael@0: { michael@0: // Override the implementation in nsFrame, to skip empty inline frames michael@0: NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range"); michael@0: int32_t startOffset = *aOffset; michael@0: if (startOffset < 0) michael@0: startOffset = 1; michael@0: if (aForward == (startOffset == 0)) { michael@0: // We're before the frame and moving forward, or after it and moving backwards: michael@0: // skip to the other side, but keep going. michael@0: *aOffset = 1 - startOffset; michael@0: } michael@0: return CONTINUE; michael@0: } michael@0: michael@0: void michael@0: nsInlineFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) michael@0: { michael@0: BuildDisplayListForInline(aBuilder, aDirtyRect, aLists); michael@0: michael@0: // The sole purpose of this is to trigger display of the selection michael@0: // window for Named Anchors, which don't have any children and michael@0: // normally don't have any size, but in Editor we use CSS to display michael@0: // an image to represent this "hidden" element. michael@0: if (!mFrames.FirstChild()) { michael@0: DisplaySelectionOverlay(aBuilder, aLists.Content()); michael@0: } michael@0: } michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: // Reflow methods michael@0: michael@0: /* virtual */ void michael@0: nsInlineFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext, michael@0: nsIFrame::InlineMinWidthData *aData) michael@0: { michael@0: DoInlineIntrinsicWidth(aRenderingContext, aData, nsLayoutUtils::MIN_WIDTH); michael@0: } michael@0: michael@0: /* virtual */ void michael@0: nsInlineFrame::AddInlinePrefWidth(nsRenderingContext *aRenderingContext, michael@0: nsIFrame::InlinePrefWidthData *aData) michael@0: { michael@0: DoInlineIntrinsicWidth(aRenderingContext, aData, nsLayoutUtils::PREF_WIDTH); michael@0: } michael@0: michael@0: /* virtual */ nsSize michael@0: nsInlineFrame::ComputeSize(nsRenderingContext *aRenderingContext, michael@0: nsSize aCBSize, nscoord aAvailableWidth, michael@0: nsSize aMargin, nsSize aBorder, nsSize aPadding, michael@0: uint32_t aFlags) michael@0: { michael@0: // Inlines and text don't compute size before reflow. michael@0: return nsSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE); michael@0: } michael@0: michael@0: nsRect michael@0: nsInlineFrame::ComputeTightBounds(gfxContext* aContext) const michael@0: { michael@0: // be conservative michael@0: if (StyleContext()->HasTextDecorationLines()) { michael@0: return GetVisualOverflowRect(); michael@0: } michael@0: return ComputeSimpleTightBounds(aContext); michael@0: } michael@0: michael@0: void michael@0: nsInlineFrame::ReparentFloatsForInlineChild(nsIFrame* aOurLineContainer, michael@0: nsIFrame* aFrame, michael@0: bool aReparentSiblings) michael@0: { michael@0: // XXXbz this would be better if it took a nsFrameList or a frame michael@0: // list slice.... michael@0: NS_ASSERTION(aOurLineContainer->GetNextContinuation() || michael@0: aOurLineContainer->GetPrevContinuation(), michael@0: "Don't call this when we have no continuation, it's a waste"); michael@0: if (!aFrame) { michael@0: NS_ASSERTION(aReparentSiblings, "Why did we get called?"); michael@0: return; michael@0: } michael@0: michael@0: nsIFrame* ancestor = aFrame; michael@0: do { michael@0: ancestor = ancestor->GetParent(); michael@0: if (!ancestor) michael@0: return; michael@0: } while (!ancestor->IsFloatContainingBlock()); michael@0: michael@0: if (ancestor == aOurLineContainer) michael@0: return; michael@0: michael@0: nsBlockFrame* ourBlock = nsLayoutUtils::GetAsBlock(aOurLineContainer); michael@0: NS_ASSERTION(ourBlock, "Not a block, but broke vertically?"); michael@0: nsBlockFrame* frameBlock = nsLayoutUtils::GetAsBlock(ancestor); michael@0: NS_ASSERTION(frameBlock, "ancestor not a block"); michael@0: michael@0: while (true) { michael@0: ourBlock->ReparentFloats(aFrame, frameBlock, false); michael@0: michael@0: if (!aReparentSiblings) michael@0: return; michael@0: nsIFrame* next = aFrame->GetNextSibling(); michael@0: if (!next) michael@0: return; michael@0: if (next->GetParent() == aFrame->GetParent()) { michael@0: aFrame = next; michael@0: continue; michael@0: } michael@0: // This is paranoid and will hardly ever get hit ... but we can't actually michael@0: // trust that the frames in the sibling chain all have the same parent, michael@0: // because lazy reparenting may be going on. If we find a different michael@0: // parent we need to redo our analysis. michael@0: ReparentFloatsForInlineChild(aOurLineContainer, next, aReparentSiblings); michael@0: return; michael@0: } michael@0: } michael@0: michael@0: static void michael@0: ReparentChildListStyle(nsPresContext* aPresContext, michael@0: const nsFrameList::Slice& aFrames, michael@0: nsIFrame* aParentFrame) michael@0: { michael@0: RestyleManager* restyleManager = aPresContext->RestyleManager(); michael@0: michael@0: for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) { michael@0: NS_ASSERTION(e.get()->GetParent() == aParentFrame, "Bogus parentage"); michael@0: restyleManager->ReparentStyleContext(e.get()); michael@0: nsLayoutUtils::MarkDescendantsDirty(e.get()); michael@0: } michael@0: } michael@0: michael@0: nsresult michael@0: nsInlineFrame::Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: DO_GLOBAL_REFLOW_COUNT("nsInlineFrame"); michael@0: DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus); michael@0: if (nullptr == aReflowState.mLineLayout) { michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: if (IsFrameTreeTooDeep(aReflowState, aMetrics, aStatus)) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: bool lazilySetParentPointer = false; michael@0: michael@0: nsIFrame* lineContainer = aReflowState.mLineLayout->LineContainerFrame(); michael@0: michael@0: // Check for an overflow list with our prev-in-flow michael@0: nsInlineFrame* prevInFlow = (nsInlineFrame*)GetPrevInFlow(); michael@0: if (prevInFlow) { michael@0: AutoFrameListPtr prevOverflowFrames(aPresContext, michael@0: prevInFlow->StealOverflowFrames()); michael@0: if (prevOverflowFrames) { michael@0: // When pushing and pulling frames we need to check for whether any michael@0: // views need to be reparented. michael@0: nsContainerFrame::ReparentFrameViewList(*prevOverflowFrames, prevInFlow, michael@0: this); michael@0: michael@0: // Check if we should do the lazilySetParentPointer optimization. michael@0: // Only do it in simple cases where we're being reflowed for the michael@0: // first time, nothing (e.g. bidi resolution) has already given michael@0: // us children, and there's no next-in-flow, so all our frames michael@0: // will be taken from prevOverflowFrames. michael@0: if ((GetStateBits() & NS_FRAME_FIRST_REFLOW) && mFrames.IsEmpty() && michael@0: !GetNextInFlow()) { michael@0: // If our child list is empty, just put the new frames into it. michael@0: // Note that we don't set the parent pointer for the new frames. Instead wait michael@0: // to do this until we actually reflow the frame. If the overflow list contains michael@0: // thousands of frames this is a big performance issue (see bug #5588) michael@0: mFrames.SetFrames(*prevOverflowFrames); michael@0: lazilySetParentPointer = true; michael@0: } else { michael@0: // Assign all floats to our block if necessary michael@0: if (lineContainer && lineContainer->GetPrevContinuation()) { michael@0: ReparentFloatsForInlineChild(lineContainer, michael@0: prevOverflowFrames->FirstChild(), michael@0: true); michael@0: } michael@0: // Insert the new frames at the beginning of the child list michael@0: // and set their parent pointer michael@0: const nsFrameList::Slice& newFrames = michael@0: mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); michael@0: // If our prev in flow was under the first continuation of a first-line michael@0: // frame then we need to reparent the style contexts to remove the michael@0: // the special first-line styling. In the lazilySetParentPointer case michael@0: // we reparent the style contexts when we set their parents in michael@0: // nsInlineFrame::ReflowFrames and nsInlineFrame::ReflowInlineFrame. michael@0: if (aReflowState.mLineLayout->GetInFirstLine()) { michael@0: ReparentChildListStyle(aPresContext, newFrames, this); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: // It's also possible that we have an overflow list for ourselves michael@0: #ifdef DEBUG michael@0: if (GetStateBits() & NS_FRAME_FIRST_REFLOW) { michael@0: // If it's our initial reflow, then we should not have an overflow list. michael@0: // However, add an assertion in case we get reflowed more than once with michael@0: // the initial reflow reason michael@0: nsFrameList* overflowFrames = GetOverflowFrames(); michael@0: NS_ASSERTION(!overflowFrames || overflowFrames->IsEmpty(), michael@0: "overflow list is not empty for initial reflow"); michael@0: } michael@0: #endif michael@0: if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) { michael@0: DrainFlags flags = michael@0: lazilySetParentPointer ? eDontReparentFrames : DrainFlags(0); michael@0: if (aReflowState.mLineLayout->GetInFirstLine()) { michael@0: flags = DrainFlags(flags | eInFirstLine); michael@0: } michael@0: DrainSelfOverflowListInternal(flags, lineContainer); michael@0: } michael@0: michael@0: // Set our own reflow state (additional state above and beyond michael@0: // aReflowState) michael@0: InlineReflowState irs; michael@0: irs.mPrevFrame = nullptr; michael@0: irs.mLineContainer = lineContainer; michael@0: irs.mLineLayout = aReflowState.mLineLayout; michael@0: irs.mNextInFlow = (nsInlineFrame*) GetNextInFlow(); michael@0: irs.mSetParentPointer = lazilySetParentPointer; michael@0: michael@0: nsresult rv; michael@0: if (mFrames.IsEmpty()) { michael@0: // Try to pull over one frame before starting so that we know michael@0: // whether we have an anonymous block or not. michael@0: bool complete; michael@0: (void) PullOneFrame(aPresContext, irs, &complete); michael@0: } michael@0: michael@0: rv = ReflowFrames(aPresContext, aReflowState, irs, aMetrics, aStatus); michael@0: michael@0: ReflowAbsoluteFrames(aPresContext, aMetrics, aReflowState, aStatus); michael@0: michael@0: // Note: the line layout code will properly compute our michael@0: // overflow-rect state for us. michael@0: michael@0: NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics); michael@0: return rv; michael@0: } michael@0: michael@0: bool michael@0: nsInlineFrame::DrainSelfOverflowListInternal(DrainFlags aFlags, michael@0: nsIFrame* aLineContainer) michael@0: { michael@0: AutoFrameListPtr overflowFrames(PresContext(), StealOverflowFrames()); michael@0: if (overflowFrames) { michael@0: NS_ASSERTION(mFrames.NotEmpty(), "overflow list w/o frames"); michael@0: // The frames on our own overflowlist may have been pushed by a michael@0: // previous lazilySetParentPointer Reflow so we need to ensure the michael@0: // correct parent pointer. This is sometimes skipped by Reflow. michael@0: if (!(aFlags & eDontReparentFrames)) { michael@0: nsIFrame* firstChild = overflowFrames->FirstChild(); michael@0: if (aLineContainer && aLineContainer->GetPrevContinuation()) { michael@0: ReparentFloatsForInlineChild(aLineContainer, firstChild, true); michael@0: } michael@0: const bool inFirstLine = (aFlags & eInFirstLine); michael@0: RestyleManager* restyleManager = PresContext()->RestyleManager(); michael@0: for (nsIFrame* f = firstChild; f; f = f->GetNextSibling()) { michael@0: f->SetParent(this); michael@0: if (inFirstLine) { michael@0: restyleManager->ReparentStyleContext(f); michael@0: nsLayoutUtils::MarkDescendantsDirty(f); michael@0: } michael@0: } michael@0: } michael@0: bool result = !overflowFrames->IsEmpty(); michael@0: mFrames.AppendFrames(nullptr, *overflowFrames); michael@0: return result; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: /* virtual */ bool michael@0: nsInlineFrame::DrainSelfOverflowList() michael@0: { michael@0: nsIFrame* lineContainer = nsLayoutUtils::FindNearestBlockAncestor(this); michael@0: // Add the eInFirstLine flag if we have a ::first-line ancestor frame. michael@0: // No need to look further than the nearest line container though. michael@0: DrainFlags flags = DrainFlags(0); michael@0: for (nsIFrame* p = GetParent(); p != lineContainer; p = p->GetParent()) { michael@0: if (p->GetType() == nsGkAtoms::lineFrame) { michael@0: flags = DrainFlags(flags | eInFirstLine); michael@0: break; michael@0: } michael@0: } michael@0: return DrainSelfOverflowListInternal(flags, lineContainer); michael@0: } michael@0: michael@0: /* virtual */ bool michael@0: nsInlineFrame::CanContinueTextRun() const michael@0: { michael@0: // We can continue a text run through an inline frame michael@0: return true; michael@0: } michael@0: michael@0: /* virtual */ void michael@0: nsInlineFrame::PullOverflowsFromPrevInFlow() michael@0: { michael@0: nsInlineFrame* prevInFlow = static_cast(GetPrevInFlow()); michael@0: if (prevInFlow) { michael@0: nsPresContext* presContext = PresContext(); michael@0: AutoFrameListPtr prevOverflowFrames(presContext, michael@0: prevInFlow->StealOverflowFrames()); michael@0: if (prevOverflowFrames) { michael@0: // Assume that our prev-in-flow has the same line container that we do. michael@0: nsContainerFrame::ReparentFrameViewList(*prevOverflowFrames, prevInFlow, michael@0: this); michael@0: mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); michael@0: } michael@0: } michael@0: } michael@0: michael@0: nsresult michael@0: nsInlineFrame::ReflowFrames(nsPresContext* aPresContext, michael@0: const nsHTMLReflowState& aReflowState, michael@0: InlineReflowState& irs, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: nsresult rv = NS_OK; michael@0: aStatus = NS_FRAME_COMPLETE; michael@0: michael@0: nsLineLayout* lineLayout = aReflowState.mLineLayout; michael@0: bool inFirstLine = aReflowState.mLineLayout->GetInFirstLine(); michael@0: RestyleManager* restyleManager = aPresContext->RestyleManager(); michael@0: WritingMode wm = aReflowState.GetWritingMode(); michael@0: nscoord startEdge = 0; michael@0: // Don't offset by our start borderpadding if we have a prev continuation or michael@0: // if we're in a part of an {ib} split other than the first one. michael@0: if (!GetPrevContinuation() && !FrameIsNonFirstInIBSplit()) { michael@0: startEdge = aReflowState.ComputedLogicalBorderPadding().IStart(wm); michael@0: } michael@0: nscoord availableISize = aReflowState.AvailableISize(); michael@0: NS_ASSERTION(availableISize != NS_UNCONSTRAINEDSIZE, michael@0: "should no longer use available widths"); michael@0: // Subtract off inline axis border+padding from availableISize michael@0: availableISize -= startEdge; michael@0: availableISize -= aReflowState.ComputedLogicalBorderPadding().IEnd(wm); michael@0: lineLayout->BeginSpan(this, &aReflowState, startEdge, michael@0: startEdge + availableISize, &mBaseline); michael@0: michael@0: // First reflow our principal children. michael@0: nsIFrame* frame = mFrames.FirstChild(); michael@0: bool done = false; michael@0: while (frame) { michael@0: // Check if we should lazily set the child frame's parent pointer. michael@0: if (irs.mSetParentPointer) { michael@0: bool havePrevBlock = michael@0: irs.mLineContainer && irs.mLineContainer->GetPrevContinuation(); michael@0: nsIFrame* child = frame; michael@0: do { michael@0: // If our block is the first in flow, then any floats under the pulled michael@0: // frame must already belong to our block. michael@0: if (havePrevBlock) { michael@0: // This has to happen before we update frame's parent; we need to michael@0: // know frame's ancestry under its old block. michael@0: // The blockChildren.ContainsFrame check performed by michael@0: // ReparentFloatsForInlineChild here may be slow, but we can't michael@0: // easily avoid it because we don't know where 'frame' originally michael@0: // came from. If we really really have to optimize this we could michael@0: // cache whether frame->GetParent() is under its containing blocks michael@0: // overflowList or not. michael@0: ReparentFloatsForInlineChild(irs.mLineContainer, child, false); michael@0: } michael@0: child->SetParent(this); michael@0: if (inFirstLine) { michael@0: restyleManager->ReparentStyleContext(child); michael@0: nsLayoutUtils::MarkDescendantsDirty(child); michael@0: } michael@0: // We also need to do the same for |frame|'s next-in-flows that are in michael@0: // the sibling list. Otherwise, if we reflow |frame| and it's complete michael@0: // we'll crash when trying to delete its next-in-flow. michael@0: // This scenario doesn't happen often, but it can happen. michael@0: nsIFrame* nextSibling = child->GetNextSibling(); michael@0: child = child->GetNextInFlow(); michael@0: if (MOZ_UNLIKELY(child)) { michael@0: while (child != nextSibling && nextSibling) { michael@0: nextSibling = nextSibling->GetNextSibling(); michael@0: } michael@0: if (!nextSibling) { michael@0: child = nullptr; michael@0: } michael@0: } michael@0: MOZ_ASSERT(!child || mFrames.ContainsFrame(child)); michael@0: } while (child); michael@0: michael@0: // Fix the parent pointer for ::first-letter child frame next-in-flows, michael@0: // so nsFirstLetterFrame::Reflow can destroy them safely (bug 401042). michael@0: nsIFrame* realFrame = nsPlaceholderFrame::GetRealFrameFor(frame); michael@0: if (realFrame->GetType() == nsGkAtoms::letterFrame) { michael@0: nsIFrame* child = realFrame->GetFirstPrincipalChild(); michael@0: if (child) { michael@0: NS_ASSERTION(child->GetType() == nsGkAtoms::textFrame, michael@0: "unexpected frame type"); michael@0: nsIFrame* nextInFlow = child->GetNextInFlow(); michael@0: for ( ; nextInFlow; nextInFlow = nextInFlow->GetNextInFlow()) { michael@0: NS_ASSERTION(nextInFlow->GetType() == nsGkAtoms::textFrame, michael@0: "unexpected frame type"); michael@0: if (mFrames.ContainsFrame(nextInFlow)) { michael@0: nextInFlow->SetParent(this); michael@0: if (inFirstLine) { michael@0: restyleManager->ReparentStyleContext(nextInFlow); michael@0: nsLayoutUtils::MarkDescendantsDirty(nextInFlow); michael@0: } michael@0: } michael@0: else { michael@0: #ifdef DEBUG michael@0: // Once we find a next-in-flow that isn't ours none of the michael@0: // remaining next-in-flows should be either. michael@0: for ( ; nextInFlow; nextInFlow = nextInFlow->GetNextInFlow()) { michael@0: NS_ASSERTION(!mFrames.ContainsFrame(nextInFlow), michael@0: "unexpected letter frame flow"); michael@0: } michael@0: #endif michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: MOZ_ASSERT(frame->GetParent() == this); michael@0: michael@0: if (!done) { michael@0: bool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); michael@0: rv = ReflowInlineFrame(aPresContext, aReflowState, irs, frame, aStatus); michael@0: done = NS_FAILED(rv) || michael@0: NS_INLINE_IS_BREAK(aStatus) || michael@0: (!reflowingFirstLetter && NS_FRAME_IS_NOT_COMPLETE(aStatus)); michael@0: if (done) { michael@0: if (!irs.mSetParentPointer) { michael@0: break; michael@0: } michael@0: // Keep reparenting the remaining siblings, but don't reflow them. michael@0: nsFrameList* pushedFrames = GetOverflowFrames(); michael@0: if (pushedFrames && pushedFrames->FirstChild() == frame) { michael@0: // Don't bother if |frame| was pushed to our overflow list. michael@0: break; michael@0: } michael@0: } else { michael@0: irs.mPrevFrame = frame; michael@0: } michael@0: } michael@0: frame = frame->GetNextSibling(); michael@0: } michael@0: michael@0: // Attempt to pull frames from our next-in-flow until we can't michael@0: if (!done && GetNextInFlow()) { michael@0: while (true) { michael@0: bool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); michael@0: bool isComplete; michael@0: if (!frame) { // Could be non-null if we pulled a first-letter frame and michael@0: // it created a continuation, since we don't push those. michael@0: frame = PullOneFrame(aPresContext, irs, &isComplete); michael@0: } michael@0: #ifdef NOISY_PUSHING michael@0: printf("%p pulled up %p\n", this, frame); michael@0: #endif michael@0: if (nullptr == frame) { michael@0: if (!isComplete) { michael@0: aStatus = NS_FRAME_NOT_COMPLETE; michael@0: } michael@0: break; michael@0: } michael@0: rv = ReflowInlineFrame(aPresContext, aReflowState, irs, frame, aStatus); michael@0: if (NS_FAILED(rv) || michael@0: NS_INLINE_IS_BREAK(aStatus) || michael@0: (!reflowingFirstLetter && NS_FRAME_IS_NOT_COMPLETE(aStatus))) { michael@0: break; michael@0: } michael@0: irs.mPrevFrame = frame; michael@0: frame = frame->GetNextSibling(); michael@0: } michael@0: } michael@0: michael@0: NS_ASSERTION(!NS_FRAME_IS_COMPLETE(aStatus) || !GetOverflowFrames(), michael@0: "We can't be complete AND have overflow frames!"); michael@0: michael@0: // If after reflowing our children they take up no area then make michael@0: // sure that we don't either. michael@0: // michael@0: // Note: CSS demands that empty inline elements still affect the michael@0: // line-height calculations. However, continuations of an inline michael@0: // that are empty we force to empty so that things like collapsed michael@0: // whitespace in an inline element don't affect the line-height. michael@0: aMetrics.ISize() = lineLayout->EndSpan(this); michael@0: michael@0: // Compute final width. michael@0: michael@0: // Make sure to not include our start border and padding if we have a prev michael@0: // continuation or if we're in a part of an {ib} split other than the first michael@0: // one. michael@0: if (!GetPrevContinuation() && !FrameIsNonFirstInIBSplit()) { michael@0: aMetrics.ISize() += aReflowState.ComputedLogicalBorderPadding().IStart(wm); michael@0: } michael@0: michael@0: /* michael@0: * We want to only apply the end border and padding if we're the last michael@0: * continuation and either not in an {ib} split or the last part of it. To michael@0: * be the last continuation we have to be complete (so that we won't get a michael@0: * next-in-flow) and have no non-fluid continuations on our continuation michael@0: * chain. michael@0: */ michael@0: if (NS_FRAME_IS_COMPLETE(aStatus) && michael@0: !LastInFlow()->GetNextContinuation() && michael@0: !FrameIsNonLastInIBSplit()) { michael@0: aMetrics.Width() += aReflowState.ComputedLogicalBorderPadding().IEnd(wm); michael@0: } michael@0: michael@0: nsRefPtr fm; michael@0: float inflation = nsLayoutUtils::FontSizeInflationFor(this); michael@0: nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm), inflation); michael@0: aReflowState.rendContext->SetFont(fm); michael@0: michael@0: if (fm) { michael@0: // Compute final height of the frame. michael@0: // michael@0: // Do things the standard css2 way -- though it's hard to find it michael@0: // in the css2 spec! It's actually found in the css1 spec section michael@0: // 4.4 (you will have to read between the lines to really see michael@0: // it). michael@0: // michael@0: // The height of our box is the sum of our font size plus the top michael@0: // and bottom border and padding. The height of children do not michael@0: // affect our height. michael@0: aMetrics.SetTopAscent(fm->MaxAscent()); michael@0: aMetrics.Height() = fm->MaxHeight(); michael@0: } else { michael@0: NS_WARNING("Cannot get font metrics - defaulting sizes to 0"); michael@0: aMetrics.SetTopAscent(aMetrics.Height() = 0); michael@0: } michael@0: aMetrics.SetTopAscent(aMetrics.TopAscent() + aReflowState.ComputedPhysicalBorderPadding().top); michael@0: aMetrics.Height() += aReflowState.ComputedPhysicalBorderPadding().top + michael@0: aReflowState.ComputedPhysicalBorderPadding().bottom; michael@0: michael@0: // For now our overflow area is zero. The real value will be michael@0: // computed in |nsLineLayout::RelativePositionFrames|. michael@0: aMetrics.mOverflowAreas.Clear(); michael@0: michael@0: #ifdef NOISY_FINAL_SIZE michael@0: ListTag(stdout); michael@0: printf(": metrics=%d,%d ascent=%d\n", michael@0: aMetrics.Width(), aMetrics.Height(), aMetrics.TopAscent()); michael@0: #endif michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: nsresult michael@0: nsInlineFrame::ReflowInlineFrame(nsPresContext* aPresContext, michael@0: const nsHTMLReflowState& aReflowState, michael@0: InlineReflowState& irs, michael@0: nsIFrame* aFrame, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: nsLineLayout* lineLayout = aReflowState.mLineLayout; michael@0: bool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); michael@0: bool pushedFrame; michael@0: nsresult rv = michael@0: lineLayout->ReflowFrame(aFrame, aStatus, nullptr, pushedFrame); michael@0: michael@0: if (NS_FAILED(rv)) { michael@0: return rv; michael@0: } michael@0: michael@0: if (NS_INLINE_IS_BREAK_BEFORE(aStatus)) { michael@0: if (aFrame != mFrames.FirstChild()) { michael@0: // Change break-before status into break-after since we have michael@0: // already placed at least one child frame. This preserves the michael@0: // break-type so that it can be propagated upward. michael@0: aStatus = NS_FRAME_NOT_COMPLETE | michael@0: NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER | michael@0: (aStatus & NS_INLINE_BREAK_TYPE_MASK); michael@0: PushFrames(aPresContext, aFrame, irs.mPrevFrame, irs); michael@0: } michael@0: else { michael@0: // Preserve reflow status when breaking-before our first child michael@0: // and propagate it upward without modification. michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: // Create a next-in-flow if needed. michael@0: if (!NS_FRAME_IS_FULLY_COMPLETE(aStatus)) { michael@0: nsIFrame* newFrame; michael@0: rv = CreateNextInFlow(aFrame, newFrame); michael@0: if (NS_FAILED(rv)) { michael@0: return rv; michael@0: } michael@0: } michael@0: michael@0: if (NS_INLINE_IS_BREAK_AFTER(aStatus)) { michael@0: nsIFrame* nextFrame = aFrame->GetNextSibling(); michael@0: if (nextFrame) { michael@0: NS_FRAME_SET_INCOMPLETE(aStatus); michael@0: PushFrames(aPresContext, nextFrame, aFrame, irs); michael@0: } michael@0: else { michael@0: // We must return an incomplete status if there are more child michael@0: // frames remaining in a next-in-flow that follows this frame. michael@0: nsInlineFrame* nextInFlow = static_cast(GetNextInFlow()); michael@0: while (nextInFlow) { michael@0: if (nextInFlow->mFrames.NotEmpty()) { michael@0: NS_FRAME_SET_INCOMPLETE(aStatus); michael@0: break; michael@0: } michael@0: nextInFlow = static_cast(nextInFlow->GetNextInFlow()); michael@0: } michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: if (!NS_FRAME_IS_FULLY_COMPLETE(aStatus) && !reflowingFirstLetter) { michael@0: nsIFrame* nextFrame = aFrame->GetNextSibling(); michael@0: if (nextFrame) { michael@0: PushFrames(aPresContext, nextFrame, aFrame, irs); michael@0: } michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsIFrame* michael@0: nsInlineFrame::PullOneFrame(nsPresContext* aPresContext, michael@0: InlineReflowState& irs, michael@0: bool* aIsComplete) michael@0: { michael@0: bool isComplete = true; michael@0: michael@0: nsIFrame* frame = nullptr; michael@0: nsInlineFrame* nextInFlow = irs.mNextInFlow; michael@0: while (nextInFlow) { michael@0: frame = nextInFlow->mFrames.FirstChild(); michael@0: if (!frame) { michael@0: // The nextInFlow's principal list has no frames, try its overflow list. michael@0: nsFrameList* overflowFrames = nextInFlow->GetOverflowFrames(); michael@0: if (overflowFrames) { michael@0: frame = overflowFrames->RemoveFirstChild(); michael@0: if (overflowFrames->IsEmpty()) { michael@0: // We're stealing the only frame - delete the overflow list. michael@0: nextInFlow->DestroyOverflowList(); michael@0: } else { michael@0: // We leave the remaining frames on the overflow list (rather than michael@0: // putting them on nextInFlow's principal list) so we don't have to michael@0: // set up the parent for them. michael@0: } michael@0: // ReparentFloatsForInlineChild needs it to be on a child list - michael@0: // we remove it again below. michael@0: nextInFlow->mFrames.SetFrames(frame); michael@0: } michael@0: } michael@0: michael@0: if (frame) { michael@0: // If our block has no next continuation, then any floats belonging to michael@0: // the pulled frame must belong to our block already. This check ensures michael@0: // we do no extra work in the common non-vertical-breaking case. michael@0: if (irs.mLineContainer && irs.mLineContainer->GetNextContinuation()) { michael@0: // The blockChildren.ContainsFrame check performed by michael@0: // ReparentFloatsForInlineChild will be fast because frame's ancestor michael@0: // will be the first child of its containing block. michael@0: ReparentFloatsForInlineChild(irs.mLineContainer, frame, false); michael@0: } michael@0: nextInFlow->mFrames.RemoveFirstChild(); michael@0: // nsFirstLineFrame::PullOneFrame calls ReparentStyleContext. michael@0: michael@0: mFrames.InsertFrame(this, irs.mPrevFrame, frame); michael@0: isComplete = false; michael@0: if (irs.mLineLayout) { michael@0: irs.mLineLayout->SetDirtyNextLine(); michael@0: } michael@0: nsContainerFrame::ReparentFrameView(frame, nextInFlow, this); michael@0: break; michael@0: } michael@0: nextInFlow = static_cast(nextInFlow->GetNextInFlow()); michael@0: irs.mNextInFlow = nextInFlow; michael@0: } michael@0: michael@0: *aIsComplete = isComplete; michael@0: return frame; michael@0: } michael@0: michael@0: void michael@0: nsInlineFrame::PushFrames(nsPresContext* aPresContext, michael@0: nsIFrame* aFromChild, michael@0: nsIFrame* aPrevSibling, michael@0: InlineReflowState& aState) michael@0: { michael@0: NS_PRECONDITION(aFromChild, "null pointer"); michael@0: NS_PRECONDITION(aPrevSibling, "pushing first child"); michael@0: NS_PRECONDITION(aPrevSibling->GetNextSibling() == aFromChild, "bad prev sibling"); michael@0: michael@0: #ifdef NOISY_PUSHING michael@0: printf("%p pushing aFromChild %p, disconnecting from prev sib %p\n", michael@0: this, aFromChild, aPrevSibling); michael@0: #endif michael@0: michael@0: // Add the frames to our overflow list (let our next in flow drain michael@0: // our overflow list when it is ready) michael@0: SetOverflowFrames(mFrames.RemoveFramesAfter(aPrevSibling)); michael@0: if (aState.mLineLayout) { michael@0: aState.mLineLayout->SetDirtyNextLine(); michael@0: } michael@0: } michael@0: michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: int michael@0: nsInlineFrame::GetLogicalSkipSides(const nsHTMLReflowState* aReflowState) const michael@0: { michael@0: int skip = 0; michael@0: if (!IsFirst()) { michael@0: nsInlineFrame* prev = (nsInlineFrame*) GetPrevContinuation(); michael@0: if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) || michael@0: (prev && (prev->mRect.height || prev->mRect.width))) { michael@0: // Prev continuation is not empty therefore we don't render our start michael@0: // border edge. michael@0: skip |= LOGICAL_SIDE_I_START; michael@0: } michael@0: else { michael@0: // If the prev continuation is empty, then go ahead and let our start michael@0: // edge border render. michael@0: } michael@0: } michael@0: if (!IsLast()) { michael@0: nsInlineFrame* next = (nsInlineFrame*) GetNextContinuation(); michael@0: if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) || michael@0: (next && (next->mRect.height || next->mRect.width))) { michael@0: // Next continuation is not empty therefore we don't render our end michael@0: // border edge. michael@0: skip |= LOGICAL_SIDE_I_END; michael@0: } michael@0: else { michael@0: // If the next continuation is empty, then go ahead and let our end michael@0: // edge border render. michael@0: } michael@0: } michael@0: michael@0: if (GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) { michael@0: // All but the last part of an {ib} split should skip the "end" side (as michael@0: // determined by this frame's direction) and all but the first part of such michael@0: // a split should skip the "start" side. But figuring out which part of michael@0: // the split we are involves getting our first continuation, which might be michael@0: // expensive. So don't bother if we already have the relevant bits set. michael@0: if (skip != LOGICAL_SIDES_I_BOTH) { michael@0: // We're missing one of the skip bits, so check whether we need to set it. michael@0: // Only get the first continuation once, as an optimization. michael@0: nsIFrame* firstContinuation = FirstContinuation(); michael@0: if (firstContinuation->FrameIsNonLastInIBSplit()) { michael@0: skip |= LOGICAL_SIDE_I_END; michael@0: } michael@0: if (firstContinuation->FrameIsNonFirstInIBSplit()) { michael@0: skip |= LOGICAL_SIDE_I_START; michael@0: } michael@0: } michael@0: } michael@0: michael@0: return skip; michael@0: } michael@0: michael@0: nscoord michael@0: nsInlineFrame::GetBaseline() const michael@0: { michael@0: return mBaseline; michael@0: } michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: a11y::AccType michael@0: nsInlineFrame::AccessibleType() michael@0: { michael@0: // Broken image accessibles are created here, because layout michael@0: // replaces the image or image control frame with an inline frame michael@0: nsIAtom *tagAtom = mContent->Tag(); michael@0: if (tagAtom == nsGkAtoms::input) // Broken michael@0: return a11y::eHTMLButtonType; michael@0: if (tagAtom == nsGkAtoms::img) // Create accessible for broken michael@0: return a11y::eHyperTextType; michael@0: michael@0: return a11y::eNoType; michael@0: } michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: // nsLineFrame implementation michael@0: michael@0: nsIFrame* michael@0: NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsFirstLineFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsFirstLineFrame) michael@0: michael@0: void michael@0: nsFirstLineFrame::Init(nsIContent* aContent, nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) michael@0: { michael@0: nsInlineFrame::Init(aContent, aParent, aPrevInFlow); michael@0: if (!aPrevInFlow) { michael@0: MOZ_ASSERT(StyleContext()->GetPseudo() == nsCSSPseudoElements::firstLine); michael@0: return; michael@0: } michael@0: michael@0: // This frame is a continuation - fixup the style context if aPrevInFlow michael@0: // is the first-in-flow (the only one with a ::first-line pseudo). michael@0: if (aPrevInFlow->StyleContext()->GetPseudo() == nsCSSPseudoElements::firstLine) { michael@0: MOZ_ASSERT(FirstInFlow() == aPrevInFlow); michael@0: // Create a new style context that is a child of the parent michael@0: // style context thus removing the ::first-line style. This way michael@0: // we behave as if an anonymous (unstyled) span was the child michael@0: // of the parent frame. michael@0: nsStyleContext* parentContext = aParent->StyleContext(); michael@0: nsRefPtr newSC = PresContext()->StyleSet()-> michael@0: ResolveAnonymousBoxStyle(nsCSSAnonBoxes::mozLineFrame, parentContext); michael@0: SetStyleContext(newSC); michael@0: } else { michael@0: MOZ_ASSERT(FirstInFlow() != aPrevInFlow); michael@0: MOZ_ASSERT(aPrevInFlow->StyleContext()->GetPseudo() == michael@0: nsCSSAnonBoxes::mozLineFrame); michael@0: } michael@0: } michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: nsresult michael@0: nsFirstLineFrame::GetFrameName(nsAString& aResult) const michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("Line"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: nsIAtom* michael@0: nsFirstLineFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::lineFrame; michael@0: } michael@0: michael@0: nsIFrame* michael@0: nsFirstLineFrame::PullOneFrame(nsPresContext* aPresContext, InlineReflowState& irs, michael@0: bool* aIsComplete) michael@0: { michael@0: nsIFrame* frame = nsInlineFrame::PullOneFrame(aPresContext, irs, aIsComplete); michael@0: if (frame && !GetPrevInFlow()) { michael@0: // We are a first-line frame. Fixup the child frames michael@0: // style-context that we just pulled. michael@0: NS_ASSERTION(frame->GetParent() == this, "Incorrect parent?"); michael@0: aPresContext->RestyleManager()->ReparentStyleContext(frame); michael@0: nsLayoutUtils::MarkDescendantsDirty(frame); michael@0: } michael@0: return frame; michael@0: } michael@0: michael@0: nsresult michael@0: nsFirstLineFrame::Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: if (nullptr == aReflowState.mLineLayout) { michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: michael@0: nsIFrame* lineContainer = aReflowState.mLineLayout->LineContainerFrame(); michael@0: michael@0: // Check for an overflow list with our prev-in-flow michael@0: nsFirstLineFrame* prevInFlow = (nsFirstLineFrame*)GetPrevInFlow(); michael@0: if (prevInFlow) { michael@0: AutoFrameListPtr prevOverflowFrames(aPresContext, michael@0: prevInFlow->StealOverflowFrames()); michael@0: if (prevOverflowFrames) { michael@0: // Assign all floats to our block if necessary michael@0: if (lineContainer && lineContainer->GetPrevContinuation()) { michael@0: ReparentFloatsForInlineChild(lineContainer, michael@0: prevOverflowFrames->FirstChild(), michael@0: true); michael@0: } michael@0: const nsFrameList::Slice& newFrames = michael@0: mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); michael@0: ReparentChildListStyle(aPresContext, newFrames, this); michael@0: } michael@0: } michael@0: michael@0: // It's also possible that we have an overflow list for ourselves. michael@0: DrainSelfOverflowList(); michael@0: michael@0: // Set our own reflow state (additional state above and beyond michael@0: // aReflowState) michael@0: InlineReflowState irs; michael@0: irs.mPrevFrame = nullptr; michael@0: irs.mLineContainer = lineContainer; michael@0: irs.mLineLayout = aReflowState.mLineLayout; michael@0: irs.mNextInFlow = (nsInlineFrame*) GetNextInFlow(); michael@0: michael@0: nsresult rv; michael@0: bool wasEmpty = mFrames.IsEmpty(); michael@0: if (wasEmpty) { michael@0: // Try to pull over one frame before starting so that we know michael@0: // whether we have an anonymous block or not. michael@0: bool complete; michael@0: PullOneFrame(aPresContext, irs, &complete); michael@0: } michael@0: michael@0: if (nullptr == GetPrevInFlow()) { michael@0: // XXX This is pretty sick, but what we do here is to pull-up, in michael@0: // advance, all of the next-in-flows children. We re-resolve their michael@0: // style while we are at at it so that when we reflow they have michael@0: // the right style. michael@0: // michael@0: // All of this is so that text-runs reflow properly. michael@0: irs.mPrevFrame = mFrames.LastChild(); michael@0: for (;;) { michael@0: bool complete; michael@0: nsIFrame* frame = PullOneFrame(aPresContext, irs, &complete); michael@0: if (!frame) { michael@0: break; michael@0: } michael@0: irs.mPrevFrame = frame; michael@0: } michael@0: irs.mPrevFrame = nullptr; michael@0: } michael@0: michael@0: NS_ASSERTION(!aReflowState.mLineLayout->GetInFirstLine(), michael@0: "Nested first-line frames? BOGUS"); michael@0: aReflowState.mLineLayout->SetInFirstLine(true); michael@0: rv = ReflowFrames(aPresContext, aReflowState, irs, aMetrics, aStatus); michael@0: aReflowState.mLineLayout->SetInFirstLine(false); michael@0: michael@0: ReflowAbsoluteFrames(aPresContext, aMetrics, aReflowState, aStatus); michael@0: michael@0: // Note: the line layout code will properly compute our overflow state for us michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: /* virtual */ void michael@0: nsFirstLineFrame::PullOverflowsFromPrevInFlow() michael@0: { michael@0: nsFirstLineFrame* prevInFlow = static_cast(GetPrevInFlow()); michael@0: if (prevInFlow) { michael@0: nsPresContext* presContext = PresContext(); michael@0: AutoFrameListPtr prevOverflowFrames(presContext, michael@0: prevInFlow->StealOverflowFrames()); michael@0: if (prevOverflowFrames) { michael@0: // Assume that our prev-in-flow has the same line container that we do. michael@0: const nsFrameList::Slice& newFrames = michael@0: mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); michael@0: ReparentChildListStyle(presContext, newFrames, this); michael@0: } michael@0: } michael@0: } michael@0: michael@0: /* virtual */ bool michael@0: nsFirstLineFrame::DrainSelfOverflowList() michael@0: { michael@0: AutoFrameListPtr overflowFrames(PresContext(), StealOverflowFrames()); michael@0: if (overflowFrames) { michael@0: NS_ASSERTION(mFrames.NotEmpty(), "overflow list w/o frames"); michael@0: michael@0: bool result = !overflowFrames->IsEmpty(); michael@0: const nsFrameList::Slice& newFrames = michael@0: mFrames.AppendFrames(nullptr, *overflowFrames); michael@0: ReparentChildListStyle(PresContext(), newFrames, this); michael@0: return result; michael@0: } michael@0: return false; michael@0: }