Subversion Repositories Kolibri OS

Rev

Rev 4364 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * This file is part of LibCSS.
3
 * Licensed under the MIT License,
4
 *		  http://www.opensource.org/licenses/mit-license.php
5
 * Copyright 2008 John-Mark Bell 
6
 */
7
 
8
#ifndef css_stylesheet_h_
9
#define css_stylesheet_h_
10
 
11
#include 
12
#include 
13
 
14
#include 
15
 
16
#include 
17
#include 
18
#include 
19
#include 
20
 
21
#include "bytecode/bytecode.h"
22
#include "parse/parse.h"
23
#include "select/hash.h"
24
 
25
typedef struct css_rule css_rule;
26
typedef struct css_selector css_selector;
27
 
28
typedef struct css_style {
29
	css_code_t *bytecode;	      /**< Pointer to bytecode */
30
	uint32_t used;		      /**< number of code entries used */
31
	uint32_t allocated;	      /**< number of allocated code entries */
32
	struct css_stylesheet *sheet; /**< containing sheet */
33
} css_style;
34
 
35
typedef enum css_selector_type {
36
	CSS_SELECTOR_ELEMENT,
37
	CSS_SELECTOR_CLASS,
38
	CSS_SELECTOR_ID,
39
	CSS_SELECTOR_PSEUDO_CLASS,
40
	CSS_SELECTOR_PSEUDO_ELEMENT,
41
	CSS_SELECTOR_ATTRIBUTE,
42
	CSS_SELECTOR_ATTRIBUTE_EQUAL,
43
	CSS_SELECTOR_ATTRIBUTE_DASHMATCH,
44
	CSS_SELECTOR_ATTRIBUTE_INCLUDES,
45
	CSS_SELECTOR_ATTRIBUTE_PREFIX,
46
	CSS_SELECTOR_ATTRIBUTE_SUFFIX,
47
	CSS_SELECTOR_ATTRIBUTE_SUBSTRING
48
} css_selector_type;
49
 
50
typedef enum css_combinator {
51
	CSS_COMBINATOR_NONE,
52
	CSS_COMBINATOR_ANCESTOR,
53
	CSS_COMBINATOR_PARENT,
54
	CSS_COMBINATOR_SIBLING,
55
	CSS_COMBINATOR_GENERIC_SIBLING
56
} css_combinator;
57
 
58
typedef enum css_selector_detail_value_type {
59
	CSS_SELECTOR_DETAIL_VALUE_STRING,
60
	CSS_SELECTOR_DETAIL_VALUE_NTH
61
} css_selector_detail_value_type;
62
 
63
typedef union css_selector_detail_value {
64
	lwc_string *string;		/**< Interned string, or NULL */
65
	struct {
66
		int32_t a;
67
		int32_t b;
68
	} nth;				/**< Data for x = an + b */
69
} css_selector_detail_value;
70
 
71
typedef struct css_selector_detail {
72
	css_qname qname;			/**< Interned name */
73
	css_selector_detail_value value;	/**< Detail value */
74
 
75
	unsigned int type       : 4,		/**< Type of selector */
76
		     comb       : 3,		/**< Type of combinator */
77
		     next       : 1,		/**< Another selector detail
78
						 * follows */
79
		     value_type : 1,		/**< Type of value field */
80
		     negate     : 1;		/**< Detail match is inverted */
81
} css_selector_detail;
82
 
83
struct css_selector {
84
	css_selector *combinator;		/**< Combining selector */
85
 
86
	css_rule *rule;				/**< Owning rule */
87
 
88
#define CSS_SPECIFICITY_A 0x01000000
89
#define CSS_SPECIFICITY_B 0x00010000
90
#define CSS_SPECIFICITY_C 0x00000100
91
#define CSS_SPECIFICITY_D 0x00000001
92
	uint32_t specificity;			/**< Specificity of selector */
93
 
94
	css_selector_detail data;		/**< Selector data */
95
};
96
 
