Libcroco
cr-statement.h
Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00018  * USA
00019  * 
00020  * Author: Dodji Seketeli
00021  * See COPYRIGHTS file for copyright information.
00022  */
00023 
00024 #include <stdio.h>
00025 #include "cr-utils.h"
00026 #include "cr-term.h"
00027 #include "cr-selector.h"
00028 #include "cr-declaration.h"
00029 
00030 #ifndef __CR_STATEMENT_H__
00031 #define __CR_STATEMENT_H__
00032 
00033 G_BEGIN_DECLS
00034 
00035 /**
00036  *@file
00037  *Declaration of the #CRStatement class.
00038  */
00039 
00040 /*
00041  *forward declaration of CRStyleSheet which is defined in
00042  *cr-stylesheet.h
00043  */
00044 
00045 struct _CRStatement ;
00046 
00047 /*
00048  *typedef struct _CRStatement CRStatement ; 
00049  *this is forward declared in 
00050  *cr-declaration.h already.
00051  */
00052 
00053 struct _CRAtMediaRule ;
00054 typedef struct _CRAtMediaRule CRAtMediaRule ;
00055 
00056 typedef struct _CRRuleSet CRRuleSet ;
00057 
00058 /**
00059  *The abstraction of a css ruleset.
00060  *A ruleset is made of a list of selectors,
00061  *followed by a list of declarations.
00062  */
00063 struct _CRRuleSet
00064 {
00065         /**A list of instances of #CRSimpeSel*/
00066         CRSelector *sel_list ;
00067 
00068         /**A list of instances of #CRDeclaration*/
00069         CRDeclaration *decl_list ;
00070         
00071         /**
00072          *The parent media rule, or NULL if
00073          *no parent media rule exists.
00074          */
00075         CRStatement *parent_media_rule ;
00076 } ;
00077 
00078 /*
00079  *a forward declaration of CRStylesheet.
00080  *CRStylesheet is actually declared in
00081  *cr-stylesheet.h
00082  */
00083 struct _CRStyleSheet ;
00084 typedef struct _CRStyleSheet CRStyleSheet;
00085 
00086 
00087 /**The \@import rule abstraction.*/
00088 typedef struct _CRAtImportRule CRAtImportRule ;
00089 struct _CRAtImportRule
00090 {
00091         /**the url of the import rule*/
00092         CRString *url ;
00093 
00094         GList *media_list ;
00095 
00096         /**
00097          *the stylesheet fetched from the url, if any.
00098          *this is not "owned" by #CRAtImportRule which means
00099          *it is not destroyed by the destructor of #CRAtImportRule.
00100          */
00101         CRStyleSheet * sheet;
00102 };
00103 
00104 
00105 /**abstraction of an \@media rule*/
00106 struct _CRAtMediaRule
00107 {
00108         GList *media_list ;
00109         CRStatement *rulesets ; 
00110 } ;
00111 
00112 
00113 typedef struct _CRAtPageRule CRAtPageRule ;
00114 /**The \@page rule abstraction*/
00115 struct _CRAtPageRule
00116 {
00117         /**a list of instances of #CRDeclaration*/
00118         CRDeclaration *decl_list ;
00119 
00120         /**page selector. Is a pseudo selector*/
00121         CRString *name ;
00122         CRString *pseudo ;
00123 } ;
00124 
00125 /**The \@charset rule abstraction*/
00126 typedef struct _CRAtCharsetRule CRAtCharsetRule ;
00127 struct _CRAtCharsetRule
00128 {
00129         CRString * charset ;
00130 };
00131 
00132 /**The abstaction of the \@font-face rule.*/
00133 typedef struct _CRAtFontFaceRule CRAtFontFaceRule ;
00134 struct _CRAtFontFaceRule
00135 {
00136         /*a list of instanaces of #CRDeclaration*/
00137         CRDeclaration *decl_list ;
00138 } ;
00139 
00140 
00141 /**
00142  *The possible types of css2 statements.
00143  */
00144 enum CRStatementType
00145 {
00146         /**
00147          *A generic css at-rule
00148          *each unknown at-rule will
00149          *be of this type.
00150          */
00151 
00152         /**A css at-rule*/
00153         AT_RULE_STMT = 0,
00154 
00155         /*A css ruleset*/
00156         RULESET_STMT,
00157 
00158         /**A css2 import rule*/
00159         AT_IMPORT_RULE_STMT,
00160 
00161         /**A css2 media rule*/
00162         AT_MEDIA_RULE_STMT,
00163 
00164         /**A css2 page rule*/
00165         AT_PAGE_RULE_STMT,
00166 
00167         /**A css2 charset rule*/
00168         AT_CHARSET_RULE_STMT,
00169 
00170         /**A css2 font face rule*/
00171         AT_FONT_FACE_RULE_STMT
00172 } ;
00173 
00174 
00175 /**
00176  *The abstraction of css statement as defined
00177  *in the chapter 4 and appendix D.1 of the css2 spec.
00178  *A statement is actually a double chained list of
00179  *statements.A statement can be a ruleset, an \@import
00180  *rule, an \@page rule etc ...
00181  */
00182 struct _CRStatement
00183 {
00184         /**
00185          *The type of the statement.
00186          */
00187         enum CRStatementType type ;
00188 
00189         union
00190         {
00191                 CRRuleSet *ruleset ;
00192                 CRAtImportRule *import_rule ;
00193                 CRAtMediaRule *media_rule ;
00194                 CRAtPageRule *page_rule ;
00195                 CRAtCharsetRule *charset_rule ;
00196                 CRAtFontFaceRule *font_face_rule ;
00197         } kind ;
00198 
00199         /*
00200          *the specificity of the selector
00201          *that matched this statement.
00202          *This is only used by the cascading
00203          *order determination algorithm.
00204          */
00205         gulong specificity ;
00206 
00207         /*
00208          *the style sheet that contains
00209          *this css statement.
00210          */
00211         CRStyleSheet *parent_sheet ;
00212         CRStatement *next ;
00213         CRStatement *prev ;
00214 
00215         CRParsingLocation location ;
00216 
00217         /**
00218          *a custom pointer useable by
00219          *applications that use libcroco.
00220          *libcroco itself will never modify
00221          *this pointer.
00222          */        
00223         gpointer app_data ;
00224 
00225         /**
00226          *a custom pointer used
00227          *by the upper layers of libcroco.
00228          *application should never use this
00229          *pointer.
00230          */
00231         gpointer croco_data ;
00232 
00233 } ;
00234 
00235 
00236 gboolean
00237 cr_statement_does_buf_parses_against_core (const guchar *a_buf,
00238                                            enum CREncoding a_encoding) ;
00239 CRStatement *
00240 cr_statement_parse_from_buf (const guchar *a_buf,
00241                              enum CREncoding a_encoding) ;
00242 CRStatement*
00243 cr_statement_new_ruleset (CRStyleSheet *a_sheet,
00244                           CRSelector *a_sel_list, 
00245                           CRDeclaration *a_decl_list,
00246                           CRStatement *a_media_rule) ;
00247 CRStatement *
00248 cr_statement_ruleset_parse_from_buf (const guchar * a_buf,
00249                                      enum CREncoding a_enc) ;
00250 
00251 CRStatement*
00252 cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
00253                                  CRString *a_url,
00254                                  GList *a_media_list,
00255                                  CRStyleSheet *a_imported_sheet) ;
00256 
00257 CRStatement *
00258 cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
00259                                             enum CREncoding a_encoding) ;
00260 
00261 CRStatement *
00262 cr_statement_new_at_media_rule (CRStyleSheet *a_sheet,
00263                                 CRStatement *a_ruleset,
00264                                 GList *a_media) ;
00265 CRStatement *
00266 cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf,
00267                                            enum CREncoding a_enc) ;
00268 
00269 CRStatement *
00270 cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
00271                                   CRString *a_charset) ;
00272 CRStatement *
00273 cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf,
00274                                              enum CREncoding a_encoding);
00275 
00276 
00277 CRStatement *
00278 cr_statement_new_at_font_face_rule (CRStyleSheet *a_sheet,
00279                                     CRDeclaration *a_font_decls) ;
00280 CRStatement *
00281 cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf,
00282                                             enum CREncoding a_encoding) ;
00283 
00284 CRStatement *
00285 cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
00286                                CRDeclaration *a_decl_list,
00287                                CRString *a_name,
00288                                CRString *a_pseudo) ;
00289 CRStatement *
00290 cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
00291                                           enum CREncoding a_encoding)  ;
00292 
00293 enum CRStatus
00294 cr_statement_set_parent_sheet (CRStatement *a_this, 
00295                                CRStyleSheet *a_sheet) ;
00296 
00297 enum CRStatus
00298 cr_statement_get_parent_sheet (CRStatement *a_this, 
00299                                CRStyleSheet **a_sheet) ;
00300 
00301 CRStatement *
00302 cr_statement_append (CRStatement *a_this,
00303                      CRStatement *a_new) ;
00304 
00305 CRStatement*
00306 cr_statement_prepend (CRStatement *a_this,
00307                       CRStatement *a_new) ;
00308 
00309 CRStatement *
00310 cr_statement_unlink (CRStatement *a_stmt) ;
00311 
00312 enum CRStatus
00313 cr_statement_ruleset_set_sel_list (CRStatement *a_this,
00314                                    CRSelector *a_sel_list) ;
00315 
00316 enum CRStatus
00317 cr_statement_ruleset_get_sel_list (CRStatement const *a_this,
00318                                    CRSelector **a_list) ;
00319 
00320 enum CRStatus
00321 cr_statement_ruleset_set_decl_list (CRStatement *a_this,
00322                                     CRDeclaration *a_list) ;
00323 
00324 enum CRStatus
00325 cr_statement_ruleset_get_declarations (CRStatement *a_this,
00326                                        CRDeclaration **a_decl_list) ;
00327 
00328 enum CRStatus
00329 cr_statement_ruleset_append_decl2 (CRStatement *a_this,
00330                                    CRString *a_prop, CRTerm *a_value) ;
00331 
00332 enum CRStatus
00333 cr_statement_ruleset_append_decl (CRStatement *a_this,
00334                                   CRDeclaration *a_decl) ;
00335 
00336 enum CRStatus
00337 cr_statement_at_import_rule_set_imported_sheet (CRStatement *a_this,
00338                                                 CRStyleSheet *a_sheet) ;
00339 
00340 enum CRStatus
00341 cr_statement_at_import_rule_get_imported_sheet (CRStatement *a_this,
00342                                                 CRStyleSheet **a_sheet) ;
00343 
00344 enum CRStatus
00345 cr_statement_at_import_rule_set_url (CRStatement *a_this,
00346                                      CRString *a_url) ;
00347 
00348 enum CRStatus
00349 cr_statement_at_import_rule_get_url (CRStatement const *a_this,
00350                                      CRString **a_url) ;
00351 
00352 gint
00353 cr_statement_at_media_nr_rules (CRStatement const *a_this) ;
00354 
00355 CRStatement *
00356 cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) ;
00357 
00358 enum CRStatus
00359 cr_statement_at_page_rule_set_sel (CRStatement *a_this,
00360                                    CRSelector *a_sel) ;
00361 
00362 enum CRStatus
00363 cr_statement_at_page_rule_get_sel (CRStatement const *a_this,
00364                                    CRSelector **a_sel) ;
00365 
00366 enum CRStatus
00367 cr_statement_at_page_rule_set_declarations (CRStatement *a_this,
00368                                             CRDeclaration *a_decl_list) ;
00369 
00370 enum CRStatus
00371 cr_statement_at_page_rule_get_declarations (CRStatement *a_this,
00372                                             CRDeclaration **a_decl_list) ;
00373 
00374 enum CRStatus
00375 cr_statement_at_charset_rule_set_charset (CRStatement *a_this,
00376                                           CRString *a_charset) ;
00377 
00378 enum CRStatus
00379 cr_statement_at_charset_rule_get_charset (CRStatement const *a_this,
00380                                           CRString **a_charset) ;
00381 
00382 enum CRStatus
00383 cr_statement_at_font_face_rule_set_decls (CRStatement *a_this,
00384                                           CRDeclaration *a_decls) ;
00385 
00386 enum CRStatus
00387 cr_statement_at_font_face_rule_get_decls (CRStatement *a_this,
00388                                           CRDeclaration **a_decls) ;
00389 
00390 enum CRStatus
00391 cr_statement_at_font_face_rule_add_decl (CRStatement *a_this,
00392                                          CRString *a_prop,
00393                                          CRTerm *a_value) ;
00394 
00395 gchar *
00396 cr_statement_to_string (CRStatement const * a_this, gulong a_indent) ;
00397 
00398 gchar*
00399 cr_statement_list_to_string (CRStatement const *a_this, gulong a_indent) ;
00400 
00401 void
00402 cr_statement_dump (CRStatement const *a_this, FILE *a_fp, gulong a_indent) ;
00403 
00404 void
00405 cr_statement_dump_ruleset (CRStatement const * a_this, FILE * a_fp,
00406                            glong a_indent) ;
00407 
00408 void
00409 cr_statement_dump_font_face_rule (CRStatement const * a_this,
00410                                   FILE * a_fp,
00411                                   glong a_indent) ;
00412 
00413 void
00414 cr_statement_dump_page (CRStatement const * a_this, FILE * a_fp,
00415                         gulong a_indent) ;
00416 
00417 
00418 void
00419 cr_statement_dump_media_rule (CRStatement const * a_this,
00420                               FILE * a_fp,
00421                               gulong a_indent) ;
00422 
00423 void
00424 cr_statement_dump_import_rule (CRStatement const * a_this, FILE * a_fp,
00425                                gulong a_indent) ; 
00426 void
00427 cr_statement_dump_charset (CRStatement const * a_this, FILE * a_fp,
00428                            gulong a_indent) ;
00429 gint
00430 cr_statement_nr_rules (CRStatement const *a_this) ;
00431 
00432 CRStatement *
00433 cr_statement_get_from_list (CRStatement *a_this, int itemnr) ;
00434 
00435 void
00436 cr_statement_destroy (CRStatement *a_this) ;
00437 
00438 G_END_DECLS
00439 
00440 #endif /*__CR_STATEMENT_H__*/