Commit d0876ff7 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Fieldset NG: Percentage heights for content elements are incorrect

They referred to the container of the fieldset incorrectly.

Bug: 1140595
Change-Id: Ib70048c4e5e59bfd96f44b04ae0c23271e47e840
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2497945
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821092}
parent 325f5ae2
...@@ -4790,6 +4790,7 @@ bool LayoutBox::StretchesToViewportInQuirksMode() const { ...@@ -4790,6 +4790,7 @@ bool LayoutBox::StretchesToViewportInQuirksMode() const {
bool LayoutBox::SkipContainingBlockForPercentHeightCalculation( bool LayoutBox::SkipContainingBlockForPercentHeightCalculation(
const LayoutBox* containing_block) { const LayoutBox* containing_block) {
const bool in_quirks_mode = containing_block->GetDocument().InQuirksMode();
// Anonymous blocks should not impede percentage resolution on a child. // Anonymous blocks should not impede percentage resolution on a child.
// Examples of such anonymous blocks are blocks wrapped around inlines that // Examples of such anonymous blocks are blocks wrapped around inlines that
// have block siblings (from the CSS spec) and multicol flow threads (an // have block siblings (from the CSS spec) and multicol flow threads (an
...@@ -4798,6 +4799,9 @@ bool LayoutBox::SkipContainingBlockForPercentHeightCalculation( ...@@ -4798,6 +4799,9 @@ bool LayoutBox::SkipContainingBlockForPercentHeightCalculation(
// objects, such as table-cells, will be treated just as if they were // objects, such as table-cells, will be treated just as if they were
// non-anonymous. // non-anonymous.
if (containing_block->IsAnonymous()) { if (containing_block->IsAnonymous()) {
if (!in_quirks_mode && containing_block->Parent() &&
containing_block->Parent()->IsLayoutNGFieldset())
return false;
EDisplay display = containing_block->StyleRef().Display(); EDisplay display = containing_block->StyleRef().Display();
return display == EDisplay::kBlock || display == EDisplay::kInlineBlock || return display == EDisplay::kBlock || display == EDisplay::kInlineBlock ||
display == EDisplay::kFlowRoot; display == EDisplay::kFlowRoot;
...@@ -4805,8 +4809,7 @@ bool LayoutBox::SkipContainingBlockForPercentHeightCalculation( ...@@ -4805,8 +4809,7 @@ bool LayoutBox::SkipContainingBlockForPercentHeightCalculation(
// For quirks mode, we skip most auto-height containing blocks when computing // For quirks mode, we skip most auto-height containing blocks when computing
// percentages. // percentages.
if (!containing_block->GetDocument().InQuirksMode() || if (!in_quirks_mode || !containing_block->StyleRef().LogicalHeight().IsAuto())
!containing_block->StyleRef().LogicalHeight().IsAuto())
return false; return false;
const Node* node = containing_block->GetNode(); const Node* node = containing_block->GetNode();
......
...@@ -426,6 +426,13 @@ NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForFieldsetContent( ...@@ -426,6 +426,13 @@ NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForFieldsetContent(
/* is_new_fc */ true); /* is_new_fc */ true);
builder.SetTextDirection(fieldset_content.Style().Direction()); builder.SetTextDirection(fieldset_content.Style().Direction());
builder.SetAvailableSize(padding_box_size); builder.SetAvailableSize(padding_box_size);
// We pass the container's PercentageResolutionSize because percentage
// padding for the fieldset content should be computed as they are in
// the container.
//
// https://html.spec.whatwg.org/C/#anonymous-fieldset-content-box
// > * For the purpose of calculating percentage padding, act as if the
// > padding was calculated for the fieldset element.
builder.SetPercentageResolutionSize( builder.SetPercentageResolutionSize(
ConstraintSpace().PercentageResolutionSize()); ConstraintSpace().PercentageResolutionSize());
builder.SetIsFixedBlockSize(padding_box_size.block_size != kIndefiniteSize); builder.SetIsFixedBlockSize(padding_box_size.block_size != kIndefiniteSize);
......
<!DOCTYPE html>
<link rel="help" href="https://crbug.com/1140595">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div style="height:100px;">
<fieldset style="margin:0; padding:0; border:none;">
<div id="inner" style="height:59%;"></div>
</fieldset>
</div>
<script>
test(() => {
let innerDiv = document.querySelector('#inner');
assert_equals(innerDiv.clientHeight, 0);
}, 'A percentage height for an element in an auto-height fieldset should be ignored');
</script>
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