From bc9c80c2dbf21d805f5372aea3df14d310a1512c Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Sep 2013 17:44:53 +0100 Subject: Add support for parsing the writing-mode property. Thanks to Caitlin Potter. --- src/select/computed.h | 2 +- src/select/dispatch.c | 5 +++ src/select/properties/Makefile | 1 + src/select/properties/writing_mode.c | 70 ++++++++++++++++++++++++++++++++++++ src/select/propget.h | 19 ++++++++++ src/select/propset.h | 24 ++++++++++++- 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/select/properties/writing_mode.c (limited to 'src/select') diff --git a/src/select/computed.h b/src/select/computed.h index f891047..8be3873 100644 --- a/src/select/computed.h +++ b/src/select/computed.h @@ -59,7 +59,7 @@ typedef struct css_computed_uncommon { * 2 ooooooob outline-width | border-spacing * 3 bbbbbbbb border-spacing * 4 wwwwwwir word-spacing | counter-increment | counter-reset - * 5 uuuuu... cursor | + * 5 uuuuumm. cursor | writing-mode | * 6 cccccccc clip * 7 cccccccc clip * 8 ccccccoo clip | content diff --git a/src/select/dispatch.c b/src/select/dispatch.c index 85c1289..03d5c63 100644 --- a/src/select/dispatch.c +++ b/src/select/dispatch.c @@ -572,5 +572,10 @@ struct prop_table prop_dispatch[CSS_N_PROPERTIES] = { PROPERTY_FUNCS(column_width), 0, GROUP_NORMAL + }, + { + PROPERTY_FUNCS(writing_mode), + 0, + GROUP_UNCOMMON } }; diff --git a/src/select/properties/Makefile b/src/select/properties/Makefile index a557846..eacc240 100644 --- a/src/select/properties/Makefile +++ b/src/select/properties/Makefile @@ -110,6 +110,7 @@ white_space.c \ width.c \ windows.c \ word_spacing.c \ +writing_mode.c \ z_index.c include $(NSBUILD)/Makefile.subdir diff --git a/src/select/properties/writing_mode.c b/src/select/properties/writing_mode.c new file mode 100644 index 0000000..3ec1352 --- /dev/null +++ b/src/select/properties/writing_mode.c @@ -0,0 +1,70 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2009 John-Mark Bell + */ + +#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_writing_mode(uint32_t opv, css_style *style, + css_select_state *state) +{ + bool inherit = isInherit(opv); + uint16_t writing_mode = CSS_WRITING_MODE_INHERIT; + UNUSED(style); + + if (inherit == false) { + switch (getValue(opv)) { + case WRITING_MODE_HORIZONTAL_TB: + writing_mode = CSS_WRITING_MODE_HORIZONTAL_TB; + break; + case WRITING_MODE_VERTICAL_RL: + writing_mode = CSS_WRITING_MODE_VERTICAL_RL; + break; + case WRITING_MODE_VERTICAL_LR: + writing_mode = CSS_WRITING_MODE_VERTICAL_LR; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + inherit)) { + return set_writing_mode(state->computed, writing_mode); + } + + return CSS_OK; +} + +css_error css__set_writing_mode_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_writing_mode(style, hint->status); +} + +css_error css__initial_writing_mode(css_select_state *state) +{ + return set_writing_mode(state->computed, + CSS_WRITING_MODE_HORIZONTAL_TB); +} + +css_error css__compose_writing_mode(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t writing_mode = get_writing_mode(child); + + if (writing_mode == CSS_WRITING_MODE_INHERIT) { + writing_mode = get_writing_mode(parent); + } + + return set_writing_mode(result, writing_mode); +} + diff --git a/src/select/propget.h b/src/select/propget.h index 41f6315..16b8fc2 100644 --- a/src/select/propget.h +++ b/src/select/propget.h @@ -174,6 +174,25 @@ static inline uint8_t get_word_spacing( #undef WORD_SPACING_SHIFT #undef WORD_SPACING_INDEX +#define WRITING_MODE_INDEX 4 +#define WRITING_MODE_MASK 0x6 +#define WRITING_MODE_SHIFT 1 +static inline uint8_t get_writing_mode( + const css_computed_style *style) +{ + if (style->uncommon != NULL) { + uint8_t bits = style->uncommon->bits[WRITING_MODE_INDEX]; + bits &= WRITING_MODE_MASK; + bits >>= WRITING_MODE_SHIFT; + return bits; + } + + return CSS_WRITING_MODE_HORIZONTAL_TB; +} +#undef WRITING_MODE_INDEX +#undef WRITING_MODE_MASK +#undef WRITING_MODE_SHIFT + #define COUNTER_INCREMENT_INDEX 3 #define COUNTER_INCREMENT_SHIFT 1 #define COUNTER_INCREMENT_MASK 0x2 diff --git a/src/select/propset.h b/src/select/propset.h index 2b705ae..29e8ae5 100644 --- a/src/select/propset.h +++ b/src/select/propset.h @@ -22,7 +22,7 @@ static const css_computed_uncommon default_uncommon = { 0, (CSS_WORD_SPACING_INHERIT << 2) | (CSS_COUNTER_INCREMENT_NONE << 1) | CSS_COUNTER_RESET_NONE, - (CSS_CURSOR_INHERIT << 3) | 0, + (CSS_CURSOR_INHERIT << 3) | (CSS_WRITING_MODE_INHERIT << 1) | 0, 0, 0, (CSS_CLIP_AUTO << 2) | CSS_CONTENT_NORMAL @@ -214,6 +214,28 @@ static inline css_error set_word_spacing( #undef WORD_SPACING_SHIFT #undef WORD_SPACING_INDEX +#define WRITING_MODE_INDEX 4 +#define WRITING_MODE_SHIFT 1 +#define WRITING_MODE_MASK 0x6 +static inline css_error set_writing_mode( + css_computed_style *style, uint8_t type) +{ + uint8_t *bits; + + ENSURE_UNCOMMON; + + bits = &style->uncommon->bits[WRITING_MODE_INDEX]; + + /* 2bits: type */ + *bits = (*bits & ~WRITING_MODE_MASK) | + ((type & 0x3) << WRITING_MODE_SHIFT); + + return CSS_OK; +} +#undef WRITING_MODE_MASK +#undef WRITING_MODE_SHIFT +#undef WRITING_MODE_INDEX + #define COUNTER_INCREMENT_INDEX 3 #define COUNTER_INCREMENT_SHIFT 1 #define COUNTER_INCREMENT_MASK 0x2 -- cgit v1.2.3