1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibWeb: Clarify StyleValue API with new naming scheme

This does a few things, that are hard to separate. For a while now, it's
been confuzing what `StyleValue::is_foo()` actually means. It sometimes
was used to check the type, and sometimes to see if it could return a
certain value type. The new naming scheme is:

- `is_length()` - is it a LengthStyleValue?
- `as_length()` - casts it to LengthStyleValue
- `has_length()` - can it return a Length?
- `to_length()` - gets the internal value out (eg, Length)

This also means, no more `static_cast<LengthStyleValue const&>(*this)`
stuff when dealing with StyleValues. :^)

Hopefully this will be a bit clearer going forward. There are lots of
places using the original methods, so I'll be going through them to
hopefully catch any issues.
This commit is contained in:
Sam Atkins 2021-09-23 19:54:19 +01:00 committed by Andreas Kling
parent 1ae0781ce1
commit 4b554ba92a
6 changed files with 263 additions and 60 deletions

View file

@ -329,13 +329,13 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
if (computed_values.opacity() == 0)
m_visible = false;
if (auto width = specified_style.property(CSS::PropertyID::Width); width.has_value() && !width.value()->is_auto())
if (auto width = specified_style.property(CSS::PropertyID::Width); width.has_value() && !width.value()->has_auto())
m_has_definite_width = true;
computed_values.set_width(specified_style.length_or_fallback(CSS::PropertyID::Width, {}));
computed_values.set_min_width(specified_style.length_or_fallback(CSS::PropertyID::MinWidth, {}));
computed_values.set_max_width(specified_style.length_or_fallback(CSS::PropertyID::MaxWidth, {}));
if (auto height = specified_style.property(CSS::PropertyID::Height); height.has_value() && !height.value()->is_auto())
if (auto height = specified_style.property(CSS::PropertyID::Height); height.has_value() && !height.value()->has_auto())
m_has_definite_height = true;
computed_values.set_height(specified_style.length_or_fallback(CSS::PropertyID::Height, {}));
computed_values.set_min_height(specified_style.length_or_fallback(CSS::PropertyID::MinHeight, {}));