srctree

Robin Linden parent a8f88d9b 99bc7300
layout: Treat invalid max-width properties as 'none'

This matches what other browser do.

inlinesplit
layout/layout.cpp added: 17, removed: 7, total 10
@@ -475,10 +475,15 @@ void Layouter::calculate_width_and_margin(LayoutBox &box, geom::Rect const &pare
}
}
 
if (auto max = box.get_property<css::PropertyId::MaxWidth>(); !max.is_none()) {
auto resolved = max.resolve(font_size, root_font_size_, parent.width);
if (box.dimensions.content.width > resolved) {
box.dimensions.content.width = resolved;
auto max = box.get_property<css::PropertyId::MaxWidth>();
std::optional<int> resolved_max;
if (!max.is_none()) {
resolved_max = max.try_resolve(font_size, root_font_size_, parent.width);
}
 
if (resolved_max) {
if (box.dimensions.content.width > *resolved_max) {
box.dimensions.content.width = *resolved_max;
calculate_left_and_right_margin(box, parent, margin_left, margin_right, font_size);
}
}
 
layout/layout_test.cpp added: 17, removed: 7, total 10
@@ -1914,7 +1914,7 @@ int main() {
expect_eq(layout.children.at(0).dimensions.border_box().width, 50);
});
 
etest::test("invalid width", [] {
etest::test("invalid width properties", [] {
dom::Node dom = dom::Element{"html", {}, {dom::Element{"div"}}};
auto const &div = std::get<dom::Element>(dom).children[0];
style::StyledNode style{
@@ -1932,6 +1932,11 @@ int main() {
auto layout = layout::create_layout(style, 1000).value();
expect_eq(layout.dimensions.border_box().width, 1000);
expect_eq(layout.children.at(0).dimensions.border_box().width, 100);
 
style.properties.push_back({css::PropertyId::MaxWidth, "asdf"});
layout = layout::create_layout(style, 1000).value();
expect_eq(layout.dimensions.border_box().width, 1000);
expect_eq(layout.children.at(0).dimensions.border_box().width, 100);
});
 
whitespace_collapsing_tests();