summaryrefslogtreecommitdiff
path: root/src/stylesheet.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-10-23 00:28:20 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-10-23 00:28:20 +0000
commitc8e73871f9006987983fd1010d97b6168c13f6a3 (patch)
tree2fb79379af6643828fb93bd6c855a6e0a5e6dc7b /src/stylesheet.c
parent5d9507591d83b48be8c76421b602500c196e3785 (diff)
downloadlibcss-c8e73871f9006987983fd1010d97b6168c13f6a3.tar.gz
libcss-c8e73871f9006987983fd1010d97b6168c13f6a3.tar.bz2
Something approximating a parser for clear.
Provide API to create/destroy css_styles and append them to css_rules. svn path=/trunk/libcss/; revision=5625
Diffstat (limited to 'src/stylesheet.c')
-rw-r--r--src/stylesheet.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 9d6f877..7a093f9 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -269,6 +269,45 @@ css_error css_stylesheet_set_disabled(css_stylesheet *sheet, bool disabled)
******************************************************************************/
/**
+ * Create a style
+ *
+ * \param sheet The stylesheet context
+ * \param len The required length of the style
+ * \return Pointer to style, or NULL on error
+ */
+css_style *css_stylesheet_style_create(css_stylesheet *sheet, uint32_t len)
+{
+ css_style *style;
+
+ if (sheet == NULL || len == 0)
+ return NULL;
+
+ style = sheet->alloc(NULL, sizeof(css_style) + len, sheet->pw);
+ if (style == NULL)
+ return NULL;
+
+ /* DIY variable-sized data member */
+ style->bytecode = ((uint8_t *) style + sizeof(css_style));
+ style->length = len;
+
+ return style;
+}
+
+/**
+ * Destroy a style
+ *
+ * \param sheet The stylesheet context
+ * \param style The style to destroy
+ */
+void css_stylesheet_style_destroy(css_stylesheet *sheet, css_style *style)
+{
+ UNUSED(sheet);
+ UNUSED(style);
+
+ /** \todo destroy style */
+}
+
+/**
* Create a selector
*
* \param sheet The stylesheet context
@@ -462,6 +501,59 @@ css_error css_stylesheet_rule_add_selector(css_stylesheet *sheet,
}
/**
+ * Append a style to a CSS rule
+ *
+ * \param sheet The stylesheet context
+ * \param rule The rule to add to (must be CSS_RULE_SELECTOR or CSS_RULE_PAGE)
+ * \param style The style to add
+ * \return CSS_OK on success, appropriate error otherwise
+ */
+css_error css_stylesheet_rule_append_style(css_stylesheet *sheet,
+ css_rule *rule, css_style *style)
+{
+ css_style *cur;
+
+ if (sheet == NULL || rule == NULL || style == NULL)
+ return CSS_BADPARM;
+
+ if (rule->type != CSS_RULE_SELECTOR && rule->type != CSS_RULE_PAGE)
+ return CSS_INVALID;
+
+ if (rule->type == CSS_RULE_SELECTOR)
+ cur = rule->data.selector.style;
+ else
+ cur = rule->data.page.style;
+
+ if (cur != NULL) {
+ /* Already have a style, so append to the end of the bytecode */
+ css_style *temp = sheet->alloc(cur,
+ cur->length + style->length, sheet->pw);
+ if (temp == NULL)
+ return CSS_NOMEM;
+
+ /** \todo Can we optimise the bytecode here? */
+ memcpy((uint8_t *) temp->bytecode + temp->length,
+ style->bytecode, style->length);
+
+ cur = temp;
+ cur->length += style->length;
+
+ /* Done with style */
+ css_stylesheet_style_destroy(sheet, style);
+ } else {
+ /* No current style, so use this one */
+ cur = style;
+ }
+
+ if (rule->type == CSS_RULE_SELECTOR)
+ rule->data.selector.style = cur;
+ else
+ rule->data.page.style = cur;
+
+ return CSS_OK;
+}
+
+/**
* Add a rule to a stylesheet
*
* \param sheet The stylesheet to add to