diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp index a08230fa00c..9be8bc28a86 100644 --- a/Libraries/LibHTML/DOM/Document.cpp +++ b/Libraries/LibHTML/DOM/Document.cpp @@ -16,6 +16,7 @@ Document::Document() : ParentNode(*this, NodeType::DOCUMENT_NODE) + , m_style_resolver(make(*this)) { } @@ -23,13 +24,6 @@ Document::~Document() { } -StyleResolver& Document::style_resolver() -{ - if (!m_style_resolver) - m_style_resolver = make(*this); - return *m_style_resolver; -} - bool Document::is_child_allowed(const Node& node) const { switch (node.type()) { @@ -174,7 +168,7 @@ void Document::update_layout() on_layout_updated(); } -RefPtr Document::create_layout_node(const StyleResolver&, const StyleProperties*) const +RefPtr Document::create_layout_node(const StyleProperties*) const { return adopt(*new LayoutDocument(*this, StyleProperties::create())); } diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h index 6898805377d..032522b6944 100644 --- a/Libraries/LibHTML/DOM/Document.h +++ b/Libraries/LibHTML/DOM/Document.h @@ -31,7 +31,8 @@ public: void fixup(); - StyleResolver& style_resolver(); + StyleResolver& style_resolver() { return *m_style_resolver; } + const StyleResolver& style_resolver() const { return *m_style_resolver; } void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); } const NonnullRefPtrVector& stylesheets() const { return m_sheets; } @@ -76,7 +77,7 @@ public: const LayoutDocument* layout_node() const; private: - virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override; + virtual RefPtr create_layout_node(const StyleProperties* parent_style) const override; OwnPtr m_style_resolver; NonnullRefPtrVector m_sheets; diff --git a/Libraries/LibHTML/DOM/Element.cpp b/Libraries/LibHTML/DOM/Element.cpp index 67b00abcb18..f6484674217 100644 --- a/Libraries/LibHTML/DOM/Element.cpp +++ b/Libraries/LibHTML/DOM/Element.cpp @@ -71,12 +71,10 @@ bool Element::has_class(const StringView& class_name) const return false; } -RefPtr Element::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const +RefPtr Element::create_layout_node(const StyleProperties* parent_style) const { - auto style = resolver.resolve_style(*this, parent_style); - - auto display_property = style->property(CSS::PropertyID::Display); - String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline"; + auto style = document().style_resolver().resolve_style(*this, parent_style); + auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline"); if (display == "none") return nullptr; diff --git a/Libraries/LibHTML/DOM/Element.h b/Libraries/LibHTML/DOM/Element.h index 1c354a6af07..b8d342959d3 100644 --- a/Libraries/LibHTML/DOM/Element.h +++ b/Libraries/LibHTML/DOM/Element.h @@ -54,7 +54,7 @@ public: const LayoutNodeWithStyle* layout_node() const { return static_cast(Node::layout_node()); } private: - RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override; + RefPtr create_layout_node(const StyleProperties* parent_style) const override; Attribute* find_attribute(const String& name); const Attribute* find_attribute(const String& name) const; diff --git a/Libraries/LibHTML/DOM/HTMLBRElement.cpp b/Libraries/LibHTML/DOM/HTMLBRElement.cpp index c2e6d853251..b822fabae4a 100644 --- a/Libraries/LibHTML/DOM/HTMLBRElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLBRElement.cpp @@ -10,7 +10,7 @@ HTMLBRElement::~HTMLBRElement() { } -RefPtr HTMLBRElement::create_layout_node(const StyleResolver&, const StyleProperties*) const +RefPtr HTMLBRElement::create_layout_node(const StyleProperties*) const { return adopt(*new LayoutBreak(*this)); } diff --git a/Libraries/LibHTML/DOM/HTMLBRElement.h b/Libraries/LibHTML/DOM/HTMLBRElement.h index 086b2b960d3..413f0a11611 100644 --- a/Libraries/LibHTML/DOM/HTMLBRElement.h +++ b/Libraries/LibHTML/DOM/HTMLBRElement.h @@ -7,7 +7,7 @@ public: HTMLBRElement(Document&, const String& tag_name); virtual ~HTMLBRElement() override; - virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override; + virtual RefPtr create_layout_node(const StyleProperties* parent_style) const override; }; template<> diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.cpp b/Libraries/LibHTML/DOM/HTMLImageElement.cpp index 3d6a8d0ae47..2b34659a466 100644 --- a/Libraries/LibHTML/DOM/HTMLImageElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLImageElement.cpp @@ -60,13 +60,10 @@ int HTMLImageElement::preferred_height() const return 0; } -RefPtr HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const +RefPtr HTMLImageElement::create_layout_node(const StyleProperties* parent_style) const { - auto style = resolver.resolve_style(*this, parent_style); - - auto display_property = style->property(CSS::PropertyID::Display); - String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline"; - + auto style = document().style_resolver().resolve_style(*this, parent_style); + auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline"); if (display == "none") return nullptr; return adopt(*new LayoutImage(*this, move(style))); diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.h b/Libraries/LibHTML/DOM/HTMLImageElement.h index b79fdcb80f3..d9091fb0527 100644 --- a/Libraries/LibHTML/DOM/HTMLImageElement.h +++ b/Libraries/LibHTML/DOM/HTMLImageElement.h @@ -20,7 +20,7 @@ public: private: void load_image(const String& src); - virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override; + virtual RefPtr create_layout_node(const StyleProperties* parent_style) const override; mutable RefPtr m_bitmap; }; diff --git a/Libraries/LibHTML/DOM/Node.cpp b/Libraries/LibHTML/DOM/Node.cpp index cfd48d0c206..f6880c7075f 100644 --- a/Libraries/LibHTML/DOM/Node.cpp +++ b/Libraries/LibHTML/DOM/Node.cpp @@ -63,7 +63,7 @@ const Element* Node::previous_element_sibling() const return nullptr; } -RefPtr Node::create_layout_node(const StyleResolver&, const StyleProperties*) const +RefPtr Node::create_layout_node(const StyleProperties*) const { return nullptr; } diff --git a/Libraries/LibHTML/DOM/Node.h b/Libraries/LibHTML/DOM/Node.h index ca71a5fb2fb..66ff78f4f72 100644 --- a/Libraries/LibHTML/DOM/Node.h +++ b/Libraries/LibHTML/DOM/Node.h @@ -37,7 +37,7 @@ public: bool is_character_data() const { return type() == NodeType::TEXT_NODE || type() == NodeType::COMMENT_NODE; } bool is_parent_node() const { return is_element() || is_document(); } - virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const; + virtual RefPtr create_layout_node(const StyleProperties* parent_style) const; virtual String tag_name() const = 0; diff --git a/Libraries/LibHTML/DOM/Text.cpp b/Libraries/LibHTML/DOM/Text.cpp index 4dc3d34ff9c..843133b82e3 100644 --- a/Libraries/LibHTML/DOM/Text.cpp +++ b/Libraries/LibHTML/DOM/Text.cpp @@ -10,7 +10,7 @@ Text::~Text() { } -RefPtr Text::create_layout_node(const StyleResolver&, const StyleProperties*) const +RefPtr Text::create_layout_node(const StyleProperties*) const { return adopt(*new LayoutText(*this)); } diff --git a/Libraries/LibHTML/DOM/Text.h b/Libraries/LibHTML/DOM/Text.h index 30dd7d02c8d..c159f74418c 100644 --- a/Libraries/LibHTML/DOM/Text.h +++ b/Libraries/LibHTML/DOM/Text.h @@ -11,7 +11,7 @@ public: virtual String tag_name() const override { return "#text"; } private: - virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override; + virtual RefPtr create_layout_node(const StyleProperties* parent_style) const override; }; template<> diff --git a/Libraries/LibHTML/Layout/LayoutTreeBuilder.cpp b/Libraries/LibHTML/Layout/LayoutTreeBuilder.cpp index 4345d8be5de..1b56bb830c4 100644 --- a/Libraries/LibHTML/Layout/LayoutTreeBuilder.cpp +++ b/Libraries/LibHTML/Layout/LayoutTreeBuilder.cpp @@ -10,7 +10,7 @@ LayoutTreeBuilder::LayoutTreeBuilder() static RefPtr create_layout_tree(Node& node, const StyleProperties* parent_style) { - auto layout_node = node.create_layout_node(node.document().style_resolver(), parent_style); + auto layout_node = node.create_layout_node(parent_style); if (!layout_node) return nullptr;