mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
LibWeb: Add range-checking to property_accepts_value()
For `number` and `integer` types, you can add a range afterwards to add a range check, using similar syntax to that used in the CSS specs. For example: ```json "font-weight": { ... "valid-types": [ "number [1,1000]" ], ... } ``` This limits any numbers to the range `1 <= n <= 1000`.
This commit is contained in:
parent
e262596ee1
commit
b927972da7
4 changed files with 31 additions and 3 deletions
|
@ -668,7 +668,7 @@
|
|||
"inherited": true,
|
||||
"initial": "normal",
|
||||
"valid-types": [
|
||||
"integer"
|
||||
"number [1,1000]"
|
||||
],
|
||||
"valid-identifiers": [
|
||||
"bold",
|
||||
|
|
|
@ -98,6 +98,12 @@ bool StyleValue::is_color() const
|
|||
return false;
|
||||
}
|
||||
|
||||
float StyleValue::as_number() const
|
||||
{
|
||||
VERIFY(is_numeric());
|
||||
return static_cast<NumericStyleValue const&>(*this).value();
|
||||
}
|
||||
|
||||
String IdentifierStyleValue::to_string() const
|
||||
{
|
||||
return CSS::string_from_value_id(m_id);
|
||||
|
|
|
@ -290,8 +290,11 @@ public:
|
|||
return is_builtin() || is_custom_property() || is_calculated();
|
||||
}
|
||||
|
||||
float as_number() const;
|
||||
|
||||
virtual String to_string() const = 0;
|
||||
virtual Length to_length() const { return {}; }
|
||||
|
||||
virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; }
|
||||
|
||||
CSS::ValueID to_identifier() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue