summaryrefslogtreecommitdiff
path: root/content/handlers/css
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/css')
-rw-r--r--content/handlers/css/Makefile2
-rw-r--r--content/handlers/css/css.c3
-rw-r--r--content/handlers/css/dump.c37
-rw-r--r--content/handlers/css/hints.c65
-rw-r--r--content/handlers/css/select.c158
-rw-r--r--content/handlers/css/select.h5
-rw-r--r--content/handlers/css/utils.c259
-rw-r--r--content/handlers/css/utils.h104
8 files changed, 118 insertions, 515 deletions
diff --git a/content/handlers/css/Makefile b/content/handlers/css/Makefile
index bbfc8d7b4..d5cf16647 100644
--- a/content/handlers/css/Makefile
+++ b/content/handlers/css/Makefile
@@ -1,4 +1,4 @@
# CSS sources
-S_CSS := css.c dump.c internal.c hints.c select.c utils.c
+S_CSS := css.c dump.c internal.c hints.c select.c
diff --git a/content/handlers/css/css.c b/content/handlers/css/css.c
index be945fb97..f9197ddfe 100644
--- a/content/handlers/css/css.c
+++ b/content/handlers/css/css.c
@@ -40,6 +40,9 @@
/* Define to trace import fetches */
#undef NSCSS_IMPORT_TRACE
+/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
+css_fixed nscss_screen_dpi = F_90;
+
struct content_css_data;
/**
diff --git a/content/handlers/css/dump.c b/content/handlers/css/dump.c
index b12e1d9e8..950a6f8cc 100644
--- a/content/handlers/css/dump.c
+++ b/content/handlers/css/dump.c
@@ -19,6 +19,8 @@
#include <stdio.h>
#include <libcss/libcss.h>
+#include "netsurf/inttypes.h"
+
#include "css/dump.h"
#include "css/utils.h"
@@ -36,7 +38,7 @@ static void dump_css_fixed(FILE *stream, css_fixed f)
uint32_t fracpart = ((NSCSS_ABS(f) & 0x3ff) * 1000 + 500) / (1 << 10);
#undef NSCSS_ABS
- fprintf(stream, "%s%d.%03d", f < 0 ? "-" : "", uintpart, fracpart);
+ fprintf(stream, "%s%"PRIu32".%03"PRIu32, f < 0 ? "-" : "", uintpart, fracpart);
}
/**
@@ -48,7 +50,7 @@ static void dump_css_fixed(FILE *stream, css_fixed f)
static void dump_css_number(FILE *stream, css_fixed val)
{
if (INTTOFIX(FIXTOINT(val)) == val)
- fprintf(stream, "%d", FIXTOINT(val));
+ fprintf(stream, "%"PRId32, FIXTOINT(val));
else
dump_css_fixed(stream, val);
}
@@ -113,24 +115,15 @@ static void dump_css_unit(FILE *stream, css_fixed val, css_unit unit)
case CSS_UNIT_KHZ:
fprintf(stream, "kHz");
break;
- case CSS_UNIT_CAP:
- fprintf(stream, "cap");
- break;
case CSS_UNIT_CH:
fprintf(stream, "ch");
break;
- case CSS_UNIT_IC:
- fprintf(stream, "ic");
- break;
case CSS_UNIT_REM:
fprintf(stream, "rem");
break;
case CSS_UNIT_LH:
fprintf(stream, "lh");
break;
- case CSS_UNIT_RLH:
- fprintf(stream, "rlh");
- break;
case CSS_UNIT_VH:
fprintf(stream, "vh");
break;
@@ -190,7 +183,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_background_color(style, &color);
switch (val) {
case CSS_BACKGROUND_COLOR_COLOR:
- fprintf(stream, "background-color: #%08x ", color);
+ fprintf(stream, "background-color: #%08"PRIx32" ", color);
break;
default:
break;
@@ -264,7 +257,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_border_top_color(style, &color);
switch (val) {
case CSS_BORDER_COLOR_COLOR:
- fprintf(stream, "border-top-color: #%08x ", color);
+ fprintf(stream, "border-top-color: #%08"PRIx32" ", color);
break;
default:
break;
@@ -274,7 +267,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_border_right_color(style, &color);
switch (val) {
case CSS_BORDER_COLOR_COLOR:
- fprintf(stream, "border-right-color: #%08x ", color);
+ fprintf(stream, "border-right-color: #%08"PRIx32" ", color);
break;
default:
break;
@@ -284,7 +277,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_border_bottom_color(style, &color);
switch (val) {
case CSS_BORDER_COLOR_COLOR:
- fprintf(stream, "border-bottom-color: #%08x ", color);
+ fprintf(stream, "border-bottom-color: #%08"PRIx32" ", color);
break;
default:
break;
@@ -294,7 +287,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_border_left_color(style, &color);
switch (val) {
case CSS_BORDER_COLOR_COLOR:
- fprintf(stream, "border-left-color: #%08x ", color);
+ fprintf(stream, "border-left-color: #%08"PRIx32" ", color);
break;
default:
break;
@@ -619,7 +612,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
/* color */
val = css_computed_color(style, &color);
if (val == CSS_COLOR_COLOR) {
- fprintf(stream, "color: #%08x ", color);
+ fprintf(stream, "color: #%08"PRIx32" ", color);
}
/* content */
@@ -873,6 +866,12 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
case CSS_DISPLAY_NONE:
fprintf(stream, "display: none ");
break;
+ case CSS_DISPLAY_FLEX:
+ fprintf(stream, "display: flex ");
+ break;
+ case CSS_DISPLAY_INLINE_FLEX:
+ fprintf(stream, "display: inline-flex ");
+ break;
default:
break;
}
@@ -1356,7 +1355,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
fprintf(stream, "outline-color: invert ");
break;
case CSS_OUTLINE_COLOR_COLOR:
- fprintf(stream, "outline-color: #%08x ", color);
+ fprintf(stream, "outline-color: #%08"PRIx32" ", color);
break;
default:
break;
@@ -1823,7 +1822,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
fprintf(stream, "z-index: auto ");
break;
case CSS_Z_INDEX_SET:
- fprintf(stream, "z-index: %d ", zindex);
+ fprintf(stream, "z-index: %"PRId32" ", zindex);
break;
default:
break;
diff --git a/content/handlers/css/hints.c b/content/handlers/css/hints.c
index 9748030b7..0f246a64c 100644
--- a/content/handlers/css/hints.c
+++ b/content/handlers/css/hints.c
@@ -1579,14 +1579,64 @@ static void css_hint_white_space_nowrap(
}
}
+static void css_hint_list(
+ nscss_select_ctx *ctx,
+ dom_node *node)
+{
+ struct css_hint *hint = &(hint_ctx.hints[hint_ctx.len]);
+ dom_exception err;
+ dom_string *attr;
+
+ err = dom_element_get_attribute(node, corestring_dom_type, &attr);
+ if (err == DOM_NO_ERR && attr != NULL) {
+ const char *attr_str = dom_string_data(attr);
+ size_t attr_len = dom_string_byte_length(attr);
+ enum css_list_style_type_e type = CSS_LIST_STYLE_TYPE_INHERIT;
+
+ if (attr_len == 1) {
+ switch (attr_str[0]) {
+ case 'a':
+ type = CSS_LIST_STYLE_TYPE_LOWER_ALPHA;
+ break;
+ case 'A':
+ type = CSS_LIST_STYLE_TYPE_UPPER_ALPHA;
+ break;
+ case 'i':
+ type = CSS_LIST_STYLE_TYPE_LOWER_ROMAN;
+ break;
+ case 'I':
+ type = CSS_LIST_STYLE_TYPE_UPPER_ROMAN;
+ break;
+ case '1':
+ type = CSS_LIST_STYLE_TYPE_DECIMAL;
+ break;
+ }
+ }
-/* Exported function, documeted in css/hints.h */
+ if (type != CSS_LIST_STYLE_TYPE_INHERIT) {
+ hint->prop = CSS_PROP_LIST_STYLE_TYPE;
+ hint->status = type;
+ css_hint_advance(&hint);
+ }
+
+ dom_string_unref(attr);
+ }
+}
+
+
+/* Exported function, documented in css/hints.h */
css_error node_presentational_hint(void *pw, void *node,
uint32_t *nhints, css_hint **hints)
{
dom_exception exc;
dom_html_element_type tag_type;
+ if (nsoption_bool(author_level_css) == false) {
+ *nhints = 0;
+ *hints = NULL;
+ return CSS_OK;
+ }
+
css_hint_clean();
exc = dom_html_element_get_tag_type(node, &tag_type);
@@ -1600,22 +1650,22 @@ css_error node_presentational_hint(void *pw, void *node,
css_hint_width(pw, node);
css_hint_table_cell_border_padding(pw, node);
css_hint_white_space_nowrap(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_TR:
css_hint_height(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_THEAD:
case DOM_HTML_ELEMENT_TYPE_TBODY:
case DOM_HTML_ELEMENT_TYPE_TFOOT:
css_hint_text_align_special(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_COL:
css_hint_vertical_align_table_cells(pw, node);
break;
case DOM_HTML_ELEMENT_TYPE_APPLET:
case DOM_HTML_ELEMENT_TYPE_IMG:
css_hint_margin_hspace_vspace(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_EMBED:
case DOM_HTML_ELEMENT_TYPE_IFRAME:
case DOM_HTML_ELEMENT_TYPE_OBJECT:
@@ -1638,7 +1688,7 @@ css_error node_presentational_hint(void *pw, void *node,
break;
case DOM_HTML_ELEMENT_TYPE_CAPTION:
css_hint_caption_side(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_DIV:
css_hint_text_align_special(pw, node);
break;
@@ -1671,6 +1721,9 @@ css_error node_presentational_hint(void *pw, void *node,
case DOM_HTML_ELEMENT_TYPE_CANVAS:
css_hint_height_width_canvas(pw, node);
break;
+ case DOM_HTML_ELEMENT_TYPE_OL:
+ css_hint_list(pw, node);
+ break;
default:
break;
}
diff --git a/content/handlers/css/select.c b/content/handlers/css/select.c
index 99840e954..c77644b43 100644
--- a/content/handlers/css/select.c
+++ b/content/handlers/css/select.c
@@ -91,10 +91,6 @@ static css_error set_libcss_node_data(void *pw, void *node,
static css_error get_libcss_node_data(void *pw, void *node,
void **libcss_node_data);
-static css_error nscss_compute_font_size(void *pw, const css_hint *parent,
- css_hint *size);
-
-
/**
* Selection callback table for libcss
*/
@@ -135,9 +131,8 @@ static css_select_handler selection_handler = {
node_is_lang,
node_presentational_hint,
ua_default_for_property,
- nscss_compute_font_size,
set_libcss_node_data,
- get_libcss_node_data
+ get_libcss_node_data,
};
/**
@@ -250,12 +245,15 @@ static void nscss_dom_user_data_handler(dom_node_operation operation,
* \param ctx CSS selection context
* \param n Element to select for
* \param media Permitted media types
+ * \param unit_unit_len_ctx Unit length conversion context
* \param inline_style Inline style associated with element, or NULL
* \return Pointer to selection results (containing computed styles),
* or NULL on failure
*/
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
- const css_media *media, const css_stylesheet *inline_style)
+ const css_media *media,
+ const css_unit_ctx *unit_len_ctx,
+ const css_stylesheet *inline_style)
{
css_computed_style *composed;
css_select_results *styles;
@@ -263,7 +261,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
css_error error;
/* Select style for node */
- error = css_select_style(ctx->ctx, n, media, inline_style,
+ error = css_select_style(ctx->ctx, n, unit_len_ctx, media, inline_style,
&selection_handler, ctx, &styles);
if (error != CSS_OK || styles == NULL) {
@@ -278,8 +276,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
* element's style */
error = css_computed_style_compose(ctx->parent_style,
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
- nscss_compute_font_size, ctx,
- &composed);
+ unit_len_ctx, &composed);
if (error != CSS_OK) {
css_select_results_destroy(styles);
return NULL;
@@ -310,8 +307,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
error = css_computed_style_compose(
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
styles->styles[pseudo_element],
- nscss_compute_font_size, ctx,
- &composed);
+ unit_len_ctx, &composed);
if (error != CSS_OK) {
/* TODO: perhaps this shouldn't be quite so
* catastrophic? */
@@ -330,11 +326,13 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
/**
* Get a blank style
*
- * \param ctx CSS selection context
- * \param parent Parent style to cascade inherited properties from
+ * \param ctx CSS selection context
+ * \param unit_unit_len_ctx Unit length conversion context
+ * \param parent Parent style to cascade inherited properties from
* \return Pointer to blank style, or NULL on failure
*/
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent)
{
css_computed_style *partial, *composed;
@@ -349,7 +347,7 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
/* TODO: Do we really need to compose? Initial style shouldn't
* have any inherited properties. */
error = css_computed_style_compose(parent, partial,
- nscss_compute_font_size, ctx, &composed);
+ unit_len_ctx, &composed);
css_computed_style_destroy(partial);
if (error != CSS_OK) {
css_computed_style_destroy(composed);
@@ -359,133 +357,6 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
return composed;
}
-/**
- * Font size computation callback for libcss
- *
- * \param pw Computation context
- * \param parent Parent font size (absolute)
- * \param size Font size to compute
- * \return CSS_OK on success
- *
- * \post \a size will be an absolute font size
- */
-css_error nscss_compute_font_size(void *pw, const css_hint *parent,
- css_hint *size)
-{
- /**
- * Table of font-size keyword scale factors
- *
- * These are multiplied by the configured default font size
- * to produce an absolute size for the relevant keyword
- */
- static const css_fixed factors[] = {
- FLTTOFIX(0.5625), /* xx-small */
- FLTTOFIX(0.6250), /* x-small */
- FLTTOFIX(0.8125), /* small */
- FLTTOFIX(1.0000), /* medium */
- FLTTOFIX(1.1250), /* large */
- FLTTOFIX(1.5000), /* x-large */
- FLTTOFIX(2.0000) /* xx-large */
- };
- css_hint_length parent_size;
-
- /* Grab parent size, defaulting to medium if none */
- if (parent == NULL) {
- parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1],
- INTTOFIX(nsoption_int(font_size))),
- INTTOFIX(10));
- parent_size.unit = CSS_UNIT_PT;
- } else {
- assert(parent->status == CSS_FONT_SIZE_DIMENSION);
- assert(parent->data.length.unit != CSS_UNIT_EM);
- assert(parent->data.length.unit != CSS_UNIT_EX);
- assert(parent->data.length.unit != CSS_UNIT_PCT);
-
- parent_size = parent->data.length;
- }
-
- assert(size->status != CSS_FONT_SIZE_INHERIT);
-
- if (size->status < CSS_FONT_SIZE_LARGER) {
- /* Keyword -- simple */
- size->data.length.value = FDIV(FMUL(factors[size->status - 1],
- INTTOFIX(nsoption_int(font_size))), F_10);
- size->data.length.unit = CSS_UNIT_PT;
- } else if (size->status == CSS_FONT_SIZE_LARGER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FMUL(parent_size.value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size.unit;
- } else if (size->status == CSS_FONT_SIZE_SMALLER) {
- /** \todo Step within table, if appropriate */
- size->data.length.value =
- FDIV(parent_size.value, FLTTOFIX(1.2));
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_EM ||
- size->data.length.unit == CSS_UNIT_EX ||
- size->data.length.unit == CSS_UNIT_CAP ||
- size->data.length.unit == CSS_UNIT_CH ||
- size->data.length.unit == CSS_UNIT_IC) {
- size->data.length.value =
- FMUL(size->data.length.value, parent_size.value);
-
- switch (size->data.length.unit) {
- case CSS_UNIT_EX:
- /* 1ex = 0.6em in NetSurf */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CAP:
- /* Height of captals. 1cap = 0.9em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.9));
- break;
- case CSS_UNIT_CH:
- /* Width of '0'. 1ch = 0.4em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.4));
- break;
- case CSS_UNIT_IC:
- /* Width of U+6C43. 1ic = 1.1em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(1.1));
- break;
- default:
- /* No scaling required for EM. */
- break;
- }
-
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_PCT) {
- size->data.length.value = FDIV(FMUL(size->data.length.value,
- parent_size.value), INTTOFIX(100));
- size->data.length.unit = parent_size.unit;
- } else if (size->data.length.unit == CSS_UNIT_REM) {
- nscss_select_ctx *ctx = pw;
- if (parent == NULL) {
- size->data.length.value = parent_size.value;
- size->data.length.unit = parent_size.unit;
- } else {
- css_computed_font_size(ctx->root_style,
- &parent_size.value,
- &size->data.length.unit);
- size->data.length.value = FMUL(
- size->data.length.value,
- parent_size.value);
- }
- } else if (size->data.length.unit == CSS_UNIT_RLH) {
- /** TODO: Convert root element line-height to absolute value. */
- size->data.length.value = FMUL(size->data.length.value, FDIV(
- INTTOFIX(nsoption_int(font_size)),
- INTTOFIX(10)));
- size->data.length.unit = CSS_UNIT_PT;
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
/******************************************************************************
* Style selection callbacks *
******************************************************************************/
@@ -602,6 +473,7 @@ css_error named_ancestor_node(void *pw, void *node,
{
dom_element_named_ancestor_node(node, qname->name,
(struct dom_element **)ancestor);
+ dom_node_unref(*ancestor);
return CSS_OK;
}
@@ -622,6 +494,7 @@ css_error named_parent_node(void *pw, void *node,
{
dom_element_named_parent_node(node, qname->name,
(struct dom_element **)parent);
+ dom_node_unref(*parent);
return CSS_OK;
}
@@ -771,6 +644,7 @@ css_error named_generic_sibling_node(void *pw, void *node,
css_error parent_node(void *pw, void *node, void **parent)
{
dom_element_parent_node(node, (struct dom_element **)parent);
+ dom_node_unref(*parent);
return CSS_OK;
}
diff --git a/content/handlers/css/select.h b/content/handlers/css/select.h
index b45d1ed3c..c17caadcb 100644
--- a/content/handlers/css/select.h
+++ b/content/handlers/css/select.h
@@ -45,9 +45,12 @@ css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,
const char *charset, const char *url, bool allow_quirks);
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
- const css_media *media, const css_stylesheet *inline_style);
+ const css_media *media,
+ const css_unit_ctx *unit_len_ctx,
+ const css_stylesheet *inline_style);
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *parent);
diff --git a/content/handlers/css/utils.c b/content/handlers/css/utils.c
deleted file mode 100644
index cf48e8919..000000000
--- a/content/handlers/css/utils.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright 2004 James Bursa <james@netsurf-browser.org>
- * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <assert.h>
-
-#include "utils/nsoption.h"
-#include "utils/log.h"
-
-#include "css/utils.h"
-
-/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
-css_fixed nscss_screen_dpi = F_90;
-
-/** Medium screen density for device viewing distance. */
-css_fixed nscss_baseline_pixel_density = F_96;
-
-/**
- * Map viewport-relative length units to either vh or vw.
- *
- * Non-viewport-relative units are unchanged.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] unit Unit to map.
- * \return the mapped unit.
- */
-static inline css_unit css_utils__fudge_viewport_units(
- const nscss_len_ctx *ctx,
- css_unit unit)
-{
- switch (unit) {
- case CSS_UNIT_VI:
- assert(ctx->root_style != NULL);
- if (css_computed_writing_mode(ctx->root_style) ==
- CSS_WRITING_MODE_HORIZONTAL_TB) {
- unit = CSS_UNIT_VW;
- } else {
- unit = CSS_UNIT_VH;
- }
- break;
- case CSS_UNIT_VB:
- assert(ctx->root_style != NULL);
- if (css_computed_writing_mode(ctx->root_style) ==
- CSS_WRITING_MODE_HORIZONTAL_TB) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- case CSS_UNIT_VMIN:
- if (ctx->vh < ctx->vw) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- case CSS_UNIT_VMAX:
- if (ctx->vh > ctx->vw) {
- unit = CSS_UNIT_VH;
- } else {
- unit = CSS_UNIT_VW;
- }
- break;
- default: break;
- }
-
- return unit;
-}
-
-/* exported interface documented in content/handlers/css/utils.h */
-css_fixed nscss_len2pt(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit)
-{
- /* Length must not be relative */
- assert(unit != CSS_UNIT_EM &&
- unit != CSS_UNIT_EX &&
- unit != CSS_UNIT_CAP &&
- unit != CSS_UNIT_CH &&
- unit != CSS_UNIT_IC &&
- unit != CSS_UNIT_REM &&
- unit != CSS_UNIT_RLH);
-
- unit = css_utils__fudge_viewport_units(ctx, unit);
-
- switch (unit) {
- /* We assume the screen and any other output has the same dpi */
- /* 1in = DPIpx => 1px = (72/DPI)pt */
- case CSS_UNIT_PX: return FDIV(FMUL(length, F_72), F_96);
- /* 1in = 72pt */
- case CSS_UNIT_IN: return FMUL(length, F_72);
- /* 1in = 2.54cm => 1cm = (72/2.54)pt */
- case CSS_UNIT_CM: return FMUL(length,
- FDIV(F_72, FLTTOFIX(2.54)));
- /* 1in = 25.4mm => 1mm = (72/25.4)pt */
- case CSS_UNIT_MM: return FMUL(length,
- FDIV(F_72, FLTTOFIX(25.4)));
- /* 1in = 101.6q => 1mm = (72/101.6)pt */
- case CSS_UNIT_Q: return FMUL(length,
- FDIV(F_72, FLTTOFIX(101.6)));
- case CSS_UNIT_PT: return length;
- /* 1pc = 12pt */
- case CSS_UNIT_PC: return FMUL(length, INTTOFIX(12));
- case CSS_UNIT_VH: return FDIV(FMUL(FDIV(FMUL(length, ctx->vh), F_100), F_72), F_96);
- case CSS_UNIT_VW: return FDIV(FMUL(FDIV(FMUL(length,ctx->vw), F_100), F_72), F_96);
- default: break;
- }
-
- return 0;
-}
-
-/* exported interface documented in content/handlers/css/utils.h */
-css_fixed nscss_len2px(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit,
- const css_computed_style *style)
-{
- /* We assume the screen and any other output has the same dpi */
- css_fixed px_per_unit;
-
- unit = css_utils__fudge_viewport_units(ctx, unit);
-
- switch (unit) {
- case CSS_UNIT_EM:
- case CSS_UNIT_EX:
- case CSS_UNIT_CAP:
- case CSS_UNIT_CH:
- case CSS_UNIT_IC:
- {
- css_fixed font_size = 0;
- css_unit font_unit = CSS_UNIT_PT;
-
- assert(style != NULL);
-
- css_computed_font_size(style, &font_size, &font_unit);
-
- /* Convert to points */
- font_size = nscss_len2pt(ctx, font_size, font_unit);
-
- /* Clamp to configured minimum */
- if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
- font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
- }
-
- /* Convert to pixels (manually, to maximise precision)
- * 1in = 72pt => 1pt = (DPI/72)px */
- px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
-
- /* Scale non-em units to em. We have fixed ratios. */
- switch (unit) {
- case CSS_UNIT_EX:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
- break;
- case CSS_UNIT_CAP:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.9));
- break;
- case CSS_UNIT_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- break;
- case CSS_UNIT_IC:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(1.1));
- break;
- default: break;
- }
- }
- break;
- case CSS_UNIT_PX:
- px_per_unit = F_1;
- break;
- /* 1in = 96 CSS pixels */
- case CSS_UNIT_IN:
- px_per_unit = F_96;
- break;
- /* 1in = 2.54cm => 1cm = (DPI/2.54)px */
- case CSS_UNIT_CM:
- px_per_unit = FDIV(F_96, FLTTOFIX(2.54));
- break;
- /* 1in = 25.4mm => 1mm = (DPI/25.4)px */
- case CSS_UNIT_MM:
- px_per_unit = FDIV(F_96, FLTTOFIX(25.4));
- break;
- /* 1in = 101.6q => 1q = (DPI/101.6)px */
- case CSS_UNIT_Q:
- px_per_unit = FDIV(F_96, FLTTOFIX(101.6));
- break;
- /* 1in = 72pt => 1pt = (DPI/72)px */
- case CSS_UNIT_PT:
- px_per_unit = FDIV(F_96, F_72);
- break;
- /* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */
- case CSS_UNIT_PC:
- px_per_unit = FDIV(F_96, INTTOFIX(6));
- break;
- case CSS_UNIT_REM:
- {
- css_fixed font_size = 0;
- css_unit font_unit = CSS_UNIT_PT;
-
- assert(ctx->root_style != NULL);
-
- css_computed_font_size(ctx->root_style,
- &font_size, &font_unit);
-
- /* Convert to points */
- font_size = nscss_len2pt(ctx, font_size, font_unit);
-
- /* Clamp to configured minimum */
- if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) {
- font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
- }
-
- /* Convert to pixels (manually, to maximise precision)
- * 1in = 72pt => 1pt = (DPI/72)px */
- px_per_unit = FDIV(FMUL(font_size, F_96), F_72);
- break;
- }
- /* 1rlh = <user_font_size>pt => 1rlh = (DPI/user_font_size)px */
- case CSS_UNIT_RLH:
- px_per_unit = FDIV(F_96, FDIV(
- INTTOFIX(nsoption_int(font_size)),
- INTTOFIX(10)));
- break;
- case CSS_UNIT_VH:
- px_per_unit = FDIV(ctx->vh, F_100);
- break;
- case CSS_UNIT_VW:
- px_per_unit = FDIV(ctx->vw, F_100);
- break;
- default:
- px_per_unit = 0;
- break;
- }
-
- px_per_unit = nscss_pixels_css_to_physical(px_per_unit);
-
- /* Ensure we round px_per_unit to the nearest whole number of pixels:
- * the use of FIXTOINT() below will truncate. */
- px_per_unit += F_0_5;
-
- /* Calculate total number of pixels */
- return FMUL(length, TRUNCATEFIX(px_per_unit));
-}
diff --git a/content/handlers/css/utils.h b/content/handlers/css/utils.h
index e35a6605b..ee241e2cc 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -26,122 +26,52 @@
/** DPI of the screen, in fixed point units */
extern css_fixed nscss_screen_dpi;
-/** Medium screen density for device viewing distance. */
-extern css_fixed nscss_baseline_pixel_density;
-
-/**
- * Length conversion context data.
- */
-typedef struct nscss_len_ctx {
- /**
- * Viewport width in px.
- * Only used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- int vw;
- /**
- * Viewport height in px.
- * Only used if unit is vh, vw, vi, vb, vmin, or vmax.
- */
- int vh;
- /**
- * Computed style for the document root element.
- * May be NULL if unit is not rem, or rlh.
- */
- const css_computed_style *root_style;
-} nscss_len_ctx;
-
-/**
- * Convert an absolute CSS length to points.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] length Absolute CSS length.
- * \param[in] unit Unit of the length.
- * \return length in points
- */
-css_fixed nscss_len2pt(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit);
-
-/**
- * Convert a CSS length to pixels.
- *
- * \param[in] ctx Length conversion context.
- * \param[in] length Length to convert.
- * \param[in] unit Corresponding unit.
- * \param[in] style Computed style applying to length.
- * May be NULL if unit is not em, ex, cap, ch, or ic.
- * \return length in pixels
- */
-css_fixed nscss_len2px(
- const nscss_len_ctx *ctx,
- css_fixed length,
- css_unit unit,
- const css_computed_style *style);
-
-/**
- * Convert css pixels to physical pixels.
- *
- * \param[in] css_pixels Length in css pixels.
- * \return length in physical pixels
- */
-static inline css_fixed nscss_pixels_css_to_physical(
- css_fixed css_pixels)
-{
- return FDIV(FMUL(css_pixels, nscss_screen_dpi),
- nscss_baseline_pixel_density);
-}
-
-/**
- * Convert physical pixels to css pixels.
- *
- * \param[in] physical_pixels Length in physical pixels.
- * \return length in css pixels
- */
-static inline css_fixed nscss_pixels_physical_to_css(
- css_fixed physical_pixels)
-{
- return FDIV(FMUL(physical_pixels, nscss_baseline_pixel_density),
- nscss_screen_dpi);
-}
-
/**
* Temporary helper wrappers for for libcss computed style getter, while
- * we don't support flexbox related property values.
+ * we don't support all values of display.
*/
-
static inline uint8_t ns_computed_display(
const css_computed_style *style, bool root)
{
uint8_t value = css_computed_display(style, root);
- if (value == CSS_DISPLAY_FLEX) {
+ switch (value) {
+ case CSS_DISPLAY_GRID:
return CSS_DISPLAY_BLOCK;
- } else if (value == CSS_DISPLAY_INLINE_FLEX) {
+ case CSS_DISPLAY_INLINE_GRID:
return CSS_DISPLAY_INLINE_BLOCK;
+
+ default:
+ break;
}
return value;
}
-
+/**
+ * Temporary helper wrappers for for libcss computed style getter, while
+ * we don't support all values of display.
+ */
static inline uint8_t ns_computed_display_static(
const css_computed_style *style)
{
uint8_t value = css_computed_display_static(style);
- if (value == CSS_DISPLAY_FLEX) {
+ switch (value) {
+ case CSS_DISPLAY_GRID:
return CSS_DISPLAY_BLOCK;
- } else if (value == CSS_DISPLAY_INLINE_FLEX) {
+ case CSS_DISPLAY_INLINE_GRID:
return CSS_DISPLAY_INLINE_BLOCK;
+
+ default:
+ break;
}
return value;
}
-
static inline uint8_t ns_computed_min_height(
const css_computed_style *style,
css_fixed *length, css_unit *unit)