summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2005-03-22 00:10:42 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2005-03-22 00:10:42 +0000
commitb832e05f034ccca6d2bcaa058ca0d9d6214bd22b (patch)
tree472ef7907956bd00501387a6588a51548a0d4793
parent28d9260ca463abe3992fd674cc127b6b2baa04aa (diff)
downloadnetsurf-b832e05f034ccca6d2bcaa058ca0d9d6214bd22b.tar.gz
netsurf-b832e05f034ccca6d2bcaa058ca0d9d6214bd22b.tar.bz2
[project @ 2005-03-22 00:10:42 by rjw]
Experimental cellpadding support svn path=/import/netsurf/; revision=1569
-rw-r--r--css/css.c34
-rw-r--r--css/css.h11
-rw-r--r--css/ruleset.c7
-rw-r--r--render/box.c15
-rw-r--r--render/layout.c13
5 files changed, 64 insertions, 16 deletions
diff --git a/css/css.c b/css/css.c
index 19e525e2b..ff5268c68 100644
--- a/css/css.c
+++ b/css/css.c
@@ -109,6 +109,7 @@ static void css_dump_selector(const struct css_selector *r);
/** Default style for a document. These are the 'Initial values' from the
* spec. */
const struct css_style css_base_style = {
+ { {CSS_CELLPADDING_VALUE, 1} },
CSS_BACKGROUND_ATTACHMENT_SCROLL,
0xffffff,
{ CSS_BACKGROUND_IMAGE_NONE, 0 },
@@ -165,10 +166,10 @@ const struct css_style css_base_style = {
{ CSS_BORDER_WIDTH_LENGTH, { 2, CSS_UNIT_PX } },
CSS_BORDER_STYLE_NONE },
CSS_OVERFLOW_VISIBLE,
- { { 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_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false }, },
CSS_PAGE_BREAK_AFTER_AUTO,
CSS_PAGE_BREAK_BEFORE_AUTO,
CSS_PAGE_BREAK_INSIDE_AUTO,
@@ -194,6 +195,7 @@ const struct css_style css_base_style = {
/** Style with no values set. */
const struct css_style css_empty_style = {
+ { { CSS_CELLPADDING_NOT_SET, 0 } },
CSS_BACKGROUND_ATTACHMENT_NOT_SET,
CSS_COLOR_NOT_SET,
{ CSS_BACKGROUND_IMAGE_NOT_SET, 0 },
@@ -250,10 +252,10 @@ const struct css_style css_empty_style = {
{ CSS_BORDER_WIDTH_NOT_SET, { 0, CSS_UNIT_PX } },
CSS_BORDER_STYLE_NOT_SET },
CSS_OVERFLOW_NOT_SET,
- { { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } },
- { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } },
- { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } },
- { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } } },
+ { { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false }, },
CSS_PAGE_BREAK_AFTER_NOT_SET,
CSS_PAGE_BREAK_BEFORE_NOT_SET,
CSS_PAGE_BREAK_INSIDE_NOT_SET,
@@ -280,6 +282,7 @@ const struct css_style css_empty_style = {
/** Default style for an element. These should be INHERIT if 'Inherited' is yes,
* and the 'Initial value' otherwise. */
const struct css_style css_blank_style = {
+ { { CSS_CELLPADDING_INHERIT, 0 } },
CSS_BACKGROUND_ATTACHMENT_SCROLL,
TRANSPARENT,
{ CSS_BACKGROUND_IMAGE_NONE, 0 },
@@ -336,10 +339,10 @@ const struct css_style css_blank_style = {
{ CSS_BORDER_WIDTH_LENGTH, { 2, CSS_UNIT_PX } },
CSS_BORDER_STYLE_NONE },
CSS_OVERFLOW_VISIBLE,
- { { 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_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
+ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false }, },
CSS_PAGE_BREAK_AFTER_AUTO,
CSS_PAGE_BREAK_BEFORE_AUTO,
CSS_PAGE_BREAK_INSIDE_INHERIT,
@@ -2378,6 +2381,11 @@ void css_cascade(struct css_style * const style,
unsigned int i;
float f;
+ if (apply->html_style.cellpadding.type !=
+ CSS_CELLPADDING_INHERIT &&
+ apply->html_style.cellpadding.type !=
+ CSS_CELLPADDING_NOT_SET)
+ style->html_style.cellpadding = apply->html_style.cellpadding;
if (apply->background_attachment !=
CSS_BACKGROUND_ATTACHMENT_INHERIT &&
apply->background_attachment !=
@@ -2668,6 +2676,8 @@ void css_merge(struct css_style * const style,
{
unsigned int i;
+ if (apply->html_style.cellpadding.type != CSS_CELLPADDING_NOT_SET)
+ style->html_style.cellpadding = apply->html_style.cellpadding;
if (apply->background_attachment != CSS_BACKGROUND_ATTACHMENT_NOT_SET)
style->background_attachment = apply->background_attachment;
if (apply->background_color != CSS_COLOR_NOT_SET)
diff --git a/css/css.h b/css/css.h
index d9701cbbe..99e9b4463 100644
--- a/css/css.h
+++ b/css/css.h
@@ -149,6 +149,16 @@ struct css_content {
/** Representation of a complete CSS 2 style. */
struct css_style {
+ /* html styles that don't translate directly to CSS */
+ struct {
+ struct {
+ enum { CSS_CELLPADDING_INHERIT,
+ CSS_CELLPADDING_VALUE,
+ CSS_CELLPADDING_NOT_SET } type;
+ int value;
+ } cellpadding;
+ } html_style;
+
/* background properties */
css_background_attachment background_attachment;
colour background_color;
@@ -368,6 +378,7 @@ struct css_style {
struct css_length length;
float percent;
} value;
+ bool override_cellpadding; /* override HTML setting */
} padding[4]; /**< top, right, bottom, left */
css_page_break_after page_break_after;
diff --git a/css/ruleset.c b/css/ruleset.c
index 117a69b92..c09bd0d1c 100644
--- a/css/ruleset.c
+++ b/css/ruleset.c
@@ -2665,14 +2665,17 @@ void parse_padding_side(struct css_style * const s, const struct css_node * cons
unsigned int i)
{
if (v->type == CSS_NODE_IDENT && v->data_length == 7 &&
- strncasecmp(v->data, "inherit", 7) == 0)
+ strncasecmp(v->data, "inherit", 7) == 0) {
s->padding[i].padding = CSS_PADDING_INHERIT;
- else if (v->type == CSS_NODE_PERCENTAGE) {
+ s->padding[i].override_cellpadding = true;
+ } else if (v->type == CSS_NODE_PERCENTAGE) {
s->padding[i].padding = CSS_PADDING_PERCENT;
s->padding[i].value.percent = atof(v->data);
+ s->padding[i].override_cellpadding = true;
} 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;
+ s->padding[i].override_cellpadding = true;
}
}
diff --git a/render/box.c b/render/box.c
index 2eb928d46..3cc8d805f 100644
--- a/render/box.c
+++ b/render/box.c
@@ -936,6 +936,21 @@ struct css_style * box_get_style(struct content *c,
}
}
}
+ style->html_style.cellpadding.type = CSS_CELLPADDING_VALUE;
+ if ((s = (char *) xmlGetProp(n,
+ (const xmlChar *) "cellpadding"))) {
+ if (!strrchr(s, '%')) { /* % not implemented */
+ int value = atoi(s);
+ if (0 <= value) {
+ style->html_style.cellpadding.value = value;
+ /* todo: match <td> and <th> rules and don't set if they are */
+ for (i = 0; i < 4; i++)
+ style->padding[i].override_cellpadding = false;
+ }
+ }
+ } else {
+ style->html_style.cellpadding.value = 1;
+ }
}
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "style")) != NULL) {
diff --git a/render/layout.c b/render/layout.c
index 48ea15ba8..96a61e31d 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -1216,7 +1216,7 @@ bool layout_table(struct box *table, int available_width,
int *excess_y;
int table_width, min_width = 0, max_width = 0;
int required_width = 0;
- int x;
+ int x, cp;
int table_height = 0;
int *xs; /* array of column x positions */
int auto_width;
@@ -1264,6 +1264,11 @@ bool layout_table(struct box *table, int available_width,
layout_find_dimensions(available_width,
c->style, 0,
c->padding, c->border);
+ if (c->style->html_style.cellpadding.type == CSS_CELLPADDING_VALUE)
+ for (cp = 0; cp < 4; cp++)
+ if (!c->style->padding[cp].override_cellpadding)
+ c->padding[cp] =
+ c->style->html_style.cellpadding.value;
if (c->style->overflow ==
CSS_OVERFLOW_SCROLL ||
c->style->overflow ==
@@ -1663,7 +1668,11 @@ bool calculate_widths(struct box *box)
/* add margins, border, padding to min, max widths */
if (style) {
for (side = 1; side != 5; side += 2) { /* RIGHT, LEFT */
- if (style->padding[side].padding == CSS_PADDING_LENGTH)
+ if ((box->type == BOX_TABLE_CELL) &&
+ (style->html_style.cellpadding.type == CSS_CELLPADDING_VALUE) &&
+ (!style->padding[side].override_cellpadding))
+ extra_fixed += style->html_style.cellpadding.value;
+ else if (style->padding[side].padding == CSS_PADDING_LENGTH)
extra_fixed += (int)css_len2px(&style->padding[side].value.length,
style);
else if (style->padding[side].padding == CSS_PADDING_PERCENT)