Use new alignment scheme

svn path=/trunk/netsurf/; revision=9390
This commit is contained in:
John Mark Bell 2009-08-22 09:56:41 +00:00
parent 6836a74521
commit 5552f2b06c
2 changed files with 97 additions and 116 deletions

View File

@ -1762,28 +1762,93 @@ css_error node_presentational_hint(void *pw, void *node,
strcmp((const char *) n->name, "h3") == 0 ||
strcmp((const char *) n->name, "h4") == 0 ||
strcmp((const char *) n->name, "h5") == 0 ||
strcmp((const char *) n->name, "h6") == 0)
strcmp((const char *) n->name, "h6") == 0) {
align = xmlGetProp(n, (const xmlChar *) "align");
if (align == NULL)
return CSS_PROPERTY_NOT_SET;
if (align == NULL)
return CSS_PROPERTY_NOT_SET;
if (strcmp((const char *) align, "left") == 0) {
hint->status = CSS_TEXT_ALIGN_LEFT;
} else if (strcmp((const char *) align,
"center") == 0) {
hint->status = CSS_TEXT_ALIGN_CENTER;
} else if (strcmp((const char *) align, "right") == 0) {
hint->status = CSS_TEXT_ALIGN_RIGHT;
} else if (strcmp((const char *) align,
"justify") == 0) {
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
} else {
xmlFree(align);
return CSS_PROPERTY_NOT_SET;
}
if (strcmp((const char *) align, "left") == 0) {
hint->status = CSS_TEXT_ALIGN_LEFT;
} else if (strcmp((const char *) align, "center") == 0) {
hint->status = CSS_TEXT_ALIGN_CENTER;
} else if (strcmp((const char *) align, "right") == 0) {
hint->status = CSS_TEXT_ALIGN_RIGHT;
} else if (strcmp((const char *) align, "justify") == 0) {
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
} else {
xmlFree(align);
return CSS_OK;
} else if (strcmp((const char *) n->name, "center") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
return CSS_OK;
} else if (strcmp((const char *) n->name, "caption") == 0) {
align = xmlGetProp(n, (const xmlChar *) "align");
if (align == NULL || strcmp((const char *) align,
"center") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
} else if (strcmp((const char *) align, "left") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_LEFT;
} else if (strcmp((const char *) align, "right") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_RIGHT;
} else if (strcmp((const char *) align,
"justify") == 0) {
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
} else {
xmlFree(align);
return CSS_PROPERTY_NOT_SET;
}
if (align != NULL)
xmlFree(align);
return CSS_OK;
} else if (strcmp((const char *) n->name, "div") == 0 ||
strcmp((const char *) n->name, "thead") == 0 ||
strcmp((const char *) n->name, "tbody") == 0 ||
strcmp((const char *) n->name, "tfoot") == 0 ||
strcmp((const char *) n->name, "tr") == 0 ||
strcmp((const char *) n->name, "td") == 0 ||
strcmp((const char *) n->name, "th") == 0) {
align = xmlGetProp(n, (const xmlChar *) "align");
if (align == NULL)
return CSS_PROPERTY_NOT_SET;
if (strcmp((const char *) align, "center") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
} else if (strcmp((const char *) align, "left") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_LEFT;
} else if (strcmp((const char *) align, "right") == 0) {
hint->status = CSS_TEXT_ALIGN_LIBCSS_RIGHT;
} else if (strcmp((const char *) align,
"justify") == 0) {
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
} else {
xmlFree(align);
return CSS_PROPERTY_NOT_SET;
}
xmlFree(align);
return CSS_OK;
} else if (strcmp((const char *) n->name, "table") == 0) {
/* Tables reset alignment */
hint->status = CSS_TEXT_ALIGN_DEFAULT;
return CSS_OK;
} else {
return CSS_PROPERTY_NOT_SET;
}
xmlFree(align);
return CSS_OK;
} else if (property == CSS_PROP_VERTICAL_ALIGN) {
xmlChar *valign = NULL;
@ -1853,72 +1918,6 @@ css_error node_presentational_hint(void *pw, void *node,
return CSS_OK;
}
} else if (property == CSS_PROP_LIBCSS_ALIGN) {
xmlChar *align = NULL;
if (strcmp((const char *) n->name, "center") == 0) {
hint->status = CSS_LIBCSS_ALIGN_CENTER;
return CSS_OK;
} else if (strcmp((const char *) n->name, "caption") == 0) {
align = xmlGetProp(n, (const xmlChar *) "align");
if (align == NULL || strcmp((const char *) align,
"center") == 0) {
hint->status = CSS_LIBCSS_ALIGN_CENTER;
} else if (strcmp((const char *) align, "left") == 0) {
hint->status = CSS_LIBCSS_ALIGN_LEFT;
} else if (strcmp((const char *) align, "right") == 0) {
hint->status = CSS_LIBCSS_ALIGN_RIGHT;
} else if (strcmp((const char *) align,
"justify") == 0) {
hint->status = CSS_LIBCSS_ALIGN_JUSTIFY;
} else {
xmlFree(align);
return CSS_PROPERTY_NOT_SET;
}
if (align != NULL)
xmlFree(align);
return CSS_OK;
} else if (strcmp((const char *) n->name, "div") == 0 ||
strcmp((const char *) n->name, "thead") == 0 ||
strcmp((const char *) n->name, "tbody") == 0 ||
strcmp((const char *) n->name, "tfoot") == 0 ||
strcmp((const char *) n->name, "tr") == 0 ||
strcmp((const char *) n->name, "td") == 0 ||
strcmp((const char *) n->name, "th") == 0) {
align = xmlGetProp(n, (const xmlChar *) "align");
if (align == NULL)
return CSS_PROPERTY_NOT_SET;
if (strcmp((const char *) align, "center") == 0) {
hint->status = CSS_LIBCSS_ALIGN_CENTER;
} else if (strcmp((const char *) align, "left") == 0) {
hint->status = CSS_LIBCSS_ALIGN_LEFT;
} else if (strcmp((const char *) align, "right") == 0) {
hint->status = CSS_LIBCSS_ALIGN_RIGHT;
} else if (strcmp((const char *) align,
"justify") == 0) {
hint->status = CSS_LIBCSS_ALIGN_JUSTIFY;
} else {
xmlFree(align);
return CSS_PROPERTY_NOT_SET;
}
xmlFree(align);
return CSS_OK;
} else if (strcmp((const char *) n->name, "table") == 0) {
/* Tables reset HTML alignment */
hint->status = CSS_LIBCSS_ALIGN_DEFAULT;
return CSS_OK;
} else {
return CSS_PROPERTY_NOT_SET;
}
}
return CSS_PROPERTY_NOT_SET;

