2009-07-24 03:05:34 +04:00
|
|
|
/*
|
|
|
|
* 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>
|
2009-09-05 19:49:09 +04:00
|
|
|
#include <stdbool.h>
|
2009-07-24 03:05:34 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/content_protected.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "content/urldb.h"
|
2014-01-10 18:32:29 +04:00
|
|
|
#include "desktop/system_colour.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2012-07-22 18:48:55 +04:00
|
|
|
#include "utils/corestrings.h"
|
2009-10-12 21:38:22 +04:00
|
|
|
#include "utils/log.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "utils/utils.h"
|
|
|
|
|
2014-05-09 13:15:42 +04:00
|
|
|
#include "css/internal.h"
|
|
|
|
#include "css/select.h"
|
|
|
|
#include "css/utils.h"
|
|
|
|
|
2013-12-01 23:15:14 +04:00
|
|
|
#undef PRINT_NODE_BLOOM_DETAILS
|
|
|
|
|
2011-03-12 20:51:59 +03:00
|
|
|
static css_error node_name(void *pw, void *node, css_qname *qname);
|
2009-07-29 13:59:29 +04:00
|
|
|
static css_error node_classes(void *pw, void *node,
|
2010-03-28 16:56:39 +04:00
|
|
|
lwc_string ***classes, uint32_t *n_classes);
|
|
|
|
static css_error node_id(void *pw, void *node, lwc_string **id);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error named_ancestor_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **ancestor);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error named_parent_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **parent);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error named_sibling_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **sibling);
|
2011-01-31 11:49:39 +03:00
|
|
|
static css_error named_generic_sibling_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **sibling);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error parent_node(void *pw, void *node, void **parent);
|
|
|
|
static css_error sibling_node(void *pw, void *node, void **sibling);
|
|
|
|
static css_error node_has_name(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, bool *match);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error node_has_class(void *pw, void *node,
|
|
|
|
lwc_string *name, bool *match);
|
|
|
|
static css_error node_has_id(void *pw, void *node,
|
|
|
|
lwc_string *name, bool *match);
|
|
|
|
static css_error node_has_attribute(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, bool *match);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error node_has_attribute_equal(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2009-07-24 03:05:34 +04:00
|
|
|
bool *match);
|
|
|
|
static css_error node_has_attribute_dashmatch(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2009-07-24 03:05:34 +04:00
|
|
|
bool *match);
|
|
|
|
static css_error node_has_attribute_includes(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2009-07-24 03:05:34 +04:00
|
|
|
bool *match);
|
2011-01-31 11:49:39 +03:00
|
|
|
static css_error node_has_attribute_prefix(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool *match);
|
|
|
|
static css_error node_has_attribute_suffix(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool *match);
|
|
|
|
static css_error node_has_attribute_substring(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool *match);
|
|
|
|
static css_error node_is_root(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_count_siblings(void *pw, void *node,
|
|
|
|
bool same_name, bool after, int32_t *count);
|
|
|
|
static css_error node_is_empty(void *pw, void *node, bool *match);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error node_is_link(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_visited(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_hover(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_active(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_focus(void *pw, void *node, bool *match);
|
2011-01-31 11:49:39 +03:00
|
|
|
static css_error node_is_enabled(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_disabled(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_checked(void *pw, void *node, bool *match);
|
|
|
|
static css_error node_is_target(void *pw, void *node, bool *match);
|
2009-07-24 03:05:34 +04:00
|
|
|
static css_error node_is_lang(void *pw, void *node,
|
|
|
|
lwc_string *lang, bool *match);
|
|
|
|
static css_error node_presentational_hint(void *pw, void *node,
|
|
|
|
uint32_t property, css_hint *hint);
|
|
|
|
static css_error ua_default_for_property(void *pw, uint32_t property,
|
|
|
|
css_hint *hint);
|
2013-12-14 00:25:08 +04:00
|
|
|
static css_error set_libcss_node_data(void *pw, void *node,
|
|
|
|
void *libcss_node_data);
|
|
|
|
static css_error get_libcss_node_data(void *pw, void *node,
|
|
|
|
void **libcss_node_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
static int cmp_colour_name(const void *a, const void *b);
|
|
|
|
static bool parse_named_colour(const char *data, css_color *result);
|
|
|
|
static bool parse_dimension(const char *data, bool strict,
|
|
|
|
css_fixed *length, css_unit *unit);
|
|
|
|
static bool parse_number(const char *data, bool non_negative, bool real,
|
|
|
|
css_fixed *value, size_t *consumed);
|
2011-09-01 01:12:57 +04:00
|
|
|
static bool parse_font_size(const char *size, uint8_t *val,
|
|
|
|
css_fixed *len, css_unit *unit);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
static bool isWhitespace(char c);
|
|
|
|
static bool isHex(char c);
|
|
|
|
static uint8_t charToHex(char c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selection callback table for libcss
|
|
|
|
*/
|
|
|
|
static css_select_handler selection_handler = {
|
2011-03-13 12:32:13 +03:00
|
|
|
CSS_SELECT_HANDLER_VERSION_1,
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
node_name,
|
2009-07-29 13:59:29 +04:00
|
|
|
node_classes,
|
|
|
|
node_id,
|
2009-07-24 03:05:34 +04:00
|
|
|
named_ancestor_node,
|
|
|
|
named_parent_node,
|
|
|
|
named_sibling_node,
|
2011-01-31 11:49:39 +03:00
|
|
|
named_generic_sibling_node,
|
2009-07-24 03:05:34 +04:00
|
|
|
parent_node,
|
|
|
|
sibling_node,
|
|
|
|
node_has_name,
|
|
|
|
node_has_class,
|
|
|
|
node_has_id,
|
|
|
|
node_has_attribute,
|
|
|
|
node_has_attribute_equal,
|
|
|
|
node_has_attribute_dashmatch,
|
|
|
|
node_has_attribute_includes,
|
2011-01-31 11:49:39 +03:00
|
|
|
node_has_attribute_prefix,
|
|
|
|
node_has_attribute_suffix,
|
|
|
|
node_has_attribute_substring,
|
|
|
|
node_is_root,
|
|
|
|
node_count_siblings,
|
|
|
|
node_is_empty,
|
2009-07-24 03:05:34 +04:00
|
|
|
node_is_link,
|
|
|
|
node_is_visited,
|
|
|
|
node_is_hover,
|
|
|
|
node_is_active,
|
|
|
|
node_is_focus,
|
2011-01-31 11:49:39 +03:00
|
|
|
node_is_enabled,
|
|
|
|
node_is_disabled,
|
|
|
|
node_is_checked,
|
|
|
|
node_is_target,
|
2009-07-24 03:05:34 +04:00
|
|
|
node_is_lang,
|
|
|
|
node_presentational_hint,
|
|
|
|
ua_default_for_property,
|
2013-12-14 00:25:08 +04:00
|
|
|
nscss_compute_font_size,
|
|
|
|
set_libcss_node_data,
|
|
|
|
get_libcss_node_data
|
2009-07-24 03:05:34 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an inline style
|
|
|
|
*
|
|
|
|
* \param data Source data
|
|
|
|
* \param len Length of data in bytes
|
|
|
|
* \param charset Charset of data, or NULL if unknown
|
2014-09-18 21:07:52 +04:00
|
|
|
* \param url Base URL of document containing data
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param allow_quirks True to permit CSS parsing quirks
|
|
|
|
* \return Pointer to stylesheet, or NULL on failure.
|
|
|
|
*/
|
|
|
|
css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,
|
2013-12-14 00:25:08 +04:00
|
|
|
const char *charset, const char *url, bool allow_quirks)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2011-01-29 17:53:18 +03:00
|
|
|
css_stylesheet_params params;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_stylesheet *sheet;
|
|
|
|
css_error error;
|
|
|
|
|
2011-03-13 12:32:13 +03:00
|
|
|
params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
|
2011-01-29 17:53:18 +03:00
|
|
|
params.level = CSS_LEVEL_DEFAULT;
|
|
|
|
params.charset = charset;
|
|
|
|
params.url = url;
|
|
|
|
params.title = NULL;
|
|
|
|
params.allow_quirks = allow_quirks;
|
|
|
|
params.inline_style = true;
|
|
|
|
params.resolve = nscss_resolve_url;
|
|
|
|
params.resolve_pw = NULL;
|
|
|
|
params.import = NULL;
|
|
|
|
params.import_pw = NULL;
|
2014-01-10 18:32:29 +04:00
|
|
|
params.color = ns_system_colour;
|
2011-01-29 17:53:18 +03:00
|
|
|
params.color_pw = NULL;
|
2011-02-03 12:31:11 +03:00
|
|
|
params.font = NULL;
|
|
|
|
params.font_pw = NULL;
|
2011-01-29 17:53:18 +03:00
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
error = css_stylesheet_create(¶ms, &sheet);
|
2009-10-12 21:38:22 +04:00
|
|
|
if (error != CSS_OK) {
|
|
|
|
LOG(("Failed creating sheet: %d", error));
|
2009-07-24 03:05:34 +04:00
|
|
|
return NULL;
|
2009-10-12 21:38:22 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
error = css_stylesheet_append_data(sheet, data, len);
|
|
|
|
if (error != CSS_OK && error != CSS_NEEDDATA) {
|
2009-10-12 21:38:22 +04:00
|
|
|
LOG(("failed appending data: %d", error));
|
2009-07-24 03:05:34 +04:00
|
|
|
css_stylesheet_destroy(sheet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = css_stylesheet_data_done(sheet);
|
|
|
|
if (error != CSS_OK) {
|
2009-10-12 21:38:22 +04:00
|
|
|
LOG(("failed completing parse: %d", error));
|
2009-07-24 03:05:34 +04:00
|
|
|
css_stylesheet_destroy(sheet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
/* Handler for libcss_node_data, stored as libdom node user data */
|
2013-12-01 23:15:14 +04:00
|
|
|
static void nscss_dom_user_data_handler(dom_node_operation operation,
|
|
|
|
dom_string *key, void *data, struct dom_node *src,
|
|
|
|
struct dom_node *dst)
|
|
|
|
{
|
2013-12-14 00:25:08 +04:00
|
|
|
css_error error;
|
2013-12-01 23:15:14 +04:00
|
|
|
|
2014-01-04 20:26:02 +04:00
|
|
|
if (dom_string_isequal(corestring_dom___ns_key_libcss_node_data,
|
|
|
|
key) == false || data == NULL) {
|
2013-12-01 23:15:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (operation) {
|
|
|
|
case DOM_NODE_CLONED:
|
2013-12-14 00:25:08 +04:00
|
|
|
error = css_libcss_node_data_handler(&selection_handler,
|
|
|
|
CSS_NODE_CLONED,
|
|
|
|
NULL, src, dst, data);
|
|
|
|
if (error != CSS_OK)
|
|
|
|
LOG(("Failed to clone libcss_node_data."));
|
|
|
|
break;
|
|
|
|
|
2013-12-01 23:15:14 +04:00
|
|
|
case DOM_NODE_RENAMED:
|
2013-12-14 00:25:08 +04:00
|
|
|
error = css_libcss_node_data_handler(&selection_handler,
|
|
|
|
CSS_NODE_MODIFIED,
|
|
|
|
NULL, src, NULL, data);
|
|
|
|
if (error != CSS_OK)
|
|
|
|
LOG(("Failed to update libcss_node_data."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_IMPORTED:
|
2013-12-01 23:15:14 +04:00
|
|
|
case DOM_NODE_ADOPTED:
|
|
|
|
case DOM_NODE_DELETED:
|
2013-12-14 00:25:08 +04:00
|
|
|
error = css_libcss_node_data_handler(&selection_handler,
|
|
|
|
CSS_NODE_DELETED,
|
|
|
|
NULL, src, NULL, data);
|
|
|
|
if (error != CSS_OK)
|
|
|
|
LOG(("Failed to delete libcss_node_data."));
|
2013-12-01 23:15:14 +04:00
|
|
|
break;
|
2013-12-14 00:25:08 +04:00
|
|
|
|
2013-12-01 23:15:14 +04:00
|
|
|
default:
|
|
|
|
LOG(("User data operation not handled."));
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
2013-12-19 18:21:15 +04:00
|
|
|
* Get style selection results for an element
|
2009-07-24 03:05:34 +04:00
|
|
|
*
|
2011-05-07 00:40:09 +04:00
|
|
|
* \param ctx CSS selection context
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param n Element to select for
|
|
|
|
* \param media Permitted media types
|
|
|
|
* \param inline_style Inline style associated with element, or NULL
|
2013-12-19 18:21:15 +04:00
|
|
|
* \return Pointer to selection results (containing computed styles),
|
2011-01-05 22:36:05 +03:00
|
|
|
* or NULL on failure
|
2009-07-24 03:05:34 +04:00
|
|
|
*/
|
2012-03-24 22:48:14 +04:00
|
|
|
css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n,
|
2013-12-14 00:25:08 +04:00
|
|
|
uint64_t media, const css_stylesheet *inline_style)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2011-01-05 22:36:05 +03:00
|
|
|
css_select_results *styles;
|
2013-12-19 18:21:15 +04:00
|
|
|
int pseudo_element;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_error error;
|
|
|
|
|
2013-12-01 23:15:14 +04:00
|
|
|
/* Select style for node */
|
2013-12-14 00:25:08 +04:00
|
|
|
error = css_select_style(ctx->ctx, n, media, inline_style,
|
2011-05-07 00:40:09 +04:00
|
|
|
&selection_handler, ctx, &styles);
|
2013-12-19 18:21:15 +04:00
|
|
|
|
|
|
|
if (error != CSS_OK || styles == NULL) {
|
|
|
|
/* Failed selecting partial style -- bail out */
|
2009-07-24 03:05:34 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-12-19 18:21:15 +04:00
|
|
|
/* 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
|
|
|
|
* element's style */
|
|
|
|
error = css_computed_style_compose(ctx->parent_style,
|
|
|
|
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
|
|
|
|
nscss_compute_font_size, NULL,
|
|
|
|
styles->styles[CSS_PSEUDO_ELEMENT_NONE]);
|
|
|
|
if (error != CSS_OK) {
|
|
|
|
css_select_results_destroy(styles);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pseudo_element = CSS_PSEUDO_ELEMENT_NONE + 1;
|
|
|
|
pseudo_element < CSS_PSEUDO_ELEMENT_COUNT;
|
|
|
|
pseudo_element++) {
|
|
|
|
|
|
|
|
if (pseudo_element == CSS_PSEUDO_ELEMENT_FIRST_LETTER ||
|
|
|
|
pseudo_element == CSS_PSEUDO_ELEMENT_FIRST_LINE)
|
|
|
|
/* TODO: Handle first-line and first-letter pseudo
|
|
|
|
* element computed style completion */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (styles->styles[pseudo_element] == NULL)
|
|
|
|
/* There were no rules concerning this pseudo element */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Complete the pseudo element's computed style, by composing
|
|
|
|
* with the base element's style */
|
|
|
|
error = css_computed_style_compose(
|
|
|
|
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
|
|
|
|
styles->styles[pseudo_element],
|
|
|
|
nscss_compute_font_size, NULL,
|
|
|
|
styles->styles[pseudo_element]);
|
|
|
|
if (error != CSS_OK) {
|
|
|
|
/* TODO: perhaps this shouldn't be quite so
|
|
|
|
* catastrophic? */
|
|
|
|
css_select_results_destroy(styles);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
return styles;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an initial style
|
|
|
|
*
|
2011-05-07 00:40:09 +04:00
|
|
|
* \param ctx CSS selection context
|
2009-07-24 03:05:34 +04:00
|
|
|
* \return Pointer to partial computed style, or NULL on failure
|
|
|
|
*/
|
2013-12-19 18:21:15 +04:00
|
|
|
static css_computed_style *nscss_get_initial_style(nscss_select_ctx *ctx)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
|
|
|
css_computed_style *style;
|
|
|
|
css_error error;
|
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
error = css_computed_style_create(&style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (error != CSS_OK)
|
|
|
|
return NULL;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
error = css_computed_style_initialise(style, &selection_handler, ctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (error != CSS_OK) {
|
|
|
|
css_computed_style_destroy(style);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a blank style
|
|
|
|
*
|
2011-05-07 00:40:09 +04:00
|
|
|
* \param ctx CSS selection context
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param parent Parent style to cascade inherited properties from
|
|
|
|
* \return Pointer to blank style, or NULL on failure
|
|
|
|
*/
|
2011-05-07 00:40:09 +04:00
|
|
|
css_computed_style *nscss_get_blank_style(nscss_select_ctx *ctx,
|
2013-12-14 00:25:08 +04:00
|
|
|
const css_computed_style *parent)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
|
|
|
css_computed_style *partial;
|
|
|
|
css_error error;
|
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
partial = nscss_get_initial_style(ctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (partial == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
error = css_computed_style_compose(parent, partial,
|
|
|
|
nscss_compute_font_size, NULL, partial);
|
|
|
|
if (error != CSS_OK) {
|
|
|
|
css_computed_style_destroy(partial);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return partial;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2011-03-12 20:46:11 +03:00
|
|
|
parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1],
|
2013-12-01 23:15:14 +04:00
|
|
|
INTTOFIX(nsoption_int(font_size))),
|
|
|
|
INTTOFIX(10));
|
2009-07-24 03:05:34 +04:00
|
|
|
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 */
|
2011-03-12 20:46:11 +03:00
|
|
|
size->data.length.value = FDIV(FMUL(factors[size->status - 1],
|
2013-12-01 23:15:14 +04:00
|
|
|
INTTOFIX(nsoption_int(font_size))), F_10);
|
2009-07-24 03:05:34 +04:00
|
|
|
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.value =
|
|
|
|
FMUL(size->data.length.value, parent_size.value);
|
|
|
|
|
|
|
|
if (size->data.length.unit == CSS_UNIT_EX) {
|
|
|
|
/* 1ex = 0.6em in NetSurf */
|
|
|
|
size->data.length.value = FMUL(size->data.length.value,
|
|
|
|
FLTTOFIX(0.6));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
size->status = CSS_FONT_SIZE_DIMENSION;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
size_t len = strlen(data);
|
|
|
|
uint8_t r, g, b;
|
|
|
|
|
|
|
|
/* 2 */
|
|
|
|
if (len == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* 3 */
|
|
|
|
if (len == SLEN("transparent") && strcasecmp(data, "transparent") == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* 4 */
|
|
|
|
if (parse_named_colour(data, result))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/** \todo Implement HTML5's utterly insane legacy colour parsing */
|
|
|
|
|
|
|
|
if (data[0] == '#') {
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 3 && isHex(data[0]) && isHex(data[1]) && isHex(data[2])) {
|
|
|
|
r = charToHex(data[0]);
|
|
|
|
g = charToHex(data[1]);
|
|
|
|
b = charToHex(data[2]);
|
|
|
|
|
|
|
|
r |= (r << 4);
|
|
|
|
g |= (g << 4);
|
|
|
|
b |= (b << 4);
|
|
|
|
|
2010-12-05 00:52:26 +03:00
|
|
|
*result = (0xff << 24) | (r << 16) | (g << 8) | b;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (len == 6 && isHex(data[0]) && isHex(data[1]) &&
|
|
|
|
isHex(data[2]) && isHex(data[3]) && isHex(data[4]) &&
|
|
|
|
isHex(data[5])) {
|
|
|
|
r = (charToHex(data[0]) << 4) | charToHex(data[1]);
|
|
|
|
g = (charToHex(data[2]) << 4) | charToHex(data[3]);
|
|
|
|
b = (charToHex(data[4]) << 4) | charToHex(data[5]);
|
|
|
|
|
2010-12-05 00:52:26 +03:00
|
|
|
*result = (0xff << 24) | (r << 16) | (g << 8) | b;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Style selection callbacks *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to retrieve a node's name.
|
|
|
|
*
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param qname Pointer to location to receive node name
|
2009-07-24 03:05:34 +04:00
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*/
|
2011-03-12 20:51:59 +03:00
|
|
|
css_error node_name(void *pw, void *node, css_qname *qname)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(n, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-03-12 20:51:59 +03:00
|
|
|
qname->ns = NULL;
|
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_string_intern(name, &qname->name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-10-08 04:21:59 +04:00
|
|
|
return CSS_OK;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-29 13:59:29 +04:00
|
|
|
/**
|
|
|
|
* Callback to retrieve a node's classes.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param classes Pointer to location to receive class name array
|
|
|
|
* \param n_classes Pointer to location to receive length of class name array
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
2009-09-05 19:49:09 +04:00
|
|
|
* \note The returned array will be destroyed by libcss. Therefore, it must
|
|
|
|
* be allocated using the same allocator as used by libcss during style
|
2009-07-29 13:59:29 +04:00
|
|
|
* selection.
|
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
css_error node_classes(void *pw, void *node,
|
|
|
|
lwc_string ***classes, uint32_t *n_classes)
|
2009-07-29 13:59:29 +04:00
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_exception err;
|
2009-07-29 13:59:29 +04:00
|
|
|
|
|
|
|
*classes = NULL;
|
|
|
|
*n_classes = 0;
|
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_element_get_classes(n, classes, n_classes);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
2009-07-29 13:59:29 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to retrieve a node's ID.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param id Pointer to location to receive id value
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
css_error node_id(void *pw, void *node, lwc_string **id)
|
2009-07-29 13:59:29 +04:00
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *attr;
|
|
|
|
dom_exception err;
|
2009-07-29 13:59:29 +04:00
|
|
|
|
|
|
|
*id = NULL;
|
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
/** \todo Assumes an HTML DOM */
|
|
|
|
err = dom_html_element_get_id(n, &attr);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
if (attr != NULL) {
|
|
|
|
err = dom_string_intern(attr, id);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(attr);
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
2012-07-23 00:50:58 +04:00
|
|
|
dom_string_unref(attr);
|
2012-03-24 22:48:14 +04:00
|
|
|
}
|
2009-07-29 13:59:29 +04:00
|
|
|
|
2011-10-08 04:21:59 +04:00
|
|
|
return CSS_OK;
|
2009-07-29 13:59:29 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Callback to find a named ancestor node.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Node name to search for
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param ancestor Pointer to location to receive ancestor
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a ancestor will contain the result, or NULL if there is no match
|
|
|
|
*/
|
|
|
|
css_error named_ancestor_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **ancestor)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-28 16:49:39 +04:00
|
|
|
dom_element_named_ancestor_node(node, qname->name,
|
|
|
|
(struct dom_element **)ancestor);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to find a named parent node
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Node name to search for
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param parent Pointer to location to receive parent
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a parent will contain the result, or NULL if there is no match
|
|
|
|
*/
|
|
|
|
css_error named_parent_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **parent)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-28 16:49:39 +04:00
|
|
|
dom_element_named_parent_node(node, qname->name,
|
|
|
|
(struct dom_element **)parent);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to find a named sibling node.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Node name to search for
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param sibling Pointer to location to receive sibling
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a sibling will contain the result, or NULL if there is no match
|
|
|
|
*/
|
|
|
|
css_error named_sibling_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **sibling)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_node *prev;
|
|
|
|
dom_exception err;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
*sibling = NULL;
|
|
|
|
|
2011-02-01 01:31:47 +03:00
|
|
|
/* Find sibling element */
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_node_get_previous_sibling(n, &n);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_OK;
|
|
|
|
|
|
|
|
while (n != NULL) {
|
|
|
|
dom_node_type type;
|
|
|
|
|
|
|
|
err = dom_node_get_node_type(n, &type);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DOM_ELEMENT_NODE)
|
2011-02-01 01:31:47 +03:00
|
|
|
break;
|
2012-03-24 22:48:14 +04:00
|
|
|
|
|
|
|
err = dom_node_get_previous_sibling(n, &prev);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(n);
|
|
|
|
n = prev;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
if (n != NULL) {
|
|
|
|
dom_string *name;
|
2011-10-08 04:21:59 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_node_get_node_name(n, &name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2011-10-08 04:21:59 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node_unref(n);
|
|
|
|
|
|
|
|
if (dom_string_caseless_lwc_isequal(name, qname->name)) {
|
|
|
|
*sibling = n;
|
|
|
|
}
|
2012-07-23 00:22:05 +04:00
|
|
|
|
|
|
|
dom_string_unref(name);
|
2012-03-24 22:48:14 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
/**
|
|
|
|
* Callback to find a named generic sibling node.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Node name to search for
|
2011-01-31 11:49:39 +03:00
|
|
|
* \param sibling Pointer to location to receive ancestor
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a sibling will contain the result, or NULL if there is no match
|
|
|
|
*/
|
|
|
|
css_error named_generic_sibling_node(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, void **sibling)
|
2011-01-31 11:49:39 +03:00
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_node *prev;
|
|
|
|
dom_exception err;
|
2011-01-31 11:49:39 +03:00
|
|
|
|
|
|
|
*sibling = NULL;
|
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_node_get_previous_sibling(n, &n);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_OK;
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
while (n != NULL) {
|
|
|
|
dom_node_type type;
|
|
|
|
dom_string *name;
|
2011-10-08 04:21:59 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_node_get_node_type(n, &type);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
2011-01-31 11:49:39 +03:00
|
|
|
}
|
2012-03-24 22:48:14 +04:00
|
|
|
|
|
|
|
if (type == DOM_ELEMENT_NODE) {
|
|
|
|
err = dom_node_get_node_name(n, &name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dom_string_caseless_lwc_isequal(name,
|
|
|
|
qname->name)) {
|
2012-07-23 16:21:57 +04:00
|
|
|
dom_string_unref(name);
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node_unref(n);
|
|
|
|
*sibling = n;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-23 16:21:57 +04:00
|
|
|
dom_string_unref(name);
|
2012-03-24 22:48:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_node_get_previous_sibling(n, &prev);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(n);
|
|
|
|
n = prev;
|
2011-01-31 11:49:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Callback to retrieve the parent of a node.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param parent Pointer to location to receive parent
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a parent will contain the result, or NULL if there is no match
|
|
|
|
*/
|
|
|
|
css_error parent_node(void *pw, void *node, void **parent)
|
|
|
|
{
|
2012-03-28 16:49:39 +04:00
|
|
|
dom_element_parent_node(node, (struct dom_element **)parent);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to retrieve the preceding sibling of a node.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param sibling Pointer to location to receive sibling
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a sibling will contain the result, or NULL if there is no match
|
|
|
|
*/
|
|
|
|
css_error sibling_node(void *pw, void *node, void **sibling)
|
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_node *prev;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
*sibling = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-02-01 01:31:47 +03:00
|
|
|
/* Find sibling element */
|
2012-03-24 22:48:14 +04:00
|
|
|
err = dom_node_get_previous_sibling(n, &n);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_OK;
|
|
|
|
|
|
|
|
while (n != NULL) {
|
|
|
|
dom_node_type type;
|
|
|
|
|
|
|
|
err = dom_node_get_node_type(n, &type);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DOM_ELEMENT_NODE)
|
2011-02-01 01:31:47 +03:00
|
|
|
break;
|
2012-03-24 22:48:14 +04:00
|
|
|
|
|
|
|
err = dom_node_get_previous_sibling(n, &prev);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(n);
|
|
|
|
n = prev;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
if (n != NULL) {
|
|
|
|
/** \todo Sort out reference counting */
|
|
|
|
dom_node_unref(n);
|
|
|
|
|
|
|
|
*sibling = n;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has the given name.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_name(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, bool *match)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2011-10-08 04:21:59 +04:00
|
|
|
nscss_select_ctx *ctx = pw;
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-11-28 15:29:22 +04:00
|
|
|
if (lwc_string_isequal(qname->name, ctx->universal, match) ==
|
|
|
|
lwc_error_ok && *match == false) {
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(n, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_OK;
|
|
|
|
|
2011-03-12 21:29:40 +03:00
|
|
|
/* Element names are case insensitive in HTML */
|
2012-03-24 22:48:14 +04:00
|
|
|
*match = dom_string_caseless_lwc_isequal(name, qname->name);
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has the given class.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param name Name to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_class(void *pw, void *node,
|
|
|
|
lwc_string *name, bool *match)
|
|
|
|
{
|
2012-03-24 22:48:14 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_exception err;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
/** \todo: Ensure that libdom performs case-insensitive
|
|
|
|
* matching in quirks mode */
|
|
|
|
err = dom_element_has_class(n, name, match);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:48:14 +04:00
|
|
|
assert(err == DOM_NO_ERR);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has the given id.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param name Name to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_id(void *pw, void *node,
|
|
|
|
lwc_string *name, bool *match)
|
|
|
|
{
|
2012-03-24 23:40:06 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *attr;
|
|
|
|
dom_exception err;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
2012-03-24 23:40:06 +04:00
|
|
|
/** \todo Assumes an HTML DOM */
|
|
|
|
err = dom_html_element_get_id(n, &attr);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_OK;
|
|
|
|
|
|
|
|
if (attr != NULL) {
|
|
|
|
*match = dom_string_lwc_isequal(attr, name);
|
|
|
|
|
|
|
|
dom_string_unref(attr);
|
2012-03-22 13:34:34 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has an attribute with the given name.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, bool *match)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-24 23:40:06 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
2009-09-05 19:49:09 +04:00
|
|
|
|
2012-03-24 23:40:06 +04:00
|
|
|
err = dom_element_has_attribute(n, name, match);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has an attribute with given name and value.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param value Value to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute_equal(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2009-07-24 03:05:34 +04:00
|
|
|
bool *match)
|
|
|
|
{
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_string *atr_val;
|
|
|
|
dom_exception err;
|
|
|
|
|
2011-02-01 01:31:47 +03:00
|
|
|
size_t vlen = lwc_string_length(value);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
if (vlen == 0) {
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
err = dom_element_get_attribute(n, name, &atr_val);
|
2012-03-25 02:42:14 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
*match = dom_string_caseless_lwc_isequal(atr_val, value);
|
|
|
|
|
|
|
|
dom_string_unref(atr_val);
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has an attribute with the given name whose
|
|
|
|
* value dashmatches that given.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param value Value to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute_dashmatch(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2009-07-24 03:05:34 +04:00
|
|
|
bool *match)
|
|
|
|
{
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_string *atr_val;
|
|
|
|
dom_exception err;
|
|
|
|
|
2011-02-01 01:31:47 +03:00
|
|
|
size_t vlen = lwc_string_length(value);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
if (vlen == 0) {
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
err = dom_element_get_attribute(n, name, &atr_val);
|
2012-03-25 02:42:14 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
/* check for exact match */
|
|
|
|
*match = dom_string_caseless_lwc_isequal(atr_val, value);
|
|
|
|
|
|
|
|
/* check for dashmatch */
|
|
|
|
if (*match == false) {
|
|
|
|
const char *vdata = lwc_string_data(value);
|
|
|
|
const char *data = (const char *) dom_string_data(atr_val);
|
|
|
|
size_t len = dom_string_byte_length(atr_val);
|
|
|
|
|
|
|
|
if (len > vlen && data[vlen] == '-' &&
|
|
|
|
strncasecmp(data, vdata, vlen) == 0) {
|
|
|
|
*match = true;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_string_unref(atr_val);
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has an attribute with the given name whose
|
|
|
|
* value includes that given.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param value Value to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute_includes(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2009-07-24 03:05:34 +04:00
|
|
|
bool *match)
|
|
|
|
{
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_string *atr_val;
|
|
|
|
dom_exception err;
|
2009-07-24 03:05:34 +04:00
|
|
|
size_t vlen = lwc_string_length(value);
|
2012-03-25 01:35:02 +04:00
|
|
|
const char *p;
|
|
|
|
const char *start;
|
|
|
|
const char *end;
|
|
|
|
|
2012-08-07 18:16:50 +04:00
|
|
|
*match = false;
|
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
if (vlen == 0) {
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
err = dom_element_get_attribute(n, name, &atr_val);
|
2012-03-25 02:42:14 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
/* check for match */
|
|
|
|
start = (const char *) dom_string_data(atr_val);
|
|
|
|
end = start + dom_string_byte_length(atr_val);
|
|
|
|
|
|
|
|
for (p = start; p <= end; p++) {
|
|
|
|
if (*p == ' ' || *p == '\0') {
|
|
|
|
if ((size_t) (p - start) == vlen &&
|
|
|
|
strncasecmp(start,
|
|
|
|
lwc_string_data(value),
|
|
|
|
vlen) == 0) {
|
|
|
|
*match = true;
|
|
|
|
break;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
start = p + 1;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2011-01-31 11:49:39 +03:00
|
|
|
}
|
|
|
|
|
2012-03-25 01:35:02 +04:00
|
|
|
dom_string_unref(atr_val);
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has an attribute with the given name whose
|
|
|
|
* value has the prefix given.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2011-01-31 11:49:39 +03:00
|
|
|
* \param value Value to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute_prefix(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool *match)
|
|
|
|
{
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_string *atr_val;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
size_t vlen = lwc_string_length(value);
|
|
|
|
|
|
|
|
if (vlen == 0) {
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
err = dom_element_get_attribute(n, name, &atr_val);
|
2012-03-25 02:42:14 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
/* check for exact match */
|
|
|
|
*match = dom_string_caseless_lwc_isequal(atr_val, value);
|
|
|
|
|
|
|
|
/* check for prefix match */
|
|
|
|
if (*match == false) {
|
|
|
|
const char *data = (const char *) dom_string_data(atr_val);
|
|
|
|
size_t len = dom_string_byte_length(atr_val);
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
if ((len >= vlen) &&
|
|
|
|
(strncasecmp(data, lwc_string_data(value), vlen) == 0)) {
|
|
|
|
*match = true;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_string_unref(atr_val);
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-31 11:49:39 +03:00
|
|
|
* Callback to determine if a node has an attribute with the given name whose
|
|
|
|
* value has the suffix given.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2011-01-31 11:49:39 +03:00
|
|
|
* \param value Value to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute_suffix(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool *match)
|
|
|
|
{
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_string *atr_val;
|
|
|
|
dom_exception err;
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
size_t vlen = lwc_string_length(value);
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
if (vlen == 0) {
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
err = dom_element_get_attribute(n, name, &atr_val);
|
2012-03-25 02:42:14 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
/* check for exact match */
|
|
|
|
*match = dom_string_caseless_lwc_isequal(atr_val, value);
|
|
|
|
|
|
|
|
/* check for prefix match */
|
|
|
|
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;
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
if ((len >= vlen) &&
|
|
|
|
(strncasecmp(start, lwc_string_data(value), vlen) == 0)) {
|
|
|
|
*match = true;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2012-03-25 02:21:25 +04:00
|
|
|
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
}
|
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_string_unref(atr_val);
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has an attribute with the given name whose
|
|
|
|
* value contains the substring given.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
2011-03-12 20:51:59 +03:00
|
|
|
* \param qname Name to match
|
2011-01-31 11:49:39 +03:00
|
|
|
* \param value Value to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_has_attribute_substring(void *pw, void *node,
|
2011-03-12 20:51:59 +03:00
|
|
|
const css_qname *qname, lwc_string *value,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool *match)
|
|
|
|
{
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *name;
|
|
|
|
dom_string *atr_val;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
size_t vlen = lwc_string_length(value);
|
|
|
|
|
|
|
|
if (vlen == 0) {
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_string_create_interned(
|
|
|
|
(const uint8_t *) lwc_string_data(qname->name),
|
|
|
|
lwc_string_length(qname->name), &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
err = dom_element_get_attribute(n, name, &atr_val);
|
2012-03-25 02:42:14 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
/* check for exact match */
|
|
|
|
*match = dom_string_caseless_lwc_isequal(atr_val, value);
|
|
|
|
|
|
|
|
/* check for prefix match */
|
|
|
|
if (*match == false) {
|
|
|
|
const char *vdata = lwc_string_data(value);
|
|
|
|
const char *start = (const char *) dom_string_data(atr_val);
|
|
|
|
size_t len = dom_string_byte_length(atr_val);
|
|
|
|
const char *last_start = start + len - vlen;
|
|
|
|
|
|
|
|
if (len >= vlen) {
|
|
|
|
while (start <= last_start) {
|
|
|
|
if (strncasecmp(start, vdata,
|
|
|
|
vlen) == 0) {
|
|
|
|
*match = true;
|
|
|
|
break;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
start++;
|
|
|
|
}
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2011-01-31 11:49:39 +03:00
|
|
|
}
|
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_string_unref(atr_val);
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is the root node of the document.
|
2009-07-24 03:05:34 +04:00
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
2011-01-31 11:49:39 +03:00
|
|
|
css_error node_is_root(void *pw, void *node, bool *match)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-25 02:21:25 +04:00
|
|
|
dom_node *n = node;
|
|
|
|
dom_node *parent;
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_parent_node(n, &parent);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 02:21:25 +04:00
|
|
|
if (parent != NULL) {
|
|
|
|
err = dom_node_get_node_type(parent, &type);
|
|
|
|
|
|
|
|
dom_node_unref(parent);
|
|
|
|
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_NOMEM;
|
|
|
|
|
|
|
|
if (type != DOM_DOCUMENT_NODE) {
|
|
|
|
*match = false;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*match = true;
|
2011-01-31 11:49:39 +03:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-25 13:23:41 +04:00
|
|
|
static int
|
|
|
|
node_count_siblings_check(dom_node *node,
|
|
|
|
bool check_name,
|
2012-03-25 13:26:39 +04:00
|
|
|
dom_string *name)
|
2012-03-25 13:23:41 +04:00
|
|
|
{
|
|
|
|
dom_node_type type;
|
|
|
|
int ret = 0;
|
2012-03-25 13:26:39 +04:00
|
|
|
dom_exception exc;
|
2012-03-25 13:23:41 +04:00
|
|
|
|
|
|
|
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) {
|
2012-03-25 13:26:39 +04:00
|
|
|
dom_string *node_name = NULL;
|
2012-03-25 13:23:41 +04:00
|
|
|
exc = dom_node_get_node_name(node, &node_name);
|
|
|
|
|
|
|
|
if ((exc == DOM_NO_ERR) && (node_name != NULL)) {
|
|
|
|
|
2012-03-25 13:26:39 +04:00
|
|
|
if (dom_string_caseless_isequal(name,
|
2012-03-25 13:23:41 +04:00
|
|
|
node_name)) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
/**
|
|
|
|
* Callback to count a node's siblings.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param same_name Only count siblings with the same name, or all
|
|
|
|
* \param after Count anteceding instead of preceding siblings
|
|
|
|
* \param count Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a count will contain the number of siblings
|
|
|
|
*/
|
2012-03-25 13:23:41 +04:00
|
|
|
css_error node_count_siblings(void *pw, void *n, bool same_name,
|
2011-01-31 11:49:39 +03:00
|
|
|
bool after, int32_t *count)
|
|
|
|
{
|
|
|
|
int32_t cnt = 0;
|
2012-03-25 13:23:41 +04:00
|
|
|
dom_exception exc;
|
2012-03-25 13:26:39 +04:00
|
|
|
dom_string *node_name = NULL;
|
2011-01-31 11:49:39 +03:00
|
|
|
|
2011-10-08 04:21:59 +04:00
|
|
|
if (same_name) {
|
2012-03-25 13:23:41 +04:00
|
|
|
dom_node *node = n;
|
|
|
|
exc = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((exc != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (after) {
|
|
|
|
dom_node *node = dom_node_ref(n);
|
|
|
|
dom_node *next;
|
|
|
|
|
2011-10-08 04:21:59 +04:00
|
|
|
do {
|
2012-03-25 13:23:41 +04:00
|
|
|
exc = dom_node_get_next_sibling(node, &next);
|
|
|
|
if ((exc != DOM_NO_ERR))
|
|
|
|
break;
|
|
|
|
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = next;
|
2011-10-08 04:21:59 +04:00
|
|
|
|
2012-03-25 13:23:41 +04:00
|
|
|
cnt += node_count_siblings_check(node, same_name, node_name);
|
|
|
|
} while (node != NULL);
|
2011-10-08 04:21:59 +04:00
|
|
|
} else {
|
2012-03-25 13:23:41 +04:00
|
|
|
dom_node *node = dom_node_ref(n);
|
|
|
|
dom_node *next;
|
|
|
|
|
2011-10-08 04:21:59 +04:00
|
|
|
do {
|
2012-03-25 13:23:41 +04:00
|
|
|
exc = dom_node_get_previous_sibling(node, &next);
|
|
|
|
if ((exc != DOM_NO_ERR))
|
|
|
|
break;
|
|
|
|
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = next;
|
2011-10-08 04:21:59 +04:00
|
|
|
|
2012-03-25 13:23:41 +04:00
|
|
|
cnt += node_count_siblings_check(node, same_name, node_name);
|
|
|
|
|
|
|
|
} while (node != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node_name != NULL) {
|
|
|
|
dom_string_unref(node_name);
|
2011-10-08 04:21:59 +04:00
|
|
|
}
|
2011-01-31 11:49:39 +03:00
|
|
|
|
|
|
|
*count = cnt;
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is empty.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node is empty and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_empty(void *pw, void *node, bool *match)
|
|
|
|
{
|
2012-03-25 12:55:27 +04:00
|
|
|
dom_node *n = node, *next;
|
|
|
|
dom_exception err;
|
|
|
|
|
2011-02-01 01:31:47 +03:00
|
|
|
*match = true;
|
2012-03-25 12:55:27 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntype == DOM_ELEMENT_NODE ||
|
|
|
|
ntype == DOM_TEXT_NODE) {
|
2011-02-01 01:31:47 +03:00
|
|
|
*match = false;
|
2012-03-25 12:55:27 +04:00
|
|
|
dom_node_unref(n);
|
2011-02-01 01:31:47 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-03-25 12:55:27 +04:00
|
|
|
|
|
|
|
err = dom_node_get_next_sibling(n, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
dom_node_unref(n);
|
|
|
|
n = next;
|
2011-02-01 01:31:47 +03:00
|
|
|
}
|
2012-03-25 12:55:27 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is a linking element.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
2012-03-25 15:14:19 +04:00
|
|
|
* \param n DOM node
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
2012-03-25 15:14:19 +04:00
|
|
|
css_error node_is_link(void *pw, void *n, bool *match)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-25 15:14:19 +04:00
|
|
|
dom_node *node = n;
|
|
|
|
dom_exception exc;
|
|
|
|
dom_string *node_name = NULL;
|
|
|
|
|
|
|
|
exc = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((exc != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(node_name, corestring_lwc_a)) {
|
2012-03-25 15:14:19 +04:00
|
|
|
bool has_href;
|
2012-07-22 18:48:55 +04:00
|
|
|
exc = dom_element_has_attribute(node, corestring_dom_href,
|
|
|
|
&has_href);
|
2012-03-25 15:14:19 +04:00
|
|
|
if ((exc == DOM_NO_ERR) && (has_href)) {
|
|
|
|
*match = true;
|
|
|
|
} else {
|
|
|
|
*match = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*match = false;
|
|
|
|
}
|
|
|
|
dom_string_unref(node_name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-09-05 19:49:09 +04:00
|
|
|
* Callback to determine if a node is a linking element whose target has been
|
2009-07-24 03:05:34 +04:00
|
|
|
* visited.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_visited(void *pw, void *node, bool *match)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
nscss_select_ctx *ctx = pw;
|
2013-05-16 21:18:06 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
const struct url_data *data;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
dom_exception exc;
|
|
|
|
dom_node *n = node;
|
|
|
|
dom_string *s = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-12-07 04:08:52 +04:00
|
|
|
*match = false;
|
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
exc = dom_node_get_node_name(n, &s);
|
|
|
|
if ((exc != DOM_NO_ERR) || (s == NULL)) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
if (!dom_string_caseless_lwc_isequal(s, corestring_lwc_a)) {
|
|
|
|
/* Can't be visited; not ancher element */
|
|
|
|
dom_string_unref(s);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
/* Finished with node name string */
|
|
|
|
dom_string_unref(s);
|
|
|
|
s = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
exc = dom_element_get_attribute(n, corestring_dom_href, &s);
|
|
|
|
if ((exc != DOM_NO_ERR) || (s == NULL)) {
|
|
|
|
/* Can't be visited; not got a URL */
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
/* Make href absolute */
|
|
|
|
/* TODO: this duplicates what we do for box->href
|
|
|
|
* should we put the absolute URL on the dom node? */
|
|
|
|
error = nsurl_join(ctx->base_url, dom_string_data(s), &url);
|
|
|
|
|
|
|
|
/* Finished with href string */
|
|
|
|
dom_string_unref(s);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-05-16 21:18:06 +04:00
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
/* Couldn't make nsurl object */
|
|
|
|
return CSS_NOMEM;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
2013-05-16 21:18:06 +04:00
|
|
|
|
|
|
|
data = urldb_get_url_data(url);
|
|
|
|
|
|
|
|
/* Visited if in the db and has
|
|
|
|
* non-zero visit count */
|
|
|
|
if (data != NULL && data->visits > 0)
|
|
|
|
*match = true;
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is currently being hovered over.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_hover(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support hovering */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is currently activated.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_active(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support active nodes */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node has the input focus.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_focus(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support focussed nodes */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:49:39 +03:00
|
|
|
/**
|
|
|
|
* Callback to determine if a node is enabled.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match with contain true if the node is enabled and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_enabled(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support enabled nodes */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is disabled.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match with contain true if the node is disabled and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_disabled(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support disabled nodes */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is checked.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match with contain true if the node is checked and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_checked(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support checked nodes */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to determine if a node is the target of the document URL.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match with contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_target(void *pw, void *node, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support target */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Callback to determine if a node has the given language
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param lang Language specifier to match
|
|
|
|
* \param match Pointer to location to receive result
|
|
|
|
* \return CSS_OK.
|
|
|
|
*
|
|
|
|
* \post \a match will contain true if the node matches and false otherwise.
|
|
|
|
*/
|
|
|
|
css_error node_is_lang(void *pw, void *node,
|
|
|
|
lwc_string *lang, bool *match)
|
|
|
|
{
|
|
|
|
/** \todo Support languages */
|
|
|
|
|
|
|
|
*match = false;
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_vertical_align(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
2009-07-24 03:05:34 +04:00
|
|
|
{
|
2012-03-25 18:51:37 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_string *valign = NULL;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(node, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_col) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_thead) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_tbody) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_tfoot) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_tr) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th)) {
|
2012-03-25 18:51:37 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_valign, &valign);
|
2012-03-25 18:51:37 +04:00
|
|
|
if (err != DOM_NO_ERR || valign == NULL) {
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:51:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_top)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_TOP;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_middle)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_MIDDLE;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_bottom)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_BOTTOM;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_baseline)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_BASELINE;
|
|
|
|
} else {
|
2012-03-25 18:51:37 +04:00
|
|
|
dom_string_unref(valign);
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:51:37 +04:00
|
|
|
dom_string_unref(valign);
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_applet) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_embed) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_iframe) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_img) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_object)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
/** \todo input[type=image][align=*] - $11.3.3 */
|
2012-03-25 18:51:37 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_align, &valign);
|
2012-03-25 18:51:37 +04:00
|
|
|
if (err != DOM_NO_ERR || valign == NULL) {
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:51:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_top)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_TOP;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_bottom) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_baseline)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_BASELINE;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_texttop)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_TEXT_TOP;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_absmiddle) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(valign,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_abscenter)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_VERTICAL_ALIGN_MIDDLE;
|
2011-10-08 02:07:57 +04:00
|
|
|
} else {
|
2012-03-25 18:51:37 +04:00
|
|
|
dom_string_unref(valign);
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2012-03-25 18:51:37 +04:00
|
|
|
dom_string_unref(valign);
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:51:37 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_text_align(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_string *align = NULL;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(node, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_p) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_h1) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_h2) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_h3) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_h4) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_h5) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_h6)) {
|
2012-03-25 19:02:08 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_align, &align);
|
2012-03-25 19:02:08 +04:00
|
|
|
if (err != DOM_NO_ERR || align == NULL) {
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 19:02:08 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_left)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LEFT;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_center)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_CENTER;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_right)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_RIGHT;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_justify)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
|
2009-07-24 03:05:34 +04:00
|
|
|
} else {
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(align);
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(align);
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2009-08-21 21:05:22 +04:00
|
|
|
return CSS_OK;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_center)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_caption)) {
|
2012-03-25 19:02:08 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_align, &align);
|
2012-03-25 19:02:08 +04:00
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (align == NULL || dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_center)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_left)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_LEFT;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_right)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_RIGHT;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_justify)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
|
|
|
|
} else {
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(align);
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (align != NULL)
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(align);
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
|
|
|
|
return CSS_OK;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_div) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_thead) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_tbody) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_tfoot) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_tr) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_td) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_th)) {
|
2012-03-25 19:02:08 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_align, &align);
|
2012-03-25 19:02:08 +04:00
|
|
|
if (err != DOM_NO_ERR || align == NULL) {
|
|
|
|
dom_string_unref(name);
|
2009-08-21 21:05:22 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 19:02:08 +04:00
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_center)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_CENTER;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_left)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_LEFT;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_right)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_LIBCSS_RIGHT;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_justify)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_TEXT_ALIGN_JUSTIFY;
|
2009-08-21 21:05:22 +04:00
|
|
|
} else {
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(align);
|
|
|
|
dom_string_unref(name);
|
2009-08-21 21:05:22 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(align);
|
|
|
|
dom_string_unref(name);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_table)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
/* Tables usually reset alignment */
|
|
|
|
hint->status = CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
|
|
|
} else {
|
2012-03-25 19:02:08 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_padding_trbl(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 20:24:46 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_exception exc;
|
|
|
|
dom_string *cellpadding = NULL;
|
2013-10-25 15:18:46 +04:00
|
|
|
css_error result = CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:24:46 +04:00
|
|
|
|
|
|
|
exc = dom_node_get_node_name(node, &name);
|
|
|
|
if (exc != DOM_NO_ERR)
|
|
|
|
return CSS_BADPARM;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th)) {
|
2012-03-25 20:24:46 +04:00
|
|
|
css_qname qs;
|
|
|
|
dom_node *tablenode = NULL;
|
|
|
|
qs.ns = NULL;
|
2012-07-22 18:48:55 +04:00
|
|
|
qs.name = lwc_string_ref(corestring_lwc_table);
|
2012-03-25 20:24:46 +04:00
|
|
|
if (named_ancestor_node(ctx, node, &qs,
|
2012-03-26 03:00:39 +04:00
|
|
|
(void *)&tablenode) != CSS_OK) {
|
2012-03-25 20:24:46 +04:00
|
|
|
/* Didn't find, or had error */
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2012-03-25 21:04:00 +04:00
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
|
2012-03-25 20:24:46 +04:00
|
|
|
if (tablenode != NULL) {
|
|
|
|
exc = dom_element_get_attribute(tablenode,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_cellpadding,
|
2012-07-22 17:06:45 +04:00
|
|
|
&cellpadding);
|
2012-03-25 20:24:46 +04:00
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* No need to unref tablenode, named_ancestor_node does not
|
|
|
|
* return a reffed node to the CSS
|
|
|
|
*/
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2012-03-25 20:24:46 +04:00
|
|
|
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2013-10-25 15:18:46 +04:00
|
|
|
if (cellpadding != NULL) {
|
|
|
|
if (parse_dimension(dom_string_data(cellpadding), false,
|
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
hint->status = CSS_PADDING_SET;
|
|
|
|
result = CSS_OK;
|
|
|
|
}
|
2012-03-25 20:24:46 +04:00
|
|
|
dom_string_unref(cellpadding);
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2012-03-25 20:24:46 +04:00
|
|
|
|
2013-10-25 15:18:46 +04:00
|
|
|
return result;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static css_error
|
|
|
|
node_presentational_hint_margin_rl(nscss_select_ctx *ctx,
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint,
|
|
|
|
uint32_t property)
|
2012-03-25 18:38:37 +04:00
|
|
|
{
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string *n;
|
|
|
|
dom_exception exc;
|
|
|
|
|
|
|
|
exc = dom_node_get_node_name(node, &n);
|
|
|
|
if (exc != DOM_NO_ERR)
|
|
|
|
return CSS_BADPARM;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(n, corestring_lwc_img) ||
|
|
|
|
dom_string_caseless_lwc_isequal(n, corestring_lwc_applet)) {
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
|
|
|
exc = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_hspace, &n);
|
2012-03-25 20:45:08 +04:00
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == NULL)
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:45:08 +04:00
|
|
|
|
|
|
|
if (parse_dimension(dom_string_data(n), false,
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
hint->status = CSS_MARGIN_SET;
|
2009-07-24 03:05:34 +04:00
|
|
|
} else {
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
2009-08-21 21:05:22 +04:00
|
|
|
return CSS_OK;
|
2012-07-22 18:48:55 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(n, corestring_lwc_table) ||
|
|
|
|
dom_string_caseless_lwc_isequal(n, corestring_lwc_align)) {
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
|
|
|
exc = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_align, &n);
|
2012-03-25 20:45:08 +04:00
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == NULL)
|
2009-08-21 21:05:22 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:45:08 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_center) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_abscenter) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_middle) ||
|
2012-07-22 17:06:45 +04:00
|
|
|
dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_absmiddle)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_MARGIN_AUTO;
|
2009-08-21 21:05:22 +04:00
|
|
|
} else {
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
2009-08-21 21:05:22 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 20:45:08 +04:00
|
|
|
|
|
|
|
dom_string_unref(n);
|
2011-09-01 01:12:57 +04:00
|
|
|
return CSS_OK;
|
2012-07-22 18:48:55 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(n, corestring_lwc_hr)) {
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
|
|
|
exc = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_align, &n);
|
2012-03-25 20:45:08 +04:00
|
|
|
if (exc != DOM_NO_ERR)
|
|
|
|
return CSS_BADPARM;
|
|
|
|
|
|
|
|
if (n == NULL)
|
2011-09-01 01:12:57 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:45:08 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_left)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
if (property == CSS_PROP_MARGIN_LEFT) {
|
|
|
|
hint->data.length.value = 0;
|
|
|
|
hint->data.length.unit = CSS_UNIT_PX;
|
|
|
|
hint->status = CSS_MARGIN_SET;
|
|
|
|
} else {
|
|
|
|
hint->status = CSS_MARGIN_AUTO;
|
|
|
|
}
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_center)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_MARGIN_AUTO;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(n,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_right)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
if (property == CSS_PROP_MARGIN_RIGHT) {
|
|
|
|
hint->data.length.value = 0;
|
|
|
|
hint->data.length.unit = CSS_UNIT_PX;
|
|
|
|
hint->status = CSS_MARGIN_SET;
|
|
|
|
} else {
|
|
|
|
hint->status = CSS_MARGIN_AUTO;
|
|
|
|
}
|
|
|
|
} else {
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
2011-09-01 01:12:57 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 20:45:08 +04:00
|
|
|
dom_string_unref(n);
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2012-03-25 20:45:08 +04:00
|
|
|
|
|
|
|
dom_string_unref(n);
|
|
|
|
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_margin_tb(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 20:48:50 +04:00
|
|
|
dom_string *name, *vspace = NULL;
|
|
|
|
dom_exception exc;
|
|
|
|
|
|
|
|
exc = dom_node_get_node_name(node, &name);
|
|
|
|
if (exc != DOM_NO_ERR)
|
|
|
|
return CSS_BADPARM;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_img) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_applet)) {
|
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_vspace,
|
2012-07-22 17:06:45 +04:00
|
|
|
&vspace);
|
2012-03-25 20:48:50 +04:00
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
if (vspace == NULL)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:48:50 +04:00
|
|
|
|
|
|
|
if (parse_dimension(dom_string_data(vspace), false,
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
hint->status = CSS_MARGIN_SET;
|
|
|
|
} else {
|
2012-03-25 20:48:50 +04:00
|
|
|
dom_string_unref(vspace);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 20:48:50 +04:00
|
|
|
dom_string_unref(vspace);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static css_error
|
|
|
|
node_presentational_hint_border_trbl_width(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 21:04:00 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_exception exc;
|
|
|
|
dom_string *width = NULL;
|
2012-03-25 18:38:37 +04:00
|
|
|
bool is_table_cell = false;
|
2012-03-25 21:04:00 +04:00
|
|
|
|
|
|
|
exc = dom_node_get_node_name(node, &name);
|
|
|
|
if (exc != DOM_NO_ERR)
|
|
|
|
return CSS_BADPARM;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th)) {
|
2012-03-25 21:04:00 +04:00
|
|
|
css_qname qs;
|
|
|
|
dom_node *tablenode = NULL;
|
|
|
|
qs.ns = NULL;
|
2012-07-22 18:48:55 +04:00
|
|
|
qs.name = lwc_string_ref(corestring_lwc_table);
|
2012-03-25 21:04:00 +04:00
|
|
|
if (named_ancestor_node(ctx, node, &qs,
|
2012-03-26 03:00:39 +04:00
|
|
|
(void *)&tablenode) != CSS_OK) {
|
2012-03-25 21:04:00 +04:00
|
|
|
/* Didn't find, or had error */
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 21:04:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
if (tablenode != NULL) {
|
|
|
|
exc = dom_element_get_attribute(tablenode,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_border, &width);
|
2012-03-25 21:04:00 +04:00
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* No need to unref tablenode, named_ancestor_node does not
|
|
|
|
* return a reffed node to the CSS
|
|
|
|
*/
|
|
|
|
is_table_cell = true;
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_table)) {
|
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_border,
|
2012-04-16 17:32:42 +04:00
|
|
|
&width);
|
2012-03-25 21:04:00 +04:00
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2012-03-25 21:04:00 +04:00
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
if (width == NULL)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
|
2012-03-25 21:04:00 +04:00
|
|
|
if (parse_dimension(dom_string_data(width), false,
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
if (is_table_cell &&
|
|
|
|
INTTOFIX(0) !=
|
|
|
|
hint->data.length.value) {
|
|
|
|
hint->data.length.value = INTTOFIX(1);
|
|
|
|
hint->data.length.unit = CSS_UNIT_PX;
|
|
|
|
}
|
|
|
|
hint->status = CSS_BORDER_WIDTH_WIDTH;
|
|
|
|
} else {
|
2012-03-25 21:04:00 +04:00
|
|
|
dom_string_unref(width);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 21:04:00 +04:00
|
|
|
dom_string_unref(width);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static css_error
|
|
|
|
node_presentational_hint_border_trbl_style(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-26 02:52:05 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_exception exc;
|
2012-03-25 19:12:15 +04:00
|
|
|
|
2012-03-26 02:52:05 +04:00
|
|
|
exc = dom_node_get_node_name(node, &name);
|
|
|
|
if (exc != DOM_NO_ERR)
|
|
|
|
return CSS_BADPARM;
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th)) {
|
2012-03-26 02:52:05 +04:00
|
|
|
css_qname qs;
|
|
|
|
dom_node *tablenode = NULL;
|
|
|
|
qs.ns = NULL;
|
2012-07-22 18:48:55 +04:00
|
|
|
qs.name = lwc_string_ref(corestring_lwc_table);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-26 02:52:05 +04:00
|
|
|
if (named_ancestor_node(ctx, node, &qs,
|
2012-03-26 03:00:39 +04:00
|
|
|
(void *)&tablenode) != CSS_OK) {
|
2012-03-26 02:52:05 +04:00
|
|
|
/* Didn't find, or had error */
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-26 02:52:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
lwc_string_unref(qs.name);
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-26 02:52:05 +04:00
|
|
|
if (tablenode != NULL) {
|
|
|
|
bool has_border = false;
|
|
|
|
|
|
|
|
exc = dom_element_has_attribute(tablenode,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_border,
|
2012-03-26 02:52:05 +04:00
|
|
|
&has_border);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_border) {
|
|
|
|
hint->status = CSS_BORDER_STYLE_INSET;
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* No need to unref tablenode, named_ancestor_node does not
|
|
|
|
* return a reffed node to the CSS
|
|
|
|
*/
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_table)) {
|
2012-03-26 02:52:05 +04:00
|
|
|
bool has_border = false;
|
|
|
|
|
|
|
|
exc = dom_element_has_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_border,
|
2012-03-26 02:52:05 +04:00
|
|
|
&has_border);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_BADPARM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_border) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_BORDER_STYLE_OUTSET;
|
2012-03-26 02:52:05 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2012-03-26 02:52:05 +04:00
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_border_trbl_color(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-28 20:40:06 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_string *bordercolor = NULL;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(node, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th)) {
|
2012-03-28 20:40:06 +04:00
|
|
|
css_qname qs;
|
|
|
|
dom_node *tablenode = NULL;
|
|
|
|
qs.ns = NULL;
|
2012-07-22 18:48:55 +04:00
|
|
|
qs.name = lwc_string_ref(corestring_lwc_table);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 20:40:06 +04:00
|
|
|
if (named_ancestor_node(ctx, node, &qs,
|
|
|
|
(void *)&tablenode) != CSS_OK) {
|
|
|
|
/* Didn't find, or had error */
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
dom_string_unref(name);
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 20:40:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
|
|
|
|
if (tablenode != NULL) {
|
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_bordercolor,
|
2012-07-22 17:06:45 +04:00
|
|
|
&bordercolor);
|
2012-03-28 20:40:06 +04:00
|
|
|
}
|
|
|
|
/* No need to unref tablenode, named_ancestor_node does not
|
|
|
|
* return a reffed node to the CSS
|
|
|
|
*/
|
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_table)) {
|
2012-03-28 20:40:06 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_bordercolor,
|
2012-07-22 17:06:45 +04:00
|
|
|
&bordercolor);
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 20:40:06 +04:00
|
|
|
dom_string_unref(name);
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 20:40:06 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (bordercolor == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 20:40:06 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 20:40:06 +04:00
|
|
|
if (nscss_parse_colour((const char *)dom_string_data(bordercolor),
|
|
|
|
&hint->data.color)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->status = CSS_BORDER_COLOR_COLOR;
|
2012-03-28 20:40:06 +04:00
|
|
|
dom_string_unref(bordercolor);
|
|
|
|
return CSS_OK;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
|
|
|
|
2012-03-28 20:40:06 +04:00
|
|
|
dom_string_unref(bordercolor);
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_border_spacing(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-28 20:13:23 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *node_name = NULL;
|
|
|
|
dom_string *cellspacing = NULL;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((err != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_table)) {
|
2012-03-28 20:13:23 +04:00
|
|
|
dom_string_unref(node_name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 20:13:23 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 20:13:23 +04:00
|
|
|
dom_string_unref(node_name);
|
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_cellspacing, &cellspacing);
|
2012-03-28 20:13:23 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (cellspacing == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 20:13:23 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 20:13:23 +04:00
|
|
|
|
|
|
|
if (parse_dimension((const char *)dom_string_data(cellspacing),
|
|
|
|
false,
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.position.h.value,
|
|
|
|
&hint->data.position.h.unit)) {
|
2012-03-28 20:13:23 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
hint->data.position.v = hint->data.position.h;
|
|
|
|
hint->status = CSS_BORDER_SPACING_SET;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 20:13:23 +04:00
|
|
|
dom_string_unref(cellspacing);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(cellspacing);
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_width(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-28 19:51:28 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_string *width = NULL;
|
|
|
|
dom_exception err;
|
|
|
|
bool textarea = false;
|
|
|
|
bool input = false;
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 19:51:28 +04:00
|
|
|
err = dom_node_get_node_name(node, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_hr) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_iframe) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_img) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_object) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_table) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_applet)) {
|
2012-03-28 19:51:28 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_width, &width);
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_textarea)) {
|
2012-03-28 19:51:28 +04:00
|
|
|
textarea = true;
|
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_cols, &width);
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_input)) {
|
2012-03-28 19:51:28 +04:00
|
|
|
input = true;
|
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_size, &width);
|
2012-03-28 19:51:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
if ((err != DOM_NO_ERR) || (width == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 19:51:28 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 19:51:28 +04:00
|
|
|
if (parse_dimension((const char *)dom_string_data(width),
|
|
|
|
false,
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
hint->status = CSS_WIDTH_SET;
|
2012-03-28 19:51:28 +04:00
|
|
|
dom_string_unref(width);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 19:51:28 +04:00
|
|
|
if (textarea) {
|
|
|
|
hint->data.length.unit = CSS_UNIT_EX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input) {
|
2012-07-15 17:06:37 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_type, &width);
|
2012-11-04 21:26:42 +04:00
|
|
|
if (err != DOM_NO_ERR) {
|
2012-03-28 19:51:28 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2012-11-04 21:26:42 +04:00
|
|
|
if ((width == NULL) ||
|
2013-01-02 17:56:00 +04:00
|
|
|
dom_string_caseless_lwc_isequal(width,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_text) ||
|
2013-01-02 17:56:00 +04:00
|
|
|
dom_string_caseless_lwc_isequal(width,
|
2012-11-04 21:29:26 +04:00
|
|
|
corestring_lwc_search) ||
|
2013-01-02 17:56:00 +04:00
|
|
|
dom_string_caseless_lwc_isequal(width,
|
2012-11-04 21:36:17 +04:00
|
|
|
corestring_lwc_file) ||
|
2013-01-02 17:56:00 +04:00
|
|
|
dom_string_caseless_lwc_isequal(width,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_password)) {
|
2012-03-28 19:51:28 +04:00
|
|
|
hint->data.length.unit = CSS_UNIT_EX;
|
|
|
|
}
|
|
|
|
dom_string_unref(width);
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2012-03-28 19:51:28 +04:00
|
|
|
return CSS_OK;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 19:51:28 +04:00
|
|
|
dom_string_unref(width);
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 19:51:28 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_height(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-28 17:34:54 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_string *height = NULL;
|
|
|
|
dom_exception err;
|
|
|
|
bool textarea = false;
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 17:34:54 +04:00
|
|
|
err = dom_node_get_node_name(node, &name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_iframe) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_td) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_th) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_tr) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_img) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_object) ||
|
|
|
|
dom_string_caseless_lwc_isequal(name, corestring_lwc_applet)) {
|
2012-03-28 17:34:54 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_height, &height);
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_textarea)) {
|
2012-03-28 17:34:54 +04:00
|
|
|
textarea = true;
|
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_rows, &height);
|
2012-03-28 17:34:54 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 17:34:54 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
if ((err != DOM_NO_ERR) || (height == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-28 17:34:54 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 17:34:54 +04:00
|
|
|
if (parse_dimension((const char *)dom_string_data(height),
|
|
|
|
false,
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
hint->status = CSS_HEIGHT_SET;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 17:34:54 +04:00
|
|
|
if (textarea) {
|
|
|
|
hint->data.length.unit = CSS_UNIT_EM;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-28 17:34:54 +04:00
|
|
|
dom_string_unref(height);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-28 17:34:54 +04:00
|
|
|
dom_string_unref(height);
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static css_error
|
|
|
|
node_presentational_hint_font_size(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-26 03:21:13 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *node_name = NULL;
|
|
|
|
dom_string *size;
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-26 03:21:13 +04:00
|
|
|
err = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((err != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_font)) {
|
2012-03-26 03:21:13 +04:00
|
|
|
dom_string_unref(node_name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-26 03:21:13 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-26 03:21:13 +04:00
|
|
|
dom_string_unref(node_name);
|
|
|
|
|
2012-09-30 13:21:46 +04:00
|
|
|
err = dom_element_get_attribute(node, corestring_dom_size, &size);
|
2012-03-26 03:21:13 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (size == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2012-03-26 03:21:13 +04:00
|
|
|
if (parse_font_size((const char *)dom_string_data(size),
|
|
|
|
&hint->status,
|
|
|
|
&hint->data.length.value,
|
|
|
|
&hint->data.length.unit)) {
|
|
|
|
dom_string_unref(size);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-26 03:21:13 +04:00
|
|
|
dom_string_unref(size);
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_float(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-26 03:14:18 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *node_name = NULL;
|
|
|
|
dom_string *align;
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2012-03-26 03:14:18 +04:00
|
|
|
err = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((err != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-26 03:14:18 +04:00
|
|
|
/** \todo input[type=image][align=*] - $11.3.3 */
|
2012-07-22 17:06:45 +04:00
|
|
|
if (!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_applet) &&
|
2012-07-22 17:06:45 +04:00
|
|
|
!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_embed) &&
|
2012-07-22 17:06:45 +04:00
|
|
|
!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_iframe) &&
|
2012-07-22 17:06:45 +04:00
|
|
|
!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_img) &&
|
2012-07-22 17:06:45 +04:00
|
|
|
!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_object)) {
|
2012-03-26 03:14:18 +04:00
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(node_name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
err = dom_element_get_attribute(node, corestring_dom_align, &align);
|
2012-03-26 03:14:18 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (align == NULL)) {
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2013-01-02 18:06:02 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(align,
|
|
|
|
corestring_lwc_left)) {
|
2012-03-26 03:14:18 +04:00
|
|
|
hint->status = CSS_FLOAT_LEFT;
|
|
|
|
dom_string_unref(align);
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_OK;
|
2013-01-02 18:06:02 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(align,
|
|
|
|
corestring_lwc_right)) {
|
2012-03-26 03:14:18 +04:00
|
|
|
hint->status = CSS_FLOAT_RIGHT;
|
|
|
|
dom_string_unref(align);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(align);
|
|
|
|
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_color(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
|
|
|
css_error error;
|
2012-03-25 21:23:26 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *node_name = NULL;
|
|
|
|
dom_string *color;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 21:23:26 +04:00
|
|
|
err = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((err != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(node_name, corestring_lwc_a)) {
|
2012-03-25 21:23:26 +04:00
|
|
|
/* find body node */
|
|
|
|
css_qname qs;
|
|
|
|
dom_node *bodynode = NULL;
|
|
|
|
bool is_visited;
|
|
|
|
|
|
|
|
qs.ns = NULL;
|
2012-07-22 18:48:55 +04:00
|
|
|
qs.name = lwc_string_ref(corestring_lwc_body);
|
2012-03-25 21:23:26 +04:00
|
|
|
if (named_ancestor_node(ctx, node, &qs,
|
2012-03-26 03:00:39 +04:00
|
|
|
(void *)&bodynode) != CSS_OK) {
|
2012-03-25 21:23:26 +04:00
|
|
|
/* Didn't find, or had error */
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
lwc_string_unref(qs.name);
|
|
|
|
|
|
|
|
/* deal with missing body ancestor */
|
|
|
|
if (bodynode == NULL) {
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_BADPARM;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 21:23:26 +04:00
|
|
|
error = node_is_visited(ctx, node, &is_visited);
|
2012-03-25 18:38:37 +04:00
|
|
|
if (error != CSS_OK)
|
|
|
|
return error;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 21:23:26 +04:00
|
|
|
if (is_visited) {
|
2012-09-25 03:39:03 +04:00
|
|
|
err = dom_element_get_attribute(bodynode,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_vlink, &color);
|
2012-03-25 21:23:26 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (color == NULL)) {
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-25 03:39:03 +04:00
|
|
|
err = dom_element_get_attribute(bodynode,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_link, &color);
|
2012-03-25 21:23:26 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (color == NULL)) {
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 17:06:45 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_body)) {
|
2012-07-22 17:06:45 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_text, &color);
|
2012-03-25 21:23:26 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (color == NULL)) {
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
} else {
|
2012-07-22 17:06:45 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_color, &color);
|
2012-03-25 21:23:26 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (color == NULL)) {
|
|
|
|
dom_string_unref(node_name);
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 21:23:26 +04:00
|
|
|
if (!nscss_parse_colour((const char *)dom_string_data(color),
|
|
|
|
&hint->data.color)) {
|
2013-10-25 16:05:38 +04:00
|
|
|
dom_string_unref(color);
|
2012-03-25 21:23:26 +04:00
|
|
|
dom_string_unref(node_name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 21:23:26 +04:00
|
|
|
hint->status = CSS_COLOR_COLOR;
|
|
|
|
|
2013-10-25 16:05:38 +04:00
|
|
|
dom_string_unref(color);
|
2012-03-25 21:23:26 +04:00
|
|
|
dom_string_unref(node_name);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_OK;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_caption_side(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 20:38:17 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *node_name = NULL;
|
|
|
|
dom_string *align = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 20:38:17 +04:00
|
|
|
err = dom_node_get_node_name(node, &node_name);
|
|
|
|
if ((err != DOM_NO_ERR) || (node_name == NULL)) {
|
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
if (!dom_string_caseless_lwc_isequal(node_name,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_lwc_caption)) {
|
2012-03-25 20:38:17 +04:00
|
|
|
dom_string_unref(node_name);
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:38:17 +04:00
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 20:38:17 +04:00
|
|
|
dom_string_unref(node_name);
|
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
err = dom_element_get_attribute(node, corestring_dom_align, &align);
|
2012-03-25 20:38:17 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (align == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-07-22 18:48:55 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(align, corestring_lwc_bottom)) {
|
2012-03-25 20:38:17 +04:00
|
|
|
hint->status = CSS_CAPTION_SIDE_BOTTOM;
|
|
|
|
dom_string_unref(align);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(align);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_background_color(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 20:38:17 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *bgcolor;
|
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_bgcolor, &bgcolor);
|
2012-03-25 20:38:17 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (bgcolor == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 20:38:17 +04:00
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 20:38:17 +04:00
|
|
|
if (nscss_parse_colour((const char *)dom_string_data(bgcolor),
|
2012-03-25 18:38:37 +04:00
|
|
|
&hint->data.color)) {
|
|
|
|
hint->status = CSS_BACKGROUND_COLOR_COLOR;
|
2012-03-25 20:38:17 +04:00
|
|
|
dom_string_unref(bgcolor);
|
|
|
|
return CSS_OK;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 20:38:17 +04:00
|
|
|
dom_string_unref(bgcolor);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 19:19:12 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
static css_error
|
|
|
|
node_presentational_hint_background_image(nscss_select_ctx *ctx,
|
|
|
|
dom_node *node,
|
|
|
|
css_hint *hint)
|
|
|
|
{
|
2012-03-25 19:12:15 +04:00
|
|
|
dom_exception err;
|
|
|
|
dom_string *atr_val;
|
2012-03-25 18:38:37 +04:00
|
|
|
nserror error;
|
2012-03-25 19:14:25 +04:00
|
|
|
nsurl *url;
|
2012-03-25 19:12:15 +04:00
|
|
|
lwc_string *iurl;
|
|
|
|
lwc_error lerror;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
err = dom_element_get_attribute(node,
|
2012-07-22 18:48:55 +04:00
|
|
|
corestring_dom_background, &atr_val);
|
2012-03-25 19:12:15 +04:00
|
|
|
if ((err != DOM_NO_ERR) || (atr_val == NULL)) {
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
2012-03-25 19:12:15 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
error = nsurl_join(ctx->base_url,
|
|
|
|
(const char *)dom_string_data(atr_val), &url);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 19:12:15 +04:00
|
|
|
dom_string_unref(atr_val);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
return CSS_NOMEM;
|
2012-03-25 19:12:15 +04:00
|
|
|
}
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-07-22 17:06:45 +04:00
|
|
|
lerror = lwc_intern_string(nsurl_access(url),
|
|
|
|
nsurl_length(url), &iurl);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 19:12:15 +04:00
|
|
|
nsurl_unref(url);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 19:12:15 +04:00
|
|
|
if (lerror == lwc_error_oom) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lerror == lwc_error_ok) {
|
|
|
|
hint->data.string = iurl;
|
|
|
|
hint->status = CSS_BACKGROUND_IMAGE_IMAGE;
|
|
|
|
return CSS_OK;
|
2012-03-25 18:38:37 +04:00
|
|
|
}
|
2012-03-25 19:12:15 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
/**
|
|
|
|
* Callback to retrieve presentational hints for a node
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param node DOM node
|
|
|
|
* \param property CSS property to retrieve
|
|
|
|
* \param hint Pointer to hint object to populate
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_PROPERTY_NOT_SET if there is no hint for the requested property,
|
|
|
|
* CSS_NOMEM on memory exhaustion.
|
|
|
|
*/
|
|
|
|
css_error node_presentational_hint(void *pw, void *node,
|
|
|
|
uint32_t property, css_hint *hint)
|
|
|
|
{
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
switch (property) {
|
|
|
|
case CSS_PROP_BACKGROUND_IMAGE:
|
|
|
|
return node_presentational_hint_background_image(pw, node, hint);
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_BACKGROUND_COLOR:
|
|
|
|
return node_presentational_hint_background_color(pw, node, hint);
|
|
|
|
case CSS_PROP_CAPTION_SIDE:
|
|
|
|
return node_presentational_hint_caption_side(pw, node, hint);
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_COLOR:
|
|
|
|
return node_presentational_hint_color(pw, node, hint);
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_FLOAT:
|
|
|
|
return node_presentational_hint_float(pw, node, hint);
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_FONT_SIZE:
|
|
|
|
return node_presentational_hint_font_size(pw, node, hint);
|
2009-08-22 13:56:41 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_HEIGHT:
|
|
|
|
return node_presentational_hint_height(pw, node, hint);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_WIDTH:
|
|
|
|
return node_presentational_hint_width(pw, node, hint);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_BORDER_SPACING:
|
|
|
|
return node_presentational_hint_border_spacing(pw, node, hint);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_BORDER_TOP_COLOR :
|
|
|
|
case CSS_PROP_BORDER_RIGHT_COLOR :
|
|
|
|
case CSS_PROP_BORDER_BOTTOM_COLOR :
|
|
|
|
case CSS_PROP_BORDER_LEFT_COLOR :
|
|
|
|
return node_presentational_hint_border_trbl_color(pw, node, hint);
|
2009-08-21 21:05:22 +04:00
|
|
|
|
2012-03-25 18:38:37 +04:00
|
|
|
case CSS_PROP_BORDER_TOP_STYLE :
|
|
|
|
case CSS_PROP_BORDER_RIGHT_STYLE :
|
|
|
|
case CSS_PROP_BORDER_BOTTOM_STYLE :
|
|
|
|
case CSS_PROP_BORDER_LEFT_STYLE :
|
|
|
|
return node_presentational_hint_border_trbl_style(pw, node, hint);
|
|
|
|
|
|
|
|
case CSS_PROP_BORDER_TOP_WIDTH :
|
|
|
|
case CSS_PROP_BORDER_RIGHT_WIDTH :
|
|
|
|
case CSS_PROP_BORDER_BOTTOM_WIDTH :
|
|
|
|
case CSS_PROP_BORDER_LEFT_WIDTH :
|
|
|
|
return node_presentational_hint_border_trbl_width(pw, node, hint);
|
|
|
|
|
|
|
|
case CSS_PROP_MARGIN_TOP :
|
|
|
|
case CSS_PROP_MARGIN_BOTTOM :
|
|
|
|
return node_presentational_hint_margin_tb(pw, node, hint);
|
|
|
|
|
|
|
|
case CSS_PROP_MARGIN_RIGHT:
|
|
|
|
case CSS_PROP_MARGIN_LEFT:
|
2012-03-25 20:45:08 +04:00
|
|
|
return node_presentational_hint_margin_rl(pw, node, hint, property);
|
2012-03-25 18:38:37 +04:00
|
|
|
|
|
|
|
case CSS_PROP_PADDING_TOP:
|
|
|
|
case CSS_PROP_PADDING_RIGHT :
|
|
|
|
case CSS_PROP_PADDING_BOTTOM :
|
|
|
|
case CSS_PROP_PADDING_LEFT:
|
|
|
|
return node_presentational_hint_padding_trbl(pw, node, hint);
|
|
|
|
|
|
|
|
case CSS_PROP_TEXT_ALIGN:
|
|
|
|
return node_presentational_hint_text_align(pw, node, hint);
|
|
|
|
|
|
|
|
case CSS_PROP_VERTICAL_ALIGN:
|
|
|
|
return node_presentational_hint_vertical_align(pw, node, hint);
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
2012-03-25 18:38:37 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return CSS_PROPERTY_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to retrieve the User-Agent defaults for a CSS property.
|
|
|
|
*
|
|
|
|
* \param pw HTML document
|
|
|
|
* \param property Property to retrieve defaults for
|
|
|
|
* \param hint Pointer to hint object to populate
|
|
|
|
* \return CSS_OK on success,
|
|
|
|
* CSS_INVALID if the property should not have a user-agent default.
|
|
|
|
*/
|
|
|
|
css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
|
|
|
|
{
|
|
|
|
if (property == CSS_PROP_COLOR) {
|
2010-12-05 00:52:26 +03:00
|
|
|
hint->data.color = 0xff000000;
|
2009-07-24 03:05:34 +04:00
|
|
|
hint->status = CSS_COLOR_COLOR;
|
|
|
|
} else if (property == CSS_PROP_FONT_FAMILY) {
|
|
|
|
hint->data.strings = NULL;
|
2012-03-22 13:34:34 +04:00
|
|
|
switch (nsoption_int(font_default)) {
|
2009-07-24 03:05:34 +04:00
|
|
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
|
|
|
hint->status = CSS_FONT_FAMILY_SANS_SERIF;
|
|
|
|
break;
|
|
|
|
case PLOT_FONT_FAMILY_SERIF:
|
|
|
|
hint->status = CSS_FONT_FAMILY_SERIF;
|
|
|
|
break;
|
|
|
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
|
|
|
hint->status = CSS_FONT_FAMILY_MONOSPACE;
|
|
|
|
break;
|
|
|
|
case PLOT_FONT_FAMILY_CURSIVE:
|
|
|
|
hint->status = CSS_FONT_FAMILY_CURSIVE;
|
|
|
|
break;
|
|
|
|
case PLOT_FONT_FAMILY_FANTASY:
|
|
|
|
hint->status = CSS_FONT_FAMILY_FANTASY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (property == CSS_PROP_QUOTES) {
|
|
|
|
/** \todo Not exactly useful :) */
|
|
|
|
hint->data.strings = NULL;
|
|
|
|
hint->status = CSS_QUOTES_NONE;
|
|
|
|
} else if (property == CSS_PROP_VOICE_FAMILY) {
|
|
|
|
/** \todo Fix this when we have voice-family done */
|
|
|
|
hint->data.strings = NULL;
|
|
|
|
hint->status = 0;
|
|
|
|
} else {
|
|
|
|
return CSS_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
css_error set_libcss_node_data(void *pw, void *node, void *libcss_node_data)
|
|
|
|
{
|
|
|
|
dom_node *n = node;
|
|
|
|
dom_exception err;
|
|
|
|
void *old_node_data;
|
|
|
|
|
|
|
|
/* Set this node's node data */
|
2013-12-14 03:02:15 +04:00
|
|
|
err = dom_node_set_user_data(n,
|
|
|
|
corestring_dom___ns_key_libcss_node_data,
|
2013-12-14 00:25:08 +04:00
|
|
|
libcss_node_data, nscss_dom_user_data_handler,
|
|
|
|
(void *) &old_node_data);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(old_node_data == NULL);
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
css_error get_libcss_node_data(void *pw, void *node, void **libcss_node_data)
|
|
|
|
{
|
|
|
|
dom_node *n = node;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
/* Get this node's node data */
|
2013-12-14 03:02:15 +04:00
|
|
|
err = dom_node_get_user_data(n,
|
|
|
|
corestring_dom___ns_key_libcss_node_data,
|
2013-12-14 00:25:08 +04:00
|
|
|
libcss_node_data);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
return CSS_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Mapping of colour name to CSS color
|
|
|
|
*/
|
|
|
|
struct colour_map {
|
|
|
|
const char *name;
|
|
|
|
css_color color;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name comparator for named colour matching
|
|
|
|
*
|
|
|
|
* \param a Name to match
|
|
|
|
* \param b Colour map entry to consider
|
2009-09-05 19:49:09 +04:00
|
|
|
* \return 0 on match,
|
|
|
|
* < 0 if a < b,
|
2009-07-24 03:05:34 +04:00
|
|
|
* > 0 if b > a.
|
|
|
|
*/
|
|
|
|
int cmp_colour_name(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const char *aa = a;
|
|
|
|
const struct colour_map *bb = b;
|
|
|
|
|
|
|
|
return strcasecmp(aa, bb->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a named colour
|
|
|
|
*
|
|
|
|
* \param name Name to parse
|
|
|
|
* \param result Pointer to location to receive css_color
|
|
|
|
* \return true on success, false on invalid input
|
|
|
|
*/
|
|
|
|
bool parse_named_colour(const char *name, css_color *result)
|
|
|
|
{
|
|
|
|
static const struct colour_map named_colours[] = {
|
2010-12-05 00:52:26 +03:00
|
|
|
{ "aliceblue", 0xfff0f8ff },
|
|
|
|
{ "antiquewhite", 0xfffaebd7 },
|
|
|
|
{ "aqua", 0xff00ffff },
|
|
|
|
{ "aquamarine", 0xff7fffd4 },
|
|
|
|
{ "azure", 0xfff0ffff },
|
|
|
|
{ "beige", 0xfff5f5dc },
|
|
|
|
{ "bisque", 0xffffe4c4 },
|
|
|
|
{ "black", 0xff000000 },
|
|
|
|
{ "blanchedalmond", 0xffffebcd },
|
|
|
|
{ "blue", 0xff0000ff },
|
|
|
|
{ "blueviolet", 0xff8a2be2 },
|
|
|
|
{ "brown", 0xffa52a2a },
|
|
|
|
{ "burlywood", 0xffdeb887 },
|
|
|
|
{ "cadetblue", 0xff5f9ea0 },
|
|
|
|
{ "chartreuse", 0xff7fff00 },
|
|
|
|
{ "chocolate", 0xffd2691e },
|
|
|
|
{ "coral", 0xffff7f50 },
|
|
|
|
{ "cornflowerblue", 0xff6495ed },
|
|
|
|
{ "cornsilk", 0xfffff8dc },
|
|
|
|
{ "crimson", 0xffdc143c },
|
|
|
|
{ "cyan", 0xff00ffff },
|
|
|
|
{ "darkblue", 0xff00008b },
|
|
|
|
{ "darkcyan", 0xff008b8b },
|
|
|
|
{ "darkgoldenrod", 0xffb8860b },
|
|
|
|
{ "darkgray", 0xffa9a9a9 },
|
|
|
|
{ "darkgreen", 0xff006400 },
|
|
|
|
{ "darkgrey", 0xffa9a9a9 },
|
|
|
|
{ "darkkhaki", 0xffbdb76b },
|
|
|
|
{ "darkmagenta", 0xff8b008b },
|
|
|
|
{ "darkolivegreen", 0xff556b2f },
|
|
|
|
{ "darkorange", 0xffff8c00 },
|
|
|
|
{ "darkorchid", 0xff9932cc },
|
|
|
|
{ "darkred", 0xff8b0000 },
|
|
|
|
{ "darksalmon", 0xffe9967a },
|
|
|
|
{ "darkseagreen", 0xff8fbc8f },
|
|
|
|
{ "darkslateblue", 0xff483d8b },
|
|
|
|
{ "darkslategray", 0xff2f4f4f },
|
|
|
|
{ "darkslategrey", 0xff2f4f4f },
|
|
|
|
{ "darkturquoise", 0xff00ced1 },
|
|
|
|
{ "darkviolet", 0xff9400d3 },
|
|
|
|
{ "deeppink", 0xffff1493 },
|
|
|
|
{ "deepskyblue", 0xff00bfff },
|
|
|
|
{ "dimgray", 0xff696969 },
|
|
|
|
{ "dimgrey", 0xff696969 },
|
|
|
|
{ "dodgerblue", 0xff1e90ff },
|
|
|
|
{ "feldspar", 0xffd19275 },
|
|
|
|
{ "firebrick", 0xffb22222 },
|
|
|
|
{ "floralwhite", 0xfffffaf0 },
|
|
|
|
{ "forestgreen", 0xff228b22 },
|
|
|
|
{ "fuchsia", 0xffff00ff },
|
|
|
|
{ "gainsboro", 0xffdcdcdc },
|
|
|
|
{ "ghostwhite", 0xfff8f8ff },
|
|
|
|
{ "gold", 0xffffd700 },
|
|
|
|
{ "goldenrod", 0xffdaa520 },
|
|
|
|
{ "gray", 0xff808080 },
|
|
|
|
{ "green", 0xff008000 },
|
|
|
|
{ "greenyellow", 0xffadff2f },
|
|
|
|
{ "grey", 0xff808080 },
|
|
|
|
{ "honeydew", 0xfff0fff0 },
|
|
|
|
{ "hotpink", 0xffff69b4 },
|
|
|
|
{ "indianred", 0xffcd5c5c },
|
|
|
|
{ "indigo", 0xff4b0082 },
|
|
|
|
{ "ivory", 0xfffffff0 },
|
|
|
|
{ "khaki", 0xfff0e68c },
|
|
|
|
{ "lavender", 0xffe6e6fa },
|
|
|
|
{ "lavenderblush", 0xfffff0f5 },
|
|
|
|
{ "lawngreen", 0xff7cfc00 },
|
|
|
|
{ "lemonchiffon", 0xfffffacd },
|
|
|
|
{ "lightblue", 0xffadd8e6 },
|
|
|
|
{ "lightcoral", 0xfff08080 },
|
|
|
|
{ "lightcyan", 0xffe0ffff },
|
|
|
|
{ "lightgoldenrodyellow", 0xfffafad2 },
|
|
|
|
{ "lightgray", 0xffd3d3d3 },
|
|
|
|
{ "lightgreen", 0xff90ee90 },
|
|
|
|
{ "lightgrey", 0xffd3d3d3 },
|
|
|
|
{ "lightpink", 0xffffb6c1 },
|
|
|
|
{ "lightsalmon", 0xffffa07a },
|
|
|
|
{ "lightseagreen", 0xff20b2aa },
|
|
|
|
{ "lightskyblue", 0xff87cefa },
|
|
|
|
{ "lightslateblue", 0xff8470ff },
|
|
|
|
{ "lightslategray", 0xff778899 },
|
|
|
|
{ "lightslategrey", 0xff778899 },
|
|
|
|
{ "lightsteelblue", 0xffb0c4de },
|
|
|
|
{ "lightyellow", 0xffffffe0 },
|
|
|
|
{ "lime", 0xff00ff00 },
|
|
|
|
{ "limegreen", 0xff32cd32 },
|
|
|
|
{ "linen", 0xfffaf0e6 },
|
|
|
|
{ "magenta", 0xffff00ff },
|
|
|
|
{ "maroon", 0xff800000 },
|
|
|
|
{ "mediumaquamarine", 0xff66cdaa },
|
|
|
|
{ "mediumblue", 0xff0000cd },
|
|
|
|
{ "mediumorchid", 0xffba55d3 },
|
|
|
|
{ "mediumpurple", 0xff9370db },
|
|
|
|
{ "mediumseagreen", 0xff3cb371 },
|
|
|
|
{ "mediumslateblue", 0xff7b68ee },
|
|
|
|
{ "mediumspringgreen", 0xff00fa9a },
|
|
|
|
{ "mediumturquoise", 0xff48d1cc },
|
|
|
|
{ "mediumvioletred", 0xffc71585 },
|
|
|
|
{ "midnightblue", 0xff191970 },
|
|
|
|
{ "mintcream", 0xfff5fffa },
|
|
|
|
{ "mistyrose", 0xffffe4e1 },
|
|
|
|
{ "moccasin", 0xffffe4b5 },
|
|
|
|
{ "navajowhite", 0xffffdead },
|
|
|
|
{ "navy", 0xff000080 },
|
|
|
|
{ "oldlace", 0xfffdf5e6 },
|
|
|
|
{ "olive", 0xff808000 },
|
|
|
|
{ "olivedrab", 0xff6b8e23 },
|
|
|
|
{ "orange", 0xffffa500 },
|
|
|
|
{ "orangered", 0xffff4500 },
|
|
|
|
{ "orchid", 0xffda70d6 },
|
|
|
|
{ "palegoldenrod", 0xffeee8aa },
|
|
|
|
{ "palegreen", 0xff98fb98 },
|
|
|
|
{ "paleturquoise", 0xffafeeee },
|
|
|
|
{ "palevioletred", 0xffdb7093 },
|
|
|
|
{ "papayawhip", 0xffffefd5 },
|
|
|
|
{ "peachpuff", 0xffffdab9 },
|
|
|
|
{ "peru", 0xffcd853f },
|
|
|
|
{ "pink", 0xffffc0cb },
|
|
|
|
{ "plum", 0xffdda0dd },
|
|
|
|
{ "powderblue", 0xffb0e0e6 },
|
|
|
|
{ "purple", 0xff800080 },
|
|
|
|
{ "red", 0xffff0000 },
|
|
|
|
{ "rosybrown", 0xffbc8f8f },
|
|
|
|
{ "royalblue", 0xff4169e1 },
|
|
|
|
{ "saddlebrown", 0xff8b4513 },
|
|
|
|
{ "salmon", 0xfffa8072 },
|
|
|
|
{ "sandybrown", 0xfff4a460 },
|
|
|
|
{ "seagreen", 0xff2e8b57 },
|
|
|
|
{ "seashell", 0xfffff5ee },
|
|
|
|
{ "sienna", 0xffa0522d },
|
|
|
|
{ "silver", 0xffc0c0c0 },
|
|
|
|
{ "skyblue", 0xff87ceeb },
|
|
|
|
{ "slateblue", 0xff6a5acd },
|
|
|
|
{ "slategray", 0xff708090 },
|
|
|
|
{ "slategrey", 0xff708090 },
|
|
|
|
{ "snow", 0xfffffafa },
|
|
|
|
{ "springgreen", 0xff00ff7f },
|
|
|
|
{ "steelblue", 0xff4682b4 },
|
|
|
|
{ "tan", 0xffd2b48c },
|
|
|
|
{ "teal", 0xff008080 },
|
|
|
|
{ "thistle", 0xffd8bfd8 },
|
|
|
|
{ "tomato", 0xffff6347 },
|
|
|
|
{ "turquoise", 0xff40e0d0 },
|
|
|
|
{ "violet", 0xffee82ee },
|
|
|
|
{ "violetred", 0xffd02090 },
|
|
|
|
{ "wheat", 0xfff5deb3 },
|
|
|
|
{ "white", 0xffffffff },
|
|
|
|
{ "whitesmoke", 0xfff5f5f5 },
|
|
|
|
{ "yellow", 0xffffff00 },
|
|
|
|
{ "yellowgreen", 0xff9acd32 }
|
2009-07-24 03:05:34 +04:00
|
|
|
};
|
|
|
|
const struct colour_map *entry;
|
|
|
|
|
|
|
|
entry = bsearch(name, named_colours,
|
|
|
|
sizeof(named_colours) / sizeof(named_colours[0]),
|
|
|
|
sizeof(named_colours[0]),
|
|
|
|
cmp_colour_name);
|
|
|
|
|
|
|
|
if (entry != NULL)
|
|
|
|
*result = entry->color;
|
|
|
|
|
|
|
|
return entry != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a dimension string
|
|
|
|
*
|
|
|
|
* \param data Data to parse (NUL-terminated)
|
|
|
|
* \param strict Whether to enforce strict parsing rules
|
|
|
|
* \param length Pointer to location to receive dimension's length
|
|
|
|
* \param unit Pointer to location to receive dimension's unit
|
|
|
|
* \return true on success, false on invalid input
|
|
|
|
*/
|
|
|
|
bool parse_dimension(const char *data, bool strict, css_fixed *length,
|
|
|
|
css_unit *unit)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
size_t read;
|
|
|
|
css_fixed value;
|
|
|
|
|
|
|
|
len = strlen(data);
|
|
|
|
|
|
|
|
if (parse_number(data, false, true, &value, &read) == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (strict && value < INTTOFIX(1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*length = value;
|
|
|
|
|
|
|
|
if (len > read && data[read] == '%')
|
|
|
|
*unit = CSS_UNIT_PCT;
|
|
|
|
else
|
|
|
|
*unit = CSS_UNIT_PX;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a number string
|
|
|
|
*
|
|
|
|
* \param data Data to parse (NUL-terminated)
|
|
|
|
* \param maybe_negative Negative numbers permitted
|
|
|
|
* \param real Floating point numbers permitted
|
|
|
|
* \param value Pointer to location to receive numeric value
|
2009-09-05 19:49:09 +04:00
|
|
|
* \param consumed Pointer to location to receive number of input
|
2009-07-24 03:05:34 +04:00
|
|
|
* bytes consumed
|
|
|
|
* \return true on success, false on invalid input
|
|
|
|
*/
|
|
|
|
bool parse_number(const char *data, bool maybe_negative, bool real,
|
|
|
|
css_fixed *value, size_t *consumed)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const uint8_t *ptr;
|
|
|
|
int32_t intpart = 0;
|
|
|
|
int32_t fracpart = 0;
|
|
|
|
int32_t pwr = 1;
|
|
|
|
int sign = 1;
|
|
|
|
|
|
|
|
*consumed = 0;
|
|
|
|
|
|
|
|
len = strlen(data);
|
|
|
|
ptr = (const uint8_t *) data;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Skip leading whitespace */
|
|
|
|
while (len > 0 && isWhitespace(ptr[0])) {
|
|
|
|
len--;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Extract sign, if any */
|
|
|
|
if (ptr[0] == '+') {
|
|
|
|
len--;
|
|
|
|
ptr++;
|
|
|
|
} else if (ptr[0] == '-' && maybe_negative) {
|
|
|
|
sign = -1;
|
|
|
|
len--;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Must have a digit [0,9] */
|
|
|
|
if ('0' > ptr[0] || ptr[0] > '9')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Now extract intpart, assuming base 10 */
|
|
|
|
while (len > 0) {
|
|
|
|
/* Stop on first non-digit */
|
|
|
|
if (ptr[0] < '0' || '9' < ptr[0])
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Prevent overflow of 'intpart'; proper clamping below */
|
|
|
|
if (intpart < (1 << 22)) {
|
|
|
|
intpart *= 10;
|
|
|
|
intpart += ptr[0] - '0';
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And fracpart, again, assuming base 10 */
|
|
|
|
if (real && len > 1 && ptr[0] == '.' &&
|
|
|
|
('0' <= ptr[1] && ptr[1] <= '9')) {
|
|
|
|
ptr++;
|
|
|
|
len--;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
if (ptr[0] < '0' || '9' < ptr[0])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (pwr < 1000000) {
|
|
|
|
pwr *= 10;
|
|
|
|
fracpart *= 10;
|
|
|
|
fracpart += ptr[0] - '0';
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
fracpart = ((1 << 10) * fracpart + pwr/2) / pwr;
|
|
|
|
if (fracpart >= (1 << 10)) {
|
|
|
|
intpart++;
|
|
|
|
fracpart &= (1 << 10) - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sign > 0) {
|
|
|
|
/* If the result is larger than we can represent,
|
|
|
|
* then clamp to the maximum value we can store. */
|
|
|
|
if (intpart >= (1 << 21)) {
|
|
|
|
intpart = (1 << 21) - 1;
|
|
|
|
fracpart = (1 << 10) - 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* If the negated result is smaller than we can represent
|
|
|
|
* then clamp to the minimum value we can store. */
|
|
|
|
if (intpart >= (1 << 21)) {
|
|
|
|
intpart = -(1 << 21);
|
|
|
|
fracpart = 0;
|
|
|
|
} else {
|
|
|
|
intpart = -intpart;
|
|
|
|
if (fracpart) {
|
|
|
|
fracpart = (1 << 10) - fracpart;
|
|
|
|
intpart--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = (intpart << 10) | fracpart;
|
|
|
|
|
|
|
|
*consumed = ptr - (const uint8_t *) data;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-01 01:12:57 +04:00
|
|
|
/**
|
2012-07-24 19:19:49 +04:00
|
|
|
* Parse a font \@size attribute
|
2011-09-01 01:12:57 +04:00
|
|
|
*
|
|
|
|
* \param size Data to parse (NUL-terminated)
|
|
|
|
* \param val Pointer to location to receive enum value
|
|
|
|
* \param len Pointer to location to receive length
|
|
|
|
* \param unit Pointer to location to receive unit
|
|
|
|
* \return True on success, false on failure
|
|
|
|
*/
|
|
|
|
bool parse_font_size(const char *size, uint8_t *val,
|
|
|
|
css_fixed *len, css_unit *unit)
|
|
|
|
{
|
|
|
|
static const uint8_t size_map[] = {
|
|
|
|
CSS_FONT_SIZE_XX_SMALL,
|
|
|
|
CSS_FONT_SIZE_SMALL,
|
|
|
|
CSS_FONT_SIZE_MEDIUM,
|
|
|
|
CSS_FONT_SIZE_LARGE,
|
|
|
|
CSS_FONT_SIZE_X_LARGE,
|
|
|
|
CSS_FONT_SIZE_XX_LARGE,
|
|
|
|
CSS_FONT_SIZE_DIMENSION /* xxx-large (see below) */
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *p = size;
|
|
|
|
char mode;
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
/* Skip whitespace */
|
|
|
|
while (*p != '\0' && isWhitespace(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
mode = *p;
|
|
|
|
|
|
|
|
/* Skip +/- */
|
|
|
|
if (mode == '+' || mode == '-')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Need at least one digit */
|
|
|
|
if (*p < '0' || *p > '9') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Consume digits, computing value */
|
|
|
|
while ('0' <= *p && *p <= '9') {
|
|
|
|
value = value * 10 + (*p - '0');
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resolve relative sizes */
|
|
|
|
if (mode == '+')
|
|
|
|
value += 3;
|
|
|
|
else if (mode == '-')
|
|
|
|
value = 3 - value;
|
|
|
|
|
|
|
|
/* Clamp to range [1,7] */
|
|
|
|
if (value < 1)
|
|
|
|
value = 1;
|
|
|
|
else if (value > 7)
|
|
|
|
value = 7;
|
|
|
|
|
|
|
|
if (value == 7) {
|
|
|
|
/* Manufacture xxx-large */
|
2012-03-22 13:34:34 +04:00
|
|
|
*len = FDIV(FMUL(INTTOFIX(3), INTTOFIX(nsoption_int(font_size))),
|
2011-09-01 01:12:57 +04:00
|
|
|
F_10);
|
|
|
|
} else {
|
|
|
|
/* Len is irrelevant */
|
|
|
|
*len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*unit = CSS_UNIT_PT;
|
|
|
|
*val = size_map[value - 1];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* Utility functions *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given character is whitespace
|
|
|
|
*
|
|
|
|
* \param c Character to consider
|
|
|
|
* \return true if character is whitespace, false otherwise
|
|
|
|
*/
|
|
|
|
bool isWhitespace(char c)
|
|
|
|
{
|
|
|
|
return c == ' ' || c == '\t' || c == '\f' || c == '\r' || c == '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given character is a valid hex digit
|
|
|
|
*
|
|
|
|
* \param c Character to consider
|
|
|
|
* \return true if character is a valid hex digit, false otherwise
|
|
|
|
*/
|
|
|
|
bool isHex(char c)
|
|
|
|
{
|
|
|
|
return ('0' <= c && c <= '9') ||
|
|
|
|
('A' <= (c & ~0x20) && (c & ~0x20) <= 'F');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a character representing a hex digit to the corresponding hex value
|
|
|
|
*
|
|
|
|
* \param c Character to convert
|
|
|
|
* \return Hex value represented by character
|
|
|
|
*
|
|
|
|
* \note This function assumes an ASCII-compatible character set
|
|
|
|
*/
|
|
|
|
uint8_t charToHex(char c)
|
|
|
|
{
|
|
|
|
/* 0-9 */
|
|
|
|
c -= '0';
|
|
|
|
|
|
|
|
/* A-F */
|
|
|
|
if (c > 9)
|
|
|
|
c -= 'A' - '9' - 1;
|
|
|
|
|
|
|
|
/* a-f */
|
|
|
|
if (c > 15)
|
|
|
|
c -= 'a' - 'A';
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|