Bug 287088. Stop first-line styling from leaking into second and subsequent lines when a single element is split between first and second lines. r=roc

--HG--
extra : rebase_source : 0dcf9009a73d5f8082c09172f4ce6840be5e6c98
This commit is contained in:
Timothy Nikkel 2009-12-22 17:42:45 -06:00
parent 86412ece0c
commit 01699b9589
6 changed files with 103 additions and 14 deletions

View File

@ -303,6 +303,19 @@ nsInlineFrame::ReparentFloatsForInlineChild(nsIFrame* aOurLineContainer,
}
}
static void
ReParentChildListStyle(nsPresContext* aPresContext,
const nsFrameList::Slice& aFrames,
nsIFrame* aParentFrame)
{
nsFrameManager *frameManager = aPresContext->FrameManager();
for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) {
NS_ASSERTION(e.get()->GetParent() == aParentFrame, "Bogus parentage");
frameManager->ReParentStyleContext(e.get());
}
}
NS_IMETHODIMP
nsInlineFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aMetrics,
@ -353,7 +366,16 @@ nsInlineFrame::Reflow(nsPresContext* aPresContext,
}
// Insert the new frames at the beginning of the child list
// and set their parent pointer
mFrames.InsertFrames(this, nsnull, *prevOverflowFrames);
const nsFrameList::Slice& newFrames =
mFrames.InsertFrames(this, nsnull, *prevOverflowFrames);
// If our prev in flow was under the first continuation of a first-line
// frame then we need to reparent the style contexts to remove the
// the special first-line styling. In the lazilySetParentPointer case
// we reparent the style contexts when we set their parents in
// nsInlineFrame::ReflowFrames and nsInlineFrame::ReflowInlineFrame.
if (aReflowState.mLineLayout->GetInFirstLine()) {
ReParentChildListStyle(aPresContext, newFrames, this);
}
}
}
}
@ -455,6 +477,8 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
aStatus = NS_FRAME_COMPLETE;
nsLineLayout* lineLayout = aReflowState.mLineLayout;
PRBool inFirstLine = aReflowState.mLineLayout->GetInFirstLine();
nsFrameManager* frameManager = aPresContext->FrameManager();
PRBool ltr = (NS_STYLE_DIRECTION_LTR == aReflowState.mStyleVisibility->mDirection);
nscoord leftEdge = 0;
// Don't offset by our start borderpadding if we have a prev continuation or
@ -497,6 +521,9 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
ReparentFloatsForInlineChild(irs.mLineContainer, frame, PR_FALSE);
}
frame->SetParent(this);
if (inFirstLine) {
frameManager->ReParentStyleContext(frame);
}
// 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
@ -512,6 +539,9 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
ReparentFloatsForInlineChild(irs.mLineContainer, nextInFlow, PR_FALSE);
}
nextInFlow->SetParent(this);
if (inFirstLine) {
frameManager->ReParentStyleContext(nextInFlow);
}
}
// Fix the parent pointer for ::first-letter child frame next-in-flows,
@ -528,6 +558,9 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
"unexpected frame type");
if (mFrames.ContainsFrame(nextInFlow)) {
nextInFlow->SetParent(this);
if (inFirstLine) {
frameManager->ReParentStyleContext(nextInFlow);
}
}
else {
#ifdef DEBUG
@ -710,6 +743,9 @@ nsInlineFrame::ReflowInlineFrame(nsPresContext* aPresContext,
}
for (nsIFrame* f = aFrame->GetNextSibling(); f; f = f->GetNextSibling()) {
f->SetParent(this);
if (lineLayout->GetInFirstLine()) {
aPresContext->FrameManager()->ReParentStyleContext(f);
}
}
}
}
@ -927,19 +963,6 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
// nsLineFrame implementation
static void
ReParentChildListStyle(nsPresContext* aPresContext,
const nsFrameList::Slice& aFrames,
nsIFrame* aParentFrame)
{
nsFrameManager *frameManager = aPresContext->FrameManager();
for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) {
NS_ASSERTION(e.get()->GetParent() == aParentFrame, "Bogus parentage");
frameManager->ReParentStyleContext(e.get());
}
}
nsIFrame*
NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{

View File

@ -0,0 +1,18 @@
<html>
<head>
<style>
div::first-line { color: red; background-color: blue; font-size: 200%; text-transform: uppercase; }
</style>
</head>
<body>
<div>
Line number one.<br/>Line number two.<br/>Line number three.
</div>
<div style="height: 50000px;">
<!-- to force a scrollbar -->
</div>
</body>
</html>

View File

@ -0,0 +1,18 @@
<html>
<head>
<style>
div::first-line { color: red; background-color: blue; font-size: 200%; text-transform: uppercase; }
</style>
</head>
<body>
<div>
<span>Line number one.<br/>Line number two.<br/>Line number three.</span>
</div>
<div style="height: 50000px;">
<!-- to force a scrollbar -->
</div>
</body>
</html>

View File

@ -0,0 +1,14 @@
<html>
<head>
<style>
div::first-line { color: red; background-color: blue; font-size: 200%; text-transform: uppercase; }
</style>
</head>
<body>
<div>
Line number one.<br/>Line number two.<br/>Line number three.
</div>
</body>
</html>

View File

@ -0,0 +1,14 @@
<html>
<head>
<style>
div::first-line { color: red; background-color: blue; font-size: 200%; text-transform: uppercase; }
</style>
</head>
<body>
<div>
<span>Line number one.<br/>Line number two.<br/>Line number three.</span>
</div>
</body>
</html>

View File

@ -26,6 +26,8 @@ fails == out-of-flow-1d.html out-of-flow-1-ref.html # bug 396645
== stress-11.xhtml stress-11-ref.xhtml
== border-not-apply.html border-not-apply-ref.html
== 287088-1.html 287088-1-ref.html
== 287088-2.html 287088-2-ref.html
== 403177-1.html 403177-1-ref.html
== 469227-2.html 469227-2-ref.html
== 469227-3.html 469227-3-ref.html