1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00

LibWeb: Add CSS property 'border'

This makes it possible to write shorter CSS. Instead of writing
.foo {
        border-width: 3px;
        border-style: solid;
        border-color: blue;
}
it is now possible to write
.foo {
        border: 3px solid blue;
}
while the order of values is irrelevant.
Currently only the basic values are supported. More values should be
added in the future.

Three more value specific parse functions were added:
parse_line_width, parse_color, and parse_line_style

Additionally a few test cases were added to borders.html.
This commit is contained in:
myphs 2020-03-20 20:29:39 +01:00 committed by Andreas Kling
parent 12e8efd74e
commit 0891f860f7
4 changed files with 205 additions and 0 deletions

View file

@ -153,6 +153,42 @@ NonnullRefPtr<StyleValue> parse_css_value(const StringView& string)
return StringStyleValue::create(string);
}
RefPtr<StyleValue> parse_line_width(const StringView& part)
{
NonnullRefPtr<StyleValue> value = parse_css_value(part);
if (value->is_length())
return value;
return nullptr;
}
RefPtr<StyleValue> parse_color(const StringView& part)
{
NonnullRefPtr<StyleValue> value = parse_css_value(part);
if (value->is_color())
return value;
return nullptr;
}
RefPtr<StyleValue> parse_line_style(const StringView& part)
{
NonnullRefPtr<StyleValue> value = parse_css_value(part);
if (value->is_string()) {
if (value->to_string() == "dotted")
return value;
if (value->to_string() == "dashed")
return value;
if (value->to_string() == "solid")
return value;
if (value->to_string() == "double")
return value;
if (value->to_string() == "groove")
return value;
if (value->to_string() == "ridge")
return value;
}
return nullptr;
}
class CSSParser {
public:
CSSParser(const StringView& input)