move the CSS content handler

This commit is contained in:
Vincent Sanders 2016-05-26 11:18:41 +01:00
parent c25eb6b7e7
commit 6722943b81
46 changed files with 344 additions and 328 deletions

View File

@ -672,12 +672,13 @@ INPUT = frontends/amiga \
frontends/riscos/templates \
frontends/riscos/scripts \
frontends/windows \
css \
include/netsurf \
render \
desktop \
content \
content/fetchers \
content/handlers/image \
content/handlers/css \
javascript \
javascript/jsapi \
utils \

View File

@ -539,8 +539,8 @@ $(eval $(call pkg_config_find_and_add_enabled,NSSVG,libsvgtiny,SVG))
$(eval $(call pkg_config_find_and_add_enabled,ROSPRITE,librosprite,Sprite))
# add top level and build directory to include search path
CFLAGS += -I. -Ifrontends -I$(OBJROOT)
CXXFLAGS += -I. -Ifrontends -I$(OBJROOT)
CFLAGS += -I. -Iinclude -Ifrontends -I$(OBJROOT)
CXXFLAGS += -I. -Iinclude -Ifrontends -I$(OBJROOT)
# export the user agent format
CFLAGS += -DNETSURF_UA_FORMAT_STRING=\"$(NETSURF_UA_FORMAT_STRING)\"
@ -585,9 +585,6 @@ include frontends/Makefile
# Content sources
include content/Makefile
# CSS sources
include css/Makefile
# render sources
include render/Makefile

View File

@ -1,4 +1,9 @@
# Image content handler sources
include content/handlers/image/Makefile
S_IMAGE := $(addprefix content/handlers/,$(S_IMAGE))
S_IMAGE := $(addprefix content/handlers/image/,$(S_IMAGE))
# CSS sources
include content/handlers/css/Makefile
S_CSS := $(addprefix content/handlers/css/,$(S_CSS))

View File

@ -2,4 +2,3 @@
S_CSS := css.c dump.c internal.c hints.c select.c utils.c
S_CSS := $(addprefix css/,$(S_CSS))

View File

