LibWeb: Rename "identifier" and "ValueID" to "Keyword" where correct

For a long time, we've used two terms, inconsistently:
- "Identifier" is a spec term, but refers to a sequence of alphanumeric
  characters, which may or may not be a keyword. (Keywords are a
  subset of all identifiers.)
- "ValueID" is entirely non-spec, and is directly called a "keyword" in
  the CSS specs.

So to avoid confusion as much as possible, let's align with the spec
terminology. I've attempted to change variable names as well, but
obviously we use Keywords in a lot of places in LibWeb and so I may
have missed some.

One exception is that I've not renamed "valid-identifiers" in
Properties.json... I'd like to combine that and the "valid-types" array
together eventually, so there's no benefit to doing an extra rename
now.
This commit is contained in:
Sam Atkins 2024-08-14 14:06:03 +01:00 committed by Sam Atkins
commit 6a74b01644
Notes: github-actions[bot] 2024-08-15 12:59:33 +00:00
48 changed files with 702 additions and 702 deletions

View file

@ -374,14 +374,14 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
}
if (auto attachment_value = value_for_layer(attachments, layer_index); attachment_value && attachment_value->is_keyword()) {
switch (attachment_value->to_identifier()) {
case CSS::ValueID::Fixed:
switch (attachment_value->to_keyword()) {
case CSS::Keyword::Fixed:
layer.attachment = CSS::BackgroundAttachment::Fixed;
break;
case CSS::ValueID::Local:
case CSS::Keyword::Local:
layer.attachment = CSS::BackgroundAttachment::Local;
break;
case CSS::ValueID::Scroll:
case CSS::Keyword::Scroll:
layer.attachment = CSS::BackgroundAttachment::Scroll;
break;
default:
@ -389,15 +389,15 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
}
}
auto as_box = [](auto value_id) {
switch (value_id) {
case CSS::ValueID::BorderBox:
auto as_box = [](auto keyword) {
switch (keyword) {
case CSS::Keyword::BorderBox:
return CSS::BackgroundBox::BorderBox;
case CSS::ValueID::ContentBox:
case CSS::Keyword::ContentBox:
return CSS::BackgroundBox::ContentBox;
case CSS::ValueID::PaddingBox:
case CSS::Keyword::PaddingBox:
return CSS::BackgroundBox::PaddingBox;
case CSS::ValueID::Text:
case CSS::Keyword::Text:
return CSS::BackgroundBox::Text;
default:
VERIFY_NOT_REACHED();
@ -405,11 +405,11 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
};
if (auto origin_value = value_for_layer(origins, layer_index); origin_value && origin_value->is_keyword()) {
layer.origin = as_box(origin_value->to_identifier());
layer.origin = as_box(origin_value->to_keyword());
}
if (auto clip_value = value_for_layer(clips, layer_index); clip_value && clip_value->is_keyword()) {
layer.clip = as_box(clip_value->to_identifier());
layer.clip = as_box(clip_value->to_keyword());
}
if (auto position_value = value_for_layer(x_positions, layer_index); position_value && position_value->is_edge()) {
@ -431,11 +431,11 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
layer.size_x = size.size_x();
layer.size_y = size.size_y();
} else if (size_value->is_keyword()) {
switch (size_value->to_identifier()) {
case CSS::ValueID::Contain:
switch (size_value->to_keyword()) {
case CSS::Keyword::Contain:
layer.size_type = CSS::BackgroundSize::Contain;
break;
case CSS::ValueID::Cover:
case CSS::Keyword::Cover:
layer.size_type = CSS::BackgroundSize::Cover;
break;
default:
@ -722,12 +722,12 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
return value->as_length().length().to_px(*this);
if (value->is_keyword()) {
// https://www.w3.org/TR/css-backgrounds-3/#valdef-line-width-thin
switch (value->to_identifier()) {
case CSS::ValueID::Thin:
switch (value->to_keyword()) {
case CSS::Keyword::Thin:
return 1;
case CSS::ValueID::Medium:
case CSS::Keyword::Medium:
return 3;
case CSS::ValueID::Thick:
case CSS::Keyword::Thick:
return 5;
default:
VERIFY_NOT_REACHED();
@ -843,22 +843,22 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
if (aspect_ratio->is_value_list()) {
auto& values_list = aspect_ratio->as_value_list().values();
if (values_list.size() == 2
&& values_list[0]->is_keyword() && values_list[0]->as_keyword().id() == CSS::ValueID::Auto
&& values_list[0]->is_keyword() && values_list[0]->as_keyword().keyword() == CSS::Keyword::Auto
&& values_list[1]->is_ratio()) {
computed_values.set_aspect_ratio({ true, values_list[1]->as_ratio().ratio() });
}
} else if (aspect_ratio->is_keyword() && aspect_ratio->as_keyword().id() == CSS::ValueID::Auto) {
} else if (aspect_ratio->is_keyword() && aspect_ratio->as_keyword().keyword() == CSS::Keyword::Auto) {
computed_values.set_aspect_ratio({ true, {} });
} else if (aspect_ratio->is_ratio()) {
computed_values.set_aspect_ratio({ false, aspect_ratio->as_ratio().ratio() });
}
auto math_shift_value = computed_style.property(CSS::PropertyID::MathShift);
if (auto math_shift = value_id_to_math_shift(math_shift_value->to_identifier()); math_shift.has_value())
if (auto math_shift = keyword_to_math_shift(math_shift_value->to_keyword()); math_shift.has_value())
computed_values.set_math_shift(math_shift.value());
auto math_style_value = computed_style.property(CSS::PropertyID::MathStyle);
if (auto math_style = value_id_to_math_style(math_style_value->to_identifier()); math_style.has_value())
if (auto math_style = keyword_to_math_style(math_style_value->to_keyword()); math_style.has_value())
computed_values.set_math_style(math_style.value());
computed_values.set_math_depth(computed_style.math_depth());