View File

@ -1072,27 +1072,23 @@ int layout_solve_width(struct box *box, int available_width, int width,
/* Width was not auto, or was constrained by min/max width
* Need to compute left/right margins */
/* HTML alignment (only applies to over-constrained boxes)
* Additionally, we ignore HTML alignment for any boxes whose
* parent has non-default text-align. */
/* HTML alignment (only applies to over-constrained boxes) */
if (box->margin[LEFT] != AUTO && box->margin[RIGHT] != AUTO &&
box->parent != NULL && box->parent->style != NULL &&
css_computed_text_align(box->parent->style) ==
CSS_TEXT_ALIGN_DEFAULT) {
switch (css_computed_libcss_align(box->parent->style)) {
case CSS_LIBCSS_ALIGN_RIGHT:
box->parent != NULL && box->parent->style != NULL) {
switch (css_computed_text_align(box->parent->style)) {
case CSS_TEXT_ALIGN_LIBCSS_RIGHT:
box->margin[LEFT] = AUTO;
box->margin[RIGHT] = 0;
break;
case CSS_LIBCSS_ALIGN_CENTER:
case CSS_TEXT_ALIGN_LIBCSS_CENTER:
box->margin[LEFT] = box->margin[RIGHT] = AUTO;
break;
case CSS_LIBCSS_ALIGN_LEFT:
case CSS_LIBCSS_ALIGN_JUSTIFY:
case CSS_TEXT_ALIGN_LIBCSS_LEFT:
box->margin[LEFT] = 0;
box->margin[RIGHT] = AUTO;
break;
case CSS_LIBCSS_ALIGN_DEFAULT:
default:
/* Leave it alone; no HTML alignment */
break;
}
}
@ -2449,40 +2445,26 @@ bool layout_line(struct box *first, int *width, int *y,
/* set positions */
switch (css_computed_text_align(first->parent->parent->style)) {
case CSS_TEXT_ALIGN_RIGHT:
case CSS_TEXT_ALIGN_LIBCSS_RIGHT:
x0 = x1 - x;
break;
case CSS_TEXT_ALIGN_CENTER:
case CSS_TEXT_ALIGN_LIBCSS_CENTER:
x0 = (x0 + (x1 - x)) / 2;
break;
case CSS_TEXT_ALIGN_LEFT:
case CSS_TEXT_ALIGN_LIBCSS_LEFT:
case CSS_TEXT_ALIGN_JUSTIFY:
/* leave on left */
break;
case CSS_TEXT_ALIGN_DEFAULT:
/* No specified text-align; consider html alignment */
switch (css_computed_libcss_align(
first->parent->parent->style)) {
case CSS_LIBCSS_ALIGN_RIGHT:
x0 = x1 - x;
break;
case CSS_LIBCSS_ALIGN_CENTER:
x0 = (x0 + (x1 - x)) / 2;
break;
case CSS_LIBCSS_ALIGN_LEFT:
case CSS_LIBCSS_ALIGN_JUSTIFY:
/* None; consider text direction */
switch (css_computed_direction(first->parent->parent->style)) {
case CSS_DIRECTION_LTR:
/* leave on left */
break;
case CSS_LIBCSS_ALIGN_DEFAULT:
/* None; consider text direction */
switch (css_computed_direction(
first->parent->parent->style)) {
case CSS_DIRECTION_LTR:
/* leave on left */
break;
case CSS_DIRECTION_RTL:
x0 = x1 - x;
break;
}
case CSS_DIRECTION_RTL:
x0 = x1 - x;
break;
}
break;