1 /* -*- Mode: C; indent-tabs-mode: ni; c-basic-offset: 8 -*- */
4 * This file is part of The Croco Library
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.
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.
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
20 * See COPRYRIGHTS file for copyright information.
25 #include "cr-doc-handler.h"
26 #include "cr-parser.h"
31 *The definition of the CRDocHandler class.
32 *Contains methods to instantiate, destroy,
33 *and initialyze instances of #CRDocHandler
37 #define PRIVATE(obj) (obj)->priv
39 struct _CRDocHandlerPriv {
41 *This pointer is to hold an application parsing context.
42 *For example, it used by the Object Model parser to
43 *store it parsing context. #CRParser does not touch it, but
44 *#CROMParser does. #CROMParser allocates this pointer at
45 *the beginning of the css document, and frees it at the end
51 *The place where #CROMParser puts the result of its parsing, if
56 *a pointer to the parser used to parse
57 *the current document.
64 *Constructor of #CRDocHandler.
66 *Returns the newly built instance of
71 cr_doc_handler_new (void)
73 CRDocHandler *result = NULL;
75 result = g_try_malloc (sizeof (CRDocHandler));
77 g_return_val_if_fail (result, NULL);
79 memset (result, 0, sizeof (CRDocHandler));
81 result->priv = g_try_malloc (sizeof (CRDocHandlerPriv));
83 cr_utils_trace_info ("Out of memory exception");
88 cr_doc_handler_set_default_sac_handler (result);
94 * cr_doc_handler_get_ctxt:
95 *@a_this: the current instance of #CRDocHandler.
96 *@a_ctxt: out parameter. The new parsing context.
98 *Gets the private parsing context associated to the document handler
99 *The private parsing context is used by libcroco only.
101 *Returns CR_OK upon successfull completion, an error code otherwise.
104 cr_doc_handler_get_ctxt (CRDocHandler * a_this, gpointer * a_ctxt)
106 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
108 *a_ctxt = a_this->priv->context;
114 * cr_doc_handler_set_ctxt:
115 *@a_this: the current instance of #CRDocHandler
116 *@a_ctxt: a pointer to the parsing context.
118 *Sets the private parsing context.
119 *This is used by libcroco only.
120 *Returns CR_OK upon successfull completion, an error code otherwise.
123 cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
125 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
126 a_this->priv->context = a_ctxt;
131 * cr_doc_handler_get_result:
132 *@a_this: the current instance of #CRDocHandler
133 *@a_result: out parameter. The returned result.
135 *Gets the private parsing result.
136 *The private parsing result is used by libcroco only.
138 *Returns CR_OK upon successfull completion, an error code otherwise.
141 cr_doc_handler_get_result (CRDocHandler * a_this, gpointer * a_result)
143 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
145 *a_result = a_this->priv->result;
151 * cr_doc_handler_set_result:
152 *@a_this: the current instance of #CRDocHandler
153 *@a_result: the new result.
155 *Sets the private parsing context.
156 *This is used by libcroco only.
158 *Returns CR_OK upon successfull completion, an error code otherwise.
161 cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result)
163 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
164 a_this->priv->result = a_result;
169 *cr_doc_handler_set_default_sac_handler:
170 *@a_this: a pointer to the current instance of #CRDocHandler.
172 *Sets the sac handlers contained in the current
173 *instance of DocHandler to the default handlers.
174 *For the time being the default handlers are
175 *test handlers. This is expected to change in a
176 *near future, when the libcroco gets a bit debugged.
178 *Returns CR_OK upon successfull completion, an error code otherwise.
181 cr_doc_handler_set_default_sac_handler (CRDocHandler * a_this)
183 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
185 a_this->start_document = NULL;
186 a_this->end_document = NULL;
187 a_this->import_style = NULL;
188 a_this->namespace_declaration = NULL;
189 a_this->comment = NULL;
190 a_this->start_selector = NULL;
191 a_this->end_selector = NULL;
192 a_this->property = NULL;
193 a_this->start_font_face = NULL;
194 a_this->end_font_face = NULL;
195 a_this->start_media = NULL;
196 a_this->end_media = NULL;
197 a_this->start_page = NULL;
198 a_this->end_page = NULL;
199 a_this->ignorable_at_rule = NULL;
200 a_this->error = NULL;
201 a_this->unrecoverable_error = NULL;
206 * cr_doc_handler_ref:
207 *@a_this: the current instance of #CRDocHandler.
210 cr_doc_handler_ref (CRDocHandler * a_this)
212 g_return_if_fail (a_this);
218 * cr_doc_handler_unref:
219 *@a_this: the currrent instance of #CRDocHandler.
221 *Decreases the ref count of the current instance of #CRDocHandler.
222 *If the ref count reaches '0' then, destroys the instance.
224 *Returns TRUE if the instance as been destroyed, FALSE otherwise.
227 cr_doc_handler_unref (CRDocHandler * a_this)
229 g_return_val_if_fail (a_this, FALSE);
231 if (a_this->ref_count > 0) {
235 if (a_this->ref_count == 0) {
236 cr_doc_handler_destroy (a_this);
243 * cr_doc_handler_destroy:
244 *@a_this: the instance of #CRDocHandler to
247 *The destructor of the #CRDocHandler class.
250 cr_doc_handler_destroy (CRDocHandler * a_this)
252 g_return_if_fail (a_this);
255 g_free (a_this->priv);
262 * cr_doc_handler_associate_a_parser:
263 *Associates a parser to the current document handler
264 *@a_this: the current instance of document handler.
265 *@a_parser: the parser to associate.
268 cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
271 g_return_if_fail (a_this && PRIVATE (a_this)
274 PRIVATE (a_this)->parser = a_parser ;