From 7a3f59ae3fc29e144c0bd937aa0581cf53bfa629 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 27 Jun 2019 08:37:47 +0200 Subject: [PATCH] LibHTML: Add a StyledNode class. I'd like to try doing DOM -> style tree -> layout tree. I'm not exactly sure how it's gonna work, but we'll figure it out as we go. --- LibHTML/CSS/StyledNode.cpp | 10 ++++++++++ LibHTML/CSS/StyledNode.h | 37 +++++++++++++++++++++++++++++++++++++ LibHTML/Makefile.shared | 1 + 3 files changed, 48 insertions(+) create mode 100644 LibHTML/CSS/StyledNode.cpp create mode 100644 LibHTML/CSS/StyledNode.h diff --git a/LibHTML/CSS/StyledNode.cpp b/LibHTML/CSS/StyledNode.cpp new file mode 100644 index 0000000000..ed8a1ec211 --- /dev/null +++ b/LibHTML/CSS/StyledNode.cpp @@ -0,0 +1,10 @@ +#include + +StyledNode::StyledNode(const Node* node) + : m_node(node) +{ +} + +StyledNode::~StyledNode() +{ +} diff --git a/LibHTML/CSS/StyledNode.h b/LibHTML/CSS/StyledNode.h new file mode 100644 index 0000000000..eaf171e570 --- /dev/null +++ b/LibHTML/CSS/StyledNode.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include +#include +#include + +class Node; + +class StyledNode : public TreeNode { +public: + ~StyledNode(); + + const Node* node() const { return m_node; } + + template + inline void for_each_child(Callback callback) const + { + for (auto* node = first_child(); node; node = node->next_sibling()) + callback(*node); + } + + template + inline void for_each_child(Callback callback) + { + for (auto* node = first_child(); node; node = node->next_sibling()) + callback(*node); + } + +protected: + explicit StyledNode(const Node*); + +private: + const Node* m_node { nullptr }; + HashMap> m_property_values; +}; diff --git a/LibHTML/Makefile.shared b/LibHTML/Makefile.shared index 89340faef7..fd30a0521c 100644 --- a/LibHTML/Makefile.shared +++ b/LibHTML/Makefile.shared @@ -9,6 +9,7 @@ LIBHTML_OBJS = \ CSS/StyleRule.o \ CSS/StyleDeclaration.o \ CSS/StyleValue.o \ + CSS/StyledNode.o \ CSS/DefaultStyleSheetSource.o \ Parser/HTMLParser.o \ Parser/CSSParser.o \