mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
LibWeb: Replace is_inherited_property() with generated code
We already include the inheritance for each property in Properties.json, so made sense to use that instead of a list in StyleResolver. Added `inherited: true` to a couple of properties to match the previous code's behavior. One of those had a FIXME which I've moved to the JSON file, which is hacky, but it works.
This commit is contained in:
parent
ea2b02186c
commit
0fba71a655
5 changed files with 36 additions and 36 deletions
|
@ -293,6 +293,7 @@
|
||||||
"initial": "normal"
|
"initial": "normal"
|
||||||
},
|
},
|
||||||
"list-style": {
|
"list-style": {
|
||||||
|
"inherited": true,
|
||||||
"longhands": [
|
"longhands": [
|
||||||
"list-style-type",
|
"list-style-type",
|
||||||
"list-style-position",
|
"list-style-position",
|
||||||
|
@ -422,7 +423,8 @@
|
||||||
"initial": "none"
|
"initial": "none"
|
||||||
},
|
},
|
||||||
"text-decoration-line": {
|
"text-decoration-line": {
|
||||||
"inherited": false,
|
"__comment": "FIXME: This property is not supposed to be inherited, but we currently rely on inheritance to propagate decorations into line boxes.",
|
||||||
|
"inherited": true,
|
||||||
"initial": "none"
|
"initial": "none"
|
||||||
},
|
},
|
||||||
"text-decoration-style": {
|
"text-decoration-style": {
|
||||||
|
|
|
@ -102,38 +102,6 @@ void StyleResolver::sort_matching_rules(Vector<MatchingRule>& matching_rules) co
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyleResolver::is_inherited_property(CSS::PropertyID property_id)
|
|
||||||
{
|
|
||||||
static HashTable<CSS::PropertyID> inherited_properties;
|
|
||||||
if (inherited_properties.is_empty()) {
|
|
||||||
inherited_properties.set(CSS::PropertyID::BorderCollapse);
|
|
||||||
inherited_properties.set(CSS::PropertyID::BorderSpacing);
|
|
||||||
inherited_properties.set(CSS::PropertyID::Color);
|
|
||||||
inherited_properties.set(CSS::PropertyID::FontFamily);
|
|
||||||
inherited_properties.set(CSS::PropertyID::FontSize);
|
|
||||||
inherited_properties.set(CSS::PropertyID::FontStyle);
|
|
||||||
inherited_properties.set(CSS::PropertyID::FontVariant);
|
|
||||||
inherited_properties.set(CSS::PropertyID::FontWeight);
|
|
||||||
inherited_properties.set(CSS::PropertyID::LetterSpacing);
|
|
||||||
inherited_properties.set(CSS::PropertyID::LineHeight);
|
|
||||||
inherited_properties.set(CSS::PropertyID::ListStyle);
|
|
||||||
inherited_properties.set(CSS::PropertyID::ListStyleImage);
|
|
||||||
inherited_properties.set(CSS::PropertyID::ListStylePosition);
|
|
||||||
inherited_properties.set(CSS::PropertyID::ListStyleType);
|
|
||||||
inherited_properties.set(CSS::PropertyID::TextAlign);
|
|
||||||
inherited_properties.set(CSS::PropertyID::TextIndent);
|
|
||||||
inherited_properties.set(CSS::PropertyID::TextTransform);
|
|
||||||
inherited_properties.set(CSS::PropertyID::Visibility);
|
|
||||||
inherited_properties.set(CSS::PropertyID::WhiteSpace);
|
|
||||||
inherited_properties.set(CSS::PropertyID::WordSpacing);
|
|
||||||
|
|
||||||
// FIXME: This property is not supposed to be inherited, but we currently
|
|
||||||
// rely on inheritance to propagate decorations into line boxes.
|
|
||||||
inherited_properties.set(CSS::PropertyID::TextDecorationLine);
|
|
||||||
}
|
|
||||||
return inherited_properties.contains(property_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Edge {
|
enum class Edge {
|
||||||
Top,
|
Top,
|
||||||
Right,
|
Right,
|
||||||
|
|
|
@ -41,8 +41,6 @@ public:
|
||||||
CustomPropertyResolutionTuple resolve_custom_property_with_specificity(DOM::Element&, String const&) const;
|
CustomPropertyResolutionTuple resolve_custom_property_with_specificity(DOM::Element&, String const&) const;
|
||||||
Optional<StyleProperty> resolve_custom_property(DOM::Element&, String const&) const;
|
Optional<StyleProperty> resolve_custom_property(DOM::Element&, String const&) const;
|
||||||
|
|
||||||
static bool is_inherited_property(CSS::PropertyID);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each_stylesheet(Callback) const;
|
void for_each_stylesheet(Callback) const;
|
||||||
|
|
|
@ -82,7 +82,7 @@ const char* string_from_property_id(PropertyID property_id) {
|
||||||
member_generator.append(R"~~~(
|
member_generator.append(R"~~~(
|
||||||
case PropertyID::@name:titlecase@:
|
case PropertyID::@name:titlecase@:
|
||||||
return "@name@";
|
return "@name@";
|
||||||
)~~~");
|
)~~~");
|
||||||
});
|
});
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
@ -91,6 +91,37 @@ const char* string_from_property_id(PropertyID property_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_inherited_property(PropertyID property_id)
|
||||||
|
{
|
||||||
|
switch (property_id) {
|
||||||
|
)~~~");
|
||||||
|
|
||||||
|
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
||||||
|
VERIFY(value.is_object());
|
||||||
|
|
||||||
|
bool inherited = false;
|
||||||
|
if (value.as_object().has("inherited")) {
|
||||||
|
auto& inherited_value = value.as_object().get("inherited");
|
||||||
|
VERIFY(inherited_value.is_bool());
|
||||||
|
inherited = inherited_value.as_bool();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inherited) {
|
||||||
|
auto member_generator = generator.fork();
|
||||||
|
member_generator.set("name:titlecase", title_casify(name));
|
||||||
|
member_generator.append(R"~~~(
|
||||||
|
case PropertyID::@name:titlecase@:
|
||||||
|
return true;
|
||||||
|
)~~~");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
generator.append(R"~~~(
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool is_pseudo_property(PropertyID property_id)
|
bool is_pseudo_property(PropertyID property_id)
|
||||||
{
|
{
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
|
|
|
@ -71,6 +71,7 @@ enum class PropertyID {
|
||||||
|
|
||||||
PropertyID property_id_from_string(const StringView&);
|
PropertyID property_id_from_string(const StringView&);
|
||||||
const char* string_from_property_id(PropertyID);
|
const char* string_from_property_id(PropertyID);
|
||||||
|
bool is_inherited_property(PropertyID);
|
||||||
bool is_pseudo_property(PropertyID);
|
bool is_pseudo_property(PropertyID);
|
||||||
|
|
||||||
} // namespace Web::CSS
|
} // namespace Web::CSS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue