summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libcss/bloom.h205
-rw-r--r--include/libcss/computed.h3
-rw-r--r--include/libcss/functypes.h3
-rw-r--r--include/libcss/libcss.h1
-rw-r--r--include/libcss/select.h74
-rw-r--r--include/libcss/stylesheet.h1
6 files changed, 65 insertions, 222 deletions
diff --git a/include/libcss/bloom.h b/include/libcss/bloom.h
deleted file mode 100644
index 8c1da3f..0000000
--- a/include/libcss/bloom.h
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * This file is part of LibCSS.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2013 Michael Drake <tlsa@netsurf-browser.org>
- */
-
-/** \file
- * Bloom filter for CSS style selection optimisation.
- *
- * Attempting to match CSS rules by querying the client about DOM nodes via
- * the selection callbacks is slow. To avoid this, clients may pass a node
- * bloom filter to css_get_style. This bloom filter has bits set according
- * to the node's ancestor element names, class names and id names.
- *
- * Generate the bloom filter by adding calling css_bloom_add_hash() on each
- * ancestor element name, class name and id name for the node.
- *
- * Use the insesnsitive lwc_string:
- *
- * lwc_string_hash_value(str->insensitive)
- */
-
-#ifndef libcss_bloom_h_
-#define libcss_bloom_h_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include <stdint.h>
-
-/* Size of bloom filter as multiple of 32 bits.
- * Has to be 4, 8, or 16.
- * Larger increases optimisation of style selection engine but uses more memory.
- */
-#define CSS_BLOOM_SIZE 4
-
-
-
-/* Check valid bloom filter size */
-#if !(CSS_BLOOM_SIZE == 4 || CSS_BLOOM_SIZE == 8 || CSS_BLOOM_SIZE == 16)
-# error Unsupported bloom filter size. Size must be {4|8|16}.
-#endif
-
-/* Setup index bit mask */
-#define INDEX_BITS_N (CSS_BLOOM_SIZE - 1)
-
-
-
-/* type for bloom */
-typedef uint32_t css_bloom;
-
-
-/**
- * Add a hash value to the bloom filter.
- *
- * \param bloom bloom filter to insert into
- * \param hash libwapcaplet hash value to insert
- */
-static inline void css_bloom_add_hash(css_bloom bloom[CSS_BLOOM_SIZE],
- lwc_hash hash)
-{
- unsigned int bit = hash & 0x1f; /* Top 5 bits */
- unsigned int index = (hash >> 5) & INDEX_BITS_N; /* Next N bits */
-
- bloom[index] |= (1 << bit);
-}
-
-
-/**
- * Test whether bloom filter contains given hash value.
- *
- * \param bloom bloom filter to check inside
- * \param hash libwapcaplet hash value to look for
- * \return true hash value is already set in bloom
- */
-static inline bool css_bloom_has_hash(const css_bloom bloom[CSS_BLOOM_SIZE],
- lwc_hash hash)
-{
- unsigned int bit = hash & 0x1f; /* Top 5 bits */
- unsigned int index = (hash >> 5) & INDEX_BITS_N; /* Next N bits */
-
- return (bloom[index] & (1 << bit));
-}
-
-
-/**
- * Test whether bloom 'a' is a subset of bloom 'b'.
- *
- * \param a potential subset bloom to test
- * \param b superset bloom
- * \return true iff 'a' is subset of 'b'
- */
-static inline bool css_bloom_in_bloom(const css_bloom a[CSS_BLOOM_SIZE],
- const css_bloom b[CSS_BLOOM_SIZE])
-{
- if ((a[0] & b[0]) != a[0])
- return false;
- if ((a[1] & b[1]) != a[1])
- return false;
- if ((a[2] & b[2]) != a[2])
- return false;
- if ((a[3] & b[3]) != a[3])
- return false;
-#if (CSS_BLOOM_SIZE > 4)
- if ((a[4] & b[4]) != a[4])
- return false;
- if ((a[5] & b[5]) != a[5])
- return false;
- if ((a[6] & b[6]) != a[6])
- return false;
- if ((a[7] & b[7]) != a[7])
- return false;
-#endif
-#if (CSS_BLOOM_SIZE > 8)
- if ((a[8] & b[8]) != a[8])
- return false;
- if ((a[9] & b[9]) != a[9])
- return false;
- if ((a[10] & b[10]) != a[10])
- return false;
- if ((a[11] & b[11]) != a[11])
- return false;
- if ((a[12] & b[12]) != a[12])
- return false;
- if ((a[13] & b[13]) != a[13])
- return false;
- if ((a[14] & b[14]) != a[14])
- return false;
- if ((a[15] & b[15]) != a[15])
- return false;
-#endif
- return true;
-}
-
-
-/**
- * Merge bloom 'a' into bloom 'b'.
- *
- * \param a bloom to insert
- * \param b target bloom
- */
-static inline void css_bloom_merge(const css_bloom a[CSS_BLOOM_SIZE],
- css_bloom b[CSS_BLOOM_SIZE])
-{
- b[0] |= a[0];
- b[1] |= a[1];
- b[2] |= a[2];
- b[3] |= a[3];
-#if (CSS_BLOOM_SIZE > 4)
- b[4] |= a[4];
- b[5] |= a[5];
- b[6] |= a[6];
- b[7] |= a[7];
-#endif
-#if (CSS_BLOOM_SIZE > 8)
- b[8] |= a[8];
- b[9] |= a[9];
- b[10] |= a[10];
- b[11] |= a[11];
- b[12] |= a[12];
- b[13] |= a[13];
- b[14] |= a[14];
- b[15] |= a[15];
-#endif
-}
-
-
-/**
- * Initialise a bloom filter to 0
- *
- * \param bloom bloom filter to initialise
- */
-static inline void css_bloom_init(css_bloom bloom[CSS_BLOOM_SIZE])
-{
- bloom[0] = 0;
- bloom[1] = 0;
- bloom[2] = 0;
- bloom[3] = 0;
-#if (CSS_BLOOM_SIZE > 4)
- bloom[4] = 0;
- bloom[5] = 0;
- bloom[6] = 0;
- bloom[7] = 0;
-#endif
-#if (CSS_BLOOM_SIZE > 8)
- bloom[8] = 0;
- bloom[9] = 0;
- bloom[10] = 0;
- bloom[11] = 0;
- bloom[12] = 0;
- bloom[13] = 0;
- bloom[14] = 0;
- bloom[15] = 0;
-#endif
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 6e04e61..324af3f 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -76,8 +76,7 @@ typedef struct css_computed_content_item {
} data;
} css_computed_content_item;
-css_error css_computed_style_create(css_allocator_fn alloc, void *pw,
- css_computed_style **result);
+css_error css_computed_style_create(css_computed_style **result);
css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_initialise(css_computed_style *style,
diff --git a/include/libcss/functypes.h b/include/libcss/functypes.h
index 2acd44a..68a3f09 100644
--- a/include/libcss/functypes.h
+++ b/include/libcss/functypes.h
@@ -19,9 +19,6 @@ extern "C"
#include <libcss/types.h>
-/* Type of allocation function for libcss */
-typedef void *(*css_allocator_fn)(void *ptr, size_t size, void *pw);
-
#ifdef __cplusplus
}
#endif
diff --git a/include/libcss/libcss.h b/include/libcss/libcss.h
index bde2707..89e83b5 100644
--- a/include/libcss/libcss.h
+++ b/include/libcss/libcss.h
@@ -15,7 +15,6 @@ extern "C"
#include <libwapcaplet/libwapcaplet.h>
-#include <libcss/bloom.h>
#include <libcss/errors.h>
#include <libcss/types.h>
#include <libcss/functypes.h>
diff --git a/include/libcss/select.h b/include/libcss/select.h
index 9ab2550..d504e81 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -13,7 +13,6 @@ extern "C"
{
#endif
-#include <libcss/bloom.h>
#include <libcss/errors.h>
#include <libcss/functypes.h>
#include <libcss/hint.h>
@@ -34,9 +33,6 @@ typedef enum css_pseudo_element {
* Style selection result set
*/
typedef struct css_select_results {
- css_allocator_fn alloc;
- void *pw;
-
/**
* Array of pointers to computed styles,
* indexed by css_pseudo_element. If there
@@ -129,15 +125,37 @@ typedef struct css_select_handler {
css_error (*compute_font_size)(void *pw, const css_hint *parent,
css_hint *size);
+
+ /**
+ * Set libcss_node_data on a DOM node.
+ *
+ * Replaces any existing libcss_node_data. If node is deleted, cloned,
+ * or its ancestors are modified, call css_libcss_node_data_handler for
+ * any non-NULL libcss_node_data.
+ *
+ * \param pw Client data
+ * \param node DOM node to set data for
+ * \param libcss_node_data Data to set on node, or NULL
+ * \return CSS_OK on success, or appropriate error otherwise
+ */
+ css_error (*set_libcss_node_data)(void *pw, void *node,
+ void *libcss_node_data);
+ /**
+ * Get libcss_node_data from a DOM node.
+ *
+ * \param pw Client data
+ * \param node DOM node to get data from
+ * \param libcss_node_data Updated to node data, else set to NULL.
+ * \return CSS_OK on success, or appropriate error otherwise
+ */
+ css_error (*get_libcss_node_data)(void *pw, void *node,
+ void **libcss_node_data);
} css_select_handler;
/**
* Font face selection result set
*/
typedef struct css_select_font_faces_results {
- css_allocator_fn alloc;
- void *pw;
-
/**
* Array of pointers to computed font faces.
*/
@@ -145,8 +163,45 @@ typedef struct css_select_font_faces_results {
uint32_t n_font_faces;
} css_select_font_faces_results;
-css_error css_select_ctx_create(css_allocator_fn alloc, void *pw,
- css_select_ctx **result);
+typedef enum {
+ CSS_NODE_DELETED,
+ CSS_NODE_MODIFIED,
+ CSS_NODE_ANCESTORS_MODIFIED,
+ CSS_NODE_CLONED
+} css_node_data_action;
+
+/**
+ * Handle libcss_node_data on DOM changes/deletion.
+ *
+ * When a DOM node is deleted, if it has libcss_node_data, call with
+ * action CSS_NODE_DELETED, to ensure the libcss_node_data is not leaked.
+ * Does not call handler->set_libcss_node_data.
+ *
+ * When a DOM node is modified, if the node has libcss_node_data,
+ * call with CSS_NODE_MODIFIED. This will result in a call to
+ * handler->set_libcss_node_data for the node.
+ *
+ * When a DOM node's ancestors are modified, if the node has libcss_node_data,
+ * call with CSS_NODE_ANCESTORS_MODIFIED. This will result in a call to
+ * handler->set_libcss_node_data for the node.
+ *
+ * When a DOM node with libcss_node_data is cloned, and its ancestors are
+ * also clones, call with CSS_NODE_CLONED. This will result in a call to
+ * handler->set_libcss_node_data for the clone node.
+ *
+ * \param handler Selection handler vtable
+ * \param action Type of node action.
+ * \param pw Client data
+ * \param node DOM node to get data from
+ * \param clone_node Clone node, or NULL
+ * \param libcss_node_data Node data (non-NULL)
+ * \return CSS_OK on success, or appropriate error otherwise
+ */
+css_error css_libcss_node_data_handler(css_select_handler *handler,
+ css_node_data_action action, void *pw, void *node,
+ void *clone_node, void *libcss_node_data);
+
+css_error css_select_ctx_create(css_select_ctx **result);
css_error css_select_ctx_destroy(css_select_ctx *ctx);
css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
@@ -163,7 +218,6 @@ css_error css_select_ctx_get_sheet(css_select_ctx *ctx, uint32_t index,
const css_stylesheet **sheet);
css_error css_select_style(css_select_ctx *ctx, void *node,
- const css_bloom bloom[CSS_BLOOM_SIZE],
uint64_t media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
diff --git a/include/libcss/stylesheet.h b/include/libcss/stylesheet.h
index 86a0917..f92d870 100644
--- a/include/libcss/stylesheet.h
+++ b/include/libcss/stylesheet.h
@@ -137,7 +137,6 @@ typedef struct css_stylesheet_params {
} css_stylesheet_params;
css_error css_stylesheet_create(const css_stylesheet_params *params,
- css_allocator_fn alloc, void *alloc_pw,
css_stylesheet **stylesheet);
css_error css_stylesheet_destroy(css_stylesheet *sheet);