summaryrefslogtreecommitdiff
path: root/css
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2004-02-02 00:22:59 +0000
committerJames Bursa <james@netsurf-browser.org>2004-02-02 00:22:59 +0000
commitb0c5b7498704aff375da29fc701b1a7e6941b6ba (patch)
treea613c9fcf6cccf6d99d33034eefb9e3502f1c0a6 /css
parentdbda424e61ae158f8cca6d58d6d967b93003b50c (diff)
downloadnetsurf-b0c5b7498704aff375da29fc701b1a7e6941b6ba.tar.gz
netsurf-b0c5b7498704aff375da29fc701b1a7e6941b6ba.tar.bz2
[project @ 2004-02-02 00:22:59 by bursa]
Start at margin / padding / border support. svn path=/import/netsurf/; revision=529
Diffstat (limited to 'css')
-rw-r--r--css/css.c106
-rw-r--r--css/css.h36
-rw-r--r--css/css_enums4
-rw-r--r--css/ruleset.c257
4 files changed, 397 insertions, 6 deletions
diff --git a/css/css.c b/css/css.c
index 4b2ca4845..3f967b548 100644
--- a/css/css.c
+++ b/css/css.c
@@ -38,6 +38,14 @@ static bool css_match_rule(struct css_node *rule, xmlNode *element);
const struct css_style css_base_style = {
0xffffff,
+ { { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE },
+ { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE },
+ { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE },
+ { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE } },
CSS_CLEAR_NONE,
0x000000,
CSS_DISPLAY_BLOCK,
@@ -49,6 +57,14 @@ const struct css_style css_base_style = {
CSS_FONT_VARIANT_NORMAL,
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
{ CSS_LINE_HEIGHT_ABSOLUTE, { 1.3 } },
+ { { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } } },
+ { { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } } },
CSS_TEXT_ALIGN_LEFT,
CSS_TEXT_DECORATION_NONE,
{ CSS_TEXT_INDENT_LENGTH, { { 0, CSS_UNIT_EM } } },
@@ -60,6 +76,14 @@ const struct css_style css_base_style = {
const struct css_style css_empty_style = {
CSS_COLOR_INHERIT,
+ { { CSS_COLOR_INHERIT, { CSS_BORDER_WIDTH_INHERIT,
+ { 0, CSS_UNIT_PX } }, CSS_BORDER_STYLE_INHERIT },
+ { CSS_COLOR_INHERIT, { CSS_BORDER_WIDTH_INHERIT,
+ { 0, CSS_UNIT_PX } }, CSS_BORDER_STYLE_INHERIT },
+ { CSS_COLOR_INHERIT, { CSS_BORDER_WIDTH_INHERIT,
+ { 0, CSS_UNIT_PX } }, CSS_BORDER_STYLE_INHERIT },
+ { CSS_COLOR_INHERIT, { CSS_BORDER_WIDTH_INHERIT,
+ { 0, CSS_UNIT_PX } }, CSS_BORDER_STYLE_INHERIT } },
CSS_CLEAR_INHERIT,
CSS_COLOR_INHERIT,
CSS_DISPLAY_INHERIT,
@@ -71,6 +95,14 @@ const struct css_style css_empty_style = {
CSS_FONT_VARIANT_INHERIT,
{ CSS_HEIGHT_INHERIT, { 1, CSS_UNIT_EM } },
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
+ { { CSS_MARGIN_INHERIT, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_INHERIT, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_INHERIT, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_INHERIT, { { 0, CSS_UNIT_PX } } } },
+ { { CSS_PADDING_INHERIT, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_INHERIT, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_INHERIT, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_INHERIT, { { 0, CSS_UNIT_PX } } } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_INHERIT,
{ CSS_TEXT_INDENT_INHERIT, { { 0, CSS_UNIT_EM } } },
@@ -82,6 +114,14 @@ const struct css_style css_empty_style = {
const struct css_style css_blank_style = {
TRANSPARENT,
+ { { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE },
+ { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE },
+ { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE },
+ { 0x000000, { CSS_BORDER_WIDTH_LENGTH,
+ { 2, CSS_UNIT_PX } }, CSS_BORDER_STYLE_NONE } },
CSS_CLEAR_NONE,
CSS_COLOR_INHERIT,
CSS_DISPLAY_INLINE,
@@ -93,6 +133,14 @@ const struct css_style css_blank_style = {
CSS_FONT_VARIANT_INHERIT,
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
+ { { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_MARGIN_LENGTH, { { 0, CSS_UNIT_PX } } } },
+ { { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_INHERIT,
{ CSS_TEXT_INDENT_INHERIT, { { 0, CSS_UNIT_EM } } },
@@ -643,6 +691,7 @@ static void dump_length(const struct css_length * const length)
void css_dump_style(const struct css_style * const style)
{
+ unsigned int i;
fprintf(stderr, "{ ");
fprintf(stderr, "background-color: #%lx; ", style->background_color);
fprintf(stderr, "clear: %s; ", css_clear_name[style->clear]);
@@ -676,6 +725,29 @@ void css_dump_style(const struct css_style * const style)
default: fprintf(stderr, "UNKNOWN"); break;
}
fprintf(stderr, "; ");
+ fprintf(stderr, "margin:");
+ for (i = 0; i != 4; i++) {
+ switch (style->margin[i].margin) {
+ case CSS_MARGIN_INHERIT: fprintf(stderr, " inherit"); break;
+ case CSS_MARGIN_LENGTH: fprintf(stderr, " ");
+ dump_length(&style->margin[i].value.length); break;
+ case CSS_MARGIN_PERCENT: fprintf(stderr, " %g%%", style->margin[i].value.percent);
+ case CSS_MARGIN_AUTO: fprintf(stderr, " auto"); break;
+ default: fprintf(stderr, "UNKNOWN"); break;
+ }
+ }
+ fprintf(stderr, "; ");
+ fprintf(stderr, "padding:");
+ for (i = 0; i != 4; i++) {
+ switch (style->padding[i].padding) {
+ case CSS_PADDING_INHERIT: fprintf(stderr, " inherit"); break;
+ case CSS_PADDING_LENGTH: fprintf(stderr, " ");
+ dump_length(&style->padding[i].value.length); break;
+ case CSS_PADDING_PERCENT: fprintf(stderr, " %g%%", style->padding[i].value.percent);
+ default: fprintf(stderr, "UNKNOWN"); break;
+ }
+ }
+ fprintf(stderr, "; ");
fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]);
fprintf(stderr, "text-decoration:");
switch (style->text_decoration) {
@@ -704,6 +776,7 @@ void css_dump_style(const struct css_style * const style)
fprintf(stderr, "visibility: %s; ", css_visibility_name[style->visibility]);
fprintf(stderr, "width: ");
switch (style->width.width) {
+ case CSS_WIDTH_INHERIT: fprintf(stderr, "inherit"); break;
case CSS_WIDTH_AUTO: fprintf(stderr, "auto"); break;
case CSS_WIDTH_LENGTH: dump_length(&style->width.value.length); break;
case CSS_WIDTH_PERCENT: fprintf(stderr, "%g%%", style->width.value.percent); break;
@@ -753,6 +826,7 @@ void css_dump_stylesheet(const struct css_stylesheet * stylesheet)
void css_cascade(struct css_style * const style, const struct css_style * const apply)
{
+ unsigned int i;
float f;
/* text-decoration: approximate CSS 2.1 by inheriting into inline elements */
@@ -833,11 +907,28 @@ void css_cascade(struct css_style * const style, const struct css_style * const
default: /* leave unchanged */
break;
}
+
+ for (i = 0; i != 4; i++) {
+ if (apply->border[i].color != CSS_COLOR_INHERIT)
+ style->border[i].color = apply->border[i].color;
+ if (apply->border[i].width.width != CSS_BORDER_WIDTH_INHERIT)
+ style->border[i].width = apply->border[i].width;
+ if (apply->border[i].style != CSS_BORDER_STYLE_INHERIT)
+ style->border[i].style = apply->border[i].style;
+
+ if (apply->margin[i].margin != CSS_MARGIN_INHERIT)
+ style->margin[i] = apply->margin[i];
+
+ if (apply->padding[i].padding != CSS_PADDING_INHERIT)
+ style->padding[i] = apply->padding[i];
+ }
}
void css_merge(struct css_style * const style, const struct css_style * const apply)
{
+ unsigned int i;
+
if (apply->background_color != CSS_COLOR_INHERIT)
style->background_color = apply->background_color;
if (apply->clear != CSS_CLEAR_INHERIT)
@@ -876,6 +967,21 @@ void css_merge(struct css_style * const style, const struct css_style * const ap
style->width = apply->width;
if (apply->white_space != CSS_WHITE_SPACE_INHERIT)
style->white_space = apply->white_space;
+
+ for (i = 0; i != 4; i++) {
+ if (apply->border[i].color != CSS_COLOR_INHERIT)
+ style->border[i].color = apply->border[i].color;
+ if (apply->border[i].width.width != CSS_BORDER_WIDTH_INHERIT)
+ style->border[i].width = apply->border[i].width;
+ if (apply->border[i].style != CSS_BORDER_STYLE_INHERIT)
+ style->border[i].style = apply->border[i].style;
+
+ if (apply->margin[i].margin != CSS_MARGIN_INHERIT)
+ style->margin[i] = apply->margin[i];
+
+ if (apply->padding[i].padding != CSS_PADDING_INHERIT)
+ style->padding[i] = apply->padding[i];
+ }
}
diff --git a/css/css.h b/css/css.h
index 0482932f8..71caabfdd 100644
--- a/css/css.h
+++ b/css/css.h
@@ -35,6 +35,10 @@ typedef unsigned long colour; /* 0xbbggrr */
#define TRANSPARENT 0x1000000
#define CSS_COLOR_INHERIT 0x2000000
#define CSS_COLOR_NONE 0x3000000
+#define TOP 0
+#define RIGHT 1
+#define BOTTOM 2
+#define LEFT 3
/** Representation of a CSS 2 length. */
struct css_length {
@@ -55,6 +59,17 @@ typedef enum {
/** Representation of a complete CSS 2 style. */
struct css_style {
colour background_color;
+
+ struct {
+ colour color;
+ struct {
+ enum { CSS_BORDER_WIDTH_INHERIT,
+ CSS_BORDER_WIDTH_LENGTH } width;
+ struct css_length value;
+ } width;
+ css_border_style style;
+ } border[4]; /**< top, right, bottom, left */
+
css_clear clear;
colour color;
css_display display;
@@ -96,6 +111,27 @@ struct css_style {
} value;
} line_height;
+ struct {
+ enum { CSS_MARGIN_INHERIT,
+ CSS_MARGIN_LENGTH,
+ CSS_MARGIN_PERCENT,
+ CSS_MARGIN_AUTO } margin;
+ union {
+ struct css_length length;
+ float percent;
+ } value;
+ } margin[4]; /**< top, right, bottom, left */
+
+ struct {
+ enum { CSS_PADDING_INHERIT,
+ CSS_PADDING_LENGTH,
+ CSS_PADDING_PERCENT } padding;
+ union {
+ struct css_length length;
+ float percent;
+ } value;
+ } padding[4]; /**< top, right, bottom, left */
+
css_text_align text_align;
css_text_decoration text_decoration;
struct {
diff --git a/css/css_enums b/css/css_enums
index aaaed1419..e8d85ae5e 100644
--- a/css/css_enums
+++ b/css/css_enums
@@ -2,8 +2,7 @@ css_unit em ex px in cm mm pt pc
css_background_attachment inherit fixed scroll
css_background_position inherit top center bottom left right length percent
css_background_repeat inherit repeat repeat_x repeat_y no_repeat
-css_border_width inherit medium thin thick length
-css_border_style inherit none dashed dotted double groove inset outset ridge solid
+css_border_style inherit none hidden dotted dashed solid double groove ridge inset outset
css_clear inherit none both left right
css_display inherit inline block list-item run-in inline-block table inline-table table-row-group table-header-group table-footer-group table-row table-column-group table-column table-cell table-caption none
css_float inherit none left right
@@ -14,7 +13,6 @@ css_font_weight inherit normal bold bolder lighter 100 200 300 400 500 600 700 8
css_letter_spacing normal length
css_list_style_position outside inside
css_list_style_type disc circle square decimal lower_alpha lower_roman upper_alpha upper_roman none
-css_margin auto length percent
css_text_align inherit left right center justify
css_text_transform inherit none capitalize lowercase uppercase
css_vertical_align baseline bottom middle sub super text_bottom text_top top percent
diff --git a/css/ruleset.c b/css/ruleset.c
index fa3fe775e..82385956d 100644
--- a/css/ruleset.c
+++ b/css/ruleset.c
@@ -39,6 +39,26 @@ static int parse_length(struct css_length * const length,
static colour parse_colour(const struct css_node * const v);
static void parse_background(struct css_style * const s, const struct css_node * v);
static void parse_background_color(struct css_style * const s, const struct css_node * const v);
+static void parse_border(struct css_style * const s, const struct css_node * v);
+static void parse_border_bottom(struct css_style * const s, const struct css_node * v);
+static void parse_border_bottom_color(struct css_style * const s, const struct css_node * v);
+static void parse_border_bottom_style(struct css_style * const s, const struct css_node * v);
+static void parse_border_bottom_width(struct css_style * const s, const struct css_node * v);
+static void parse_border_color(struct css_style * const s, const struct css_node * v);
+static void parse_border_left(struct css_style * const s, const struct css_node * v);
+static void parse_border_left_color(struct css_style * const s, const struct css_node * v);
+static void parse_border_left_style(struct css_style * const s, const struct css_node * v);
+static void parse_border_left_width(struct css_style * const s, const struct css_node * v);
+static void parse_border_right(struct css_style * const s, const struct css_node * v);
+static void parse_border_right_color(struct css_style * const s, const struct css_node * v);
+static void parse_border_right_style(struct css_style * const s, const struct css_node * v);
+static void parse_border_right_width(struct css_style * const s, const struct css_node * v);
+static void parse_border_style(struct css_style * const s, const struct css_node * v);
+static void parse_border_top(struct css_style * const s, const struct css_node * v);
+static void parse_border_top_color(struct css_style * const s, const struct css_node * v);
+static void parse_border_top_style(struct css_style * const s, const struct css_node * v);
+static void parse_border_top_width(struct css_style * const s, const struct css_node * v);
+static void parse_border_width(struct css_style * const s, const struct css_node * v);
static void parse_clear(struct css_style * const s, const struct css_node * const v);
static void parse_color(struct css_style * const s, const struct css_node * const v);
static void parse_display(struct css_style * const s, const struct css_node * const v);
@@ -51,6 +71,20 @@ static void parse_font_variant(struct css_style * const s, const struct css_node
static void parse_font_weight(struct css_style * const s, const struct css_node * const v);
static void parse_height(struct css_style * const s, const struct css_node * const v);
static void parse_line_height(struct css_style * const s, const struct css_node * const v);
+static void parse_margin(struct css_style * const s, const struct css_node * const v);
+static void parse_margin_bottom(struct css_style * const s, const struct css_node * const v);
+static void parse_margin_left(struct css_style * const s, const struct css_node * const v);
+static void parse_margin_right(struct css_style * const s, const struct css_node * const v);
+static void parse_margin_top(struct css_style * const s, const struct css_node * const v);
+static void parse_margin_side(struct css_style * const s, const struct css_node * const v,
+ unsigned int i);
+static void parse_padding(struct css_style * const s, const struct css_node * const v);
+static void parse_padding_bottom(struct css_style * const s, const struct css_node * const v);
+static void parse_padding_left(struct css_style * const s, const struct css_node * const v);
+static void parse_padding_right(struct css_style * const s, const struct css_node * const v);
+static void parse_padding_top(struct css_style * const s, const struct css_node * const v);
+static void parse_padding_side(struct css_style * const s, const struct css_node * const v,
+ unsigned int i);
static void parse_text_align(struct css_style * const s, const struct css_node * const v);
static void parse_text_decoration(struct css_style * const s, const struct css_node * const v);
static void parse_text_indent(struct css_style * const s, const struct css_node * const v);
@@ -65,6 +99,26 @@ static css_text_decoration css_text_decoration_parse(const char * const s);
static const struct property_entry property_table[] = {
{ "background", parse_background },
{ "background-color", parse_background_color },
+/* { "border", parse_border },
+ { "border-bottom", parse_border_bottom },
+ { "border-bottom-color", parse_border_bottom_color },
+ { "border-bottom-style", parse_border_bottom_style },
+ { "border-bottom-width", parse_border_bottom_width },
+ { "border-color", parse_border_color },
+ { "border-left", parse_border_left },
+ { "border-left-color", parse_border_left_color },
+ { "border-left-style", parse_border_left_style },
+ { "border-left-width", parse_border_left_width },
+ { "border-right", parse_border_right },
+ { "border-right-color", parse_border_right_color },
+ { "border-right-style", parse_border_right_style },
+ { "border-right-width", parse_border_right_width },
+ { "border-style", parse_border_style },
+ { "border-top", parse_border_top },
+ { "border-top-color", parse_border_top_color },
+ { "border-top-style", parse_border_top_style },
+ { "border-top-width", parse_border_top_width },
+ { "border-width", parse_border_width },*/
{ "clear", parse_clear },
{ "color", parse_color },
{ "display", parse_display },
@@ -77,6 +131,16 @@ static const struct property_entry property_table[] = {
{ "font-weight", parse_font_weight },
{ "height", parse_height },
{ "line-height", parse_line_height },
+ { "margin", parse_margin },
+ { "margin-bottom", parse_margin_bottom },
+ { "margin-left", parse_margin_left },
+ { "margin-right", parse_margin_right },
+ { "margin-top", parse_margin_top },
+ { "padding", parse_padding },
+ { "padding-bottom", parse_padding_bottom },
+ { "padding-left", parse_padding_left },
+ { "padding-right", parse_padding_right },
+ { "padding-top", parse_padding_top },
{ "text-align", parse_text_align },
{ "text-decoration", parse_text_decoration },
{ "text-indent", parse_text_indent },
@@ -274,6 +338,11 @@ int parse_length(struct css_length * const length,
{
css_unit u;
float value;
+ if (v->type == CSS_NODE_NUMBER && atof(v->data) == 0) {
+ length->unit = CSS_UNIT_EM;
+ length->value = 0;
+ return 0;
+ }
if (v->type != CSS_NODE_DIMENSION)
return 1;
u = css_unit_parse(v->data + strspn(v->data, "0123456789+-."));
@@ -542,7 +611,8 @@ void parse_height(struct css_style * const s, const struct css_node * const v)
{
if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "auto") == 0)
s->height.height = CSS_HEIGHT_AUTO;
- else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->height.length, v, true) == 0)
+ else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
+ parse_length(&s->height.length, v, true) == 0)
s->height.height = CSS_HEIGHT_LENGTH;
}
@@ -563,6 +633,186 @@ void parse_line_height(struct css_style * const s, const struct css_node * const
}
}
+void parse_margin(struct css_style * const s, const struct css_node * const v)
+{
+ unsigned int count = 0;
+ const struct css_node *w;
+
+ for (w = v; w; w = w->next, count++)
+ if (!((w->type == CSS_NODE_IDENT && (
+ (strcasecmp(w->data, "inherit") == 0) ||
+ (strcasecmp(w->data, "auto") == 0))) ||
+ (w->type == CSS_NODE_PERCENTAGE) ||
+ (w->type == CSS_NODE_DIMENSION) ||
+ (w->type == CSS_NODE_NUMBER)))
+ return;
+
+ switch (count) {
+ case 1: /* one value: applies to all sides */
+ parse_margin_side(s, v, 0);
+ parse_margin_side(s, v, 1);
+ parse_margin_side(s, v, 2);
+ parse_margin_side(s, v, 3);
+ break;
+ case 2: /* (top and bottom), (left and right) */
+ parse_margin_side(s, v, 0);
+ parse_margin_side(s, v, 2);
+ v = v->next;
+ parse_margin_side(s, v, 1);
+ parse_margin_side(s, v, 3);
+ break;
+ case 3: /* top, (left and right), bottom */
+ parse_margin_side(s, v, 0);
+ v = v->next;
+ parse_margin_side(s, v, 1);
+ parse_margin_side(s, v, 3);
+ v = v->next;
+ parse_margin_side(s, v, 2);
+ break;
+ case 4: /* top, right, bottom, left */
+ parse_margin_side(s, v, 0);
+ v = v->next;
+ parse_margin_side(s, v, 1);
+ v = v->next;
+ parse_margin_side(s, v, 2);
+ v = v->next;
+ parse_margin_side(s, v, 3);
+ break;
+ }
+}
+
+void parse_margin_top(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_margin_side(s, v, 0);
+}
+
+void parse_margin_right(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_margin_side(s, v, 1);
+}
+
+void parse_margin_bottom(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_margin_side(s, v, 2);
+}
+
+void parse_margin_left(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_margin_side(s, v, 3);
+}
+
+void parse_margin_side(struct css_style * const s, const struct css_node * const v,
+ unsigned int i)
+{
+ if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "inherit") == 0)
+ s->margin[i].margin = CSS_MARGIN_INHERIT;
+ else if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "auto") == 0)
+ s->margin[i].margin = CSS_MARGIN_AUTO;
+ else if (v->type == CSS_NODE_PERCENTAGE) {
+ s->margin[i].margin = CSS_MARGIN_PERCENT;
+ s->margin[i].value.percent = atof(v->data);
+ } else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
+ parse_length(&s->margin[i].value.length, v, false) == 0) {
+ s->margin[i].margin = CSS_MARGIN_LENGTH;
+ }
+}
+
+void parse_padding(struct css_style * const s, const struct css_node * const v)
+{
+ unsigned int count = 0;
+ const struct css_node *w;
+
+ for (w = v; w; w = w->next, count++)
+ if (!((w->type == CSS_NODE_IDENT && strcasecmp(w->data, "inherit") == 0) ||
+ (w->type == CSS_NODE_PERCENTAGE) ||
+ (w->type == CSS_NODE_DIMENSION) ||
+ (w->type == CSS_NODE_NUMBER)))
+ return;
+
+ switch (count) {
+ case 1: /* one value: applies to all sides */
+ parse_padding_side(s, v, 0);
+ parse_padding_side(s, v, 1);
+ parse_padding_side(s, v, 2);
+ parse_padding_side(s, v, 3);
+ break;
+ case 2: /* (top and bottom), (left and right) */
+ parse_padding_side(s, v, 0);
+ parse_padding_side(s, v, 2);
+ v = v->next;
+ parse_padding_side(s, v, 1);
+ parse_padding_side(s, v, 3);
+ break;
+ case 3: /* top, (left and right), bottom */
+ parse_padding_side(s, v, 0);
+ v = v->next;
+ parse_padding_side(s, v, 1);
+ parse_padding_side(s, v, 3);
+ v = v->next;
+ parse_padding_side(s, v, 2);
+ break;
+ case 4: /* top, right, bottom, left */
+ parse_padding_side(s, v, 0);
+ v = v->next;
+ parse_padding_side(s, v, 1);
+ v = v->next;
+ parse_padding_side(s, v, 2);
+ v = v->next;
+ parse_padding_side(s, v, 3);
+ break;
+ }
+}
+
+void parse_padding_top(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_padding_side(s, v, 0);
+}
+
+void parse_padding_right(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_padding_side(s, v, 1);
+}
+
+void parse_padding_bottom(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_padding_side(s, v, 2);
+}
+
+void parse_padding_left(struct css_style * const s, const struct css_node * const v)
+{
+ if (v->next != 0)
+ return;
+ parse_padding_side(s, v, 3);
+}
+
+void parse_padding_side(struct css_style * const s, const struct css_node * const v,
+ unsigned int i)
+{
+ if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "inherit") == 0)
+ s->padding[i].padding = CSS_PADDING_INHERIT;
+ else if (v->type == CSS_NODE_PERCENTAGE) {
+ s->padding[i].padding = CSS_PADDING_PERCENT;
+ s->padding[i].value.percent = atof(v->data);
+ } else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
+ parse_length(&s->padding[i].value.length, v, true) == 0) {
+ s->padding[i].padding = CSS_PADDING_LENGTH;
+ }
+}
+
void parse_text_align(struct css_style * const s, const struct css_node * const v)
{
css_text_align z;
@@ -580,7 +830,8 @@ void parse_text_indent(struct css_style * const s, const struct css_node * const
} else if (v->type == CSS_NODE_PERCENTAGE) {
s->text_indent.size = CSS_TEXT_INDENT_PERCENT;
s->text_indent.value.percent = atof(v->data);
- } else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->text_indent.value.length, v, true) == 0) {
+ } else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
+ parse_length(&s->text_indent.value.length, v, true) == 0) {
s->text_indent.size = CSS_TEXT_INDENT_LENGTH;
}
}
@@ -633,7 +884,7 @@ void parse_width(struct css_style * const s, const struct css_node * const v)
else if (v->type == CSS_NODE_PERCENTAGE) {
s->width.width = CSS_WIDTH_PERCENT;
s->width.value.percent = atof(v->data);
- } else if (v->type == CSS_NODE_DIMENSION &&
+ } else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
parse_length(&s->width.value.length, v, true) == 0)
s->width.width = CSS_WIDTH_LENGTH;
}