Bug 403526: Do not propagate text-decoration to floats. r=dbaron

This commit is contained in:
Zack Weinberg 2010-03-17 11:18:06 -07:00
parent 182beccf00
commit 0140b565ce
6 changed files with 175 additions and 28 deletions

View file

@ -446,41 +446,31 @@ nsHTMLContainerFrame::GetTextDecorations(nsPresContext* aPresContext,
return;
}
// A mask of all possible decorations.
PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_UNDERLINE |
NS_STYLE_TEXT_DECORATION_OVERLINE |
NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
if (!aIsBlock) {
aDecorations = GetStyleTextReset()->mTextDecoration & decorMask;
aDecorations = this->GetStyleTextReset()->mTextDecoration &
NS_STYLE_TEXT_DECORATION_LINES_MASK;
if (aDecorations) {
const nsStyleColor* styleColor = GetStyleColor();
aUnderColor = styleColor->mColor;
aOverColor = styleColor->mColor;
aStrikeColor = styleColor->mColor;
nscolor color = this->GetStyleColor()->mColor;
aUnderColor = color;
aOverColor = color;
aStrikeColor = color;
}
}
else {
// We want to ignore a text-decoration from an ancestor frame that
// is redundant with one from a descendant frame. This isn't just
// an optimization; the descendant frame's color specification
// must win. At any point in the loop below, this variable
// indicates which decorations we are still paying attention to;
// it starts set to all possible decorations.
PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_LINES_MASK;
// walk tree
for (nsIFrame *frame = this; frame && decorMask; frame = frame->GetParent()) {
// find text-decorations. "Inherit" from parent *block* frames
nsStyleContext* styleContext = frame->GetStyleContext();
const nsStyleDisplay* styleDisplay = styleContext->GetStyleDisplay();
if (!styleDisplay->IsBlockInside() &&
styleDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL &&
styleDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CAPTION) {
// If an inline frame is discovered while walking up the tree,
// we should stop according to CSS3 draft. CSS2 is rather vague
// about this.
break;
}
const nsStyleTextReset* styleText = styleContext->GetStyleTextReset();
PRUint8 decors = decorMask & styleText->mTextDecoration;
for (nsIFrame* frame = this; frame; frame = frame->GetParent()) {
PRUint8 decors = frame->GetStyleTextReset()->mTextDecoration & decorMask;
if (decors) {
// A *new* text-decoration is found.
nscolor color = styleContext->GetStyleColor()->mColor;
nscolor color = frame->GetStyleColor()->mColor;
if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decors) {
aUnderColor = color;
@ -498,6 +488,35 @@ nsHTMLContainerFrame::GetTextDecorations(nsPresContext* aPresContext,
aDecorations |= NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
}
}
// If all possible decorations have now been specified, no
// further ancestor frames can affect the rendering.
if (!decorMask) {
break;
}
// CSS2.1 16.3.1 specifies that this property is not always
// inherited from ancestor boxes (frames in our terminology):
//
// When specified on an inline element, [the
// text-decoration property] affects all the boxes
// generated by that element; for all other elements, the
// decorations are propagated to an anonymous inline box
// that wraps all the in-flow inline children of the
// element, and to any block-level in-flow descendants. It
// is not, however, further propagated to floating and
// absolutely positioned descendants, nor to the contents
// of 'inline-table' and 'inline-block' descendants.
//
// So do not look at the ancestor frame if this frame is any of
// the above. This check is at the bottom of the loop because
// even if it's true we still want to look at decorations on the
// frame itself.
const nsStyleDisplay* styleDisplay = frame->GetStyleDisplay();
if (styleDisplay->IsFloating() ||
styleDisplay->IsAbsolutelyPositioned() ||
styleDisplay->IsInlineOutside()) {
break;
}
}
}

View file

@ -7,6 +7,7 @@
== underline-table-cell-quirks.html underline-table-cell-quirks-ref.html
!= underline-table-cell-quirks.html underline-table-cell-quirks-notref.html
fails == underline-block-propagation-quirks.html underline-block-propagation-quirks-ref.html # currently too quirky (bug 403524)
fails == underline-block-propagation-2-quirks.html underline-block-propagation-2-quirks-ref.html # same problem as previous line (bug 403524)
== underline-block-standards.html underline-block-standards-ref.html
!= underline-block-standards.html underline-block-standards-notref.html
== underline-inline-block-standards.html underline-inline-block-standards-ref.html
@ -15,6 +16,7 @@ fails == underline-block-propagation-quirks.html underline-block-propagation-qui
!= underline-table-caption-standards.html underline-table-caption-standards-notref.html
== underline-table-cell-standards.html underline-table-cell-standards-ref.html
!= underline-table-cell-standards.html underline-table-cell-standards-notref.html
fails == underline-block-propagation-standards.html underline-block-propagation-standards-ref.html # bug that we propagate to floats (bug 403526)
fails == underline-block-propagation-standards.html underline-block-propagation-standards-ref.html # bug that decoration is drawn through non-text child (bug 428599)
== underline-block-propagation-2-standards.html underline-block-propagation-2-standards-ref.html
== text-decoration-zorder-1-standards.html text-decoration-zorder-1-ref.html
fails == text-decoration-zorder-1-quirks.html text-decoration-zorder-1-ref.html # bug 403524

View file

@ -0,0 +1,34 @@
<html><head>
<title>More tests of propagation of text-decoration</title>
</head>
<body>
<!-- t-d should not propagate to the content of a form control -->
<form>
<span style="text-decoration:underline">This text should be underlined.</span><br>
<textarea rows="2" cols="40">This text should not be underlined.</textarea
><textarea rows="2" cols="40" style="text-decoration:line-through"
>This text should be struck out.</textarea>
<p style="text-decoration:underline">This text should also be underlined.</p>
</form>
<!-- t-d should propagate from parent elements to table-cells -->
<div>
<table>
<tr>
<td>
<span style="text-decoration:underline">
<span style="text-decoration:overline">
<span style="text-decoration:line-through">
underlined, overlined, and struck out
</span></span></span>
</td>
</tr>
</table>
</div>
<!-- t-d on a float itself should apply -->
<div>
<p style="text-decoration:underline">This text should be underlined.</p>
<p style="float:left; text-decoration:overline"
>This text should be overlined (only).</p>
</div>
</body>
</html>

View file

@ -0,0 +1,28 @@
<html><head>
<title>More tests of propagation of text-decoration</title>
</head>
<body>
<!-- t-d should not propagate to the content of a form control -->
<form style="text-decoration:underline">
This text should be underlined.<br>
<textarea rows="2" cols="40">This text should not be underlined.</textarea
><textarea rows="2" cols="40" style="text-decoration:line-through"
>This text should be struck out.</textarea>
<p>This text should also be underlined.</p>
</form>
<!-- t-d should propagate from parent elements to table-cells -->
<div style="text-decoration:underline">
<table style="text-decoration:overline">
<tr style="text-decoration:line-through">
<td>underlined, overlined, and struck out</td>
</tr>
</table>
</div>
<!-- t-d on a float itself should apply -->
<div style="text-decoration:underline">
<p>This text should be underlined.</p>
<p style="float:left; text-decoration:overline"
>This text should be overlined (only).</p>
</div>
</body>
</html>

View file

@ -0,0 +1,35 @@
<!DOCTYPE HTML>
<html><head>
<title>More tests of propagation of text-decoration</title>
</head>
<body>
<!-- t-d should not propagate to the content of a form control -->
<form>
<span style="text-decoration:underline">This text should be underlined.</span><br>
<textarea rows="2" cols="40">This text should not be underlined.</textarea
><textarea rows="2" cols="40" style="text-decoration:line-through"
>This text should be struck out.</textarea>
<p style="text-decoration:underline">This text should also be underlined.</p>
</form>
<!-- t-d should propagate from parent elements to table-cells -->
<div>
<table>
<tr>
<td>
<span style="text-decoration:underline">
<span style="text-decoration:overline">
<span style="text-decoration:line-through">
underlined, overlined, and struck out
</span></span></span>
</td>
</tr>
</table>
</div>
<!-- t-d on a float itself should apply -->
<div>
<p style="text-decoration:underline">This text should be underlined.</p>
<p style="float:left; text-decoration:overline"
>This text should be overlined (only).</p>
</div>
</body>
</html>

View file

@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<html><head>
<title>More tests of propagation of text-decoration</title>
</head>
<body>
<!-- t-d should not propagate to the content of a form control -->
<form style="text-decoration:underline">
This text should be underlined.<br>
<textarea rows="2" cols="40">This text should not be underlined.</textarea
><textarea rows="2" cols="40" style="text-decoration:line-through"
>This text should be struck out.</textarea>
<p>This text should also be underlined.</p>
</form>
<!-- t-d should propagate from parent elements to table-cells -->
<div style="text-decoration:underline">
<table style="text-decoration:overline">
<tr style="text-decoration:line-through">
<td>underlined, overlined, and struck out</td>
</tr>
</table>
</div>
<!-- t-d on a float itself should apply -->
<div style="text-decoration:underline">
<p>This text should be underlined.</p>
<p style="float:left; text-decoration:overline"
>This text should be overlined (only).</p>
</div>
</body>
</html>