diff --git a/Libraries/LibWeb/CSS/StyleResolver.cpp b/Libraries/LibWeb/CSS/StyleResolver.cpp index 95a8cc4c84..21715ee92b 100644 --- a/Libraries/LibWeb/CSS/StyleResolver.cpp +++ b/Libraries/LibWeb/CSS/StyleResolver.cpp @@ -564,11 +564,11 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope style.set_property(property_id, value); } -NonnullRefPtr StyleResolver::resolve_style(const DOM::Element& element, const StyleProperties* parent_style) const +NonnullRefPtr StyleResolver::resolve_style(const DOM::Element& element) const { 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) { if (is_inherited_property(property_id)) set_property_expanding_shorthands(style, property_id, value, m_document); diff --git a/Libraries/LibWeb/CSS/StyleResolver.h b/Libraries/LibWeb/CSS/StyleResolver.h index 1682cf9b74..0dde35a261 100644 --- a/Libraries/LibWeb/CSS/StyleResolver.h +++ b/Libraries/LibWeb/CSS/StyleResolver.h @@ -48,7 +48,7 @@ public: DOM::Document& document() { return m_document; } const DOM::Document& document() const { return m_document; } - NonnullRefPtr resolve_style(const DOM::Element&, const StyleProperties* parent_style) const; + NonnullRefPtr resolve_style(const DOM::Element&) const; Vector collect_matching_rules(const DOM::Element&) const; void sort_matching_rules(Vector&) const; diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index c781439706..5f9a31804a 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -408,7 +408,7 @@ void Document::update_style() update_layout(); } -RefPtr Document::create_layout_node(const CSS::StyleProperties*) +RefPtr Document::create_layout_node() { return adopt(*new Layout::InitialContainingBlockBox(*this, CSS::StyleProperties::create())); } diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 23615d55a5..34e179e67c 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -223,7 +223,7 @@ public: private: explicit Document(const URL&); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; void tear_down_layout_tree(); diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index e23b5ccb66..1a2abdaa4d 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -111,9 +111,9 @@ bool Element::has_class(const FlyString& class_name) const return false; } -RefPtr Element::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr Element::create_layout_node() { - auto style = document().style_resolver().resolve_style(*this, parent_style); + auto style = document().style_resolver().resolve_style(*this); const_cast(*this).m_specified_css_values = style; auto display = style->display(); @@ -199,8 +199,7 @@ void Element::recompute_style() set_needs_style_update(false); ASSERT(parent()); auto old_specified_css_values = m_specified_css_values; - auto* parent_specified_css_values = parent()->is_element() ? downcast(*parent()).specified_css_values() : nullptr; - auto new_specified_css_values = document().style_resolver().resolve_style(*this, parent_specified_css_values); + auto new_specified_css_values = document().style_resolver().resolve_style(*this); m_specified_css_values = new_specified_css_values; if (!layout_node()) { if (new_specified_css_values->display() == CSS::Display::None) diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 6939ee6c9c..76a29fc30d 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -99,7 +99,7 @@ public: virtual bool is_focusable() const { return false; } protected: - RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + RefPtr create_layout_node() override; private: Attribute* find_attribute(const FlyString& name); diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index aca4a39637..55e062f4bc 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -105,7 +105,7 @@ void Node::set_text_content(const String& content) document().invalidate_layout(); } -RefPtr Node::create_layout_node(const CSS::StyleProperties*) +RefPtr Node::create_layout_node() { return nullptr; } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index de4b3755d9..8103bbbff6 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -84,7 +84,7 @@ public: RefPtr insert_before(NonnullRefPtr node, RefPtr child, bool notify = true); void remove_all_children(); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style); + virtual RefPtr create_layout_node(); virtual FlyString node_name() const = 0; diff --git a/Libraries/LibWeb/DOM/Text.cpp b/Libraries/LibWeb/DOM/Text.cpp index a0c6ba9dab..de7beec7b6 100644 --- a/Libraries/LibWeb/DOM/Text.cpp +++ b/Libraries/LibWeb/DOM/Text.cpp @@ -38,7 +38,7 @@ Text::~Text() { } -RefPtr Text::create_layout_node(const CSS::StyleProperties*) +RefPtr Text::create_layout_node() { return adopt(*new Layout::TextNode(document(), *this)); } diff --git a/Libraries/LibWeb/DOM/Text.h b/Libraries/LibWeb/DOM/Text.h index 5ee7595561..0e6f4a2dbd 100644 --- a/Libraries/LibWeb/DOM/Text.h +++ b/Libraries/LibWeb/DOM/Text.h @@ -42,7 +42,7 @@ public: virtual FlyString node_name() const override { return "#text"; } private: - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; }; } diff --git a/Libraries/LibWeb/HTML/HTMLBRElement.cpp b/Libraries/LibWeb/HTML/HTMLBRElement.cpp index 3d7e7e5eec..d3a0bc1b9e 100644 --- a/Libraries/LibWeb/HTML/HTMLBRElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLBRElement.cpp @@ -38,7 +38,7 @@ HTMLBRElement::~HTMLBRElement() { } -RefPtr HTMLBRElement::create_layout_node(const CSS::StyleProperties*) +RefPtr HTMLBRElement::create_layout_node() { return adopt(*new Layout::BreakNode(document(), *this)); } diff --git a/Libraries/LibWeb/HTML/HTMLBRElement.h b/Libraries/LibWeb/HTML/HTMLBRElement.h index 086900e79f..5e453c6ecb 100644 --- a/Libraries/LibWeb/HTML/HTMLBRElement.h +++ b/Libraries/LibWeb/HTML/HTMLBRElement.h @@ -37,7 +37,7 @@ public: HTMLBRElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~HTMLBRElement() override; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; }; } diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index bbad3a0657..406f18c7e8 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -55,9 +55,9 @@ unsigned HTMLCanvasElement::height() const return attribute(HTML::AttributeNames::height).to_uint().value_or(150); } -RefPtr HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr 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) return nullptr; return adopt(*new Layout::CanvasBox(document(), *this, move(style))); diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Libraries/LibWeb/HTML/HTMLCanvasElement.h index 7e114761e0..9616af98b7 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.h +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.h @@ -49,7 +49,7 @@ public: unsigned height() const; private: - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; RefPtr m_bitmap; RefPtr m_context; diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 937ca36321..e59818ba82 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -54,9 +54,9 @@ HTMLIFrameElement::~HTMLIFrameElement() { } -RefPtr HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr 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))); } diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Libraries/LibWeb/HTML/HTMLIFrameElement.h index 99f8781bfa..0237ea3c91 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.h +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.h @@ -37,7 +37,7 @@ public: HTMLIFrameElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~HTMLIFrameElement() override; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; Frame* content_frame() { return m_content_frame; } const Frame* content_frame() const { return m_content_frame; } diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cpp index c2d82fef1b..8ab8263273 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -84,9 +84,9 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu m_image_loader.load(document().complete_url(value)); } -RefPtr HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr 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) return nullptr; return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader)); diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.h b/Libraries/LibWeb/HTML/HTMLImageElement.h index 5e5971dbb1..7cc97f1983 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -53,7 +53,7 @@ private: void animate(); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; ImageLoader m_image_loader; }; diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 9ffc91041a..c5654c3530 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -62,7 +62,7 @@ void HTMLInputElement::did_click_button(Badge) } } -RefPtr HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLInputElement::create_layout_node() { ASSERT(document().page()); auto& page = *document().page(); @@ -71,7 +71,7 @@ RefPtr HTMLInputElement::create_layout_node(const CSS::StyleProper if (type() == "hidden") 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) return nullptr; diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index c3676d1dbe..b887118263 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -37,7 +37,7 @@ public: HTMLInputElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~HTMLInputElement() override; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; String type() const { return attribute(HTML::AttributeNames::type); } String value() const { return attribute(HTML::AttributeNames::value); } diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 4a3d0a11d4..a7514179d4 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -61,12 +61,12 @@ void HTMLObjectElement::parse_attribute(const FlyString& name, const String& val m_image_loader.load(document().complete_url(value)); } -RefPtr HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLObjectElement::create_layout_node() { 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) return nullptr; if (m_image_loader.has_image()) diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Libraries/LibWeb/HTML/HTMLObjectElement.h index f49e8b22c8..f07e122ff7 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -46,7 +46,7 @@ public: String type() const { return attribute(HTML::AttributeNames::type); } private: - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; ImageLoader m_image_loader; bool m_should_show_fallback_content { false }; diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp index e447976bf6..fc2b83f7b9 100644 --- a/Libraries/LibWeb/Layout/Node.cpp +++ b/Libraries/LibWeb/Layout/Node.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -215,6 +216,7 @@ NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, CSS::Comp , m_computed_values(move(computed_values)) { m_has_style = true; + m_font = Gfx::FontDatabase::default_font(); } void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) diff --git a/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Libraries/LibWeb/Layout/TreeBuilder.cpp index e73507c140..46070fa346 100644 --- a/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -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()) parent_style = downcast(*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) return; diff --git a/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Libraries/LibWeb/SVG/SVGPathElement.cpp index a0ec408fb3..b9fec926f4 100644 --- a/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -430,9 +430,9 @@ SVGPathElement::SVGPathElement(DOM::Document& document, const QualifiedName& qua { } -RefPtr SVGPathElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr 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) return nullptr; return adopt(*new Layout::SVGPathBox(document(), *this, move(style))); diff --git a/Libraries/LibWeb/SVG/SVGPathElement.h b/Libraries/LibWeb/SVG/SVGPathElement.h index cc6025fb02..738df73a13 100644 --- a/Libraries/LibWeb/SVG/SVGPathElement.h +++ b/Libraries/LibWeb/SVG/SVGPathElement.h @@ -109,7 +109,7 @@ public: SVGPathElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~SVGPathElement() override = default; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; virtual void parse_attribute(const FlyString& name, const String& value) override; diff --git a/Libraries/LibWeb/SVG/SVGSVGElement.cpp b/Libraries/LibWeb/SVG/SVGSVGElement.cpp index cd5e1e6fbd..ad0eb2e637 100644 --- a/Libraries/LibWeb/SVG/SVGSVGElement.cpp +++ b/Libraries/LibWeb/SVG/SVGSVGElement.cpp @@ -40,9 +40,9 @@ SVGSVGElement::SVGSVGElement(DOM::Document& document, const QualifiedName& quali { } -RefPtr SVGSVGElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr 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) return nullptr; return adopt(*new Layout::SVGSVGBox(document(), *this, move(style))); diff --git a/Libraries/LibWeb/SVG/SVGSVGElement.h b/Libraries/LibWeb/SVG/SVGSVGElement.h index 0e6c99b504..c84a483d07 100644 --- a/Libraries/LibWeb/SVG/SVGSVGElement.h +++ b/Libraries/LibWeb/SVG/SVGSVGElement.h @@ -37,7 +37,7 @@ public: SVGSVGElement(DOM::Document&, const QualifiedName& qualified_name); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node() override; unsigned width() const; unsigned height() const;