mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibHTML: Add an empty CSS parser.
This commit is contained in:
parent
85d71024f7
commit
891e668e35
Notes:
sideshowbarker
2024-07-19 13:32:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/891e668e35f
14 changed files with 67 additions and 11 deletions
1
LibHTML/CSS/.gitignore
vendored
Normal file
1
LibHTML/CSS/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
DefaultStyleSheetSource.cpp
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class StyleDeclaration : public RefCounted<StyleDeclaration> {
|
||||
public:
|
||||
NonnullRefPtr<StyleDeclaration> create(const String& property_name, NonnullRefPtr<StyleValue>&& value)
|
||||
static NonnullRefPtr<StyleDeclaration> create(const String& property_name, NonnullRefPtr<StyleValue>&& value)
|
||||
{
|
||||
return adopt(*new StyleDeclaration(property_name, move(value)));
|
||||
}
|
||||
|
|
|
@ -4,5 +4,8 @@ StyleRule::StyleRule(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDec
|
|||
: m_selectors(move(selectors))
|
||||
, m_declarations(move(declarations))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StyleRule::~StyleRule()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
class StyleRule : public RefCounted<StyleRule> {
|
||||
public:
|
||||
NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
|
||||
static NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
|
||||
{
|
||||
return adopt(*new StyleRule(move(selectors), move(declarations)));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class StyleSheet : public RefCounted<StyleSheet> {
|
||||
public:
|
||||
NonnullRefPtr<StyleSheet> create(Vector<NonnullRefPtr<StyleRule>>&& rules)
|
||||
static NonnullRefPtr<StyleSheet> create(Vector<NonnullRefPtr<StyleRule>>&& rules)
|
||||
{
|
||||
return adopt(*new StyleSheet(move(rules)));
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <LibHTML/CSS/StyleSheet.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/DOM/Text.h>
|
||||
|
@ -65,3 +66,8 @@ void dump_tree(const LayoutNode& layout_node)
|
|||
});
|
||||
--indent;
|
||||
}
|
||||
|
||||
void dump_sheet(const StyleSheet& sheet)
|
||||
{
|
||||
printf("StyleSheet{%p}: %d rule(s)\n", &sheet, sheet.rules().size());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
class Node;
|
||||
class LayoutNode;
|
||||
class StyleSheet;
|
||||
|
||||
void dump_tree(const Node&);
|
||||
void dump_tree(const LayoutNode&);
|
||||
void dump_sheet(const StyleSheet&);
|
||||
|
|
|
@ -11,7 +11,9 @@ LIBHTML_OBJS = \
|
|||
CSS/StyleRule.o \
|
||||
CSS/StyleDeclaration.o \
|
||||
CSS/StyleValue.o \
|
||||
Parser/Parser.o \
|
||||
CSS/DefaultStyleSheetSource.o \
|
||||
Parser/HTMLParser.o \
|
||||
Parser/CSSParser.o \
|
||||
Layout/LayoutNode.o \
|
||||
Layout/LayoutText.o \
|
||||
Layout/LayoutBlock.o \
|
||||
|
@ -21,6 +23,9 @@ LIBHTML_OBJS = \
|
|||
Frame.o \
|
||||
Dump.o
|
||||
|
||||
GENERATED_SOURCES = \
|
||||
CSS/DefaultStyleSheetSource.cpp
|
||||
|
||||
TEST_OBJS = test.o
|
||||
TEST_PROGRAM = tho
|
||||
|
||||
|
@ -31,6 +36,9 @@ DEFINES += -DUSERLAND
|
|||
|
||||
all: $(LIBRARY) $(TEST_PROGRAM)
|
||||
|
||||
CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSource.sh
|
||||
@echo "GENERATE $@"; Scripts/GenerateStyleSheetSource.sh default_stylesheet_source $< > $@
|
||||
|
||||
$(TEST_PROGRAM): $(TEST_OBJS) $(LIBRARY)
|
||||
$(LD) -o $@ $(LDFLAGS) -L. $(TEST_OBJS) -lhtml -lgui -lcore -lc
|
||||
|
||||
|
@ -43,7 +51,7 @@ $(LIBRARY): $(LIBHTML_OBJS)
|
|||
-include $(OBJS:%.o=%.d)
|
||||
|
||||
clean:
|
||||
@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d
|
||||
@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
|
||||
|
||||
install: $(LIBRARY)
|
||||
mkdir -p ../Root/usr/include/LibHTML
|
||||
|
|
11
LibHTML/Parser/CSSParser.cpp
Normal file
11
LibHTML/Parser/CSSParser.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <LibHTML/CSS/StyleSheet.h>
|
||||
#include <LibHTML/Parser/CSSParser.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
NonnullRefPtr<StyleSheet> parse_css(const String& css)
|
||||
{
|
||||
Vector<NonnullRefPtr<StyleRule>> rules;
|
||||
|
||||
return StyleSheet::create(move(rules));
|
||||
}
|
7
LibHTML/Parser/CSSParser.h
Normal file
7
LibHTML/Parser/CSSParser.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibHTML/CSS/StyleSheet.h>
|
||||
|
||||
NonnullRefPtr<StyleSheet> parse_css(const String&);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/DOM/Text.h>
|
||||
#include <LibHTML/Parser/Parser.h>
|
||||
#include <LibHTML/Parser/HTMLParser.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -32,7 +32,7 @@ static bool is_self_closing_tag(const String& tag_name)
|
|||
|| tag_name == "wbr";
|
||||
}
|
||||
|
||||
NonnullRefPtr<Document> parse(const String& html)
|
||||
NonnullRefPtr<Document> parse_html(const String& html)
|
||||
{
|
||||
Vector<NonnullRefPtr<ParentNode>> node_stack;
|
||||
|
|
@ -3,5 +3,5 @@
|
|||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
|
||||
NonnullRefPtr<Document> parse(const String& html);
|
||||
NonnullRefPtr<Document> parse_html(const String&);
|
||||
|
10
LibHTML/Scripts/GenerateStyleSheetSource.sh
Executable file
10
LibHTML/Scripts/GenerateStyleSheetSource.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "extern const char $1[];"
|
||||
echo "const char $1[] = \"\\"
|
||||
IFS=$'\n'
|
||||
for line in $(cat $2); do
|
||||
echo $line"\\"
|
||||
done
|
||||
echo "\";"
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
#include <LibCore/CFile.h>
|
||||
#include <LibHTML/Dump.h>
|
||||
#include <LibHTML/Frame.h>
|
||||
#include <LibHTML/Parser/Parser.h>
|
||||
#include <LibHTML/Parser/CSSParser.h>
|
||||
#include <LibHTML/Parser/HTMLParser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
@ -11,8 +12,15 @@ int main(int argc, char** argv)
|
|||
fprintf(stderr, "Error: %s\n", f.error_string());
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern const char default_stylesheet_source[];
|
||||
String css = default_stylesheet_source;
|
||||
|
||||
auto sheet = parse_css(css);
|
||||
dump_sheet(sheet);
|
||||
|
||||
String html = String::copy(f.read_all());
|
||||
auto doc = parse(html);
|
||||
auto doc = parse_html(html);
|
||||
dump_tree(doc);
|
||||
|
||||
doc->build_layout_tree();
|
||||
|
|
Loading…
Reference in a new issue