LibHTML: Simplify Node::create_layout_node()

There's no need to pass the StyleResolver to this function. Nodes that
need it can just get it from the document.
This commit is contained in:
Andreas Kling 2019-10-15 15:06:16 +02:00
parent f7cd5662ef
commit f4f5ede10a
Notes: sideshowbarker 2024-07-19 11:41:16 +09:00
13 changed files with 20 additions and 30 deletions

View file

@ -16,6 +16,7 @@
Document::Document()
: ParentNode(*this, NodeType::DOCUMENT_NODE)
, m_style_resolver(make<StyleResolver>(*this))
{
}
@ -23,13 +24,6 @@ Document::~Document()
{
}
StyleResolver& Document::style_resolver()
{
if (!m_style_resolver)
m_style_resolver = make<StyleResolver>(*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<LayoutNode> Document::create_layout_node(const StyleResolver&, const StyleProperties*) const
RefPtr<LayoutNode> Document::create_layout_node(const StyleProperties*) const
{
return adopt(*new LayoutDocument(*this, StyleProperties::create()));
}

View file

@ -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<StyleSheet>& stylesheets() const { return m_sheets; }
@ -76,7 +77,7 @@ public:
const LayoutDocument* layout_node() const;
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
OwnPtr<StyleResolver> m_style_resolver;
NonnullRefPtrVector<StyleSheet> m_sheets;

View file

@ -71,12 +71,10 @@ bool Element::has_class(const StringView& class_name) const
return false;
}
RefPtr<LayoutNode> Element::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
RefPtr<LayoutNode> 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;

View file

@ -54,7 +54,7 @@ public:
const LayoutNodeWithStyle* layout_node() const { return static_cast<const LayoutNodeWithStyle*>(Node::layout_node()); }
private:
RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
Attribute* find_attribute(const String& name);
const Attribute* find_attribute(const String& name) const;

View file

@ -10,7 +10,7 @@ HTMLBRElement::~HTMLBRElement()
{
}
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const StyleResolver&, const StyleProperties*) const
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const StyleProperties*) const
{
return adopt(*new LayoutBreak(*this));
}

View file

@ -7,7 +7,7 @@ public:
HTMLBRElement(Document&, const String& tag_name);
virtual ~HTMLBRElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
};
template<>

View file

@ -60,13 +60,10 @@ int HTMLImageElement::preferred_height() const
return 0;
}
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
RefPtr<LayoutNode> 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)));

View file

@ -20,7 +20,7 @@ public:
private:
void load_image(const String& src);
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
mutable RefPtr<GraphicsBitmap> m_bitmap;
};

View file

@ -63,7 +63,7 @@ const Element* Node::previous_element_sibling() const
return nullptr;
}
RefPtr<LayoutNode> Node::create_layout_node(const StyleResolver&, const StyleProperties*) const
RefPtr<LayoutNode> Node::create_layout_node(const StyleProperties*) const
{
return nullptr;
}

View file

@ -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<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const;
virtual String tag_name() const = 0;

View file

@ -10,7 +10,7 @@ Text::~Text()
{
}
RefPtr<LayoutNode> Text::create_layout_node(const StyleResolver&, const StyleProperties*) const
RefPtr<LayoutNode> Text::create_layout_node(const StyleProperties*) const
{
return adopt(*new LayoutText(*this));
}

View file

@ -11,7 +11,7 @@ public:
virtual String tag_name() const override { return "#text"; }
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
};
template<>

View file

@ -10,7 +10,7 @@ LayoutTreeBuilder::LayoutTreeBuilder()
static RefPtr<LayoutNode> 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;