[project @ 2005-03-23 18:14:38 by rjw]

Fix incorrect background position calculations. Modify CSS parser to pass all background-position testcases.

svn path=/import/netsurf/; revision=1574
This commit is contained in:
Richard Wilson 2005-03-23 18:14:38 +00:00
parent c16c3ffa2f
commit 511891d27c
2 changed files with 25 additions and 10 deletions

View File

@ -1085,7 +1085,9 @@ bool css_background_position_parse(const struct css_node **node,
{
const struct css_node *v = *node;
const struct css_node *w = v->next;
struct css_background_entry *bg = 0, *bg2 = 0;
const struct css_node *n_temp = 0;
struct css_background_entry *bg = 0, *bg2 = 0, *b_temp = 0;
bool switched = false;
if (v->type == CSS_NODE_IDENT)
bg = css_background_lookup(v);
@ -1151,6 +1153,14 @@ bool css_background_position_parse(const struct css_node **node,
*node = w->next;
return true;
}
/* reverse specifiers such that idents are places in h, v order */
if ((v->type == CSS_NODE_IDENT && bg && bg->vertical) ||
(w->type == CSS_NODE_IDENT && bg2 && bg2->horizontal)) {
n_temp = v; v = w; w = n_temp;
b_temp = bg; bg = bg2; bg2 = b_temp;
switched = true;
}
if (v->type == CSS_NODE_IDENT) { /* horizontal value */
if (!bg || bg->vertical)
@ -1185,6 +1195,12 @@ bool css_background_position_parse(const struct css_node **node,
vert->pos = CSS_BACKGROUND_POSITION_LENGTH;
}
/* undo any switching we did */
if (switched) {
n_temp = v; v = w; w = n_temp;
b_temp = bg; bg = bg2; bg2 = b_temp;
}
*node = w->next;
return true;
}

View File

@ -701,7 +701,6 @@ bool html_redraw_file(int x, int y, int width, int height,
bool html_redraw_background(int x, int y,
struct box *box, float scale, colour background_colour)
{
int image_width, image_height;
bool repeat_x = false;
bool repeat_y = false;
@ -718,10 +717,6 @@ bool html_redraw_background(int x, int y,
else if (!option_background_images)
return true;*/
/* get the image dimensions for our positioning and scaling */
image_width = box->background->width * scale;
image_height = box->background->height * scale;
/* handle background-repeat */
switch (box->style->background_repeat) {
case CSS_BACKGROUND_REPEAT_REPEAT:
@ -743,7 +738,8 @@ bool html_redraw_background(int x, int y,
switch (box->style->background_position.horz.pos) {
case CSS_BACKGROUND_POSITION_PERCENT:
x += (box->padding[LEFT] + box->width +
box->padding[RIGHT] - image_width) *
box->padding[RIGHT] -
box->background->width) * scale *
box->style->background_position.horz.
value.percent / 100;
break;
@ -758,12 +754,13 @@ bool html_redraw_background(int x, int y,
switch (box->style->background_position.vert.pos) {
case CSS_BACKGROUND_POSITION_PERCENT:
y += (box->padding[TOP] + box->height +
box->padding[BOTTOM] - image_height) *
box->padding[BOTTOM] -
box->background->height) * scale *
box->style->background_position.vert.
value.percent / 100;
break;
case CSS_BACKGROUND_POSITION_LENGTH:
y -= (int) (css_len2px(&box->style->background_position.
y += (int) (css_len2px(&box->style->background_position.
vert.value.length, box->style) * scale);
break;
default:
@ -771,7 +768,9 @@ bool html_redraw_background(int x, int y,
}
/* and plot the image */
return plot.bitmap_tile(x, y, image_width, image_height,
return plot.bitmap_tile(x, y,
box->background->width * scale,
box->background->height * scale,
box->background->bitmap,
background_colour,
repeat_x, repeat_y);