summaryrefslogtreecommitdiff
path: root/src/select/properties/counter_increment.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2010-12-05 17:22:06 +0000
committerVincent Sanders <vince@netsurf-browser.org>2010-12-05 17:22:06 +0000
commit97449b2e23ef5252cb4f766d9215d14e763a0732 (patch)
tree8eca8edc44aa19f384ff6fc48b868c5a9a7a5f21 /src/select/properties/counter_increment.c
parent9ff129943ec479fa51b95e84b6e8c042a44363ae (diff)
downloadlibcss-97449b2e23ef5252cb4f766d9215d14e763a0732.tar.gz
libcss-97449b2e23ef5252cb4f766d9215d14e763a0732.tar.bz2
Split up properties selectors
svn path=/trunk/libcss/; revision=11011
Diffstat (limited to 'src/select/properties/counter_increment.c')
-rw-r--r--src/select/properties/counter_increment.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/select/properties/counter_increment.c b/src/select/properties/counter_increment.c
new file mode 100644
index 0000000..9697028
--- /dev/null
+++ b/src/select/properties/counter_increment.c
@@ -0,0 +1,116 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "bytecode/bytecode.h"
+#include "bytecode/opcodes.h"
+#include "select/propset.h"
+#include "select/propget.h"
+#include "utils/utils.h"
+
+#include "select/properties/properties.h"
+#include "select/properties/helpers.h"
+
+css_error cascade_counter_increment(uint32_t opv, css_style *style,
+ css_select_state *state)
+{
+ return cascade_counter_increment_reset(opv, style, state,
+ set_counter_increment);
+}
+
+css_error set_counter_increment_from_hint(const css_hint *hint,
+ css_computed_style *style)
+{
+ css_computed_counter *item;
+ css_error error;
+
+ error = set_counter_increment(style, hint->status, hint->data.counter);
+
+ if (hint->status == CSS_COUNTER_INCREMENT_NAMED &&
+ hint->data.counter != NULL) {
+ for (item = hint->data.counter; item->name != NULL; item++) {
+ lwc_string_unref(item->name);
+ }
+ }
+
+ if (error != CSS_OK && hint->data.counter != NULL)
+ style->alloc(hint->data.counter, 0, style->pw);
+
+ return error;
+}
+
+css_error initial_counter_increment(css_select_state *state)
+{
+ return set_counter_increment(state->result,
+ CSS_COUNTER_INCREMENT_NONE, NULL);
+}
+
+css_error compose_counter_increment(const css_computed_style *parent,
+ const css_computed_style *child,
+ css_computed_style *result)
+{
+ css_error error;
+ const css_computed_counter *items = NULL;
+ uint8_t type = get_counter_increment(child, &items);
+
+ if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ type == CSS_COUNTER_INCREMENT_INHERIT ||
+ (child->uncommon != NULL && result != child)) {
+ size_t n_items = 0;
+ css_computed_counter *copy = NULL;
+
+ if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ type == CSS_COUNTER_INCREMENT_INHERIT) {
+ type = get_counter_increment(parent, &items);
+ }
+
+ if (type == CSS_COUNTER_INCREMENT_NAMED && items != NULL) {
+ const css_computed_counter *i;
+
+ for (i = items; i->name != NULL; i++)
+ n_items++;
+
+ copy = result->alloc(NULL, (n_items + 1) *
+ sizeof(css_computed_counter),
+ result->pw);
+ if (copy == NULL)
+ return CSS_NOMEM;
+
+ memcpy(copy, items, (n_items + 1) *
+ sizeof(css_computed_counter));
+ }
+
+ error = set_counter_increment(result, type, copy);
+ if (error != CSS_OK && copy != NULL)
+ result->alloc(copy, 0, result->pw);
+
+ return error;
+ }
+
+ return CSS_OK;
+}
+
+uint32_t destroy_counter_increment(void *bytecode)
+{
+ uint32_t consumed = sizeof(uint32_t);
+ uint32_t value = getValue(*((uint32_t*)bytecode));
+ bytecode = ((uint8_t*)bytecode) + sizeof(uint32_t);
+
+ if (value == COUNTER_INCREMENT_NAMED) {
+ while (value != COUNTER_INCREMENT_NONE) {
+ lwc_string *str = *((lwc_string **)bytecode);
+ consumed += sizeof(lwc_string*) + sizeof(css_fixed);
+ bytecode = ((uint8_t*)bytecode) + sizeof(lwc_string*) + sizeof(css_fixed);
+ lwc_string_unref(str);
+
+ consumed += sizeof(uint32_t);
+ value = *((uint32_t*)bytecode);
+ bytecode = ((uint8_t*)bytecode) + sizeof(uint32_t);
+ }
+ }
+
+ return consumed;
+}