summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-09-25 08:13:30 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-09-25 08:13:30 +0000
commitab2a3c493f8f6430ad96f7637c842b666c29a9f4 (patch)
treec56229e077a10384d675b5a5f27beecc8fb74910
parent1e5dee524f9fbff6c811dba66ff404882b02b900 (diff)
downloadlibcss-ab2a3c493f8f6430ad96f7637c842b666c29a9f4.tar.gz
libcss-ab2a3c493f8f6430ad96f7637c842b666c29a9f4.tar.bz2
Create a parser instance for a stylesheet. Also create a level-specific frontend. This probably wants reworking as we don't really want to be switching on the language level every time we want to interact with the parser frontend.
svn path=/trunk/libcss/; revision=5437
-rw-r--r--include/libcss/stylesheet.h2
-rw-r--r--src/stylesheet.c36
-rw-r--r--src/stylesheet.h6
3 files changed, 41 insertions, 3 deletions
diff --git a/include/libcss/stylesheet.h b/include/libcss/stylesheet.h
index de4770e..5f00502 100644
--- a/include/libcss/stylesheet.h
+++ b/include/libcss/stylesheet.h
@@ -18,7 +18,7 @@ typedef css_error (*css_import_handler)(void *pw, const char *url,
css_stylesheet *sheet);
css_stylesheet *css_stylesheet_create(css_language_level level,
- const char *url, const char *title,
+ const char *charset, const char *url, const char *title,
css_origin origin, uint32_t media,
css_import_handler import_callback, void *import_pw,
css_alloc alloc, void *alloc_pw);
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 35bc13c..ed1f870 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -8,12 +8,14 @@
#include <string.h>
#include "stylesheet.h"
+#include "parse/css21.h"
#include "utils/utils.h"
/**
* Create a stylesheet
*
* \param level The language level of the stylesheet
+ * \param charset The charset of the stylesheet data, or NULL to detect
* \param url URL of stylesheet
* \param title Title of stylesheet
* \param origin Origin of stylesheet
@@ -25,7 +27,7 @@
* \return Pointer to stylesheet on success, NULL otherwise
*/
css_stylesheet *css_stylesheet_create(css_language_level level,
- const char *url, const char *title,
+ const char *charset, const char *url, const char *title,
css_origin origin, uint32_t media,
css_import_handler import_callback, void *import_pw,
css_alloc alloc, void *alloc_pw)
@@ -42,13 +44,37 @@ css_stylesheet *css_stylesheet_create(css_language_level level,
memset(sheet, 0, sizeof(css_stylesheet));
- /** \todo need a parser instance */
+ sheet->parser = css_parser_create(charset,
+ charset ? CSS_CHARSET_DICTATED : CSS_CHARSET_DEFAULT,
+ alloc, alloc_pw);
+ if (sheet->parser == NULL) {
+ alloc(sheet, 0, alloc_pw);
+ return NULL;
+ }
+
+ /* We only support CSS 2.1 */
+ if (level != CSS_LEVEL_21) {
+ css_parser_destroy(sheet->parser);
+ alloc(sheet, 0, alloc_pw);
+ return NULL;
+ }
+
+ sheet->level = level;
+ sheet->parser_frontend =
+ css_css21_create(sheet, sheet->parser, alloc, alloc_pw);
+ if (sheet->parser_frontend == NULL) {
+ css_parser_destroy(sheet->parser);
+ alloc(sheet, 0, alloc_pw);
+ return NULL;
+ }
/** \todo create selector hash */
len = strlen(url) + 1;
sheet->url = alloc(NULL, len, alloc_pw);
if (sheet->url == NULL) {
+ css_css21_destroy(sheet->parser_frontend);
+ css_parser_destroy(sheet->parser);
alloc(sheet, 0, alloc_pw);
return NULL;
}
@@ -58,6 +84,8 @@ css_stylesheet *css_stylesheet_create(css_language_level level,
len = strlen(title) + 1;
sheet->title = alloc(NULL, len, alloc_pw);
if (sheet->title == NULL) {
+ css_css21_destroy(sheet->parser_frontend);
+ css_parser_destroy(sheet->parser);
alloc(sheet->url, 0, alloc_pw);
alloc(sheet, 0, alloc_pw);
return NULL;
@@ -94,6 +122,10 @@ void css_stylesheet_destroy(css_stylesheet *sheet)
/** \todo destroy selector hash + other data */
+ css_css21_destroy(sheet->parser_frontend);
+
+ css_parser_destroy(sheet->parser);
+
sheet->alloc(sheet, 0, sheet->pw);
}
diff --git a/src/stylesheet.h b/src/stylesheet.h
index 5968083..ea1c9c4 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -15,6 +15,8 @@
#include <libcss/stylesheet.h>
#include <libcss/types.h>
+#include "parse/parse.h"
+
typedef struct css_rule css_rule;
typedef struct css_selector css_selector;
typedef struct css_style css_style;
@@ -138,6 +140,10 @@ struct css_stylesheet {
css_import_handler import; /**< Import callback */
void *import_pw; /**< Import handler data */
+ css_language_level level; /**< Language level of sheet */
+ css_parser *parser; /**< Core parser for sheet */
+ void *parser_frontend; /**< Frontend parser */
+
css_alloc alloc; /**< Allocation function */
void *pw; /**< Private word */
};