97
typedef enum css_rule_type {
98
	CSS_RULE_UNKNOWN,
99
	CSS_RULE_SELECTOR,
100
	CSS_RULE_CHARSET,
101
	CSS_RULE_IMPORT,
102
	CSS_RULE_MEDIA,
103
	CSS_RULE_FONT_FACE,
104
	CSS_RULE_PAGE
105
} css_rule_type;
106
 
107
typedef enum css_rule_parent_type {
108
	CSS_RULE_PARENT_STYLESHEET,
109
	CSS_RULE_PARENT_RULE
110
} css_rule_parent_type;
111
 
112
struct css_rule {
113
	void *parent;				/**< containing rule or owning
114
						 * stylesheet (defined by ptype)
115
						 */
116
	css_rule *next;				/**< next in list */
117
	css_rule *prev;				/**< previous in list */
118
 
119
	unsigned int type  :  4,		/**< css_rule_type */
120
		     index : 16,		/**< index in sheet */
121
		     items :  8,		/**< # items in rule */
122
		     ptype :  1;		/**< css_rule_parent_type */
4821 ashmew2 123
};// _ALIGNED;
3584 sourcerer 124
 
125
typedef struct css_rule_selector {
126
	css_rule base;
127
 
128
	css_selector **selectors;
129
	css_style *style;
130
} css_rule_selector;
131
 
132
typedef struct css_rule_media {
133
	css_rule base;
134
 
135
	uint64_t media;
136
 
137
	css_rule *first_child;
138
	css_rule *last_child;
139
} css_rule_media;
140
 
141
typedef struct css_rule_font_face {
142
	css_rule base;
143
 
144
	css_font_face *font_face;
145
} css_rule_font_face;
146
 
147
typedef struct css_rule_page {
148
	css_rule base;
149
 
150
	css_selector *selector;
151
	css_style *style;
152
} css_rule_page;
153
 
154
typedef struct css_rule_import {
155
	css_rule base;
156
 
157
	lwc_string *url;
158
	uint64_t media;
159
 
160
	css_stylesheet *sheet;
161
} css_rule_import;
162
 
163
typedef struct css_rule_charset {
164
	css_rule base;
165
 
166
	lwc_string *encoding;	/** \todo use MIB enum? */
167
} css_rule_charset;
168
 
169
struct css_stylesheet {
170
	css_selector_hash *selectors;		/**< Hashtable of selectors */
171
 
172
	uint32_t rule_count;			/**< Number of rules in sheet */
173
	css_rule *rule_list;			/**< List of rules in sheet */
174
	css_rule *last_rule;			/**< Last rule in list */
175
 
176
	bool disabled;				/**< Whether this sheet is
177
						 * disabled */
178
 
179
	char *url;				/**< URL of this sheet */
180
	char *title;				/**< Title of this sheet */
181
 
182
	css_language_level level;		/**< Language level of sheet */
183
	css_parser *parser;			/**< Core parser for sheet */
184
	void *parser_frontend;			/**< Frontend parser */
185
	lwc_string **propstrings;		/**< Property strings, for parser */
186
 
187
	bool quirks_allowed;			/**< Quirks permitted */
188
	bool quirks_used;			/**< Quirks actually used */
189
 
190
	bool inline_style;			/**< Is an inline style */
191
 
192
	size_t size;				/**< Size, in bytes */
193
 
194
	css_import_notification_fn import;	/**< Import notification function */
195
	void *import_pw;			/**< Private word */
196
 
197
	css_url_resolution_fn resolve;		/**< URL resolution function */
198
	void *resolve_pw;			/**< Private word */
199
 
200
	css_color_resolution_fn color;		/**< Colour resolution function */
201
	void *color_pw;				/**< Private word */
202
 
203
	/** System font resolution function */
204
	css_font_resolution_fn font;
205
	void *font_pw;				/**< Private word */
206
 
207
	css_allocator_fn alloc;			/**< Allocation function */
208
	void *pw;				/**< Private word */
209
 
210
	css_style *cached_style;		/**< Cache for style parsing */
211
 
212
	lwc_string **string_vector;             /**< Bytecode string vector */
213
	uint32_t string_vector_l;               /**< The string vector allocated
214
						 * length in entries */
215
	uint32_t string_vector_c;               /**< The number of string
216
						 * vector entries used */
217
};
218
 
219
css_error css__stylesheet_style_create(css_stylesheet *sheet,
220
		css_style **style);
221
css_error css__stylesheet_style_append(css_style *style, css_code_t code);
222
css_error css__stylesheet_style_vappend(css_style *style, uint32_t style_count,
223
		...);
224
css_error css__stylesheet_style_destroy(css_style *style);
225
css_error css__stylesheet_merge_style(css_style *target, css_style *style);
226
 
227
/** Helper function to avoid distinct buildOPV call */
228
static inline css_error css__stylesheet_style_appendOPV(css_style *style,
229
		opcode_t opcode, uint8_t flags, uint16_t value)
230
{
231
	return css__stylesheet_style_append(style,
232
			buildOPV(opcode, flags, value));
233
}
234
 
235
/** Helper function to set inherit flag */
236
static inline css_error css_stylesheet_style_inherit(css_style *style,
237
		opcode_t opcode)
238
{
239
	return css__stylesheet_style_append(style,
240
			buildOPV(opcode, FLAG_INHERIT, 0));
241
}
242
 
243
css_error css__stylesheet_selector_create(css_stylesheet *sheet,
244
		css_qname *qname, css_selector **selector);
245
css_error css__stylesheet_selector_destroy(css_stylesheet *sheet,
246
		css_selector *selector);
247
 
248
css_error css__stylesheet_selector_detail_init(css_stylesheet *sheet,
249
		css_selector_type type, css_qname *qname,
250
		css_selector_detail_value value,
251
		css_selector_detail_value_type value_type,
252
		bool negate, css_selector_detail *detail);
253
 
254
css_error css__stylesheet_selector_append_specific(css_stylesheet *sheet,
255
		css_selector **parent, const css_selector_detail *specific);
256
 
257
css_error css__stylesheet_selector_combine(css_stylesheet *sheet,
258
		css_combinator type, css_selector *a, css_selector *b);
259
 
260
css_error css__stylesheet_rule_create(css_stylesheet *sheet, css_rule_type type,
261
		css_rule **rule);
262
css_error css__stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule);
263
 
264
css_error css__stylesheet_rule_add_selector(css_stylesheet *sheet,
265
		css_rule *rule, css_selector *selector);
266
 
267
css_error css__stylesheet_rule_append_style(css_stylesheet *sheet,
268
		css_rule *rule, css_style *style);
269
 
270
css_error css__stylesheet_rule_set_charset(css_stylesheet *sheet,
271
		css_rule *rule, lwc_string *charset);
272
 
273
css_error css__stylesheet_rule_set_nascent_import(css_stylesheet *sheet,
274
		css_rule *rule, lwc_string *url, uint64_t media);
275
 
276
css_error css__stylesheet_rule_set_media(css_stylesheet *sheet,
277
		css_rule *rule, uint64_t media);
278
 
279
css_error css__stylesheet_rule_set_page_selector(css_stylesheet *sheet,
280
		css_rule *rule, css_selector *sel);
281
 
282
css_error css__stylesheet_add_rule(css_stylesheet *sheet, css_rule *rule,
283
		css_rule *parent);
284
css_error css__stylesheet_remove_rule(css_stylesheet *sheet, css_rule *rule);
285
 
286
css_error css__stylesheet_string_get(css_stylesheet *sheet,
287
		uint32_t string_number, lwc_string **string);
288
 
289
css_error css__stylesheet_string_add(css_stylesheet *sheet,
290
		lwc_string *string, uint32_t *string_number);
291
 
292
#endif
293