From 0cab24ffcbe59104967362219f3c831c84681f7e Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 6 Dec 2014 15:34:27 +0000 Subject: Add column-width property to computed styles. --- src/select/computed.h | 14 ++++++---- src/select/properties/column_width.c | 54 +++++++++++++----------------------- src/select/propget.h | 27 ++++++++++++++++++ src/select/propset.h | 28 ++++++++++++++++++- 4 files changed, 82 insertions(+), 41 deletions(-) (limited to 'src/select') diff --git a/src/select/computed.h b/src/select/computed.h index 05ea5fa..574d36b 100644 --- a/src/select/computed.h +++ b/src/select/computed.h @@ -24,12 +24,13 @@ typedef struct css_computed_uncommon { * column_rule_style 4 0 * column_rule_width 3 + 4 4 * column_span 2 0 + * column_width 2 + 4 4 * letter_spacing 2 + 4 4 * outline_color 2 4 * outline_width 3 + 4 4 * word_spacing 2 + 4 4 * --- --- - * 77 bits 56 bytes + * 83 bits 60 bytes * * Encode counter_increment and _reset as an array of name, value pairs, * terminated with a blank entry. @@ -53,11 +54,11 @@ typedef struct css_computed_uncommon { * 2 bits sizeof(ptr) * * ___ ___ - * 90 bits 58 + 4sizeof(ptr) bytes + * 96 bits 62 + 4sizeof(ptr) bytes * - * 12 bytes 58 + 4sizeof(ptr) bytes + * 12 bytes 62 + 4sizeof(ptr) bytes * =================== - * 68 + 4sizeof(ptr) bytes + * 72 + 4sizeof(ptr) bytes * * Bit allocations: * @@ -72,8 +73,8 @@ typedef struct css_computed_uncommon { * 8 ccccccoo clip | content * 9 ccffssss column_count | column-fill | column-rule-style * 10 ggggggcc column-gap | column-rule-color - * 11 wwwwwww. column-rule-width - * 12 ss...... column-span + * 11 wwwwwww. column-rule-width | + * 12 sswwwwww column-span | column_width */ uint8_t bits[12]; @@ -92,6 +93,7 @@ typedef struct css_computed_uncommon { css_fixed column_gap; css_color column_rule_color; css_fixed column_rule_width; + css_fixed column_width; css_computed_counter *counter_increment; css_computed_counter *counter_reset; diff --git a/src/select/properties/column_width.c b/src/select/properties/column_width.c index fd053d9..45eb7fc 100644 --- a/src/select/properties/column_width.c +++ b/src/select/properties/column_width.c @@ -14,57 +14,43 @@ #include "select/properties/properties.h" #include "select/properties/helpers.h" -css_error css__cascade_column_width(uint32_t opv, css_style *style, +css_error css__cascade_column_width(uint32_t opv, css_style *style, css_select_state *state) { - css_fixed length = 0; - uint32_t unit = UNIT_PX; - - if (isInherit(opv) == false) { - switch (getValue(opv)) { - case COLUMN_WIDTH_SET: - length = *((css_fixed *) style->bytecode); - advance_bytecode(style, sizeof(length)); - unit = *((uint32_t *) style->bytecode); - advance_bytecode(style, sizeof(unit)); - break; - case COLUMN_WIDTH_AUTO: - /** \todo convert to public values */ - break; - } - } - - if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { - /** \todo set computed elevation */ - } - - return CSS_OK; + return css__cascade_length_normal(opv, style, state, set_column_width); } css_error css__set_column_width_from_hint(const css_hint *hint, css_computed_style *style) { - UNUSED(hint); - UNUSED(style); - - return CSS_OK; + return set_column_width(style, hint->status, + hint->data.length.value, hint->data.length.unit); } css_error css__initial_column_width(css_select_state *state) { - UNUSED(state); - - return CSS_OK; + return set_column_width(state->computed, CSS_COLUMN_WIDTH_AUTO, + INTTOFIX(1), CSS_UNIT_EM); } css_error css__compose_column_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { - UNUSED(parent); - UNUSED(child); - UNUSED(result); + css_fixed length = INTTOFIX(1); + css_unit unit = CSS_UNIT_EM; + uint8_t type = get_column_width(child, &length, &unit); + + if ((child->uncommon == NULL && parent->uncommon != NULL) || + type == CSS_COLUMN_WIDTH_INHERIT || + (child->uncommon != NULL && result != child)) { + if ((child->uncommon == NULL && parent->uncommon != NULL) || + type == CSS_COLUMN_WIDTH_INHERIT) { + type = get_column_width(parent, &length, &unit); + } + + return set_column_width(result, type, length, unit); + } return CSS_OK; } diff --git a/src/select/propget.h b/src/select/propget.h index 7be323e..08ed0f4 100644 --- a/src/select/propget.h +++ b/src/select/propget.h @@ -507,6 +507,33 @@ static inline uint8_t get_column_span( #undef COLUMN_SPAN_SHIFT #undef COLUMN_SPAN_INDEX +#define COLUMN_WIDTH_INDEX 11 +#define COLUMN_WIDTH_SHIFT 0 +#define COLUMN_WIDTH_MASK 0x3f +static inline uint8_t get_column_width( + const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + if (style->uncommon != NULL) { + uint8_t bits = style->uncommon->bits[COLUMN_WIDTH_INDEX]; + bits &= COLUMN_WIDTH_MASK; + bits >>= COLUMN_WIDTH_SHIFT; + + /* 6bits: uuuutt : units | type */ + if ((bits & 0x3) == CSS_COLUMN_WIDTH_SET) { + *length = style->uncommon->column_width; + *unit = bits >> 2; + } + + return (bits & 0x3); + } + + return CSS_COLUMN_WIDTH_AUTO; +} +#undef COLUMN_WIDTH_MASK +#undef COLUMN_WIDTH_SHIFT +#undef COLUMN_WIDTH_INDEX + #define CONTENT_INDEX 7 #define CONTENT_SHIFT 0 #define CONTENT_MASK 0x3 diff --git a/src/select/propset.h b/src/select/propset.h index baac10b..769d3b3 100644 --- a/src/select/propset.h +++ b/src/select/propset.h @@ -30,7 +30,7 @@ static const css_computed_uncommon default_uncommon = { (CSS_COLUMN_RULE_STYLE_NONE << 0), (CSS_COLUMN_GAP_NORMAL << 2) | (CSS_COLUMN_RULE_COLOR_CURRENT_COLOR), (CSS_COLUMN_RULE_WIDTH_MEDIUM << 1), - (CSS_COLUMN_SPAN_NONE << 6) + (CSS_COLUMN_SPAN_NONE << 6) | CSS_COLUMN_WIDTH_AUTO }, { 0, 0 }, { 0, 0, 0, 0 }, @@ -42,6 +42,7 @@ static const css_computed_uncommon default_uncommon = { 0, 0, 0, + 0, NULL, NULL, NULL, @@ -578,6 +579,31 @@ static inline css_error set_column_span( #undef COLUMN_SPAN_SHIFT #undef COLUMN_SPAN_INDEX +#define COLUMN_WIDTH_INDEX 11 +#define COLUMN_WIDTH_SHIFT 0 +#define COLUMN_WIDTH_MASK 0x3f +static inline css_error set_column_width( + css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint8_t *bits; + + ENSURE_UNCOMMON; + + bits = &style->uncommon->bits[COLUMN_WIDTH_INDEX]; + + /* 6bits: uuuutt : units | type */ + *bits = (*bits & ~COLUMN_WIDTH_MASK) | + (((type & 0x3) | (unit << 2)) << COLUMN_WIDTH_SHIFT); + + style->uncommon->column_width = length; + + return CSS_OK; +} +#undef COLUMN_WIDTH_MASK +#undef COLUMN_WIDTH_SHIFT +#undef COLUMN_WIDTH_INDEX + #define CONTENT_INDEX 7 #define CONTENT_SHIFT 0 #define CONTENT_MASK 0x3 -- cgit v1.2.3