mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibHTML: Start fleshing out a StyleResolver class.
This will be responsible for matching selectors and creating LayoutStyle objects for the document and its elements.
This commit is contained in:
parent
2282e89d3f
commit
2b4eea5a50
4 changed files with 58 additions and 0 deletions
23
LibHTML/CSS/StyleResolver.cpp
Normal file
23
LibHTML/CSS/StyleResolver.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <LibHTML/CSS/StyleResolver.h>
|
||||||
|
#include <LibHTML/CSS/StyleSheet.h>
|
||||||
|
|
||||||
|
StyleResolver::StyleResolver(Document& document)
|
||||||
|
: m_document(document)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleResolver::~StyleResolver()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
OwnPtr<LayoutStyle> StyleResolver::resolve_document_style(const Document& document)
|
||||||
|
{
|
||||||
|
UNUSED_PARAM(document);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
OwnPtr<LayoutStyle> StyleResolver::resolve_element_style(const Element& element)
|
||||||
|
{
|
||||||
|
UNUSED_PARAM(element);
|
||||||
|
return nullptr;
|
||||||
|
}
|
28
LibHTML/CSS/StyleResolver.h
Normal file
28
LibHTML/CSS/StyleResolver.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/OwnPtr.h>
|
||||||
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
|
#include <LibHTML/Layout/LayoutStyle.h>
|
||||||
|
|
||||||
|
class Document;
|
||||||
|
class Element;
|
||||||
|
class StyleSheet;
|
||||||
|
|
||||||
|
class StyleResolver {
|
||||||
|
public:
|
||||||
|
explicit StyleResolver(Document&);
|
||||||
|
~StyleResolver();
|
||||||
|
|
||||||
|
Document& document() { return m_document; }
|
||||||
|
const Document& document() const { return m_document; }
|
||||||
|
|
||||||
|
void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
|
||||||
|
|
||||||
|
OwnPtr<LayoutStyle> resolve_element_style(const Element&);
|
||||||
|
OwnPtr<LayoutStyle> resolve_document_style(const Document&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Document& m_document;
|
||||||
|
|
||||||
|
NonnullRefPtrVector<StyleSheet> m_sheets;
|
||||||
|
};
|
|
@ -10,6 +10,7 @@ LIBHTML_OBJS = \
|
||||||
CSS/StyleDeclaration.o \
|
CSS/StyleDeclaration.o \
|
||||||
CSS/StyleValue.o \
|
CSS/StyleValue.o \
|
||||||
CSS/StyledNode.o \
|
CSS/StyledNode.o \
|
||||||
|
CSS/StyleResolver.o \
|
||||||
CSS/DefaultStyleSheetSource.o \
|
CSS/DefaultStyleSheetSource.o \
|
||||||
Parser/HTMLParser.o \
|
Parser/HTMLParser.o \
|
||||||
Parser/CSSParser.o \
|
Parser/CSSParser.o \
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <LibHTML/Dump.h>
|
#include <LibHTML/Dump.h>
|
||||||
#include <LibHTML/Frame.h>
|
#include <LibHTML/Frame.h>
|
||||||
#include <LibHTML/Parser/CSSParser.h>
|
#include <LibHTML/Parser/CSSParser.h>
|
||||||
|
#include <LibHTML/CSS/StyleResolver.h>
|
||||||
#include <LibHTML/Parser/HTMLParser.h>
|
#include <LibHTML/Parser/HTMLParser.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -23,6 +24,11 @@ int main(int argc, char** argv)
|
||||||
auto doc = parse_html(html);
|
auto doc = parse_html(html);
|
||||||
dump_tree(doc);
|
dump_tree(doc);
|
||||||
|
|
||||||
|
StyleResolver resolver(*doc);
|
||||||
|
resolver.add_sheet(*sheet);
|
||||||
|
|
||||||
|
auto doc_style = resolver.resolve_document_style(*doc);
|
||||||
|
|
||||||
doc->build_layout_tree();
|
doc->build_layout_tree();
|
||||||
ASSERT(doc->layout_node());
|
ASSERT(doc->layout_node());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue