Skip to content

Commit 891e668

Browse files
committed
LibHTML: Add an empty CSS parser.
1 parent 85d7102 commit 891e668

File tree

14 files changed

+66
-10
lines changed

14 files changed

+66
-10
lines changed

LibHTML/CSS/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DefaultStyleSheetSource.cpp

LibHTML/CSS/StyleDeclaration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class StyleDeclaration : public RefCounted<StyleDeclaration> {
77
public:
8-
NonnullRefPtr<StyleDeclaration> create(const String& property_name, NonnullRefPtr<StyleValue>&& value)
8+
static NonnullRefPtr<StyleDeclaration> create(const String& property_name, NonnullRefPtr<StyleValue>&& value)
99
{
1010
return adopt(*new StyleDeclaration(property_name, move(value)));
1111
}

LibHTML/CSS/StyleRule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ StyleRule::StyleRule(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDec
44
: m_selectors(move(selectors))
55
, m_declarations(move(declarations))
66
{
7+
}
78

9+
StyleRule::~StyleRule()
10+
{
811
}

LibHTML/CSS/StyleRule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class StyleRule : public RefCounted<StyleRule> {
88
public:
9-
NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
9+
static NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
1010
{
1111
return adopt(*new StyleRule(move(selectors), move(declarations)));
1212
}

LibHTML/CSS/StyleSheet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class StyleSheet : public RefCounted<StyleSheet> {
77
public:
8-
NonnullRefPtr<StyleSheet> create(Vector<NonnullRefPtr<StyleRule>>&& rules)
8+
static NonnullRefPtr<StyleSheet> create(Vector<NonnullRefPtr<StyleRule>>&& rules)
99
{
1010
return adopt(*new StyleSheet(move(rules)));
1111
}

LibHTML/Dump.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <LibHTML/CSS/StyleSheet.h>
12
#include <LibHTML/DOM/Document.h>
23
#include <LibHTML/DOM/Element.h>
34
#include <LibHTML/DOM/Text.h>
@@ -65,3 +66,8 @@ void dump_tree(const LayoutNode& layout_node)
6566
});
6667
--indent;
6768
}
69+
70+
void dump_sheet(const StyleSheet& sheet)
71+
{
72+
printf("StyleSheet{%p}: %d rule(s)\n", &sheet, sheet.rules().size());
73+
}

LibHTML/Dump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
class Node;
44
class LayoutNode;
5+
class StyleSheet;
56

67
void dump_tree(const Node&);
78
void dump_tree(const LayoutNode&);
9+
void dump_sheet(const StyleSheet&);

LibHTML/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ LIBHTML_OBJS = \
1111
CSS/StyleRule.o \
1212
CSS/StyleDeclaration.o \
1313
CSS/StyleValue.o \
14-
Parser/Parser.o \
14+
CSS/DefaultStyleSheetSource.o \
15+
Parser/HTMLParser.o \
16+
Parser/CSSParser.o \
1517
Layout/LayoutNode.o \
1618
Layout/LayoutText.o \
1719
Layout/LayoutBlock.o \
@@ -21,6 +23,9 @@ LIBHTML_OBJS = \
2123
Frame.o \
2224
Dump.o
2325

26+
GENERATED_SOURCES = \
27+
CSS/DefaultStyleSheetSource.cpp
28+
2429
TEST_OBJS = test.o
2530
TEST_PROGRAM = tho
2631

@@ -31,6 +36,9 @@ DEFINES += -DUSERLAND
3136

3237
all: $(LIBRARY) $(TEST_PROGRAM)
3338

39+
CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSource.sh
40+
@echo "GENERATE $@"; Scripts/GenerateStyleSheetSource.sh default_stylesheet_source $< > $@
41+
3442
$(TEST_PROGRAM): $(TEST_OBJS) $(LIBRARY)
3543
$(LD) -o $@ $(LDFLAGS) -L. $(TEST_OBJS) -lhtml -lgui -lcore -lc
3644

@@ -43,7 +51,7 @@ $(LIBRARY): $(LIBHTML_OBJS)
4351
-include $(OBJS:%.o=%.d)
4452

4553
clean:
46-
@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d
54+
@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
4755

4856
install: $(LIBRARY)
4957
mkdir -p ../Root/usr/include/LibHTML

LibHTML/Parser/CSSParser.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <LibHTML/CSS/StyleSheet.h>
2+
#include <LibHTML/Parser/CSSParser.h>
3+
#include <ctype.h>
4+
#include <stdio.h>
5+
6+
NonnullRefPtr<StyleSheet> parse_css(const String& css)
7+
{
8+
Vector<NonnullRefPtr<StyleRule>> rules;
9+
10+
return StyleSheet::create(move(rules));
11+
}

LibHTML/Parser/CSSParser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include <AK/NonnullRefPtr.h>
4+
#include <LibHTML/CSS/StyleSheet.h>
5+
6+
NonnullRefPtr<StyleSheet> parse_css(const String&);
7+

0 commit comments

Comments
 (0)