summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2017-04-27 09:56:03 (GMT)
committer Michael Drake <michael.drake@codethink.co.uk>2017-04-27 09:56:03 (GMT)
commited0b3a8c9d3549fb0a66372d4bbd3566138c2a06 (patch)
treed3a8fc64ba19b5ed420b08d1dd9441a32be546b0
parent4729f01919b7ba3f99abfea8900931616fbb8320 (diff)
downloadlibcss-ed0b3a8c9d3549fb0a66372d4bbd3566138c2a06.tar.gz
libcss-ed0b3a8c9d3549fb0a66372d4bbd3566138c2a06.tar.bz2
Parsing: Add support for parsing the CSS3 box-sizing property.
-rw-r--r--docs/Bytecode8
-rw-r--r--include/libcss/properties.h7
-rw-r--r--src/bytecode/opcodes.h5
-rw-r--r--src/parse/properties/properties.c1
-rw-r--r--src/parse/properties/properties.gen2
-rw-r--r--src/parse/properties/properties.h3
-rw-r--r--src/parse/propstrings.c3
-rw-r--r--src/parse/propstrings.h9
-rw-r--r--src/select/dispatch.c5
-rw-r--r--src/select/properties/Makefile1
-rw-r--r--src/select/properties/box_sizing.c66
-rw-r--r--src/select/properties/properties.h1
12 files changed, 106 insertions, 5 deletions
diff --git a/docs/Bytecode b/docs/Bytecode
index 3f53d71..f2d10cc 100644
--- a/docs/Bytecode
+++ b/docs/Bytecode
@@ -1249,5 +1249,11 @@ Opcodes
3 => auto,
other => Reserved for future expansion.
-71-3ff - Reserved for future expansion.
+71 - box-sizing
+ <value> (14bits) :
+ 0 => content-box,
+ 1 => border-box,
+ other => Reserved for future expansion.
+
+72-3ff - Reserved for future expansion.
diff --git a/include/libcss/properties.h b/include/libcss/properties.h
index 0840f6f..06c033f 100644
--- a/include/libcss/properties.h
+++ b/include/libcss/properties.h
@@ -127,6 +127,7 @@ enum css_properties_e {
CSS_PROP_COLUMN_WIDTH = 0x06e,
CSS_PROP_WRITING_MODE = 0x06f,
CSS_PROP_OVERFLOW_Y = 0x070,
+ CSS_PROP_BOX_SIZING = 0x071,
CSS_N_PROPERTIES
};
@@ -209,6 +210,12 @@ enum css_bottom_e {
CSS_BOTTOM_AUTO = 0x2
};
+enum css_box_sizing_e {
+ CSS_BOX_SIZING_INHERIT = 0x0,
+ CSS_BOX_SIZING_CONTENT_BOX = 0x1,
+ CSS_BOX_SIZING_BORDER_BOX = 0x2
+};
+
enum css_break_after_e {
CSS_BREAK_AFTER_INHERIT = 0x0,
CSS_BREAK_AFTER_AUTO = 0x1,
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h
index 4f80142..64ea482 100644
--- a/src/bytecode/opcodes.h
+++ b/src/bytecode/opcodes.h
@@ -103,6 +103,11 @@ enum op_bottom {
BOTTOM_AUTO = 0x0000
};
+enum op_box_sizing {
+ BOX_SIZING_CONTENT_BOX = 0x0000,
+ BOX_SIZING_BORDER_BOX = 0x0001
+};
+
enum op_break_after {
BREAK_AFTER_AUTO = 0x0000,
BREAK_AFTER_ALWAYS = 0x0001,
diff --git a/src/parse/properties/properties.c b/src/parse/properties/properties.c
index 49933cd..f32e374 100644
--- a/src/parse/properties/properties.c
+++ b/src/parse/properties/properties.c
@@ -42,6 +42,7 @@ const css_prop_handler property_handlers[LAST_PROP + 1 - FIRST_PROP] =
css__parse_border_top_width,
css__parse_border_width,
css__parse_bottom,
+ css__parse_box_sizing,
css__parse_break_after,
css__parse_break_before,
css__parse_break_inside,
diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen
index 4417cb6..60d5536 100644
--- a/src/parse/properties/properties.gen
+++ b/src/parse/properties/properties.gen
@@ -215,3 +215,5 @@ 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:)
+
+box_sizing:CSS_PROP_BOX_SIZING IDENT:( INHERIT: CONTENT_BOX:0,BOX_SIZING_CONTENT_BOX BORDER_BOX:0,BOX_SIZING_BORDER_BOX IDENT:)
diff --git a/src/parse/properties/properties.h b/src/parse/properties/properties.h
index cf80761..e7b2bf7 100644
--- a/src/parse/properties/properties.h
+++ b/src/parse/properties/properties.h
@@ -112,6 +112,9 @@ css_error css__parse_border_width(css_language *c,
css_error css__parse_bottom(css_language *c,
const parserutils_vector *vector, int *ctx,
css_style *result);
+css_error css__parse_box_sizing(css_language *c,
+ const parserutils_vector *vector, int *ctx,
+ css_style *result);
css_error css__parse_break_after(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 2c166a0..dd6bee4 100644
--- a/src/parse/propstrings.c
+++ b/src/parse/propstrings.c
@@ -112,6 +112,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
{ "border-top-width", SLEN("border-top-width") },
{ "border-width", SLEN("border-width") },
{ "bottom", SLEN("bottom") },
+ { "box-sizing", SLEN("box-sizing") },
{ "break-after", SLEN("break-after") },
{ "break-before", SLEN("break-before") },
{ "break-inside", SLEN("break-inside") },
@@ -412,6 +413,8 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
{ "horizontal-tb", SLEN("horizontal-tb") },
{ "vertical-rl", SLEN("vertical-rl") },
{ "vertical-lr", SLEN("vertical-lr") },
+ { "content-box", SLEN("content-box") },
+ { "border-box", SLEN("border-box") },
{ "aliceblue", SLEN("aliceblue") },
{ "antiquewhite", SLEN("antiquewhite") },
diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h
index c686a91..1203c22 100644
--- a/src/parse/propstrings.h
+++ b/src/parse/propstrings.h
@@ -46,9 +46,9 @@ enum {
BORDER_LEFT_WIDTH, BORDER_RIGHT, BORDER_RIGHT_COLOR,
BORDER_RIGHT_STYLE, BORDER_RIGHT_WIDTH, BORDER_SPACING,
BORDER_STYLE, BORDER_TOP, BORDER_TOP_COLOR, BORDER_TOP_STYLE,
- BORDER_TOP_WIDTH, BORDER_WIDTH, BOTTOM, BREAK_AFTER, BREAK_BEFORE,
- BREAK_INSIDE, CAPTION_SIDE, CLEAR, CLIP, COLOR, COLUMNS, COLUMN_COUNT,
- COLUMN_FILL, COLUMN_GAP, COLUMN_RULE, COLUMN_RULE_COLOR,
+ BORDER_TOP_WIDTH, BORDER_WIDTH, BOTTOM, BOX_SIZING, BREAK_AFTER,
+ BREAK_BEFORE, BREAK_INSIDE, CAPTION_SIDE, CLEAR, CLIP, COLOR, COLUMNS,
+ COLUMN_COUNT, COLUMN_FILL, COLUMN_GAP, COLUMN_RULE, COLUMN_RULE_COLOR,
COLUMN_RULE_STYLE, COLUMN_RULE_WIDTH, COLUMN_SPAN, COLUMN_WIDTH,
CONTENT, COUNTER_INCREMENT, COUNTER_RESET, CUE, CUE_AFTER, CUE_BEFORE,
CURSOR, DIRECTION, DISPLAY, ELEVATION, EMPTY_CELLS, LIBCSS_FLOAT, FONT,
@@ -97,7 +97,8 @@ 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, HORIZONTAL_TB, VERTICAL_RL, VERTICAL_LR,
+ AVOID_PAGE, AVOID_COLUMN, BALANCE, HORIZONTAL_TB, VERTICAL_RL,
+ VERTICAL_LR, CONTENT_BOX, BORDER_BOX,
/* Named colours */
FIRST_COLOUR,
diff --git a/src/select/dispatch.c b/src/select/dispatch.c
index 326da58..7af9000 100644
--- a/src/select/dispatch.c
+++ b/src/select/dispatch.c
@@ -582,5 +582,10 @@ struct prop_table prop_dispatch[CSS_N_PROPERTIES] = {
PROPERTY_FUNCS(overflow_y),
0,
GROUP_NORMAL
+ },
+ {
+ PROPERTY_FUNCS(box_sizing),
+ 0,
+ GROUP_NORMAL
}
};
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
--- a/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 <tlsa@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_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);