File tree Expand file tree Collapse file tree 8 files changed +36
-27
lines changed Expand file tree Collapse file tree 8 files changed +36
-27
lines changed Original file line number Diff line number Diff line change @@ -125,3 +125,8 @@ URL Document::complete_url(const String& string) const
125
125
url.set_path (fspath.string ());
126
126
return url;
127
127
}
128
+
129
+ RefPtr<LayoutNode> Document::create_layout_node (const StyleResolver&, const StyleProperties*) const
130
+ {
131
+ return adopt (*new LayoutDocument (*this , StyleProperties::create ()));
132
+ }
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ class Document : public ParentNode {
55
55
Color background_color () const ;
56
56
57
57
private:
58
+ virtual RefPtr<LayoutNode> create_layout_node (const StyleResolver&, const StyleProperties* parent_properties) const override ;
59
+
58
60
OwnPtr<StyleResolver> m_style_resolver;
59
61
NonnullRefPtrVector<StyleSheet> m_sheets;
60
62
RefPtr<Node> m_hovered_node;
Original file line number Diff line number Diff line change
1
+ #include < LibHTML/CSS/StyleResolver.h>
1
2
#include < LibHTML/DOM/Element.h>
2
3
#include < LibHTML/Layout/LayoutBlock.h>
3
4
#include < LibHTML/Layout/LayoutInline.h>
@@ -34,7 +35,7 @@ String Element::attribute(const String& name) const
34
35
{
35
36
if (auto * attribute = find_attribute (name))
36
37
return attribute->value ();
37
- return { };
38
+ return {};
38
39
}
39
40
40
41
void Element::set_attribute (const String& name, const String& value)
@@ -62,3 +63,20 @@ bool Element::has_class(const StringView& class_name) const
62
63
}
63
64
return false ;
64
65
}
66
+
67
+ RefPtr<LayoutNode> Element::create_layout_node (const StyleResolver& resolver, const StyleProperties* parent_properties) const
68
+ {
69
+ auto style_properties = resolver.resolve_style (*this , parent_properties);
70
+
71
+ auto display_property = style_properties->property (" display" );
72
+ String display = display_property.has_value () ? display_property.release_value ()->to_string () : " inline" ;
73
+
74
+ if (display == " none" )
75
+ return nullptr ;
76
+ if (display == " block" || display == " list-item" )
77
+ return adopt (*new LayoutBlock (this , move (style_properties)));
78
+ if (display == " inline" )
79
+ return adopt (*new LayoutInline (*this , move (style_properties)));
80
+
81
+ ASSERT_NOT_REACHED ();
82
+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ class Element : public ParentNode {
45
45
virtual void apply_presentational_hints (StyleProperties&) const {}
46
46
47
47
private:
48
+ RefPtr<LayoutNode> create_layout_node (const StyleResolver&, const StyleProperties* parent_properties) const override ;
49
+
48
50
Attribute* find_attribute (const String& name);
49
51
const Attribute* find_attribute (const String& name) const ;
50
52
Original file line number Diff line number Diff line change @@ -19,31 +19,6 @@ Node::~Node()
19
19
{
20
20
}
21
21
22
- RefPtr<LayoutNode> Node::create_layout_node (const StyleResolver& resolver, const StyleProperties* parent_properties) const
23
- {
24
- if (is_document ())
25
- return adopt (*new LayoutDocument (static_cast <const Document&>(*this ), StyleProperties::create ()));
26
-
27
- if (is_text ())
28
- return adopt (*new LayoutText (static_cast <const Text&>(*this )));
29
-
30
- ASSERT (is_element ());
31
-
32
- auto style_properties = resolver.resolve_style (static_cast <const Element&>(*this ), parent_properties);
33
-
34
- auto display_property = style_properties->property (" display" );
35
- String display = display_property.has_value () ? display_property.release_value ()->to_string () : " inline" ;
36
-
37
- if (display == " none" )
38
- return nullptr ;
39
- if (display == " block" || display == " list-item" )
40
- return adopt (*new LayoutBlock (this , move (style_properties)));
41
- if (display == " inline" )
42
- return adopt (*new LayoutInline (*this , move (style_properties)));
43
-
44
- ASSERT_NOT_REACHED ();
45
- }
46
-
47
22
RefPtr<LayoutNode> Node::create_layout_tree (const StyleResolver& resolver, const StyleProperties* parent_properties) const
48
23
{
49
24
auto layout_node = create_layout_node (resolver, parent_properties);
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ class Node : public TreeNode<Node> {
31
31
bool is_document () const { return type () == NodeType::DOCUMENT_NODE; }
32
32
bool is_parent_node () const { return is_element () || is_document (); }
33
33
34
- RefPtr<LayoutNode> create_layout_node (const StyleResolver&, const StyleProperties* parent_properties) const ;
34
+ virtual RefPtr<LayoutNode> create_layout_node (const StyleResolver&, const StyleProperties* parent_properties) const = 0 ;
35
35
RefPtr<LayoutNode> create_layout_tree (const StyleResolver&, const StyleProperties* parent_properties) const ;
36
36
37
37
virtual String tag_name () const = 0;
Original file line number Diff line number Diff line change @@ -10,3 +10,8 @@ Text::Text(Document& document, const String& data)
10
10
Text::~Text ()
11
11
{
12
12
}
13
+
14
+ RefPtr<LayoutNode> Text::create_layout_node (const StyleResolver&, const StyleProperties*) const
15
+ {
16
+ return adopt (*new LayoutText (*this ));
17
+ }
Original file line number Diff line number Diff line change @@ -15,5 +15,7 @@ class Text final : public Node {
15
15
virtual String text_content () const override { return m_data; }
16
16
17
17
private:
18
+ virtual RefPtr<LayoutNode> create_layout_node (const StyleResolver&, const StyleProperties* parent_properties) const override ;
19
+
18
20
String m_data;
19
21
};
You can’t perform that action at this time.
0 commit comments