srctree

Robin Linden parent 9bdbf380 a8f88d9b
layout: Treat invalid width properties as 'auto'

This matches what other browsers do.

inlinesplit
layout/layout.cpp added: 30, removed: 4, total 26
@@ -448,8 +448,14 @@ void Layouter::calculate_width_and_margin(LayoutBox &box, geom::Rect const &pare
 
auto margin_left = box.get_property<css::PropertyId::MarginLeft>();
auto margin_right = box.get_property<css::PropertyId::MarginRight>();
if (auto width = box.get_property<css::PropertyId::Width>(); !width.is_auto()) {
box.dimensions.content.width = width.resolve(font_size, root_font_size_, parent.width);
auto width = box.get_property<css::PropertyId::Width>();
std::optional<int> resolved_width;
if (!width.is_auto()) {
resolved_width = width.try_resolve(font_size, root_font_size_, parent.width);
}
 
if (resolved_width) {
box.dimensions.content.width = *resolved_width;
calculate_left_and_right_margin(box, parent, margin_left, margin_right, font_size);
} else {
if (margin_left != "auto") {
 
layout/layout_test.cpp added: 30, removed: 4, total 26
@@ -1914,6 +1914,26 @@ int main() {
expect_eq(layout.children.at(0).dimensions.border_box().width, 50);
});
 
etest::test("invalid width", [] {
dom::Node dom = dom::Element{"html", {}, {dom::Element{"div"}}};
auto const &div = std::get<dom::Element>(dom).children[0];
style::StyledNode style{
.node{dom},
.properties{{css::PropertyId::Width, "asdf"}, {css::PropertyId::Display, "block"}},
.children{
style::StyledNode{
.node{div},
.properties{{css::PropertyId::Width, "100px"}, {css::PropertyId::Display, "block"}},
},
},
};
set_up_parent_ptrs(style);
 
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);
});
 
whitespace_collapsing_tests();
text_transform_tests();
img_tests();