srctree

Robin Lindén parent f2072891 51857969
style: Make outline-{color,style} less stringly typed

inlinesplit
style/styled_node.h added: 31, removed: 3, total 28
@@ -32,6 +32,8 @@ enum class BorderStyle {
Outset,
};
 
using OutlineStyle = BorderStyle;
 
enum class DisplayValue {
None,
Inline,
@@ -74,7 +76,7 @@ struct StyledNode {
// Some of these branches have the same content, but we still want to
// keep related properties grouped together and away from unrelated
// ones, e.g. all border-<side>-color properties in the same branch.
// NOLINTNEXTLINE(bugprone-branch-clone)
// NOLINTBEGIN(bugprone-branch-clone)
if constexpr (T == css::PropertyId::BackgroundColor) {
return get_color_property(T);
} else if constexpr (T == css::PropertyId::BorderBottomColor || T == css::PropertyId::BorderLeftColor
@@ -83,6 +85,10 @@ struct StyledNode {
} else if constexpr (T == css::PropertyId::BorderBottomStyle || T == css::PropertyId::BorderLeftStyle
|| T == css::PropertyId::BorderRightStyle || T == css::PropertyId::BorderTopStyle) {
return get_border_style_property(T);
} else if constexpr (T == css::PropertyId::OutlineStyle) {
return get_border_style_property(T);
} else if constexpr (T == css::PropertyId::OutlineColor) {
return get_color_property(T);
} else if constexpr (T == css::PropertyId::Color) {
return get_color_property(T);
} else if constexpr (T == css::PropertyId::Display) {
@@ -106,6 +112,7 @@ struct StyledNode {
} else {
return get_raw_property(T);
}
// NOLINTEND(bugprone-branch-clone)
}
 
private:
 
style/styled_node_test.cpp added: 31, removed: 3, total 28
@@ -289,6 +289,27 @@ int main() {
expect_property_eq<css::PropertyId::BorderTopStyle>("ridge", style::BorderStyle::Ridge);
});
 
etest::test("get_property, outline-style", [] {
expect_property_eq<css::PropertyId::OutlineStyle>("none", style::BorderStyle::None);
expect_property_eq<css::PropertyId::OutlineStyle>("hidden", style::BorderStyle::Hidden);
expect_property_eq<css::PropertyId::OutlineStyle>("dotted", style::BorderStyle::Dotted);
expect_property_eq<css::PropertyId::OutlineStyle>("dashed", style::BorderStyle::Dashed);
expect_property_eq<css::PropertyId::OutlineStyle>("solid", style::BorderStyle::Solid);
expect_property_eq<css::PropertyId::OutlineStyle>("double", style::BorderStyle::Double);
expect_property_eq<css::PropertyId::OutlineStyle>("groove", style::BorderStyle::Groove);
expect_property_eq<css::PropertyId::OutlineStyle>("ridge", style::BorderStyle::Ridge);
expect_property_eq<css::PropertyId::OutlineStyle>("inset", style::BorderStyle::Inset);
expect_property_eq<css::PropertyId::OutlineStyle>("outset", style::BorderStyle::Outset);
expect_property_eq<css::PropertyId::OutlineStyle>("???", style::BorderStyle::None);
});
 
etest::test("get_property, outline-color", [] {
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3)", gfx::Color{1, 2, 3});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / .5)", gfx::Color{1, 2, 3, 127});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / -0.5)", gfx::Color{1, 2, 3, 0});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / 1.5)", gfx::Color{1, 2, 3, 0xFF});
});
 
etest::test("get_property, color", [] {
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3)", gfx::Color{1, 2, 3});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / .5)", gfx::Color{1, 2, 3, 127});