srctree

Robin Linden parent 1250dcd6 43084198
layout: Handle height: auto

Previously height: auto would get parsed as height: 0 and overridewhatever the height of the LayoutBox's children was.

inlinesplit
layout/layout.cpp added: 31, removed: 4, total 27
@@ -163,7 +163,7 @@ void calculate_height(LayoutBox &box, int const font_size) {
box.dimensions.content.height = font_size;
}
 
if (auto height = box.get_property("height")) {
if (auto height = box.get_property("height"); height && height != "auto") {
box.dimensions.content.height = to_px(*height, font_size);
}
 
 
layout/layout_test.cpp added: 31, removed: 4, total 27
@@ -931,7 +931,7 @@ int main() {
expect_eq(layout, expected_layout);
});
 
etest::test("max-height: auto", [] {
etest::test("max-height: none", [] {
dom::Node dom = dom::Element{.name{"html"}};
style::StyledNode style{.node{dom}, .properties{{"height", "100px"}, {"max-height", "none"}}};
layout::LayoutBox expected_layout{.node = &style, .type = LayoutType::Block, .dimensions{{0, 0, 0, 100}}};
@@ -940,6 +940,33 @@ int main() {
expect_eq(layout, expected_layout);
});
 
etest::test("height: auto", [] {
dom::Node dom = dom::Element{.name{"html"}, .children{dom::Element{.name{"p"}}}};
style::StyledNode style{
.node{dom},
.properties{{"height", "auto"}},
.children{
style::StyledNode{
.node{std::get<dom::Element>(dom).children[0]},
.properties{{"height", "10px"}},
},
},
};
layout::LayoutBox expected_layout{
.node = &style,
.type = LayoutType::Block,
.dimensions{{0, 0, 0, 10}},
.children{layout::LayoutBox{
.node = &style.children[0],
.type = LayoutType::Block,
.dimensions{{0, 0, 0, 10}},
}},
};
 
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{}};