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