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 32 #ifndef __CR_DOC_HANDLER_H__ 33 #define __CR_DOC_HANDLER_H__ 34 35 /** 36 *@file 37 *The declaration of the #CRDocumentHandler class. 38 *This class is actually the parsing events handler. 39 */ 40 41 #include <glib.h> 42 #include "cr-utils.h" 43 #include "cr-input.h" 44 #include "cr-stylesheet.h" 45 46 G_BEGIN_DECLS 47 48 49 typedef struct _CRDocHandler CRDocHandler ; 50 51 struct _CRDocHandlerPriv ; 52 typedef struct _CRDocHandlerPriv CRDocHandlerPriv ; 53 54 55 /** 56 *The SAC document handler. 57 *An instance of this class is to 58 *be passed to a parser. Then, during the parsing 59 *the parser calls the convenient function pointer 60 *whenever a particular event (a css construction) occurs. 61 */ 62 struct _CRDocHandler 63 { 64 CRDocHandlerPriv *priv ; 65 66 /** 67 *This pointer is to be used by the application for 68 *it custom needs. It is there to extend the doc handler. 69 */ 70 gpointer app_data ; 71 72 /** 73 *Is called at the beginning of the parsing of the document. 74 *@param a_this a pointer to the current instance of 75 *#CRDocHandler. 76 */ 77 void (*start_document) (CRDocHandler *a_this) ; 78 79 /** 80 *Is called to notify the end of the parsing of the document. 81 *@param a_this a pointer to the current instance of 82 *#CRDocHandler. 83 */ 84 void (*end_document) (CRDocHandler *a_this) ; 85 86 /** 87 *Is called to notify an at charset rule. 88 *@param a_this the document handler. 89 *@param a_charset the declared charset. 90 */ 91 void (*charset) (CRDocHandler *a_this, 92 CRString *a_charset, 93 CRParsingLocation *a_charset_sym_location) ; 94 95 /** 96 *Is called to notify an import statement in 97 *the stylesheet. 98 *@param a_this the current instance of #CRDocHandler. 99 *@param a_media_list a doubly linked list of GString objects. 100 *Each GString object contains a string which is the 101 *destination media for style information. 102 *@param a_uri the uri of the imported style sheet. 103 *@param a_uri_default_ns the default namespace of URI 104 *@param a_location the parsing location of the '\@import' 105 *keyword. 106 *of the imported style sheet. 107 */ 108 void (*import_style) (CRDocHandler *a_this, 109 GList *a_media_list, 110 CRString *a_uri, 111 CRString *a_uri_default_ns, 112 CRParsingLocation *a_location) ; 113 114 void (*import_style_result) (CRDocHandler *a_this, 115 GList *a_media_list, 116 CRString *a_uri, 117 CRString *a_uri_default_ns, 118 CRStyleSheet *a_sheet) ; 119 120 /** 121 *Is called to notify a namespace declaration. 122 *Not used yet. 123 *@param a_this the current instance of #CRDocHandler. 124 *@param a_prefix the prefix of the namespace. 125 *@param a_uri the uri of the namespace. 126 *@param a_location the location of the "@namespace" keyword. 127 */ 128 void (*namespace_declaration) (CRDocHandler *a_this, 129 CRString *a_prefix, 130 CRString *a_uri, 131 CRParsingLocation *a_location) ; 132 133 /** 134 *Is called to notify a comment. 135 *@param a_this a pointer to the current instance 136 *of #CRDocHandler. 137 *@param a_comment the comment. 138 */ 139 void (*comment) (CRDocHandler *a_this, 140 CRString *a_comment) ; 141 142 /** 143 *Is called to notify the beginning of a rule 144 *statement. 145 *@param a_this the current instance of #CRDocHandler. 146 *@param a_selector_list the list of selectors that precedes 147 *the rule declarations. 148 */ 149 void (*start_selector) (CRDocHandler * a_this, 150 CRSelector *a_selector_list) ; 151 152 /** 153 *Is called to notify the end of a rule statement. 154 *@param a_this the current instance of #CRDocHandler. 155 *@param a_selector_list the list of selectors that precedes 156 *the rule declarations. This pointer is the same as 157 *the one passed to start_selector() ; 158 */ 159 void (*end_selector) (CRDocHandler *a_this, 160 CRSelector *a_selector_list) ; 161 162 163 /** 164 *Is called to notify a declaration. 165 *@param a_this a pointer to the current instance 166 *of #CRDocHandler. 167 *@param a_name the name of the parsed property. 168 *@param a_expression a css expression that represents 169 *the value of the property. A css expression is 170 *actually a linked list of 'terms'. Each term can 171 *be linked to other using operators. 172 * 173 */ 174 void (*property) (CRDocHandler *a_this, 175 CRString *a_name, 176 CRTerm *a_expression, 177 gboolean a_is_important) ; 178 /** 179 *Is called to notify the start of a font face statement. 180 *The parser invokes this method at the beginning of every 181 *font face statement in the style sheet. There will 182 *be a corresponding end_font_face () event for every 183 *start_font_face () event. 184 * 185 *@param a_this a pointer to the current instance of 186 *#CRDocHandler. 187 *@param a_location the parsing location of the "\@font-face" 188 *keyword. 189 */ 190 void (*start_font_face) (CRDocHandler *a_this, 191 CRParsingLocation *a_location) ; 192 193 /** 194 *Is called to notify the end of a font face statement. 195 *@param a_this a pointer to the current instance of 196 *#CRDocHandler. 197 */ 198 void (*end_font_face) (CRDocHandler *a_this) ; 199 200 201 /** 202 *Is called to notify the beginning of a media statement. 203 *The parser will invoke this method at the beginning of 204 *every media statement in the style sheet. There will be 205 *a corresponding end_media() event for every start_media() 206 *event. 207 *@param a_this a pointer to the current instance of 208 *#CRDocHandler. 209 *@param a_media_list a double linked list of 210 #CRString * objects. 211 *Each CRString objects is actually a destination media for 212 *the style information. 213 */ 214 void (*start_media) (CRDocHandler *a_this, 215 GList *a_media_list, 216 CRParsingLocation *a_location) ; 217 218 /** 219 *Is called to notify the end of a media statement. 220 *@param a_this a pointer to the current instance 221 *of #CRDocHandler. 222 *@param a_media_list a double linked list of GString * objects. 223 *Each GString objects is actually a destination media for 224 *the style information. 225 */ 226 void (*end_media) (CRDocHandler *a_this, 227 GList *a_media_list) ; 228 229 /** 230 *Is called to notify the beginning of a page statement. 231 *The parser invokes this function at the beginning of 232 *every page statement in the style sheet. There will be 233 *a corresponding end_page() event for every single 234 *start_page() event. 235 *@param a_this a pointer to the current instance of 236 *#CRDocHandler. 237 *@param a_name the name of the page (if any, null otherwise). 238 *@param a_pseudo_page the pseudo page (if any, null otherwise). 239 *@param a_location the parsing location of the "\@page" keyword. 240 */ 241 void (*start_page) (CRDocHandler *a_this, 242 CRString *a_name, 243 CRString *a_pseudo_page, 244 CRParsingLocation *a_location) ; 245 246 /** 247 *Is called to notify the end of a page statement. 248 *@param a_this a pointer to the current instance of 249 *#CRDocHandler. 250 *@param a_name the name of the page (if any, null otherwise). 251 *@param a_pseudo_page the pseudo page (if any, null otherwise). 252 */ 253 void (*end_page) (CRDocHandler *a_this, 254 CRString *a_name, 255 CRString *pseudo_page) ; 256 257 /** 258 *Is Called to notify an unknown at-rule not supported 259 *by this parser. 260 */ 261 void (*ignorable_at_rule) (CRDocHandler *a_this, 262 CRString *a_name) ; 263 264 /** 265 *Is called to notify a parsing error. After this error 266 *the application must ignore the rule being parsed, if 267 *any. After completion of this callback, 268 *the parser will then try to resume the parsing, 269 *ignoring the current error. 270 */ 271 void (*error) (CRDocHandler *a_this) ; 272 273 /** 274 *Is called to notify an unrecoverable parsing error. 275 *This is the place to put emergency routines that free allocated 276 *resources. 277 */ 278 void (*unrecoverable_error) (CRDocHandler *a_this) ; 279 280 gboolean resolve_import ; 281 gulong ref_count ; 282 } ; 283 284 CRDocHandler * cr_doc_handler_new (void) ; 285 286 enum CRStatus cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) ; 287 288 enum CRStatus cr_doc_handler_get_result (CRDocHandler const *a_this, gpointer * a_result) ; 289 290 enum CRStatus cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) ; 291 292 enum CRStatus cr_doc_handler_get_ctxt (CRDocHandler const *a_this, gpointer * a_ctxt) ; 293 294 enum CRStatus cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this) ; 295 296 void cr_doc_handler_associate_a_parser (CRDocHandler *a_this, 297 gpointer a_parser) ; 298 299 void cr_doc_handler_ref (CRDocHandler *a_this) ; 300 301 gboolean cr_doc_handler_unref (CRDocHandler *a_this) ; 302 303 void cr_doc_handler_destroy (CRDocHandler *a_this) ; 304 305 G_END_DECLS 306 307 #endif /*__CR_DOC_HANDLER_H__*/ 308