srctree

Robin Linden parent 77a85ca3 9985bb46
style: Add support for the unset CSS keyword

inlinesplit
style/styled_node.cpp added: 39, removed: 2, total 37
@@ -98,6 +98,13 @@ std::string_view StyledNode::get_raw_property(css::PropertyId property) const {
} else if (it->second == "inherit") {
// https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
return get_parent_raw_property(*this, property);
} else if (it->second == "unset") {
// https://developer.mozilla.org/en-US/docs/Web/CSS/unset
if (is_inherited(property) && parent != nullptr) {
return parent->get_raw_property(property);
}
 
return kInitialValues.at(property);
} else if (it->second == "currentcolor") {
// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword
// If the "color" property has the value "currentcolor", treat it as "inherit".
 
style/styled_node_test.cpp added: 39, removed: 2, total 37
@@ -89,6 +89,36 @@ int main() {
expect_eq(child.get_property<css::PropertyId::BackgroundColor>(), "transparent");
});
 
etest::test("unset css keyword", [] {
dom::Node dom_node = dom::Element{"dummy"s};
style::StyledNode root{
.node = dom_node,
.properties = {{css::PropertyId::Color, "blue"s}},
.children{
style::StyledNode{
.node{dom_node},
.properties{
{css::PropertyId::Color, "unset"s},
{css::PropertyId::Width, "unset"s},
},
},
},
};
 
auto &child = root.children[0];
child.parent = &root;
 
// unset, not inherited, so receives initial value for property.
expect_eq(child.get_property<css::PropertyId::Width>(), "auto"sv);
 
// unset, inherited, value in parent.
expect_eq(child.get_property<css::PropertyId::Color>(), "blue"sv);
 
// unset, inherited, no parent node.
child.parent = nullptr;
expect_eq(child.get_property<css::PropertyId::Color>(), "canvastext");
});
 
etest::test("currentcolor css keyword", [] {
dom::Node dom_node = dom::Element{"dummy"s};
style::StyledNode root{