summaryrefslogtreecommitdiff
path: root/src/select/properties/background_position.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/select/properties/background_position.c')
-rw-r--r--src/select/properties/background_position.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/select/properties/background_position.c b/src/select/properties/background_position.c
new file mode 100644
index 0000000..56125e3
--- /dev/null
+++ b/src/select/properties/background_position.c
@@ -0,0 +1,129 @@
+/*
+ * 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_background_position(uint32_t opv, css_style *style,
+ css_select_state *state)
+{
+ uint16_t value = CSS_BACKGROUND_POSITION_INHERIT;
+ css_fixed hlength = 0;
+ css_fixed vlength = 0;
+ uint32_t hunit = UNIT_PX;
+ uint32_t vunit = UNIT_PX;
+
+ if (isInherit(opv) == false) {
+ value = CSS_BACKGROUND_POSITION_SET;
+
+ switch (getValue(opv) & 0xf0) {
+ case BACKGROUND_POSITION_HORZ_SET:
+ hlength = *((css_fixed *) style->bytecode);
+ advance_bytecode(style, sizeof(hlength));
+ hunit = *((uint32_t *) style->bytecode);
+ advance_bytecode(style, sizeof(hunit));
+ break;
+ case BACKGROUND_POSITION_HORZ_CENTER:
+ hlength = INTTOFIX(50);
+ hunit = UNIT_PCT;
+ break;
+ case BACKGROUND_POSITION_HORZ_RIGHT:
+ hlength = INTTOFIX(100);
+ hunit = UNIT_PCT;
+ break;
+ case BACKGROUND_POSITION_HORZ_LEFT:
+ hlength = INTTOFIX(0);
+ hunit = UNIT_PCT;
+ break;
+ }
+
+ switch (getValue(opv) & 0x0f) {
+ case BACKGROUND_POSITION_VERT_SET:
+ vlength = *((css_fixed *) style->bytecode);
+ advance_bytecode(style, sizeof(vlength));
+ vunit = *((uint32_t *) style->bytecode);
+ advance_bytecode(style, sizeof(vunit));
+ break;
+ case BACKGROUND_POSITION_VERT_CENTER:
+ vlength = INTTOFIX(50);
+ vunit = UNIT_PCT;
+ break;
+ case BACKGROUND_POSITION_VERT_BOTTOM:
+ vlength = INTTOFIX(100);
+ vunit = UNIT_PCT;
+ break;
+ case BACKGROUND_POSITION_VERT_TOP:
+ vlength = INTTOFIX(0);
+ vunit = UNIT_PCT;
+ break;
+ }
+ }
+
+ hunit = to_css_unit(hunit);
+ vunit = to_css_unit(vunit);
+
+ if (outranks_existing(getOpcode(opv), isImportant(opv), state,
+ isInherit(opv))) {
+ return set_background_position(state->result, value,
+ hlength, hunit, vlength, vunit);
+ }
+
+ return CSS_OK;
+}
+
+css_error set_background_position_from_hint(const css_hint *hint,
+ css_computed_style *style)
+{
+ return set_background_position(style, hint->status,
+ hint->data.position.h.value, hint->data.position.h.unit,
+ hint->data.position.v.value, hint->data.position.v.unit);
+}
+
+css_error initial_background_position(css_select_state *state)
+{
+ return set_background_position(state->result,
+ CSS_BACKGROUND_POSITION_SET,
+ 0, CSS_UNIT_PCT, 0, CSS_UNIT_PCT);
+}
+
+css_error compose_background_position(const css_computed_style *parent,
+ const css_computed_style *child,
+ css_computed_style *result)
+{
+ css_fixed hlength = 0, vlength = 0;
+ css_unit hunit = CSS_UNIT_PX, vunit = CSS_UNIT_PX;
+ uint8_t type = get_background_position(child, &hlength, &hunit,
+ &vlength, &vunit);
+
+ if (type == CSS_BACKGROUND_POSITION_INHERIT) {
+ type = get_background_position(parent,
+ &hlength, &hunit, &vlength, &vunit);
+ }
+
+ return set_background_position(result, type, hlength, hunit,
+ vlength, vunit);
+}
+
+
+uint32_t destroy_background_position(void *bytecode)
+{
+ uint32_t value = getValue(*((uint32_t*)bytecode));
+ uint32_t extra_size = 0;
+
+ if ((value & 0x0f) == BACKGROUND_POSITION_VERT_SET)
+ extra_size += sizeof(css_fixed) + sizeof(uint32_t);
+ if ((value & 0xf0) == BACKGROUND_POSITION_HORZ_SET)
+ extra_size += sizeof(css_fixed) + sizeof(uint32_t);
+
+ return sizeof(uint32_t) + extra_size;
+}