diff --git a/Libraries/LibHTML/CSS/StyleProperties.cpp b/Libraries/LibHTML/CSS/StyleProperties.cpp
index d179ce9718..25ec56b950 100644
--- a/Libraries/LibHTML/CSS/StyleProperties.cpp
+++ b/Libraries/LibHTML/CSS/StyleProperties.cpp
@@ -3,6 +3,25 @@
#include
#include
+StyleProperties::StyleProperties()
+{
+}
+
+StyleProperties::StyleProperties(const StyleProperties& other)
+ : m_property_values(*new HashMap(other.m_property_values))
+{
+ if (other.m_font) {
+ m_font = other.m_font->clone();
+ } else {
+ m_font = nullptr;
+ }
+}
+
+NonnullRefPtr StyleProperties::clone() const
+{
+ return adopt(*new StyleProperties(*this));
+}
+
void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr value)
{
m_property_values.set((unsigned)id, move(value));
diff --git a/Libraries/LibHTML/CSS/StyleProperties.h b/Libraries/LibHTML/CSS/StyleProperties.h
index 79ef18226f..454267c3f1 100644
--- a/Libraries/LibHTML/CSS/StyleProperties.h
+++ b/Libraries/LibHTML/CSS/StyleProperties.h
@@ -9,14 +9,13 @@ class Color;
class StyleProperties : public RefCounted {
public:
+ StyleProperties();
+
+ explicit StyleProperties(const StyleProperties&);
+
static NonnullRefPtr create() { return adopt(*new StyleProperties); }
- static NonnullRefPtr create(const StyleProperties& properties) {
- auto style_properties = new StyleProperties();
- properties.for_each_property([&](auto property_id, auto& property_value) {
- style_properties->set_property(property_id, property_value);
- });
- return adopt(*style_properties);
- }
+
+ NonnullRefPtr clone() const;
template
inline void for_each_property(Callback callback) const
diff --git a/Libraries/LibHTML/DOM/Element.cpp b/Libraries/LibHTML/DOM/Element.cpp
index d0e6d92d53..08b86e88e3 100644
--- a/Libraries/LibHTML/DOM/Element.cpp
+++ b/Libraries/LibHTML/DOM/Element.cpp
@@ -165,7 +165,7 @@ void Element::recompute_style()
RefPtr Element::computed_style()
{
- auto properties = StyleProperties::create(*m_resolved_style);
+ auto properties = m_resolved_style->clone();
if (layout_node() && layout_node()->has_style()) {
CSS::PropertyID box_model_metrics[] = {
CSS::PropertyID::MarginTop,