/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Mozilla Communicator client code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ /* rendering object for CSS display:inline objects */ #include "nsCOMPtr.h" #include "nsInlineFrame.h" #include "nsBlockFrame.h" #include "nsHTMLAtoms.h" #include "nsHTMLParts.h" #include "nsStyleContext.h" #include "nsIPresShell.h" #include "nsPresContext.h" #include "nsIRenderingContext.h" #include "nsIFontMetrics.h" #include "nsAbsoluteContainingBlock.h" #include "nsLayoutAtoms.h" #include "nsCSSAnonBoxes.h" #include "nsReflowPath.h" #include "nsAutoPtr.h" #include "nsFrameManager.h" #ifdef ACCESSIBILITY #include "nsIServiceManager.h" #include "nsIAccessibilityService.h" #endif #include "nsDisplayList.h" #ifdef DEBUG #undef NOISY_PUSHING #endif NS_DEFINE_IID(kInlineFrameCID, NS_INLINE_FRAME_CID); ////////////////////////////////////////////////////////////////////// // Basic nsInlineFrame methods nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) { return new (aPresShell) nsInlineFrame(aContext); } NS_IMETHODIMP nsInlineFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) { if (nsnull == aInstancePtr) { return NS_ERROR_NULL_POINTER; } if (aIID.Equals(kInlineFrameCID)) { nsInlineFrame* tmp = this; *aInstancePtr = (void*) tmp; return NS_OK; } return nsInlineFrameSuper::QueryInterface(aIID, aInstancePtr); } #ifdef DEBUG NS_IMETHODIMP nsInlineFrame::GetFrameName(nsAString& aResult) const { return MakeFrameName(NS_LITERAL_STRING("Inline"), aResult); } #endif nsIAtom* nsInlineFrame::GetType() const { return nsLayoutAtoms::inlineFrame; } PRBool nsInlineFrame::IsFrameOfType(PRUint32 aFlags) const { return !(aFlags & ~nsIFrame::eBidiInlineContainer); } inline PRBool IsPaddingZero(nsStyleUnit aUnit, nsStyleCoord &aCoord) { return (aUnit == eStyleUnit_Null || (aUnit == eStyleUnit_Coord && aCoord.GetCoordValue() == 0) || (aUnit == eStyleUnit_Percent && aCoord.GetPercentValue() == 0.0)); } inline PRBool IsMarginZero(nsStyleUnit aUnit, nsStyleCoord &aCoord) { return (aUnit == eStyleUnit_Null || aUnit == eStyleUnit_Auto || (aUnit == eStyleUnit_Coord && aCoord.GetCoordValue() == 0) || (aUnit == eStyleUnit_Percent && aCoord.GetPercentValue() == 0.0)); } /* virtual */ PRBool nsInlineFrame::IsSelfEmpty() { #if 0 // I used to think inline frames worked this way, but it seems they // don't. At least not in our codebase. if (GetPresContext()->CompatibilityMode() == eCompatibility_FullStandards) { return PR_FALSE; } #endif const nsStyleMargin* margin = GetStyleMargin(); const nsStyleBorder* border = GetStyleBorder(); const nsStylePadding* padding = GetStylePadding(); nsStyleCoord coord; // XXX Top and bottom removed, since they shouldn't affect things, but this // doesn't really match with nsLineLayout.cpp's setting of // ZeroEffectiveSpanBox, anymore, so what should this really be? if (border->GetBorderWidth(NS_SIDE_RIGHT) != 0 || border->GetBorderWidth(NS_SIDE_LEFT) != 0 || !IsPaddingZero(padding->mPadding.GetRightUnit(), padding->mPadding.GetRight(coord)) || !IsPaddingZero(padding->mPadding.GetLeftUnit(), padding->mPadding.GetLeft(coord)) || !IsMarginZero(margin->mMargin.GetRightUnit(), margin->mMargin.GetRight(coord)) || !IsMarginZero(margin->mMargin.GetLeftUnit(), margin->mMargin.GetLeft(coord))) { return PR_FALSE; } return PR_TRUE; } PRBool nsInlineFrame::IsEmpty() { if (!IsSelfEmpty()) { return PR_FALSE; } for (nsIFrame *kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) { if (!kid->IsEmpty()) return PR_FALSE; } return PR_TRUE; } PRBool nsInlineFrame::PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset) { // Override the implementation in nsFrame, to skip empty inline frames NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range"); PRInt32 startOffset = *aOffset; if (startOffset < 0) startOffset = 1; if (aForward == (startOffset == 0)) { // We're before the frame and moving forward, or after it and moving backwards: // skip to the other side, but keep going. *aOffset = 1 - startOffset; } return PR_FALSE; } NS_IMETHODIMP nsInlineFrame::AppendFrames(nsIAtom* aListName, nsIFrame* aFrameList) { if (nsnull != aListName) { #ifdef IBMBIDI if (aListName != nsLayoutAtoms::nextBidi) #endif { NS_ERROR("unexpected child list"); return NS_ERROR_INVALID_ARG; } } if (aFrameList) { mFrames.AppendFrames(this, aFrameList); // Ask the parent frame to reflow me. #ifdef IBMBIDI if (nsnull == aListName) #endif ReflowDirtyChild(GetPresContext()->PresShell(), nsnull); } return NS_OK; } NS_IMETHODIMP nsInlineFrame::InsertFrames(nsIAtom* aListName, nsIFrame* aPrevFrame, nsIFrame* aFrameList) { NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this, "inserting after sibling frame with different parent"); if (nsnull != aListName) { #ifdef IBMBIDI if (aListName != nsLayoutAtoms::nextBidi) #endif { NS_ERROR("unexpected child list"); return NS_ERROR_INVALID_ARG; } } if (aFrameList) { // Insert frames after aPrevFrame mFrames.InsertFrames(this, aPrevFrame, aFrameList); #ifdef IBMBIDI if (nsnull == aListName) #endif // Ask the parent frame to reflow me. ReflowDirtyChild(GetPresContext()->PresShell(), nsnull); } return NS_OK; } NS_IMETHODIMP nsInlineFrame::RemoveFrame(nsIAtom* aListName, nsIFrame* aOldFrame) { if (nsnull != aListName) { #ifdef IBMBIDI if (nsLayoutAtoms::nextBidi != aListName) #endif { NS_ERROR("unexpected child list"); return NS_ERROR_INVALID_ARG; } } if (aOldFrame) { // Loop and destroy the frame and all of its continuations. // If the frame we are removing is a brFrame, we need a reflow so // the line the brFrame was on can attempt to pull up any frames // that can fit from lines below it. PRBool generateReflowCommand = aOldFrame->GetType() == nsLayoutAtoms::brFrame; nsInlineFrame* parent = NS_STATIC_CAST(nsInlineFrame*, aOldFrame->GetParent()); while (aOldFrame) { #ifdef IBMBIDI if (nsLayoutAtoms::nextBidi != aListName) { #endif // If the frame being removed has zero size then don't bother // generating a reflow command, otherwise make sure we do. nsRect bbox = aOldFrame->GetRect(); if (bbox.width || bbox.height) { generateReflowCommand = PR_TRUE; } #ifdef IBMBIDI } #endif // When the parent is an inline frame we have a simple task - just // remove the frame from its parents list and generate a reflow // command. nsIFrame* oldFrameNextContinuation = aOldFrame->GetNextContinuation(); parent->mFrames.DestroyFrame(aOldFrame); aOldFrame = oldFrameNextContinuation; if (aOldFrame) { parent = NS_STATIC_CAST(nsInlineFrame*, aOldFrame->GetParent()); } } if (generateReflowCommand) { // Ask the parent frame to reflow me. ReflowDirtyChild(GetPresContext()->PresShell(), nsnull); } } return NS_OK; } NS_IMETHODIMP nsInlineFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { nsresult rv = nsHTMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists); NS_ENSURE_SUCCESS(rv, rv); // The sole purpose of this is to trigger display of the selection // window for Named Anchors, which don't have any children and // normally don't have any size, but in Editor we use CSS to display // an image to represent this "hidden" element. if (!mFrames.FirstChild()) { rv = DisplaySelectionOverlay(aBuilder, aLists); } return rv; } ////////////////////////////////////////////////////////////////////// // Reflow methods NS_IMETHODIMP nsInlineFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aMetrics, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { DO_GLOBAL_REFLOW_COUNT("nsInlineFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus); if (nsnull == aReflowState.mLineLayout) { return NS_ERROR_INVALID_ARG; } PRBool lazilySetParentPointer = PR_FALSE; // Check for an overflow list with our prev-in-flow nsInlineFrame* prevInFlow = (nsInlineFrame*)GetPrevInFlow(); if (nsnull != prevInFlow) { nsIFrame* prevOverflowFrames = prevInFlow->GetOverflowFrames(aPresContext, PR_TRUE); if (prevOverflowFrames) { // When pushing and pulling frames we need to check for whether any // views need to be reparented. nsHTMLContainerFrame::ReparentFrameViewList(aPresContext, prevOverflowFrames, prevInFlow, this); if (aReflowState.reason == eReflowReason_Initial) { // If it's the initial reflow, then our child list must be empty, so // just set the child list rather than calling InsertFrame(). This avoids // having to get the last child frame in the list. // Note that we don't set the parent pointer for the new frames. Instead wait // to do this until we actually reflow the frame. If the overflow list contains // thousands of frames this is a big performance issue (see bug #5588) NS_ASSERTION(mFrames.IsEmpty(), "child list is not empty for initial reflow"); mFrames.SetFrames(prevOverflowFrames); lazilySetParentPointer = PR_TRUE; } else { // Insert the new frames at the beginning of the child list // and set their parent pointer mFrames.InsertFrames(this, nsnull, prevOverflowFrames); } } } // It's also possible that we have an overflow list for ourselves #ifdef DEBUG if (aReflowState.reason == eReflowReason_Initial) { // If it's our initial reflow, then we should not have an overflow list. // However, add an assertion in case we get reflowed more than once with // the initial reflow reason nsIFrame* overflowFrames = GetOverflowFrames(aPresContext, PR_FALSE); NS_ASSERTION(!overflowFrames, "overflow list is not empty for initial reflow"); } #endif if (aReflowState.reason != eReflowReason_Initial) { nsIFrame* overflowFrames = GetOverflowFrames(aPresContext, PR_TRUE); if (overflowFrames) { NS_ASSERTION(mFrames.NotEmpty(), "overflow list w/o frames"); // Because we lazily set the parent pointer of child frames we get from // our prev-in-flow's overflow list, it's possible that we have not set // the parent pointer for these frames. Check the first frame to see, and // if we haven't set the parent pointer then set it now mFrames.AppendFrames(overflowFrames->GetParent() == this ? nsnull : this, overflowFrames); } } if (IsFrameTreeTooDeep(aReflowState, aMetrics)) { #ifdef DEBUG_kipp { extern char* nsPresShell_ReflowStackPointerTop; char marker; char* newsp = (char*) ▮ printf("XXX: frame tree is too deep; approx stack size = %d\n", nsPresShell_ReflowStackPointerTop - newsp); } #endif aStatus = NS_FRAME_COMPLETE; return NS_OK; } // Set our own reflow state (additional state above and beyond // aReflowState) InlineReflowState irs; irs.mPrevFrame = nsnull; irs.mNextInFlow = (nsInlineFrame*) GetNextInFlow(); irs.mSetParentPointer = lazilySetParentPointer; nsresult rv; if (mFrames.IsEmpty()) { // Try to pull over one frame before starting so that we know // whether we have an anonymous block or not. PRBool complete; (void) PullOneFrame(aPresContext, irs, &complete); } rv = ReflowFrames(aPresContext, aReflowState, irs, aMetrics, aStatus); // Note: the line layout code will properly compute our // NS_FRAME_OUTSIDE_CHILDREN state for us. NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics); return rv; } NS_IMETHODIMP nsInlineFrame::CanContinueTextRun(PRBool& aContinueTextRun) const { // We can continue a text run through an inline frame aContinueTextRun = PR_TRUE; return NS_OK; } NS_IMETHODIMP nsInlineFrame::ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild) { // The inline container frame does not handle the reflow // request. It passes it up to its parent container. // If you don't already have dirty children, if (!(mState & NS_FRAME_HAS_DIRTY_CHILDREN)) { if (mParent) { // Record that you are dirty and have dirty children mState |= NS_FRAME_IS_DIRTY; mState |= NS_FRAME_HAS_DIRTY_CHILDREN; // Pass the reflow request up to the parent mParent->ReflowDirtyChild(aPresShell, this); } else { NS_ERROR("No parent to pass the reflow request up to."); } } return NS_OK; } nsresult nsInlineFrame::ReflowFrames(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, InlineReflowState& irs, nsHTMLReflowMetrics& aMetrics, nsReflowStatus& aStatus) { nsresult rv = NS_OK; aStatus = NS_FRAME_COMPLETE; nsLineLayout* lineLayout = aReflowState.mLineLayout; PRBool ltr = (NS_STYLE_DIRECTION_LTR == aReflowState.mStyleVisibility->mDirection); nscoord leftEdge = 0; if (nsnull == GetPrevContinuation()) { leftEdge = ltr ? aReflowState.mComputedBorderPadding.left : aReflowState.mComputedBorderPadding.right; } nscoord availableWidth = aReflowState.availableWidth; if (NS_UNCONSTRAINEDSIZE != availableWidth) { // Subtract off left and right border+padding from availableWidth availableWidth -= leftEdge; availableWidth -= ltr ? aReflowState.mComputedBorderPadding.right : aReflowState.mComputedBorderPadding.left; availableWidth = PR_MAX(0, availableWidth); } lineLayout->BeginSpan(this, &aReflowState, leftEdge, leftEdge + availableWidth); // First reflow our current children nsIFrame* frame = mFrames.FirstChild(); PRBool done = PR_FALSE; while (nsnull != frame) { PRBool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); // Check if we should lazily set the child frame's parent pointer if (irs.mSetParentPointer) { frame->SetParent(this); // We also need to check if frame has a next-in-flow. If it does, then set // its parent frame pointer, too. Otherwise, if we reflow frame and it's // complete we'll fail when deleting its next-in-flow which is no longer // needed. This scenario doesn't happen often, but it can happen nsIFrame* nextInFlow = frame->GetNextInFlow(); while (nextInFlow) { // Since we only do lazy setting of parent pointers for the frame's // initial reflow, this frame can't have a next-in-flow. That means // the continuing child frame must be in our child list as well. If // not, then something is wrong NS_ASSERTION(mFrames.ContainsFrame(nextInFlow), "unexpected flow"); nextInFlow->SetParent(this); nextInFlow = nextInFlow->GetNextInFlow(); } } rv = ReflowInlineFrame(aPresContext, aReflowState, irs, frame, aStatus); if (NS_FAILED(rv)) { done = PR_TRUE; break; } if (NS_INLINE_IS_BREAK(aStatus) || (!reflowingFirstLetter && NS_FRAME_IS_NOT_COMPLETE(aStatus))) { done = PR_TRUE; break; } irs.mPrevFrame = frame; frame = frame->GetNextSibling(); } // Attempt to pull frames from our next-in-flow until we can't if (!done && (nsnull != GetNextInFlow())) { while (!done) { PRBool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); PRBool isComplete; frame = PullOneFrame(aPresContext, irs, &isComplete); #ifdef NOISY_PUSHING printf("%p pulled up %p\n", this, frame); #endif if (nsnull == frame) { if (!isComplete) { aStatus = NS_FRAME_NOT_COMPLETE; } break; } rv = ReflowInlineFrame(aPresContext, aReflowState, irs, frame, aStatus); if (NS_FAILED(rv)) { done = PR_TRUE; break; } if (NS_INLINE_IS_BREAK(aStatus) || (!reflowingFirstLetter && NS_FRAME_IS_NOT_COMPLETE(aStatus))) { done = PR_TRUE; break; } irs.mPrevFrame = frame; } } #ifdef DEBUG if (NS_FRAME_IS_COMPLETE(aStatus)) { // We can't be complete AND have overflow frames! nsIFrame* overflowFrames = GetOverflowFrames(aPresContext, PR_FALSE); NS_ASSERTION(!overflowFrames, "whoops"); } #endif // If after reflowing our children they take up no area then make // sure that we don't either. // // Note: CSS demands that empty inline elements still affect the // line-height calculations. However, continuations of an inline // that are empty we force to empty so that things like collapsed // whitespace in an inline element don't affect the line-height. nsSize size; lineLayout->EndSpan(this, size, aMetrics.mComputeMEW ? &aMetrics.mMaxElementWidth : nsnull); if ((0 == size.height) && (0 == size.width) && ((nsnull != GetPrevInFlow()) || (nsnull != GetNextInFlow()))) { // This is a continuation of a previous inline. Therefore make // sure we don't affect the line-height. aMetrics.width = 0; aMetrics.height = 0; aMetrics.ascent = 0; aMetrics.descent = 0; if (aMetrics.mComputeMEW) { aMetrics.mMaxElementWidth = 0; } } else { // Compute final width aMetrics.width = size.width; if (nsnull == GetPrevContinuation()) { aMetrics.width += ltr ? aReflowState.mComputedBorderPadding.left : aReflowState.mComputedBorderPadding.right; } if (NS_FRAME_IS_COMPLETE(aStatus) && (!GetNextContinuation() || GetNextInFlow())) { aMetrics.width += ltr ? aReflowState.mComputedBorderPadding.right : aReflowState.mComputedBorderPadding.left; } SetFontFromStyle(aReflowState.rendContext, mStyleContext); nsCOMPtr fm; aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm)); if (fm) { // Compute final height of the frame. // // Do things the standard css2 way -- though it's hard to find it // in the css2 spec! It's actually found in the css1 spec section // 4.4 (you will have to read between the lines to really see // it). // // The height of our box is the sum of our font size plus the top // and bottom border and padding. The height of children do not // affect our height. fm->GetMaxAscent(aMetrics.ascent); fm->GetMaxDescent(aMetrics.descent); fm->GetHeight(aMetrics.height); } else { NS_WARNING("Cannot get font metrics - defaulting sizes to 0"); aMetrics.ascent = aMetrics.descent = aMetrics.height = 0; } aMetrics.ascent += aReflowState.mComputedBorderPadding.top; aMetrics.descent += aReflowState.mComputedBorderPadding.bottom; aMetrics.height += aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom; } // For now our overflow area is zero. The real value will be // computed during vertical alignment of the line we are on. aMetrics.mOverflowArea.SetRect(0, 0, 0, 0); #ifdef NOISY_FINAL_SIZE ListTag(stdout); printf(": metrics=%d,%d ascent=%d descent=%d\n", aMetrics.width, aMetrics.height, aMetrics.ascent, aMetrics.descent); if (aMetrics.mComputeMEW) { printf(" maxElementWidth %d\n", aMetrics.mMaxElementWidth); } #endif return rv; } static void SetContainsPercentAwareChild(nsIFrame *aFrame) { aFrame->AddStateBits(NS_INLINE_FRAME_CONTAINS_PERCENT_AWARE_CHILD); } static void MarkPercentAwareFrame(nsPresContext *aPresContext, nsInlineFrame *aInline, nsIFrame *aFrame) { if (aFrame->GetStateBits() & NS_FRAME_REPLACED_ELEMENT) { // aFrame is a replaced element, check it's style if (nsLineLayout::IsPercentageAwareReplacedElement(aPresContext, aFrame)) { SetContainsPercentAwareChild(aInline); } } else { if (aFrame->GetFirstChild(nsnull)) { // aFrame is an inline container frame, check my frame state if (aFrame->GetStateBits() & NS_INLINE_FRAME_CONTAINS_PERCENT_AWARE_CHILD) { SetContainsPercentAwareChild(aInline); // if a child container is effected, so am I } } // else frame is a leaf that we don't care about } } nsresult nsInlineFrame::ReflowInlineFrame(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, InlineReflowState& irs, nsIFrame* aFrame, nsReflowStatus& aStatus) { nsLineLayout* lineLayout = aReflowState.mLineLayout; PRBool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); PRBool pushedFrame; nsresult rv = lineLayout->ReflowFrame(aFrame, aStatus, nsnull, pushedFrame); /* This next block is for bug 28811 Test the child frame for %-awareness, and mark this frame with a bit if it is %-aware. Don't bother if this frame is already marked */ if (!(mState & NS_INLINE_FRAME_CONTAINS_PERCENT_AWARE_CHILD)) { MarkPercentAwareFrame(aPresContext, this, aFrame); } if (NS_FAILED(rv)) { return rv; } if (NS_INLINE_IS_BREAK(aStatus)) { if (NS_INLINE_IS_BREAK_BEFORE(aStatus)) { if (aFrame != mFrames.FirstChild()) { // Change break-before status into break-after since we have // already placed at least one child frame. This preserves the // break-type so that it can be propagated upward. aStatus = NS_FRAME_NOT_COMPLETE | NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER | (aStatus & NS_INLINE_BREAK_TYPE_MASK); PushFrames(aPresContext, aFrame, irs.mPrevFrame); } else { // Preserve reflow status when breaking-before our first child // and propagate it upward without modification. // Note: if we're lazily setting the frame pointer for our child // frames, then we need to set it now. Don't return and leave the // remaining child frames in our child list with the wrong parent // frame pointer... if (irs.mSetParentPointer) { for (nsIFrame* f = aFrame->GetNextSibling(); f; f = f->GetNextSibling()) { f->SetParent(this); } } } } else { // Break-after if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) { nsIFrame* newFrame; rv = CreateNextInFlow(aPresContext, this, aFrame, newFrame); if (NS_FAILED(rv)) { return rv; } } nsIFrame* nextFrame = aFrame->GetNextSibling(); if (nextFrame) { aStatus |= NS_FRAME_NOT_COMPLETE; PushFrames(aPresContext, nextFrame, aFrame); } else if (nsnull != GetNextInFlow()) { // We must return an incomplete status if there are more child // frames remaining in a next-in-flow that follows this frame. nsInlineFrame* nextInFlow = (nsInlineFrame*) GetNextInFlow(); while (nsnull != nextInFlow) { if (nextInFlow->mFrames.NotEmpty()) { aStatus |= NS_FRAME_NOT_COMPLETE; break; } nextInFlow = (nsInlineFrame*) nextInFlow->GetNextInFlow(); } } } } else if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) { if (nsLayoutAtoms::placeholderFrame == aFrame->GetType()) { nsBlockReflowState* blockRS = lineLayout->mBlockRS; blockRS->mBlock->SplitPlaceholder(*blockRS, aFrame); // Allow the parent to continue reflowing aStatus = NS_FRAME_COMPLETE; } else { nsIFrame* newFrame; rv = CreateNextInFlow(aPresContext, this, aFrame, newFrame); if (NS_FAILED(rv)) { return rv; } if (!reflowingFirstLetter) { nsIFrame* nextFrame = aFrame->GetNextSibling(); if (nextFrame) { PushFrames(aPresContext, nextFrame, aFrame); } } } } return rv; } nsIFrame* nsInlineFrame::PullOneFrame(nsPresContext* aPresContext, InlineReflowState& irs, PRBool* aIsComplete) { PRBool isComplete = PR_TRUE; nsIFrame* frame = nsnull; nsInlineFrame* nextInFlow = irs.mNextInFlow; while (nsnull != nextInFlow) { frame = mFrames.PullFrame(this, irs.mPrevFrame, nextInFlow->mFrames); if (nsnull != frame) { isComplete = PR_FALSE; nsHTMLContainerFrame::ReparentFrameView(aPresContext, frame, nextInFlow, this); break; } nextInFlow = (nsInlineFrame*) nextInFlow->GetNextInFlow(); irs.mNextInFlow = nextInFlow; } *aIsComplete = isComplete; return frame; } void nsInlineFrame::PushFrames(nsPresContext* aPresContext, nsIFrame* aFromChild, nsIFrame* aPrevSibling) { NS_PRECONDITION(nsnull != aFromChild, "null pointer"); NS_PRECONDITION(nsnull != aPrevSibling, "pushing first child"); NS_PRECONDITION(aPrevSibling->GetNextSibling() == aFromChild, "bad prev sibling"); #ifdef NOISY_PUSHING printf("%p pushing aFromChild %p, disconnecting from prev sib %p\n", this, aFromChild, aPrevSibling); #endif // Disconnect aFromChild from its previous sibling aPrevSibling->SetNextSibling(nsnull); // Add the frames to our overflow list (let our next in flow drain // our overflow list when it is ready) SetOverflowFrames(aPresContext, aFromChild); } ////////////////////////////////////////////////////////////////////// PRIntn nsInlineFrame::GetSkipSides() const { PRIntn skip = 0; if (!IsLeftMost()) { nsInlineFrame* prev = (nsInlineFrame*) GetPrevContinuation(); if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) || (prev && (prev->mRect.height || prev->mRect.width))) { // Prev continuation is not empty therefore we don't render our left // border edge. skip |= 1 << NS_SIDE_LEFT; } else { // If the prev continuation is empty, then go ahead and let our left // edge border render. } } if (!IsRightMost()) { nsInlineFrame* next = (nsInlineFrame*) GetNextContinuation(); if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) || (next && (next->mRect.height || next->mRect.width))) { // Next continuation is not empty therefore we don't render our right // border edge. skip |= 1 << NS_SIDE_RIGHT; } else { // If the next continuation is empty, then go ahead and let our right // edge border render. } } return skip; } #ifdef ACCESSIBILITY NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible) { // Broken image accessibles are created here, because layout // replaces the image or image control frame with an inline frame *aAccessible = nsnull; nsIAtom *tagAtom = mContent->Tag(); if ((tagAtom == nsHTMLAtoms::img || tagAtom == nsHTMLAtoms::input || tagAtom == nsHTMLAtoms::label) && mContent->IsNodeOfType(nsINode::eHTML)) { // Only get accessibility service if we're going to use it nsCOMPtr accService(do_GetService("@mozilla.org/accessibilityService;1")); if (!accService) return NS_ERROR_FAILURE; if (tagAtom == nsHTMLAtoms::input) // Broken return accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); else if (tagAtom == nsHTMLAtoms::label) // Creat accessible for