From ed0b3a8c9d3549fb0a66372d4bbd3566138c2a06 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 27 Apr 2017 10:56:03 +0100 Subject: Parsing: Add support for parsing the CSS3 box-sizing property. --- src/select/properties/Makefile | 1 + src/select/properties/box_sizing.c | 66 ++++++++++++++++++++++++++++++++++++++ src/select/properties/properties.h | 1 + 3 files changed, 68 insertions(+) create mode 100644 src/select/properties/box_sizing.c (limited to 'src/select/properties') diff --git a/src/select/properties/Makefile b/src/select/properties/Makefile index ce3ddfa..288eda9 100644 --- a/src/select/properties/Makefile +++ b/src/select/properties/Makefile @@ -21,6 +21,7 @@ border_top_color.c \ border_top_style.c \ border_top_width.c \ bottom.c \ +box_sizing.c \ break_after.c \ break_before.c \ break_inside.c \ diff --git a/src/select/properties/box_sizing.c b/src/select/properties/box_sizing.c new file mode 100644 index 0000000..357dd3c --- /dev/null +++ b/src/select/properties/box_sizing.c @@ -0,0 +1,66 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Michael Drake + */ + +#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_box_sizing(uint32_t opv, css_style *style, + css_select_state *state) +{ + UNUSED(style); + + if (isInherit(opv) == false) { + switch (getValue(opv)) { + case BOX_SIZING_CONTENT_BOX: + case BOX_SIZING_BORDER_BOX: + /** \todo convert to public values */ + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + isInherit(opv))) { + /** \todo set computed value */ + } + + return CSS_OK; +} + +css_error css__set_box_sizing_from_hint(const css_hint *hint, + css_computed_style *style) +{ + UNUSED(hint); + UNUSED(style); + + return CSS_OK; +} + +css_error css__initial_box_sizing(css_select_state *state) +{ + UNUSED(state); + + return CSS_OK; +} + +css_error css__compose_box_sizing( + const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + UNUSED(parent); + UNUSED(child); + UNUSED(result); + + return CSS_OK; +} + diff --git a/src/select/properties/properties.h b/src/select/properties/properties.h index f0ab29d..a1ab49f 100644 --- a/src/select/properties/properties.h +++ b/src/select/properties/properties.h @@ -42,6 +42,7 @@ PROPERTY_FUNCS(border_right_width); PROPERTY_FUNCS(border_bottom_width); PROPERTY_FUNCS(border_left_width); PROPERTY_FUNCS(bottom); +PROPERTY_FUNCS(box_sizing); PROPERTY_FUNCS(break_after); PROPERTY_FUNCS(break_before); PROPERTY_FUNCS(break_inside); -- cgit v1.2.3 From 8d583fbe94b801353faec8e3a5a6729e3fe767a5 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 27 Apr 2017 11:57:37 +0100 Subject: Selection: Add support for the CSS3 box-sizing property. --- src/select/computed.h | 5 +++-- src/select/properties/box_sizing.c | 27 ++++++++++++++------------- src/select/propget.h | 17 +++++++++++++++++ src/select/propset.h | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+), 15 deletions(-) (limited to 'src/select/properties') diff --git a/src/select/computed.h b/src/select/computed.h index f77bda2..d2301f5 100644 --- a/src/select/computed.h +++ b/src/select/computed.h @@ -159,8 +159,9 @@ struct css_computed_style_i { * unicode_bidi 2 * visibility 2 * white_space 3 + * box_sizing 2 * --- - * 84 bits + * 86 bits * * Colours are 32bits of AARRGGBB * Dimensions are encoded as a fixed point value + 4 bits of unit data @@ -250,7 +251,7 @@ struct css_computed_style_i { * 21 mmmmmccc min-width | clear * 22 tttttxxx padding-top | overflow-x * 23 rrrrrppp padding-right | position - * 24 bbbbbo.. padding-bottom | opacity | + * 24 bbbbboss padding-bottom | opacity | box-sizing * 25 lllllttt padding-left | text-transform * 26 tttttwww text-indent | white-space * 27 bbbbbbbb background-position diff --git a/src/select/properties/box_sizing.c b/src/select/properties/box_sizing.c index 357dd3c..91c475d 100644 --- a/src/select/properties/box_sizing.c +++ b/src/select/properties/box_sizing.c @@ -17,20 +17,24 @@ css_error css__cascade_box_sizing(uint32_t opv, css_style *style, css_select_state *state) { + uint16_t value = CSS_BOX_SIZING_INHERIT; + UNUSED(style); if (isInherit(opv) == false) { switch (getValue(opv)) { case BOX_SIZING_CONTENT_BOX: + value = CSS_BOX_SIZING_CONTENT_BOX; + break; case BOX_SIZING_BORDER_BOX: - /** \todo convert to public values */ + value = CSS_BOX_SIZING_BORDER_BOX; break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - /** \todo set computed value */ + return set_box_sizing(state->computed, value); } return CSS_OK; @@ -39,17 +43,12 @@ css_error css__cascade_box_sizing(uint32_t opv, css_style *style, css_error css__set_box_sizing_from_hint(const css_hint *hint, css_computed_style *style) { - UNUSED(hint); - UNUSED(style); - - return CSS_OK; + return set_box_sizing(style, hint->status); } css_error css__initial_box_sizing(css_select_state *state) { - UNUSED(state); - - return CSS_OK; + return set_box_sizing(state->computed, CSS_BOX_SIZING_CONTENT_BOX); } css_error css__compose_box_sizing( @@ -57,10 +56,12 @@ css_error css__compose_box_sizing( const css_computed_style *child, css_computed_style *result) { - UNUSED(parent); - UNUSED(child); - UNUSED(result); + uint8_t type = get_box_sizing(child); - return CSS_OK; + if (type == CSS_BOX_SIZING_INHERIT) { + type = get_box_sizing(parent); + } + + return set_box_sizing(result, type); } diff --git a/src/select/propget.h b/src/select/propget.h index 5552e39..6719443 100644 --- a/src/select/propget.h +++ b/src/select/propget.h @@ -1268,6 +1268,23 @@ static inline uint8_t get_background_attachment( #undef BACKGROUND_ATTACHMENT_SHIFT #undef BACKGROUND_ATTACHMENT_INDEX +#define BOX_SIZING_INDEX 34 +#define BOX_SIZING_SHIFT 0 +#define BOX_SIZING_MASK 0x3 +static inline uint8_t get_box_sizing( + const css_computed_style *style) +{ + uint8_t bits = style->i.bits[BOX_SIZING_INDEX]; + bits &= BOX_SIZING_MASK; + bits >>= BOX_SIZING_SHIFT; + + /* 2bits: type */ + return bits; +} +#undef BOX_SIZING_MASK +#undef BOX_SIZING_SHIFT +#undef BOX_SIZING_INDEX + #define BORDER_COLLAPSE_INDEX 13 #define BORDER_COLLAPSE_SHIFT 0 #define BORDER_COLLAPSE_MASK 0x3 diff --git a/src/select/propset.h b/src/select/propset.h index 76e4fe6..3f4038c 100644 --- a/src/select/propset.h +++ b/src/select/propset.h @@ -1361,6 +1361,24 @@ static inline css_error set_background_attachment( #undef BACKGROUND_ATTACHMENT_SHIFT #undef BACKGROUND_ATTACHMENT_INDEX +#define BOX_SIZING_INDEX 34 +#define BOX_SIZING_SHIFT 0 +#define BOX_SIZING_MASK 0x3 +static inline css_error set_box_sizing( + css_computed_style *style, uint8_t type) +{ + uint8_t *bits = &style->i.bits[BOX_SIZING_INDEX]; + + /* 2bits: type */ + *bits = (*bits & ~BOX_SIZING_MASK) | + ((type & 0x3) << BOX_SIZING_SHIFT); + + return CSS_OK; +} +#undef BOX_SIZING_MASK +#undef BOX_SIZING_SHIFT +#undef BOX_SIZING_INDEX + #define BORDER_COLLAPSE_INDEX 13 #define BORDER_COLLAPSE_SHIFT 0 #define BORDER_COLLAPSE_MASK 0x3 -- cgit v1.2.3