1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* rendering object for CSS display:inline objects */
41 #include "nsInlineFrame.h"
42 #include "nsBlockFrame.h"
43 #include "nsGkAtoms.h"
44 #include "nsHTMLParts.h"
45 #include "nsStyleContext.h"
46 #include "nsIPresShell.h"
47 #include "nsPresContext.h"
48 #include "nsIRenderingContext.h"
49 #include "nsIFontMetrics.h"
50 #include "nsAbsoluteContainingBlock.h"
51 #include "nsCSSAnonBoxes.h"
52 #include "nsAutoPtr.h"
53 #include "nsFrameManager.h"
55 #include "nsIServiceManager.h"
56 #include "nsIAccessibilityService.h"
58 #include "nsDisplayList.h"
65 NS_DEFINE_IID(kInlineFrameCID
, NS_INLINE_FRAME_CID
);
68 //////////////////////////////////////////////////////////////////////
70 // Basic nsInlineFrame methods
73 NS_NewInlineFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
75 return new (aPresShell
) nsInlineFrame(aContext
);
79 nsInlineFrame::QueryInterface(const nsIID
& aIID
, void** aInstancePtr
)
81 NS_PRECONDITION(aInstancePtr
, "null out param");
83 if (aIID
.Equals(kInlineFrameCID
)) {
88 return nsInlineFrameSuper::QueryInterface(aIID
, aInstancePtr
);
93 nsInlineFrame::GetFrameName(nsAString
& aResult
) const
95 return MakeFrameName(NS_LITERAL_STRING("Inline"), aResult
);
100 nsInlineFrame::GetType() const
102 return nsGkAtoms::inlineFrame
;
106 IsPaddingZero(nsStyleUnit aUnit
, const nsStyleCoord
&aCoord
)
108 return ((aUnit
== eStyleUnit_Coord
&& aCoord
.GetCoordValue() == 0) ||
109 (aUnit
== eStyleUnit_Percent
&& aCoord
.GetPercentValue() == 0.0));
113 IsMarginZero(nsStyleUnit aUnit
, const nsStyleCoord
&aCoord
)
115 return (aUnit
== eStyleUnit_Auto
||
116 (aUnit
== eStyleUnit_Coord
&& aCoord
.GetCoordValue() == 0) ||
117 (aUnit
== eStyleUnit_Percent
&& aCoord
.GetPercentValue() == 0.0));
121 nsInlineFrame::IsSelfEmpty()
124 // I used to think inline frames worked this way, but it seems they
125 // don't. At least not in our codebase.
126 if (GetPresContext()->CompatibilityMode() == eCompatibility_FullStandards
) {
130 const nsStyleMargin
* margin
= GetStyleMargin();
131 const nsStyleBorder
* border
= GetStyleBorder();
132 const nsStylePadding
* padding
= GetStylePadding();
133 // XXX Top and bottom removed, since they shouldn't affect things, but this
134 // doesn't really match with nsLineLayout.cpp's setting of
135 // ZeroEffectiveSpanBox, anymore, so what should this really be?
136 if (border
->GetActualBorderWidth(NS_SIDE_RIGHT
) != 0 ||
137 border
->GetActualBorderWidth(NS_SIDE_LEFT
) != 0 ||
138 !IsPaddingZero(padding
->mPadding
.GetRightUnit(),
139 padding
->mPadding
.GetRight()) ||
140 !IsPaddingZero(padding
->mPadding
.GetLeftUnit(),
141 padding
->mPadding
.GetLeft()) ||
142 !IsMarginZero(margin
->mMargin
.GetRightUnit(),
143 margin
->mMargin
.GetRight()) ||
144 !IsMarginZero(margin
->mMargin
.GetLeftUnit(),
145 margin
->mMargin
.GetLeft())) {
152 nsInlineFrame::IsEmpty()
154 if (!IsSelfEmpty()) {
158 for (nsIFrame
*kid
= mFrames
.FirstChild(); kid
; kid
= kid
->GetNextSibling()) {
167 nsInlineFrame::PeekOffsetCharacter(PRBool aForward
, PRInt32
* aOffset
)
169 // Override the implementation in nsFrame, to skip empty inline frames
170 NS_ASSERTION (aOffset
&& *aOffset
<= 1, "aOffset out of range");
171 PRInt32 startOffset
= *aOffset
;
174 if (aForward
== (startOffset
== 0)) {
175 // We're before the frame and moving forward, or after it and moving backwards:
176 // skip to the other side, but keep going.
177 *aOffset
= 1 - startOffset
;
183 nsInlineFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
184 const nsRect
& aDirtyRect
,
185 const nsDisplayListSet
& aLists
)
187 nsresult rv
= nsHTMLContainerFrame::BuildDisplayList(aBuilder
, aDirtyRect
, aLists
);
188 NS_ENSURE_SUCCESS(rv
, rv
);
190 // The sole purpose of this is to trigger display of the selection
191 // window for Named Anchors, which don't have any children and
192 // normally don't have any size, but in Editor we use CSS to display
193 // an image to represent this "hidden" element.
194 if (!mFrames
.FirstChild()) {
195 rv
= DisplaySelectionOverlay(aBuilder
, aLists
);
200 //////////////////////////////////////////////////////////////////////
204 nsInlineFrame::AddInlineMinWidth(nsIRenderingContext
*aRenderingContext
,
205 nsIFrame::InlineMinWidthData
*aData
)
207 DoInlineIntrinsicWidth(aRenderingContext
, aData
, nsLayoutUtils::MIN_WIDTH
);
211 nsInlineFrame::AddInlinePrefWidth(nsIRenderingContext
*aRenderingContext
,
212 nsIFrame::InlinePrefWidthData
*aData
)
214 DoInlineIntrinsicWidth(aRenderingContext
, aData
, nsLayoutUtils::PREF_WIDTH
);
218 nsInlineFrame::ComputeSize(nsIRenderingContext
*aRenderingContext
,
219 nsSize aCBSize
, nscoord aAvailableWidth
,
220 nsSize aMargin
, nsSize aBorder
, nsSize aPadding
,
223 // Inlines and text don't compute size before reflow.
224 return nsSize(NS_UNCONSTRAINEDSIZE
, NS_UNCONSTRAINEDSIZE
);
228 nsInlineFrame::ComputeTightBounds(gfxContext
* aContext
) const
231 if (GetStyleContext()->HasTextDecorations())
232 return GetOverflowRect();
233 return ComputeSimpleTightBounds(aContext
);
237 nsInlineFrame::ReparentFloatsForInlineChild(nsIFrame
* aOurLineContainer
,
239 PRBool aReparentSiblings
)
241 NS_ASSERTION(aOurLineContainer
->GetNextContinuation() ||
242 aOurLineContainer
->GetPrevContinuation(),
243 "Don't call this when we have no continuation, it's a waste");
245 NS_ASSERTION(aReparentSiblings
, "Why did we get called?");
249 nsIFrame
* ancestor
= aFrame
;
250 nsIFrame
* ancestorBlockChild
;
252 ancestorBlockChild
= ancestor
;
253 ancestor
= ancestor
->GetParent();
256 } while (!ancestor
->IsFloatContainingBlock());
258 if (ancestor
== aOurLineContainer
)
261 nsBlockFrame
* ourBlock
= nsLayoutUtils::GetAsBlock(aOurLineContainer
);
262 NS_ASSERTION(ourBlock
, "Not a block, but broke vertically?");
263 nsBlockFrame
* frameBlock
= nsLayoutUtils::GetAsBlock(ancestor
);
264 NS_ASSERTION(frameBlock
, "ancestor not a block");
266 nsFrameList
blockChildren(ancestor
->GetFirstChild(nsnull
));
267 PRBool isOverflow
= !blockChildren
.ContainsFrame(ancestorBlockChild
);
270 ourBlock
->ReparentFloats(aFrame
, frameBlock
, isOverflow
, PR_FALSE
);
272 if (!aReparentSiblings
)
274 nsIFrame
* next
= aFrame
->GetNextSibling();
277 if (next
->GetParent() == aFrame
->GetParent()) {
281 // This is paranoid and will hardly ever get hit ... but we can't actually
282 // trust that the frames in the sibling chain all have the same parent,
283 // because lazy reparenting may be going on. If we find a different
284 // parent we need to redo our analysis.
285 ReparentFloatsForInlineChild(aOurLineContainer
, next
, aReparentSiblings
);
291 nsInlineFrame::Reflow(nsPresContext
* aPresContext
,
292 nsHTMLReflowMetrics
& aMetrics
,
293 const nsHTMLReflowState
& aReflowState
,
294 nsReflowStatus
& aStatus
)
296 DO_GLOBAL_REFLOW_COUNT("nsInlineFrame");
297 DISPLAY_REFLOW(aPresContext
, this, aReflowState
, aMetrics
, aStatus
);
298 if (nsnull
== aReflowState
.mLineLayout
) {
299 return NS_ERROR_INVALID_ARG
;
302 PRBool lazilySetParentPointer
= PR_FALSE
;
304 nsIFrame
* lineContainer
= aReflowState
.mLineLayout
->GetLineContainerFrame();
306 // Check for an overflow list with our prev-in-flow
307 nsInlineFrame
* prevInFlow
= (nsInlineFrame
*)GetPrevInFlow();
308 if (nsnull
!= prevInFlow
) {
309 nsIFrame
* prevOverflowFrames
= prevInFlow
->GetOverflowFrames(aPresContext
, PR_TRUE
);
311 if (prevOverflowFrames
) {
312 // When pushing and pulling frames we need to check for whether any
313 // views need to be reparented.
314 nsHTMLContainerFrame::ReparentFrameViewList(aPresContext
, prevOverflowFrames
,
317 if (GetStateBits() & NS_FRAME_FIRST_REFLOW
) {
318 // If it's the initial reflow, then our child list must be empty, so
319 // just set the child list rather than calling InsertFrame(). This avoids
320 // having to get the last child frame in the list.
321 // Note that we don't set the parent pointer for the new frames. Instead wait
322 // to do this until we actually reflow the frame. If the overflow list contains
323 // thousands of frames this is a big performance issue (see bug #5588)
324 NS_ASSERTION(mFrames
.IsEmpty(), "child list is not empty for initial reflow");
325 mFrames
.SetFrames(prevOverflowFrames
);
326 lazilySetParentPointer
= PR_TRUE
;
328 // Assign all floats to our block if necessary
329 if (lineContainer
&& lineContainer
->GetPrevContinuation()) {
330 ReparentFloatsForInlineChild(lineContainer
, prevOverflowFrames
, PR_TRUE
);
332 // Insert the new frames at the beginning of the child list
333 // and set their parent pointer
334 mFrames
.InsertFrames(this, nsnull
, prevOverflowFrames
);
339 // It's also possible that we have an overflow list for ourselves
341 if (GetStateBits() & NS_FRAME_FIRST_REFLOW
) {
342 // If it's our initial reflow, then we should not have an overflow list.
343 // However, add an assertion in case we get reflowed more than once with
344 // the initial reflow reason
345 nsIFrame
* overflowFrames
= GetOverflowFrames(aPresContext
, PR_FALSE
);
346 NS_ASSERTION(!overflowFrames
, "overflow list is not empty for initial reflow");
349 if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW
)) {
350 nsIFrame
* overflowFrames
= GetOverflowFrames(aPresContext
, PR_TRUE
);
351 if (overflowFrames
) {
352 NS_ASSERTION(mFrames
.NotEmpty(), "overflow list w/o frames");
354 // Because we lazily set the parent pointer of child frames we get from
355 // our prev-in-flow's overflow list, it's possible that we have not set
356 // the parent pointer for these frames.
357 mFrames
.AppendFrames(this, overflowFrames
);
361 if (IsFrameTreeTooDeep(aReflowState
, aMetrics
)) {
364 extern char* nsPresShell_ReflowStackPointerTop
;
366 char* newsp
= (char*) &marker
;
367 printf("XXX: frame tree is too deep; approx stack size = %d\n",
368 nsPresShell_ReflowStackPointerTop
- newsp
);
371 aStatus
= NS_FRAME_COMPLETE
;
375 // Set our own reflow state (additional state above and beyond
377 InlineReflowState irs
;
378 irs
.mPrevFrame
= nsnull
;
379 irs
.mLineContainer
= lineContainer
;
380 irs
.mNextInFlow
= (nsInlineFrame
*) GetNextInFlow();
381 irs
.mSetParentPointer
= lazilySetParentPointer
;
384 if (mFrames
.IsEmpty()) {
385 // Try to pull over one frame before starting so that we know
386 // whether we have an anonymous block or not.
388 (void) PullOneFrame(aPresContext
, irs
, &complete
);
391 rv
= ReflowFrames(aPresContext
, aReflowState
, irs
, aMetrics
, aStatus
);
393 // Note: the line layout code will properly compute our
394 // NS_FRAME_OUTSIDE_CHILDREN state for us.
396 NS_FRAME_SET_TRUNCATION(aStatus
, aReflowState
, aMetrics
);
401 nsInlineFrame::CanContinueTextRun() const
403 // We can continue a text run through an inline frame
408 nsInlineFrame::ReflowFrames(nsPresContext
* aPresContext
,
409 const nsHTMLReflowState
& aReflowState
,
410 InlineReflowState
& irs
,
411 nsHTMLReflowMetrics
& aMetrics
,
412 nsReflowStatus
& aStatus
)
415 aStatus
= NS_FRAME_COMPLETE
;
417 nsLineLayout
* lineLayout
= aReflowState
.mLineLayout
;
418 PRBool ltr
= (NS_STYLE_DIRECTION_LTR
== aReflowState
.mStyleVisibility
->mDirection
);
419 nscoord leftEdge
= 0;
420 if (nsnull
== GetPrevContinuation()) {
421 leftEdge
= ltr
? aReflowState
.mComputedBorderPadding
.left
422 : aReflowState
.mComputedBorderPadding
.right
;
424 nscoord availableWidth
= aReflowState
.availableWidth
;
425 NS_ASSERTION(availableWidth
!= NS_UNCONSTRAINEDSIZE
,
426 "should no longer use available widths");
427 // Subtract off left and right border+padding from availableWidth
428 availableWidth
-= leftEdge
;
429 availableWidth
-= ltr
? aReflowState
.mComputedBorderPadding
.right
430 : aReflowState
.mComputedBorderPadding
.left
;
431 lineLayout
->BeginSpan(this, &aReflowState
, leftEdge
, leftEdge
+ availableWidth
);
433 // First reflow our current children
434 nsIFrame
* frame
= mFrames
.FirstChild();
435 PRBool done
= PR_FALSE
;
436 while (nsnull
!= frame
) {
437 PRBool reflowingFirstLetter
= lineLayout
->GetFirstLetterStyleOK();
439 // Check if we should lazily set the child frame's parent pointer
440 if (irs
.mSetParentPointer
) {
441 PRBool havePrevBlock
=
442 irs
.mLineContainer
&& irs
.mLineContainer
->GetPrevContinuation();
443 // If our block is the first in flow, then any floats under the pulled
444 // frame must already belong to our block.
446 // This has to happen before we update frame's parent; we need to
447 // know frame's ancestry under its old block.
448 // The blockChildren.ContainsFrame check performed by
449 // ReparentFloatsForInlineChild here may be slow, but we can't
450 // easily avoid it because we don't know where 'frame' originally
451 // came from. If we really really have to optimize this we could
452 // cache whether frame->GetParent() is under its containing blocks
453 // overflowList or not.
454 ReparentFloatsForInlineChild(irs
.mLineContainer
, frame
, PR_FALSE
);
456 frame
->SetParent(this);
457 // We also need to check if frame has a next-in-flow. If it does, then set
458 // its parent frame pointer, too. Otherwise, if we reflow frame and it's
459 // complete we'll fail when deleting its next-in-flow which is no longer
460 // needed. This scenario doesn't happen often, but it can happen
461 nsIFrame
* nextInFlow
= frame
->GetNextInFlow();
463 // Since we only do lazy setting of parent pointers for the frame's
464 // initial reflow, this frame can't have a next-in-flow. That means
465 // the continuing child frame must be in our child list as well. If
466 // not, then something is wrong
467 NS_ASSERTION(mFrames
.ContainsFrame(nextInFlow
), "unexpected flow");
469 ReparentFloatsForInlineChild(irs
.mLineContainer
, nextInFlow
, PR_FALSE
);
471 nextInFlow
->SetParent(this);
472 nextInFlow
= nextInFlow
->GetNextInFlow();
475 rv
= ReflowInlineFrame(aPresContext
, aReflowState
, irs
, frame
, aStatus
);
480 if (NS_INLINE_IS_BREAK(aStatus
) ||
481 (!reflowingFirstLetter
&& NS_FRAME_IS_NOT_COMPLETE(aStatus
))) {
485 irs
.mPrevFrame
= frame
;
486 frame
= frame
->GetNextSibling();
489 // Attempt to pull frames from our next-in-flow until we can't
490 if (!done
&& (nsnull
!= GetNextInFlow())) {
492 PRBool reflowingFirstLetter
= lineLayout
->GetFirstLetterStyleOK();
494 if (!frame
) { // Could be non-null if we pulled a first-letter frame and
495 // it created a continuation, since we don't push those.
496 frame
= PullOneFrame(aPresContext
, irs
, &isComplete
);
499 printf("%p pulled up %p\n", this, frame
);
501 if (nsnull
== frame
) {
503 aStatus
= NS_FRAME_NOT_COMPLETE
;
507 rv
= ReflowInlineFrame(aPresContext
, aReflowState
, irs
, frame
, aStatus
);
512 if (NS_INLINE_IS_BREAK(aStatus
) ||
513 (!reflowingFirstLetter
&& NS_FRAME_IS_NOT_COMPLETE(aStatus
))) {
517 irs
.mPrevFrame
= frame
;
518 frame
= frame
->GetNextSibling();
522 if (NS_FRAME_IS_COMPLETE(aStatus
)) {
523 // We can't be complete AND have overflow frames!
524 nsIFrame
* overflowFrames
= GetOverflowFrames(aPresContext
, PR_FALSE
);
525 NS_ASSERTION(!overflowFrames
, "whoops");
529 // If after reflowing our children they take up no area then make
530 // sure that we don't either.
532 // Note: CSS demands that empty inline elements still affect the
533 // line-height calculations. However, continuations of an inline
534 // that are empty we force to empty so that things like collapsed
535 // whitespace in an inline element don't affect the line-height.
536 aMetrics
.width
= lineLayout
->EndSpan(this);
538 // Compute final width
539 if (nsnull
== GetPrevContinuation()) {
540 aMetrics
.width
+= ltr
? aReflowState
.mComputedBorderPadding
.left
541 : aReflowState
.mComputedBorderPadding
.right
;
543 if (NS_FRAME_IS_COMPLETE(aStatus
) && (!GetNextContinuation() || GetNextInFlow())) {
544 aMetrics
.width
+= ltr
? aReflowState
.mComputedBorderPadding
.right
545 : aReflowState
.mComputedBorderPadding
.left
;
548 nsLayoutUtils::SetFontFromStyle(aReflowState
.rendContext
, mStyleContext
);
549 nsCOMPtr
<nsIFontMetrics
> fm
;
550 aReflowState
.rendContext
->GetFontMetrics(*getter_AddRefs(fm
));
553 // Compute final height of the frame.
555 // Do things the standard css2 way -- though it's hard to find it
556 // in the css2 spec! It's actually found in the css1 spec section
557 // 4.4 (you will have to read between the lines to really see
560 // The height of our box is the sum of our font size plus the top
561 // and bottom border and padding. The height of children do not
562 // affect our height.
563 fm
->GetMaxAscent(aMetrics
.ascent
);
564 fm
->GetHeight(aMetrics
.height
);
566 NS_WARNING("Cannot get font metrics - defaulting sizes to 0");
567 aMetrics
.ascent
= aMetrics
.height
= 0;
569 aMetrics
.ascent
+= aReflowState
.mComputedBorderPadding
.top
;
570 aMetrics
.height
+= aReflowState
.mComputedBorderPadding
.top
+
571 aReflowState
.mComputedBorderPadding
.bottom
;
573 // For now our overflow area is zero. The real value will be
574 // computed in |nsLineLayout::RelativePositionFrames|.
575 aMetrics
.mOverflowArea
.SetRect(0, 0, 0, 0);
577 #ifdef NOISY_FINAL_SIZE
579 printf(": metrics=%d,%d ascent=%d\n",
580 aMetrics
.width
, aMetrics
.height
, aMetrics
.ascent
);
587 nsInlineFrame::ReflowInlineFrame(nsPresContext
* aPresContext
,
588 const nsHTMLReflowState
& aReflowState
,
589 InlineReflowState
& irs
,
591 nsReflowStatus
& aStatus
)
593 nsLineLayout
* lineLayout
= aReflowState
.mLineLayout
;
594 PRBool reflowingFirstLetter
= lineLayout
->GetFirstLetterStyleOK();
597 lineLayout
->ReflowFrame(aFrame
, aStatus
, nsnull
, pushedFrame
);
602 if (NS_INLINE_IS_BREAK(aStatus
)) {
603 if (NS_INLINE_IS_BREAK_BEFORE(aStatus
)) {
604 if (aFrame
!= mFrames
.FirstChild()) {
605 // Change break-before status into break-after since we have
606 // already placed at least one child frame. This preserves the
607 // break-type so that it can be propagated upward.
608 aStatus
= NS_FRAME_NOT_COMPLETE
|
609 NS_INLINE_BREAK
| NS_INLINE_BREAK_AFTER
|
610 (aStatus
& NS_INLINE_BREAK_TYPE_MASK
);
611 PushFrames(aPresContext
, aFrame
, irs
.mPrevFrame
);
614 // Preserve reflow status when breaking-before our first child
615 // and propagate it upward without modification.
616 // Note: if we're lazily setting the frame pointer for our child
617 // frames, then we need to set it now. Don't return and leave the
618 // remaining child frames in our child list with the wrong parent
620 if (irs
.mSetParentPointer
) {
621 if (irs
.mLineContainer
&& irs
.mLineContainer
->GetPrevContinuation()) {
622 ReparentFloatsForInlineChild(irs
.mLineContainer
, aFrame
->GetNextSibling(),
625 for (nsIFrame
* f
= aFrame
->GetNextSibling(); f
; f
= f
->GetNextSibling()) {
633 if (NS_FRAME_IS_NOT_COMPLETE(aStatus
)) {
635 rv
= CreateNextInFlow(aPresContext
, this, aFrame
, newFrame
);
640 nsIFrame
* nextFrame
= aFrame
->GetNextSibling();
642 NS_FRAME_SET_INCOMPLETE(aStatus
);
643 PushFrames(aPresContext
, nextFrame
, aFrame
);
645 else if (nsnull
!= GetNextInFlow()) {
646 // We must return an incomplete status if there are more child
647 // frames remaining in a next-in-flow that follows this frame.
648 nsInlineFrame
* nextInFlow
= (nsInlineFrame
*) GetNextInFlow();
649 while (nsnull
!= nextInFlow
) {
650 if (nextInFlow
->mFrames
.NotEmpty()) {
651 NS_FRAME_SET_INCOMPLETE(aStatus
);
654 nextInFlow
= (nsInlineFrame
*) nextInFlow
->GetNextInFlow();
659 else if (NS_FRAME_IS_NOT_COMPLETE(aStatus
)) {
660 if (nsGkAtoms::placeholderFrame
== aFrame
->GetType()) {
661 nsBlockReflowState
* blockRS
= lineLayout
->mBlockRS
;
662 blockRS
->mBlock
->SplitPlaceholder(*blockRS
, aFrame
);
663 // Allow the parent to continue reflowing
664 aStatus
= NS_FRAME_COMPLETE
;
668 rv
= CreateNextInFlow(aPresContext
, this, aFrame
, newFrame
);
672 if (!reflowingFirstLetter
) {
673 nsIFrame
* nextFrame
= aFrame
->GetNextSibling();
675 PushFrames(aPresContext
, nextFrame
, aFrame
);
684 nsInlineFrame::PullOneFrame(nsPresContext
* aPresContext
,
685 InlineReflowState
& irs
,
688 PRBool isComplete
= PR_TRUE
;
690 nsIFrame
* frame
= nsnull
;
691 nsInlineFrame
* nextInFlow
= irs
.mNextInFlow
;
692 while (nsnull
!= nextInFlow
) {
693 frame
= nextInFlow
->mFrames
.FirstChild();
694 if (nsnull
!= frame
) {
695 // If our block has no next continuation, then any floats belonging to
696 // the pulled frame must belong to our block already. This check ensures
697 // we do no extra work in the common non-vertical-breaking case.
698 if (irs
.mLineContainer
&& irs
.mLineContainer
->GetNextContinuation()) {
699 // The blockChildren.ContainsFrame check performed by
700 // ReparentFloatsForInlineChild will be fast because frame's ancestor
701 // will be the first child of its containing block.
702 ReparentFloatsForInlineChild(irs
.mLineContainer
, frame
, PR_FALSE
);
704 nextInFlow
->mFrames
.RemoveFirstChild();
705 mFrames
.InsertFrame(this, irs
.mPrevFrame
, frame
);
706 isComplete
= PR_FALSE
;
707 nsHTMLContainerFrame::ReparentFrameView(aPresContext
, frame
, nextInFlow
, this);
710 nextInFlow
= (nsInlineFrame
*) nextInFlow
->GetNextInFlow();
711 irs
.mNextInFlow
= nextInFlow
;
714 *aIsComplete
= isComplete
;
719 nsInlineFrame::PushFrames(nsPresContext
* aPresContext
,
720 nsIFrame
* aFromChild
,
721 nsIFrame
* aPrevSibling
)
723 NS_PRECONDITION(nsnull
!= aFromChild
, "null pointer");
724 NS_PRECONDITION(nsnull
!= aPrevSibling
, "pushing first child");
725 NS_PRECONDITION(aPrevSibling
->GetNextSibling() == aFromChild
, "bad prev sibling");
728 printf("%p pushing aFromChild %p, disconnecting from prev sib %p\n",
729 this, aFromChild
, aPrevSibling
);
731 // Disconnect aFromChild from its previous sibling
732 aPrevSibling
->SetNextSibling(nsnull
);
734 // Add the frames to our overflow list (let our next in flow drain
735 // our overflow list when it is ready)
736 SetOverflowFrames(aPresContext
, aFromChild
);
740 //////////////////////////////////////////////////////////////////////
743 nsInlineFrame::GetSkipSides() const
747 nsInlineFrame
* prev
= (nsInlineFrame
*) GetPrevContinuation();
748 if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
) ||
749 (prev
&& (prev
->mRect
.height
|| prev
->mRect
.width
))) {
750 // Prev continuation is not empty therefore we don't render our left
752 skip
|= 1 << NS_SIDE_LEFT
;
755 // If the prev continuation is empty, then go ahead and let our left
756 // edge border render.
759 if (!IsRightMost()) {
760 nsInlineFrame
* next
= (nsInlineFrame
*) GetNextContinuation();
761 if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
) ||
762 (next
&& (next
->mRect
.height
|| next
->mRect
.width
))) {
763 // Next continuation is not empty therefore we don't render our right
765 skip
|= 1 << NS_SIDE_RIGHT
;
768 // If the next continuation is empty, then go ahead and let our right
769 // edge border render.
776 NS_IMETHODIMP
nsInlineFrame::GetAccessible(nsIAccessible
** aAccessible
)
778 // Broken image accessibles are created here, because layout
779 // replaces the image or image control frame with an inline frame
780 *aAccessible
= nsnull
;
781 nsIAtom
*tagAtom
= mContent
->Tag();
782 if ((tagAtom
== nsGkAtoms::img
|| tagAtom
== nsGkAtoms::input
||
783 tagAtom
== nsGkAtoms::label
) && mContent
->IsNodeOfType(nsINode::eHTML
)) {
784 // Only get accessibility service if we're going to use it
785 nsCOMPtr
<nsIAccessibilityService
> accService(do_GetService("@mozilla.org/accessibilityService;1"));
787 return NS_ERROR_FAILURE
;
788 if (tagAtom
== nsGkAtoms::input
) // Broken <input type=image ... />
789 return accService
->CreateHTMLButtonAccessible(static_cast<nsIFrame
*>(this), aAccessible
);
790 else if (tagAtom
== nsGkAtoms::img
) // Create accessible for broken <img>
791 return accService
->CreateHTMLImageAccessible(static_cast<nsIFrame
*>(this), aAccessible
);
792 else if (tagAtom
== nsGkAtoms::label
) // Creat accessible for <label>
793 return accService
->CreateHTMLLabelAccessible(static_cast<nsIFrame
*>(this), aAccessible
);
796 return NS_ERROR_FAILURE
;
800 //////////////////////////////////////////////////////////////////////
802 // nsLineFrame implementation
805 ReParentChildListStyle(nsPresContext
* aPresContext
,
806 nsFrameList
& aFrameList
,
807 nsIFrame
* aParentFrame
)
809 nsFrameManager
*frameManager
= aPresContext
->FrameManager();
811 for (nsIFrame
* kid
= aFrameList
.FirstChild(); kid
;
812 kid
= kid
->GetNextSibling()) {
813 NS_ASSERTION(kid
->GetParent() == aParentFrame
, "Bogus parentage");
814 frameManager
->ReParentStyleContext(kid
);
819 NS_NewFirstLineFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
821 return new (aPresShell
) nsFirstLineFrame(aContext
);
826 nsFirstLineFrame::GetFrameName(nsAString
& aResult
) const
828 return MakeFrameName(NS_LITERAL_STRING("Line"), aResult
);
833 nsFirstLineFrame::GetType() const
835 return nsGkAtoms::lineFrame
;
839 nsFirstLineFrame::StealFramesFrom(nsIFrame
* aFrame
)
841 nsIFrame
* prevFrame
= mFrames
.GetPrevSiblingFor(aFrame
);
843 prevFrame
->SetNextSibling(nsnull
);
846 mFrames
.SetFrames(nsnull
);
851 nsFirstLineFrame::PullOneFrame(nsPresContext
* aPresContext
, InlineReflowState
& irs
,
854 nsIFrame
* frame
= nsInlineFrame::PullOneFrame(aPresContext
, irs
, aIsComplete
);
855 if (frame
&& !GetPrevInFlow()) {
856 // We are a first-line frame. Fixup the child frames
857 // style-context that we just pulled.
858 NS_ASSERTION(frame
->GetParent() == this, "Incorrect parent?");
859 aPresContext
->FrameManager()->ReParentStyleContext(frame
);
865 nsFirstLineFrame::Reflow(nsPresContext
* aPresContext
,
866 nsHTMLReflowMetrics
& aMetrics
,
867 const nsHTMLReflowState
& aReflowState
,
868 nsReflowStatus
& aStatus
)
870 if (nsnull
== aReflowState
.mLineLayout
) {
871 return NS_ERROR_INVALID_ARG
;
874 nsIFrame
* lineContainer
= aReflowState
.mLineLayout
->GetLineContainerFrame();
876 // Check for an overflow list with our prev-in-flow
877 nsFirstLineFrame
* prevInFlow
= (nsFirstLineFrame
*)GetPrevInFlow();
878 if (nsnull
!= prevInFlow
) {
879 nsIFrame
* prevOverflowFrames
= prevInFlow
->GetOverflowFrames(aPresContext
, PR_TRUE
);
880 if (prevOverflowFrames
) {
881 nsFrameList
frames(prevOverflowFrames
);
883 // Assign all floats to our block if necessary
884 if (lineContainer
&& lineContainer
->GetPrevContinuation()) {
885 ReparentFloatsForInlineChild(lineContainer
, prevOverflowFrames
, PR_TRUE
);
887 mFrames
.InsertFrames(this, nsnull
, prevOverflowFrames
);
888 ReParentChildListStyle(aPresContext
, frames
, this);
892 // It's also possible that we have an overflow list for ourselves
893 nsIFrame
* overflowFrames
= GetOverflowFrames(aPresContext
, PR_TRUE
);
894 if (overflowFrames
) {
895 NS_ASSERTION(mFrames
.NotEmpty(), "overflow list w/o frames");
896 nsFrameList
frames(overflowFrames
);
898 mFrames
.AppendFrames(nsnull
, overflowFrames
);
899 ReParentChildListStyle(aPresContext
, frames
, this);
902 // Set our own reflow state (additional state above and beyond
904 InlineReflowState irs
;
905 irs
.mPrevFrame
= nsnull
;
906 irs
.mLineContainer
= lineContainer
;
907 irs
.mNextInFlow
= (nsInlineFrame
*) GetNextInFlow();
910 PRBool wasEmpty
= mFrames
.IsEmpty();
912 // Try to pull over one frame before starting so that we know
913 // whether we have an anonymous block or not.
915 PullOneFrame(aPresContext
, irs
, &complete
);
918 if (nsnull
== GetPrevInFlow()) {
919 // XXX This is pretty sick, but what we do here is to pull-up, in
920 // advance, all of the next-in-flows children. We re-resolve their
921 // style while we are at at it so that when we reflow they have
924 // All of this is so that text-runs reflow properly.
925 irs
.mPrevFrame
= mFrames
.LastChild();
928 nsIFrame
* frame
= PullOneFrame(aPresContext
, irs
, &complete
);
932 irs
.mPrevFrame
= frame
;
934 irs
.mPrevFrame
= nsnull
;
937 // XXX do this in the Init method instead
938 // For continuations, we need to check and see if our style
939 // context is right. If its the same as the first-in-flow, then
940 // we need to fix it up (that way :first-line style doesn't leak
941 // into this continuation since we aren't the first line).
942 nsFirstLineFrame
* first
= (nsFirstLineFrame
*) GetFirstInFlow();
943 if (mStyleContext
== first
->mStyleContext
) {
944 // Fixup our style context and our children. First get the
945 // proper parent context.
946 nsStyleContext
* parentContext
= first
->GetParent()->GetStyleContext();
948 // Create a new style context that is a child of the parent
949 // style context thus removing the :first-line style. This way
950 // we behave as if an anonymous (unstyled) span was the child
951 // of the parent frame.
952 nsRefPtr
<nsStyleContext
> newSC
;
953 newSC
= aPresContext
->StyleSet()->
954 ResolvePseudoStyleFor(nsnull
,
955 nsCSSAnonBoxes::mozLineFrame
, parentContext
);
957 // Switch to the new style context.
958 SetStyleContext(newSC
);
960 // Re-resolve all children
961 ReParentChildListStyle(aPresContext
, mFrames
, this);
967 NS_ASSERTION(!aReflowState
.mLineLayout
->GetInFirstLine(),
968 "Nested first-line frames? BOGUS");
969 aReflowState
.mLineLayout
->SetInFirstLine(PR_TRUE
);
970 rv
= ReflowFrames(aPresContext
, aReflowState
, irs
, aMetrics
, aStatus
);
971 aReflowState
.mLineLayout
->SetInFirstLine(PR_FALSE
);
973 // Note: the line layout code will properly compute our overflow state for us
978 //////////////////////////////////////////////////////////////////////
981 NS_NewPositionedInlineFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
983 return new (aPresShell
) nsPositionedInlineFrame(aContext
);
987 nsPositionedInlineFrame::Destroy()
989 mAbsoluteContainer
.DestroyFrames(this);
990 nsInlineFrame::Destroy();
994 nsPositionedInlineFrame::SetInitialChildList(nsIAtom
* aListName
,
995 nsIFrame
* aChildList
)
999 if (nsGkAtoms::absoluteList
== aListName
) {
1000 rv
= mAbsoluteContainer
.SetInitialChildList(this, aListName
, aChildList
);
1002 rv
= nsInlineFrame::SetInitialChildList(aListName
, aChildList
);
1009 nsPositionedInlineFrame::AppendFrames(nsIAtom
* aListName
,
1010 nsIFrame
* aFrameList
)
1014 if (nsGkAtoms::absoluteList
== aListName
) {
1015 rv
= mAbsoluteContainer
.AppendFrames(this, aListName
, aFrameList
);
1017 rv
= nsInlineFrame::AppendFrames(aListName
, aFrameList
);
1024 nsPositionedInlineFrame::InsertFrames(nsIAtom
* aListName
,
1025 nsIFrame
* aPrevFrame
,
1026 nsIFrame
* aFrameList
)
1030 if (nsGkAtoms::absoluteList
== aListName
) {
1031 rv
= mAbsoluteContainer
.InsertFrames(this, aListName
, aPrevFrame
,
1034 rv
= nsInlineFrame::InsertFrames(aListName
, aPrevFrame
, aFrameList
);
1041 nsPositionedInlineFrame::RemoveFrame(nsIAtom
* aListName
,
1042 nsIFrame
* aOldFrame
)
1046 if (nsGkAtoms::absoluteList
== aListName
) {
1047 rv
= mAbsoluteContainer
.RemoveFrame(this, aListName
, aOldFrame
);
1049 rv
= nsInlineFrame::RemoveFrame(aListName
, aOldFrame
);
1056 nsPositionedInlineFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
1057 const nsRect
& aDirtyRect
,
1058 const nsDisplayListSet
& aLists
)
1060 aBuilder
->MarkFramesForDisplayList(this, mAbsoluteContainer
.GetFirstChild(), aDirtyRect
);
1061 return nsHTMLContainerFrame::BuildDisplayList(aBuilder
, aDirtyRect
, aLists
);
1065 nsPositionedInlineFrame::GetAdditionalChildListName(PRInt32 aIndex
) const
1068 return nsGkAtoms::absoluteList
;
1074 nsPositionedInlineFrame::GetFirstChild(nsIAtom
* aListName
) const
1076 if (nsGkAtoms::absoluteList
== aListName
) {
1077 nsIFrame
* result
= nsnull
;
1078 mAbsoluteContainer
.FirstChild(this, aListName
, &result
);
1082 return nsInlineFrame::GetFirstChild(aListName
);
1086 nsPositionedInlineFrame::GetType() const
1088 return nsGkAtoms::positionedInlineFrame
;
1092 nsPositionedInlineFrame::Reflow(nsPresContext
* aPresContext
,
1093 nsHTMLReflowMetrics
& aDesiredSize
,
1094 const nsHTMLReflowState
& aReflowState
,
1095 nsReflowStatus
& aStatus
)
1097 nsresult rv
= NS_OK
;
1099 // Don't bother optimizing for fast incremental reflow of absolute
1100 // children of an inline
1102 // Let the inline frame do its reflow first
1103 rv
= nsInlineFrame::Reflow(aPresContext
, aDesiredSize
, aReflowState
, aStatus
);
1105 // Let the absolutely positioned container reflow any absolutely positioned
1106 // child frames that need to be reflowed
1107 // We want to do this under either of two conditions:
1108 // 1. If we didn't do the incremental reflow above.
1109 // 2. If our size changed.
1110 // Even though it's the padding edge that's the containing block, we
1111 // can use our rect (the border edge) since if the border style
1112 // changed, the reflow would have been targeted at us so we'd satisfy
1114 if (NS_SUCCEEDED(rv
) &&
1115 mAbsoluteContainer
.HasAbsoluteFrames()) {
1116 // The containing block for the abs pos kids is formed by our padding edge.
1117 nsMargin computedBorder
=
1118 aReflowState
.mComputedBorderPadding
- aReflowState
.mComputedPadding
;
1119 nscoord containingBlockWidth
=
1120 aDesiredSize
.width
- computedBorder
.LeftRight();
1121 nscoord containingBlockHeight
=
1122 aDesiredSize
.height
- computedBorder
.TopBottom();
1124 // Factor the absolutely positioned child bounds into the overflow area
1125 // Don't include this frame's bounds, nor its inline descendants' bounds,
1126 // and don't store the overflow property.
1127 // That will all be done by nsLineLayout::RelativePositionFrames.
1128 rv
= mAbsoluteContainer
.Reflow(this, aPresContext
, aReflowState
, aStatus
,
1129 containingBlockWidth
, containingBlockHeight
,
1130 PR_TRUE
, PR_TRUE
, PR_TRUE
, // XXX could be optimized
1131 &aDesiredSize
.mOverflowArea
);