diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index cb528c7252..b370c7da8e 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2394,9 +2394,9 @@ RefPtr Parser::parse_background_value(ParsingContext const& context, { RefPtr background_color; RefPtr background_image; - RefPtr background_repeat; RefPtr background_position; - // FIXME: Implement background-size. + RefPtr background_size; + RefPtr background_repeat; RefPtr background_attachment; RefPtr background_clip; RefPtr background_origin; @@ -2456,7 +2456,19 @@ RefPtr Parser::parse_background_value(ParsingContext const& context, tokens.reconsume_current_input_token(); if (auto maybe_background_position = parse_single_background_position_value(context, tokens)) { background_position = maybe_background_position.release_nonnull(); - // FIXME: background-size optionally goes here, after a '/' + + // Attempt to parse `/ ` + auto before_slash = tokens.position(); + auto& maybe_slash = tokens.next_token(); + if (maybe_slash.is(Token::Type::Delim) && maybe_slash.token().delim() == "/"sv) { + if (auto maybe_background_size = parse_single_background_size_value(context, tokens)) { + background_size = maybe_background_size.release_nonnull(); + continue; + } + return nullptr; + } + + tokens.rewind_to_position(before_slash); continue; } return nullptr; @@ -2481,6 +2493,8 @@ RefPtr Parser::parse_background_value(ParsingContext const& context, background_image = property_initial_value(PropertyID::BackgroundImage); if (!background_position) background_position = property_initial_value(PropertyID::BackgroundPosition); + if (!background_size) + background_size = property_initial_value(PropertyID::BackgroundSize); if (!background_repeat) background_repeat = property_initial_value(PropertyID::BackgroundRepeat); if (!background_attachment) @@ -2497,6 +2511,7 @@ RefPtr Parser::parse_background_value(ParsingContext const& context, background_color.release_nonnull(), background_image.release_nonnull(), background_position.release_nonnull(), + background_size.release_nonnull(), background_repeat.release_nonnull(), background_attachment.release_nonnull(), background_origin.release_nonnull(), diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index f4f40b868c..c66bc0ccb8 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -653,6 +653,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: auto maybe_background_color = property(CSS::PropertyID::BackgroundColor); auto maybe_background_image = property(CSS::PropertyID::BackgroundImage); auto maybe_background_position = property(CSS::PropertyID::BackgroundPosition); + auto maybe_background_size = property(CSS::PropertyID::BackgroundSize); auto maybe_background_repeat = property(CSS::PropertyID::BackgroundRepeat); auto maybe_background_attachment = property(CSS::PropertyID::BackgroundAttachment); auto maybe_background_origin = property(CSS::PropertyID::BackgroundOrigin); @@ -662,6 +663,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: value_or_default(maybe_background_color, InitialStyleValue::the()), value_or_default(maybe_background_image, IdentifierStyleValue::create(CSS::ValueID::None)), value_or_default(maybe_background_position, PositionStyleValue::create(PositionEdge::Left, Length::make_px(0), PositionEdge::Top, Length::make_px(0))), + value_or_default(maybe_background_size, IdentifierStyleValue::create(CSS::ValueID::Auto)), value_or_default(maybe_background_repeat, BackgroundRepeatStyleValue::create(CSS::Repeat::Repeat, CSS::Repeat::Repeat)), value_or_default(maybe_background_attachment, IdentifierStyleValue::create(CSS::ValueID::Scroll)), value_or_default(maybe_background_origin, IdentifierStyleValue::create(CSS::ValueID::PaddingBox)), diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 3c11ffd36a..e99b1108cb 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -297,6 +297,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundColor, background.color(), document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundImage, background.image(), document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundPosition, background.position(), document); + set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundSize, background.size(), document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeat, background.repeat(), document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundAttachment, background.attachment(), document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundOrigin, background.origin(), document); @@ -322,6 +323,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundColor, value, document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundImage, value, document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundPosition, value, document); + set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundSize, value, document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeat, value, document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundAttachment, value, document); set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundOrigin, value, document); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index b712b7df4b..faab372d81 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -398,12 +398,13 @@ public: NonnullRefPtr color, NonnullRefPtr image, NonnullRefPtr position, + NonnullRefPtr size, NonnullRefPtr repeat, NonnullRefPtr attachment, NonnullRefPtr origin, NonnullRefPtr clip) { - return adopt_ref(*new BackgroundStyleValue(color, image, position, repeat, attachment, origin, clip)); + return adopt_ref(*new BackgroundStyleValue(color, image, position, size, repeat, attachment, origin, clip)); } virtual ~BackgroundStyleValue() override { } @@ -414,10 +415,11 @@ public: NonnullRefPtr origin() const { return m_origin; } NonnullRefPtr position() const { return m_position; } NonnullRefPtr repeat() const { return m_repeat; } + NonnullRefPtr size() const { return m_size; } virtual String to_string() const override { - return String::formatted("{} {} {} {} {} {} {}", m_color->to_string(), m_image->to_string(), m_position->to_string(), m_repeat->to_string(), m_attachment->to_string(), m_origin->to_string(), m_clip->to_string()); + return String::formatted("{} {} {} {} {} {} {} {}", m_color->to_string(), m_image->to_string(), m_position->to_string(), m_size->to_string(), m_repeat->to_string(), m_attachment->to_string(), m_origin->to_string(), m_clip->to_string()); } private: @@ -425,6 +427,7 @@ private: NonnullRefPtr color, NonnullRefPtr image, NonnullRefPtr position, + NonnullRefPtr size, NonnullRefPtr repeat, NonnullRefPtr attachment, NonnullRefPtr origin, @@ -433,6 +436,7 @@ private: , m_color(color) , m_image(image) , m_position(position) + , m_size(size) , m_repeat(repeat) , m_attachment(attachment) , m_origin(origin) @@ -442,7 +446,7 @@ private: NonnullRefPtr m_color; NonnullRefPtr m_image; NonnullRefPtr m_position; - // FIXME: background-size + NonnullRefPtr m_size; NonnullRefPtr m_repeat; NonnullRefPtr m_attachment; NonnullRefPtr m_origin;