mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 17:37:34 +00:00
LibWeb: Apply the CSS background-image property to elements
Previously we'd only pick up background-image when it was part of the background shorthand. CSS property application remains hackish, lots of room for improvement in this area. :^)
This commit is contained in:
parent
18b6c47178
commit
95077f9a5d
1 changed files with 16 additions and 8 deletions
|
@ -402,18 +402,26 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||||
continue;
|
continue;
|
||||||
if (!string.ends_with(')'))
|
if (!string.ends_with(')'))
|
||||||
continue;
|
continue;
|
||||||
auto url = string.substring_view(4, string.length() - 5);
|
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundImage, value, document);
|
||||||
if (url.length() >= 2 && url.starts_with('"') && url.ends_with('"'))
|
|
||||||
url = url.substring_view(1, url.length() - 2);
|
|
||||||
else if (url.length() >= 2 && url.starts_with('\'') && url.ends_with('\''))
|
|
||||||
url = url.substring_view(1, url.length() - 2);
|
|
||||||
|
|
||||||
auto background_image_value = ImageStyleValue::create(document.complete_url(url), document);
|
|
||||||
style.set_property(CSS::PropertyID::BackgroundImage, move(background_image_value));
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property_id == CSS::PropertyID::BackgroundImage) {
|
||||||
|
if (!value.is_string())
|
||||||
|
return;
|
||||||
|
auto string = value.to_string();
|
||||||
|
auto url = string.substring_view(4, string.length() - 5);
|
||||||
|
if (url.length() >= 2 && url.starts_with('"') && url.ends_with('"'))
|
||||||
|
url = url.substring_view(1, url.length() - 2);
|
||||||
|
else if (url.length() >= 2 && url.starts_with('\'') && url.ends_with('\''))
|
||||||
|
url = url.substring_view(1, url.length() - 2);
|
||||||
|
|
||||||
|
auto background_image_value = ImageStyleValue::create(document.complete_url(url), document);
|
||||||
|
style.set_property(CSS::PropertyID::BackgroundImage, move(background_image_value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (property_id == CSS::PropertyID::Margin) {
|
if (property_id == CSS::PropertyID::Margin) {
|
||||||
if (value.is_length()) {
|
if (value.is_length()) {
|
||||||
style.set_property(CSS::PropertyID::MarginTop, value);
|
style.set_property(CSS::PropertyID::MarginTop, value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue