summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaitlin Potter <snowball@defpixel.com>2013-09-10 17:44:53 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2013-09-10 17:44:53 +0100
commitbc9c80c2dbf21d805f5372aea3df14d310a1512c (patch)
tree990fab4a6a72e7ddea5f12da20329412da5006b6
parent2234cab352b0ef702b32aaa7ef433c4793086824 (diff)
downloadlibcss-bc9c80c2dbf21d805f5372aea3df14d310a1512c.tar.gz
libcss-bc9c80c2dbf21d805f5372aea3df14d310a1512c.tar.bz2
Add support for parsing the writing-mode property. Thanks to Caitlin Potter.
-rw-r--r--docs/Bytecode11
-rw-r--r--include/libcss/properties.h8
-rw-r--r--src/bytecode/opcodes.h6
-rw-r--r--src/parse/properties/properties.gen1
-rw-r--r--src/parse/properties/properties.h3
-rw-r--r--src/parse/propstrings.c4
-rw-r--r--src/parse/propstrings.h5
-rw-r--r--src/select/computed.h2
-rw-r--r--src/select/dispatch.c5
-rw-r--r--src/select/properties/Makefile1
-rw-r--r--src/select/properties/writing_mode.c70
-rw-r--r--src/select/propget.h19
-rw-r--r--src/select/propset.h24
13 files changed, 154 insertions, 5 deletions
diff --git a/docs/Bytecode b/docs/Bytecode
index 900b1f9..b4154b5 100644
--- a/docs/Bytecode
+++ b/docs/Bytecode
@@ -1232,6 +1232,15 @@ Opcodes
bits 0-6: 0000000 => auto,
other => rffe.
+6f - writing-mode
+ <value> (14bits) :
+ bits 8-13: MBZ
+ bits 0-7 :
+ 00000000 => horizontal-tb,
+ 00000001 => vertical-rl,
+ 00000010 => vertical-lr,
+ other => Reserved for future expansion.
+
-6f-3ff - Reserved for future expansion.
+70-3ff - Reserved for future expansion.
diff --git a/include/libcss/properties.h b/include/libcss/properties.h
index feba9ce..bbb6baa 100644
--- a/include/libcss/properties.h
+++ b/include/libcss/properties.h
@@ -125,6 +125,7 @@ enum css_properties_e {
CSS_PROP_COLUMN_RULE_WIDTH = 0x06c,
CSS_PROP_COLUMN_SPAN = 0x06d,
CSS_PROP_COLUMN_WIDTH = 0x06e,
+ CSS_PROP_WRITING_MODE = 0x06f,
CSS_N_PROPERTIES
};
@@ -740,6 +741,13 @@ enum css_word_spacing_e {
CSS_WORD_SPACING_NORMAL = 0x2
};
+enum css_writing_mode_e {
+ CSS_WRITING_MODE_INHERIT = 0x0,
+ CSS_WRITING_MODE_HORIZONTAL_TB = 0x1,
+ CSS_WRITING_MODE_VERTICAL_RL = 0x2,
+ CSS_WRITING_MODE_VERTICAL_LR = 0x3
+};
+
enum css_z_index_e {
CSS_Z_INDEX_INHERIT = 0x0,
CSS_Z_INDEX_SET = 0x1,
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h
index a0d38d4..544687a 100644
--- a/src/bytecode/opcodes.h
+++ b/src/bytecode/opcodes.h
@@ -718,6 +718,12 @@ enum op_word_spacing {
WORD_SPACING_NORMAL = 0x0000
};
+enum op_writing_mode {
+ WRITING_MODE_HORIZONTAL_TB = 0x0000,
+ WRITING_MODE_VERTICAL_RL = 0x0001,
+ WRITING_MODE_VERTICAL_LR = 0x0002
+};
+
enum op_z_index {
Z_INDEX_SET = 0x0080,
diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen
index 5a4ebe0..80f1a30 100644
--- a/src/parse/properties/properties.gen
+++ b/src/parse/properties/properties.gen
@@ -212,3 +212,4 @@ column_span:CSS_PROP_COLUMN_SPAN IDENT:( INHERIT: NONE:0,COLUMN_SPAN_NONE ALL:0,
column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:)
+writing_mode:CSS_PROP_WRITING_MODE IDENT:( INHERIT: HORIZONTAL_TB:0,WRITING_MODE_HORIZONTAL_TB VERTICAL_RL:0,WRITING_MODE_VERTICAL_RL VERTICAL_LR:0,WRITING_MODE_VERTICAL_LR IDENT:)
diff --git a/src/parse/properties/properties.h b/src/parse/properties/properties.h
index 7280d93..7c4d8a1 100644
--- a/src/parse/properties/properties.h
+++ b/src/parse/properties/properties.h
@@ -406,6 +406,9 @@ css_error css__parse_width(css_language *c,
css_error css__parse_word_spacing(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result);
+css_error css__parse_writing_mode(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result);
css_error css__parse_z_index(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result);
diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c
index 35466eb..913241c 100644
--- a/src/parse/propstrings.c
+++ b/src/parse/propstrings.c
@@ -210,6 +210,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
{ "widows", SLEN("widows") },
{ "width", SLEN("width") },
{ "word-spacing", SLEN("word-spacing") },
+ { "writing-mode", SLEN("writing-mode") },
{ "z-index", SLEN("z-index") },
{ "inherit", SLEN("inherit") },
@@ -406,6 +407,9 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
{ "avoid-page", SLEN("avoid_page") },
{ "avoid-column", SLEN("avoid-column") },
{ "balance", SLEN("balance") },
+ { "horizontal-tb", SLEN("horizontal-tb") },
+ { "vertical-rl", SLEN("vertical-rl") },
+ { "vertical-lr", SLEN("vertical-lr") },
{ "aliceblue", SLEN("aliceblue") },
{ "antiquewhite", SLEN("antiquewhite") },
diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h
index 2ed0743..72a60ae 100644
--- a/src/parse/propstrings.h
+++ b/src/parse/propstrings.h
@@ -64,7 +64,8 @@ enum {
SPEAK_HEADER, SPEAK_NUMERAL, SPEAK_PUNCTUATION, SPEAK, SPEECH_RATE,
STRESS, TABLE_LAYOUT, TEXT_ALIGN, TEXT_DECORATION, TEXT_INDENT,
TEXT_TRANSFORM, TOP, UNICODE_BIDI, VERTICAL_ALIGN, VISIBILITY,
- VOICE_FAMILY, VOLUME, WHITE_SPACE, WIDOWS, WIDTH, WORD_SPACING, Z_INDEX,
+ VOICE_FAMILY, VOLUME, WHITE_SPACE, WIDOWS, WIDTH, WORD_SPACING,
+ WRITING_MODE, Z_INDEX,
LAST_PROP = Z_INDEX,
@@ -96,7 +97,7 @@ enum {
LINE_THROUGH, BLINK, RGB, RGBA, HSL, HSLA, LIBCSS_LEFT, LIBCSS_CENTER,
LIBCSS_RIGHT, CURRENTCOLOR, ODD, EVEN, SRC, LOCAL, INITIAL,
FORMAT, WOFF, TRUETYPE, OPENTYPE, EMBEDDED_OPENTYPE, SVG, COLUMN,
- AVOID_PAGE, AVOID_COLUMN, BALANCE,
+ AVOID_PAGE, AVOID_COLUMN, BALANCE, HORIZONTAL_TB, VERTICAL_RL, VERTICAL_LR,
/* Named colours */
FIRST_COLOUR,
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 | <unused>
+ * 5 uuuuumm. cursor | writing-mode | <unused>
* 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 <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 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