Skip to content

Commit

Permalink
style: Fix font-size: {inherit,unset}
Browse files Browse the repository at this point in the history
For all other properties, these keywords are handled by
StyledNode::get_raw_property, but font-size is special as it needs to
know the node its value originated from.
  • Loading branch information
robinlinden committed Dec 14, 2023
1 parent b53789c commit b625a5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion style/styled_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int StyledNode::get_font_size_property() const {
auto it = std::ranges::find_if(rbegin(n->properties), rend(n->properties), [](auto const &v) {
return v.first == css::PropertyId::FontSize;
});
if (it != rend(n->properties)) {
if (it != rend(n->properties) && it->second != "inherit" && it->second != "unset") {
return {{it->second, n}};
}
}
Expand Down
6 changes: 6 additions & 0 deletions style/styled_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ int main() {
expect_eq(child.get_property<css::PropertyId::FontSize>(), 10);
expect_eq(root.get_property<css::PropertyId::FontSize>(), 50);

// inherit, unset
child.properties[0] = {css::PropertyId::FontSize, "unset"};
expect_eq(child.get_property<css::PropertyId::FontSize>(), 50);
child.properties[0] = {css::PropertyId::FontSize, "inherit"};
expect_eq(child.get_property<css::PropertyId::FontSize>(), 50);

// %
child.properties[0] = {css::PropertyId::FontSize, "100%"};
expect_eq(child.get_property<css::PropertyId::FontSize>(), 50);
Expand Down

0 comments on commit b625a5d

Please sign in to comment.