LibWeb/CSS: Implement "is a custom property name string" to spec
This will be needed in the Parser soon, so for lack of a better place, it's going in a separate header.
This commit is contained in:
parent
7723873016
commit
f11c0e6cc0
Notes:
github-actions[bot]
2024-10-14 06:09:40 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/f11c0e6cc0a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1729
2 changed files with 24 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -9,6 +9,7 @@
|
|||
#include <LibWeb/CSS/CSS.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/PropertyName.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -33,8 +34,7 @@ bool supports(JS::VM& vm, StringView property, StringView value)
|
|||
}
|
||||
|
||||
// 2. Otherwise, if property is a custom property name string, return true.
|
||||
// FIXME: This check is not enough to make sure this is a valid custom property name, but it's close enough.
|
||||
else if (property.starts_with("--"sv) && property.length() >= 3) {
|
||||
else if (is_a_custom_property_name_string(property)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
21
Userland/Libraries/LibWeb/CSS/PropertyName.h
Normal file
21
Userland/Libraries/LibWeb/CSS/PropertyName.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
// https://drafts.css-houdini.org/css-typed-om-1/#custom-property-name-string
|
||||
static bool is_a_custom_property_name_string(StringView string)
|
||||
{
|
||||
// A string is a custom property name string if it starts with two dashes (U+002D HYPHEN-MINUS), like --foo.
|
||||
return string.starts_with("--"sv);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue