summaryrefslogtreecommitdiff
path: root/css/css.h
blob: f09cf55a04cea3a534680920eb1ecd6b7e7eeaa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * This file is part of NetSurf, http://netsurf.sourceforge.net/
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
 */

#ifndef _NETSURF_CSS_CSS_H_
#define _NETSURF_CSS_CSS_H_

#include "libxml/HTMLparser.h"
#include "css_enum.h"

/**
 * structures and typedefs
 */

typedef unsigned long colour;  /* 0xbbggrr */
#define TRANSPARENT 0x1000000
#define CSS_COLOR_INHERIT 0x2000000

struct css_length {
	float value;
	css_unit unit;
};

struct css_style {
	colour background_color;
	css_clear clear;
	colour color;
	css_display display;
	css_float float_;

	struct {
		enum { CSS_FONT_SIZE_INHERIT,
		       CSS_FONT_SIZE_ABSOLUTE,
		       CSS_FONT_SIZE_LENGTH,
		       CSS_FONT_SIZE_PERCENT } size;
		union {
			struct css_length length;
			float absolute;
			float percent;
		} value;
	} font_size;

	css_font_weight font_weight;
	css_font_style font_style;

	struct {
		enum { CSS_HEIGHT_INHERIT,
		       CSS_HEIGHT_AUTO,
		       CSS_HEIGHT_LENGTH } height;
		struct css_length length;
	} height;

	struct {
		enum { CSS_LINE_HEIGHT_INHERIT,
		       CSS_LINE_HEIGHT_ABSOLUTE,
		       CSS_LINE_HEIGHT_LENGTH,
		       CSS_LINE_HEIGHT_PERCENT } size;
		union {
			float absolute;
			struct css_length length;
			float percent;
		} value;
	} line_height;

	css_text_align text_align;

	struct {
		enum { CSS_WIDTH_INHERIT,
		       CSS_WIDTH_AUTO,
		       CSS_WIDTH_LENGTH,
		       CSS_WIDTH_PERCENT } width;
		union {
			struct css_length length;
			float percent;
		} value;
	} width;
};

struct css_stylesheet;

struct css_selector {
	const char *element;
	char *class;
	char *id;
};

struct content_css_data {
	struct css_stylesheet *css;
	unsigned int import_count;
	char **import_url;
	struct content **import_content;
};


extern const struct css_style css_base_style;
extern const struct css_style css_empty_style;
extern const struct css_style css_blank_style;


#ifdef CSS_INTERNALS

typedef enum {
	NODE_BLOCK,
	NODE_DECLARATION,
	NODE_IDENT,
	NODE_NUMBER,
	NODE_PERCENTAGE,
	NODE_DIMENSION,
	NODE_STRING,
	NODE_DELIM,
	NODE_URI,
	NODE_HASH,
	NODE_UNICODE_RANGE,
	NODE_INCLUDES,
	NODE_FUNCTION,
	NODE_DASHMATCH,
	NODE_COLON,
	NODE_COMMA,
	NODE_PLUS,
	NODE_GT,
	NODE_PAREN,
	NODE_BRAC,
	NODE_SELECTOR,
	NODE_ID,
	NODE_CLASS,
	NODE_ATTRIB,
	NODE_ATTRIB_EQ,
	NODE_ATTRIB_INC,
	NODE_ATTRIB_DM,
} node_type;

typedef enum {
	COMB_NONE,
	COMB_ANCESTOR,
	COMB_PARENT,
	COMB_PRECEDED,
} combinator;

struct node {
	node_type type;
	char *data;
	char *data2;
	struct node *left;
	struct node *right;
	struct node *next;
	combinator comb;
	struct css_style *style;
};

#include "netsurf/css/scanner.h"

#define HASH_SIZE (47 + 1)

struct css_stylesheet {
	yyscan_t lexer;
	void *parser;
	struct node *rule[HASH_SIZE];
};

struct parse_params {
	int ruleset_only;
	struct content *stylesheet;
	struct node *declaration;
};

#endif

/**
 * interface
 */

struct content;

void css_create(struct content *c);
void css_process_data(struct content *c, char *data, unsigned long size);
int css_convert(struct content *c, unsigned int width, unsigned int height);
void css_revive(struct content *c, unsigned int width, unsigned int height);
void css_reformat(struct content *c, unsigned int width, unsigned int height);
void css_destroy(struct content *c);

#ifdef CSS_INTERNALS

struct node * css_new_node(node_type type, char *data,
		struct node *left, struct node *right);
void css_free_node(struct node *node);
void css_atimport(struct content *c, struct node *node);
void css_add_ruleset(struct content *c,
		struct node *selector,
		struct node *declaration);
void css_add_declarations(struct css_style *style, struct node *declaration);
unsigned int css_hash(const char *s);

void css_parser_Trace(FILE *TraceFILE, char *zTracePrompt);
void *css_parser_Alloc(void *(*mallocProc)(int));
void css_parser_Free(void *p, void (*freeProc)(void*));
void css_parser_(void *yyp, int yymajor, char* yyminor,
		struct parse_params *param);

#endif

void css_get_style(struct content *c, xmlNode *n, struct css_style * style);
void css_cascade(struct css_style * const style, const struct css_style * const apply);
void css_merge(struct css_style * const style, const struct css_style * const apply);
void css_parse_property_list(struct css_style * style, char * str);
colour named_colour(const char *name);
void css_dump_style(const struct css_style * const style);

signed long len(struct css_length * length, struct css_style * style);

#endif