mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 16:10:20 +00:00
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:
parent
f7cd5662ef
commit
f4f5ede10a
Notes:
sideshowbarker
2024-07-19 11:41:16 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f4f5ede10a9
13 changed files with 20 additions and 30 deletions
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<>
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue