srctree

Robin Linden parent b3888c48 9ab10aa7
style: Fix inconsistent display values on LayoutBox for dom::Text

LayoutBox will correctly have its "type" set to LayoutType::Inline, butcalling LayoutBox::get_property<PropertyId::Display>() can returnDisplayValue::Block if the StyledNode parent is a block.

inlinesplit
style/styled_node.cpp added: 19, removed: 3, total 16
@@ -335,6 +335,13 @@ gfx::Color StyledNode::get_color_property(css::PropertyId property) const {
// https://developer.mozilla.org/en-US/docs/Web/CSS/float
// ^ has info about the weird float<->display property interaction.
DisplayValue StyledNode::get_display_property() const {
// TODO(robinlinden): Special-case for text not needed once the special case
// where we get the parent properties for text in get_raw_property is
// removed.
if (std::holds_alternative<dom::Text>(node)) {
return DisplayValue::Inline;
}
 
auto raw = get_raw_property(css::PropertyId::Display);
if (raw == "none") {
return DisplayValue::None;
 
style/styled_node_test.cpp added: 19, removed: 3, total 16
@@ -421,12 +421,21 @@ int main() {
etest::test("get_property, non-inherited property for a text node", [] {
dom::Node dom = dom::Element{"hello"};
dom::Node text = dom::Text{"world"};
style::StyledNode styled_node{.node = dom, .properties = {{css::PropertyId::TextDecorationLine, "blink"s}}};
style::StyledNode styled_node{
.node = dom,
.properties{
{css::PropertyId::TextDecorationLine, "blink"s},
{css::PropertyId::Display, "block"s},
},
};
auto const &child = styled_node.children.emplace_back(style::StyledNode{.node = text, .parent = &styled_node});
 
expect(!css::is_inherited(css::PropertyId::TextDecorationLine));
expect_eq(child.get_property<css::PropertyId::TextDecorationLine>(),
std::vector{style::TextDecorationLine::Blink});
 
// Text is always "display: inline".
expect_eq(child.get_property<css::PropertyId::Display>(), style::DisplayValue::Inline);
});
 
etest::test("get_property, font-weight", [] {