mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:27:44 +00:00
LibWeb: Make DOM::Node::create_layout_node() not need parent's style
The StyleResolver can find the specified CSS values for the parent element via the DOM. Forcing everyone to locate specified values for their parent was completely unnecessary.
This commit is contained in:
parent
d9b2650dcc
commit
29a4da30b7
28 changed files with 40 additions and 39 deletions
|
@ -564,11 +564,11 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||||
style.set_property(property_id, value);
|
style.set_property(property_id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const DOM::Element& element, const StyleProperties* parent_style) const
|
NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const DOM::Element& element) const
|
||||||
{
|
{
|
||||||
auto style = StyleProperties::create();
|
auto style = StyleProperties::create();
|
||||||
|
|
||||||
if (parent_style) {
|
if (auto* parent_style = element.parent_element() ? element.parent_element()->specified_css_values() : nullptr) {
|
||||||
parent_style->for_each_property([&](auto property_id, auto& value) {
|
parent_style->for_each_property([&](auto property_id, auto& value) {
|
||||||
if (is_inherited_property(property_id))
|
if (is_inherited_property(property_id))
|
||||||
set_property_expanding_shorthands(style, property_id, value, m_document);
|
set_property_expanding_shorthands(style, property_id, value, m_document);
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
DOM::Document& document() { return m_document; }
|
DOM::Document& document() { return m_document; }
|
||||||
const DOM::Document& document() const { return m_document; }
|
const DOM::Document& document() const { return m_document; }
|
||||||
|
|
||||||
NonnullRefPtr<StyleProperties> resolve_style(const DOM::Element&, const StyleProperties* parent_style) const;
|
NonnullRefPtr<StyleProperties> resolve_style(const DOM::Element&) const;
|
||||||
|
|
||||||
Vector<MatchingRule> collect_matching_rules(const DOM::Element&) const;
|
Vector<MatchingRule> collect_matching_rules(const DOM::Element&) const;
|
||||||
void sort_matching_rules(Vector<MatchingRule>&) const;
|
void sort_matching_rules(Vector<MatchingRule>&) const;
|
||||||
|
|
|
@ -408,7 +408,7 @@ void Document::update_style()
|
||||||
update_layout();
|
update_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> Document::create_layout_node(const CSS::StyleProperties*)
|
RefPtr<Layout::Node> Document::create_layout_node()
|
||||||
{
|
{
|
||||||
return adopt(*new Layout::InitialContainingBlockBox(*this, CSS::StyleProperties::create()));
|
return adopt(*new Layout::InitialContainingBlockBox(*this, CSS::StyleProperties::create()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ public:
|
||||||
private:
|
private:
|
||||||
explicit Document(const URL&);
|
explicit Document(const URL&);
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
void tear_down_layout_tree();
|
void tear_down_layout_tree();
|
||||||
|
|
||||||
|
|
|
@ -111,9 +111,9 @@ bool Element::has_class(const FlyString& class_name) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> Element::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> Element::create_layout_node()
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
const_cast<Element&>(*this).m_specified_css_values = style;
|
const_cast<Element&>(*this).m_specified_css_values = style;
|
||||||
auto display = style->display();
|
auto display = style->display();
|
||||||
|
|
||||||
|
@ -199,8 +199,7 @@ void Element::recompute_style()
|
||||||
set_needs_style_update(false);
|
set_needs_style_update(false);
|
||||||
ASSERT(parent());
|
ASSERT(parent());
|
||||||
auto old_specified_css_values = m_specified_css_values;
|
auto old_specified_css_values = m_specified_css_values;
|
||||||
auto* parent_specified_css_values = parent()->is_element() ? downcast<Element>(*parent()).specified_css_values() : nullptr;
|
auto new_specified_css_values = document().style_resolver().resolve_style(*this);
|
||||||
auto new_specified_css_values = document().style_resolver().resolve_style(*this, parent_specified_css_values);
|
|
||||||
m_specified_css_values = new_specified_css_values;
|
m_specified_css_values = new_specified_css_values;
|
||||||
if (!layout_node()) {
|
if (!layout_node()) {
|
||||||
if (new_specified_css_values->display() == CSS::Display::None)
|
if (new_specified_css_values->display() == CSS::Display::None)
|
||||||
|
|
|
@ -99,7 +99,7 @@ public:
|
||||||
virtual bool is_focusable() const { return false; }
|
virtual bool is_focusable() const { return false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Attribute* find_attribute(const FlyString& name);
|
Attribute* find_attribute(const FlyString& name);
|
||||||
|
|
|
@ -105,7 +105,7 @@ void Node::set_text_content(const String& content)
|
||||||
document().invalidate_layout();
|
document().invalidate_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> Node::create_layout_node(const CSS::StyleProperties*)
|
RefPtr<Layout::Node> Node::create_layout_node()
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ public:
|
||||||
RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true);
|
RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true);
|
||||||
void remove_all_children();
|
void remove_all_children();
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style);
|
virtual RefPtr<Layout::Node> create_layout_node();
|
||||||
|
|
||||||
virtual FlyString node_name() const = 0;
|
virtual FlyString node_name() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ Text::~Text()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> Text::create_layout_node(const CSS::StyleProperties*)
|
RefPtr<Layout::Node> Text::create_layout_node()
|
||||||
{
|
{
|
||||||
return adopt(*new Layout::TextNode(document(), *this));
|
return adopt(*new Layout::TextNode(document(), *this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
virtual FlyString node_name() const override { return "#text"; }
|
virtual FlyString node_name() const override { return "#text"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ HTMLBRElement::~HTMLBRElement()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> HTMLBRElement::create_layout_node(const CSS::StyleProperties*)
|
RefPtr<Layout::Node> HTMLBRElement::create_layout_node()
|
||||||
{
|
{
|
||||||
return adopt(*new Layout::BreakNode(document(), *this));
|
return adopt(*new Layout::BreakNode(document(), *this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
HTMLBRElement(DOM::Document&, const QualifiedName& qualified_name);
|
HTMLBRElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||||
virtual ~HTMLBRElement() override;
|
virtual ~HTMLBRElement() override;
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,9 @@ unsigned HTMLCanvasElement::height() const
|
||||||
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
|
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> HTMLCanvasElement::create_layout_node()
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
if (style->display() == CSS::Display::None)
|
if (style->display() == CSS::Display::None)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return adopt(*new Layout::CanvasBox(document(), *this, move(style)));
|
return adopt(*new Layout::CanvasBox(document(), *this, move(style)));
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
unsigned height() const;
|
unsigned height() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
RefPtr<CanvasRenderingContext2D> m_context;
|
RefPtr<CanvasRenderingContext2D> m_context;
|
||||||
|
|
|
@ -54,9 +54,9 @@ HTMLIFrameElement::~HTMLIFrameElement()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> HTMLIFrameElement::create_layout_node()
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
return adopt(*new Layout::FrameBox(document(), *this, move(style)));
|
return adopt(*new Layout::FrameBox(document(), *this, move(style)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
HTMLIFrameElement(DOM::Document&, const QualifiedName& qualified_name);
|
HTMLIFrameElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||||
virtual ~HTMLIFrameElement() override;
|
virtual ~HTMLIFrameElement() override;
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
Frame* content_frame() { return m_content_frame; }
|
Frame* content_frame() { return m_content_frame; }
|
||||||
const Frame* content_frame() const { return m_content_frame; }
|
const Frame* content_frame() const { return m_content_frame; }
|
||||||
|
|
|
@ -84,9 +84,9 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu
|
||||||
m_image_loader.load(document().complete_url(value));
|
m_image_loader.load(document().complete_url(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> HTMLImageElement::create_layout_node()
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
if (style->display() == CSS::Display::None)
|
if (style->display() == CSS::Display::None)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader));
|
return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader));
|
||||||
|
|
|
@ -53,7 +53,7 @@ private:
|
||||||
|
|
||||||
void animate();
|
void animate();
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
ImageLoader m_image_loader;
|
ImageLoader m_image_loader;
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ void HTMLInputElement::did_click_button(Badge<Layout::ButtonBox>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> HTMLInputElement::create_layout_node()
|
||||||
{
|
{
|
||||||
ASSERT(document().page());
|
ASSERT(document().page());
|
||||||
auto& page = *document().page();
|
auto& page = *document().page();
|
||||||
|
@ -71,7 +71,7 @@ RefPtr<Layout::Node> HTMLInputElement::create_layout_node(const CSS::StyleProper
|
||||||
if (type() == "hidden")
|
if (type() == "hidden")
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
if (style->display() == CSS::Display::None)
|
if (style->display() == CSS::Display::None)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
HTMLInputElement(DOM::Document&, const QualifiedName& qualified_name);
|
HTMLInputElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||||
virtual ~HTMLInputElement() override;
|
virtual ~HTMLInputElement() override;
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
String type() const { return attribute(HTML::AttributeNames::type); }
|
String type() const { return attribute(HTML::AttributeNames::type); }
|
||||||
String value() const { return attribute(HTML::AttributeNames::value); }
|
String value() const { return attribute(HTML::AttributeNames::value); }
|
||||||
|
|
|
@ -61,12 +61,12 @@ void HTMLObjectElement::parse_attribute(const FlyString& name, const String& val
|
||||||
m_image_loader.load(document().complete_url(value));
|
m_image_loader.load(document().complete_url(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> HTMLObjectElement::create_layout_node()
|
||||||
{
|
{
|
||||||
if (m_should_show_fallback_content)
|
if (m_should_show_fallback_content)
|
||||||
return HTMLElement::create_layout_node(parent_style);
|
return HTMLElement::create_layout_node();
|
||||||
|
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
if (style->display() == CSS::Display::None)
|
if (style->display() == CSS::Display::None)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (m_image_loader.has_image())
|
if (m_image_loader.has_image())
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
String type() const { return attribute(HTML::AttributeNames::type); }
|
String type() const { return attribute(HTML::AttributeNames::type); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
ImageLoader m_image_loader;
|
ImageLoader m_image_loader;
|
||||||
bool m_should_show_fallback_content { false };
|
bool m_should_show_fallback_content { false };
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <AK/Demangle.h>
|
#include <AK/Demangle.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
#include <LibGfx/FontDatabase.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/Element.h>
|
#include <LibWeb/DOM/Element.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
|
@ -215,6 +216,7 @@ NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, CSS::Comp
|
||||||
, m_computed_values(move(computed_values))
|
, m_computed_values(move(computed_values))
|
||||||
{
|
{
|
||||||
m_has_style = true;
|
m_has_style = true;
|
||||||
|
m_font = Gfx::FontDatabase::default_font();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
||||||
|
|
|
@ -95,7 +95,7 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node)
|
||||||
if (!m_parent_stack.is_empty() && m_parent_stack.last()->dom_node() && m_parent_stack.last()->dom_node()->is_element())
|
if (!m_parent_stack.is_empty() && m_parent_stack.last()->dom_node() && m_parent_stack.last()->dom_node()->is_element())
|
||||||
parent_style = downcast<DOM::Element>(*m_parent_stack.last()->dom_node()).specified_css_values();
|
parent_style = downcast<DOM::Element>(*m_parent_stack.last()->dom_node()).specified_css_values();
|
||||||
|
|
||||||
auto layout_node = dom_node.create_layout_node(parent_style);
|
auto layout_node = dom_node.create_layout_node();
|
||||||
if (!layout_node)
|
if (!layout_node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -430,9 +430,9 @@ SVGPathElement::SVGPathElement(DOM::Document& document, const QualifiedName& qua
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> SVGPathElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> SVGPathElement::create_layout_node()
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
if (style->display() == CSS::Display::None)
|
if (style->display() == CSS::Display::None)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return adopt(*new Layout::SVGPathBox(document(), *this, move(style)));
|
return adopt(*new Layout::SVGPathBox(document(), *this, move(style)));
|
||||||
|
|
|
@ -109,7 +109,7 @@ public:
|
||||||
SVGPathElement(DOM::Document&, const QualifiedName& qualified_name);
|
SVGPathElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||||
virtual ~SVGPathElement() override = default;
|
virtual ~SVGPathElement() override = default;
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
virtual void parse_attribute(const FlyString& name, const String& value) override;
|
virtual void parse_attribute(const FlyString& name, const String& value) override;
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ SVGSVGElement::SVGSVGElement(DOM::Document& document, const QualifiedName& quali
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layout::Node> SVGSVGElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
RefPtr<Layout::Node> SVGSVGElement::create_layout_node()
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this);
|
||||||
if (style->display() == CSS::Display::None)
|
if (style->display() == CSS::Display::None)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return adopt(*new Layout::SVGSVGBox(document(), *this, move(style)));
|
return adopt(*new Layout::SVGSVGBox(document(), *this, move(style)));
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
|
|
||||||
SVGSVGElement(DOM::Document&, const QualifiedName& qualified_name);
|
SVGSVGElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
virtual RefPtr<Layout::Node> create_layout_node() override;
|
||||||
|
|
||||||
unsigned width() const;
|
unsigned width() const;
|
||||||
unsigned height() const;
|
unsigned height() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue