1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
3 /*
4 * This file is part of The Croco Library
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2.1 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 *
20 * Author: Dodji Seketeli
21 * See COPYRIGHTS file for copyright information.
22 */
24 #include <stdio.h>
25 #include "cr-utils.h"
26 #include "cr-term.h"
27 #include "cr-selector.h"
28 #include "cr-declaration.h"
30 #ifndef __CR_STATEMENT_H__
31 #define __CR_STATEMENT_H__
33 G_BEGIN_DECLS
35 /**
36 *@file
37 *Declaration of the #CRStatement class.
38 */
40 /*
41 *forward declaration of CRStyleSheet which is defined in
42 *cr-stylesheet.h
43 */
45 struct _CRStatement ;
47 /*
48 *typedef struct _CRStatement CRStatement ;
49 *this is forward declared in
50 *cr-declaration.h already.
51 */
53 struct _CRAtMediaRule ;
54 typedef struct _CRAtMediaRule CRAtMediaRule ;
56 typedef struct _CRRuleSet CRRuleSet ;
58 /**
59 *The abstraction of a css ruleset.
60 *A ruleset is made of a list of selectors,
61 *followed by a list of declarations.
62 */
63 struct _CRRuleSet
64 {
65 /**A list of instances of #CRSimpeSel*/
66 CRSelector *sel_list ;
68 /**A list of instances of #CRDeclaration*/
69 CRDeclaration *decl_list ;
71 /**
72 *The parent media rule, or NULL if
73 *no parent media rule exists.
74 */
75 CRStatement *parent_media_rule ;
76 } ;
78 /*
79 *a forward declaration of CRStylesheet.
80 *CRStylesheet is actually declared in
81 *cr-stylesheet.h
82 */
83 struct _CRStyleSheet ;
84 typedef struct _CRStyleSheet CRStyleSheet;
87 /**The @import rule abstraction.*/
88 typedef struct _CRAtImportRule CRAtImportRule ;
89 struct _CRAtImportRule
90 {
91 /**the url of the import rule*/
92 CRString *url ;
94 GList *media_list ;
96 /**
97 *the stylesheet fetched from the url, if any.
98 *this is not "owned" by #CRAtImportRule which means
99 *it is not destroyed by the destructor of #CRAtImportRule.
100 */
101 CRStyleSheet * sheet;
102 };
105 /**abstraction of an @media rule*/
106 struct _CRAtMediaRule
107 {
108 GList *media_list ;
109 CRStatement *rulesets ;
110 } ;
113 typedef struct _CRAtPageRule CRAtPageRule ;
114 /**The @page rule abstraction*/
115 struct _CRAtPageRule
116 {
117 /**a list of instances of #CRDeclaration*/
118 CRDeclaration *decl_list ;
120 /**page selector. Is a pseudo selector*/
121 CRString *name ;
122 CRString *pseudo ;
123 } ;
125 /**The @charset rule abstraction*/
126 typedef struct _CRAtCharsetRule CRAtCharsetRule ;
127 struct _CRAtCharsetRule
128 {
129 CRString * charset ;
130 };
132 /**The abstaction of the @font-face rule.*/
133 typedef struct _CRAtFontFaceRule CRAtFontFaceRule ;
134 struct _CRAtFontFaceRule
135 {
136 /*a list of instanaces of #CRDeclaration*/
137 CRDeclaration *decl_list ;
138 } ;
141 /**
142 *The possible types of css2 statements.
143 */
144 enum CRStatementType
145 {
146 /**
147 *A generic css at-rule
148 *each unknown at-rule will
149 *be of this type.
150 */
152 /**A css at-rule*/
153 AT_RULE_STMT = 0,
155 /*A css ruleset*/
156 RULESET_STMT,
158 /**A css2 import rule*/
159 AT_IMPORT_RULE_STMT,
161 /**A css2 media rule*/
162 AT_MEDIA_RULE_STMT,
164 /**A css2 page rule*/
165 AT_PAGE_RULE_STMT,
167 /**A css2 charset rule*/
168 AT_CHARSET_RULE_STMT,
170 /**A css2 font face rule*/
171 AT_FONT_FACE_RULE_STMT
172 } ;
175 /**
176 *The abstraction of css statement as defined
177 *in the chapter 4 and appendix D.1 of the css2 spec.
178 *A statement is actually a double chained list of
179 *statements.A statement can be a ruleset, an @import
180 *rule, an @page rule etc ...
181 */
182 struct _CRStatement
183 {
184 /**
185 *The type of the statement.
186 */
187 enum CRStatementType type ;
189 union
190 {
191 CRRuleSet *ruleset ;
192 CRAtImportRule *import_rule ;
193 CRAtMediaRule *media_rule ;
194 CRAtPageRule *page_rule ;
195 CRAtCharsetRule *charset_rule ;
196 CRAtFontFaceRule *font_face_rule ;
197 } kind ;
199 /*
200 *the specificity of the selector
201 *that matched this statement.
202 *This is only used by the cascading
203 *order determination algorithm.
204 */
205 gulong specificity ;
207 /*
208 *the style sheet that contains
209 *this css statement.
210 */
211 CRStyleSheet *parent_sheet ;
212 CRStatement *next ;
213 CRStatement *prev ;
215 CRParsingLocation location ;
217 /**
218 *a custom pointer useable by
219 *applications that use libcroco.
220 *libcroco itself will never modify
221 *this pointer.
222 */
223 gpointer app_data ;
225 /**
226 *a custom pointer used
227 *by the upper layers of libcroco.
228 *application should never use this
229 *pointer.
230 */
231 gpointer croco_data ;
233 } ;
236 gboolean
237 cr_statement_does_buf_parses_against_core (const guchar *a_buf,
238 enum CREncoding a_encoding) ;
239 CRStatement *
240 cr_statement_parse_from_buf (const guchar *a_buf,
241 enum CREncoding a_encoding) ;
242 CRStatement*
243 cr_statement_new_ruleset (CRStyleSheet *a_sheet,
244 CRSelector *a_sel_list,
245 CRDeclaration *a_decl_list,
246 CRStatement *a_media_rule) ;
247 CRStatement *
248 cr_statement_ruleset_parse_from_buf (const guchar * a_buf,
249 enum CREncoding a_enc) ;
251 CRStatement*
252 cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
253 CRString *a_url,
254 GList *a_media_list,
255 CRStyleSheet *a_imported_sheet) ;
257 CRStatement *
258 cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
259 enum CREncoding a_encoding) ;
261 CRStatement *
262 cr_statement_new_at_media_rule (CRStyleSheet *a_sheet,
263 CRStatement *a_ruleset,
264 GList *a_media) ;
265 CRStatement *
266 cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf,
267 enum CREncoding a_enc) ;
269 CRStatement *
270 cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
271 CRString *a_charset) ;
272 CRStatement *
273 cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf,
274 enum CREncoding a_encoding);
277 CRStatement *
278 cr_statement_new_at_font_face_rule (CRStyleSheet *a_sheet,
279 CRDeclaration *a_font_decls) ;
280 CRStatement *
281 cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf,
282 enum CREncoding a_encoding) ;
284 CRStatement *
285 cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
286 CRDeclaration *a_decl_list,
287 CRString *a_name,
288 CRString *a_pseudo) ;
289 CRStatement *
290 cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
291 enum CREncoding a_encoding) ;
293 enum CRStatus
294 cr_statement_set_parent_sheet (CRStatement *a_this,
295 CRStyleSheet *a_sheet) ;
297 enum CRStatus
298 cr_statement_get_parent_sheet (CRStatement *a_this,
299 CRStyleSheet **a_sheet) ;
301 CRStatement *
302 cr_statement_append (CRStatement *a_this,
303 CRStatement *a_new) ;
305 CRStatement*
306 cr_statement_prepend (CRStatement *a_this,
307 CRStatement *a_new) ;
309 CRStatement *
310 cr_statement_unlink (CRStatement *a_stmt) ;
312 enum CRStatus
313 cr_statement_ruleset_set_sel_list (CRStatement *a_this,
314 CRSelector *a_sel_list) ;
316 enum CRStatus
317 cr_statement_ruleset_get_sel_list (CRStatement *a_this,
318 CRSelector **a_list) ;
320 enum CRStatus
321 cr_statement_ruleset_set_decl_list (CRStatement *a_this,
322 CRDeclaration *a_list) ;
324 enum CRStatus
325 cr_statement_ruleset_get_declarations (CRStatement *a_this,
326 CRDeclaration **a_decl_list) ;
328 enum CRStatus
329 cr_statement_ruleset_append_decl2 (CRStatement *a_this,
330 CRString *a_prop, CRTerm *a_value) ;
332 enum CRStatus
333 cr_statement_ruleset_append_decl (CRStatement *a_this,
334 CRDeclaration *a_decl) ;
336 enum CRStatus
337 cr_statement_at_import_rule_set_imported_sheet (CRStatement *a_this,
338 CRStyleSheet *a_sheet) ;
340 enum CRStatus
341 cr_statement_at_import_rule_get_imported_sheet (CRStatement *a_this,
342 CRStyleSheet **a_sheet) ;
344 enum CRStatus
345 cr_statement_at_import_rule_set_url (CRStatement *a_this,
346 CRString *a_url) ;
348 enum CRStatus
349 cr_statement_at_import_rule_get_url (CRStatement *a_this,
350 CRString **a_url) ;
352 gint
353 cr_statement_at_media_nr_rules (CRStatement *a_this) ;
355 CRStatement *
356 cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) ;
358 enum CRStatus
359 cr_statement_at_page_rule_set_sel (CRStatement *a_this,
360 CRSelector *a_sel) ;
362 enum CRStatus
363 cr_statement_at_page_rule_get_sel (CRStatement *a_this,
364 CRSelector **a_sel) ;
366 enum CRStatus
367 cr_statement_at_page_rule_set_declarations (CRStatement *a_this,
368 CRDeclaration *a_decl_list) ;
370 enum CRStatus
371 cr_statement_at_page_rule_get_declarations (CRStatement *a_this,
372 CRDeclaration **a_decl_list) ;
374 enum CRStatus
375 cr_statement_at_charset_rule_set_charset (CRStatement *a_this,
376 CRString *a_charset) ;
378 enum CRStatus
379 cr_statement_at_charset_rule_get_charset (CRStatement *a_this,
380 CRString **a_charset) ;
382 enum CRStatus
383 cr_statement_at_font_face_rule_set_decls (CRStatement *a_this,
384 CRDeclaration *a_decls) ;
386 enum CRStatus
387 cr_statement_at_font_face_rule_get_decls (CRStatement *a_this,
388 CRDeclaration **a_decls) ;
390 enum CRStatus
391 cr_statement_at_font_face_rule_add_decl (CRStatement *a_this,
392 CRString *a_prop,
393 CRTerm *a_value) ;
395 gchar *
396 cr_statement_to_string (CRStatement * a_this, gulong a_indent) ;
398 gchar*
399 cr_statement_list_to_string (CRStatement *a_this, gulong a_indent) ;
401 void
402 cr_statement_dump (CRStatement *a_this, FILE *a_fp, gulong a_indent) ;
404 void
405 cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp,
406 glong a_indent) ;
408 void
409 cr_statement_dump_font_face_rule (CRStatement * a_this,
410 FILE * a_fp,
411 glong a_indent) ;
413 void
414 cr_statement_dump_page (CRStatement * a_this, FILE * a_fp,
415 gulong a_indent) ;
418 void
419 cr_statement_dump_media_rule (CRStatement * a_this,
420 FILE * a_fp,
421 gulong a_indent) ;
423 void
424 cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp,
425 gulong a_indent) ;
426 void
427 cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp,
428 gulong a_indent) ;
429 gint
430 cr_statement_nr_rules (CRStatement *a_this) ;
432 CRStatement *
433 cr_statement_get_from_list (CRStatement *a_this, int itemnr) ;
435 void
436 cr_statement_destroy (CRStatement *a_this) ;
438 G_END_DECLS
440 #endif /*__CR_STATEMENT_H__*/