diff options
author | Lucas Neves <lcneves@gmail.com> | 2017-08-28 17:33:24 +0000 |
---|---|---|
committer | Lucas Neves <lcneves@gmail.com> | 2017-09-25 21:57:41 -0400 |
commit | cc22c90d5d67488c1da1fc3655423ebb44247223 (patch) | |
tree | 8b0adea9a31e0a1660e865ebdb97bbc92924c479 | |
parent | 69574fa847973dd6d449c2dd997ae0c86b671ad0 (diff) | |
download | libcss-cc22c90d5d67488c1da1fc3655423ebb44247223.tar.gz |
Select: write property files
-rw-r--r-- | docs/Bytecode | 10 | ||||
-rw-r--r-- | include/libcss/computed.h | 35 | ||||
-rw-r--r-- | include/libcss/properties.h | 2 | ||||
-rw-r--r-- | src/bytecode/opcodes.h | 6 | ||||
-rw-r--r-- | src/parse/properties/properties.gen | 4 | ||||
-rw-r--r-- | src/select/computed.c | 59 | ||||
-rw-r--r-- | src/select/properties/align_content.c | 81 | ||||
-rw-r--r-- | src/select/properties/align_items.c | 75 | ||||
-rw-r--r-- | src/select/properties/align_self.c | 78 | ||||
-rw-r--r-- | src/select/properties/display.c | 6 | ||||
-rw-r--r-- | src/select/properties/flex_basis.c | 79 | ||||
-rw-r--r-- | src/select/properties/flex_direction.c | 72 | ||||
-rw-r--r-- | src/select/properties/flex_grow.c | 62 | ||||
-rw-r--r-- | src/select/properties/flex_shrink.c | 62 | ||||
-rw-r--r-- | src/select/properties/flex_wrap.c | 69 | ||||
-rw-r--r-- | src/select/properties/justify_content.c | 79 | ||||
-rw-r--r-- | src/select/properties/order.c | 62 |
17 files changed, 827 insertions, 14 deletions
diff --git a/docs/Bytecode b/docs/Bytecode index 01d4cff..40813c6 100644 --- a/docs/Bytecode +++ b/docs/Bytecode @@ -680,9 +680,8 @@ Opcodes bits 0-7 : bit 7: set => length or percentage follows bits 0-6: MBZ - bit 7 clear => keywords: - bits 0-6: 0000000 => auto, - other => rffe. + clear => Reserved for future expansion + bits 0-6: MBZ 37 - min-width <value> (14bits) : @@ -690,9 +689,8 @@ Opcodes bits 0-7 : bit 7: set => length or percentage follows bits 0-6: MBZ - bit 7 clear => keywords: - bits 0-6: 0000000 => auto, - other => rffe. + clear => Reserved for future expansion + bits 0-6: MBZ 38 - orphans <value> (14bits) : diff --git a/include/libcss/computed.h b/include/libcss/computed.h index e15d0b0..9d77034 100644 --- a/include/libcss/computed.h +++ b/include/libcss/computed.h @@ -439,6 +439,41 @@ uint8_t css_computed_widows( const css_computed_style *style, int32_t *widows); +uint8_t css_computed_align_content( + const css_computed_style *style); + +uint8_t css_computed_align_items( + const css_computed_style *style); + +uint8_t css_computed_align_self( + const css_computed_style *style); + +uint8_t css_computed_flex_basis( + const css_computed_style *style, + css_fixed *length, + css_unit *unit); + +uint8_t css_computed_flex_direction( + const css_computed_style *style); + +uint8_t css_computed_flex_grow( + const css_computed_style *style, + css_fixed *number); + +uint8_t css_computed_flex_shrink( + const css_computed_style *style, + css_fixed *number); + +uint8_t css_computed_flex_wrap( + const css_computed_style *style); + +uint8_t css_computed_justify_content( + const css_computed_style *style); + +uint8_t css_computed_order( + const css_computed_style *style, + css_fixed *order); + #ifdef __cplusplus } #endif diff --git a/include/libcss/properties.h b/include/libcss/properties.h index 2163068..caa5f83 100644 --- a/include/libcss/properties.h +++ b/include/libcss/properties.h @@ -630,13 +630,11 @@ enum css_max_width_e { enum css_min_height_e { CSS_MIN_HEIGHT_INHERIT = 0x0, CSS_MIN_HEIGHT_SET = 0x1, - CSS_MIN_HEIGHT_AUTO = 0x2 }; enum css_min_width_e { CSS_MIN_WIDTH_INHERIT = 0x0, CSS_MIN_WIDTH_SET = 0x1, - CSS_MIN_WIDTH_AUTO = 0x2 }; enum css_opacity_e { diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h index 82bf75f..9da47fc 100644 --- a/src/bytecode/opcodes.h +++ b/src/bytecode/opcodes.h @@ -510,13 +510,11 @@ enum op_max_width { }; enum op_min_height { - MIN_HEIGHT_SET = 0x0080, - MIN_HEIGHT_AUTO = 0x0000 + MIN_HEIGHT_SET = 0x0080 }; enum op_min_width { - MIN_WIDTH_SET = 0x0080, - MIN_WIDTH_AUTO = 0x0000 + MIN_WIDTH_SET = 0x0080 }; enum op_opacity { diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen index e9167c8..efda8a9 100644 --- a/src/parse/properties/properties.gen +++ b/src/parse/properties/properties.gen @@ -43,9 +43,9 @@ max_height:CSS_PROP_MAX_HEIGHT IDENT:( INHERIT: NONE:0,MAX_HEIGHT_NONE IDENT:) L max_width:CSS_PROP_MAX_WIDTH IDENT:( INHERIT: NONE:0,MAX_WIDTH_NONE IDENT:) LENGTH_UNIT:( UNIT_PX:MAX_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:) -min_height:CSS_PROP_MIN_HEIGHT IDENT:( INHERIT: AUTO:0,MIN_HEIGHT_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:) +min_height:CSS_PROP_MIN_HEIGHT IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:MIN_HEIGHT_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:) -min_width:CSS_PROP_MIN_WIDTH IDENT:( INHERIT: AUTO:0,MIN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:) +min_width:CSS_PROP_MIN_WIDTH IDENT:INHERIT LENGTH_UNIT:( UNIT_PX:MIN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ RANGE:<0 LENGTH_UNIT:) color:CSS_PROP_COLOR IDENT:INHERIT COLOR:COLOR_SET diff --git a/src/select/computed.c b/src/select/computed.c index 03e7c15..f7887a2 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -1054,6 +1054,59 @@ uint8_t css_computed_widows(const css_computed_style *style, return get_widows(style, widows); } +uint8_t css_computed_align_content(const css_computed_style *style) +{ + return get_align_content(style); +} + +uint8_t css_computed_align_items(const css_computed_style *style) +{ + return get_align_items(style); +} + +uint8_t css_computed_align_self(const css_computed_style *style) +{ + return get_align_self(style); +} + +uint8_t css_computed_flex_basis(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + return get_flex_basis(style, length, unit); +} + +uint8_t css_computed_flex_direction(const css_computed_style *style) +{ + return get_flex_direction(style); +} + +uint8_t css_computed_flex_grow(const css_computed_style *style, + css_fixed *number) +{ + return get_flex_grow(style, number); +} + +uint8_t css_computed_flex_shrink(const css_computed_style *style, + css_fixed *number) +{ + return get_flex_shrink(style, number); +} + +uint8_t css_computed_flex_wrap(const css_computed_style *style) +{ + return get_flex_wrap(style); +} + +uint8_t css_computed_justify_content(const css_computed_style *style) +{ + return get_justify_content(style); +} + +uint8_t css_computed_order(const css_computed_style *style, + css_fixed *order) +{ + return get_order(style, order); +} /****************************************************************************** * Library internals * @@ -1205,6 +1258,12 @@ css_error css__compute_absolute_values(const css_computed_style *parent, if (error != CSS_OK) return error; + /* Fix up flex-basis */ + error = compute_absolute_length(style, &ex_size.data.length, + get_flex_basis, set_flex_basis); + if (error != CSS_OK) + return error; + /* Uncommon properties */ if (style->i.uncommon != NULL) { /* Fix up border-spacing */ diff --git a/src/select/properties/align_content.c b/src/select/properties/align_content.c new file mode 100644 index 0000000..f43cd8e --- /dev/null +++ b/src/select/properties/align_content.c @@ -0,0 +1,81 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_align_content(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ALIGN_CONTENT_INHERIT; + + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case ALIGN_CONTENT_STRETCH: + value = CSS_ALIGN_CONTENT_STRETCH; + break; + case ALIGN_CONTENT_FLEX_START: + value = CSS_ALIGN_CONTENT_FLEX_START; + break; + case ALIGN_CONTENT_FLEX_END: + value = CSS_ALIGN_CONTENT_FLEX_END; + break; + case ALIGN_CONTENT_CENTER: + value = CSS_ALIGN_CONTENT_CENTER; + break; + case ALIGN_CONTENT_SPACE_BETWEEN: + value = CSS_ALIGN_CONTENT_SPACE_BETWEEN; + break; + case ALIGN_CONTENT_SPACE_AROUND: + value = CSS_ALIGN_CONTENT_SPACE_AROUND; + break; + case ALIGN_CONTENT_SPACE_EVENLY: + value = CSS_ALIGN_CONTENT_SPACE_EVENLY; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_align_content(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_align_content_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_align_content(style, hint->status); +} + +css_error css__initial_align_content(css_select_state *state) +{ + return set_align_content(state->computed, CSS_ALIGN_CONTENT_STRETCH); +} + +css_error css__compose_align_content(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_align_content(child); + + if (type == CSS_ALIGN_CONTENT_INHERIT) { + type = get_align_content(parent); + } + + return set_align_content(result, type); +} + diff --git a/src/select/properties/align_items.c b/src/select/properties/align_items.c new file mode 100644 index 0000000..ad69c81 --- /dev/null +++ b/src/select/properties/align_items.c @@ -0,0 +1,75 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_align_items(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ALIGN_ITEMS_INHERIT; + + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case ALIGN_ITEMS_STRETCH: + value = CSS_ALIGN_ITEMS_STRETCH; + break; + case ALIGN_ITEMS_FLEX_START: + value = CSS_ALIGN_ITEMS_FLEX_START; + break; + case ALIGN_ITEMS_FLEX_END: + value = CSS_ALIGN_ITEMS_FLEX_END; + break; + case ALIGN_ITEMS_CENTER: + value = CSS_ALIGN_ITEMS_CENTER; + break; + case ALIGN_ITEMS_BASELINE: + value = CSS_ALIGN_ITEMS_BASELINE; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_align_items(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_align_items_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_align_items(style, hint->status); +} + +css_error css__initial_align_items(css_select_state *state) +{ + return set_align_items(state->computed, CSS_ALIGN_ITEMS_STRETCH); +} + +css_error css__compose_align_items(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_align_items(child); + + if (type == CSS_ALIGN_ITEMS_INHERIT) { + type = get_align_items(parent); + } + + return set_align_items(result, type); +} + diff --git a/src/select/properties/align_self.c b/src/select/properties/align_self.c new file mode 100644 index 0000000..e8e469e --- /dev/null +++ b/src/select/properties/align_self.c @@ -0,0 +1,78 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_align_self(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ALIGN_SELF_INHERIT; + + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case ALIGN_SELF_STRETCH: + value = CSS_ALIGN_SELF_STRETCH; + break; + case ALIGN_SELF_FLEX_START: + value = CSS_ALIGN_SELF_FLEX_START; + break; + case ALIGN_SELF_FLEX_END: + value = CSS_ALIGN_SELF_FLEX_END; + break; + case ALIGN_SELF_CENTER: + value = CSS_ALIGN_SELF_CENTER; + break; + case ALIGN_SELF_BASELINE: + value = CSS_ALIGN_SELF_BASELINE; + break; + case ALIGN_SELF_AUTO: + value = CSS_ALIGN_SELF_AUTO; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_align_self(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_align_self_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_align_self(style, hint->status); +} + +css_error css__initial_align_self(css_select_state *state) +{ + return set_align_self(state->computed, CSS_ALIGN_SELF_AUTO); +} + +css_error css__compose_align_self(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_align_self(child); + + if (type == CSS_ALIGN_SELF_INHERIT) { + type = get_align_self(parent); + } + + return set_align_self(result, type); +} + diff --git a/src/select/properties/display.c b/src/select/properties/display.c index 40c2e3e..510d24a 100644 --- a/src/select/properties/display.c +++ b/src/select/properties/display.c @@ -71,6 +71,12 @@ css_error css__cascade_display(uint32_t opv, css_style *style, case DISPLAY_NONE: value = CSS_DISPLAY_NONE; break; + case DISPLAY_FLEX: + value = CSS_DISPLAY_FLEX; + break; + case DISPLAY_INLINE_FLEX: + value = CSS_DISPLAY_INLINE_FLEX; + break; } } diff --git a/src/select/properties/flex_basis.c b/src/select/properties/flex_basis.c new file mode 100644 index 0000000..5f59fad --- /dev/null +++ b/src/select/properties/flex_basis.c @@ -0,0 +1,79 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_flex_basis(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_BASIS_INHERIT; + css_fixed length = 0; + uint32_t unit = UNIT_PX; + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case FLEX_BASIS_AUTO: + value = CSS_FLEX_BASIS_AUTO; + break; + case FLEX_BASIS_CONTENT: + value = CSS_FLEX_BASIS_CONTENT; + break; + case FLEX_BASIS_SET: + value = CSS_FLEX_BASIS_SET; + length = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(length)); + unit = *((uint32_t *) style->bytecode); + advance_bytecode(style, sizeof(unit)); + break; + } + } + + unit = css__to_css_unit(unit); + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_flex_basis(state->computed, value, length, unit); + } + + return CSS_OK; +} + +css_error css__set_flex_basis_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_basis(style, hint->status, + hint->data.length.value, hint->data.length.unit); +} + +css_error css__initial_flex_basis(css_select_state *state) +{ + return set_flex_basis(state->computed, CSS_FLEX_BASIS_AUTO, 0, + CSS_UNIT_PX); +} + +css_error css__compose_flex_basis(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_flex_basis(child, &length, &unit); + + if (type == CSS_FLEX_BASIS_INHERIT) { + type = get_flex_basis(parent, &length, &unit); + } + + return set_flex_basis(result, type, length, unit); +} + diff --git a/src/select/properties/flex_direction.c b/src/select/properties/flex_direction.c new file mode 100644 index 0000000..79703be --- /dev/null +++ b/src/select/properties/flex_direction.c @@ -0,0 +1,72 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_flex_direction(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_DIRECTION_INHERIT; + + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case FLEX_DIRECTION_ROW: + value = CSS_FLEX_DIRECTION_ROW; + break; + case FLEX_DIRECTION_ROW_REVERSE: + value = CSS_FLEX_DIRECTION_ROW_REVERSE; + break; + case FLEX_DIRECTION_COLUMN: + value = CSS_FLEX_DIRECTION_COLUMN; + break; + case FLEX_DIRECTION_COLUMN_REVERSE: + value = CSS_FLEX_DIRECTION_COLUMN_REVERSE; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_flex_direction(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_flex_direction_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_direction(style, hint->status); +} + +css_error css__initial_flex_direction(css_select_state *state) +{ + return set_flex_direction(state->computed, CSS_FLEX_DIRECTION_ROW); +} + +css_error css__compose_flex_direction(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_flex_direction(child); + + if (type == CSS_FLEX_DIRECTION_INHERIT) { + type = get_flex_direction(parent); + } + + return set_flex_direction(result, type); +} + diff --git a/src/select/properties/flex_grow.c b/src/select/properties/flex_grow.c new file mode 100644 index 0000000..7f37cfe --- /dev/null +++ b/src/select/properties/flex_grow.c @@ -0,0 +1,62 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_flex_grow(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_GROW_INHERIT; + css_fixed flex_grow = 0; + + if (isInherit(opv) == false) { + value = CSS_FLEX_GROW_SET; + + flex_grow = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(flex_grow)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_flex_grow(state->computed, value, flex_grow); + } + + return CSS_OK; +} + +css_error css__set_flex_grow_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_grow(style, hint->status, hint->data.fixed); +} + +css_error css__initial_flex_grow(css_select_state *state) +{ + return set_flex_grow(state->computed, CSS_FLEX_GROW_SET, INTTOFIX(0)); +} + +css_error css__compose_flex_grow(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed flex_grow = 0; + uint8_t type = get_flex_grow(child, &flex_grow); + + if (type == CSS_FLEX_GROW_INHERIT) { + type = get_flex_grow(parent, &flex_grow); + } + + return set_flex_grow(result, type, flex_grow); +} + diff --git a/src/select/properties/flex_shrink.c b/src/select/properties/flex_shrink.c new file mode 100644 index 0000000..d1acd2a --- /dev/null +++ b/src/select/properties/flex_shrink.c @@ -0,0 +1,62 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_flex_shrink(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_SHRINK_INHERIT; + css_fixed flex_shrink = 0; + + if (isInherit(opv) == false) { + value = CSS_FLEX_SHRINK_SET; + + flex_shrink = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(flex_shrink)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_flex_shrink(state->computed, value, flex_shrink); + } + + return CSS_OK; +} + +css_error css__set_flex_shrink_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_shrink(style, hint->status, hint->data.fixed); +} + +css_error css__initial_flex_shrink(css_select_state *state) +{ + return set_flex_shrink(state->computed, CSS_FLEX_SHRINK_SET, INTTOFIX(1)); +} + +css_error css__compose_flex_shrink(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed flex_shrink = 0; + uint8_t type = get_flex_shrink(child, &flex_shrink); + + if (type == CSS_FLEX_SHRINK_INHERIT) { + type = get_flex_shrink(parent, &flex_shrink); + } + + return set_flex_shrink(result, type, flex_shrink); +} + diff --git a/src/select/properties/flex_wrap.c b/src/select/properties/flex_wrap.c new file mode 100644 index 0000000..688a9b6 --- /dev/null +++ b/src/select/properties/flex_wrap.c @@ -0,0 +1,69 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_flex_wrap(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_WRAP_INHERIT; + + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case FLEX_WRAP_NOWRAP: + value = CSS_FLEX_WRAP_NOWRAP; + break; + case FLEX_WRAP_WRAP: + value = CSS_FLEX_WRAP_WRAP; + break; + case FLEX_WRAP_WRAP_REVERSE: + value = CSS_FLEX_WRAP_WRAP_REVERSE; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_flex_wrap(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_flex_wrap_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_wrap(style, hint->status); +} + +css_error css__initial_flex_wrap(css_select_state *state) +{ + return set_flex_wrap(state->computed, CSS_FLEX_WRAP_NOWRAP); +} + +css_error css__compose_flex_wrap(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_flex_wrap(child); + + if (type == CSS_FLEX_WRAP_INHERIT) { + type = get_flex_wrap(parent); + } + + return set_flex_wrap(result, type); +} + diff --git a/src/select/properties/justify_content.c b/src/select/properties/justify_content.c new file mode 100644 index 0000000..2e17ca5 --- /dev/null +++ b/src/select/properties/justify_content.c @@ -0,0 +1,79 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_justify_content(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_JUSTIFY_CONTENT_INHERIT; + + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case JUSTIFY_CONTENT_FLEX_START: + value = CSS_JUSTIFY_CONTENT_FLEX_START; + break; + case JUSTIFY_CONTENT_FLEX_END: + value = CSS_JUSTIFY_CONTENT_FLEX_END; + break; + case JUSTIFY_CONTENT_CENTER: + value = CSS_JUSTIFY_CONTENT_CENTER; + break; + case JUSTIFY_CONTENT_SPACE_BETWEEN: + value = CSS_JUSTIFY_CONTENT_SPACE_BETWEEN; + break; + case JUSTIFY_CONTENT_SPACE_AROUND: + value = CSS_JUSTIFY_CONTENT_SPACE_AROUND; + break; + case JUSTIFY_CONTENT_SPACE_EVENLY: + value = CSS_JUSTIFY_CONTENT_SPACE_EVENLY; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_justify_content(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_justify_content_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_justify_content(style, hint->status); +} + +css_error css__initial_justify_content(css_select_state *state) +{ + return set_justify_content(state->computed, + CSS_JUSTIFY_CONTENT_FLEX_START); +} + +css_error css__compose_justify_content(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_justify_content(child); + + if (type == CSS_JUSTIFY_CONTENT_INHERIT) { + type = get_justify_content(parent); + } + + return set_justify_content(result, type); +} + diff --git a/src/select/properties/order.c b/src/select/properties/order.c new file mode 100644 index 0000000..5216038 --- /dev/null +++ b/src/select/properties/order.c @@ -0,0 +1,62 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#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 css__cascade_order(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ORDER_INHERIT; + css_fixed order = 0; + + if (isInherit(opv) == false) { + value = CSS_ORDER_SET; + + order = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(order)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + return set_order(state->computed, value, order); + } + + return CSS_OK; +} + +css_error css__set_order_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_order(style, hint->status, hint->data.fixed); +} + +css_error css__initial_order(css_select_state *state) +{ + return set_order(state->computed, CSS_ORDER_SET, INTTOFIX(0)); +} + +css_error css__compose_order(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed order = 0; + uint8_t type = get_order(child, &order); + + if (type == CSS_ORDER_INHERIT) { + type = get_order(parent, &order); + } + + return set_order(result, type, order); +} + |