r5437 jmb - in /trunk/libcss: include/libcss/stylesheet.h src/stylesheet.c src/stylesheet.h

netsurf at semichrome.net netsurf at semichrome.net
Thu Sep 25 09:13:30 BST 2008


Author: jmb
Date: Thu Sep 25 03:13:30 2008
New Revision: 5437

URL: http://source.netsurf-browser.org?rev=5437&view=rev
Log:
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.

Modified:
    trunk/libcss/include/libcss/stylesheet.h
    trunk/libcss/src/stylesheet.c
    trunk/libcss/src/stylesheet.h

Modified: trunk/libcss/include/libcss/stylesheet.h
URL: http://source.netsurf-browser.org/trunk/libcss/include/libcss/stylesheet.h?rev=5437&r1=5436&r2=5437&view=diff
==============================================================================
--- trunk/libcss/include/libcss/stylesheet.h (original)
+++ trunk/libcss/include/libcss/stylesheet.h Thu Sep 25 03:13:30 2008
@@ -18,7 +18,7 @@
 		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);

Modified: trunk/libcss/src/stylesheet.c
URL: http://source.netsurf-browser.org/trunk/libcss/src/stylesheet.c?rev=5437&r1=5436&r2=5437&view=diff
==============================================================================
--- trunk/libcss/src/stylesheet.c (original)
+++ trunk/libcss/src/stylesheet.c Thu Sep 25 03:13:30 2008
@@ -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 @@
 
 	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 @@
 		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;
@@ -93,6 +121,10 @@
 	sheet->alloc(sheet->url, 0, sheet->pw);
 
 	/** \todo destroy selector hash + other data */
+
+	css_css21_destroy(sheet->parser_frontend);
+
+	css_parser_destroy(sheet->parser);
 
 	sheet->alloc(sheet, 0, sheet->pw);
 }

Modified: trunk/libcss/src/stylesheet.h
URL: http://source.netsurf-browser.org/trunk/libcss/src/stylesheet.h?rev=5437&r1=5436&r2=5437&view=diff
==============================================================================
--- trunk/libcss/src/stylesheet.h (original)
+++ trunk/libcss/src/stylesheet.h Thu Sep 25 03:13:30 2008
@@ -14,6 +14,8 @@
 #include <libcss/functypes.h>
 #include <libcss/stylesheet.h>
 #include <libcss/types.h>
+
+#include "parse/parse.h"
 
 typedef struct css_rule css_rule;
 typedef struct css_selector css_selector;
@@ -138,6 +140,10 @@
 	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 */
 };




More information about the netsurf-commits mailing list