mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibWeb: Store Repeat values directly in BackgroundRepeatStyleValue
...as opposed to storing StyleValues, which we have to later check are IdentifierStyleValues, which store identifiers that we can convert to Repeat values later. It's fewer allocations, and we can't end up with invalid values by mistake. :^)
This commit is contained in:
parent
901a990b1b
commit
891dd46a17
4 changed files with 47 additions and 50 deletions
|
@ -693,28 +693,9 @@ Optional<BackgroundRepeatData> StyleProperties::background_repeat() const
|
|||
auto value = property(CSS::PropertyID::BackgroundRepeat);
|
||||
if (!value.has_value() || !value.value()->is_background_repeat())
|
||||
return {};
|
||||
|
||||
auto& background_repeat = value.value()->as_background_repeat();
|
||||
|
||||
auto to_repeat = [](auto value) -> Optional<CSS::Repeat> {
|
||||
switch (value->to_identifier()) {
|
||||
case CSS::ValueID::NoRepeat:
|
||||
return CSS::Repeat::NoRepeat;
|
||||
case CSS::ValueID::Repeat:
|
||||
return CSS::Repeat::Repeat;
|
||||
case CSS::ValueID::Round:
|
||||
return CSS::Repeat::Round;
|
||||
case CSS::ValueID::Space:
|
||||
return CSS::Repeat::Space;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
};
|
||||
auto repeat_x = to_repeat(background_repeat.repeat_x());
|
||||
auto repeat_y = to_repeat(background_repeat.repeat_y());
|
||||
if (repeat_x.has_value() && repeat_y.has_value())
|
||||
return BackgroundRepeatData { repeat_x.value(), repeat_y.value() };
|
||||
|
||||
return {};
|
||||
return BackgroundRepeatData { background_repeat.repeat_x(), background_repeat.repeat_y() };
|
||||
}
|
||||
|
||||
Optional<CSS::BoxShadowData> StyleProperties::box_shadow() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue