summaryrefslogtreecommitdiff
path: root/src/stylesheet.h
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-28 01:36:03 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-28 01:36:03 +0000
commit5aa8288b483e07769ae363d23c7cb27d9613a9d5 (patch)
tree4b5157ce5e35f68157d4521203640b6b6e3e83eb /src/stylesheet.h
parent7adaf92154adc7f3455769ca197f906e3d4cddaa (diff)
downloadlibcss-5aa8288b483e07769ae363d23c7cb27d9613a9d5.tar.gz
libcss-5aa8288b483e07769ae363d23c7cb27d9613a9d5.tar.bz2
Change the way in which css_rules are defined. This is more compact than the previous approach. Space requirements for rule objects alone is now 447,120 bytes as opposed to 819,270 bytes previously. This reduces the space requirements for allzengarden.css to 2,041,712 bytes, which is 45% the size of what we had originally.
svn path=/trunk/libcss/; revision=5810
Diffstat (limited to 'src/stylesheet.h')
-rw-r--r--src/stylesheet.h95
1 files changed, 56 insertions, 39 deletions
diff --git a/src/stylesheet.h b/src/stylesheet.h
index c5c2812..2156b8e 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -77,48 +77,65 @@ typedef enum css_rule_type {
CSS_RULE_PAGE
} css_rule_type;
+typedef enum css_rule_parent_type {
+ CSS_RULE_PARENT_STYLESHEET,
+ CSS_RULE_PARENT_RULE
+} css_rule_parent_type;
+
struct css_rule {
- css_rule_type type; /**< Type of rule */
-
- union {
- struct {
- uint32_t selector_count;
- css_selector **selectors;
- css_style *style;
- } selector;
- struct {
- uint32_t media;
- uint32_t rule_count;
- css_rule **rules; /** \todo why this? isn't the
- * child list sufficient? */
- } media;
- struct {
- css_style *style;
- } font_face;
- struct {
- uint32_t selector_count;
- css_selector **selectors;
- css_style *style;
- } page;
- struct {
- css_stylesheet *sheet;
- } import;
- struct {
- char *encoding; /** \todo use MIB enum? */
- } charset;
- } data; /**< Rule data */
-
- uint32_t index; /**< Index of rule in sheet */
-
- css_stylesheet *owner; /**< Owning sheet */
-
- css_rule *parent; /**< Parent rule */
- css_rule *first_child; /**< First in child list */
- css_rule *last_child; /**< Last in child list */
- css_rule *next; /**< Next rule */
- css_rule *prev; /**< Previous rule */
+ void *parent; /**< containing rule or owning
+ * stylesheet (defined by ptype)
+ */
+ css_rule *next; /**< next in list */
+ css_rule *prev; /**< previous in list */
+
+ uint32_t type : 4, /**< css_rule_type */
+ index : 16, /**< index in sheet */
+ items : 8, /**< # items in rule */
+ ptype : 1; /**< css_rule_parent_type */
};
+typedef struct css_rule_selector {
+ css_rule base;
+
+ css_selector **selectors;
+ css_style *style;
+} css_rule_selector;
+
+typedef struct css_rule_media {
+ css_rule base;
+
+ uint32_t media;
+
+ css_rule *first_child;
+ css_rule *last_child;
+} css_rule_media;
+
+typedef struct css_rule_font_face {
+ css_rule base;
+
+ css_style *style;
+} css_rule_font_face;
+
+typedef struct css_rule_page {
+ css_rule base;
+
+ css_selector **selectors;
+ css_style *style;
+} css_rule_page;
+
+typedef struct css_rule_import {
+ css_rule base;
+
+ css_stylesheet *sheet;
+} css_rule_import;
+
+typedef struct css_rule_charset {
+ css_rule base;
+
+ char *encoding; /** \todo use MIB enum? */
+} css_rule_charset;
+
struct css_stylesheet {
#define HASH_SIZE (37)
css_selector *selectors[HASH_SIZE]; /**< Hashtable of selectors */