diff options
Diffstat (limited to 'src/seleng')
-rw-r--r-- | src/seleng/Makefile.am | 18 | ||||
-rw-r--r-- | src/seleng/cr-fonts.c | 382 | ||||
-rw-r--r-- | src/seleng/cr-fonts.h | 276 | ||||
-rw-r--r-- | src/seleng/cr-sel-eng.c | 1558 | ||||
-rw-r--r-- | src/seleng/cr-sel-eng.h | 111 | ||||
-rw-r--r-- | src/seleng/cr-style.c | 2190 | ||||
-rw-r--r-- | src/seleng/cr-style.h | 284 |
7 files changed, 0 insertions, 4819 deletions
diff --git a/src/seleng/Makefile.am b/src/seleng/Makefile.am deleted file mode 100644 index 25ad853..0000000 --- a/src/seleng/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -SELENG_SRCS= cr-style.c cr-style.h cr-sel-eng.c cr-sel-eng.h cr-fonts.c cr-fonts.h -EXTRA_DIST=$(SELENG_SRCS) - -if HAVE_SELENG -lib_LTLIBRARIES=libcrseleng.la - -crselengincdir=$(includedir)/@PACKAGE@/seleng -crselenginc_HEADERS= cr-fonts.h cr-sel-eng.h cr-style.h - -#the selection engine files - -libcrseleng_la_SOURCES=$(SELENG_SRCS) -INCLUDES=-I$(top_srcdir) -I$(top_srcdir)/src/parser -I$(top_srcdir)/intl \ -@GLIB2_CFLAGS@ @LIBXML2_CFLAGS@ - -LDADD=$(top_srcdir)/src/parser/libcroco.la -endif -libcrseleng_la_LDFLAGS=-version-info @LIBCRSELENG_VERSION_INFO@ @LIBXML2_LIBS@ diff --git a/src/seleng/cr-fonts.c b/src/seleng/cr-fonts.c deleted file mode 100644 index 2a5f908..0000000 --- a/src/seleng/cr-fonts.c +++ /dev/null @@ -1,382 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */ - -/* - * This file is part of The Croco Library - * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of - * the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program 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 Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "cr-fonts.h" -#include <string.h> - - -static enum CRStatus -cr_font_family_to_string_real (CRFontFamily *a_this, - gboolean a_walk_list, - GString **a_string) -{ - guchar * name = NULL ; - enum CRStatus result = CR_OK ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - if (!*a_string) - { - *a_string = g_string_new (NULL) ; - g_return_val_if_fail (*a_string, - CR_INSTANCIATION_FAILED_ERROR) ; - } - - switch (a_this->type) - { - case FONT_FAMILY_SANS_SERIF: - name = (guchar*) "sans-serif" ; - break ; - - case FONT_FAMILY_SERIF: - name = (guchar*) "sans-serif" ; - break ; - - case FONT_FAMILY_CURSIVE: - name = (guchar*) "cursive" ; - break ; - - case FONT_FAMILY_FANTASY: - name = (guchar*) "fantasy" ; - break ; - - case FONT_FAMILY_MONOSPACE: - name = (guchar*) "monospace" ; - break ; - - case FONT_FAMILY_NON_GENERIC: - name = (guchar*) a_this->name; - break ; - - default: - name = (guchar*) NULL ; - break ; - } - - if (name) - { - if (a_this->prev) - { - g_string_append_printf (*a_string, - ", %s", name) ; - } - else - { - g_string_append (*a_string, - name) ; - } - } - - if (a_walk_list == TRUE && a_this->next) - { - result = cr_font_family_to_string_real (a_this->next, - TRUE, a_string) ; - } - - return result ; -} - -CRFontFamily * -cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name) -{ - CRFontFamily *result = NULL ; - - result = g_try_malloc (sizeof (CRFontFamily)) ; - - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - - memset (result, 0, sizeof (CRFontFamily)) ; - result->type = a_type ; - - cr_font_family_set_name (result, a_name) ; - - return result ; -} - - -guchar * -cr_font_family_to_string (CRFontFamily *a_this, - gboolean a_walk_font_family_list) -{ - enum CRStatus status = CR_OK ; - guchar *result = NULL ; - GString *stringue = NULL ; - - g_return_val_if_fail (a_this, - NULL) ; - - status = cr_font_family_to_string_real (a_this, - a_walk_font_family_list, - &stringue) ; - - if (status == CR_OK && stringue) - { - result = stringue->str ; - g_string_free (stringue, FALSE) ; - stringue = NULL ; - - } - else - { - if (stringue) - { - g_string_free (stringue, TRUE) ; - stringue = NULL ; - } - } - - return result ; -} -enum CRStatus -cr_font_family_set_name (CRFontFamily *a_this, guchar *a_name) -{ - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - /* - *only non generic font families can have a name - */ - - if (a_this->type != FONT_FAMILY_NON_GENERIC) - { - return CR_BAD_PARAM_ERROR ; - } - - if (a_this->name) - { - g_free (a_this->name) ; - a_this->name = NULL ; - } - - a_this->name = a_name ; - return CR_OK ; -} - - -CRFontFamily * -cr_font_family_append (CRFontFamily *a_this, - CRFontFamily *a_family_to_append) -{ - CRFontFamily *cur_ff = NULL ; - - g_return_val_if_fail (a_family_to_append, - NULL) ; - - if (!a_this) - return a_family_to_append ; - - for (cur_ff = a_this ; - cur_ff && cur_ff->next; - cur_ff = cur_ff->next ) ; - - cur_ff->next = a_family_to_append; - a_family_to_append->prev = cur_ff ; - - return a_this ; - - -} - -CRFontFamily * -cr_font_family_prepend (CRFontFamily *a_this, - CRFontFamily *a_family_to_prepend) -{ - g_return_val_if_fail (a_this && a_family_to_prepend, - NULL) ; - - if (!a_this) - return a_family_to_prepend ; - - a_family_to_prepend->next = a_this ; - a_this->prev = a_family_to_prepend ; - - return CR_OK ; -} - - -enum CRStatus -cr_font_family_destroy (CRFontFamily *a_this) -{ - CRFontFamily *cur_ff = NULL ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - for (cur_ff = a_this ; - cur_ff && cur_ff->next ; - cur_ff = cur_ff->next) - ; - - for (; cur_ff ; cur_ff = cur_ff->prev) - { - if (a_this->name) - { - g_free (a_this->name) ; - a_this->name = NULL ; - } - - if (cur_ff->next) - { - g_free (cur_ff->next) ; - - } - - if (cur_ff->prev == NULL) - { - g_free (a_this) ; - } - } - - return CR_OK ; -} - -/*************************************************** - *'font-size' manipulation functions definitions - ***************************************************/ - -CRFontSize * -cr_font_size_new (void) -{ - CRFontSize *result = NULL ; - - result = g_try_malloc (sizeof (CRFontSize)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRFontSize)) ; - - return result ; -} - -enum CRStatus -cr_font_size_clear (CRFontSize *a_this) -{ - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - switch (a_this->type) - { - case PREDEFINED_ABSOLUTE_FONT_SIZE: - case RELATIVE_FONT_SIZE: - case INHERITED_FONT_SIZE: - memset (a_this, 0, sizeof (CRFontSize)) ; - break ; - - case ABSOLUTE_FONT_SIZE: - if (a_this->value.absolute) - { - cr_num_destroy (a_this->value.absolute) ; - } - memset (a_this, 0, sizeof (CRFontSize)) ; - break ; - - default: - return CR_UNKNOWN_TYPE_ERROR ; - } - - return CR_OK ; -} - -enum CRStatus -cr_font_size_copy (CRFontSize *a_dst, CRFontSize *a_src) -{ - g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR) ; - - switch (a_src->type) - { - case PREDEFINED_ABSOLUTE_FONT_SIZE: - case RELATIVE_FONT_SIZE: - case INHERITED_FONT_SIZE: - cr_font_size_clear (a_dst) ; - memcpy (a_dst, a_src, sizeof (CRFontSize)) ; - break ; - - case ABSOLUTE_FONT_SIZE: - if (a_src->value.absolute) - { - cr_font_size_clear (a_dst) ; - if (!a_dst->value.absolute) - { - a_dst->value.absolute = cr_num_new () ; - } - cr_num_copy (a_dst->value.absolute, - a_src->value.absolute) ; - a_dst->type = a_src->type ; - } - break ; - - default: - return CR_UNKNOWN_TYPE_ERROR ; - } - return CR_OK ; -} - -void -cr_font_size_destroy (CRFontSize *a_font_size) -{ - g_return_if_fail (a_font_size) ; - - if (a_font_size->type == ABSOLUTE_FONT_SIZE - && a_font_size->value.absolute) - { - cr_num_destroy (a_font_size->value.absolute) ; - a_font_size->value.absolute = NULL ; - } -} - -/******************************************************* - *'font-size-adjust' manipulation function definition - *******************************************************/ - -CRFontSizeAdjust * -cr_font_size_adjust_new (void) -{ - CRFontSizeAdjust *result = NULL ; - - result = g_try_malloc (sizeof (CRFontSizeAdjust)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRFontSizeAdjust)) ; - - return result ; -} - -void -cr_font_size_adjust_destroy (CRFontSizeAdjust *a_this) -{ - g_return_if_fail (a_this) ; - - if (a_this->type == FONT_SIZE_ADJUST_NUMBER - && a_this->num) - { - cr_num_destroy (a_this->num) ; - a_this->num = NULL ; - } -} diff --git a/src/seleng/cr-fonts.h b/src/seleng/cr-fonts.h deleted file mode 100644 index 758778f..0000000 --- a/src/seleng/cr-fonts.h +++ /dev/null @@ -1,276 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */ - -/* - * This file is part of The Croco Library - * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of - * the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program 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 Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef __CR_FONTS_H__ -#define __CR_FONTS_H__ -#endif - -#include "cr-utils.h" -#include "cr-num.h" - -/** - *@file - *Various type declarations about font selection related - *properties. - */ -G_BEGIN_DECLS - - -enum CRFontFamilyType -{ - FONT_FAMILY_SANS_SERIF, - FONT_FAMILY_SERIF, - FONT_FAMILY_CURSIVE, - FONT_FAMILY_FANTASY, - FONT_FAMILY_MONOSPACE, - FONT_FAMILY_NON_GENERIC, - /**/ - NB_FONT_FAMILIE_TYPES -} ; - -typedef struct _CRFontFamily CRFontFamily ; - -struct _CRFontFamily -{ - enum CRFontFamilyType type ; - - /* - *The name of the font family, in case - *it is non generic. - *Is set only if the type is FONT_FAMILY_NON_GENERIC. - */ - guchar *name ; - - CRFontFamily *next ; - CRFontFamily *prev ; -} ; - - -/** - *The different types - *of absolute font size. - *This is used by the 'font-size' - *property defined in css2 spec - *in chapter 15.2.4 . - *These values a indexes of - *table of size so please, do not - *change their definition order unless - *you know what you are doing. - */ -enum CRPredefinedAbsoluteFontSize -{ - FONT_SIZE_XX_SMALL=0, - FONT_SIZE_X_SMALL, - FONT_SIZE_SMALL, - FONT_SIZE_MEDIUM, - FONT_SIZE_LARGE, - FONT_SIZE_X_LARGE, - FONT_SIZE_XX_LARGE, - - NB_PREDEFINED_ABSOLUTE_FONT_SIZES -} ; - -/** - *The different types - *of relative font size. - *This is used by the 'font-size' - *property defined in css2 spec - *in chapter 15.2.4 . - *These values a indexes of - *table of size so please, do not - *change their definition order unless - *you know what you are doing. - */ -enum CRRelativeFontSize -{ - FONT_SIZE_LARGER, - FONT_SIZE_SMALLER -} ; - -/** - *The type of font-size property. - *Used to define the type of #CRFontSize . - *See css2 spec chapter 15.2.4 to understand. - */ -enum CRFontSizeType -{ - /** - *If the type of #CRFontSize is - *PREDEFINED_ABSOLUTE_FONT_SIZE, - *the CRFontSize::value.predefined_absolute - *field will be defined. - */ - PREDEFINED_ABSOLUTE_FONT_SIZE, - - /** - *If the type of #CRFontSize is - *ABSOLUTE_FONT_SIZE, - *the CRFontSize::value.absolute - *field will be defined. - */ - ABSOLUTE_FONT_SIZE, - - /** - *If the type of #CRFontSize is - *RELATIVE_FONT_SIZE, - *the CRFontSize::value.relative - *field will be defined. - */ - RELATIVE_FONT_SIZE, - - /** - *If the type of #CRFontSize is - *INHERITED_FONT_SIZE, - *the None of the field of the CRFontSize::value enum - *will be defined. - */ - INHERITED_FONT_SIZE -} ; - -typedef struct _CRFontSize CRFontSize ; -struct _CRFontSize -{ - enum CRFontSizeType type ; - union - { - enum CRPredefinedAbsoluteFontSize predefined ; - enum CRRelativeFontSize relative ; - CRNum * absolute ; - } value; -} ; - -enum CRFontSizeAdjustType -{ - FONT_SIZE_ADJUST_NONE = 0, - FONT_SIZE_ADJUST_NUMBER, - FONT_SIZE_ADJUST_INHERIT -} ; -typedef struct _CRFontSizeAdjust CRFontSizeAdjust ; -struct _CRFontSizeAdjust -{ - enum CRFontSizeAdjustType type ; - CRNum *num ; -} ; - -enum CRFontStyle -{ - FONT_STYLE_NORMAL=0, - FONT_STYLE_ITALIC, - FONT_STYLE_OBLIQUE, - FONT_STYLE_INHERIT -} ; - -enum CRFontVariant -{ - FONT_VARIANT_NORMAL=0, - FONT_VARIANT_SMALL_CAPS, - FONT_VARIANT_INHERIT -} ; - -enum CRFontWeight -{ - FONT_WEIGHT_NORMAL=0, - FONT_WEIGHT_BOLD, - FONT_WEIGHT_BOLDER, - FONT_WEIGHT_LIGHTER, - FONT_WEIGHT_100, - FONT_WEIGHT_200, - FONT_WEIGHT_300, - FONT_WEIGHT_400, - FONT_WEIGHT_500, - FONT_WEIGHT_600, - FONT_WEIGHT_700, - FONT_WEIGHT_800, - FONT_WEIGHT_900, - FONT_WEIGHT_INHERIT, -} ; - -enum CRFontStretch -{ - FONT_STRETCH_NORMAL=0, - FONT_STRETCH_WIDER, - FONT_STRETCH_NARROWER, - FONT_STRETCH_ULTRA_CONDENSED, - FONT_STRETCH_EXTRA_CONDENSED, - FONT_STRETCH_CONDENSED, - FONT_STRETCH_SEMI_CONDENSED, - FONT_STRETCH_SEMI_EXPANDED, - FONT_STRETCH_EXPANDED, - FONT_STRETCH_EXTRA_EXPANDED, - FONT_STRETCH_ULTRA_EXPANDED, - FONT_STRETCH_INHERIT -} ; - -/************************************** - *'font-family' manipulation functions - ***************************************/ -CRFontFamily * -cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name) ; - -CRFontFamily * -cr_font_family_append (CRFontFamily *a_this, - CRFontFamily *a_family_to_append) ; - -guchar * -cr_font_family_to_string (CRFontFamily *a_this, - gboolean a_walk_font_family_list) ; - -CRFontFamily * -cr_font_family_prepend (CRFontFamily *a_this, - CRFontFamily *a_family_to_prepend); - -enum CRStatus -cr_font_family_destroy (CRFontFamily *a_this) ; - -enum CRStatus -cr_font_family_set_name (CRFontFamily *a_this, guchar *a_name) ; - - -/************************************ - *'font-size' manipulation functions - ***********************************/ - -CRFontSize * -cr_font_size_new (void) ; - -enum CRStatus -cr_font_size_clear (CRFontSize *a_this) ; - -enum CRStatus -cr_font_size_copy (CRFontSize *a_dst, CRFontSize *a_src) ; - - -void -cr_font_size_destroy (CRFontSize *a_font_size) ; - -/******************************************************* - *'font-size-adjust' manipulation function declarations - *******************************************************/ - -CRFontSizeAdjust * -cr_font_size_adjust_new (void) ; - -void -cr_font_size_adjust_destroy (CRFontSizeAdjust *a_this) ; - -G_END_DECLS diff --git a/src/seleng/cr-sel-eng.c b/src/seleng/cr-sel-eng.c deleted file mode 100644 index edec6b3..0000000 --- a/src/seleng/cr-sel-eng.c +++ /dev/null @@ -1,1558 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */ - -/* - * This file is part of The Croco Library - * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji at seketeli.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program 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 Lesser - * General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#include <string.h> -#include "cr-sel-eng.h" - -/** - *@file: - *The definition of the #CRSelEng class. - *The #CRSelEng is actually the "Selection Engine" - *class. This is highly experimental for at the moment and - *its api is very likely to change in a near future. - */ - -#define PRIVATE(a_this) (a_this)->priv - -struct CRPseudoClassSelHandlerEntry -{ - guchar *name ; - enum CRPseudoType type ; - CRPseudoClassSelectorHandler handler ; -} ; - -struct _CRSelEngPriv -{ - /*not used yet*/ - gboolean case_sensitive ; - - CRStyleSheet *sheet ; - /** - *where to store the next statement - *to be visited so that we can remember - *it from one method call to another. - */ - CRStatement *cur_stmt ; - GList *pcs_handlers ; - gint pcs_handlers_size ; -}; - -static gboolean class_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; - -static gboolean id_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; - -static gboolean attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; - -static enum CRStatus sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, gboolean *a_result, - gboolean a_recurse) ; - -static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, - CRStyleSheet *a_stylesheet, - xmlNode *a_node, - CRStatement **a_rulesets, - gulong *a_len) ; - -static enum CRStatus put_css_properties_in_hashtable (GHashTable **a_props_hashtable, - CRStatement *a_ruleset) ; - -static void set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, - gpointer a_style) ; - -static gboolean pseudo_class_add_sel_matches_node (CRSelEng * a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; - -static gboolean first_child_pseudo_class_handler (CRSelEng *a_this, - CRAdditionalSel *a_sel, - xmlNode *a_node) ; - -static xmlNode * get_next_element_node (xmlNode *a_node) ; - -static xmlNode * get_next_child_element_node (xmlNode *a_node) ; - -static xmlNode * get_prev_element_node (xmlNode *a_node) ; - -static xmlNode * get_next_parent_element_node (xmlNode *a_node) ; - -static gboolean -first_child_pseudo_class_handler (CRSelEng *a_this, - CRAdditionalSel *a_sel, - xmlNode *a_node) -{ - xmlNode *node = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_sel && a_sel->content.pseudo - && a_sel->content.pseudo - && a_sel->content.pseudo->name - && a_node, - CR_BAD_PARAM_ERROR) ; - - if (strcmp (a_sel->content.pseudo->name->str, - "first-child") - || !a_sel->content.pseudo->type == IDENT_PSEUDO) - { - cr_utils_trace_info - ("This handler is for :first-child only") ; - return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR ; - } - if (!a_node->parent) - return FALSE ; - node = get_next_child_element_node (a_node->parent) ; - if (node == a_node) - return TRUE ; - return FALSE ; -} - -static gboolean -pseudo_class_add_sel_matches_node (CRSelEng * a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) -{ - enum CRStatus status = CR_OK ; - CRPseudoClassSelectorHandler handler = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_add_sel - && a_add_sel->content.pseudo - && a_add_sel->content.pseudo->name - && a_add_sel->content.pseudo->name->str - && a_node, - CR_BAD_PARAM_ERROR) ; - - status = cr_sel_eng_get_pseudo_class_selector_handler - (a_this, a_add_sel->content.pseudo->name->str, - a_add_sel->content.pseudo->type, - &handler) ; - if (status != CR_OK || !handler) - return FALSE ; - - return handler (a_this, a_add_sel, a_node) ; -} - -/** - *@param a_add_sel the class additional selector to consider. - *@param a_node the xml node to consider. - *@return TRUE if the class additional selector matches - *the xml node given in argument, FALSE otherwise. - */ -static gboolean -class_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) -{ - gboolean result = FALSE ; - xmlChar *klass = NULL, *cur = NULL ; - - g_return_val_if_fail (a_add_sel - && a_add_sel->type == CLASS_ADD_SELECTOR - && a_add_sel->content.class_name - && a_add_sel->content.class_name->str - && a_node, FALSE) ; - - if (xmlHasProp (a_node, "class")) - { - klass = xmlGetProp (a_node, "class") ; - for (cur = klass ; *cur ; cur++) - { - while (cr_utils_is_white_space (*cur) == TRUE && *cur) - cur ++ ; - if (!*cur) - break ; - if (!strncmp (cur, a_add_sel->content.class_name->str, - a_add_sel->content.class_name->len)) - { - cur += a_add_sel->content.class_name->len; - if (!*cur || cr_utils_is_white_space (*cur) == TRUE) - result = TRUE ; - } - } - } - - if (klass) - { - xmlFree (klass) ; - klass = NULL ; - } - return result ; - -} - -/** - *@return TRUE if the additional attribute selector matches - *the current xml node given in argument, FALSE otherwise. - *@param a_add_sel the additional attribute selector to consider. - *@param a_node the xml node to consider. - */ -static gboolean -id_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) -{ - gboolean result = FALSE ; - xmlChar *id = NULL ; - - g_return_val_if_fail (a_add_sel - && a_add_sel->type == ID_ADD_SELECTOR - && a_add_sel->content.id_name - && a_add_sel->content.id_name->str - && a_node, FALSE) ; - g_return_val_if_fail (a_add_sel - && a_add_sel->type == ID_ADD_SELECTOR - && a_node, FALSE) ; - - if (xmlHasProp (a_node, "id")) - { - id = xmlGetProp (a_node, "id") ; - if (!strncmp (id, a_add_sel->content.id_name->str, - a_add_sel->content.id_name->len)) - { - result = TRUE ; - } - } - - if (id) - { - xmlFree (id) ; - id = NULL ; - } - return result ; -} - -/** - *Returns TRUE if the instance of #CRAdditional selector matches - *the node given in parameter, FALSE otherwise. - *@param a_add_sel the additional selector to evaluate. - *@param a_node the xml node against whitch the selector is to - *be evaluated - *return TRUE if the additional selector matches the current xml node - *FALSE otherwise. - */ -static gboolean -attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) -{ - CRAttrSel *cur_sel = NULL ; - - g_return_val_if_fail (a_add_sel - && a_add_sel->type == ATTRIBUTE_ADD_SELECTOR - && a_node, FALSE) ; - - for (cur_sel = a_add_sel->content.attr_sel ; - cur_sel ; cur_sel = cur_sel->next) - { - switch (cur_sel->match_way) - { - case SET: - if (!cur_sel->name || !cur_sel->name->str) - return FALSE ; - - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - break ; - - case EQUALS: - { - xmlChar *value = NULL ; - - if (!cur_sel->name || !cur_sel->name->str - || !cur_sel->value || !cur_sel->value->str) - return FALSE ; - - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - - value = xmlGetProp (a_node, cur_sel->name->str) ; - - if (value && strncmp (value, cur_sel->value->str, - cur_sel->value->len)) - { - xmlFree (value) ; - return FALSE ; - } - xmlFree (value); - } - break ; - - case INCLUDES: - { - xmlChar *value = NULL, *ptr1 = NULL, *ptr2 = NULL, - *cur = NULL; - gboolean found = FALSE ; - - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - value = xmlGetProp (a_node, cur_sel->name->str) ; - - if (!value) - return FALSE; - - /* - *here, make sure value is a space - *separated list of "words", where one - *value is exactly cur_sel->value->str - */ - for (cur = value ; *cur ; cur++) - { - /* - *set ptr1 to the first non white space - *char addr. - */ - while (cr_utils_is_white_space - (*cur) == TRUE && *cur) - cur ++ ; - if (!*cur) - break ; - ptr1 = cur ; - - /* - *set ptr2 to the end the word. - */ - while (cr_utils_is_white_space - (*cur) == FALSE && *cur) - cur++ ; - if (!*cur) - break ; - cur-- ; - ptr2 = cur ; - - if (!strncmp (ptr1, cur_sel->value->str, - ptr2 - ptr1 + 1)) - { - found = TRUE ; - break ; - } - ptr1 = ptr2 = NULL ; - } - - if (found == FALSE) - { - xmlFree (value) ; - return FALSE ; - } - xmlFree (value) ; - } - break ; - - case DASHMATCH: - { - xmlChar *value = NULL, *ptr1 = NULL, *ptr2 = NULL, - *cur = NULL; - gboolean found = FALSE ; - - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - value = xmlGetProp (a_node, cur_sel->name->str) ; - - /* - *here, make sure value is an hyphen - *separated list of "words", each of which - *starting with "cur_sel->value->str" - */ - for (cur = value ; *cur ; cur++) - { - if (*cur == '-') - cur ++ ; - ptr1 = cur ; - - while (*cur != '-' && *cur) - cur ++ ; - if (!*cur) - break ; - cur-- ; - ptr2 = cur ; - - if (g_strstr_len (ptr1, ptr2 - ptr1 + 1, - cur_sel->value->str) - == (gchar*)ptr1) - { - found = TRUE ; - break ; - } - } - - if (found == FALSE) - { - xmlFree (value) ; - return FALSE ; - } - xmlFree (value) ; - } - break ; - default: - return FALSE ; - } - } - - return TRUE ; -} - -/** - *Evaluates if a given additional selector matches an xml node. - *@param a_add_sel the additional selector to consider. - *@param a_node the xml node to consider. - *@return TRUE is a_add_sel matches a_node, FALSE otherwise. - */ -static gboolean -additional_selector_matches_node (CRSelEng *a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) -{ - if (!a_add_sel) - { - return FALSE ; - } - - if (a_add_sel->type == NO_ADD_SELECTOR) - { - return FALSE ; - } - - if (a_add_sel->type == CLASS_ADD_SELECTOR - && a_add_sel->content.class_name - && a_add_sel->content.class_name->str) - { - if (class_add_sel_matches_node - (a_add_sel, a_node) == FALSE) - { - return FALSE ; - } - return TRUE ; - } - else if (a_add_sel->type == ID_ADD_SELECTOR - && a_add_sel->content.id_name - && a_add_sel->content.id_name->str) - { - if (id_add_sel_matches_node - (a_add_sel, a_node) == FALSE) - { - return FALSE ; - } - return TRUE ; - } - else if (a_add_sel->type == ATTRIBUTE_ADD_SELECTOR - && a_add_sel->content.attr_sel) - { - /* - *here, call a function that does the match - *against an attribute additionnal selector - *and an xml node. - */ - if (attr_add_sel_matches_node - (a_add_sel, a_node) - == FALSE) - { - return FALSE ; - } - return TRUE ; - } else if (a_add_sel->type == PSEUDO_CLASS_ADD_SELECTOR - && a_add_sel->content.pseudo) - { - if (pseudo_class_add_sel_matches_node - (a_this, a_add_sel, a_node) == TRUE) - { - return TRUE ; - } - return FALSE ; - } - return FALSE ; -} - -static xmlNode * -get_next_element_node (xmlNode *a_node) -{ - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->next ; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) - { - cur_node = cur_node->next ; - } - return cur_node ; -} - -static xmlNode * -get_next_child_element_node (xmlNode *a_node) -{ - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->children ; - if (!cur_node) - return cur_node ; - if (a_node->children->type == XML_ELEMENT_NODE) - return a_node->children ; - return get_next_element_node (a_node->children) ; -} - -static xmlNode * -get_prev_element_node (xmlNode *a_node) -{ - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->prev ; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) - { - cur_node = cur_node->prev ; - } - return cur_node ; -} - -static xmlNode * -get_next_parent_element_node (xmlNode *a_node) -{ - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->parent ; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) - { - cur_node = cur_node->parent ; - } - return cur_node ; -} - -/** - *Evaluate a selector (a simple selectors list) and says - *if it matches the xml node given in parameter. - *The algorithm used here is the following: - *Walk the combinator separated list of simple selectors backward, starting - *from the end of the list. For each simple selector, looks if - *if matches the current node. - * - *@param a_this the selection engine. - *@param a_sel the simple selection list. - *@param a_node the xml node. - *@param a_result out parameter. Set to true if the - *selector matches the xml node, FALSE otherwise. - *@param a_recurse if set to TRUE, the function will walk to - *the next simple selector (after the evaluation of the current one) - *and recursively evaluate it. Must be usually set to TRUE unless you - *know what you are doing. - */ -static enum CRStatus -sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, gboolean *a_result, - gboolean a_recurse) -{ - CRSimpleSel *cur_sel = NULL ; - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_this && a_node - && a_result, - CR_BAD_PARAM_ERROR) ; - - *a_result = FALSE ; - - if (a_node->type != XML_ELEMENT_NODE) - return CR_OK ; - - - if (a_recurse == TRUE) - { - /*go and get the last simple selector of the list*/ - for (cur_sel = a_sel ; - cur_sel && cur_sel->next ; - cur_sel = cur_sel->next) ; - } - else - { - cur_sel = a_sel ; - } - - for (cur_node = a_node ; cur_sel ; cur_sel = cur_sel->prev) - { - if (cur_sel->type_mask & UNIVERSAL_SELECTOR) - { - goto walk_a_step_in_expr ; - } - else if (cur_sel->type_mask & TYPE_SELECTOR) - { - if (cur_sel && cur_sel->name && cur_sel->name->str) - { - if (!strcmp (cur_sel->name->str, - cur_node->name)) - { - /* - *this simple selector - *matches the current xml node - *Let's see if the preceding - *simple selectors also match - *their xml node counterpart. - */ - if (cur_sel->add_sel) { - if (additional_selector_matches_node - (a_this, cur_sel->add_sel, cur_node) == TRUE) - { - goto walk_a_step_in_expr ; - } else { - goto done ; - } - } else { - goto walk_a_step_in_expr ; - } - } - goto done ; - } - else - { - goto done ; - } - } - - if (!cur_sel->add_sel) - { - goto done ; - } - if (additional_selector_matches_node - (a_this, cur_sel->add_sel, cur_node) == TRUE) - { - goto walk_a_step_in_expr ; - } else { - goto done ; - } - - walk_a_step_in_expr: - if (a_recurse == FALSE) - { - *a_result = TRUE ; - goto done ; - } - - /* - *here, depending on the combinator of cur_sel - *choose the axis of the xml tree traversal - *and walk one step in the xml tree. - */ - if (!cur_sel->prev) - break ; - - switch (cur_sel->combinator) - { - case NO_COMBINATOR: - break ; - - case COMB_WS:/*descendant selector*/ - { - xmlNode *n = NULL ; - enum CRStatus status = CR_OK ; - gboolean matches= FALSE ; - - /* - *walk the xml tree upward looking for a parent - *node that matches the preceding selector. - */ - for (n = cur_node->parent ; n ; n = n->parent) - { - status = - sel_matches_node_real - (a_this, cur_sel->prev, - n, &matches, FALSE) ; - if (status != CR_OK) - goto done ; - if (matches == TRUE) - { - cur_node = n ; - break ; - } - } - - if (!n) - { - /* - *didn't find any ancestor that matches - *the previous simple selector. - */ - goto done ; - } - /* - *in this case, the preceding simple sel - *will have been interpreted twice, which - *is a cpu and mem waste ... I need to find - *another way to do this. Anyway, this is - *my first attempt to write this function and - *I am a bit clueless. - */ - break ; - } - - case COMB_PLUS: - cur_node = get_prev_element_node (cur_node); - if (!cur_node) - goto done ; - break ; - - case COMB_GT: - cur_node = get_next_parent_element_node - (cur_node) ; - if (!cur_node) - goto done ; - break ; - - default: - goto done ; - } - continue ; - } - - /* - *if we reached this point, it means the selector matches - *the xml node. - */ - *a_result = TRUE ; - - done: - return CR_OK ; -} - - -/** - *Returns array of the ruleset statements that matches the - *given xml node. - *The engine keeps in memory the last statement he - *visited during the match. So, the next call - *to this function will eventually return a rulesets list starting - *from the last ruleset statement visited during the previous call. - *The enable users to get matching rulesets in an incremental way. - *Note that for each statement returned, - *the engine calculates the specificity of the selector - *that matched the xml node and stores it in the "specifity" field - *of the statement structure. - * - *@param a_sel_eng the current selection engine - *@param a_node the xml node for which the request - *is being made. - *@param a_sel_list the list of selectors to perform the search in. - *@param a_rulesets in/out parameter. A pointer to the - *returned array of rulesets statements that match the xml node - *given in parameter. The caller allocates the array before calling this - *function. - *@param a_len in/out parameter the length (in sizeof (#CRStatement*)) - *of the returned array. - *(the length of a_rulesets, more precisely). - *The caller must set it to the length of a_ruleset prior to calling this - *function. In return, the function sets it to the length - *(in sizeof (#CRStatement)) of the actually returned CRStatement array. - *@return CR_OUTPUT_TOO_SHORT_ERROR if found more rulesets than the size - *of the a_rulesets array. In this case, the first *a_len rulesets found - *are put in a_rulesets, and a further call will return the following - *ruleset(s) following the same principle. - *@return CR_OK if all the rulesets found have been returned. In this - *case, *a_len is set to the actual number of ruleset found. - *@return CR_BAD_PARAM_ERROR in case any of the given parameter are - *bad (e.g null pointer). - *@return CR_ERROR if any other error occured. - */ -static enum CRStatus -cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, - CRStyleSheet *a_stylesheet, - xmlNode *a_node, - CRStatement **a_rulesets, - gulong *a_len) -{ - CRStatement *cur_stmt = NULL ; - CRSelector *sel_list = NULL, *cur_sel = NULL ; - gboolean matches = FALSE ; - enum CRStatus status = CR_OK ; - gulong i = 0; - - g_return_val_if_fail (a_this - && a_stylesheet - && a_stylesheet->statements - && a_node - && a_rulesets, - CR_BAD_PARAM_ERROR) ; - - /* - *if this stylesheet is "new one" - *let's remember it for subsequent calls. - */ - if (PRIVATE (a_this)->sheet != a_stylesheet) - { - PRIVATE (a_this)->sheet = a_stylesheet ; - PRIVATE (a_this)->cur_stmt = a_stylesheet->statements ; - } - - /* - *walk through the list of statements and, - *get the selectors list inside the statements that - *contain some, and try to match our xml node in these - *selectors lists. - */ - for (cur_stmt = PRIVATE (a_this)->cur_stmt, i = 0 ; - (PRIVATE (a_this)->cur_stmt = cur_stmt); - cur_stmt = cur_stmt->next) - { - /* - *initialyze the selector list in which we will - *really perform the search. - */ - sel_list = NULL ; - - /* - *get the the damn selector list in - *which we have to look - */ - switch (cur_stmt->type) - { - case RULESET_STMT: - if (cur_stmt->kind.ruleset - && cur_stmt->kind.ruleset->sel_list) - { - sel_list = cur_stmt->kind.ruleset->sel_list ; - } - break ; - - case AT_MEDIA_RULE_STMT: - if (cur_stmt->kind.media_rule - && cur_stmt->kind.media_rule->rulesets - && cur_stmt->kind.media_rule->rulesets-> - kind.ruleset - &&cur_stmt->kind.media_rule->rulesets-> - kind.ruleset->sel_list) - { - sel_list = - cur_stmt->kind.media_rule-> - rulesets->kind.ruleset->sel_list ; - } - break ; - - case AT_IMPORT_RULE_STMT: - /* - *some recursivity may be needed here. - *I don't like this :( - */ - break ; - default: - break ; - } - - if (!sel_list) - continue ; - - /* - *now, we have a comma separated selector list to look in. - *let's walk it and try to match the xml_node - *on each item of the list. - */ - for (cur_sel = sel_list ; cur_sel ; cur_sel = cur_sel->next) - { - if (!cur_sel->simple_sel) - continue ; - - status = cr_sel_eng_matches_node - (a_this, cur_sel->simple_sel, - a_node, &matches) ; - - if (status == CR_OK && matches == TRUE) - { - /* - *bingo!!! we found one ruleset that - *matches that fucking node. - *lets put it in the out array. - */ - - if (i < *a_len) - { - a_rulesets[i] = cur_stmt ; - i++ ; - - /* - *For the cascade computing algorithm - *(which is gonna take place later) - *we must compute the specificity - *(css2 spec chap 6.4.1) of the selector - *that matched the current xml node - *and store it in the css2 statement - *(statement == ruleset here). - */ - status = - cr_simple_sel_compute_specificity - (cur_sel->simple_sel) ; - - g_return_val_if_fail (status == CR_OK, - CR_ERROR) ; - cur_stmt->specificity = - cur_sel->simple_sel->specificity; - } - else - - { - *a_len = i ; - return CR_OUTPUT_TOO_SHORT_ERROR ; - } - } - } - } - - /* - *if we reached this point, it means - *we reached the end of stylesheet. - *no need to store any info about the stylesheet - *anymore. - */ - g_return_val_if_fail (!PRIVATE (a_this)->cur_stmt, CR_ERROR) ; - PRIVATE (a_this)->sheet = NULL ; - *a_len = i ; - return CR_OK ; -} - -/** - *Walks through the property/value pairs of a ruleset - *statement and put the properties found into a hashtable. - *Each key of the hashtable is a css property. The - *associated value is a pointer to the current #CRDeclaration. - *This function is where the cascading property sorting is done. - * - *@param a_props_hashtable in/out parameter. The hashtable into - *which the the property/Declaration pairs will be added. - *Note that each hashtable key (a statement property) is a null terminated - *instance of guchar *. - *Each value associated to a key is an instance of #CRDeclaration. - *The declaration is actually the css declaration (rule) - *that contains the property (the key). - *@param a_ruleset the ruleset from wich the properties are gathered. - *@return CR_OK upon successfull completion, an error code otherwise. - */ -static enum CRStatus -put_css_properties_in_hashtable (GHashTable **a_props_hashtable, - CRStatement *a_stmt) -{ - GHashTable *props_hash = NULL ; - CRDeclaration *cur_decl = NULL ; - - g_return_val_if_fail (a_props_hashtable && a_stmt - && a_stmt->type == RULESET_STMT - && a_stmt->kind.ruleset, - CR_BAD_PARAM_ERROR) ; - - if (!*a_props_hashtable) - { - *a_props_hashtable = g_hash_table_new (g_str_hash, - g_str_equal) ; - } - props_hash = *a_props_hashtable ; - - for (cur_decl = a_stmt->kind.ruleset->decl_list ; - cur_decl ; cur_decl = cur_decl->next) - { - CRDeclaration *decl = NULL ; - - if (!cur_decl->property || !cur_decl->property->str) - continue ; - - /* - *First, test if the property is not - *already present in our properties hashtable. - *If yes, apply the cascading rules to - *compute the precedence. If not, insert - *the property into the hashtable. - */ - decl = g_hash_table_lookup - (props_hash, cur_decl->property->str) ; - - if (!decl) - { - g_hash_table_replace - (props_hash, - cur_decl->property->str, - cur_decl) ; - continue ; - } - - /* - *A property with the same name already exists. - *We must apply here - *some cascading rules - *to compute the precedence. - */ - - /* - *first, look at the origin. - *6.4.1 says: - *"for normal declarations, - *author style sheets override user - *style sheets which override - *the default style sheet." - */ - if (decl->parent_statement - && decl->parent_statement->parent_sheet - && (decl->parent_statement->parent_sheet->origin - < - a_stmt->parent_sheet->origin)) - { - g_hash_table_insert - (props_hash, - cur_decl->property->str, - cur_decl) ; - continue ; - } - else if (decl->parent_statement - && decl->parent_statement->parent_sheet - && (decl->parent_statement-> - parent_sheet->origin - > - a_stmt->parent_sheet->origin)) - { - /*TODO: support !important rule.*/ - continue ; - } - - /* - *A property with the same - *name and the same origin already exist. - *shit. This is lasting longer than expected ... - *Luckily, the spec says in 6.4.1: - *"more specific selectors will override - *more general ones" - *and - *"if two rules have the same weight, - *origin and specificity, - *the latter specified wins" - */ - if (a_stmt->specificity - >= decl->parent_statement->specificity) - { - g_hash_table_insert - (props_hash, - cur_decl->property->str, - cur_decl) ; - } - } - - - return CR_OK ; -} - -static void -set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, - gpointer a_style) -{ - CRDeclaration *decl = a_decl ; - CRStyle *style = a_style ; - - g_return_if_fail (a_decl && a_prop && a_style) ; - - cr_style_set_style_from_decl (style, decl) ; -} - -/**************************************** - *PUBLIC METHODS - ****************************************/ - -/** - *Creates a new instance of #CRSelEng. - *@return the newly built instance of #CRSelEng of - *NULL if an error occurs. - */ -CRSelEng * -cr_sel_eng_new (void) -{ - CRSelEng *result = NULL; - - result = g_try_malloc (sizeof (CRSelEng)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRSelEng)) ; - - PRIVATE (result) = g_try_malloc (sizeof (CRSelEngPriv)) ; - if (!PRIVATE (result)) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - memset (PRIVATE (result), 0, sizeof (CRSelEngPriv)) ; - cr_sel_eng_register_pseudo_class_sel_handler - (result, (guchar*)"first-child", - IDENT_PSEUDO, - (CRPseudoClassSelectorHandler) - first_child_pseudo_class_handler) ; - - return result ; -} - -/** - *Adds a new handler entry in the handlers entry table. - *@param a_this the current instance of #CRSelEng - *@param a_pseudo_class_sel_name the name of the pseudo class selector. - *@param a_pseudo_class_type the type of the pseudo class selector. - *@param a_handler the actual handler or callback to be called during - *the selector evaluation process. - *@return CR_OK, upon successful completion, an error code otherwise. - */ -enum CRStatus -cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng *a_this, - guchar *a_name, - enum CRPseudoType a_type, - CRPseudoClassSelectorHandler a_handler) -{ - struct CRPseudoClassSelHandlerEntry *handler_entry = NULL ; - GList *list = NULL ; - - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_handler - && a_name, - CR_BAD_PARAM_ERROR) ; - - handler_entry = g_try_malloc - (sizeof (struct CRPseudoClassSelHandlerEntry)) ; - if (!handler_entry) - { - return CR_OUT_OF_MEMORY_ERROR ; - } - memset (handler_entry, 0, - sizeof (struct CRPseudoClassSelHandlerEntry)) ; - handler_entry->name = g_strdup (a_name) ; - handler_entry->type= a_type ; - handler_entry->handler = a_handler ; - list = g_list_append - (PRIVATE (a_this)->pcs_handlers, handler_entry) ; - if (!list) - { - return CR_OUT_OF_MEMORY_ERROR ; - } - PRIVATE (a_this)->pcs_handlers = list ; - return CR_OK ; -} - -enum CRStatus -cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng *a_this, - guchar *a_name, - enum CRPseudoType a_type) -{ - GList *elem = NULL, *deleted_elem = NULL ; - gboolean found = FALSE ; - struct CRPseudoClassSelHandlerEntry *entry = NULL ; - - g_return_val_if_fail (a_this - && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - for (elem = PRIVATE (a_this)->pcs_handlers ; - elem ; - elem = g_list_next (elem)) - { - entry = elem->data ; - if (!strcmp (entry->name, a_name) - && entry->type == a_type) - { - found = TRUE; - break ; - } - } - if (found == FALSE) - return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR ; - PRIVATE (a_this)->pcs_handlers = g_list_delete_link - (PRIVATE (a_this)->pcs_handlers, - elem) ; - entry = elem->data ; - if (entry->name) - g_free (entry->name) ; - g_free (elem) ; - g_list_free (deleted_elem) ; - - return CR_OK ; -} - -/** - *Unregisters all the pseudo class sel handlers - *and frees all the associated allocated datastructures. - *@param a_this the current instance of #CRSelEng . - *@return CR_OK upon succesful completion, an error code - *otherwise. - */ -enum CRStatus -cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng *a_this) -{ - GList *elem = NULL ; - struct CRPseudoClassSelHandlerEntry *entry = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - if (!PRIVATE (a_this)->pcs_handlers) - return CR_OK ; - for (elem = PRIVATE (a_this)->pcs_handlers ; - elem; - elem = g_list_next (elem)) - { - entry = elem->data ; - if (!entry) - continue ; - if (entry->name) - { - g_free (entry->name) ; - entry->name = NULL ; - } - g_free (entry) ; - elem->data = NULL ; - } - g_list_free (PRIVATE (a_this)->pcs_handlers) ; - PRIVATE (a_this)->pcs_handlers = NULL ; - return CR_OK ; -} - -enum CRStatus -cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, - guchar *a_name, - enum CRPseudoType a_type, - CRPseudoClassSelectorHandler *a_handler) -{ - GList *elem = NULL ; - struct CRPseudoClassSelHandlerEntry *entry = NULL ; - gboolean found = FALSE ; - - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_name, - CR_BAD_PARAM_ERROR) ; - - for (elem = PRIVATE (a_this)->pcs_handlers ; - elem ; - elem = g_list_next (elem)) - { - entry = elem->data ; - if (!strcmp (a_name, entry->name) - && entry->type == a_type) - { - found = TRUE ; - break ; - } - } - - if (found == FALSE) - return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR ; - *a_handler = entry->handler ; - return CR_OK ; -} - -/** - *Evaluates a chained list of simple selectors (known as a css2 selector). - *Says wheter if this selector matches the xml node given in parameter or - *not. - *@param a_this the selection engine. - *@param a_sel the simple selector against which the xml node - *is going to be matched. - *@param a_node the node against which the selector is going to be matched. - *@param a_result out parameter. The result of the match. Is set to - *TRUE if the selector matches the node, FALSE otherwise. This value - *is considered if and only if this functions returns CR_OK. - *@return the CR_OK if the selection ran correctly, an error code otherwise. - */ -enum CRStatus -cr_sel_eng_matches_node (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, gboolean *a_result) -{ - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_this && a_node - && a_result, - CR_BAD_PARAM_ERROR) ; - - if (a_node->type != XML_ELEMENT_NODE) - { - *a_result = FALSE ; - return CR_OK ; - } - - return sel_matches_node_real (a_this, a_sel, a_node, - a_result, TRUE) ; -} - -/** - *Returns an array of pointers to selectors that matches - *the xml node given in parameter. - * - *@param a_this the current instance of the selection engine. - *@param a_sheet the stylesheet that holds the selectors. - *@param a_node the xml node to consider during the walk thru - *the stylesheet. - *@param a_rulesets out parameter. A pointer to an array of - *rulesets statement pointers. *a_rulesets is allocated by - *this function and must be freed by the caller. However, the caller - *must not alter the rulesets statements pointer because they - *point to statements that are still in the css stylesheet. - *@param a_len the length of *a_ruleset. - *@return CR_OK upon sucessfull completion, an error code otherwise. - */ -enum CRStatus -cr_sel_eng_get_matched_rulesets (CRSelEng *a_this, - CRStyleSheet *a_sheet, - xmlNode *a_node, - CRStatement ***a_rulesets, - gulong *a_len) -{ - CRStatement ** stmts_tab = NULL ; - enum CRStatus status = CR_OK ; - gulong tab_size = 0, tab_len = 0, index = 0 ; - gushort stmts_chunck_size = 8 ; - - g_return_val_if_fail (a_this - && a_sheet - && a_node - && a_rulesets && *a_rulesets == NULL - && a_len, - CR_BAD_PARAM_ERROR) ; - - stmts_tab = g_try_malloc (stmts_chunck_size * - sizeof (CRStatement *)) ; - - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; - } - memset (stmts_tab, 0, stmts_chunck_size * sizeof (CRStatement*)) ; - - tab_size = stmts_chunck_size ; - tab_len = tab_size ; - - while ((status = cr_sel_eng_get_matched_rulesets_real - (a_this, a_sheet, a_node, stmts_tab + index, &tab_len)) - == CR_OUTPUT_TOO_SHORT_ERROR) - { - stmts_tab = g_try_realloc (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; - } - tab_size += stmts_chunck_size ; - index += tab_len ; - tab_len = tab_size - index ; - } - - - tab_len = tab_size - stmts_chunck_size +tab_len ; - *a_rulesets = stmts_tab ; - *a_len = tab_len ; - - return CR_OK ; - - error: - - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab = NULL ; - - } - - *a_len = 0 ; - return status ; -} - -enum CRStatus -cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - GHashTable **a_props_hashtable) -{ - CRStatement ** stmts_tab = NULL ; - enum CRStatus status = CR_OK ; - gulong tab_size = 0, tab_len = 0, index = 0, i = 0 ; - enum CRStyleOrigin origin = 0 ; - gushort stmts_chunck_size = 8 ; - CRStyleSheet *sheet = NULL ; - - g_return_val_if_fail (a_this - && a_cascade - && a_node - && a_props_hashtable, - CR_BAD_PARAM_ERROR) ; - - stmts_tab = g_try_malloc (stmts_chunck_size * - sizeof (CRStatement *)) ; - - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; - } - memset (stmts_tab, 0, stmts_chunck_size * sizeof (CRStatement*)) ; - tab_size = stmts_chunck_size ; - tab_len = tab_size ; - - for (origin = ORIGIN_UA ; origin < NB_ORIGINS ; origin++) - { - sheet = cr_cascade_get_sheet (a_cascade, origin) ; - if (!sheet) - continue ; - - while ((status = cr_sel_eng_get_matched_rulesets_real - (a_this, sheet, a_node, stmts_tab + index, &tab_len)) - == CR_OUTPUT_TOO_SHORT_ERROR) - { - stmts_tab = g_try_realloc - (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; - } - tab_size += stmts_chunck_size ; - index += tab_len ; - tab_len = tab_size - index ; - } - if (status != CR_OK) - { - cr_utils_trace_info ("Error while running " - "selector engine") ; - goto error ; - } - - } - - /* - *TODO, walk down the stmts_tab and build the - *property_name/declaration hashtable. - *Make sure one can walk from the declaration to - *the stylesheet. - */ - for (i = 0 ; i < tab_len ; i ++) - { - CRStatement *stmt = stmts_tab[i] ; - - if (!stmt) - continue ; - - switch (stmt->type) - { - case RULESET_STMT: - if (!stmt->parent_sheet) - continue ; - status = put_css_properties_in_hashtable - (a_props_hashtable, - stmt) ; - break ; - - default: - break ; - } - - } - - return CR_OK ; - error: - - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab = NULL ; - - } - - return status ; -} - - -enum CRStatus -cr_sel_eng_get_matched_style (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - CRStyle *a_parent_style, - CRStyle **a_style) -{ - enum CRStatus status = CR_OK ; - GHashTable *props_hash = NULL ; - - g_return_val_if_fail (a_this && a_cascade - && a_node && a_style - && (*a_style == NULL), - CR_BAD_PARAM_ERROR) ; - - status = cr_sel_eng_get_matched_properties_from_cascade - (a_this, a_cascade, a_node, &props_hash) ; - g_return_val_if_fail (status == CR_OK, status) ; - - if (props_hash && g_hash_table_size (props_hash)) - { - - if (!*a_style) - { - *a_style = cr_style_new () ; - g_return_val_if_fail (*a_style, CR_ERROR) ; - } - (*a_style)->parent_style = a_parent_style ; - - g_hash_table_foreach (props_hash, - ((GHFunc) - set_style_from_props_hash_hr_func), - *a_style) ; - } - - if (props_hash) - { - g_hash_table_destroy (props_hash) ; - props_hash = NULL ; - } - - return CR_OK ; -} - -/** - *The destructor of #CRSelEng - *@param a_this the current instance of the selection engine. - */ -void -cr_sel_eng_destroy (CRSelEng *a_this) -{ - g_return_if_fail (a_this) ; - - if (PRIVATE (a_this)) - { - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; - } - /* - *FIXME: - *unregister all the pseudo class sel handlers. - */ - if (a_this) - { - g_free (a_this) ; - } -} - diff --git a/src/seleng/cr-sel-eng.h b/src/seleng/cr-sel-eng.h deleted file mode 100644 index 44de096..0000000 --- a/src/seleng/cr-sel-eng.h +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */ - -/* - * This file is part of The Croco Library - * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program 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 Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef __CR_SEL_ENG_H__ -#define __CR_SEL_ENG_H__ - -#include "cr-utils.h" -#include "cr-stylesheet.h" -#include "cr-cascade.h" -#include "cr-style.h" - -#ifdef CROCO_HAVE_LIBXML2 - #include <libxml/tree.h> -#endif - -#ifdef CROCO_SELENG_ENABLED - - -/** - *@file: - *The declaration of the #CRSelEng class. - *The #CRSelEng is actually the "Selection Engine" - *class. - */ - -G_BEGIN_DECLS - -typedef struct _CRSelEng CRSelEng ; -typedef struct _CRSelEngPriv CRSelEngPriv ; - -/** - *The Selection engine class. - *The main service provided by this class, is - *the ability to interpret a libcroco implementation - *of css2 selectors, and given an xml node, say if - *the selector matches the node or not. - */ -struct _CRSelEng -{ - CRSelEngPriv *priv ; -} ; - -typedef gboolean (*CRPseudoClassSelectorHandler) (CRSelEng* a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; -CRSelEng * cr_sel_eng_new (void) ; - -enum CRStatus cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng *a_this, - guchar *a_pseudo_class_sel_name, - enum CRPseudoType a_pseudo_class_type, - CRPseudoClassSelectorHandler a_handler) ; - -enum CRStatus cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng *a_this, - guchar *a_pseudo_class_sel_name, - enum CRPseudoType a_pseudo_class_type) ; - -enum CRStatus cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng *a_this) ; - -enum CRStatus cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, - guchar *a_pseudo_class_sel_name, - enum CRPseudoType a_pseudo_class_type, - CRPseudoClassSelectorHandler *a_handler) ; - -enum CRStatus cr_sel_eng_matches_node (CRSelEng *a_this, - CRSimpleSel *a_sel, - xmlNode *a_node, - gboolean *a_result) ; - -enum CRStatus cr_sel_eng_get_matched_rulesets (CRSelEng *a_this, - CRStyleSheet *a_sheet, - xmlNode *a_node, - CRStatement ***a_rulesets, - gulong *a_len) ; - -enum CRStatus cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - GHashTable **props_decls_dict) ; - -enum CRStatus cr_sel_eng_get_matched_style (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - CRStyle *a_parent_style, - CRStyle **a_style) ; - -void cr_sel_eng_destroy (CRSelEng *a_this) ; - -G_END_DECLS - -#endif /*CROCO_SELENG_ENABLED*/ - -#endif/*__CR_SEL_ENG_H__*/ diff --git a/src/seleng/cr-style.c b/src/seleng/cr-style.c deleted file mode 100644 index 8059bcd..0000000 --- a/src/seleng/cr-style.c +++ /dev/null @@ -1,2190 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */ - -/* - * This file is part of The Croco Library - * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of - * the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program 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 Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - *$Id$ - */ -#include <string.h> -#include "cr-style.h" - -/** - *@file - *The definition of the #CRStyle class. - */ - - -/** - *A property ID. - *Each supported css property has an ID which is - *an entry into a property "population" jump table. - *each entry of the property population jump table - *contains code to tranform the literal form of - *a property value into a strongly typed value. - */ -enum CRPropertyID -{ - PROP_ID_NOT_KNOWN = 0, - PROP_ID_PADDING_TOP, - PROP_ID_PADDING_RIGHT, - PROP_ID_PADDING_BOTTOM, - PROP_ID_PADDING_LEFT, - PROP_ID_PADDING, - PROP_ID_BORDER_TOP_WIDTH, - PROP_ID_BORDER_RIGHT_WIDTH, - PROP_ID_BORDER_BOTTOM_WIDTH, - PROP_ID_BORDER_LEFT_WIDTH, - PROP_ID_BORDER_TOP_STYLE, - PROP_ID_BORDER_RIGHT_STYLE, - PROP_ID_BORDER_BOTTOM_STYLE, - PROP_ID_BORDER_LEFT_STYLE, - PROP_ID_BORDER_TOP_COLOR, - PROP_ID_BORDER_RIGHT_COLOR, - PROP_ID_BORDER_BOTTOM_COLOR, - PROP_ID_BORDER_LEFT_COLOR, - PROP_ID_BORDER_TOP, - PROP_ID_BORDER_RIGHT, - PROP_ID_BORDER_BOTTOM, - PROP_ID_BORDER_LEFT, - PROP_ID_BORDER, - PROP_ID_MARGIN_TOP, - PROP_ID_MARGIN_RIGHT, - PROP_ID_MARGIN_BOTTOM, - PROP_ID_MARGIN_LEFT, - PROP_ID_MARGIN, - PROP_ID_DISPLAY, - PROP_ID_POSITION, - PROP_ID_TOP, - PROP_ID_RIGHT, - PROP_ID_BOTTOM, - PROP_ID_LEFT, - PROP_ID_FLOAT, - PROP_ID_WIDTH, - PROP_ID_COLOR, - PROP_ID_BACKGROUND_COLOR, - PROP_ID_FONT_FAMILY, - PROP_ID_FONT_SIZE, - PROP_ID_FONT_STYLE, - PROP_ID_FONT_WEIGHT, - /*should be the last one.*/ - NB_PROP_IDS -} ; - - -typedef struct _CRPropertyDesc CRPropertyDesc ; - -struct _CRPropertyDesc -{ - const guchar * name ; - enum CRPropertyID prop_id ; -} ; - -static CRPropertyDesc gv_prop_table [] = - -{ - {"padding-top", PROP_ID_PADDING_TOP}, - {"padding-right", PROP_ID_PADDING_RIGHT}, - {"padding-bottom", PROP_ID_PADDING_BOTTOM}, - {"padding-left", PROP_ID_PADDING_LEFT}, - {"padding", PROP_ID_PADDING}, - {"border-top-width", PROP_ID_BORDER_TOP_WIDTH}, - {"border-right-width", PROP_ID_BORDER_RIGHT_WIDTH}, - {"border-bottom-width", PROP_ID_BORDER_BOTTOM_WIDTH}, - {"border-left-width", PROP_ID_BORDER_LEFT_WIDTH}, - {"border-top-style", PROP_ID_BORDER_TOP_STYLE}, - {"border-right-style", PROP_ID_BORDER_RIGHT_STYLE}, - {"border-bottom-style", PROP_ID_BORDER_BOTTOM_STYLE}, - {"border-left-style", PROP_ID_BORDER_LEFT_STYLE}, - {"border-top", PROP_ID_BORDER_TOP}, - {"border-right", PROP_ID_BORDER_RIGHT}, - {"border-bottom", PROP_ID_BORDER_BOTTOM}, - {"border-left", PROP_ID_BORDER_LEFT}, - {"border", PROP_ID_BORDER}, - {"margin-top", PROP_ID_MARGIN_TOP}, - {"margin-right", PROP_ID_MARGIN_RIGHT}, - {"margin-bottom", PROP_ID_MARGIN_BOTTOM}, - {"margin-left", PROP_ID_MARGIN_LEFT}, - {"margin", PROP_ID_MARGIN}, - {"display", PROP_ID_DISPLAY}, - {"position", PROP_ID_POSITION}, - {"top", PROP_ID_TOP}, - {"right", PROP_ID_RIGHT}, - {"bottom", PROP_ID_BOTTOM}, - {"left", PROP_ID_LEFT}, - {"float", PROP_ID_FLOAT}, - {"width", PROP_ID_WIDTH}, - {"color", PROP_ID_COLOR}, - {"background-color", PROP_ID_BACKGROUND_COLOR}, - {"font-family", PROP_ID_FONT_FAMILY}, - {"font-size", PROP_ID_FONT_SIZE}, - {"font-style", PROP_ID_FONT_STYLE}, - {"font-weight", PROP_ID_FONT_WEIGHT}, - /*must be the last one*/ - {NULL, 0} -} ; - - - -/** - *A the key/value pair of this hash table - *are: - *key => name of the the css propertie found in gv_prop_table - *value => matching property id found in gv_prop_table. - *So this hash table is here just to retrieval of a property id - *from a property name. - */ -static GHashTable *gv_prop_hash = NULL ; - -/** - *incremented by each new instance of #CRStyle - *and decremented at the it destroy time. - *When this reaches zero, gv_prop_hash is destroyed. - */ -static gulong gv_prop_hash_ref_count = 0 ; - -static enum CRStatus -cr_style_init_properties (void) ; - -enum CRDirection -{ - DIR_TOP = 0, - DIR_RIGHT, - DIR_BOTTOM, - DIR_LEFT, - - /*must be the last one*/ - NB_DIRS -} ; - -static enum CRStatus -cr_style_set_props_to_defaults (CRStyle *a_this) ; - -static enum CRStatus -set_prop_padding_x_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_border_x_width_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_border_x_style_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_margin_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_display_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_position_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_float (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_width (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_color_rgb (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_background_color (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_border_x_color_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_border_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; - -static enum CRStatus -set_prop_border_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_padding_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_margin_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_font_family_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -init_style_font_size_field (CRStyle *a_style) ; - -static enum CRStatus -set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) ; - - -static enum CRStatus -set_prop_font_style_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) ; - -static enum CRStatus -cr_style_init_properties (void) -{ - - if (!gv_prop_hash) - { - gulong i = 0 ; - - gv_prop_hash = g_hash_table_new (g_str_hash, - g_str_equal) ; - if (!gv_prop_hash) - { - cr_utils_trace_info ("Out of memory") ; - return CR_ERROR ; - } - - /*load gv_prop_hash from gv_prop_table*/ - for (i = 0 ; gv_prop_table[i].name ; i++) - { - g_hash_table_insert - (gv_prop_hash, - (gpointer)gv_prop_table[i].name, - GINT_TO_POINTER - (gv_prop_table[i].prop_id)) ; - } - } - - return CR_OK ; -} - -/** - *Sets the style properties to their default values - *according to the css2 spec. - *@param a_this the current instance of #CRStyle. - *@return CR_OK upon successfull completion, an error code otherwise. - */ -static enum CRStatus -cr_style_set_props_to_defaults (CRStyle *a_this) -{ - glong i = 0 ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - for (i = 0 ; i < NB_NUM_PROPS ; i++) - { - switch (i) - { - case NUM_PROP_WIDTH: - case NUM_PROP_TOP: - case NUM_PROP_RIGHT: - case NUM_PROP_BOTTOM: - case NUM_PROP_LEFT: - cr_num_set (&a_this->num_props[i].sv, - 0, NUM_AUTO) ; - break ; - - case NUM_PROP_PADDING_TOP: - case NUM_PROP_PADDING_RIGHT: - case NUM_PROP_PADDING_BOTTOM: - case NUM_PROP_PADDING_LEFT: - case NUM_PROP_BORDER_TOP: - case NUM_PROP_BORDER_RIGHT: - case NUM_PROP_BORDER_BOTTOM: - case NUM_PROP_BORDER_LEFT: - case NUM_PROP_MARGIN_TOP: - case NUM_PROP_MARGIN_RIGHT: - case NUM_PROP_MARGIN_BOTTOM: - case NUM_PROP_MARGIN_LEFT: - cr_num_set (&a_this->num_props[i].sv, - 0, NUM_LENGTH_PX) ; - break ; - - default: - cr_utils_trace_info ("Unknown property") ; - break ; - } - } - - for (i = 0 ; i < NB_RGB_PROPS ; i++) - { - - switch (i) - { - /*default foreground color is black*/ - case RGB_PROP_COLOR: - cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, - FALSE) ; - break ; - - /*default background color is white*/ - case RGB_PROP_BACKGROUND_COLOR: - cr_rgb_set (&a_this->rgb_props[i].sv, - 255, 255, 255, FALSE) ; - break ; - - default: - cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, - FALSE) ; - break ; - } - } - - for (i = 0 ; i < NB_BORDER_STYLE_PROPS ; i++) - { - a_this->border_style_props[i] = BORDER_STYLE_NONE ; - } - - a_this->display = DISPLAY_BLOCK ; - a_this->position = POSITION_STATIC ; - a_this->float_type = FLOAT_NONE ; - a_this->parent_style = NULL ; - - return CR_OK ; -} - - -static enum CRPropertyID -cr_style_get_prop_id (const guchar * a_prop) -{ - gpointer * raw_id = NULL ; - - if (!gv_prop_hash) - { - cr_style_init_properties () ; - } - - raw_id = g_hash_table_lookup (gv_prop_hash, - a_prop) ; - if (!raw_id) - { - return PROP_ID_NOT_KNOWN ; - } - return GPOINTER_TO_INT (raw_id) ; -} - - -static enum CRStatus -set_prop_padding_x_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) -{ - enum CRStatus status = CR_OK ; - CRNum *num_val = NULL, *parent_num_val = NULL ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - if (a_value->type != TERM_NUMBER - && a_value->type != TERM_IDENT) - return CR_BAD_PARAM_ERROR ; - - switch (a_dir) - { - case DIR_TOP: - num_val = &a_style->num_props[NUM_PROP_PADDING_TOP].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_PADDING_TOP].sv ; - break ; - - case DIR_RIGHT: - num_val = &a_style->num_props[NUM_PROP_PADDING_RIGHT].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_PADDING_RIGHT].sv; - - num_val = &a_style->num_props[NUM_PROP_PADDING_RIGHT].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_PADDING_RIGHT].sv ; - break ; - - case DIR_BOTTOM: - num_val = - &a_style->num_props[NUM_PROP_PADDING_BOTTOM].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_PADDING_BOTTOM].sv ; - break ; - - case DIR_LEFT: - num_val = & a_style->num_props[NUM_PROP_PADDING_LEFT].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_PADDING_LEFT].sv ; - break ; - - default: - return CR_BAD_PARAM_ERROR ; - } - - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str - && a_value->content.str->str - && !strncmp ((guchar*)"inherited", - a_value->content.str->str, - strlen ("inherited"))) - { - cr_num_copy (num_val, parent_num_val) ; - return CR_OK ; - } - else - return CR_UNKNOWN_TYPE_ERROR ; - } - - g_return_val_if_fail (a_value->type == TERM_NUMBER - && a_value->content.num, - CR_UNKNOWN_TYPE_ERROR) ; - - switch (a_value->content.num->type) - { - case NUM_LENGTH_EM: - case NUM_LENGTH_EX: - case NUM_LENGTH_PX: - case NUM_LENGTH_IN: - case NUM_LENGTH_CM: - case NUM_LENGTH_MM: - case NUM_LENGTH_PT: - case NUM_LENGTH_PC: - case NUM_PERCENTAGE: - status = cr_num_copy (num_val, a_value->content.num) ; - break ; - default: - status = CR_UNKNOWN_TYPE_ERROR ; - break ; - } - - return status ; -} - - -static enum CRStatus -set_prop_border_x_width_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) -{ - enum CRStatus status = CR_OK ; - CRNum *num_val = NULL ; - - g_return_val_if_fail (a_value - && a_style, - CR_BAD_PARAM_ERROR) ; - - switch (a_dir) - { - case DIR_TOP: - num_val = &a_style->num_props[NUM_PROP_BORDER_TOP].sv ; - break ; - - case DIR_RIGHT: - num_val = - &a_style->num_props[NUM_PROP_BORDER_RIGHT].sv ; - break ; - - case DIR_BOTTOM: - num_val = &a_style->num_props[NUM_PROP_BORDER_BOTTOM].sv ; - break ; - - case DIR_LEFT: - num_val = &a_style->num_props[NUM_PROP_BORDER_LEFT].sv ; - break ; - - default: - return CR_BAD_PARAM_ERROR ; - break ; - } - - - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str && a_value->content.str->str) - { - if (!strncmp ("thin", - a_value->content.str->str, - strlen ("thin"))) - { - cr_num_set (num_val, BORDER_THIN, - NUM_LENGTH_PX) ; - } - else if (!strncmp ("medium", - a_value->content.str->str, - strlen ("medium"))) - { - cr_num_set (num_val, BORDER_MEDIUM, - NUM_LENGTH_PX) ; - } - else if (!strncmp ("thick", - a_value->content.str->str, - strlen ("thick"))) - { - cr_num_set (num_val, BORDER_THICK, - NUM_LENGTH_PX) ; - } - else - { - return CR_UNKNOWN_TYPE_ERROR ; - } - } - } - else if (a_value->type == TERM_NUMBER) - { - if (a_value->content.num) - { - cr_num_copy (num_val, a_value->content.num) ; - } - } - else if (a_value->type != TERM_NUMBER - || a_value->content.num == NULL) - { - return CR_UNKNOWN_TYPE_ERROR ; - } - - return status ; -} - - -static enum CRStatus -set_prop_border_x_style_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) -{ - enum CRStatus status = CR_OK ; - enum CRBorderStyle *border_style_ptr=NULL, - *parent_border_style_ptr = NULL; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_dir) - { - case DIR_TOP: - border_style_ptr = &a_style-> - border_style_props[BORDER_STYLE_PROP_TOP] ; - parent_border_style_ptr = (a_style->parent_style)? - &a_style->parent_style-> - border_style_props[BORDER_STYLE_PROP_TOP]: NULL ; - - break ; - - case DIR_RIGHT: - border_style_ptr = - &a_style->border_style_props[BORDER_STYLE_PROP_RIGHT] ; - - parent_border_style_ptr = (a_style->parent_style)? - &a_style->parent_style-> - border_style_props[BORDER_STYLE_PROP_RIGHT] : NULL ; - break ; - - case DIR_BOTTOM: - border_style_ptr = &a_style-> - border_style_props[BORDER_STYLE_PROP_BOTTOM] ; - parent_border_style_ptr = (a_style->parent_style)? - &a_style->parent_style-> - border_style_props[BORDER_STYLE_PROP_BOTTOM] : NULL; - break ; - - case DIR_LEFT: - border_style_ptr = &a_style-> - border_style_props[BORDER_STYLE_PROP_LEFT] ; - parent_border_style_ptr = (a_style->parent_style)? - &a_style->parent_style-> - border_style_props[BORDER_STYLE_PROP_LEFT] : NULL; - break ; - - default: - break ; - } - - if (a_value->type != TERM_IDENT - || !a_value->content.str) - { - return CR_UNKNOWN_TYPE_ERROR ; - } - - if (!strncmp ("none", - a_value->content.str->str, - strlen ("none"))) - { - *border_style_ptr = BORDER_STYLE_NONE ; - } - else if (!strncmp ("hidden", - a_value->content.str->str, - strlen ("hidden"))) - { - *border_style_ptr = BORDER_STYLE_HIDDEN ; - } - else if (!strncmp ("dotted", - a_value->content.str->str, - strlen ("dotted"))) - { - *border_style_ptr = BORDER_STYLE_DOTTED ; - } - else if (!strncmp ("dashed", - a_value->content.str->str, - strlen ("dashed"))) - { - *border_style_ptr = BORDER_STYLE_DASHED ; - } - else if (!strncmp ("solid", - a_value->content.str->str, - strlen ("solid"))) - { - *border_style_ptr = BORDER_STYLE_SOLID ; - } - else if (!strncmp ("double", - a_value->content.str->str, - strlen ("double"))) - { - *border_style_ptr = BORDER_STYLE_DOUBLE ; - } - else if (!strncmp ("groove", - a_value->content.str->str, - strlen ("groove"))) - { - *border_style_ptr = BORDER_STYLE_GROOVE ; - } - else if (!strncmp ("ridge", - a_value->content.str->str, - strlen ("ridge"))) - { - *border_style_ptr = BORDER_STYLE_RIDGE ; - } - else if (!strncmp ("inset", - a_value->content.str->str, - strlen ("inset"))) - { - *border_style_ptr = BORDER_STYLE_INSET ; - } - else if (!strncmp ("outset", - a_value->content.str->str, - strlen ("outset"))) - { - *border_style_ptr = BORDER_STYLE_OUTSET ; - } - else if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { - if (parent_border_style_ptr) - *border_style_ptr = *parent_border_style_ptr ; - } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; - } - - return status ; -} - -static enum CRStatus -set_prop_margin_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) -{ - enum CRStatus status = CR_OK ; - CRNum *num_val = NULL, *parent_num_val = NULL ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_dir) - { - case DIR_TOP: - num_val = &a_style->num_props[NUM_PROP_MARGIN_TOP].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_MARGIN_TOP].sv ; - break ; - - case DIR_RIGHT: - num_val = - &a_style->num_props[NUM_PROP_MARGIN_RIGHT].sv ; - - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_MARGIN_RIGHT].sv ; - break ; - - case DIR_BOTTOM: - num_val = &a_style->num_props[NUM_PROP_MARGIN_BOTTOM].sv ; - parent_num_val = - &a_style->parent_style->num_props[NUM_PROP_MARGIN_BOTTOM].sv ; - break ; - - case DIR_LEFT: - num_val = &a_style->num_props[NUM_PROP_MARGIN_LEFT].sv ; - parent_num_val = - &a_style->parent_style-> - num_props[NUM_PROP_MARGIN_LEFT].sv ; - break ; - - default: - break ; - } - - switch (a_value->type) - { - case TERM_IDENT: - if (a_value->content.str - && a_value->content.str->str - && !strncmp (a_value->content.str->str, - "inherit", strlen ("inherit"))) - { - status = cr_num_copy (num_val, parent_num_val) ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strncmp (a_value->content.str->str, - "auto", strlen ("auto"))) - { - status = cr_num_set (num_val, 0.0, NUM_AUTO) ; - } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; - } - - case TERM_NUMBER: - status = cr_num_copy (num_val, a_value->content.num) ; - break ; - - default: - status = CR_UNKNOWN_TYPE_ERROR ; - break ; - } - - return status ; -} - -struct CRPropDisplayValPair -{ - const guchar *prop_name ; - enum CRDisplayType type; -} ; - -static enum CRStatus -set_prop_display_from_value (CRStyle *a_style, CRTerm *a_value) -{ - enum CRDisplayType default_display_val = DISPLAY_INLINE ; - static const struct CRPropDisplayValPair disp_vals_map[] = - { - {"none", DISPLAY_NONE}, - {"inline", DISPLAY_INLINE}, - {"block", DISPLAY_BLOCK}, - {"run-in", DISPLAY_RUN_IN}, - {"compact", DISPLAY_COMPACT}, - {"marker", DISPLAY_MARKER}, - {"table", DISPLAY_TABLE}, - {"inline-table", DISPLAY_INLINE_TABLE}, - {"table-row-group", DISPLAY_TABLE_ROW_GROUP}, - {"table-header-group", DISPLAY_TABLE_HEADER_GROUP}, - {"table-footer-group", DISPLAY_TABLE_FOOTER_GROUP}, - {"table-row", DISPLAY_TABLE_ROW}, - {"table-column-group", DISPLAY_TABLE_COLUMN_GROUP}, - {"table-column", DISPLAY_TABLE_COLUMN}, - {"table-cell", DISPLAY_TABLE_CELL}, - {"table-caption", DISPLAY_TABLE_CAPTION}, - {"inherit", DISPLAY_INHERIT}, - {NULL, DISPLAY_NONE} - } ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - /*Sets to its default value according to the css2 spec.*/ - a_style->display = default_display_val ; - - switch (a_value->type) - { - case TERM_IDENT: - { - int i = 0 ; - - if (!a_value->content.str || !a_value->content.str->str) - break ; - - for (i = 0; disp_vals_map[i].prop_name ; i++) - { - if (!strncmp (disp_vals_map[i].prop_name, - a_value->content.str->str, - strlen - (disp_vals_map[i].prop_name))) - { - a_style->display = disp_vals_map[i].type ; - break ; - } - } - - if (a_style->display == DISPLAY_INHERIT) - { - if (a_style->parent_style) - { - a_style->display = - a_style->parent_style->display ; - } - else - { - a_style->display = default_display_val ; - } - } - } - break ; - - default : - break ; - } - - return CR_OK ; -} - -struct CRPropPositionValPair -{ - const guchar * name ; - enum CRPositionType type ; -} ; - -static enum CRStatus -set_prop_position_from_value (CRStyle *a_style, CRTerm *a_value) -{ - enum CRStatus status = CR_UNKNOWN_PROP_VAL_ERROR ; - static const struct CRPropPositionValPair position_vals_map [] = - { - {"static", POSITION_STATIC}, - {"relative", POSITION_RELATIVE}, - {"absolute", POSITION_ABSOLUTE}, - {"fixed", POSITION_FIXED}, - {"inherited", POSITION_INHERIT}, - {NULL, POSITION_STATIC} - /*must alwas be the last one*/ - } ; - - g_return_val_if_fail (a_value, CR_BAD_PARAM_ERROR) ; - - /*set to it's default value according to the css2 spec*/ - a_style->position = POSITION_STATIC ; - - switch (a_value->type) - { - case TERM_IDENT: - { - int i = 0 ; - - if (!a_value->content.str || !a_value->content.str->str) - break ; - - for (i = 0; position_vals_map[i].name ; i++) - { - if (!strncmp (position_vals_map[i].name, - a_value->content.str->str, - strlen (position_vals_map[i].name))) - { - a_style->position = - position_vals_map[i].type ; - status = CR_OK ; - break ; - } - } - if (a_style->position == POSITION_INHERIT) - { - if (a_style->parent_style) - { - a_style->position = - a_style->parent_style->position ; - } - else - { - a_style->position = POSITION_STATIC ; - } - } - } - break ; - - default: - break ; - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) -{ - CRNum *box_offset = NULL, *parent_box_offset = NULL ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - - if (!(a_value->type == TERM_NUMBER) - && !(a_value->type == TERM_IDENT)) - { - return CR_UNKNOWN_PROP_VAL_ERROR ; - } - - switch (a_dir) - { - case DIR_TOP: - box_offset = &a_style->num_props[NUM_PROP_TOP].sv ; - if (a_style->parent_style) - parent_box_offset = - &a_style->parent_style-> - num_props[NUM_PROP_TOP].sv ; - break ; - - case DIR_RIGHT: - box_offset = &a_style->num_props[NUM_PROP_RIGHT].sv ; - if (a_style->parent_style) - parent_box_offset = &a_style->parent_style-> - num_props[NUM_PROP_RIGHT].sv ; - break ; - - case DIR_BOTTOM: - box_offset = &a_style->num_props[NUM_PROP_BOTTOM].sv ; - if (a_style->parent_style) - parent_box_offset = - &a_style->parent_style-> - num_props[NUM_PROP_BOTTOM].sv ; - break ; - case DIR_LEFT: - box_offset = &a_style->num_props[NUM_PROP_LEFT].sv ; - if (a_style->parent_style) - parent_box_offset = - &a_style->parent_style-> - num_props[NUM_PROP_LEFT].sv ; - break ; - - default: - break ; - } - - box_offset->type = NUM_AUTO ; - - if (a_value->type == TERM_NUMBER - && a_value->content.num) - { - cr_num_copy (box_offset, a_value->content.num) ; - } - else if (a_value->type == TERM_IDENT - && a_value->content.str - && a_value->content.str->str) - { - if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { - cr_num_copy (box_offset, - parent_box_offset) ; - } - else if (!strncmp ("auto", - a_value->content.str->str, - strlen ("auto"))) - { - box_offset->type = NUM_AUTO ; - } - } - - return CR_OK ; -} - - -static enum CRStatus -set_prop_float (CRStyle *a_style, CRTerm *a_value) -{ - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - /*the default float type as specified by the css2 spec*/ - a_style->float_type = FLOAT_NONE ; - - if (a_value->type != TERM_IDENT - || !a_value->content.str - || !a_value->content.str->str) - {/*unknow type, the float type is set to it's default value*/ - return CR_OK ; - } - - if (!strncmp ("none", - a_value->content.str->str, - strlen ("none"))) - { - a_style->float_type = FLOAT_NONE ; - } - else if (!strncmp ("left", - a_value->content.str->str, - strlen ("left"))) - { - a_style->float_type = FLOAT_LEFT ; - } - else if (!strncmp ("right", - a_value->content.str->str, - strlen ("right"))) - { - a_style->float_type = FLOAT_RIGHT ; - } - else if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { - a_style->float_type = - a_style->parent_style->float_type ; - } - - return CR_OK ; -} - - -static enum CRStatus -set_prop_width (CRStyle *a_style, CRTerm *a_value) -{ - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - - a_style->num_props[NUM_PROP_WIDTH].sv.type = NUM_AUTO ; - - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str - && a_value->content.str->str) - { - if (!strncmp ("auto", - a_value->content.str->str, - strlen ("auto"))) - { - a_style->num_props[NUM_PROP_WIDTH].sv.type = - NUM_AUTO ; - } - else if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { - cr_num_copy - (&a_style-> - num_props[NUM_PROP_WIDTH].sv, - &a_style->parent_style-> - num_props[NUM_PROP_WIDTH].sv) ; - } - } - } - else if (a_value->type == TERM_NUMBER) - { - if (a_value->content.num) - { - cr_num_copy (&a_style->num_props[NUM_PROP_WIDTH].sv, - a_value->content.num) ; - } - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_color_rgb (CRStyle *a_style, CRTerm *a_value) -{ - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - if (a_value->type == TERM_RGB) - { - if (a_value->content.rgb) - { - cr_rgb_set_from_rgb - (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.rgb) ; - } - - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_background_color (CRStyle *a_style, CRTerm *a_value) -{ - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_value->type) - { - case TERM_RGB: - if (a_value->content.rgb) - { - status = cr_rgb_set_from_rgb - (&a_style-> - rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.rgb) ; - } - break ; - - case TERM_IDENT: - status = cr_rgb_set_from_name - (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.str->str) ; - break ; - - case TERM_HASH: - status = cr_rgb_set_from_hex_str - (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.str->str) ; - break ; - - default: - status = CR_UNKNOWN_TYPE_ERROR ; - break ; - } - - return status ; -} - -/** - *Sets border-top-color, border-right-color, - *border-bottom-color or border-left-color properties - *in the style structure. The value is taken from a - *css2 term of type IDENT or RGB. - *@param a_style the style structure to set. - *@param a_value the css2 term to take the color information from. - *@param a_dir the direction (TOP, LEFT, RIGHT, or BOTTOM). - *@return CR_OK upon successfull completion, an error code otherwise. - */ -static enum CRStatus -set_prop_border_x_color_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) -{ - CRRgb *rgb_color = NULL ; - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_dir) - { - case DIR_TOP: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_TOP_COLOR].sv ; - break ; - - case DIR_RIGHT: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_RIGHT_COLOR].sv ; - break ; - - case DIR_BOTTOM: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_BOTTOM_COLOR].sv; - break ; - - case DIR_LEFT: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_LEFT_COLOR].sv ; - break ; - - default: - cr_utils_trace_info ("unknown DIR type") ; - return CR_BAD_PARAM_ERROR ; - } - - status = CR_UNKNOWN_PROP_VAL_ERROR ; - - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str && a_value->content.str->str) - { - status = cr_rgb_set_from_name - (rgb_color, a_value->content.str->str) ; - - } - - if (status != CR_OK) - { - cr_rgb_set_from_name (rgb_color, "black") ; - } - } - else if (a_value->type == TERM_RGB) - { - if (a_value->content.rgb) - { - status = cr_rgb_set_from_rgb - (rgb_color, a_value->content.rgb) ; - } - } - - return status ; -} - - -static enum CRStatus -set_prop_border_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) -{ - CRTerm *cur_term = NULL ; - - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - for (cur_term = a_value ; cur_term ; cur_term = cur_term->next) - { - status = - set_prop_border_x_width_from_value (a_style, cur_term, - a_dir) ; - - if (status != CR_OK) - { - status = set_prop_border_x_style_from_value - (a_style, cur_term, a_dir) ; - } - - if (status != CR_OK) - { - status = set_prop_border_x_color_from_value - (a_style, cur_term, a_dir) ; - } - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_border_from_value (CRStyle *a_style, CRTerm *a_value) -{ - enum CRDirection direction = 0 ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - for (direction = 0 ; direction < NB_DIRS ; direction ++) - { - set_prop_border_x_from_value (a_style, a_value, direction) ; - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_padding_from_value (CRStyle *a_style, CRTerm *a_value) -{ - CRTerm *cur_term = NULL ; - enum CRDirection direction = 0 ; - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - cur_term = a_value ; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - - if (!cur_term) - return CR_OK ; - - for (direction = 0 ; direction < NB_DIRS ; direction ++) - { - set_prop_padding_x_from_value (a_style, cur_term, - direction) ; - } - cur_term = cur_term->next ; - - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - if (!cur_term) - return CR_OK ; - - set_prop_padding_x_from_value (a_style, cur_term, DIR_RIGHT) ; - set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT) ; - - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - if (!cur_term) - return CR_OK ; - - set_prop_padding_x_from_value (a_style, cur_term, DIR_BOTTOM) ; - - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - if (!cur_term) - return CR_OK ; - - status = set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT) ; - - return status ; -} - -static enum CRStatus -set_prop_margin_from_value (CRStyle *a_style, CRTerm *a_value) -{ - CRTerm *cur_term = NULL ; - enum CRDirection direction = 0 ; - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - cur_term = a_value ; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - - if (!cur_term) - return CR_OK ; - - for (direction = 0 ; direction < NB_DIRS ; direction ++) - { - set_prop_margin_x_from_value (a_style, cur_term, - direction) ; - } - cur_term = cur_term->next ; - - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - if (!cur_term) - return CR_OK ; - - set_prop_margin_x_from_value (a_style, cur_term, DIR_RIGHT) ; - set_prop_margin_x_from_value (a_style, cur_term, DIR_LEFT) ; - - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - if (!cur_term) - return CR_OK ; - - set_prop_margin_x_from_value (a_style, cur_term, DIR_BOTTOM) ; - - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; - } - if (!cur_term) - return CR_OK ; - - status = set_prop_margin_x_from_value (a_style, cur_term, DIR_LEFT) ; - - return status ; -} - -static enum CRStatus -set_prop_font_family_from_value (CRStyle *a_style, CRTerm *a_value) -{ - CRTerm *cur_term = NULL ; - CRFontFamily *font_family = NULL, *cur_ff = NULL, *cur_ff2 = NULL; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - - for (cur_term = a_value ; cur_term ; cur_term = cur_term->next) - { - switch (cur_term->type) - { - case TERM_IDENT: - { - enum CRFontFamilyType font_type ; - - if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "sans-serif")) - { - font_type = FONT_FAMILY_SANS_SERIF ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "serif")) - { - font_type = FONT_FAMILY_SERIF ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "cursive")) - { - font_type = FONT_FAMILY_CURSIVE ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "fantasy")) - { - font_type = FONT_FAMILY_FANTASY ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "monospace")) - { - font_type = FONT_FAMILY_MONOSPACE ; - } - else - { - /* - *unknown property value. - *ignore it. - */ - continue ; - } - - cur_ff = - cr_font_family_new (font_type, NULL) ; - } - break ; - - case TERM_STRING: - { - if (cur_term->content.str - && cur_term->content.str->str) - { - cur_ff = cr_font_family_new - (FONT_FAMILY_NON_GENERIC, - cur_term->content.str->str) ; - } - } - break ; - - default: - break ; - } - - cur_ff2 = cr_font_family_append (font_family, - cur_ff) ; - if (cur_ff2) - { - font_family = cur_ff2 ; - } - } - - if (font_family) - { - if (a_style->font_family) - { - cr_font_family_destroy (a_style->font_family) ; - a_style->font_family = font_family ; - } - } - - return CR_OK ; -} - -static enum CRStatus -init_style_font_size_field (CRStyle *a_style) -{ - g_return_val_if_fail (a_style, CR_BAD_PARAM_ERROR) ; - - if (!a_style->font_size) - { - a_style->font_size = cr_font_size_new () ; - if (!a_style->font_size) - { - return CR_INSTANCIATION_FAILED_ERROR ; - } - } - else - { - cr_font_size_clear (a_style->font_size) ; - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) -{ - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - switch (a_value->type) - { - case TERM_IDENT: - if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "xx-small")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_XX_SMALL ; - - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "x-small")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_X_SMALL ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "small")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_SMALL ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "medium")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_MEDIUM ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "large")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_LARGE ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "x-large")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_X_LARGE ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "xx-large")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_XX_LARGE ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "larger")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; - - a_style->font_size->type = - RELATIVE_FONT_SIZE ; - a_style->font_size->value.relative = - FONT_SIZE_LARGER ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "smaller")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; - - a_style->font_size->type = - RELATIVE_FONT_SIZE ; - a_style->font_size->value.relative = - FONT_SIZE_SMALLER ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "inherit")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; - - if (a_style->parent_style - && a_style->parent_style->font_style) - { - cr_font_size_copy - (a_style->font_size, - a_style->parent_style->font_size) ; - } - } - else - { - return CR_UNKNOWN_PROP_VAL_ERROR ; - } - break ; - - case TERM_NUMBER: - if (a_value->content.num) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; - - a_style->font_size->type = ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.absolute = - cr_num_dup (a_value->content.num) ; - } - break ; - - default: - return CR_UNKNOWN_PROP_VAL_ERROR ; - } - - return CR_OK ; -} - -static enum CRStatus -set_prop_font_style_from_value (CRStyle *a_style, CRTerm *a_value) -{ - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_value->type) - { - case TERM_IDENT: - if (a_value->content.str && a_value->content.str->str) - { - if (!strcmp (a_value->content.str->str, "normal")) - { - a_style->font_style = FONT_STYLE_NORMAL ; - } - else if (!strcmp (a_value->content.str->str, "italic")) - { - a_style->font_style = FONT_STYLE_ITALIC ; - } - else if (!strcmp (a_value->content.str->str, "oblique")) - { - a_style->font_style = FONT_STYLE_OBLIQUE ; - } - else if (!strcmp (a_value->content.str->str, "inherit")) - { - if (!a_style->font_style) - a_style->font_style = FONT_STYLE_NORMAL; - else - a_style->font_style = - a_style->parent_style-> - font_style ; - } - else - { - status = CR_UNKNOWN_PROP_VAL_ERROR ; - } - } - break ; - - default: - status = CR_UNKNOWN_PROP_VAL_ERROR ; - break ; - } - - return status ; -} - -static enum CRStatus -set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) -{ - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_value->type) - { - case TERM_IDENT: - if (a_value->content.str && a_value->content.str->str) - { - if (!strcmp (a_value->content.str->str, - "normal")) - { - a_style->font_weight = FONT_WEIGHT_NORMAL ; - } - else if (!strcmp (a_value->content.str->str, - "bold")) - { - a_style->font_weight = FONT_WEIGHT_BOLD ; - } - else if (!strcmp (a_value->content.str->str, - "bolder")) - { - a_style->font_weight = FONT_WEIGHT_BOLDER ; - } - else if (!strcmp (a_value->content.str->str, - "lighter")) - { - a_style->font_weight = FONT_WEIGHT_LIGHTER ; - } - else - { - status = CR_UNKNOWN_PROP_VAL_ERROR ; - } - - } - break ; - - case TERM_NUMBER: - if (a_value->content.num - && (a_value->content.num->type == NUM_GENERIC - ||a_value->content.num->type == NUM_AUTO)) - { - if (a_value->content.num->val <= 150) - { - a_style->font_weight = FONT_WEIGHT_100 ; - } - else if (a_value->content.num->val <= 250) - { - a_style->font_weight = FONT_WEIGHT_200 ; - } - else if (a_value->content.num->val <= 350) - { - a_style->font_weight = FONT_WEIGHT_300 ; - } - else if (a_value->content.num->val <= 450) - { - a_style->font_weight = FONT_WEIGHT_400 ; - } - else if (a_value->content.num->val <= 550) - { - a_style->font_weight = FONT_WEIGHT_500 ; - } - else if (a_value->content.num->val <= 650) - { - a_style->font_weight = FONT_WEIGHT_600 ; - } - else if (a_value->content.num->val <= 750) - { - a_style->font_weight = FONT_WEIGHT_700 ; - } - else if (a_value->content.num->val <= 850) - { - a_style->font_weight = FONT_WEIGHT_800 ; - } - else - { - a_style->font_weight = FONT_WEIGHT_900 ; - } - } - break ; - - default: - status = CR_UNKNOWN_PROP_VAL_ERROR ; - break ; - } - - return status ; -} - -/****************** - *Public methods - ******************/ - -/** - *Default constructor of #CRStyle. - */ -CRStyle * -cr_style_new (void) -{ - CRStyle *result = NULL ; - - result = g_try_malloc (sizeof (CRStyle)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRStyle)) ; - gv_prop_hash_ref_count ++ ; - - /*set the style properties to their default values*/ - cr_style_set_props_to_defaults (result) ; - - return result ; -} - - -/** - *Walks through a css2 property declaration, and populated the - *according field(s) in the #CRStyle structure. - *If the properties or their value(s) are/is not known, - *sets the corresponding field(s) of #CRStyle to its/their default - *value(s) - *@param a_this the instance of #CRStyle to set. - *@param a_decl the declaration from which the #CRStyle fields are set. - *@return CR_OK upon successfull completion, an error code otherwise. - */ -enum CRStatus -cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) -{ - CRTerm *value = NULL ; - enum CRStatus status = CR_OK ; - - enum CRPropertyID prop_id = PROP_ID_NOT_KNOWN ; - - g_return_val_if_fail (a_this && a_decl - && a_decl - && a_decl->property - && a_decl->property->str, - CR_BAD_PARAM_ERROR) ; - - prop_id = cr_style_get_prop_id (a_decl->property->str) ; - - value = a_decl->value ; - switch (prop_id) - { - case PROP_ID_PADDING_TOP: - status = set_prop_padding_x_from_value - (a_this, value, DIR_TOP) ; - break ; - - case PROP_ID_PADDING_RIGHT: - status = set_prop_padding_x_from_value - (a_this, value, DIR_RIGHT) ; - break ; - case PROP_ID_PADDING_BOTTOM: - status = set_prop_padding_x_from_value - (a_this, value, DIR_BOTTOM) ; - break ; - - case PROP_ID_PADDING_LEFT: - status = set_prop_padding_x_from_value - (a_this, value, DIR_LEFT) ; - break ; - - case PROP_ID_PADDING: - status = set_prop_padding_from_value (a_this, value) ; - break ; - - case PROP_ID_BORDER_TOP_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_BORDER_RIGHT_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_RIGHT) ; - break ; - - case PROP_ID_BORDER_BOTTOM_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_BORDER_LEFT_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_LEFT) ; - break ; - - case PROP_ID_BORDER_TOP_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_BORDER_RIGHT_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_RIGHT) ; - break ; - - case PROP_ID_BORDER_BOTTOM_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_BORDER_LEFT_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_LEFT) ; - break ; - - case PROP_ID_BORDER_TOP_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_BORDER_RIGHT_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_RIGHT) ; - break ; - - case PROP_ID_BORDER_BOTTOM_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_BORDER_LEFT_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_BORDER_TOP: - status = - set_prop_border_x_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_BORDER_RIGHT: - status = - set_prop_border_x_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_BORDER_BOTTOM: - status = - set_prop_border_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_BORDER_LEFT: - status = - set_prop_border_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_MARGIN_TOP: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_BORDER: - status = - set_prop_border_from_value (a_this, value) ; - break ; - - case PROP_ID_MARGIN_RIGHT: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_RIGHT) ; - break ; - - case PROP_ID_MARGIN_BOTTOM: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_MARGIN_LEFT: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_LEFT) ; - break ; - - case PROP_ID_MARGIN: - status = - set_prop_margin_from_value (a_this, value) ; - break ; - - case PROP_ID_DISPLAY: - status = - set_prop_display_from_value (a_this, value) ; - break ; - - case PROP_ID_POSITION: - status = set_prop_position_from_value (a_this, value) ; - break ; - - case PROP_ID_TOP: - status = set_prop_x_from_value (a_this, value, - DIR_TOP) ; - break ; - - case PROP_ID_RIGHT: - status = set_prop_x_from_value (a_this, value, - DIR_RIGHT) ; - break ; - - case PROP_ID_BOTTOM: - status = set_prop_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; - - case PROP_ID_LEFT: - status = set_prop_x_from_value (a_this, value, - DIR_LEFT) ; - break ; - - case PROP_ID_FLOAT: - status = set_prop_float (a_this, value) ; - break ; - - case PROP_ID_WIDTH: - status = set_prop_width (a_this, value) ; - break ; - - case PROP_ID_COLOR: - status = set_prop_color_rgb (a_this, value) ; - break ; - - case PROP_ID_BACKGROUND_COLOR: - status = set_prop_background_color (a_this, value) ; - break ; - - case PROP_ID_FONT_FAMILY: - status = - set_prop_font_family_from_value (a_this, value) ; - break ; - - case PROP_ID_FONT_SIZE: - status = - set_prop_font_size_from_value (a_this, value) ; - break ; - - case PROP_ID_FONT_STYLE: - status = - set_prop_font_style_from_value (a_this, value) ; - break ; - - case PROP_ID_FONT_WEIGHT: - status = - set_prop_font_weight_from_value (a_this, value) ; - break ; - - default: - return CR_UNKNOWN_TYPE_ERROR ; - - } - - return status ; -} - -/** - *Increases the reference count - *of the current instance of #CRStyle. - *@param a_this the current instance of #CRStyle. - *@return CR_OK upon successfull completion, an error code - *otherwise. - */ -enum CRStatus -cr_style_ref (CRStyle *a_this) -{ - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - a_this->ref_count ++ ; - return CR_OK ; -} - - -/** - *Decreases the reference count of - *the current instance of #CRStyle. - *If the reference count reaches 0, the - *instance of #CRStyle is destoyed. - *@param a_this the current instance of #CRStyle. - *@return TRUE if the instance has been destroyed, FALSE - *otherwise. - */ -gboolean -cr_style_unref (CRStyle *a_this) -{ - g_return_val_if_fail (a_this, - FALSE) ; - - if (a_this->ref_count) - a_this->ref_count -- ; - - if (!a_this->ref_count) - { - cr_style_destroy (a_this) ; - return TRUE ; - } - - return FALSE ; -} - -/** - *Duplicates the current instance of #CRStyle . - *The newly created instance of #CRStyle must be - *freed using cr_style_destroy (). - *@param a_this the current instance of #CRStyle. - *@return the newly duplicated instance of #CRStyle. - */ -CRStyle * -cr_style_dup (CRStyle *a_this) -{ - CRStyle *result = NULL ; - - g_return_val_if_fail (a_this, NULL) ; - - result = cr_style_new () ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memcpy (result, a_this, sizeof (CRStyle)) ; - - return result ; -} - - -/** - *Destructor of the #CRStyle class. - *@param a_this the instance to destroy. - */ -void -cr_style_destroy (CRStyle *a_this) -{ - g_return_if_fail (a_this) ; - - g_free (a_this) ; -} diff --git a/src/seleng/cr-style.h b/src/seleng/cr-style.h deleted file mode 100644 index 2348c76..0000000 --- a/src/seleng/cr-style.h +++ /dev/null @@ -1,284 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */ - -/* - * This file is part of The Croco Library - * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program 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 Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef __CR_STYLE_H__ -#define __CR_STYLE_H__ - -#include "cr-utils.h" -#include "cr-statement.h" -#include "cr-fonts.h" - -/** - *@file - *The declaration of the #CRStyle class. - */ -G_BEGIN_DECLS - -typedef struct _CRStyle CRStyle ; - -enum CRBorderStyle -{ - BORDER_STYLE_NONE = 0, - BORDER_STYLE_HIDDEN, - BORDER_STYLE_DOTTED, - BORDER_STYLE_DASHED, - BORDER_STYLE_SOLID, - BORDER_STYLE_DOUBLE, - BORDER_STYLE_GROOVE, - BORDER_STYLE_RIDGE, - BORDER_STYLE_INSET, - BORDER_STYLE_OUTSET -} ; - -enum CRDisplayType -{ - DISPLAY_NONE, - DISPLAY_INLINE, - DISPLAY_BLOCK, - DISPLAY_LIST_ITEM, - DISPLAY_RUN_IN, - DISPLAY_COMPACT, - DISPLAY_MARKER, - DISPLAY_TABLE, - DISPLAY_INLINE_TABLE, - DISPLAY_TABLE_ROW_GROUP, - DISPLAY_TABLE_HEADER_GROUP, - DISPLAY_TABLE_FOOTER_GROUP, - DISPLAY_TABLE_ROW, - DISPLAY_TABLE_COLUMN_GROUP, - DISPLAY_TABLE_COLUMN, - DISPLAY_TABLE_CELL, - DISPLAY_TABLE_CAPTION, - DISPLAY_INHERIT -} ; - -enum CRPositionType -{ - POSITION_STATIC, - POSITION_RELATIVE, - POSITION_ABSOLUTE, - POSITION_FIXED, - POSITION_INHERIT, -} ; - -enum CRFloatType -{ - FLOAT_NONE, - FLOAT_LEFT, - FLOAT_RIGHT, - FLOAT_INHERIT -} ; - - -#define BORDER_THIN 2 -#define BORDER_MEDIUM 4 -#define BORDER_THICK 6 - - -/** - *A numerical css property value. - *This data type is actually split in 3 parts: - *1/the specified value - *2/the computed value - *3/the actual value. - *To understand the semantic of these three parts, - *see css2 spec chap 6.1 ("Specified, computed and actual values."). - */ -typedef struct _CRNumPropVal CRNumPropVal ; -struct _CRNumPropVal -{ - /**specified value*/ - CRNum sv ; - /**computed value*/ - CRNum cv ; - /**actual value*/ - CRNum av ; -} ; - -/** - *An rgb css property value. - *This data type is actually split in 3 parts: - *1/the specified value - *2/the computed value - *3/the actual value. - *To understand the semantic of these three parts, - *see css2 spec chap 6.1 ("Specified, computed and actual values."). - */ -typedef struct _CRRgbPropVal CRRgbPropVal ; -struct _CRRgbPropVal -{ - /**specified value*/ - CRRgb sv ; - /**computed value*/ - CRRgb cv ; - /**actual value*/ - CRRgb av ; -} ; - - -enum CRNumProp -{ - NUM_PROP_TOP=0, - NUM_PROP_RIGHT, - NUM_PROP_BOTTOM, - NUM_PROP_LEFT,/*3*/ - - NUM_PROP_PADDING_TOP, - NUM_PROP_PADDING_RIGHT, - NUM_PROP_PADDING_BOTTOM, - NUM_PROP_PADDING_LEFT,/*7*/ - - NUM_PROP_BORDER_TOP, - NUM_PROP_BORDER_RIGHT, - NUM_PROP_BORDER_BOTTOM, - NUM_PROP_BORDER_LEFT,/*11*/ - - NUM_PROP_MARGIN_TOP, - NUM_PROP_MARGIN_RIGHT, - NUM_PROP_MARGIN_BOTTOM, - NUM_PROP_MARGIN_LEFT,/*15*/ - - NUM_PROP_WIDTH, - - /*must be last*/ - NB_NUM_PROPS -} ; - -enum CRRgbProp -{ - RGB_PROP_BORDER_TOP_COLOR = 0, - RGB_PROP_BORDER_RIGHT_COLOR, - RGB_PROP_BORDER_BOTTOM_COLOR, - RGB_PROP_BORDER_LEFT_COLOR, - RGB_PROP_COLOR, - RGB_PROP_BACKGROUND_COLOR, - - /*must be last*/ - NB_RGB_PROPS -} ; - - -enum CRBorderStyleProp -{ - BORDER_STYLE_PROP_TOP = 0, - BORDER_STYLE_PROP_RIGHT, - BORDER_STYLE_PROP_BOTTOM, - BORDER_STYLE_PROP_LEFT, - - /*must be last*/ - NB_BORDER_STYLE_PROPS -} ; - -enum CRBoxOffsetProp -{ - BOX_OFFSET_PROP_TOP = 0, - BOX_OFFSET_PROP_RIGHT, - BOX_OFFSET_PROP_BOTTOM, - BOX_OFFSET_PROP_LEFT, - - /*must be last*/ - NB_BOX_OFFSET_PROPS -} ; - - - - -/** - *The css2 style class. - *Contains computed and actual values - *of inferred from the declarations found - *in the stylesheets. - *See css2 spec chapter 6. - */ -struct _CRStyle -{ - /** - *numerical properties. - *the properties are indexed by - *enum #CRNumProp. - */ - CRNumPropVal num_props[NB_NUM_PROPS] ; - - /** - *color properties. - *They are indexed by enum #CRRgbProp . - */ - CRRgbPropVal rgb_props[NB_RGB_PROPS] ; - - /** - *border style properties. - *They are indexed by enum #CRBorderStyleProp . - */ - enum CRBorderStyle border_style_props[NB_BORDER_STYLE_PROPS] ; - - /**box display type*/ - enum CRDisplayType display ; - - /**the positioning scheme*/ - enum CRPositionType position ; - - /**the float property*/ - enum CRFloatType float_type ; - - /* - *the 'font-family' property. - */ - CRFontFamily *font_family ; - - /** - *the 'font-size' property. - */ - CRFontSize *font_size ; - CRFontSizeAdjust *font_size_adjust ; - enum CRFontStyle font_style ; - enum CRFontVariant font_variant ; - enum CRFontWeight font_weight ; - enum CRFontStretch font_stretch ; - - CRStyle *parent_style ; - gulong ref_count ; -} ; - - -CRStyle * -cr_style_new (void) ; - - -enum CRStatus -cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) ; - - -enum CRStatus -cr_style_ref (CRStyle *a_this) ; - -gboolean -cr_style_unref (CRStyle *a_this) ; - -void -cr_style_destroy (CRStyle *a_this) ; - -CRStyle * -cr_style_dup (CRStyle *a_this) ; - -G_END_DECLS - -#endif /*__CR_STYLE_H__*/ |