1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:57:35 +00:00

LibWeb: Compute element style in Layout::TreeBuilder

Instead of making each Layout::Node compute style for itself, we now
compute it in TreeBuilder before even calling create_layout_node().

For non-element DOM nodes, we create the style and layout tree node
in TreeBuilder. This allows us to move create_layout_node() from
DOM::Node to DOM::Element.
This commit is contained in:
Andreas Kling 2022-02-05 13:17:01 +01:00
parent 3451673ac8
commit 7e1bf4d300
31 changed files with 48 additions and 91 deletions

View file

@ -451,11 +451,6 @@ void Document::update_style()
set_needs_layout();
}
RefPtr<Layout::Node> Document::create_layout_node()
{
return adopt_ref(*new Layout::InitialContainingBlock(*this, style_computer().create_document_style()));
}
void Document::set_link_color(Color color)
{
m_link_color = color;

View file

@ -309,9 +309,6 @@ public:
private:
explicit Document(const AK::URL&);
// ^DOM::Node
virtual RefPtr<Layout::Node> create_layout_node() override;
// ^HTML::GlobalEventHandlers
virtual EventTarget& global_event_handlers_to_event_target() final { return *this; }

View file

@ -130,15 +130,10 @@ bool Element::has_class(const FlyString& class_name, CaseSensitivity case_sensit
});
}
RefPtr<Layout::Node> Element::create_layout_node()
RefPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{
auto style = document().style_computer().compute_style(*this);
const_cast<Element&>(*this).m_specified_css_values = style;
auto display = style->display();
if (display.is_none())
return nullptr;
if (local_name() == "noscript" && document().is_scripting_enabled())
return nullptr;

View file

@ -90,7 +90,8 @@ public:
String name() const { return attribute(HTML::AttributeNames::name); }
const CSS::StyleProperties* specified_css_values() const { return m_specified_css_values.ptr(); }
CSS::StyleProperties const* specified_css_values() const { return m_specified_css_values.ptr(); }
void set_specified_css_values(RefPtr<CSS::StyleProperties> style) { m_specified_css_values = move(style); }
NonnullRefPtr<CSS::StyleProperties> computed_style();
const CSS::CSSStyleDeclaration* inline_style() const { return m_inline_style; }
@ -128,8 +129,9 @@ public:
NonnullRefPtr<Geometry::DOMRect> get_bounding_client_rect() const;
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>);
protected:
RefPtr<Layout::Node> create_layout_node() override;
virtual void children_changed() override;
private:

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
@ -145,11 +145,6 @@ void Node::set_text_content(String const& content)
set_needs_style_update(true);
}
RefPtr<Layout::Node> Node::create_layout_node()
{
return nullptr;
}
void Node::invalidate_style()
{
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -105,8 +105,6 @@ public:
NonnullRefPtr<NodeList> child_nodes();
NonnullRefPtrVector<Node> children_as_vector() const;
virtual RefPtr<Layout::Node> create_layout_node();
virtual FlyString node_name() const = 0;
String descendant_text_content() const;

View file

@ -30,11 +30,6 @@ EventTarget* ShadowRoot::get_parent(const Event& event)
return host();
}
RefPtr<Layout::Node> ShadowRoot::create_layout_node()
{
return adopt_ref(*new Layout::BlockContainer(document(), this, CSS::ComputedValues {}));
}
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
String ShadowRoot::inner_html() const
{

View file

@ -34,7 +34,6 @@ public:
private:
// ^Node
virtual FlyString node_name() const override { return "#shadow-root"; }
virtual RefPtr<Layout::Node> create_layout_node() override;
// NOTE: The specification doesn't seem to specify a default value for closed. Assuming false for now.
bool m_closed { false };

View file

@ -19,11 +19,6 @@ Text::~Text()
{
}
RefPtr<Layout::Node> Text::create_layout_node()
{
return adopt_ref(*new Layout::TextNode(document(), *this));
}
// https://dom.spec.whatwg.org/#dom-text-text
NonnullRefPtr<Text> Text::create_with_global_object(Bindings::WindowObject& window, String const& data)
{

View file

@ -28,8 +28,6 @@ public:
void set_always_editable(bool b) { m_always_editable = b; }
private:
virtual RefPtr<Layout::Node> create_layout_node() override;
bool m_always_editable { false };
};