2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
2003-04-04 19:19:32 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#define CSS_INTERNALS
|
2003-04-06 22:09:34 +04:00
|
|
|
#undef NDEBUG
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/content/content.h"
|
2003-04-06 22:09:34 +04:00
|
|
|
#include "netsurf/content/fetch.h"
|
|
|
|
#include "netsurf/content/fetchcache.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2003-04-05 20:24:43 +04:00
|
|
|
#include "netsurf/css/parser.h"
|
2003-06-17 23:24:21 +04:00
|
|
|
#ifdef riscos
|
2003-04-06 22:09:34 +04:00
|
|
|
#include "netsurf/desktop/gui.h"
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* internal structures
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct decl {
|
|
|
|
unsigned long score;
|
|
|
|
struct rule * rule;
|
|
|
|
};
|
|
|
|
|
2003-07-05 01:18:24 +04:00
|
|
|
static void css_atimport_callback(content_msg msg, struct content *css,
|
2003-06-17 23:24:21 +04:00
|
|
|
void *p1, void *p2, const char *error);
|
2003-10-08 01:34:27 +04:00
|
|
|
static bool css_match_rule(struct css_node *rule, xmlNode *element);
|
|
|
|
|
2003-04-04 19:19:32 +04:00
|
|
|
const struct css_style css_base_style = {
|
|
|
|
0xffffff,
|
|
|
|
CSS_CLEAR_NONE,
|
|
|
|
0x000000,
|
|
|
|
CSS_DISPLAY_BLOCK,
|
|
|
|
CSS_FLOAT_NONE,
|
2003-09-09 02:47:38 +04:00
|
|
|
{ CSS_FONT_SIZE_LENGTH, { { 10, CSS_UNIT_PT } } },
|
2004-01-29 00:48:10 +03:00
|
|
|
CSS_FONT_FAMILY_SANS_SERIF,
|
2003-04-04 19:19:32 +04:00
|
|
|
CSS_FONT_WEIGHT_NORMAL,
|
|
|
|
CSS_FONT_STYLE_NORMAL,
|
2004-01-31 01:28:32 +03:00
|
|
|
CSS_FONT_VARIANT_NORMAL,
|
2003-04-04 19:19:32 +04:00
|
|
|
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
|
2003-09-09 02:47:38 +04:00
|
|
|
{ CSS_LINE_HEIGHT_ABSOLUTE, { 1.3 } },
|
2003-04-04 19:19:32 +04:00
|
|
|
CSS_TEXT_ALIGN_LEFT,
|
2003-10-18 03:47:13 +04:00
|
|
|
CSS_TEXT_DECORATION_NONE,
|
2004-02-01 00:18:44 +03:00
|
|
|
CSS_TEXT_TRANSFORM_NONE,
|
2003-10-10 22:13:36 +04:00
|
|
|
CSS_VISIBILITY_VISIBLE,
|
2003-10-08 01:34:27 +04:00
|
|
|
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
|
|
|
|
CSS_WHITE_SPACE_NORMAL
|
2003-04-04 19:19:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct css_style css_empty_style = {
|
|
|
|
CSS_COLOR_INHERIT,
|
|
|
|
CSS_CLEAR_INHERIT,
|
|
|
|
CSS_COLOR_INHERIT,
|
|
|
|
CSS_DISPLAY_INHERIT,
|
|
|
|
CSS_FLOAT_INHERIT,
|
|
|
|
{ CSS_FONT_SIZE_INHERIT, { { 1, CSS_UNIT_EM } } },
|
2004-01-29 00:48:10 +03:00
|
|
|
CSS_FONT_FAMILY_INHERIT,
|
2003-04-04 19:19:32 +04:00
|
|
|
CSS_FONT_WEIGHT_INHERIT,
|
|
|
|
CSS_FONT_STYLE_INHERIT,
|
2004-01-31 01:28:32 +03:00
|
|
|
CSS_FONT_VARIANT_INHERIT,
|
2003-04-15 21:53:00 +04:00
|
|
|
{ CSS_HEIGHT_INHERIT, { 1, CSS_UNIT_EM } },
|
2003-09-09 02:47:38 +04:00
|
|
|
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
|
2003-04-04 19:19:32 +04:00
|
|
|
CSS_TEXT_ALIGN_INHERIT,
|
2003-10-18 03:47:13 +04:00
|
|
|
CSS_TEXT_DECORATION_INHERIT,
|
2004-02-01 00:18:44 +03:00
|
|
|
CSS_TEXT_TRANSFORM_INHERIT,
|
2003-10-10 22:13:36 +04:00
|
|
|
CSS_VISIBILITY_INHERIT,
|
2003-10-08 01:34:27 +04:00
|
|
|
{ CSS_WIDTH_INHERIT, { { 1, CSS_UNIT_EM } } },
|
|
|
|
CSS_WHITE_SPACE_INHERIT
|
2003-04-04 19:19:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct css_style css_blank_style = {
|
|
|
|
TRANSPARENT,
|
|
|
|
CSS_CLEAR_NONE,
|
|
|
|
CSS_COLOR_INHERIT,
|
|
|
|
CSS_DISPLAY_INLINE,
|
|
|
|
CSS_FLOAT_NONE,
|
|
|
|
{ CSS_FONT_SIZE_INHERIT, { { 1, CSS_UNIT_EM } } },
|
2004-01-29 00:48:10 +03:00
|
|
|
CSS_FONT_FAMILY_INHERIT,
|
2003-04-04 19:19:32 +04:00
|
|
|
CSS_FONT_WEIGHT_INHERIT,
|
|
|
|
CSS_FONT_STYLE_INHERIT,
|
2004-01-31 01:28:32 +03:00
|
|
|
CSS_FONT_VARIANT_INHERIT,
|
2003-04-04 19:19:32 +04:00
|
|
|
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
|
2003-09-09 02:47:38 +04:00
|
|
|
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
|
2003-04-04 19:19:32 +04:00
|
|
|
CSS_TEXT_ALIGN_INHERIT,
|
2003-11-05 19:25:35 +03:00
|
|
|
CSS_TEXT_DECORATION_INHERIT,
|
2004-02-01 00:18:44 +03:00
|
|
|
CSS_TEXT_TRANSFORM_INHERIT,
|
2003-10-10 22:13:36 +04:00
|
|
|
CSS_VISIBILITY_INHERIT,
|
2003-10-08 01:34:27 +04:00
|
|
|
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
|
|
|
|
CSS_WHITE_SPACE_INHERIT
|
2003-04-04 19:19:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-27 23:15:23 +03:00
|
|
|
void css_create(struct content *c, const char *params[])
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-04-05 19:35:55 +04:00
|
|
|
unsigned int i;
|
2003-04-04 19:19:32 +04:00
|
|
|
LOG(("content %p", c));
|
2003-04-06 22:09:34 +04:00
|
|
|
c->data.css.css = xcalloc(1, sizeof(*c->data.css.css));
|
|
|
|
css_lex_init(&c->data.css.css->lexer);
|
2003-10-17 21:39:29 +04:00
|
|
|
/*css_parser_Trace(stderr, "css parser: ");*/
|
2003-12-27 04:37:51 +03:00
|
|
|
c->data.css.css->parser = css_parser_Alloc((void*)malloc);
|
2003-04-05 19:35:55 +04:00
|
|
|
for (i = 0; i != HASH_SIZE; i++)
|
2003-04-06 22:09:34 +04:00
|
|
|
c->data.css.css->rule[i] = 0;
|
|
|
|
c->data.css.import_count = 0;
|
2003-04-10 01:57:09 +04:00
|
|
|
c->data.css.import_url = xcalloc(0, sizeof(*c->data.css.import_url));
|
2003-04-06 22:09:34 +04:00
|
|
|
c->data.css.import_content = xcalloc(0, sizeof(*c->data.css.import_content));
|
|
|
|
c->active = 0;
|
2003-10-16 16:43:53 +04:00
|
|
|
c->data.css.data = xcalloc(0, 1);
|
|
|
|
c->data.css.length = 0;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void css_process_data(struct content *c, char *data, unsigned long size)
|
2003-10-16 16:43:53 +04:00
|
|
|
{
|
|
|
|
c->data.css.data = xrealloc(c->data.css.data, c->data.css.length + size + 2);
|
|
|
|
memcpy(c->data.css.data + c->data.css.length, data, size);
|
|
|
|
c->data.css.length += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int css_convert(struct content *c, unsigned int width, unsigned int height)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
int token;
|
|
|
|
YY_BUFFER_STATE buffer;
|
2003-10-17 21:39:29 +04:00
|
|
|
struct parse_params param = {0, c, 0, false};
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-10-16 16:43:53 +04:00
|
|
|
c->data.css.data[c->data.css.length] =
|
|
|
|
c->data.css.data[c->data.css.length + 1] = 0;
|
|
|
|
buffer = css__scan_buffer(c->data.css.data, c->data.css.length + 2,
|
|
|
|
c->data.css.css->lexer);
|
|
|
|
assert(buffer);
|
2003-12-27 04:37:51 +03:00
|
|
|
while ((token = css_lex(c->data.css.css->lexer))) {
|
2003-04-06 22:09:34 +04:00
|
|
|
css_parser_(c->data.css.css->parser, token,
|
2003-04-25 12:03:15 +04:00
|
|
|
xstrdup(css_get_text(c->data.css.css->lexer)),
|
2003-04-05 20:24:43 +04:00
|
|
|
¶m);
|
2003-12-26 03:17:55 +03:00
|
|
|
if (param.syntax_error) {
|
|
|
|
int line = css_get_lineno(c->data.css.css->lexer);
|
|
|
|
LOG(("syntax error near line %i", line));
|
|
|
|
param.syntax_error = false;
|
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
2003-04-06 22:09:34 +04:00
|
|
|
css__delete_buffer(buffer, c->data.css.css->lexer);
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
css_parser_(c->data.css.css->parser, 0, 0, ¶m);
|
2003-04-06 22:09:34 +04:00
|
|
|
css_parser_Free(c->data.css.css->parser, free);
|
2003-10-17 21:39:29 +04:00
|
|
|
|
2003-04-06 22:09:34 +04:00
|
|
|
css_lex_destroy(c->data.css.css->lexer);
|
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
/*css_dump_stylesheet(c->data.css.css);*/
|
2003-09-28 03:36:34 +04:00
|
|
|
|
2003-04-06 22:09:34 +04:00
|
|
|
/* complete fetch of any imported stylesheets */
|
|
|
|
while (c->active != 0) {
|
2003-04-15 21:53:00 +04:00
|
|
|
LOG(("importing %i from '%s'", c->active, c->url));
|
2003-04-06 22:09:34 +04:00
|
|
|
fetch_poll();
|
|
|
|
gui_multitask();
|
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2003-04-04 19:19:32 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void css_revive(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
2003-04-10 01:57:09 +04:00
|
|
|
unsigned int i;
|
|
|
|
/* imported stylesheets */
|
|
|
|
for (i = 0; i != c->data.css.import_count; i++) {
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.css.import_content[i] = fetchcache(
|
|
|
|
c->data.css.import_url[i], c->url,
|
2003-12-27 04:37:51 +03:00
|
|
|
css_atimport_callback, c, (void*)i,
|
2004-01-20 22:08:34 +03:00
|
|
|
c->width, c->height, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->data.css.import_content[i] == 0)
|
|
|
|
continue;
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
|
|
|
c->active++;
|
2003-04-10 01:57:09 +04:00
|
|
|
}
|
|
|
|
while (c->active != 0) {
|
|
|
|
fetch_poll();
|
|
|
|
gui_multitask();
|
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void css_reformat(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void css_destroy(struct content *c)
|
|
|
|
{
|
2003-04-06 22:09:34 +04:00
|
|
|
unsigned int i;
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *r;
|
|
|
|
|
2004-01-20 23:13:43 +03:00
|
|
|
xfree(c->data.css.data);
|
|
|
|
|
2003-04-06 22:09:34 +04:00
|
|
|
for (i = 0; i != HASH_SIZE; i++) {
|
|
|
|
for (r = c->data.css.css->rule[i]; r != 0; r = r->next)
|
|
|
|
xfree(r->style);
|
|
|
|
css_free_node(c->data.css.css->rule[i]);
|
|
|
|
}
|
|
|
|
xfree(c->data.css.css);
|
|
|
|
|
|
|
|
/* imported stylesheets */
|
|
|
|
for (i = 0; i != c->data.css.import_count; i++)
|
2003-04-10 01:57:09 +04:00
|
|
|
if (c->data.css.import_content[i] != 0) {
|
|
|
|
free(c->data.css.import_url[i]);
|
2003-06-17 23:24:21 +04:00
|
|
|
content_remove_user(c->data.css.import_content[i],
|
2003-12-27 04:37:51 +03:00
|
|
|
css_atimport_callback, c, (void*)i);
|
2003-04-10 01:57:09 +04:00
|
|
|
}
|
|
|
|
xfree(c->data.css.import_url);
|
2003-04-06 22:09:34 +04:00
|
|
|
xfree(c->data.css.import_content);
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parser support functions
|
|
|
|
*/
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node * css_new_node(css_node_type type, char *data,
|
|
|
|
struct css_node *left, struct css_node *right)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *node = xcalloc(1, sizeof(*node));
|
2003-04-04 19:19:32 +04:00
|
|
|
node->type = type;
|
|
|
|
node->data = data;
|
2003-09-28 03:36:34 +04:00
|
|
|
node->data2 = 0;
|
2003-04-04 19:19:32 +04:00
|
|
|
node->left = left;
|
|
|
|
node->right = right;
|
|
|
|
node->next = 0;
|
2003-10-08 01:34:27 +04:00
|
|
|
node->comb = CSS_COMB_NONE;
|
2003-04-04 19:19:32 +04:00
|
|
|
node->style = 0;
|
2003-09-28 21:37:43 +04:00
|
|
|
node->specificity = 0;
|
2003-04-04 19:19:32 +04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void css_free_node(struct css_node *node)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
if (node == 0)
|
|
|
|
return;
|
|
|
|
if (node->left != 0)
|
|
|
|
css_free_node(node->left);
|
|
|
|
if (node->right != 0)
|
|
|
|
css_free_node(node->right);
|
|
|
|
if (node->next != 0)
|
|
|
|
css_free_node(node->next);
|
|
|
|
if (node->data != 0)
|
|
|
|
free(node->data);
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
2003-09-28 21:37:43 +04:00
|
|
|
char *css_unquote(char *s)
|
|
|
|
{
|
|
|
|
unsigned int len = strlen(s);
|
|
|
|
memmove(s, s + 1, len);
|
|
|
|
s[len - 2] = 0;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void css_atimport(struct content *c, struct css_node *node)
|
2003-04-06 22:09:34 +04:00
|
|
|
{
|
2003-12-26 03:17:55 +03:00
|
|
|
char *s, *url, *url1;
|
2003-04-06 22:09:34 +04:00
|
|
|
int string = 0, screen = 1;
|
2003-06-17 23:24:21 +04:00
|
|
|
unsigned int i;
|
2003-04-06 22:09:34 +04:00
|
|
|
|
|
|
|
LOG(("@import rule"));
|
|
|
|
|
|
|
|
/* uri(...) or "..." */
|
|
|
|
switch (node->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_URI:
|
2003-04-06 22:09:34 +04:00
|
|
|
LOG(("URI '%s'", node->data));
|
|
|
|
for (s = node->data + 4;
|
|
|
|
*s == ' ' || *s == '\t' || *s == '\r' ||
|
|
|
|
*s == '\n' || *s == '\f';
|
|
|
|
s++)
|
|
|
|
;
|
|
|
|
if (*s == '\'' || *s == '"') {
|
|
|
|
string = 1;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
url = xstrdup(s);
|
|
|
|
for (s = url + strlen(url) - 2;
|
|
|
|
*s == ' ' || *s == '\t' || *s == '\r' ||
|
|
|
|
*s == '\n' || *s == '\f';
|
|
|
|
s--)
|
|
|
|
;
|
|
|
|
if (string)
|
|
|
|
*s = 0;
|
|
|
|
else
|
|
|
|
*(s + 1) = 0;
|
|
|
|
break;
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_STRING:
|
2003-04-06 22:09:34 +04:00
|
|
|
LOG(("STRING '%s'", node->data));
|
2003-09-28 21:37:43 +04:00
|
|
|
url = xstrdup(node->data);
|
2003-04-06 22:09:34 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* media not specified, 'screen', or 'all' */
|
|
|
|
for (node = node->next; node != 0; node = node->next) {
|
|
|
|
screen = 0;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (node->type != CSS_NODE_IDENT) {
|
2003-04-06 22:09:34 +04:00
|
|
|
free(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG(("medium '%s'", node->data));
|
|
|
|
if (strcmp(node->data, "screen") == 0 || strcmp(node->data, "all") == 0) {
|
|
|
|
screen = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node->next;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (node == 0 || node->type != CSS_NODE_COMMA) {
|
2003-04-06 22:09:34 +04:00
|
|
|
free(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!screen) {
|
|
|
|
free(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
url1 = url_join(url, c->url);
|
|
|
|
if (!url1) {
|
|
|
|
free(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-06 22:09:34 +04:00
|
|
|
/* start the fetch */
|
|
|
|
c->data.css.import_count++;
|
2003-04-10 01:57:09 +04:00
|
|
|
c->data.css.import_url = xrealloc(c->data.css.import_url,
|
|
|
|
c->data.css.import_count * sizeof(*c->data.css.import_url));
|
2003-04-06 22:09:34 +04:00
|
|
|
c->data.css.import_content = xrealloc(c->data.css.import_content,
|
|
|
|
c->data.css.import_count * sizeof(*c->data.css.import_content));
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
i = c->data.css.import_count - 1;
|
2003-12-26 03:17:55 +03:00
|
|
|
c->data.css.import_url[i] = url1;
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.css.import_content[i] = fetchcache(
|
|
|
|
c->data.css.import_url[i], c->url, css_atimport_callback,
|
2004-01-20 22:08:34 +03:00
|
|
|
c, (void*)i, c->width, c->height, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->data.css.import_content[i] &&
|
|
|
|
c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
2003-06-17 23:24:21 +04:00
|
|
|
c->active++;
|
2003-04-06 22:09:34 +04:00
|
|
|
|
|
|
|
free(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
void css_atimport_callback(content_msg msg, struct content *css,
|
|
|
|
void *p1, void *p2, const char *error)
|
2003-04-06 22:09:34 +04:00
|
|
|
{
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content *c = p1;
|
|
|
|
unsigned int i = (unsigned int) p2;
|
2003-04-06 22:09:34 +04:00
|
|
|
switch (msg) {
|
2003-06-17 23:24:21 +04:00
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
if (css->type != CONTENT_CSS) {
|
2003-12-27 04:37:51 +03:00
|
|
|
content_remove_user(css, css_atimport_callback, c, (void*)i);
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.css.import_content[i] = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
2003-04-06 22:09:34 +04:00
|
|
|
LOG(("got imported stylesheet '%s'", css->url));
|
|
|
|
/*css_dump_stylesheet(css->data.css);*/
|
|
|
|
c->active--;
|
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
2003-04-06 22:09:34 +04:00
|
|
|
c->data.css.import_content[i] = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
2003-04-06 22:09:34 +04:00
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2003-06-26 15:41:26 +04:00
|
|
|
case CONTENT_MSG_REDIRECT:
|
|
|
|
c->active--;
|
|
|
|
free(c->data.css.import_url[i]);
|
|
|
|
c->data.css.import_url[i] = xstrdup(error);
|
|
|
|
c->data.css.import_content[i] = fetchcache(
|
|
|
|
c->data.css.import_url[i], c->url, css_atimport_callback,
|
2004-01-20 22:08:34 +03:00
|
|
|
c, (void*)i, css->width, css->height, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->data.css.import_content[i] &&
|
|
|
|
c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
2003-06-26 15:41:26 +04:00
|
|
|
c->active++;
|
|
|
|
break;
|
|
|
|
|
2003-04-06 22:09:34 +04:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
/**
|
|
|
|
* Find the style which applies to an element.
|
|
|
|
*/
|
2003-04-06 22:09:34 +04:00
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
void css_get_style(struct content *css, xmlNode *element,
|
|
|
|
struct css_style *style)
|
|
|
|
{
|
|
|
|
struct css_stylesheet *stylesheet = css->data.css.css;
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *rule;
|
2003-09-28 03:36:34 +04:00
|
|
|
unsigned int hash, i;
|
2003-04-06 22:09:34 +04:00
|
|
|
|
2003-09-28 21:37:43 +04:00
|
|
|
/* imported stylesheets */
|
|
|
|
for (i = 0; i != css->data.css.import_count; i++)
|
|
|
|
if (css->data.css.import_content[i] != 0)
|
|
|
|
css_get_style(css->data.css.import_content[i],
|
|
|
|
element, style);
|
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
/* match rules which end with the same element */
|
|
|
|
hash = css_hash((char *) element->name);
|
|
|
|
for (rule = stylesheet->rule[hash]; rule; rule = rule->next)
|
|
|
|
if (css_match_rule(rule, element))
|
|
|
|
css_merge(style, rule->style);
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
/* match rules which apply to all elements */
|
|
|
|
for (rule = stylesheet->rule[0]; rule; rule = rule->next)
|
|
|
|
if (css_match_rule(rule, element))
|
|
|
|
css_merge(style, rule->style);
|
|
|
|
}
|
2003-04-06 22:09:34 +04:00
|
|
|
|
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
/**
|
|
|
|
* Determine if a rule applies to an element.
|
|
|
|
*/
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
bool css_match_rule(struct css_node *rule, xmlNode *element)
|
2003-09-28 03:36:34 +04:00
|
|
|
{
|
|
|
|
bool match;
|
|
|
|
char *s, *word, *space;
|
|
|
|
unsigned int i;
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *detail;
|
2003-09-28 03:36:34 +04:00
|
|
|
xmlNode *anc, *prev;
|
|
|
|
|
2003-10-02 15:12:44 +04:00
|
|
|
assert(element->type == XML_ELEMENT_NODE);
|
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
if (rule->data && strcasecmp(rule->data, (char *) element->name) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (detail = rule->left; detail; detail = detail->next) {
|
2003-10-17 21:39:29 +04:00
|
|
|
s = 0;
|
2003-09-28 03:36:34 +04:00
|
|
|
match = false;
|
|
|
|
switch (detail->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ID:
|
2003-09-28 03:36:34 +04:00
|
|
|
s = (char *) xmlGetProp(element, (const xmlChar *) "id");
|
2003-09-28 21:37:43 +04:00
|
|
|
if (s && strcasecmp(detail->data + 1, s) == 0)
|
2003-09-28 03:36:34 +04:00
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_CLASS:
|
2003-09-28 03:36:34 +04:00
|
|
|
s = (char *) xmlGetProp(element, (const xmlChar *) "class");
|
2003-09-28 21:37:43 +04:00
|
|
|
if (s) {
|
|
|
|
word = s;
|
|
|
|
do {
|
|
|
|
space = strchr(word, ' ');
|
|
|
|
if (space)
|
|
|
|
*space = 0;
|
|
|
|
if (strcasecmp(word, detail->data) == 0) {
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
word = space + 1;
|
|
|
|
} while (space);
|
|
|
|
}
|
2003-09-28 03:36:34 +04:00
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ATTRIB:
|
2003-09-28 03:36:34 +04:00
|
|
|
/* matches if an attribute is present */
|
|
|
|
s = (char *) xmlGetProp(element, (const xmlChar *) detail->data);
|
|
|
|
if (s)
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ATTRIB_EQ:
|
2003-09-28 03:36:34 +04:00
|
|
|
/* matches if an attribute has a certain value */
|
|
|
|
s = (char *) xmlGetProp(element, (const xmlChar *) detail->data);
|
|
|
|
if (s && strcasecmp(detail->data2, s) == 0)
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ATTRIB_INC:
|
2003-09-28 03:36:34 +04:00
|
|
|
/* matches if one of the space separated words
|
|
|
|
* in the attribute is equal */
|
|
|
|
s = (char *) xmlGetProp(element, (const xmlChar *) detail->data);
|
|
|
|
if (s) {
|
|
|
|
word = s;
|
|
|
|
do {
|
|
|
|
space = strchr(word, ' ');
|
|
|
|
if (space)
|
|
|
|
*space = 0;
|
|
|
|
if (strcasecmp(word, detail->data2) == 0) {
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
2003-09-28 21:37:43 +04:00
|
|
|
word = space + 1;
|
|
|
|
} while (space);
|
2003-09-28 03:36:34 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ATTRIB_DM:
|
2003-09-28 03:36:34 +04:00
|
|
|
/* matches if a prefix up to a hyphen matches */
|
|
|
|
s = (char *) xmlGetProp(element, (const xmlChar *) detail->data);
|
|
|
|
if (s) {
|
|
|
|
i = strlen(detail->data2);
|
|
|
|
if (strncasecmp(detail->data2, s, i) == 0 &&
|
|
|
|
(s[i] == '-' || s[i] == 0))
|
|
|
|
match = true;
|
|
|
|
}
|
|
|
|
break;
|
2003-04-05 19:35:55 +04:00
|
|
|
|
2003-10-17 21:39:29 +04:00
|
|
|
case CSS_NODE_PSEUDO:
|
|
|
|
break;
|
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
default:
|
|
|
|
assert(0);
|
2003-04-06 01:38:06 +04:00
|
|
|
}
|
2003-09-28 03:36:34 +04:00
|
|
|
if (s)
|
|
|
|
xmlFree(s);
|
|
|
|
if (!match)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rule->right)
|
|
|
|
return true;
|
2003-10-08 01:34:27 +04:00
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
switch (rule->comb) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_COMB_ANCESTOR:
|
2003-09-28 03:36:34 +04:00
|
|
|
for (anc = element->parent; anc; anc = anc->parent)
|
2003-10-02 15:12:44 +04:00
|
|
|
if (anc->type == XML_ELEMENT_NODE &&
|
|
|
|
css_match_rule(rule->right, anc))
|
2003-09-28 03:36:34 +04:00
|
|
|
return true;
|
2003-04-06 22:09:34 +04:00
|
|
|
break;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_COMB_PRECEDED:
|
2003-09-28 03:36:34 +04:00
|
|
|
for (prev = element->prev;
|
|
|
|
prev && prev->type != XML_ELEMENT_NODE;
|
|
|
|
prev = prev->prev)
|
|
|
|
;
|
|
|
|
if (!prev)
|
|
|
|
return false;
|
|
|
|
return css_match_rule(rule->right, prev);
|
|
|
|
break;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_COMB_PARENT:
|
2003-10-02 15:12:44 +04:00
|
|
|
for (anc = element->parent;
|
|
|
|
anc && anc->type != XML_ELEMENT_NODE;
|
|
|
|
anc = anc->parent)
|
|
|
|
;
|
|
|
|
if (!anc)
|
2003-09-28 03:36:34 +04:00
|
|
|
return false;
|
2003-10-02 15:12:44 +04:00
|
|
|
return css_match_rule(rule->right, anc);
|
2003-09-28 03:36:34 +04:00
|
|
|
break;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
default:
|
|
|
|
assert(0);
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
2003-04-06 22:09:34 +04:00
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
return false;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void css_parse_property_list(struct css_style * style, char * str)
|
|
|
|
{
|
2003-04-05 20:24:43 +04:00
|
|
|
yyscan_t lexer;
|
|
|
|
void *parser;
|
|
|
|
YY_BUFFER_STATE buffer;
|
|
|
|
int token;
|
2003-10-25 18:13:49 +04:00
|
|
|
struct parse_params param = {1, 0, 0, false};
|
2003-04-05 20:24:43 +04:00
|
|
|
|
|
|
|
css_lex_init(&lexer);
|
2003-12-27 04:37:51 +03:00
|
|
|
parser = css_parser_Alloc((void*)malloc);
|
2003-04-25 12:03:15 +04:00
|
|
|
css_parser_(parser, LBRACE, xstrdup("{"), ¶m);
|
2003-04-05 20:24:43 +04:00
|
|
|
|
|
|
|
buffer = css__scan_string(str, lexer);
|
|
|
|
while ((token = css_lex(lexer))) {
|
|
|
|
css_parser_(parser, token,
|
2003-04-25 12:03:15 +04:00
|
|
|
xstrdup(css_get_text(lexer)),
|
2003-04-05 20:24:43 +04:00
|
|
|
¶m);
|
|
|
|
}
|
|
|
|
css__delete_buffer(buffer, lexer);
|
2003-04-25 12:03:15 +04:00
|
|
|
css_parser_(parser, RBRACE, xstrdup("}"), ¶m);
|
2003-04-05 20:24:43 +04:00
|
|
|
css_parser_(parser, 0, 0, ¶m);
|
|
|
|
|
|
|
|
css_parser_Free(parser, free);
|
|
|
|
css_lex_destroy(lexer);
|
|
|
|
|
|
|
|
css_add_declarations(style, param.declaration);
|
|
|
|
|
|
|
|
css_free_node(param.declaration);
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dump a style
|
|
|
|
*/
|
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
static void dump_length(const struct css_length * const length)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%g%s", length->value,
|
2003-11-05 19:25:35 +03:00
|
|
|
css_unit_name[length->unit]);
|
2003-04-06 01:38:06 +04:00
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
|
|
|
|
void css_dump_style(const struct css_style * const style)
|
|
|
|
{
|
2003-04-06 01:38:06 +04:00
|
|
|
fprintf(stderr, "{ ");
|
|
|
|
fprintf(stderr, "background-color: #%lx; ", style->background_color);
|
|
|
|
fprintf(stderr, "clear: %s; ", css_clear_name[style->clear]);
|
|
|
|
fprintf(stderr, "color: #%lx; ", style->color);
|
|
|
|
fprintf(stderr, "display: %s; ", css_display_name[style->display]);
|
|
|
|
fprintf(stderr, "float: %s; ", css_float_name[style->float_]);
|
2003-10-01 00:34:35 +04:00
|
|
|
fprintf(stderr, "font: %s %s ", css_font_style_name[style->font_style],
|
|
|
|
css_font_weight_name[style->font_weight]);
|
2003-04-04 19:19:32 +04:00
|
|
|
switch (style->font_size.size) {
|
2003-04-06 01:38:06 +04:00
|
|
|
case CSS_FONT_SIZE_ABSOLUTE: fprintf(stderr, "[%g]", style->font_size.value.absolute); break;
|
|
|
|
case CSS_FONT_SIZE_LENGTH: dump_length(&style->font_size.value.length); break;
|
|
|
|
case CSS_FONT_SIZE_PERCENT: fprintf(stderr, "%g%%", style->font_size.value.percent); break;
|
|
|
|
case CSS_FONT_SIZE_INHERIT: fprintf(stderr, "inherit"); break;
|
|
|
|
default: fprintf(stderr, "UNKNOWN"); break;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
2003-10-01 00:34:35 +04:00
|
|
|
fprintf(stderr, "/");
|
2003-04-04 19:19:32 +04:00
|
|
|
switch (style->line_height.size) {
|
2003-04-06 01:38:06 +04:00
|
|
|
case CSS_LINE_HEIGHT_ABSOLUTE: fprintf(stderr, "[%g]", style->line_height.value.absolute); break;
|
|
|
|
case CSS_LINE_HEIGHT_LENGTH: dump_length(&style->line_height.value.length); break;
|
|
|
|
case CSS_LINE_HEIGHT_PERCENT: fprintf(stderr, "%g%%", style->line_height.value.percent); break;
|
|
|
|
case CSS_LINE_HEIGHT_INHERIT: fprintf(stderr, "inherit"); break;
|
|
|
|
default: fprintf(stderr, "UNKNOWN"); break;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
2004-01-29 02:15:12 +03:00
|
|
|
fprintf(stderr, " %s", css_font_family_name[style->font_family]);
|
2004-01-31 01:28:32 +03:00
|
|
|
fprintf(stderr, " %s", css_font_variant_name[style->font_variant]);
|
2003-04-06 01:38:06 +04:00
|
|
|
fprintf(stderr, "; ");
|
2003-10-01 00:34:35 +04:00
|
|
|
fprintf(stderr, "height: ");
|
|
|
|
switch (style->height.height) {
|
|
|
|
case CSS_HEIGHT_AUTO: fprintf(stderr, "auto"); break;
|
|
|
|
case CSS_HEIGHT_LENGTH: dump_length(&style->height.length); break;
|
|
|
|
default: fprintf(stderr, "UNKNOWN"); break;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "; ");
|
2003-04-06 01:38:06 +04:00
|
|
|
fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]);
|
2003-11-05 19:25:35 +03:00
|
|
|
fprintf(stderr, "text-decoration:");
|
|
|
|
switch (style->text_decoration) {
|
|
|
|
case CSS_TEXT_DECORATION_NONE: fprintf(stderr, " none"); break;
|
|
|
|
case CSS_TEXT_DECORATION_INHERIT: fprintf(stderr, " inherit"); break;
|
|
|
|
default:
|
|
|
|
if (style->text_decoration & CSS_TEXT_DECORATION_UNDERLINE)
|
|
|
|
fprintf(stderr, " underline");
|
|
|
|
if (style->text_decoration & CSS_TEXT_DECORATION_OVERLINE)
|
|
|
|
fprintf(stderr, " overline");
|
|
|
|
if (style->text_decoration & CSS_TEXT_DECORATION_LINE_THROUGH)
|
|
|
|
fprintf(stderr, " line-through");
|
|
|
|
if (style->text_decoration & CSS_TEXT_DECORATION_BLINK)
|
|
|
|
fprintf(stderr, " blink");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "; ");
|
2004-02-01 00:18:44 +03:00
|
|
|
fprintf(stderr, "text-transform: %s; ", css_text_transform_name[style->text_transform]);
|
2003-10-16 16:43:53 +04:00
|
|
|
fprintf(stderr, "visibility: %s; ", css_visibility_name[style->visibility]);
|
2003-04-06 01:38:06 +04:00
|
|
|
fprintf(stderr, "width: ");
|
2003-04-04 19:19:32 +04:00
|
|
|
switch (style->width.width) {
|
2003-04-06 01:38:06 +04:00
|
|
|
case CSS_WIDTH_AUTO: fprintf(stderr, "auto"); break;
|
|
|
|
case CSS_WIDTH_LENGTH: dump_length(&style->width.value.length); break;
|
|
|
|
case CSS_WIDTH_PERCENT: fprintf(stderr, "%g%%", style->width.value.percent); break;
|
|
|
|
default: fprintf(stderr, "UNKNOWN"); break;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
fprintf(stderr, "; ");
|
2003-10-08 01:34:27 +04:00
|
|
|
fprintf(stderr, "white-space: %s; ", css_white_space_name[style->white_space]);
|
2003-04-06 01:38:06 +04:00
|
|
|
fprintf(stderr, "}");
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void css_dump_stylesheet(const struct css_stylesheet * stylesheet)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *r, *n, *m;
|
2003-04-06 01:38:06 +04:00
|
|
|
for (i = 0; i != HASH_SIZE; i++) {
|
2003-10-16 16:43:53 +04:00
|
|
|
/*fprintf(stderr, "hash %i:\n", i);*/
|
2003-04-06 01:38:06 +04:00
|
|
|
for (r = stylesheet->rule[i]; r != 0; r = r->next) {
|
|
|
|
for (n = r; n != 0; n = n->right) {
|
|
|
|
if (n->data != 0)
|
|
|
|
fprintf(stderr, "%s", n->data);
|
|
|
|
for (m = n->left; m != 0; m = m->next) {
|
|
|
|
switch (m->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ID: fprintf(stderr, "%s", m->data); break;
|
|
|
|
case CSS_NODE_CLASS: fprintf(stderr, ".%s", m->data); break;
|
|
|
|
case CSS_NODE_ATTRIB: fprintf(stderr, "[%s]", m->data); break;
|
|
|
|
case CSS_NODE_ATTRIB_EQ: fprintf(stderr, "[%s=%s]", m->data, m->data2); break;
|
|
|
|
case CSS_NODE_ATTRIB_INC: fprintf(stderr, "[%s~=%s]", m->data, m->data2); break;
|
|
|
|
case CSS_NODE_ATTRIB_DM: fprintf(stderr, "[%s|=%s]", m->data, m->data2); break;
|
2003-10-17 21:39:29 +04:00
|
|
|
case CSS_NODE_PSEUDO: fprintf(stderr, ":%s", m->data); break;
|
2003-04-06 01:38:06 +04:00
|
|
|
default: fprintf(stderr, "unexpected node");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
2003-09-28 21:37:43 +04:00
|
|
|
fprintf(stderr, "%lx ", r->specificity);
|
2003-04-06 01:38:06 +04:00
|
|
|
css_dump_style(r->style);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
|
|
|
|
2003-04-04 19:19:32 +04:00
|
|
|
/**
|
|
|
|
* cascade styles
|
|
|
|
*/
|
|
|
|
|
|
|
|
void css_cascade(struct css_style * const style, const struct css_style * const apply)
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
|
2003-11-05 19:25:35 +03:00
|
|
|
/* text-decoration: approximate CSS 2.1 by inheriting into inline elements */
|
|
|
|
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
|
|
|
|
style->text_decoration = apply->text_decoration;
|
|
|
|
/* if (style->display == CSS_DISPLAY_INLINE && apply->display != CSS_DISPLAY_INLINE)
|
|
|
|
style->text_decoration = CSS_TEXT_DECORATION_NONE;*/
|
|
|
|
|
2003-04-04 19:19:32 +04:00
|
|
|
if (apply->background_color != CSS_COLOR_INHERIT)
|
|
|
|
style->background_color = apply->background_color;
|
|
|
|
if (apply->clear != CSS_CLEAR_INHERIT)
|
|
|
|
style->clear = apply->clear;
|
|
|
|
if (apply->color != CSS_COLOR_INHERIT)
|
|
|
|
style->color = apply->color;
|
|
|
|
if (apply->display != CSS_DISPLAY_INHERIT)
|
|
|
|
style->display = apply->display;
|
|
|
|
if (apply->float_ != CSS_FLOAT_INHERIT)
|
|
|
|
style->float_ = apply->float_;
|
2004-01-29 00:48:10 +03:00
|
|
|
if (apply->font_family != CSS_FONT_FAMILY_INHERIT)
|
|
|
|
style->font_family = apply->font_family;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (apply->font_style != CSS_FONT_STYLE_INHERIT)
|
|
|
|
style->font_style = apply->font_style;
|
|
|
|
if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT)
|
|
|
|
style->font_weight = apply->font_weight;
|
2004-01-31 01:28:32 +03:00
|
|
|
if (apply->font_variant != CSS_FONT_VARIANT_INHERIT)
|
|
|
|
style->font_variant = apply->font_variant;
|
2003-04-04 19:19:32 +04:00
|
|
|
if (apply->height.height != CSS_HEIGHT_INHERIT)
|
|
|
|
style->height = apply->height;
|
2003-07-20 17:13:09 +04:00
|
|
|
if (apply->line_height.size != CSS_LINE_HEIGHT_INHERIT)
|
|
|
|
style->line_height = apply->line_height;
|
2003-04-04 19:19:32 +04:00
|
|
|
if (apply->text_align != CSS_TEXT_ALIGN_INHERIT)
|
|
|
|
style->text_align = apply->text_align;
|
2004-02-01 00:18:44 +03:00
|
|
|
if (apply->text_transform != CSS_TEXT_TRANSFORM_INHERIT)
|
|
|
|
style->text_transform = apply->text_transform;
|
2003-10-10 22:13:36 +04:00
|
|
|
if (apply->visibility != CSS_VISIBILITY_INHERIT)
|
2003-11-05 19:25:35 +03:00
|
|
|
style->visibility = apply->visibility;
|
2003-04-04 19:19:32 +04:00
|
|
|
if (apply->width.width != CSS_WIDTH_INHERIT)
|
|
|
|
style->width = apply->width;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (apply->white_space != CSS_WHITE_SPACE_INHERIT)
|
|
|
|
style->white_space = apply->white_space;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
|
|
|
/* font-size */
|
|
|
|
f = apply->font_size.value.percent / 100;
|
|
|
|
switch (apply->font_size.size) {
|
|
|
|
case CSS_FONT_SIZE_ABSOLUTE:
|
|
|
|
style->font_size = apply->font_size;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_SIZE_LENGTH:
|
|
|
|
switch (apply->font_size.value.length.unit) {
|
|
|
|
case CSS_UNIT_EM:
|
|
|
|
f = apply->font_size.value.length.value;
|
|
|
|
break;
|
|
|
|
case CSS_UNIT_EX:
|
|
|
|
f = apply->font_size.value.length.value * 0.6 /*?*/;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style->font_size = apply->font_size;
|
|
|
|
}
|
|
|
|
if ((apply->font_size.value.length.unit != CSS_UNIT_EM) &&
|
|
|
|
(apply->font_size.value.length.unit != CSS_UNIT_EX))
|
|
|
|
break;
|
|
|
|
/* drop through if EM or EX */
|
|
|
|
case CSS_FONT_SIZE_PERCENT:
|
|
|
|
switch (style->font_size.size) {
|
|
|
|
case CSS_FONT_SIZE_ABSOLUTE:
|
|
|
|
style->font_size.value.absolute *= f;
|
|
|
|
break;
|
|
|
|
case CSS_FONT_SIZE_LENGTH:
|
|
|
|
style->font_size.value.length.value *= f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
die("attempting percentage of unknown font-size");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CSS_FONT_SIZE_INHERIT:
|
|
|
|
default: /* leave unchanged */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
void css_merge(struct css_style * const style, const struct css_style * const apply)
|
|
|
|
{
|
|
|
|
if (apply->background_color != CSS_COLOR_INHERIT)
|
|
|
|
style->background_color = apply->background_color;
|
|
|
|
if (apply->clear != CSS_CLEAR_INHERIT)
|
|
|
|
style->clear = apply->clear;
|
|
|
|
if (apply->color != CSS_COLOR_INHERIT)
|
|
|
|
style->color = apply->color;
|
|
|
|
if (apply->display != CSS_DISPLAY_INHERIT)
|
|
|
|
style->display = apply->display;
|
|
|
|
if (apply->float_ != CSS_FLOAT_INHERIT)
|
|
|
|
style->float_ = apply->float_;
|
2004-01-29 00:48:10 +03:00
|
|
|
if (apply->font_family != CSS_FONT_FAMILY_INHERIT)
|
|
|
|
style->font_family = apply->font_family;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (apply->font_size.size != CSS_FONT_SIZE_INHERIT)
|
|
|
|
style->font_size = apply->font_size;
|
|
|
|
if (apply->font_style != CSS_FONT_STYLE_INHERIT)
|
|
|
|
style->font_style = apply->font_style;
|
|
|
|
if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT)
|
|
|
|
style->font_weight = apply->font_weight;
|
2004-01-31 01:28:32 +03:00
|
|
|
if (apply->font_variant != CSS_FONT_VARIANT_INHERIT)
|
|
|
|
style->font_variant = apply->font_variant;
|
2003-04-06 01:38:06 +04:00
|
|
|
if (apply->height.height != CSS_HEIGHT_INHERIT)
|
|
|
|
style->height = apply->height;
|
2003-07-20 17:13:09 +04:00
|
|
|
if (apply->line_height.size != CSS_LINE_HEIGHT_INHERIT)
|
|
|
|
style->line_height = apply->line_height;
|
2003-04-06 01:38:06 +04:00
|
|
|
if (apply->text_align != CSS_TEXT_ALIGN_INHERIT)
|
|
|
|
style->text_align = apply->text_align;
|
2003-11-05 19:25:35 +03:00
|
|
|
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
|
2003-10-18 03:47:13 +04:00
|
|
|
style->text_decoration = apply->text_decoration;
|
2004-02-01 00:18:44 +03:00
|
|
|
if (apply->text_transform != CSS_TEXT_TRANSFORM_INHERIT)
|
|
|
|
style->text_transform = apply->text_transform;
|
2003-11-05 19:25:35 +03:00
|
|
|
if (apply->visibility != CSS_VISIBILITY_INHERIT)
|
2003-10-10 22:13:36 +04:00
|
|
|
style->visibility = apply->visibility;
|
2003-04-06 01:38:06 +04:00
|
|
|
if (apply->width.width != CSS_WIDTH_INHERIT)
|
|
|
|
style->width = apply->width;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (apply->white_space != CSS_WHITE_SPACE_INHERIT)
|
|
|
|
style->white_space = apply->white_space;
|
2003-04-06 01:38:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-04-05 19:35:55 +04:00
|
|
|
unsigned int css_hash(const char *s)
|
|
|
|
{
|
|
|
|
unsigned int z = 0;
|
2003-04-06 01:38:06 +04:00
|
|
|
if (s == 0)
|
|
|
|
return 0;
|
2003-04-05 19:35:55 +04:00
|
|
|
for (; *s != 0; s++)
|
2003-07-02 18:30:53 +04:00
|
|
|
z += *s & 0x1f; /* lower 5 bits, case insensitive */
|
2003-04-06 01:38:06 +04:00
|
|
|
return (z % (HASH_SIZE - 1)) + 1;
|
2003-04-05 19:35:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 01:33:01 +04:00
|
|
|
/**
|
|
|
|
* convert a struct css_length to pixels
|
|
|
|
*/
|
|
|
|
|
|
|
|
signed long len(struct css_length * length, struct css_style * style)
|
|
|
|
{
|
|
|
|
assert(!((length->unit == CSS_UNIT_EM || length->unit == CSS_UNIT_EX) && style == 0));
|
|
|
|
switch (length->unit) {
|
|
|
|
case CSS_UNIT_EM: return length->value * len(&style->font_size.value.length, 0);
|
|
|
|
case CSS_UNIT_EX: return length->value * len(&style->font_size.value.length, 0) * 0.6;
|
|
|
|
case CSS_UNIT_PX: return length->value;
|
|
|
|
case CSS_UNIT_IN: return length->value * 90.0;
|
|
|
|
case CSS_UNIT_CM: return length->value * 35.0;
|
|
|
|
case CSS_UNIT_MM: return length->value * 3.5;
|
|
|
|
case CSS_UNIT_PT: return length->value * 90.0 / 72.0;
|
|
|
|
case CSS_UNIT_PC: return length->value * 90.0 / 6.0;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-05 19:35:55 +04:00
|
|
|
|
2003-04-04 19:19:32 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
const char data[] = "h1 { blah: foo; display: block; }"
|
|
|
|
"h1.c1 h2#id1 + h3, h4 h5.c2#id2 { size: 100mm; color: red }"
|
|
|
|
"p { background-color: #123; clear: left; color: #ff0000; display: block;"
|
|
|
|
"float: left; font-size: 150%; height: blah; line-height: 100;"
|
|
|
|
"text-align: left right; width: 90%;}";
|
|
|
|
struct content c;
|
|
|
|
css_create(&c);
|
|
|
|
css_process_data(&c, data, 24);
|
|
|
|
css_process_data(&c, data + 24, sizeof(data) - 25);
|
|
|
|
css_convert(&c, 100, 100);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|