srctree

Robin Linden parent d9a9f673 0acdf8cd
layout: Handle max-width: none

Prior to this patch, we'd try to parse none as a number, return 0, andsquish the layout to be 0px wide.

inlinesplit
layout/layout.cpp added: 12, removed: 3, total 9
@@ -141,7 +141,7 @@ void calculate_width_and_margin(LayoutBox &box, geom::Rect const &parent, int co
}
}
 
if (auto max = box.get_property("max-width")) {
if (auto max = box.get_property("max-width"); max && max != "none") {
int max_width_px = to_px(*max, font_size);
if (box.dimensions.content.width > max_width_px) {
box.dimensions.content.width = max_width_px;
 
layout/layout_test.cpp added: 12, removed: 3, total 9
@@ -922,6 +922,15 @@ int main() {
});
 
// clang-format on
etest::test("max-width: none", [] {
dom::Node dom = dom::Element{.name{"html"}};
style::StyledNode style{.node{dom}, .properties{{"width", "100px"}, {"max-width", "none"}}};
layout::LayoutBox expected_layout{.node = &style, .type = LayoutType::Block, .dimensions{{0, 0, 100, 0}}};
 
auto layout = layout::create_layout(style, 0);
expect_eq(layout, expected_layout);
});
 
etest::test("get_property", [] {
dom::Node dom_root = dom::Element{.name{"html"}, .attributes{}, .children{}};
auto style_root = style::StyledNode{.node = dom_root, .properties = {{"color", "green"}}, .children{}};