@ -30,9 +30,9 @@
#include "utils/log.h"
#include "utils/messages.h"
#include "css/css.h"
#include "css/hints.h"
#include "css/internal.h"
#include "css.h"
#include "hints.h"
#include "internal.h"
/* Define to trace import fetches */
#undef NSCSS_IMPORT_TRACE
@ -76,11 +76,11 @@ typedef struct nscss_content
*/
typedef struct {
struct content_css_data *css; /**< Object containing import */
uint32_t index; /**< Index into parent sheet's
uint32_t index; /**< Index into parent sheet's
* imports array */
} nscss_import_ctx;
static bool nscss_process_data(struct content *c, const char *data,
static bool nscss_process_data(struct content *c, const char *data,
unsigned int size);
static bool nscss_convert(struct content *c);
static void nscss_destroy(struct content *c);
@ -91,13 +91,13 @@ static content_type nscss_content_type(void);
static nserror nscss_create_css_data(struct content_css_data *c,
const char *url, const char *charset, bool quirks,
nscss_done_callback done, void *pw);
static css_error nscss_process_css_data(struct content_css_data *c, const char *data,
static css_error nscss_process_css_data(struct content_css_data *c, const char *data,
unsigned int size);
static css_error nscss_convert_css_data(struct content_css_data *c);
static void nscss_destroy_css_data(struct content_css_data *c);
static void nscss_content_done(struct content_css_data *css, void *pw);
static css_error nscss_handle_import(void *pw, css_stylesheet *parent,
static css_error nscss_handle_import(void *pw, css_stylesheet *parent,
lwc_string *url, uint64_t media);
static nserror nscss_import(hlcache_handle *handle,
const hlcache_event *event, void *pw);
@ -151,7 +151,7 @@ nscss_create(const content_handler *handler,
}
/* Find charset specified on HTTP layer, if any */
error = http_parameter_list_find_item(params, corestring_lwc_charset,
error = http_parameter_list_find_item(params, corestring_lwc_charset,
&charset_value);
if (error != NSERROR_OK || lwc_string_length(charset_value) == 0) {
/* No charset specified, use fallback, if any */
@ -167,8 +167,8 @@ nscss_create(const content_handler *handler,
xnsbase = nsurl_access(content_get_url(&result->base));
}
error = nscss_create_css_data(&result->data,
xnsbase, charset, result->base.quirks,
error = nscss_create_css_data(&result->data,
xnsbase, charset, result->base.quirks,
nscss_content_done, result);
if (error != NSERROR_OK) {
msg_data.error = messages_get("NoMemory");
@ -273,7 +273,7 @@ bool nscss_process_data(struct content *c, const char *data, unsigned int size)
static css_error nscss_process_css_data(struct content_css_data *c,
const char *data, unsigned int size)
{
return css_stylesheet_append_data(c->sheet,
return css_stylesheet_append_data(c->sheet,
(const uint8_t *) data, size);
}
@ -316,7 +316,7 @@ static css_error nscss_convert_css_data(struct content_css_data *c)
/* We must not have registered any imports yet */
assert(c->next_to_register == (uint32_t) -1);
/* Start registering, until we find one that
/* Start registering, until we find one that
* hasn't finished fetching */
c->next_to_register = 0;
error = nscss_register_imports(c);
@ -396,7 +396,7 @@ nserror nscss_clone(const struct content *old, struct content **newc)
/* Simply replay create/process/convert */
error = nscss_create_css_data(&new_css->data,
nsurl_access(content_get_url(&new_css->base)),
old_css->data.charset,
old_css->data.charset,
new_css->base.quirks,
nscss_content_done, new_css);
if (error != NSERROR_OK) {
@ -430,12 +430,7 @@ bool nscss_matches_quirks(const struct content *c, bool quirks)
return c->quirks == quirks;
}
/**
* Retrieve the stylesheet object associated with a CSS content
*
* \param h Stylesheet content
* \return Pointer to stylesheet object
*/
/* exported interface documented in netsurf/css.h */
css_stylesheet *nscss_get_stylesheet(struct hlcache_handle *h)
{
nscss_content *c = (nscss_content *) hlcache_handle_get_content(h);
@ -445,13 +440,7 @@ css_stylesheet *nscss_get_stylesheet(struct hlcache_handle *h)
return c->data.sheet;
}
/**
* Retrieve imported stylesheets
*
* \param h Stylesheet containing imports
* \param n Pointer to location to receive number of imports
* \return Pointer to array of imported stylesheets
*/
/* exported interface documented in netsurf/css.h */
struct nscss_import *nscss_get_imports(hlcache_handle *h, uint32_t *n)
{
nscss_content *c = (nscss_content *) hlcache_handle_get_content(h);
@ -562,7 +551,7 @@ css_error nscss_handle_import(void *pw, css_stylesheet *parent,
ctx->index = c->import_count;
/* Increase space in table */
imports = realloc(c->imports, (c->import_count + 1) *
imports = realloc(c->imports, (c->import_count + 1) *
sizeof(struct nscss_import));
if (imports == NULL) {
free(ctx);
@ -710,12 +699,12 @@ css_error nscss_register_imports(struct content_css_data *c)
/* Register imported sheets */
for (index = c->next_to_register; index < c->import_count; index++) {
/* Stop registering if we encounter one whose fetch hasn't
* completed yet. We'll resume at this point when it has
/* Stop registering if we encounter one whose fetch hasn't
* completed yet. We'll resume at this point when it has
* completed.
*/
if (c->imports[index].c != NULL &&
content_get_status(c->imports[index].c) !=
if (c->imports[index].c != NULL &&
content_get_status(c->imports[index].c) !=
CONTENT_STATUS_DONE) {
break;
}
@ -751,7 +740,7 @@ css_error nscss_register_import(struct content_css_data *c,
css_error error;
if (import != NULL) {
nscss_content *s =
nscss_content *s =
(nscss_content *) hlcache_handle_get_content(import);
sheet = s->data.sheet;
} else {
@ -822,16 +811,14 @@ static const content_handler css_content_handler = {
.no_share = false,
};
/**
* Initialise the CSS content handler
*/
/* exported interface documented in netsurf/css.h */
nserror nscss_init(void)
{
nserror error;
error = content_factory_register_handler("text/css",
error = content_factory_register_handler("text/css",
&css_content_handler);
if (error != NSERROR_OK)
if (error != NSERROR_OK)
goto error;
error = css_hint_init();

View File

@ -35,10 +35,28 @@ struct nscss_import {
uint64_t media; /**< Media types that sheet applies to */
};
/**
* Initialise the CSS content handler
*
* \return NSERROR_OK on success or error code on faliure
*/
nserror nscss_init(void);
/**
* Retrieve the stylesheet object associated with a CSS content
*
* \param h Stylesheet content
* \return Pointer to stylesheet object
*/
css_stylesheet *nscss_get_stylesheet(struct hlcache_handle *h);
/**
* Retrieve imported stylesheets
*
* \param h Stylesheet containing imports
* \param n Pointer to location to receive number of imports
* \return Pointer to array of imported stylesheets
*/
struct nscss_import *nscss_get_imports(struct hlcache_handle *h, uint32_t *n);
#endif

View File

@ -17,19 +17,105 @@
*/
#include <stdio.h>
#include <libcss/libcss.h>
#include "css/dump.h"
static void dump_css_fixed(FILE *stream, css_fixed f);
static void dump_css_number(FILE *stream, css_fixed val);
static void dump_css_unit(FILE *stream, css_fixed val, css_unit unit);
#include "dump.h"
/**
* Dump a computed style \a style to the give file handle \a stream.
* Dump a fixed point value to the stream in a textual form.
*
* \param stream Stream to write to
* \param style Computed style to dump
* \param f Value to write
*/
static void dump_css_fixed(FILE *stream, css_fixed f)
{
#define NSCSS_ABS(x) (uint32_t)((x) < 0 ? -(x) : (x))
uint32_t uintpart = FIXTOINT(NSCSS_ABS(f));
/* + 500 to ensure round to nearest (division will truncate) */
uint32_t fracpart = ((NSCSS_ABS(f) & 0x3ff) * 1000 + 500) / (1 << 10);
#undef NSCSS_ABS
fprintf(stream, "%s%d.%03d", f < 0 ? "-" : "", uintpart, fracpart);
}
/**
* Dump a numeric value to the stream in a textual form.
*
* \param stream Stream to write to
* \param val Value to write
*/
static void dump_css_number(FILE *stream, css_fixed val)
{
if (INTTOFIX(FIXTOINT(val)) == val)
fprintf(stream, "%d", FIXTOINT(val));
else
dump_css_fixed(stream, val);
}
/**
* Dump a dimension to the stream in a textual form.
*
* \param stream Stream to write to
* \param val Value to write
* \param unit Unit to write
*/
static void dump_css_unit(FILE *stream, css_fixed val, css_unit unit)
{
dump_css_number(stream, val);
switch (unit) {
case CSS_UNIT_PX:
fprintf(stream, "px");
break;
case CSS_UNIT_EX:
fprintf(stream, "ex");
break;
case CSS_UNIT_EM:
fprintf(stream, "em");
break;
case CSS_UNIT_IN:
fprintf(stream, "in");
break;
case CSS_UNIT_CM:
fprintf(stream, "cm");
break;
case CSS_UNIT_MM:
fprintf(stream, "mm");
break;
case CSS_UNIT_PT:
fprintf(stream, "pt");
break;
case CSS_UNIT_PC:
fprintf(stream, "pc");
break;
case CSS_UNIT_PCT:
fprintf(stream, "%%");
break;
case CSS_UNIT_DEG:
fprintf(stream, "deg");
break;
case CSS_UNIT_GRAD:
fprintf(stream, "grad");
break;
case CSS_UNIT_RAD:
fprintf(stream, "rad");
break;
case CSS_UNIT_MS:
fprintf(stream, "ms");
break;
case CSS_UNIT_S:
fprintf(stream, "s");
break;
case CSS_UNIT_HZ:
fprintf(stream, "Hz");
break;
case CSS_UNIT_KHZ:
fprintf(stream, "kHz");
break;
}
}
/* exported interface documented in content/handlers/css/dump.h */
void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
{
uint8_t val;
@ -74,7 +160,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_background_image(style, &url);
if (val == CSS_BACKGROUND_IMAGE_IMAGE && url != NULL) {
fprintf(stream, "background-image: url('%.*s') ",
(int) lwc_string_length(url),
(int) lwc_string_length(url),
lwc_string_data(url));
} else if (val == CSS_BACKGROUND_IMAGE_NONE) {
fprintf(stream, "background-image: none ");
@ -1008,7 +1094,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
val = css_computed_list_style_image(style, &url);
if (url != NULL) {
fprintf(stream, "list-style-image: url('%.*s') ",
(int) lwc_string_length(url),
(int) lwc_string_length(url),
lwc_string_data(url));
} else if (val == CSS_LIST_STYLE_IMAGE_NONE) {
fprintf(stream, "list-style-image: none ");
@ -1705,102 +1791,3 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
fprintf(stream, "}");
}
/******************************************************************************
* Helper functions for nscss_dump_computed_style *
******************************************************************************/
/**
* Dump a fixed point value to the stream in a textual form.
*
* \param stream Stream to write to
* \param f Value to write
*/
void dump_css_fixed(FILE *stream, css_fixed f)
{
#define NSCSS_ABS(x) (uint32_t)((x) < 0 ? -(x) : (x))
uint32_t uintpart = FIXTOINT(NSCSS_ABS(f));
/* + 500 to ensure round to nearest (division will truncate) */
uint32_t fracpart = ((NSCSS_ABS(f) & 0x3ff) * 1000 + 500) / (1 << 10);
#undef NSCSS_ABS
fprintf(stream, "%s%d.%03d", f < 0 ? "-" : "", uintpart, fracpart);
}
/**
* Dump a numeric value to the stream in a textual form.
*
* \param stream Stream to write to
* \param val Value to write
*/
void dump_css_number(FILE *stream, css_fixed val)
{
if (INTTOFIX(FIXTOINT(val)) == val)
fprintf(stream, "%d", FIXTOINT(val));
else
dump_css_fixed(stream, val);
}
/**
* Dump a dimension to the stream in a textual form.
*
* \param stream Stream to write to
* \param val Value to write
* \param unit Unit to write
*/
void dump_css_unit(FILE *stream, css_fixed val, css_unit unit)
{
dump_css_number(stream, val);
switch (unit) {
case CSS_UNIT_PX:
fprintf(stream, "px");
break;
case CSS_UNIT_EX:
fprintf(stream, "ex");
break;
case CSS_UNIT_EM:
fprintf(stream, "em");
break;
case CSS_UNIT_IN:
fprintf(stream, "in");
break;
case CSS_UNIT_CM:
fprintf(stream, "cm");
break;
case CSS_UNIT_MM:
fprintf(stream, "mm");
break;
case CSS_UNIT_PT:
fprintf(stream, "pt");
break;
case CSS_UNIT_PC:
fprintf(stream, "pc");
break;
case CSS_UNIT_PCT:
fprintf(stream, "%%");
break;
case CSS_UNIT_DEG:
fprintf(stream, "deg");
break;
case CSS_UNIT_GRAD:
fprintf(stream, "grad");
break;
case CSS_UNIT_RAD:
fprintf(stream, "rad");
break;
case CSS_UNIT_MS:
fprintf(stream, "ms");
break;
case CSS_UNIT_S:
fprintf(stream, "s");
break;
case CSS_UNIT_HZ:
fprintf(stream, "Hz");
break;
case CSS_UNIT_KHZ:
fprintf(stream, "kHz");
break;
}
}

View File

@ -19,8 +19,12 @@
#ifndef NETSURF_CSS_DUMP_H_
#define NETSURF_CSS_DUMP_H_
#include "css/css.h"
/**
* Dump a computed style \a style to the give file handle \a stream.
*
* \param stream Stream to write to
* \param style Computed style to dump
*/
void nscss_dump_computed_style(FILE *stream, const css_computed_style *style);
#endif

View File

@ -25,8 +25,8 @@
#include "utils/nsurl.h"
#include "utils/utils.h"
#include "css/hints.h"
#include "css/select.h"
#include "hints.h"
#include "select.h"
#define LOG_STATS
#undef LOG_STATS
@ -445,13 +445,7 @@ static bool parse_named_colour(const char *name, css_color *result)
return entry != NULL;
}
/**
* Parser for colours specified in attribute values.
*
* \param data Data to parse (NUL-terminated)
* \param result Pointer to location to receive resulting css_color
* \return true on success, false on invalid input
*/
/* exported interface documented in content/handlers/css/hints.h */
bool nscss_parse_colour(const char *data, css_color *result)
{
size_t len = strlen(data);
@ -512,7 +506,7 @@ bool nscss_parse_colour(const char *data, css_color *result)
* \param unit Pointer to location to receive unit
* \return True on success, false on failure
*/
static bool parse_font_size(const char *size, uint8_t *val,
static bool parse_font_size(const char *size, uint8_t *val,
css_fixed *len, css_unit *unit)
{
static const uint8_t size_map[] = {
@ -564,7 +558,7 @@ static bool parse_font_size(const char *size, uint8_t *val,
if (value == 7) {
/* Manufacture xxx-large */
*len = FDIV(FMUL(INTTOFIX(3), INTTOFIX(nsoption_int(font_size))),
*len = FDIV(FMUL(INTTOFIX(3), INTTOFIX(nsoption_int(font_size))),
F_10);
} else {
/* Len is irrelevant */
@ -1608,4 +1602,3 @@ css_error node_presentational_hint(void *pw, void *node,
return CSS_OK;
}

View File

@ -21,18 +21,17 @@
#include <stdint.h>
#include "css/css.h"
#include <libcss/libcss.h>
nserror css_hint_init(void);
void css_hint_fini(void);
/**
* Callback to retrieve presentational hints for a node
*
* \param[in] pw HTML document
* \param[in] node DOM node
* \param[out] nhints number of hints retrived
* \param[out] nhints number of hints retrived
* \param[out] hints retrived hints
* \return CSS_OK on success,
* CSS_PROPERTY_NOT_SET if there is no hint for the requested property,
@ -44,6 +43,13 @@ css_error node_presentational_hint(
uint32_t *nhints,
css_hint **hints);
/**
* Parser for colours specified in attribute values.
*
* \param data Data to parse (NUL-terminated)
* \param result Pointer to location to receive resulting css_color
* \return true on success, false on invalid input
*/
bool nscss_parse_colour(const char *data, css_color *result);
#endif

View File

@ -17,23 +17,14 @@
*/
#include <string.h>
#include "css/internal.h"
#include <libcss/libcss.h>
#include "utils/nsurl.h"
/**
* URL resolution callback for libcss
*
* \param pw Resolution context
* \param base Base URI
* \param rel Relative URL
* \param abs Pointer to location to receive resolved URL
* \return CSS_OK on success,
* CSS_NOMEM on memory exhaustion,
* CSS_INVALID if resolution failed.
*/
css_error nscss_resolve_url(void *pw, const char *base,
#include "internal.h"
/* exported interface documented in content/handlers/css/internal.h */
css_error nscss_resolve_url(void *pw, const char *base,
lwc_string *rel, lwc_string **abs)
{
lwc_error lerror;
@ -70,4 +61,3 @@ css_error nscss_resolve_url(void *pw, const char *base,
return CSS_OK;
}

View File

@ -19,9 +19,17 @@
#ifndef NETSURF_CSS_INTERNAL_H_
#define NETSURF_CSS_INTERNAL_H_
#include "css/css.h"
css_error nscss_resolve_url(void *pw, const char *base,
lwc_string *rel, lwc_string **abs);
/**
* URL resolution callback for libcss
*
* \param pw Resolution context
* \param base Base URI
* \param rel Relative URL
* \param abs Pointer to location to receive resolved URL
* \return CSS_OK on success,
* CSS_NOMEM on memory exhaustion,
* CSS_INVALID if resolution failed.
*/
css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs);
#endif

View File

@ -26,9 +26,9 @@
#include "utils/corestrings.h"
#include "utils/log.h"
#include "css/internal.h"
#include "css/hints.h"
#include "css/select.h"
#include "internal.h"
#include "hints.h"
#include "select.h"
static css_error node_name(void *pw, void *node, css_qname *qname);
static css_error node_classes(void *pw, void *node,
@ -265,7 +265,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
return NULL;
}
/* If there's a parent style, compose with partial to obtain
/* If there's a parent style, compose with partial to obtain
* complete computed style for element */
if (ctx->parent_style != NULL) {
/* Complete the computed style, by composing with the parent
@ -498,7 +498,7 @@ css_error node_name(void *pw, void *node, css_qname *qname)
* be allocated using the same allocator as used by libcss during style
* selection.
*/
css_error node_classes(void *pw, void *node,
css_error node_classes(void *pw, void *node,
lwc_string ***classes, uint32_t *n_classes)
{
dom_node *n = node;
@ -697,7 +697,7 @@ css_error named_generic_sibling_node(void *pw, void *node,
return CSS_OK;
}
if (dom_string_caseless_lwc_isequal(name,
if (dom_string_caseless_lwc_isequal(name,
qname->name)) {
dom_string_unref(name);
dom_node_unref(n);
@ -844,7 +844,7 @@ css_error node_has_class(void *pw, void *node,
dom_node *n = node;
dom_exception err;
/** \todo: Ensure that libdom performs case-insensitive
/** \todo: Ensure that libdom performs case-insensitive
* matching in quirks mode */
err = dom_element_has_class(n, name, match);
@ -907,7 +907,7 @@ css_error node_has_attribute(void *pw, void *node,
dom_exception err;
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -953,7 +953,7 @@ css_error node_has_attribute_equal(void *pw, void *node,
}
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -1005,7 +1005,7 @@ css_error node_has_attribute_dashmatch(void *pw, void *node,
}
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -1073,7 +1073,7 @@ css_error node_has_attribute_includes(void *pw, void *node,
}
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -1141,7 +1141,7 @@ css_error node_has_attribute_prefix(void *pw, void *node,
}
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -1163,7 +1163,7 @@ css_error node_has_attribute_prefix(void *pw, void *node,
const char *data = (const char *) dom_string_data(atr_val);
size_t len = dom_string_byte_length(atr_val);
if ((len >= vlen) &&
if ((len >= vlen) &&
(strncasecmp(data, lwc_string_data(value), vlen) == 0)) {
*match = true;
}
@ -1205,7 +1205,7 @@ css_error node_has_attribute_suffix(void *pw, void *node,
}
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -1226,10 +1226,10 @@ css_error node_has_attribute_suffix(void *pw, void *node,
if (*match == false) {
const char *data = (const char *) dom_string_data(atr_val);
size_t len = dom_string_byte_length(atr_val);
const char *start = (char *) data + len - vlen;
if ((len >= vlen) &&
if ((len >= vlen) &&
(strncasecmp(start, lwc_string_data(value), vlen) == 0)) {
*match = true;
}
@ -1273,7 +1273,7 @@ css_error node_has_attribute_substring(void *pw, void *node,
}
err = dom_string_create_interned(
(const uint8_t *) lwc_string_data(qname->name),
(const uint8_t *) lwc_string_data(qname->name),
lwc_string_length(qname->name), &name);
if (err != DOM_NO_ERR)
return CSS_NOMEM;
@ -1299,7 +1299,7 @@ css_error node_has_attribute_substring(void *pw, void *node,
if (len >= vlen) {
while (start <= last_start) {
if (strncasecmp(start, vdata,
if (strncasecmp(start, vdata,
vlen) == 0) {
*match = true;
break;
@ -1348,38 +1348,38 @@ css_error node_is_root(void *pw, void *node, bool *match)
if (type != DOM_DOCUMENT_NODE) {
*match = false;
return CSS_OK;
}
}
}
*match = true;
return CSS_OK;
}
static int
node_count_siblings_check(dom_node *node,
bool check_name,
static int
node_count_siblings_check(dom_node *node,
bool check_name,
dom_string *name)
{
dom_node_type type;
int ret = 0;
dom_exception exc;
if (node == NULL)
if (node == NULL)
return 0;
exc = dom_node_get_node_type(node, &type);
if ((exc != DOM_NO_ERR) || (type != DOM_ELEMENT_NODE)) {
return 0;
}
if (check_name) {
dom_string *node_name = NULL;
exc = dom_node_get_node_name(node, &node_name);
if ((exc == DOM_NO_ERR) && (node_name != NULL)) {
if (dom_string_caseless_isequal(name,
if (dom_string_caseless_isequal(name,
node_name)) {
ret = 1;
}
@ -1388,10 +1388,10 @@ node_count_siblings_check(dom_node *node,
} else {
ret = 1;
}
return ret;
}
/**
* Callback to count a node's siblings.
*
@ -1418,16 +1418,16 @@ css_error node_count_siblings(void *pw, void *n, bool same_name,
return CSS_NOMEM;
}
}
if (after) {
dom_node *node = dom_node_ref(n);
dom_node *next;
do {
exc = dom_node_get_next_sibling(node, &next);
if ((exc != DOM_NO_ERR))
break;
dom_node_unref(node);
node = next;
@ -1436,12 +1436,12 @@ css_error node_count_siblings(void *pw, void *n, bool same_name,
} else {
dom_node *node = dom_node_ref(n);
dom_node *next;
do {
exc = dom_node_get_previous_sibling(node, &next);
if ((exc != DOM_NO_ERR))
break;
dom_node_unref(node);
node = next;
@ -1451,7 +1451,7 @@ css_error node_count_siblings(void *pw, void *n, bool same_name,
}
if (node_name != NULL) {
dom_string_unref(node_name);
dom_string_unref(node_name);
}
*count = cnt;
@ -1472,14 +1472,14 @@ css_error node_is_empty(void *pw, void *node, bool *match)
{
dom_node *n = node, *next;
dom_exception err;
*match = true;
err = dom_node_get_first_child(n, &n);
if (err != DOM_NO_ERR) {
return CSS_BADPARM;
}
while (n != NULL) {
dom_node_type ntype;
err = dom_node_get_node_type(n, &ntype);
@ -1487,14 +1487,14 @@ css_error node_is_empty(void *pw, void *node, bool *match)
dom_node_unref(n);
return CSS_BADPARM;
}
if (ntype == DOM_ELEMENT_NODE ||
ntype == DOM_TEXT_NODE) {
*match = false;
dom_node_unref(n);
break;
}
err = dom_node_get_next_sibling(n, &next);
if (err != DOM_NO_ERR) {
dom_node_unref(n);
@ -1503,7 +1503,7 @@ css_error node_is_empty(void *pw, void *node, bool *match)
dom_node_unref(n);
n = next;
}
return CSS_OK;
}
@ -1531,7 +1531,7 @@ css_error node_is_link(void *pw, void *n, bool *match)
if (dom_string_caseless_lwc_isequal(node_name, corestring_lwc_a)) {
bool has_href;
exc = dom_element_has_attribute(node, corestring_dom_href,
&has_href);
&has_href);
if ((exc == DOM_NO_ERR) && (has_href)) {
*match = true;
} else {

View File

@ -23,7 +23,7 @@
#include <dom/dom.h>
#include "css/css.h"
#include <libcss/libcss.h>
struct content;
struct nsurl;
@ -52,6 +52,7 @@ css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
css_error named_ancestor_node(void *pw, void *node,
const css_qname *qname, void **ancestor);
css_error node_is_visited(void *pw, void *node, bool *match);
#endif

View File

@ -19,21 +19,15 @@
#include <assert.h>
#include "css/utils.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils.h"
/** Screen DPI in fixed point units: defaults to 90, which RISC OS uses */
css_fixed nscss_screen_dpi = F_90;
/**
* Convert an absolute CSS length to points.
*
* \param length Length to convert
* \param unit Corresponding unit
* \return length in points
*/
/* exported interface documented in content/handlers/css/utils.h */
css_fixed nscss_len2pt(css_fixed length, css_unit unit)
{
/* Length must not be relative */
@ -46,10 +40,10 @@ css_fixed nscss_len2pt(css_fixed length, css_unit unit)
/* 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,
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,
case CSS_UNIT_MM: return FMUL(length,
FDIV(F_72, FLTTOFIX(25.4)));
case CSS_UNIT_PT: return length;
/* 1pc = 12pt */
@ -61,16 +55,8 @@ css_fixed nscss_len2pt(css_fixed length, css_unit unit)
}
/**
* Convert a CSS length to pixels.
*
* \param length Length to convert
* \param unit Corresponding unit
* \param style Computed style applying to length. May be NULL if unit is
* neither em nor ex
* \return length in pixels
*/
css_fixed nscss_len2px(css_fixed length, css_unit unit,
/* exported interface documented in content/handlers/css/utils.h */
css_fixed nscss_len2px(css_fixed length, css_unit unit,
const css_computed_style *style)
{
/* We assume the screen and any other output has the same dpi */
@ -95,7 +81,7 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10);
}
/* Convert to pixels (manually, to maximise precision)
/* Convert to pixels (manually, to maximise precision)
* 1in = 72pt => 1pt = (DPI/72)px */
px_per_unit = FDIV(FMUL(font_size, nscss_screen_dpi), F_72);
@ -104,27 +90,27 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6));
}
break;
case CSS_UNIT_PX:
case CSS_UNIT_PX:
px_per_unit = F_1;
break;
/* 1in = DPIpx */
case CSS_UNIT_IN:
case CSS_UNIT_IN:
px_per_unit = nscss_screen_dpi;
break;
/* 1in = 2.54cm => 1cm = (DPI/2.54)px */
case CSS_UNIT_CM:
case CSS_UNIT_CM:
px_per_unit = FDIV(nscss_screen_dpi, FLTTOFIX(2.54));
break;
/* 1in = 25.4mm => 1mm = (DPI/25.4)px */
case CSS_UNIT_MM:
case CSS_UNIT_MM:
px_per_unit = FDIV(nscss_screen_dpi, FLTTOFIX(25.4));
break;
/* 1in = 72pt => 1pt = (DPI/72)px */
case CSS_UNIT_PT:
case CSS_UNIT_PT:
px_per_unit = FDIV(nscss_screen_dpi, F_72);
break;
/* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */
case CSS_UNIT_PC:
case CSS_UNIT_PC:
px_per_unit = FDIV(nscss_screen_dpi, INTTOFIX(6));
break;
default:
@ -139,4 +125,3 @@ css_fixed nscss_len2px(css_fixed length, css_unit unit,
/* Calculate total number of pixels */
return FMUL(length, TRUNCATEFIX(px_per_unit));
}

View File

@ -0,0 +1,49 @@
/*
* 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/>.
*/
#ifndef NETSURF_CSS_UTILS_H_
#define NETSURF_CSS_UTILS_H_
#include <libcss/libcss.h>
#include "netsurf/css.h"
/** DPI of the screen, in fixed point units */
extern css_fixed nscss_screen_dpi;
/**
* Convert an absolute CSS length to points.
*
* \param[in] length Absolute CSS length.
* \param[in] unit Unit of the length.
* \return length in points
*/
css_fixed nscss_len2pt(css_fixed length, css_unit unit);
/**
* Convert a CSS length to pixels.
*
* \param length Length to convert
* \param unit Corresponding unit
* \param style Computed style applying to length. May be NULL if unit is
* neither em nor ex
* \return length in pixels
*/
css_fixed nscss_len2px(css_fixed length, css_unit unit, const css_computed_style *style);
#endif

View File

@ -12,4 +12,4 @@ S_IMAGE_$(NETSURF_USE_NSSVG) += svg.c
S_IMAGE_$(NETSURF_USE_RSVG) += rsvg.c
S_IMAGE_$(NETSURF_USE_VIDEO) += video.c
S_IMAGE := $(addprefix image/,$(S_IMAGE_YES))
S_IMAGE := $(S_IMAGE_YES)

View File

@ -23,13 +23,13 @@
#include <assert.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <svgtiny.h>
#include "utils/messages.h"
#include "utils/utils.h"
#include "content/content_protected.h"
#include "css/css.h"
#include "desktop/plotters.h"
#include "svg.h"

View File

@ -52,11 +52,11 @@
#include "content/fetch.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "content/handlers/css/utils.h"
#include "render/form_internal.h"
#include "render/html.h"
#include "render/box.h"
#include "curl/curl.h"
#include "css/utils.h"
#include "javascript/js.h"
#include "desktop/browser_history.h"

View File

@ -34,7 +34,6 @@
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "css/css.h"
#include "content/handlers/image/bitmap.h"
#include "desktop/gui_layout.h"

View File

@ -36,9 +36,6 @@
#include <hpdf.h>
#include "css/css.h"
#include "css/utils.h"
#include "utils/nsoption.h"
#include "desktop/save_pdf/font_haru.h"
#include "desktop/font.h"

View File

@ -37,7 +37,7 @@
#include "content/hlcache.h"
#include "content/mimesniff.h"
#include "content/urldb.h"
#include "css/css.h"
#include "content/handlers/css/css.h"
#include "content/handlers/image/image.h"
#include "content/handlers/image/image_cache.h"
#include "javascript/js.h"

View File

@ -32,7 +32,7 @@
#include "utils/talloc.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "css/utils.h"
#include "content/handlers/css/utils.h"
#include "render/box.h"
#include "desktop/plotters.h"

View File

@ -33,8 +33,7 @@
#define NETSURF_DESKTOP_PRINT_H
#include <stdbool.h>
#include "css/css.h"
#include <libcss/libcss.h>
struct hlcache_handle;
struct printer;

View File

@ -41,7 +41,7 @@
#include "utils/messages.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "css/css.h"
#include "content/handlers/css/css.h"
#include "render/box.h"
#include "render/html.h"

View File

@ -44,6 +44,7 @@
*/
#include "utils/config.h"
#include "utils/errors.h"
#include "desktop/save_pdf.h"
@ -52,18 +53,18 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <hpdf.h>
#include "content/hlcache.h"
#include "utils/nsoption.h"
#include "desktop/plotters.h"
#include "desktop/print.h"
#include "desktop/printer.h"
#include "content/handlers/image/bitmap.h"
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/useragent.h"
#include "content/hlcache.h"
#include "utils/nsoption.h"
#include "content/handlers/image/bitmap.h"
#include "desktop/plotters.h"
#include "desktop/print.h"
#include "desktop/printer.h"
#include "font_haru.h"

View File

@ -26,10 +26,10 @@
#include "utils/config.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "css/utils.h"
#include "desktop/system_colour.h"
#include "utils/nsoption.h"
#include "netsurf/css.h"
#include "desktop/system_colour.h"
#define colour_list_len ((NSOPTION_SYS_COLOUR_END - NSOPTION_SYS_COLOUR_START) + 1)

View File

@ -26,10 +26,10 @@
#include <stdint.h>
#include <string.h>
#include "css/utils.h"
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "content/handlers/css/utils.h"
#include "desktop/browser.h"
#include "desktop/mouse.h"

View File

@ -32,7 +32,6 @@
#include "utils/utils.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "css/utils.h"
#include "utils/nsoption.h"
#include "desktop/browser.h"

View File

@ -23,9 +23,9 @@
*/
#include "utils/log.h"
#include "css/utils.h"
#include "content/handlers/image/bitmap.h"
#include "content/hlcache.h"
#include "content/handlers/css/utils.h"
#include "desktop/system_colour.h"
#include "desktop/knockout.h"

View File

@ -37,7 +37,7 @@
#include "utils/nsoption.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "css/utils.h"
#include "netsurf/css.h"
#include "desktop/mouse.h"
#include "desktop/gui_window.h"

View File

@ -16,14 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NETSURF_CSS_UTILS_H_
#define NETSURF_CSS_UTILS_H_
/**
* \file
* Netsurf core css API
*/
#include "css/css.h"
#include "desktop/plot_style.h"
/* DPI of the screen, in fixed point units */
extern css_fixed nscss_screen_dpi;
#ifndef NETSURF_CSS_H_
#define NETSURF_CSS_H_
/**
* Convert a CSS color to a NetSurf colour primitive
@ -63,8 +62,4 @@ extern css_fixed nscss_screen_dpi;
#define nscss_color_is_transparent(color) \
(((color) >> 24) == 0)
css_fixed nscss_len2pt(css_fixed length, css_unit unit);
css_fixed nscss_len2px(css_fixed length, css_unit unit,
const css_computed_style *style);
#endif

View File

@ -35,9 +35,8 @@
#include "utils/utils.h"
#include "content/content_protected.h"
#include "content/hlcache.h"
#include "css/css.h"
#include "css/utils.h"
#include "css/dump.h"
#include "content/handlers/css/utils.h"
#include "content/handlers/css/dump.h"
#include "desktop/scrollbar.h"
#include "desktop/gui_misc.h"
#include "desktop/gui_internal.h"

View File

@ -89,8 +89,7 @@
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include "css/css.h"
#include <libcss/libcss.h>
struct content;
struct box;

View File

@ -43,10 +43,9 @@
#include "utils/utils.h"
#include "utils/string.h"
#include "content/content_protected.h"
#include "css/css.h"
#include "css/hints.h"
#include "css/select.h"
#include "css/utils.h"
#include "content/handlers/css/hints.h"
#include "content/handlers/css/select.h"
#include "netsurf/css.h"
#include "desktop/gui_misc.h"
#include "desktop/gui_internal.h"

View File

@ -26,12 +26,14 @@
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include "css/css.h"
#include "css/select.h"
#include "utils/log.h"
#include "utils/errors.h"
#include "content/handlers/css/select.h"
#include "render/box.h"
#include "render/html_internal.h"
#include "render/table.h"
#include "utils/log.h"
/* Define to enable box normalise debug */
#undef BOX_NORMALISE_DEBUG

View File

@ -22,9 +22,8 @@
* Renderer internal font handling implementation.
*/
#include "css/css.h"
#include "css/utils.h"
#include "utils/nsoption.h"
#include "content/handlers/css/utils.h"
#include "render/font.h"

View File

@ -42,8 +42,7 @@
#include "utils/utils.h"
#include "content/fetch.h"
#include "content/hlcache.h"
#include "css/css.h"
#include "css/utils.h"
#include "content/handlers/css/utils.h"
#include "desktop/browser.h"
#include "desktop/mouse.h"
#include "desktop/knockout.h"

View File

@ -31,7 +31,6 @@
#include <dom/bindings/hubbub/parser.h>
#include "content/content_type.h"
#include "css/css.h"
#include "desktop/browser.h"
#include "desktop/mouse.h"
#include "desktop/plot_style.h"

View File

@ -28,6 +28,7 @@
#include <stdlib.h>
#include "content/hlcache.h"
#include "content/handlers/css/css.h"
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/config.h"

View File

@ -16,13 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
/**
* \file
* Content for text/html (private data).
*/
#ifndef NETSURF_RENDER_HTML_INTERNAL_H_
#define NETSURF_RENDER_HTML_INTERNAL_H_
#include <libcss/libcss.h>
#include "content/content_protected.h"
#include "desktop/selection.h"
#include "render/html.h"

View File

@ -33,7 +33,7 @@
#include "utils/log.h"
#include "utils/nsoption.h"
#include "content/hlcache.h"
#include "css/utils.h"
#include "content/handlers/css/utils.h"
#include "desktop/scrollbar.h"
#include "desktop/gui_misc.h"
#include "desktop/gui_internal.h"

View File

@ -41,8 +41,7 @@
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "content/content_protected.h"
#include "css/css.h"
#include "css/utils.h"
#include "content/handlers/css/utils.h"
#include "desktop/browser.h"
#include "desktop/plotters.h"
#include "desktop/selection.h"

View File

@ -46,10 +46,9 @@
#include "utils/log.h"
#include "utils/talloc.h"
#include "utils/utils.h"
#include "css/css.h"
#include "css/utils.h"
#include "content/content_protected.h"
#include "utils/nsoption.h"
#include "content/content_protected.h"
#include "content/handlers/css/utils.h"
#include "desktop/browser.h"
#include "desktop/scrollbar.h"
#include "desktop/textarea.h"

View File

@ -22,15 +22,14 @@
*/
#include <assert.h>
#include <dom/dom.h>
#include "css/css.h"
#include "css/utils.h"
#include "render/box.h"
#include "render/table.h"
#include "utils/log.h"
#include "utils/talloc.h"
#include "content/handlers/css/utils.h"
#include "render/box.h"
#include "render/table.h"
/* Define to enable verbose table debug */
#undef TABLE_DEBUG

View File

@ -39,8 +39,7 @@
#include "utils/utf8.h"
#include "content/content_protected.h"
#include "content/hlcache.h"
#include "css/css.h"
#include "css/utils.h"
#include "content/handlers/css/utils.h"
#include "desktop/browser.h"
#include "utils/nsoption.h"
#include "desktop/plotters.h"