css: Support canvas width/height presentational hints

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2020-05-22 15:59:02 +01:00
parent 4d927ff409
commit a5572cde76
No known key found for this signature in database
GPG Key ID: C30DF439F2987D74

View File

@ -1233,6 +1233,68 @@ static void css_hint_height_width_textarea(
}
}
static void css_hint_height_width_canvas(
nscss_select_ctx *ctx,
dom_node *node)
{
struct css_hint *hint = &hint_ctx.hints[hint_ctx.len];
dom_string *attr = NULL;
dom_exception err;
bool set_dim = false;
err = dom_element_get_attribute(node,
corestring_dom_height, &attr);
if (err == DOM_NO_ERR && attr != NULL) {
if (parse_dimension(
(const char *)dom_string_data(attr), true,
&hint->data.length.value,
&hint->data.length.unit)) {
hint->prop = CSS_PROP_HEIGHT;
hint->data.length.unit = CSS_UNIT_PX;
hint->status = CSS_HEIGHT_SET;
css_hint_advance(&hint);
set_dim = true;
}
dom_string_unref(attr);
}
if (set_dim == false) {
/* canvas defaults to 150px tall */
hint->prop = CSS_PROP_HEIGHT;
hint->data.length.unit = CSS_UNIT_PX;
hint->data.length.value = INTTOFIX(150);
hint->status = CSS_HEIGHT_SET;
css_hint_advance(&hint);
} else {
set_dim = false;
}
err = dom_element_get_attribute(node,
corestring_dom_width, &attr);
if (err == DOM_NO_ERR && attr != NULL) {
if (parse_dimension(
(const char *)dom_string_data(attr), true,
&hint->data.length.value,
&hint->data.length.unit)) {
hint->prop = CSS_PROP_WIDTH;
hint->data.length.unit = CSS_UNIT_PX;
hint->status = CSS_WIDTH_SET;
css_hint_advance(&hint);
set_dim = true;
}
dom_string_unref(attr);
}
if (set_dim == false) {
/* canvas defaults to 300px wide */
hint->prop = CSS_PROP_WIDTH;
hint->data.length.unit = CSS_UNIT_PX;
hint->data.length.value = INTTOFIX(300);
hint->status = CSS_WIDTH_SET;
css_hint_advance(&hint);
}
}
static void css_hint_width_input(
nscss_select_ctx *ctx,
dom_node *node)
@ -1606,6 +1668,9 @@ css_error node_presentational_hint(void *pw, void *node,
case DOM_HTML_ELEMENT_TYPE_BODY:
css_hint_body_color(pw, node);
break;
case DOM_HTML_ELEMENT_TYPE_CANVAS:
css_hint_height_width_canvas(pw, node);
break;
default:
break;
}