From 7a9cb2dfca90f3e7930faa217fcb5d847b44fe54 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Mar 2020 11:17:18 +0100 Subject: [PATCH] LibWeb: Cache the style image value This way we don't refetch the background image every time style is recomputed (e.g when hovering different elements.) --- Libraries/LibWeb/DOM/HTMLBodyElement.cpp | 5 ++++- Libraries/LibWeb/DOM/HTMLBodyElement.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/DOM/HTMLBodyElement.cpp b/Libraries/LibWeb/DOM/HTMLBodyElement.cpp index a5fbd9dc902..5ce725f1f93 100644 --- a/Libraries/LibWeb/DOM/HTMLBodyElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLBodyElement.cpp @@ -52,7 +52,8 @@ void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const if (color.has_value()) style.set_property(CSS::PropertyID::Color, ColorStyleValue::create(color.value())); } else if (name.equals_ignoring_case("background")) { - style.set_property(CSS::PropertyID::BackgroundImage, ImageStyleValue::create(document().complete_url(value), const_cast(document()))); + ASSERT(m_background_style_value); + style.set_property(CSS::PropertyID::BackgroundImage, *m_background_style_value); } }); } @@ -71,6 +72,8 @@ void HTMLBodyElement::parse_attribute(const String& name, const String& value) auto color = Color::from_string(value); if (color.has_value()) document().set_visited_link_color(color.value()); + } else if (name.equals_ignoring_case("background")) { + m_background_style_value = ImageStyleValue::create(document().complete_url(value), const_cast(document())); } } diff --git a/Libraries/LibWeb/DOM/HTMLBodyElement.h b/Libraries/LibWeb/DOM/HTMLBodyElement.h index 22296fa46ce..cef9e3a664f 100644 --- a/Libraries/LibWeb/DOM/HTMLBodyElement.h +++ b/Libraries/LibWeb/DOM/HTMLBodyElement.h @@ -37,6 +37,9 @@ public: virtual void parse_attribute(const String&, const String&) override; virtual void apply_presentational_hints(StyleProperties&) const override; + +private: + RefPtr m_background_style_value; }; template<>