Commit 80b0ec4d authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

LayoutNG: Fix min_size for <marquee>, <select>, and <input type=file>

NGBlockNode::ComputeMinMaxSizes() should return values for border-boxes.
So, the values should contain padding and border sizes. Its min_size
returned 0 for <marquee>, <select>, and <input type=file> in some cases
even though they have paddings or borders.

Bug: 1107291
Change-Id: Idef8f092df0beabff5dc8e5f815886f46c056a5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2306135
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarDavid Grogan <dgrogan@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790236}
parent cd5baf40
...@@ -819,14 +819,15 @@ MinMaxSizesResult NGBlockNode::ComputeMinMaxSizes( ...@@ -819,14 +819,15 @@ MinMaxSizesResult NGBlockNode::ComputeMinMaxSizes(
const auto* node = box_->GetNode(); const auto* node = box_->GetNode();
const auto* html_marquee_element = DynamicTo<HTMLMarqueeElement>(node); const auto* html_marquee_element = DynamicTo<HTMLMarqueeElement>(node);
if (UNLIKELY(html_marquee_element && html_marquee_element->IsHorizontal())) const auto* html_input_element = DynamicTo<HTMLInputElement>(node);
result.sizes.min_size = LayoutUnit(); if (UNLIKELY((html_marquee_element && html_marquee_element->IsHorizontal()) ||
else if (UNLIKELY(IsA<HTMLSelectElement>(node) || (IsA<HTMLSelectElement>(node) ||
(IsA<HTMLInputElement>(node) && (html_input_element &&
To<HTMLInputElement>(node)->type() == html_input_element->type() == input_type_names::kFile)) &&
input_type_names::kFile)) && Style().LogicalWidth().IsPercentOrCalc())) {
Style().LogicalWidth().IsPercentOrCalc()) result.sizes.min_size =
result.sizes.min_size = LayoutUnit(); (fragment_geometry.border + fragment_geometry.padding).InlineSum();
}
bool depends_on_percentage_block_size = bool depends_on_percentage_block_size =
uses_input_percentage_block_size && uses_input_percentage_block_size &&
......
...@@ -184,5 +184,32 @@ TEST_F(NGBlockNodeForTest, MinAndMaxContent) { ...@@ -184,5 +184,32 @@ TEST_F(NGBlockNodeForTest, MinAndMaxContent) {
EXPECT_EQ(LayoutUnit(kWidth), sizes.min_size); EXPECT_EQ(LayoutUnit(kWidth), sizes.min_size);
EXPECT_EQ(LayoutUnit(kWidth), sizes.max_size); EXPECT_EQ(LayoutUnit(kWidth), sizes.max_size);
} }
// crbug.com/1107291
TEST_F(NGBlockNodeForTest, MinContentForControls) {
SetBodyInnerHTML(R"HTML(
<div style="display: flex;">
<select id="box1" style="border: solid 2px blue; flex: 0; width: 10%;">
</select>
<input id="box2" type=file
style="border: solid 2px blue; flex: 0; width: 10%;">
<marquee id="box3" style="border: solid 2px blue; flex: 0;">foo</marquee>
</div>)HTML");
const char* ids[] = {"box1", "box2", "box3"};
constexpr int kExpectedMinWidth = 4;
for (const auto* id : ids) {
NGBlockNode box(ToLayoutBox(GetLayoutObjectByElementId(id)));
MinMaxSizes sizes =
box.ComputeMinMaxSizes(
WritingMode::kHorizontalTb,
MinMaxSizesInput(
/* percentage_resolution_block_size */ LayoutUnit(-1),
MinMaxSizesType::kContent))
.sizes;
EXPECT_EQ(LayoutUnit(kExpectedMinWidth), sizes.min_size);
}
}
} // namespace } // namespace
} // namespace blink } // namespace blink
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