cr-statement.h 11 KB

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