summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2021-03-29 10:45:59 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2021-05-30 11:52:33 +0100
commitfa64d91d12c94c9aa230cd231b1d2e16054b41f2 (patch)
treebb25197831ca661cec35c69940c5b7c08eaaca36 /content
parent638a408ddee7329f8de2a6e550b7fcc2a4baa4a3 (diff)
downloadnetsurf-master.tar.gz
netsurf-master.tar.bz2
Switch to new libcss API for unit conversion.HEADmaster
Diffstat (limited to 'content')
-rw-r--r--content/handlers/css/Makefile2
-rw-r--r--content/handlers/css/css.c3
-rw-r--r--content/handlers/css/select.c137
-rw-r--r--content/handlers/css/select.h5
-rw-r--r--content/handlers/css/utils.c242
-rw-r--r--content/handlers/css/utils.h79
-rw-r--r--content/handlers/html/box_construct.c3
-rw-r--r--content/handlers/html/box_inspect.c44
-rw-r--r--content/handlers/html/box_inspect.h6
-rw-r--r--content/handlers/html/box_normalise.c22
-rw-r--r--content/handlers/html/font.c5
-rw-r--r--content/handlers/html/font.h4
-rw-r--r--content/handlers/html/form.c6
-rw-r--r--content/handlers/html/html.c40
-rw-r--r--content/handlers/html/interaction.c8
-rw-r--r--content/handlers/html/layout.c430
-rw-r--r--content/handlers/html/object.c14
-rw-r--r--content/handlers/html/private.h5
-rw-r--r--content/handlers/html/redraw.c72
-rw-r--r--content/handlers/html/table.c226
-rw-r--r--content/handlers/html/table.h8
-rw-r--r--content/handlers/html/textselection.c18
22 files changed, 519 insertions, 860 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/select.c b/content/handlers/css/select.c
index cfefb2a08..6dc1d9b6f 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,115 +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_CH) {
- 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_CH:
- /* Width of '0'. 1ch = 0.4em in NetSurf. */
- size->data.length.value = FMUL(size->data.length.value,
- FLTTOFIX(0.4));
- 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);
- }
- }
-
- size->status = CSS_FONT_SIZE_DIMENSION;
-
- return CSS_OK;
-}
-
/******************************************************************************
* Style selection callbacks *
******************************************************************************/
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 24ba44387..000000000
--- a/content/handlers/css/utils.c
+++ /dev/null
@@ -1,242 +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_CH &&
- unit != CSS_UNIT_REM);
-
- 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_CH:
- {
- 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_CH:
- px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.4));
- 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;
- }
- 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..541677a3a 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -26,85 +26,6 @@
/** 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.
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c
index 7bfc35e44..12d9df87c 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -282,7 +282,8 @@ box_get_style(html_content *c,
ctx.parent_style = parent_style;
/* Select style for element */
- styles = nscss_get_style(&ctx, n, &c->media, inline_style);
+ styles = nscss_get_style(&ctx, n, &c->media, &c->unit_len_ctx,
+ inline_style);
/* No longer need inline style */
if (inline_style != NULL)
diff --git a/content/handlers/html/box_inspect.c b/content/handlers/html/box_inspect.c
index df9a1b4e2..b4b13940d 100644
--- a/content/handlers/html/box_inspect.c
+++ b/content/handlers/html/box_inspect.c
@@ -56,7 +56,7 @@ enum box_walk_dir {
/**
* Determine if a point lies within a box.
*
- * \param[in] len_ctx CSS length conversion context to use.
+ * \param[in] unit_len_ctx CSS length conversion context to use.
* \param[in] box Box to consider
* \param[in] x Coordinate relative to box
* \param[in] y Coordinate relative to box
@@ -71,7 +71,7 @@ enum box_walk_dir {
* This is a helper function for box_at_point().
*/
static bool
-box_contains_point(const nscss_len_ctx *len_ctx,
+box_contains_point(const css_unit_ctx *unit_len_ctx,
const struct box *box,
int x,
int y,
@@ -101,30 +101,34 @@ box_contains_point(const nscss_len_ctx *len_ctx,
/* Adjust rect to css clip region */
if (css_rect.left_auto == false) {
- r.x0 += FIXTOINT(nscss_len2px(len_ctx,
- css_rect.left,
- css_rect.lunit,
- box->style));
+ r.x0 += FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.left,
+ css_rect.lunit));
}
if (css_rect.top_auto == false) {
- r.y0 += FIXTOINT(nscss_len2px(len_ctx,
- css_rect.top,
- css_rect.tunit,
- box->style));
+ r.y0 += FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.top,
+ css_rect.tunit));
}
if (css_rect.right_auto == false) {
r.x1 = box->border[LEFT].width +
- FIXTOINT(nscss_len2px(len_ctx,
- css_rect.right,
- css_rect.runit,
- box->style));
+ FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.right,
+ css_rect.runit));
}
if (css_rect.bottom_auto == false) {
r.y1 = box->border[TOP].width +
- FIXTOINT(nscss_len2px(len_ctx,
- css_rect.bottom,
- css_rect.bunit,
- box->style));
+ FIXTOINT(css_unit_len2device_px(
+ box->style,
+ unit_len_ctx,
+ css_rect.bottom,
+ css_rect.bunit));
}
/* Test if point is in clipped box */
@@ -575,7 +579,7 @@ void box_bounds(struct box *box, struct rect *r)
/* Exported function documented in html/box.h */
struct box *
-box_at_point(const nscss_len_ctx *len_ctx,
+box_at_point(const css_unit_ctx *unit_len_ctx,
struct box *box,
const int x, const int y,
int *box_x, int *box_y)
@@ -587,7 +591,7 @@ box_at_point(const nscss_len_ctx *len_ctx,
skip_children = false;
while ((box = box_next_xy(box, box_x, box_y, skip_children))) {
- if (box_contains_point(len_ctx, box, x - *box_x, y - *box_y,
+ if (box_contains_point(unit_len_ctx, box, x - *box_x, y - *box_y,
&physically)) {
*box_x -= scrollbar_get_offset(box->scroll_x);
*box_y -= scrollbar_get_offset(box->scroll_y);
diff --git a/content/handlers/html/box_inspect.h b/content/handlers/html/box_inspect.h
index d50b84813..b9161f148 100644
--- a/content/handlers/html/box_inspect.h
+++ b/content/handlers/html/box_inspect.h
@@ -46,7 +46,7 @@ void box_bounds(struct box *box, struct rect *r);
/**
* Find the boxes at a point.
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param box box to search children of
* \param x point to find, in global document coordinates
* \param y point to find, in global document coordinates
@@ -62,12 +62,12 @@ void box_bounds(struct box *box, struct rect *r);
* struct box *box = top_of_document_to_search;
* int box_x = 0, box_y = 0;
*
- * while ((box = box_at_point(len_ctx, box, x, y, &box_x, &box_y))) {
+ * while ((box = box_at_point(unit_len_ctx, box, x, y, &box_x, &box_y))) {
* // process box
* }
* \endcode
*/
-struct box *box_at_point(const nscss_len_ctx *len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
+struct box *box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
/**
diff --git a/content/handlers/html/box_normalise.c b/content/handlers/html/box_normalise.c
index b7032da55..1b6a345d5 100644
--- a/content/handlers/html/box_normalise.c
+++ b/content/handlers/html/box_normalise.c
@@ -190,7 +190,8 @@ box_normalise_table_row(struct box *row,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row->style);
if (style == NULL)
return false;
@@ -326,7 +327,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL)
return false;
@@ -402,7 +404,8 @@ box_normalise_table_row_group(struct box *row_group,
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL) {
return false;
}
@@ -533,6 +536,7 @@ box_normalise_table_spans(struct box *table,
ctx.universal = c->universal;
style = nscss_get_blank_style(&ctx,
+ &c->unit_len_ctx,
table_row->style);
if (style == NULL)
return false;
@@ -657,7 +661,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, table->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@@ -744,7 +749,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, table->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ table->style);
if (style == NULL) {
free(col_info.spans);
return false;
@@ -759,7 +765,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c)
}
row_group->type = BOX_TABLE_ROW_GROUP;
- style = nscss_get_blank_style(&ctx, row_group->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ row_group->style);
if (style == NULL) {
box_free(row_group);
free(col_info.spans);
@@ -948,7 +955,8 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c)
ctx.base_url = c->base_url;
ctx.universal = c->universal;
- style = nscss_get_blank_style(&ctx, block->style);
+ style = nscss_get_blank_style(&ctx, &c->unit_len_ctx,
+ block->style);
if (style == NULL)
return false;
diff --git a/content/handlers/html/font.c b/content/handlers/html/font.c
index 7ebe16825..4a64759d7 100644
--- a/content/handlers/html/font.c
+++ b/content/handlers/html/font.c
@@ -133,7 +133,7 @@ static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
/* exported function documented in html/font.h */
void font_plot_style_from_css(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
plot_font_style_t *fstyle)
{
@@ -147,7 +147,8 @@ void font_plot_style_from_css(
fstyle->families = families;
css_computed_font_size(css, &length, &unit);
- fstyle->size = FIXTOINT(FMUL(nscss_len2pt(len_ctx, length, unit),
+ fstyle->size = FIXTOINT(FMUL(css_unit_font_size_len2pt(css,
+ unit_len_ctx, length, unit),
INTTOFIX(PLOT_STYLE_SCALE)));
/* Clamp font size to configured minimum */
diff --git a/content/handlers/html/font.h b/content/handlers/html/font.h
index 5f69ee7d3..26f5bf289 100644
--- a/content/handlers/html/font.h
+++ b/content/handlers/html/font.h
@@ -32,11 +32,11 @@ struct plot_font_style;
/**
* Populate a font style using data from a computed CSS style
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param css Computed style to consider
* \param fstyle Font style to populate
*/
-void font_plot_style_from_css(const nscss_len_ctx *len_ctx,
+void font_plot_style_from_css(const css_unit_ctx *unit_len_ctx,
const css_computed_style *css,
struct plot_font_style *fstyle);
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index 01e624417..97ec19518 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -1594,12 +1594,12 @@ form_open_select_menu(void *client_data,
box->border[RIGHT].width + box->padding[RIGHT] +
box->border[LEFT].width + box->padding[LEFT];
- font_plot_style_from_css(&html->len_ctx, control->box->style,
- &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx,
+ control->box->style, &fstyle);
menu->f_size = fstyle.size;
menu->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
- FMUL(nscss_screen_dpi,
+ FMUL(html->unit_len_ctx.device_dpi,
INTTOFIX(fstyle.size / PLOT_STYLE_SCALE)))),
F_72));
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 5b74e42da..c6a28724c 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -305,6 +305,9 @@ html_proceed_to_done(html_content *html)
static void html_get_dimensions(html_content *htmlc)
{
+ css_fixed device_dpi = nscss_screen_dpi;
+ unsigned f_size;
+ unsigned f_min;
unsigned w;
unsigned h;
union content_msg_data msg_data = {
@@ -316,13 +319,22 @@ static void html_get_dimensions(html_content *htmlc)
content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
- htmlc->media.width = nscss_pixels_physical_to_css(INTTOFIX(w));
- htmlc->media.height = nscss_pixels_physical_to_css(INTTOFIX(h));
- htmlc->media.client_font_size =
- FDIV(INTTOFIX(nsoption_int(font_size)), F_10);
- htmlc->media.client_line_height =
- FMUL(nscss_len2px(NULL, htmlc->media.client_font_size,
- CSS_UNIT_PT, NULL), FLTTOFIX(1.33));
+
+ w = css_unit_device2css_px(INTTOFIX(w), device_dpi);
+ h = css_unit_device2css_px(INTTOFIX(h), device_dpi);
+
+ htmlc->media.width = w;
+ htmlc->media.height = h;
+ htmlc->unit_len_ctx.viewport_width = w;
+ htmlc->unit_len_ctx.viewport_height = h;
+ htmlc->unit_len_ctx.device_dpi = device_dpi;
+
+ /** \todo Change nsoption font sizes to px. */
+ f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72);
+ f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72);
+
+ htmlc->unit_len_ctx.font_size_default = f_size;
+ htmlc->unit_len_ctx.font_size_minimum = f_min;
}
/* exported function documented in html/html_internal.h */
@@ -1035,9 +1047,11 @@ static void html_reformat(struct content *c, int width, int height)
htmlc->reflowing = true;
- htmlc->len_ctx.vw = nscss_pixels_physical_to_css(INTTOFIX(width));
- htmlc->len_ctx.vh = nscss_pixels_physical_to_css(INTTOFIX(height));
- htmlc->len_ctx.root_style = htmlc->layout->style;
+ htmlc->unit_len_ctx.viewport_width = css_unit_device2css_px(
+ INTTOFIX(width), htmlc->unit_len_ctx.device_dpi);
+ htmlc->unit_len_ctx.viewport_height = css_unit_device2css_px(
+ INTTOFIX(height), htmlc->unit_len_ctx.device_dpi);
+ htmlc->unit_len_ctx.root_style = htmlc->layout->style;
layout_document(htmlc, width, height);
layout = htmlc->layout;
@@ -1427,7 +1441,7 @@ html_get_contextual_content(struct content *c, int x, int y,
struct box *next;
int box_x = 0, box_y = 0;
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@@ -1508,7 +1522,7 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
/* TODO: invert order; visit deepest box first */
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
@@ -1657,7 +1671,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
int box_x = 0, box_y = 0;
/* Scan box tree for boxes that can handle drop */
- while ((next = box_at_point(&html->len_ctx, box, x, y,
+ while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
&box_x, &box_y)) != NULL) {
box = next;
diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c
index 90e7b7626..026ef1ee7 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -211,7 +211,7 @@ static size_t html_selection_drag_end(struct html_content *html,
if (box) {
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle, box->text, box->length,
dx, &idx, &pixel_offset);
@@ -424,7 +424,7 @@ mouse_action_drag_selection(html_content *html,
box = box_pick_text_box(html, x, y, dir, &dx, &dy);
if (box != NULL) {
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
guit->layout->position(&fstyle,
box->text,
@@ -805,7 +805,7 @@ get_mouse_action_node(html_content *html,
next_box:
/* iterate to next box */
- box = box_at_point(&html->len_ctx, box, x, y, &box_x, &box_y);
+ box = box_at_point(&html->unit_len_ctx, box, x, y, &box_x, &box_y);
} while (box != NULL);
/* use of box_x, box_y, or content below this point is probably a
@@ -1209,7 +1209,7 @@ default_mouse_action(html_content *html,
size_t idx;
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx,
+ font_plot_style_from_css(&html->unit_len_ctx,
mas->text.box->style,
&fstyle);
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index c8c0127ad..c06fdf690 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -133,7 +133,6 @@ static void layout_minmax_block(
const struct gui_layout_table *font_func,
const html_content *content);
-
/**
* Compute the size of replaced boxes with auto dimensions, according to
* content.
@@ -246,7 +245,7 @@ layout_get_object_dimensions(struct box *box,
* \return length of indent
*/
static int layout_text_indent(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *style, int width)
{
css_fixed value = 0;
@@ -257,7 +256,8 @@ static int layout_text_indent(
if (unit == CSS_UNIT_PCT) {
return FPCT_OF_INT_TOINT(value, width);
} else {
- return FIXTOINT(nscss_len2px(len_ctx, value, unit, style));
+ return FIXTOINT(css_unit_len2device_px(style, unit_len_ctx,
+ value, unit));
}
}
@@ -265,7 +265,7 @@ static int layout_text_indent(
/**
* Determine width of margin, borders, and padding on one side of a box.
*
- * \param len_ctx CSS length conversion context for document
+ * \param unit_len_ctx CSS length conversion context for document
* \param style style to measure
* \param side side of box to measure
* \param margin whether margin width is required
@@ -275,7 +275,7 @@ static int layout_text_indent(
* \param frac increased by sum of fractional margin and padding
*/
static void
-calculate_mbp_width(const nscss_len_ctx *len_ctx,
+calculate_mbp_width(const css_unit_ctx *unit_len_ctx,
const css_computed_style *style,
unsigned int side,
bool margin,
@@ -298,8 +298,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
if (unit == CSS_UNIT_PCT) {
*frac += FIXTOINT(FDIV(value, F_100));
} else {
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
}
@@ -310,8 +311,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
CSS_BORDER_STYLE_NONE) {
border_width_funcs[side](style, &value, &unit);
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
@@ -321,8 +323,9 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
if (unit == CSS_UNIT_PCT) {
*frac += FIXTOINT(FDIV(value, F_100));
} else {
- *fixed += FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *fixed += FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
}
@@ -356,7 +359,7 @@ static void layout_minmax_table(struct box *table,
if (table->max_width != UNKNOWN_MAX_WIDTH)
return;
- if (table_calculate_column_types(&content->len_ctx, table) == false) {
+ if (table_calculate_column_types(&content->unit_len_ctx, table) == false) {
NSLOG(netsurf, WARNING,
"Could not establish table column types.");
return;
@@ -379,8 +382,10 @@ static void layout_minmax_table(struct box *table,
css_computed_border_spacing(table->style, &h, &hu, &v, &vu);
- border_spacing_h = FIXTOINT(nscss_len2px(&content->len_ctx,
- h, hu, table->style));
+ border_spacing_h = FIXTOINT(css_unit_len2device_px(
+ table->style,
+ &content->unit_len_ctx,
+ h, hu));
}
/* 1st pass: consider cells with colspan 1 only */
@@ -485,8 +490,10 @@ static void layout_minmax_table(struct box *table,
/* fixed width takes priority, unless it is too narrow */
wtype = css_computed_width(table->style, &value, &unit);
if (wtype == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
- int width = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, table->style));
+ int width = FIXTOINT(css_unit_len2device_px(
+ table->style,
+ &content->unit_len_ctx,
+ value, unit));
if (table_min < width)
table_min = width;
if (table_max < width)
@@ -494,10 +501,10 @@ static void layout_minmax_table(struct box *table,
}
/* add margins, border, padding to min, max widths */
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
table->style, LEFT, true, true, true,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
table->style, RIGHT, true, true, true,
&extra_fixed, &extra_frac);
if (extra_fixed < 0)
@@ -622,17 +629,17 @@ layout_minmax_line(struct box *first,
}
assert(b->style);
- font_plot_style_from_css(&content->len_ctx, b->style, &fstyle);
+ font_plot_style_from_css(&content->unit_len_ctx, b->style, &fstyle);
if (b->type == BOX_INLINE && !b->object &&
!(b->flags & REPLACE_DIM) &&
!(b->flags & IFRAME)) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT, true, true, true,
&fixed, &frac);
if (!b->inline_end)
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -642,7 +649,7 @@ layout_minmax_line(struct box *first,
/* \todo update min width, consider fractional extra */
} else if (b->type == BOX_INLINE_END) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->inline_end->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -760,16 +767,18 @@ layout_minmax_line(struct box *first,
if (unit == CSS_UNIT_PCT) {
width = AUTO;
} else {
- width = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, b->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ value, unit));
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
fixed = frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT,
false, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT,
false, true, true,
&fixed, &frac);
@@ -787,8 +796,10 @@ layout_minmax_line(struct box *first,
/* height */
htype = css_computed_height(b->style, &value, &unit);
if (htype == CSS_HEIGHT_SET) {
- height = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, b->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ value, unit));
} else {
height = AUTO;
}
@@ -804,20 +815,20 @@ layout_minmax_line(struct box *first,
fixed = frac = 0;
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, false, false,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, false, false,
&fixed, &frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -831,20 +842,20 @@ layout_minmax_line(struct box *first,
fixed = frac = 0;
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, false, false,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, false, false,
&fixed, &frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, LEFT,
true, true, true,
&fixed, &frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
b->style, RIGHT,
true, true, true,
&fixed, &frac);
@@ -856,10 +867,10 @@ layout_minmax_line(struct box *first,
} else {
/* form control with no object */
if (width == AUTO)
- width = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- INTTOFIX(1), CSS_UNIT_EM,
- b->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx,
+ INTTOFIX(1), CSS_UNIT_EM));
}
if (min < width && !box_has_percentage_max_width(b))
@@ -873,7 +884,7 @@ layout_minmax_line(struct box *first,
if (first_line) {
/* todo: handle percentage values properly */
/* todo: handle text-indent interaction with floats */
- int text_indent = layout_text_indent(&content->len_ctx,
+ int text_indent = layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, 100);
min = (min + text_indent < 0) ? 0 : min + text_indent;
max = (max + text_indent < 0) ? 0 : max + text_indent;
@@ -1006,8 +1017,8 @@ static void layout_minmax_block(
css_fixed size = INTTOFIX(10);
css_unit unit = CSS_UNIT_EM;
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- size, unit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, size, unit));
block->flags |= HAS_HEIGHT;
}
@@ -1020,8 +1031,8 @@ static void layout_minmax_block(
/* form checkbox or radio button
* if width is AUTO, set it to 1em */
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- size, unit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, size, unit));
block->flags |= HAS_HEIGHT;
}
@@ -1104,16 +1115,16 @@ static void layout_minmax_block(
/* fixed width takes priority */
if (block->type != BOX_TABLE_CELL && wtype == CSS_WIDTH_SET &&
wunit != CSS_UNIT_PCT) {
- min = max = FIXTOINT(nscss_len2px(&content->len_ctx,
- width, wunit, block->style));
+ min = max = FIXTOINT(css_unit_len2device_px(block->style,
+ &content->unit_len_ctx, width, wunit));
if (bs == CSS_BOX_SIZING_BORDER_BOX) {
int border_box_fixed = 0;
float border_box_frac = 0;
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT,
false, true, true,
&border_box_fixed, &border_box_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT,
false, true, true,
&border_box_fixed, &border_box_frac);
@@ -1134,17 +1145,17 @@ static void layout_minmax_block(
* and paddings are wrong. */
if (bs == CSS_BOX_SIZING_BORDER_BOX && wtype == CSS_WIDTH_SET) {
/* Border and padding included in width, so just get margin */
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT, true, false, false,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT, true, false, false,
&extra_fixed, &extra_frac);
} else {
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, LEFT, true, true, true,
&extra_fixed, &extra_frac);
- calculate_mbp_width(&content->len_ctx,
+ calculate_mbp_width(&content->unit_len_ctx,
block->style, RIGHT, true, true, true,
&extra_fixed, &extra_frac);
}
@@ -1175,7 +1186,7 @@ static void layout_minmax_block(
*
* This turns the specified dimension into a content-box dimension.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box gadget to adjust dimensions of
* \param available_width width of containing block
* \param setwidth set true if the dimension to be tweaked is a width,
@@ -1185,7 +1196,7 @@ static void layout_minmax_block(
* gadget properties.
*/
static void layout_handle_box_sizing(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int available_width,
bool setwidth,
@@ -1202,10 +1213,10 @@ static void layout_handle_box_sizing(
int fixed = 0;
float frac = 0;
- calculate_mbp_width(len_ctx, box->style,
+ calculate_mbp_width(unit_len_ctx, box->style,
setwidth ? LEFT : TOP,
false, true, true, &fixed, &frac);
- calculate_mbp_width(len_ctx, box->style,
+ calculate_mbp_width(unit_len_ctx, box->style,
setwidth ? RIGHT : BOTTOM,
false, true, true, &fixed, &frac);
orig -= frac * available_width + fixed;
@@ -1217,7 +1228,7 @@ static void layout_handle_box_sizing(
/**
* Calculate width, height, and thickness of margins, paddings, and borders.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param available_width width of containing block
* \param viewport_height height of viewport in pixels or -ve if unknown
* \param box current box
@@ -1234,7 +1245,7 @@ static void layout_handle_box_sizing(
* \param border filled with border widths, may be NULL
*/
static void
-layout_find_dimensions(const nscss_len_ctx *len_ctx,
+layout_find_dimensions(const css_unit_ctx *unit_len_ctx,
int available_width,
int viewport_height,
struct box *box,
@@ -1264,15 +1275,16 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*width = FPCT_OF_INT_TOINT(
value, available_width);
} else {
- *width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
*width = AUTO;
}
if (*width != AUTO) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, width);
}
}
@@ -1352,15 +1364,16 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*height = AUTO;
}
} else {
- *height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
*height = AUTO;
}
if (*height != AUTO) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
false, height);
}
}
@@ -1377,8 +1390,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*max_width = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- *max_width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *max_width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1386,7 +1400,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
}
if (*max_width != -1) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, max_width);
}
}
@@ -1403,8 +1417,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
*min_width = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- *min_width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *min_width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1412,7 +1427,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
}
if (*min_width != 0) {
- layout_handle_box_sizing(len_ctx, box, available_width,
+ layout_handle_box_sizing(unit_len_ctx, box, available_width,
true, min_width);
}
}
@@ -1429,8 +1444,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* TODO: handle percentage */
*max_height = -1;
} else {
- *max_height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *max_height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1450,8 +1466,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* TODO: handle percentage */
*min_height = 0;
} else {
- *min_height = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ *min_height = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
/* Inadmissible */
@@ -1472,9 +1489,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
margin[i] = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- margin[i] = FIXTOINT(nscss_len2px(
- len_ctx,
- value, unit, style));
+ margin[i] = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
} else {
margin[i] = AUTO;
@@ -1491,8 +1508,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
padding[i] = FPCT_OF_INT_TOINT(value,
available_width);
} else {
- padding[i] = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ padding[i] = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
}
}
@@ -1515,8 +1533,9 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/* spec unclear: following Mozilla */
border[i].width = 0;
else
- border[i].width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, style));
+ border[i].width = FIXTOINT(css_unit_len2device_px(
+ style, unit_len_ctx,
+ value, unit));
/* Special case for border-collapse: make all borders
* on table/table-row-group/table-row zero width. */
@@ -1534,7 +1553,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
/**
* Find next block that current margin collapses to.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to start tree-order search from (top margin is included)
* \param block box responsible for current block fromatting context
* \param viewport_height height of viewport in px
@@ -1543,7 +1562,7 @@ layout_find_dimensions(const nscss_len_ctx *len_ctx,
* \return next box that current margin collapses to, or NULL if none.
*/
static struct box*
-layout_next_margin_block(const nscss_len_ctx *len_ctx,
+layout_next_margin_block(const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *block,
int viewport_height,
@@ -1563,7 +1582,7 @@ layout_next_margin_block(const nscss_len_ctx *len_ctx,
/* Get margins */
if (box->style) {
- layout_find_dimensions(len_ctx,
+ layout_find_dimensions(unit_len_ctx,
box->parent->width,
viewport_height, box,
box->style,
@@ -1638,7 +1657,7 @@ layout_next_margin_block(const nscss_len_ctx *len_ctx,
/* Get margins */
if (box->style) {
- layout_find_dimensions(len_ctx,
+ layout_find_dimensions(unit_len_ctx,
box->parent->width,
viewport_height, box,
box->style,
@@ -1875,7 +1894,7 @@ layout_solve_width(struct box *box,
* Compute dimensions of box, margins, paddings, and borders for a block-level
* element.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param available_width Max width available in pixels
* \param viewport_height Height of viewport in pixels or -ve if unknown
* \param lm min left margin required to avoid floats in px.
@@ -1888,7 +1907,7 @@ layout_solve_width(struct box *box,
* See CSS 2.1 10.3.3, 10.3.4, 10.6.2, and 10.6.3.
*/
static void
-layout_block_find_dimensions(const nscss_len_ctx *len_ctx,
+layout_block_find_dimensions(const css_unit_ctx *unit_len_ctx,
int available_width,
int viewport_height,
int lm,
@@ -1902,7 +1921,7 @@ layout_block_find_dimensions(const nscss_len_ctx *len_ctx,
struct box_border *border = box->border;
const css_computed_style *style = box->style;
- layout_find_dimensions(len_ctx, available_width, viewport_height, box,
+ layout_find_dimensions(unit_len_ctx, available_width, viewport_height, box,
style, &width, &height, &max_width, &min_width,
&max_height, &min_height, margin, padding, border);
@@ -2056,7 +2075,7 @@ static bool layout_table(struct box *table, int available_width,
memcpy(col, table->col, sizeof(col[0]) * columns);
/* find margins, paddings, and borders for table and cells */
- layout_find_dimensions(&content->len_ctx, available_width, -1, table,
+ layout_find_dimensions(&content->unit_len_ctx, available_width, -1, table,
style, 0, 0, 0, 0, 0, 0, table->margin, table->padding,
table->border);
for (row_group = table->children; row_group;
@@ -2068,8 +2087,8 @@ static bool layout_table(struct box *table, int available_width,
assert(c->style);
table_used_border_for_cell(
- &content->len_ctx, c);
- layout_find_dimensions(&content->len_ctx,
+ &content->unit_len_ctx, c);
+ layout_find_dimensions(&content->unit_len_ctx,
available_width, -1, c,
c->style, 0, 0, 0, 0, 0, 0,
0, c->padding, c->border);
@@ -2099,10 +2118,10 @@ static bool layout_table(struct box *table, int available_width,
css_computed_border_spacing(style, &h, &hu, &v, &vu);
- border_spacing_h = FIXTOINT(nscss_len2px(&content->len_ctx,
- h, hu, style));
- border_spacing_v = FIXTOINT(nscss_len2px(&content->len_ctx,
- v, vu, style));
+ border_spacing_h = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx, h, hu));
+ border_spacing_v = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx, v, vu));
}
/* find specified table width, or available width if auto-width */
@@ -2112,8 +2131,9 @@ static bool layout_table(struct box *table, int available_width,
table_width = FPCT_OF_INT_TOINT(value, available_width);
} else {
table_width =
- FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, style));
+ FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx,
+ value, unit));
}
/* specified width includes border */
@@ -2191,8 +2211,9 @@ static bool layout_table(struct box *table, int available_width,
} else {
/* This is the minimum height for the table
* (see 17.5.3) */
- min_height = FIXTOINT(nscss_len2px(&content->len_ctx,
- value, unit, style));
+ min_height = FIXTOINT(css_unit_len2device_px(
+ style, &content->unit_len_ctx,
+ value, unit));
}
}
@@ -2382,9 +2403,10 @@ static bool layout_table(struct box *table, int available_width,
htype = css_computed_height(row->style, &value, &unit);
if (htype == CSS_HEIGHT_SET && unit != CSS_UNIT_PCT) {
- row_height = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- value, unit, row->style));
+ row_height = FIXTOINT(css_unit_len2device_px(
+ row->style,
+ &content->unit_len_ctx,
+ value, unit));
}
for (c = row->children; c; c = c->next) {
assert(c->style);
@@ -2421,9 +2443,10 @@ static bool layout_table(struct box *table, int available_width,
/* some sites use height="1" or similar
* to attempt to make cells as small as
* possible, so treat it as a minimum */
- int h = FIXTOINT(nscss_len2px(
- &content->len_ctx,
- value, unit, c->style));
+ int h = FIXTOINT(css_unit_len2device_px(
+ c->style,
+ &content->unit_len_ctx,
+ value, unit));
if (c->height < h)
c->height = h;
}
@@ -2567,14 +2590,14 @@ static bool layout_table(struct box *table, int available_width,
/**
* Manimpulate box height according to CSS min-height and max-height properties
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param box block to modify with any min-height or max-height
* \param container containing block for absolutely positioned elements, or
* NULL for non absolutely positioned elements.
* \return whether the height has been changed
*/
static bool layout_apply_minmax_height(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *container)
{
@@ -2635,8 +2658,9 @@ static bool layout_apply_minmax_height(
}
}
} else {
- h = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ h = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
if (h < box->height) {
box->height = h;
updated = true;
@@ -2665,8 +2689,9 @@ static bool layout_apply_minmax_height(
}
}
} else {
- h = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ h = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
if (h > box->height) {
box->height = h;
updated = true;
@@ -2834,7 +2859,7 @@ layout_text_box_split(html_content *content,
* Compute dimensions of box, margins, paddings, and borders for a floating
* element using shrink-to-fit. Also used for inline-blocks.
*
- * \param len_ctx CSS length conversion context for document.
+ * \param unit_len_ctx CSS length conversion context for document.
* \param available_width Max width available in pixels
* \param style Box's style
* \param box Box for which to find dimensions
@@ -2843,7 +2868,7 @@ layout_text_box_split(html_content *content,
*/
static void
layout_float_find_dimensions(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
int available_width,
const css_computed_style *style,
struct box *box)
@@ -2863,7 +2888,7 @@ layout_float_find_dimensions(
overflow_y == CSS_OVERFLOW_AUTO) ?
SCROLLBAR_WIDTH : 0;
- layout_find_dimensions(len_ctx, available_width, -1, box, style,
+ layout_find_dimensions(unit_len_ctx, available_width, -1, box, style,
&width, &height, &max_width, &min_width,
&max_height, &min_height, margin, padding, border);
@@ -2899,26 +2924,30 @@ layout_float_find_dimensions(
box->gadget->type == GADGET_FILE) {
if (width == AUTO) {
size = INTTOFIX(10);
- width = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
if (box->gadget->type == GADGET_FILE &&
height == AUTO) {
size = FLTTOFIX(1.5);
- height = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
}
if (box->gadget->type == GADGET_TEXTAREA) {
if (width == AUTO) {
size = INTTOFIX(10);
- width = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ width = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
if (height == AUTO) {
size = INTTOFIX(4);
- height = FIXTOINT(nscss_len2px(len_ctx,
- size, unit, box->style));
+ height = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ size, unit));
}
}
} else if (width == AUTO) {
@@ -2939,9 +2968,9 @@ layout_float_find_dimensions(
* mbp as was used in layout_minmax_block() */
int fixed = 0;
float frac = 0;
- calculate_mbp_width(len_ctx, box->style, LEFT,
+ calculate_mbp_width(unit_len_ctx, box->style, LEFT,
true, true, true, &fixed, &frac);
- calculate_mbp_width(len_ctx, box->style, RIGHT,
+ calculate_mbp_width(unit_len_ctx, box->style, RIGHT,
true, true, true, &fixed, &frac);
if (fixed < 0)
fixed = 0;
@@ -2980,7 +3009,7 @@ static bool layout_float(struct box *b, int width, html_content *content)
{
assert(b->type == BOX_TABLE || b->type == BOX_BLOCK ||
b->type == BOX_INLINE_BLOCK);
- layout_float_find_dimensions(&content->len_ctx, width, b->style, b);
+ layout_float_find_dimensions(&content->unit_len_ctx, width, b->style, b);
if (b->type == BOX_TABLE) {
if (!layout_table(b, width, content))
return false;
@@ -3053,7 +3082,7 @@ place_float_below(struct box *c, int width, int cx, int y, struct box *cont)
* Calculate line height from a style.
*/
static int line_height(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const css_computed_style *style)
{
enum css_line_height_e lhtype;
@@ -3072,16 +3101,16 @@ static int line_height(
if (lhtype == CSS_LINE_HEIGHT_NUMBER ||
lhunit == CSS_UNIT_PCT) {
- line_height = nscss_len2px(len_ctx,
- lhvalue, CSS_UNIT_EM, style);
+ line_height = css_unit_len2device_px(style, unit_len_ctx,
+ lhvalue, CSS_UNIT_EM);
if (lhtype != CSS_LINE_HEIGHT_NUMBER)
line_height = FDIV(line_height, F_100);
} else {
assert(lhunit != CSS_UNIT_PCT);
- line_height = nscss_len2px(len_ctx,
- lhvalue, lhunit, style);
+ line_height = css_unit_len2device_px(style, unit_len_ctx,
+ lhvalue, lhunit);
}
return FIXTOINT(line_height);
@@ -3153,7 +3182,7 @@ layout_line(struct box *first,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(&content->len_ctx,
+ x0 += layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, *width);
if (x1 < x0)
@@ -3163,7 +3192,7 @@ layout_line(struct box *first,
* this is the line-height if there are text children and also in the
* case of an initially empty text input */
if (has_text_children || first->parent->parent->gadget)
- used_height = height = line_height(&content->len_ctx,
+ used_height = height = line_height(&content->unit_len_ctx,
first->parent->parent->style);
else
/* inline containers with no text are usually for layout and
@@ -3203,7 +3232,7 @@ layout_line(struct box *first,
continue;
assert(b->style != NULL);
- font_plot_style_from_css(&content->len_ctx, b->style, &fstyle);
+ font_plot_style_from_css(&content->unit_len_ctx, b->style, &fstyle);
x += space_after;
@@ -3227,7 +3256,7 @@ layout_line(struct box *first,
if (b->type == BOX_INLINE) {
/* calculate borders, margins, and padding */
- layout_find_dimensions(&content->len_ctx,
+ layout_find_dimensions(&content->unit_len_ctx,
*width, -1, b, b->style, 0, 0, 0, 0,
0, 0, b->margin, b->padding, b->border);
for (i = 0; i != 4; i++)
@@ -3262,7 +3291,7 @@ layout_line(struct box *first,
if (!b->object && !(b->flags & IFRAME) && !b->gadget &&
!(b->flags & REPLACE_DIM)) {
/* inline non-replaced, 10.3.1 and 10.6.1 */
- b->height = line_height(&content->len_ctx,
+ b->height = line_height(&content->unit_len_ctx,
b->style ? b->style :
b->parent->parent->style);
if (height < b->height)
@@ -3333,7 +3362,7 @@ layout_line(struct box *first,
/* inline replaced, 10.3.2 and 10.6.2 */
assert(b->style);
- layout_find_dimensions(&content->len_ctx,
+ layout_find_dimensions(&content->unit_len_ctx,
*width, -1, b, b->style,
&b->width, &b->height,
&max_width, &min_width,
@@ -3356,13 +3385,15 @@ layout_line(struct box *first,
} else {
/* form control with no object */
if (b->width == AUTO)
- b->width = FIXTOINT(nscss_len2px(
- &content->len_ctx, INTTOFIX(1),
- CSS_UNIT_EM, b->style));
+ b->width = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx, INTTOFIX(1),
+ CSS_UNIT_EM));
if (b->height == AUTO)
- b->height = FIXTOINT(nscss_len2px(
- &content->len_ctx, INTTOFIX(1),
- CSS_UNIT_EM, b->style));
+ b->height = FIXTOINT(css_unit_len2device_px(
+ b->style,
+ &content->unit_len_ctx, INTTOFIX(1),
+ CSS_UNIT_EM));
}
/* Reformat object to new box size */
@@ -3395,7 +3426,7 @@ layout_line(struct box *first,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(&content->len_ctx,
+ x0 += layout_text_indent(&content->unit_len_ctx,
first->parent->parent->style, *width);
if (x1 < x0)
@@ -3454,7 +3485,7 @@ layout_line(struct box *first,
else if (b->text || b->type == BOX_INLINE_END) {
if (b->space == UNKNOWN_WIDTH) {
font_plot_style_from_css(
- &content->len_ctx,
+ &content->unit_len_ctx,
b->style, &fstyle);
/** \todo handle errors */
font_func->width(&fstyle, " ", 1,
@@ -3608,7 +3639,7 @@ layout_line(struct box *first,
!(split_box->flags & IFRAME) &&
!split_box->gadget && split_box->text) {
- font_plot_style_from_css(&content->len_ctx,
+ font_plot_style_from_css(&content->unit_len_ctx,
split_box->style, &fstyle);
/** \todo handle errors */
font_func->split(&fstyle,
@@ -3972,9 +4003,10 @@ layout_block_context(struct box *block,
gadget_unit = CSS_UNIT_EM;
gadget_size = INTTOFIX(1);
if (block->height == AUTO)
- block->height = FIXTOINT(nscss_len2px(
- &content->len_ctx, gadget_size,
- gadget_unit, block->style));
+ block->height = FIXTOINT(css_unit_len2device_px(
+ block->style,
+ &content->unit_len_ctx,
+ gadget_size, gadget_unit));
}
box = block->children;
@@ -4038,7 +4070,7 @@ layout_block_context(struct box *block,
* through to, find out. Update the pos/neg margin values. */
if (margin_collapse == NULL) {
margin_collapse = layout_next_margin_block(
- &content->len_ctx, box, block,
+ &content->unit_len_ctx, box, block,
viewport_height,
&max_pos_margin, &max_neg_margin);
/* We have a margin that has not yet been applied. */
@@ -4089,7 +4121,7 @@ layout_block_context(struct box *block,
box->parent->padding[RIGHT] -
x1;
}
- layout_block_find_dimensions(&content->len_ctx,
+ layout_block_find_dimensions(&content->unit_len_ctx,
box->parent->width,
viewport_height, lm, rm, box);
if (box->type == BOX_BLOCK && !(box->flags & IFRAME)) {
@@ -4330,7 +4362,7 @@ layout_block_context(struct box *block,
css_computed_position(box->style) !=
CSS_POSITION_ABSOLUTE &&
layout_apply_minmax_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
box, NULL)) {
/* Height altered */
/* Set current cy */
@@ -4387,7 +4419,7 @@ layout_block_context(struct box *block,
if (block->style && css_computed_position(block->style) !=
CSS_POSITION_ABSOLUTE) {
/* Block is in normal flow */
- layout_apply_minmax_height(&content->len_ctx, block, NULL);
+ layout_apply_minmax_height(&content->unit_len_ctx, block, NULL);
}
if (block->gadget &&
@@ -4399,7 +4431,7 @@ layout_block_context(struct box *block,
block->padding[RIGHT];
int ta_height = block->padding[TOP] + block->height +
block->padding[BOTTOM];
- font_plot_style_from_css(&content->len_ctx,
+ font_plot_style_from_css(&content->unit_len_ctx,
block->style, &fstyle);
fstyle.background = NS_TRANSPARENT;
textarea_set_layout(block->gadget->data.text.ta,
@@ -4820,14 +4852,14 @@ layout_lists(const html_content *content, struct box *box)
marker->height =
content_get_height(marker->object);
marker->y = (line_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style) -
marker->height) / 2;
} else if (marker->text) {
if (marker->width == UNKNOWN_WIDTH) {
plot_font_style_t fstyle;
font_plot_style_from_css(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style,
&fstyle);
content->font_func->width(&fstyle,
@@ -4839,7 +4871,7 @@ layout_lists(const html_content *content, struct box *box)
marker->x = -marker->width;
marker->y = 0;
marker->height = line_height(
- &content->len_ctx,
+ &content->unit_len_ctx,
marker->style);
} else {
marker->x = 0;
@@ -4859,7 +4891,7 @@ layout_lists(const html_content *content, struct box *box)
* Compute box offsets for a relatively or absolutely positioned box with
* respect to a box.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to compute offsets for
* \param containing_block box to compute percentages with respect to
* \param top updated to top offset, or AUTO
@@ -4870,7 +4902,7 @@ layout_lists(const html_content *content, struct box *box)
* See CSS 2.1 9.3.2. containing_block must have width and height.
*/
static void
-layout_compute_offsets(const nscss_len_ctx *len_ctx,
+layout_compute_offsets(const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *containing_block,
int *top,
@@ -4893,8 +4925,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*left = FPCT_OF_INT_TOINT(value,
containing_block->width);
} else {
- *left = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *left = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*left = AUTO;
@@ -4907,8 +4940,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*right = FPCT_OF_INT_TOINT(value,
containing_block->width);
} else {
- *right = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *right = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*right = AUTO;
@@ -4921,8 +4955,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*top = FPCT_OF_INT_TOINT(value,
containing_block->height);
} else {
- *top = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *top = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*top = AUTO;
@@ -4935,8 +4970,9 @@ layout_compute_offsets(const nscss_len_ctx *len_ctx,
*bottom = FPCT_OF_INT_TOINT(value,
containing_block->height);
} else {
- *bottom = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, box->style));
+ *bottom = FIXTOINT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ value, unit));
}
} else {
*bottom = AUTO;
@@ -4992,14 +5028,14 @@ layout_absolute(struct box *box,
/** \todo inline containers */
}
- layout_compute_offsets(&content->len_ctx, box, containing_block,
+ layout_compute_offsets(&content->unit_len_ctx, box, containing_block,
&top, &right, &bottom, &left);
/* Pass containing block into layout_find_dimensions via the float
* containing block box member. This is unused for absolutely positioned
* boxes because a box can't be floated and absolutely positioned. */
box->float_container = containing_block;
- layout_find_dimensions(&content->len_ctx, available_width, -1,
+ layout_find_dimensions(&content->unit_len_ctx, available_width, -1,
box, box->style, &width, &height,
&max_width, &min_width, 0, 0,
margin, padding, border);
@@ -5317,7 +5353,7 @@ layout_absolute(struct box *box,
/** \todo Inline ancestors */
}
box->height = height;
- layout_apply_minmax_height(&content->len_ctx, box, containing_block);
+ layout_apply_minmax_height(&content->unit_len_ctx, box, containing_block);
return true;
}
@@ -5394,13 +5430,13 @@ layout_position_absolute(struct box *box,
/**
* Compute a box's relative offset as per CSS 2.1 9.4.3
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box Box to compute relative offsets for.
* \param x Receives relative offset in x.
* \param y Receives relative offset in y.
*/
static void layout_compute_relative_offset(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int *x,
int *y)
@@ -5420,7 +5456,7 @@ static void layout_compute_relative_offset(
containing_block = box->parent;
}
- layout_compute_offsets(len_ctx, box, containing_block,
+ layout_compute_offsets(unit_len_ctx, box, containing_block,
&top, &right, &bottom, &left);
if (left == AUTO && right == AUTO)
@@ -5468,7 +5504,7 @@ static void layout_compute_relative_offset(
/**
* Adjust positions of relatively positioned boxes.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param root box to adjust the position of
* \param fp box which forms the block formatting context for children of
* "root" which are floats
@@ -5481,7 +5517,7 @@ static void layout_compute_relative_offset(
*/
static void
layout_position_relative(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *root,
struct box *fp,
int fx,
@@ -5510,7 +5546,7 @@ layout_position_relative(
if (box->style && css_computed_position(box->style) ==
CSS_POSITION_RELATIVE)
layout_compute_relative_offset(
- len_ctx, box, &x, &y);
+ unit_len_ctx, box, &x, &y);
else
x = y = 0;
@@ -5546,7 +5582,7 @@ layout_position_relative(
}
/* recurse first */
- layout_position_relative(len_ctx, box, fn, fnx, fny);
+ layout_position_relative(unit_len_ctx, box, fn, fnx, fny);
/* Ignore things we're not interested in. */
if (!box->style || (box->style &&
@@ -5575,7 +5611,7 @@ layout_position_relative(
/**
* Find a box's bounding box relative to itself, i.e. the box's border edge box
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box find bounding box of
* \param desc_x0 updated to left of box's bbox
* \param desc_y0 updated to top of box's bbox
@@ -5584,7 +5620,7 @@ layout_position_relative(
*/
static void
layout_get_box_bbox(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
int *desc_x0, int *desc_y0,
int *desc_x1, int *desc_y1)
@@ -5607,8 +5643,8 @@ layout_get_box_bbox(
int text_height;
css_computed_font_size(box->style, &font_size, &font_unit);
- text_height = nscss_len2px(len_ctx, font_size, font_unit,
- box->style);
+ text_height = css_unit_len2device_px(box->style, unit_len_ctx,
+ font_size, font_unit);
text_height = FIXTOINT(text_height * 3 / 4);
*desc_y0 = (*desc_y0 < -text_height) ? *desc_y0 : -text_height;
}
@@ -5618,7 +5654,7 @@ layout_get_box_bbox(
/**
* Apply changes to box descendant_[xy][01] values due to given child.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box box to update
* \param child a box, which may affect box's descendant bbox
* \param off_x offset to apply to child->x coord to treat as child of box
@@ -5626,7 +5662,7 @@ layout_get_box_bbox(
*/
static void
layout_update_descendant_bbox(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box,
struct box *child,
int off_x,
@@ -5650,7 +5686,7 @@ layout_update_descendant_bbox(
}
/* Get child's border edge */
- layout_get_box_bbox(len_ctx, child,
+ layout_get_box_bbox(unit_len_ctx, child,
&child_desc_x0, &child_desc_y0,
&child_desc_x1, &child_desc_y1);
@@ -5688,11 +5724,11 @@ layout_update_descendant_bbox(
* Recursively calculate the descendant_[xy][01] values for a laid-out box tree
* and inform iframe browser windows of their size and position.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param box tree of boxes to update
*/
static void layout_calculate_descendant_bboxes(
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct box *box)
{
struct box *child;
@@ -5702,7 +5738,7 @@ static void layout_calculate_descendant_bboxes(
/* assert((box->width >= 0) && (box->height >= 0)); */
/* Initialise box's descendant box to border edge box */
- layout_get_box_bbox(len_ctx, box,
+ layout_get_box_bbox(unit_len_ctx, box,
&box->descendant_x0, &box->descendant_y0,
&box->descendant_x1, &box->descendant_y1);
@@ -5736,7 +5772,7 @@ static void layout_calculate_descendant_bboxes(
child->type == BOX_FLOAT_RIGHT)
continue;
- layout_update_descendant_bbox(len_ctx, box, child,
+ layout_update_descendant_bbox(unit_len_ctx, box, child,
box->x, box->y);
if (child == box->inline_end)
@@ -5754,7 +5790,7 @@ static void layout_calculate_descendant_bboxes(
child->type == BOX_FLOAT_RIGHT)
continue;
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
if (box->style && css_computed_overflow_x(box->style) ==
CSS_OVERFLOW_HIDDEN &&
@@ -5762,23 +5798,23 @@ static void layout_calculate_descendant_bboxes(
CSS_OVERFLOW_HIDDEN)
continue;
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
for (child = box->float_children; child; child = child->next_float) {
assert(child->type == BOX_FLOAT_LEFT ||
child->type == BOX_FLOAT_RIGHT);
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
if (box->list_marker) {
child = box->list_marker;
- layout_calculate_descendant_bboxes(len_ctx, child);
+ layout_calculate_descendant_bboxes(unit_len_ctx, child);
- layout_update_descendant_bbox(len_ctx, box, child, 0, 0);
+ layout_update_descendant_bbox(unit_len_ctx, box, child, 0, 0);
}
}
@@ -5796,7 +5832,7 @@ bool layout_document(html_content *content, int width, int height)
layout_minmax_block(doc, font_func, content);
- layout_block_find_dimensions(&content->len_ctx,
+ layout_block_find_dimensions(&content->unit_len_ctx,
width, height, 0, 0, doc);
doc->x = doc->margin[LEFT] + doc->border[LEFT].width;
doc->y = doc->margin[TOP] + doc->border[TOP].width;
@@ -5830,9 +5866,9 @@ bool layout_document(html_content *content, int width, int height)
layout_lists(content, doc);
layout_position_absolute(doc, doc, 0, 0, content);
- layout_position_relative(&content->len_ctx, doc, doc, 0, 0);
+ layout_position_relative(&content->unit_len_ctx, doc, doc, 0, 0);
- layout_calculate_descendant_bboxes(&content->len_ctx, doc);
+ layout_calculate_descendant_bboxes(&content->unit_len_ctx, doc);
return ret;
}
diff --git a/content/handlers/html/object.c b/content/handlers/html/object.c
index e6edf840d..a1f020bf7 100644
--- a/content/handlers/html/object.c
+++ b/content/handlers/html/object.c
@@ -265,18 +265,20 @@ html_object_callback(hlcache_handle *object,
if (hunit == CSS_UNIT_PCT) {
l = (width - w) * hpos / INTTOFIX(100);
} else {
- l = FIXTOINT(nscss_len2px(&c->len_ctx,
- hpos, hunit,
- box->style));
+ l = FIXTOINT(css_unit_len2device_px(
+ box->style,
+ &c->unit_len_ctx,
+ hpos, hunit));
}
h = content_get_height(box->background);
if (vunit == CSS_UNIT_PCT) {
t = (height - h) * vpos / INTTOFIX(100);
} else {
- t = FIXTOINT(nscss_len2px(&c->len_ctx,
- vpos, vunit,
- box->style));
+ t = FIXTOINT(css_unit_len2device_px(
+ box->style,
+ &c->unit_len_ctx,
+ vpos, vunit));
}
/* Redraw area depends on background-repeat */
diff --git a/content/handlers/html/private.h b/content/handlers/html/private.h
index 2bd9cff9d..56cd957d5 100644
--- a/content/handlers/html/private.h
+++ b/content/handlers/html/private.h
@@ -112,9 +112,6 @@ typedef struct html_content {
/** Base target */
char *base_target;
- /** CSS length conversion context for document. */
- nscss_len_ctx len_ctx;
-
/** Content has been aborted in the LOADING state */
bool aborted;
@@ -162,6 +159,8 @@ typedef struct html_content {
css_select_ctx *select_ctx;
/**< Style selection media specification */
css_media media;
+ /** CSS length conversion context for document. */
+ css_unit_ctx unit_len_ctx;
/**< Universal selector */
lwc_string *universal;
diff --git a/content/handlers/html/redraw.c b/content/handlers/html/redraw.c
index 9807512b9..f770699bb 100644
--- a/content/handlers/html/redraw.c
+++ b/content/handlers/html/redraw.c
@@ -528,14 +528,14 @@ static bool html_redraw_radio(int x, int y, int width, int height,
* \param box box of input
* \param scale scale for redraw
* \param background_colour current background colour
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
static bool html_redraw_file(int x, int y, int width, int height,
struct box *box, float scale, colour background_colour,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
int text_width;
@@ -544,7 +544,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
plot_font_style_t fstyle;
nserror res;
- font_plot_style_from_css(len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(unit_len_ctx, box->style, &fstyle);
fstyle.background = background_colour;
if (box->gadget->value) {
@@ -587,7 +587,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
* \param clip current clip rectangle
* \param background_colour current background colour
* \param background box containing background details (usually \a box)
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@@ -595,7 +595,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
static bool html_redraw_background(int x, int y, struct box *box, float scale,
const struct rect *clip, colour *background_colour,
struct box *background,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
bool repeat_x = false;
@@ -672,8 +672,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_width(background->background)) *
scale * FIXTOFLT(hpos) / 100.;
} else {
- x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
- background->style)) * scale);
+ x += (int) (FIXTOFLT(css_unit_len2device_px(
+ background->style, unit_len_ctx,
+ hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@@ -681,8 +682,9 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
content_get_height(background->background)) *
scale * FIXTOFLT(vpos) / 100.;
} else {
- y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
- background->style)) * scale);
+ y += (int) (FIXTOFLT(css_unit_len2device_px(
+ background->style, unit_len_ctx,
+ vpos, vunit)) * scale);
}
}
@@ -814,7 +816,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
* \param first true if this is the first rectangle associated with the inline
* \param last true if this is the last rectangle associated with the inline
* \param background_colour updated to current background colour if plotted
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param ctx current redraw context
* \return true if successful, false otherwise
*/
@@ -822,7 +824,7 @@ static bool html_redraw_background(int x, int y, struct box *box, float scale,
static bool html_redraw_inline_background(int x, int y, struct box *box,
float scale, const struct rect *clip, struct rect b,
bool first, bool last, colour *background_colour,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
const struct redraw_context *ctx)
{
struct rect r = *clip;
@@ -883,8 +885,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
plot_content = false;
}
} else {
- x += (int) (FIXTOFLT(nscss_len2px(len_ctx, hpos, hunit,
- box->style)) * scale);
+ x += (int) (FIXTOFLT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ hpos, hunit)) * scale);
}
if (vunit == CSS_UNIT_PCT) {
@@ -892,8 +895,9 @@ static bool html_redraw_inline_background(int x, int y, struct box *box,
content_get_height(box->background) *
scale) * FIXTOFLT(vpos) / 100.;
} else {
- y += (int) (FIXTOFLT(nscss_len2px(len_ctx, vpos, vunit,
- box->style)) * scale);
+ y += (int) (FIXTOFLT(css_unit_len2device_px(
+ box->style, unit_len_ctx,
+ vpos, vunit)) * scale);
}
}
@@ -1134,7 +1138,7 @@ static bool html_redraw_text_box(const html_content *html, struct box *box,
bool excluded = (box->object != NULL);
plot_font_style_t fstyle;
- font_plot_style_from_css(&html->len_ctx, box->style, &fstyle);
+ font_plot_style_from_css(&html->unit_len_ctx, box->style, &fstyle);
fstyle.background = current_background_color;
if (!text_redraw(box->text,
@@ -1405,28 +1409,24 @@ bool html_redraw_box(const html_content *html, struct box *box,
CSS_CLIP_RECT) {
/* We have an absolutly positioned box with a clip rect */
if (css_rect.left_auto == false)
- r.x0 = x - border_left + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.left, css_rect.lunit,
- box->style));
+ r.x0 = x - border_left + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.left, css_rect.lunit));
if (css_rect.top_auto == false)
- r.y0 = y - border_top + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.top, css_rect.tunit,
- box->style));
+ r.y0 = y - border_top + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.top, css_rect.tunit));
if (css_rect.right_auto == false)
- r.x1 = x - border_left + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.right, css_rect.runit,
- box->style));
+ r.x1 = x - border_left + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.right, css_rect.runit));
if (css_rect.bottom_auto == false)
- r.y1 = y - border_top + FIXTOINT(nscss_len2px(
- &html->len_ctx,
- css_rect.bottom, css_rect.bunit,
- box->style));
+ r.y1 = y - border_top + FIXTOINT(css_unit_len2device_px(
+ box->style, &html->unit_len_ctx,
+ css_rect.bottom, css_rect.bunit));
/* find intersection of clip rectangle and box */
if (r.x0 < clip->x0) r.x0 = clip->x0;
@@ -1515,7 +1515,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
/* plot background */
if (!html_redraw_background(x, y, box, scale, &p,
&current_background_color, bg_box,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1595,7 +1595,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
x, y, box, scale, &p, b,
first, false,
&current_background_color,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1628,7 +1628,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
* the inline */
if (!html_redraw_inline_background(x, ib_y, box, scale, &p, b,
first, true, &current_background_color,
- &html->len_ctx, ctx))
+ &html->unit_len_ctx, ctx))
return false;
/* restore previous graphics window */
if (ctx->plot->clip(ctx, &r) != NSERROR_OK)
@@ -1843,7 +1843,7 @@ bool html_redraw_box(const html_content *html, struct box *box,
} else if (box->gadget && box->gadget->type == GADGET_FILE) {
if (!html_redraw_file(x + padding_left, y + padding_top,
width, height, box, scale,
- current_background_color, &html->len_ctx, ctx))
+ current_background_color, &html->unit_len_ctx, ctx))
return false;
} else if (box->gadget &&
diff --git a/content/handlers/html/table.c b/content/handlers/html/table.c
index 263ddf1f6..4ffcceab9 100644
--- a/content/handlers/html/table.c
+++ b/content/handlers/html/table.c
@@ -50,7 +50,7 @@ struct border {
/**
* Determine if a border style is more eyecatching than another
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param a Reference border style
* \param a_src Source of \a a
* \param b Candidate border style
@@ -58,7 +58,7 @@ struct border {
* \return True if \a b is more eyecatching than \a a
*/
static bool
-table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
+table_border_is_more_eyecatching(const css_unit_ctx *unit_len_ctx,
const struct border *a,
box_type a_src,
const struct border *b,
@@ -83,8 +83,8 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* if they've come from a computed style. */
assert(a->unit != CSS_UNIT_EM && a->unit != CSS_UNIT_EX);
assert(b->unit != CSS_UNIT_EM && b->unit != CSS_UNIT_EX);
- awidth = nscss_len2px(len_ctx, a->width, a->unit, NULL);
- bwidth = nscss_len2px(len_ctx, b->width, b->unit, NULL);
+ awidth = css_unit_len2device_px(NULL, unit_len_ctx, a->width, a->unit);
+ bwidth = css_unit_len2device_px(NULL, unit_len_ctx, b->width, b->unit);
if (awidth < bwidth)
return true;
@@ -160,7 +160,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
/**
* Process a table
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param table Table to process
* \param a Current border style for cell
* \param a_src Source of \a a
@@ -169,7 +169,7 @@ table_border_is_more_eyecatching(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static void
-table_cell_top_process_table(const nscss_len_ctx *len_ctx,
+table_cell_top_process_table(const css_unit_ctx *unit_len_ctx,
struct box *table,
struct border *a,
box_type *a_src)
@@ -181,11 +181,12 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(table->style);
b.color = css_computed_border_top_color(table->style, &b.c);
css_computed_border_top_width(table->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -195,7 +196,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
/**
* Process a row
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param row Row to process
* \param a Current border style for cell
@@ -206,7 +207,7 @@ table_cell_top_process_table(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
-table_cell_top_process_row(const nscss_len_ctx *len_ctx,
+table_cell_top_process_row(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *row,
struct border *a,
@@ -219,11 +220,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -233,11 +235,12 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(row->style);
b.color = css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@@ -272,14 +275,13 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
c->style, &b.c);
css_computed_border_bottom_width(c->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width,
- b.unit,
- c->style);
+ b.width = css_unit_len2device_px(
+ c->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a,
*a_src,
&b,
@@ -305,7 +307,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
/**
* Process a group
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Cell being considered
* \param group Group to process
* \param a Current border style for cell
@@ -316,7 +318,7 @@ table_cell_top_process_row(const nscss_len_ctx *len_ctx,
* \post \a a_src will be updated also
*/
static bool
-table_cell_top_process_group(const nscss_len_ctx *len_ctx,
+table_cell_top_process_group(const css_unit_ctx *unit_len_ctx,
struct box *cell,
struct box *group,
struct border *a,
@@ -329,11 +331,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(group->style);
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx, a, *a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
}
@@ -342,7 +345,7 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/* Process rows in group, starting with last */
struct box *row = group->last;
- while (table_cell_top_process_row(len_ctx, cell, row,
+ while (table_cell_top_process_row(unit_len_ctx, cell, row,
a, a_src) == false) {
if (row->prev == NULL) {
return false;
@@ -355,11 +358,12 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
a, *a_src, &b, b_src)) {
*a = b;
*a_src = b_src;
@@ -375,11 +379,11 @@ table_cell_top_process_group(const nscss_len_ctx *len_ctx,
/**
* Calculate used values of border-left-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_left_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -390,7 +394,8 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_left_style(cell->style);
a.color = css_computed_border_left_color(cell->style, &a.c);
css_computed_border_left_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -423,11 +428,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_right_style(prev->style);
b.color = css_computed_border_right_color(prev->style, &b.c);
css_computed_border_right_width(prev->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, prev->style);
+ b.width = css_unit_len2device_px(prev->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_CELL;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -446,12 +452,13 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
row->style, &b.c);
css_computed_border_left_width(
row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(
+ row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -466,11 +473,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(group->style);
b.color = css_computed_border_left_color(group->style, &b.c);
css_computed_border_left_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -480,11 +488,12 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_left_style(table->style);
b.color = css_computed_border_left_color(table->style, &b.c);
css_computed_border_left_width(table->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -494,21 +503,19 @@ table_used_left_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used left border for the cell */
cell->border[LEFT].style = a.style;
cell->border[LEFT].c = a.c;
- cell->border[LEFT].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[LEFT].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-top-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_top_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -519,7 +526,8 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_top_style(cell->style);
css_computed_border_top_color(cell->style, &a.c);
css_computed_border_top_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -527,18 +535,19 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(row->style);
css_computed_border_top_color(row->style, &b.c);
css_computed_border_top_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx, &a, a_src, &b, b_src)) {
+ if (table_border_is_more_eyecatching(unit_len_ctx, &a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
}
if (row->prev != NULL) {
/* Consider row(s) above */
- while (table_cell_top_process_row(len_ctx, cell, row->prev,
+ while (table_cell_top_process_row(unit_len_ctx, cell, row->prev,
&a, &a_src) == false) {
if (row->prev->prev == NULL) {
/* Consider row group */
@@ -559,11 +568,12 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.style = css_computed_border_top_style(group->style);
b.color = css_computed_border_top_color(group->style, &b.c);
css_computed_border_top_width(group->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -571,16 +581,16 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
if (group->prev == NULL) {
/* Top border of table */
- table_cell_top_process_table(len_ctx,
+ table_cell_top_process_table(unit_len_ctx,
group->parent, &a, &a_src);
} else {
/* Process previous group(s) */
- while (table_cell_top_process_group(len_ctx,
+ while (table_cell_top_process_group(unit_len_ctx,
cell, group->prev,
&a, &a_src) == false) {
if (group->prev->prev == NULL) {
/* Top border of table */
- table_cell_top_process_table(len_ctx,
+ table_cell_top_process_table(unit_len_ctx,
group->parent,
&a, &a_src);
break;
@@ -594,20 +604,18 @@ table_used_top_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used top border for the cell */
cell->border[TOP].style = a.style;
cell->border[TOP].c = a.c;
- cell->border[TOP].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[TOP].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-right-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+table_used_right_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
struct border a, b;
box_type a_src, b_src;
@@ -618,7 +626,8 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
a.style = css_computed_border_right_style(cell->style);
css_computed_border_right_color(cell->style, &a.c);
css_computed_border_right_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -643,14 +652,13 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
css_computed_border_right_width(row->style,
&b.width,
&b.unit);
- b.width = nscss_len2px(len_ctx,
- b.width,
- b.unit,
- row->style);
+ b.width = css_unit_len2device_px(
+ row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@@ -667,11 +675,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(group->style, &b.c);
css_computed_border_right_width(group->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -682,11 +691,12 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
b.color = css_computed_border_right_color(table->style, &b.c);
css_computed_border_right_width(table->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src,
&b, b_src)) {
a = b;
@@ -697,21 +707,19 @@ table_used_right_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
/* a now contains the used right border for the cell */
cell->border[RIGHT].style = a.style;
cell->border[RIGHT].c = a.c;
- cell->border[RIGHT].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width,
- a.unit,
- cell->style));
+ cell->border[RIGHT].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/**
* Calculate used values of border-bottom-{style,color,width}
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*/
static void
-table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
+table_used_bottom_border_for_cell(const css_unit_ctx *unit_len_ctx,
struct box *cell)
{
struct border a, b;
@@ -723,7 +731,8 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
a.style = css_computed_border_bottom_style(cell->style);
css_computed_border_bottom_color(cell->style, &a.c);
css_computed_border_bottom_width(cell->style, &a.width, &a.unit);
- a.width = nscss_len2px(len_ctx, a.width, a.unit, cell->style);
+ a.width = css_unit_len2device_px(cell->style, unit_len_ctx,
+ a.width, a.unit);
a.unit = CSS_UNIT_PX;
a_src = BOX_TABLE_CELL;
@@ -747,11 +756,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.style = css_computed_border_bottom_style(row->style);
b.color = css_computed_border_bottom_color(row->style, &b.c);
css_computed_border_bottom_width(row->style, &b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, row->style);
+ b.width = css_unit_len2device_px(row->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -762,11 +772,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(group->style, &b.c);
css_computed_border_bottom_width(group->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, group->style);
+ b.width = css_unit_len2device_px(group->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE_ROW_GROUP;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
a_src = b_src;
@@ -777,11 +788,12 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
b.color = css_computed_border_bottom_color(table->style, &b.c);
css_computed_border_bottom_width(table->style,
&b.width, &b.unit);
- b.width = nscss_len2px(len_ctx, b.width, b.unit, table->style);
+ b.width = css_unit_len2device_px(table->style, unit_len_ctx,
+ b.width, b.unit);
b.unit = CSS_UNIT_PX;
b_src = BOX_TABLE;
- if (table_border_is_more_eyecatching(len_ctx,
+ if (table_border_is_more_eyecatching(unit_len_ctx,
&a, a_src, &b, b_src)) {
a = b;
}
@@ -790,14 +802,14 @@ table_used_bottom_border_for_cell(const nscss_len_ctx *len_ctx,
/* a now contains the used bottom border for the cell */
cell->border[BOTTOM].style = a.style;
cell->border[BOTTOM].c = a.c;
- cell->border[BOTTOM].width = FIXTOINT(nscss_len2px(len_ctx,
- a.width, a.unit, cell->style));
+ cell->border[BOTTOM].width = FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx, a.width, a.unit));
}
/* exported interface documented in html/table.h */
bool
-table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
+table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table)
{
unsigned int i, j;
struct column *col;
@@ -845,8 +857,10 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (col[i].type != COLUMN_WIDTH_FIXED &&
type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) {
col[i].type = COLUMN_WIDTH_FIXED;
- col[i].width = FIXTOINT(nscss_len2px(len_ctx,
- value, unit, cell->style));
+ col[i].width = FIXTOINT(css_unit_len2device_px(
+ cell->style,
+ unit_len_ctx,
+ value, unit));
if (col[i].width < 0)
col[i].width = 0;
continue;
@@ -911,9 +925,11 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
if (type == CSS_WIDTH_SET && unit != CSS_UNIT_PCT &&
fixed_columns + unknown_columns ==
cell->columns) {
- int width = (FIXTOFLT(nscss_len2px(len_ctx, value, unit,
- cell->style)) - fixed_width) /
- unknown_columns;
+ int width = (FIXTOFLT(css_unit_len2device_px(
+ cell->style,
+ unit_len_ctx,
+ value, unit)) -
+ fixed_width) / unknown_columns;
if (width < 0)
width = 0;
for (j = 0; j != cell->columns; j++) {
@@ -968,7 +984,7 @@ table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table)
/* exported interface documented in html/table.h */
-void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
+void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell)
{
int side;
@@ -986,8 +1002,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[LEFT].c);
css_computed_border_left_width(cell->style, &width, &unit);
cell->border[LEFT].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Top border */
cell->border[TOP].style =
@@ -996,8 +1013,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[TOP].c);
css_computed_border_top_width(cell->style, &width, &unit);
cell->border[TOP].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Right border */
cell->border[RIGHT].style =
@@ -1006,8 +1024,9 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[RIGHT].c);
css_computed_border_right_width(cell->style, &width, &unit);
cell->border[RIGHT].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
/* Bottom border */
cell->border[BOTTOM].style =
@@ -1016,20 +1035,21 @@ void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell)
&cell->border[BOTTOM].c);
css_computed_border_bottom_width(cell->style, &width, &unit);
cell->border[BOTTOM].width =
- FIXTOINT(nscss_len2px(len_ctx,
- width, unit, cell->style));
+ FIXTOINT(css_unit_len2device_px(
+ cell->style, unit_len_ctx,
+ width, unit));
} else {
/* Left border */
- table_used_left_border_for_cell(len_ctx, cell);
+ table_used_left_border_for_cell(unit_len_ctx, cell);
/* Top border */
- table_used_top_border_for_cell(len_ctx, cell);
+ table_used_top_border_for_cell(unit_len_ctx, cell);
/* Right border */
- table_used_right_border_for_cell(len_ctx, cell);
+ table_used_right_border_for_cell(unit_len_ctx, cell);
/* Bottom border */
- table_used_bottom_border_for_cell(len_ctx, cell);
+ table_used_bottom_border_for_cell(unit_len_ctx, cell);
}
/* Finally, ensure that any borders configured as
diff --git a/content/handlers/html/table.h b/content/handlers/html/table.h
index ac4af25ad..557032b06 100644
--- a/content/handlers/html/table.h
+++ b/content/handlers/html/table.h
@@ -33,24 +33,24 @@ struct box;
/**
* Determine the column width types for a table.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param table box of type BOX_TABLE
* \return true on success, false on memory exhaustion
*
* The table->col array is allocated and type and width are filled in for each
* column.
*/
-bool table_calculate_column_types(const nscss_len_ctx *len_ctx, struct box *table);
+bool table_calculate_column_types(const css_unit_ctx *unit_len_ctx, struct box *table);
/**
* Calculate used values of border-{trbl}-{style,color,width} for table cells.
*
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param cell Table cell to consider
*
* \post \a cell's border array is populated
*/
-void table_used_border_for_cell(const nscss_len_ctx *len_ctx, struct box *cell);
+void table_used_border_for_cell(const css_unit_ctx *unit_len_ctx, struct box *cell);
#endif
diff --git a/content/handlers/html/textselection.c b/content/handlers/html/textselection.c
index 9de7590f0..9b83e73ec 100644
--- a/content/handlers/html/textselection.c
+++ b/content/handlers/html/textselection.c
@@ -240,7 +240,7 @@ coords_from_range(struct box *box,
* \param text pointer to text being added, or NULL for newline
* \param length length of text to be appended (bytes)
* \param box pointer to text box, or NULL if from textplain
- * \param len_ctx Length conversion context
+ * \param unit_len_ctx Length conversion context
* \param handle selection string to append to
* \param whitespace_text whitespace to place before text for formatting
* may be NULL
@@ -251,7 +251,7 @@ static nserror
selection_copy_box(const char *text,
size_t length,
struct box *box,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
struct selection_string *handle,
const char *whitespace_text,
size_t whitespace_length)
@@ -278,7 +278,7 @@ selection_copy_box(const char *text,
if (box->style != NULL) {
/* Override default font style */
- font_plot_style_from_css(len_ctx, box->style, &style);
+ font_plot_style_from_css(unit_len_ctx, box->style, &style);
pstyle = &style;
} else {
/* If there's no style, there must be no text */
@@ -300,7 +300,7 @@ selection_copy_box(const char *text,
* boxes that lie (partially) within the given range
*
* \param box box subtree
- * \param len_ctx Length conversion context.
+ * \param unit_len_ctx Length conversion context.
* \param start_idx start of range within textual representation (bytes)
* \param end_idx end of range
* \param handler handler function to call
@@ -312,7 +312,7 @@ selection_copy_box(const char *text,
*/
static nserror
selection_copy(struct box *box,
- const nscss_len_ctx *len_ctx,
+ const css_unit_ctx *unit_len_ctx,
unsigned start_idx,
unsigned end_idx,
struct selection_string *selstr,
@@ -340,7 +340,7 @@ selection_copy(struct box *box,
/* do the marker box before continuing with the rest of the
* list element */
res = selection_copy(box->list_marker,
- len_ctx,
+ unit_len_ctx,
start_idx,
end_idx,
selstr,
@@ -383,7 +383,7 @@ selection_copy(struct box *box,
res = selection_copy_box(box->text + start_off,
min(box->length, end_off) - start_off,
box,
- len_ctx,
+ unit_len_ctx,
selstr,
whitespace_text,
whitespace_length);
@@ -415,7 +415,7 @@ selection_copy(struct box *box,
struct box *next = child->next;
res = selection_copy(child,
- len_ctx,
+ unit_len_ctx,
start_idx,
end_idx,
selstr,
@@ -518,7 +518,7 @@ html_textselection_copy(struct content *c,
}
return selection_copy(html->layout,
- &html->len_ctx,
+ &html->unit_len_ctx,
start_idx,
end_idx,
selstr,