Commit c0061058 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Fix vertical-align: text-top in quirks mode

When in quirks mode and there are no text siblings; e.g.:
  <div><img><span>text</span></div>
and 'vertical-align: text-top' applied to <img> hits
DCHECK failure and results in incorrect position.

The test ensures that results are the same with the standard
mode.

Bug: 901123
Change-Id: I30564c66d5847f09caf3672ba3d456c0eb798d3e
Reviewed-on: https://chromium-review.googlesource.com/c/1320529
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605965}
parent c0147f42
<!DOCTYPE html>
<style>
div {
font-size: 10px;
line-height: 50px;
border: 1px solid blue;
}
img {
width: 1em;
height: 2em;
background: orange;
border: 1px solid black;
}
.text-top {
vertical-align: text-top;
}
.text-bottom {
vertical-align: text-bottom;
}
.top {
vertical-align: top;
}
.bottom {
vertical-align: bottom;
}
</style>
<body>
<div>
<img class="text-top" src="../../css/support/60x60-red.png">Y
</div>
<div>
<img class="text-bottom" src="../../css/support/60x60-red.png">Y
</div>
<div>
<img class="top" src="../../css/support/60x60-red.png">Y
</div>
<div>
<img class="bottom" src="../../css/support/60x60-red.png">Y
</div>
<div>
<img class="text-top" src="../../css/support/60x60-red.png"><span>Y</span>
</div>
<div>
<img class="text-bottom" src="../../css/support/60x60-red.png"><span>Y</span>
</div>
<div>
<img class="top" src="../../css/support/60x60-red.png"><span>Y</span>
</div>
<div>
<img class="bottom" src="../../css/support/60x60-red.png"><span>Y</span>
</div>
</body>
<meta charset="utf-8">
<title>CSS Text level 3 Test: letter spacing after bidi</title>
<link rel="author" href="kojii@chromium.org">
<link rel="match" href="reference/vertical-align-in-quirks-ref.html">
<meta name="assert" content="Tests some vertical-align values match in quirks and standard modes.">
<style>
div {
font-size: 10px;
line-height: 50px;
border: 1px solid blue;
}
img {
width: 1em;
height: 2em;
background: orange;
border: 1px solid black;
}
.text-top {
vertical-align: text-top;
}
.text-bottom {
vertical-align: text-bottom;
}
.top {
vertical-align: top;
}
.bottom {
vertical-align: bottom;
}
</style>
<body>
<div>
<img class="text-top" src="../css/support/60x60-red.png">Y
</div>
<div>
<img class="text-bottom" src="../css/support/60x60-red.png">Y
</div>
<div>
<img class="top" src="../css/support/60x60-red.png">Y
</div>
<div>
<img class="bottom" src="../css/support/60x60-red.png">Y
</div>
<div>
<img class="text-top" src="../css/support/60x60-red.png"><span>Y</span>
</div>
<div>
<img class="text-bottom" src="../css/support/60x60-red.png"><span>Y</span>
</div>
<div>
<img class="top" src="../css/support/60x60-red.png"><span>Y</span>
</div>
<div>
<img class="bottom" src="../css/support/60x60-red.png"><span>Y</span>
</div>
</body>
......@@ -80,6 +80,15 @@ void NGInlineBoxState::AccumulateUsedFonts(const ShapeResult* shape_result,
}
}
LayoutUnit NGInlineBoxState::TextTop(FontBaseline baseline_type) const {
if (!text_metrics.IsEmpty())
return text_top;
if (const SimpleFontData* font_data = style->GetFont().PrimaryFont())
return -font_data->GetFontMetrics().FixedAscent(baseline_type);
NOTREACHED();
return LayoutUnit();
}
bool NGInlineBoxState::CanAddTextOfStyle(
const ComputedStyle& text_style) const {
if (text_style.VerticalAlign() != EVerticalAlign::kBaseline)
......@@ -552,8 +561,7 @@ NGInlineLayoutStateStack::ApplyBaselineShift(
child.metrics = NGLineHeightMetrics::Zero();
switch (child.vertical_align) {
case EVerticalAlign::kTextTop:
DCHECK(!box->text_metrics.IsEmpty());
baseline_shift = child.metrics.ascent + box->text_top;
baseline_shift = child.metrics.ascent + box->TextTop(baseline_type);
break;
case EVerticalAlign::kTop:
baseline_shift = child.metrics.ascent - max.ascent;
......
......@@ -87,6 +87,9 @@ struct NGInlineBoxState {
void AccumulateUsedFonts(const ShapeResult*, FontBaseline);
// 'text-top' offset for 'vertical-align'.
LayoutUnit TextTop(FontBaseline baseline_type) const;
// Create a box fragment for this box.
void SetNeedsBoxFragment(const LayoutObject* inline_container);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment