diff options
author | Dodji Seketeli <dodji@gnome.org> | 2003-12-24 01:41:30 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-12-24 01:41:30 +0000 |
commit | 825fcd6b90e43ae76d520dc18318984417d22acd (patch) | |
tree | 881c9cf3446eaebad6e9537b68e31f41f163b581 | |
parent | 62f9f6ec4e2e536e158d8f6effd821e608d9dac7 (diff) | |
download | libcroco-825fcd6b90e43ae76d520dc18318984417d22acd.tar.gz |
small cosmetic changes. started to work on the support of a pluggable
2003-12-24 Dodji Seketeli <dodji@gnome.org>
* src/parser/cr-additional-sel.h: small cosmetic changes.
* src/seleng/cr-sel-eng.c: started to work on the
support of a pluggable handler for pseudo class selectors
evaluation. Wrote facilities to register/unregister/lookup
the handler.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/parser/cr-additional-sel.h | 52 | ||||
-rw-r--r-- | src/parser/cr-doc-handler.h | 6 | ||||
-rw-r--r-- | src/parser/cr-utils.h | 2 | ||||
-rw-r--r-- | src/seleng/cr-sel-eng.c | 186 | ||||
-rw-r--r-- | src/seleng/cr-sel-eng.h | 20 | ||||
-rw-r--r-- | tests/test7-main.c | 2 |
7 files changed, 220 insertions, 56 deletions
@@ -1,3 +1,11 @@ +2003-12-24 Dodji Seketeli <dodji@gnome.org> + + * src/parser/cr-additional-sel.h: small cosmetic changes. + * src/seleng/cr-sel-eng.c: started to work on the + support of a pluggable handler for pseudo class selectors + evaluation. Wrote facilities to register/unregister/lookup + the handler. + 2003-12-21 Dodji Seketeli <dodji@gnome.org> * docs/design/parser-architecture.txt: fixed some typos. diff --git a/src/parser/cr-additional-sel.h b/src/parser/cr-additional-sel.h index 827d9a5..d55d536 100644 --- a/src/parser/cr-additional-sel.h +++ b/src/parser/cr-additional-sel.h @@ -29,8 +29,8 @@ *This file holds the declaration of the *#CRAddSel class. */ -#ifndef __CR_ADD_SEL_H -#define __CR_ADD_SEL_H +#ifndef __CR_ADD_SEL_H__ +#define __CR_ADD_SEL_H__ #include <stdio.h> #include <glib.h> @@ -77,43 +77,33 @@ struct _CRAdditionalSel CRAdditionalSel * prev ; } ; -CRAdditionalSel * -cr_additional_sel_new (void) ; +CRAdditionalSel * cr_additional_sel_new (void) ; -CRAdditionalSel * -cr_additional_sel_new_with_type -(enum AddSelectorType a_sel_type) ; +CRAdditionalSel * cr_additional_sel_new_with_type (enum AddSelectorType a_sel_type) ; -CRAdditionalSel * -cr_additional_sel_append (CRAdditionalSel *a_this, - CRAdditionalSel *a_sel) ; -void -cr_additional_sel_set_class_name (CRAdditionalSel *a_this, - GString *a_class_name) ; -void -cr_additional_sel_set_id_name (CRAdditionalSel *a_this, - GString *a_id) ; +CRAdditionalSel * cr_additional_sel_append (CRAdditionalSel *a_this, + CRAdditionalSel *a_sel) ; -void -cr_additional_sel_set_pseudo (CRAdditionalSel *a_this, - CRPseudo *a_pseudo) ; +void cr_additional_sel_set_class_name (CRAdditionalSel *a_this, + GString *a_class_name) ; -void -cr_additional_sel_set_attr_sel (CRAdditionalSel *a_this, - CRAttrSel *a_sel) ; +void cr_additional_sel_set_id_name (CRAdditionalSel *a_this, + GString *a_id) ; -CRAdditionalSel * -cr_additional_sel_prepend (CRAdditionalSel *a_this, - CRAdditionalSel *a_sel) ; +void cr_additional_sel_set_pseudo (CRAdditionalSel *a_this, + CRPseudo *a_pseudo) ; -guchar * -cr_additional_sel_to_string (CRAdditionalSel *a_this) ; +void cr_additional_sel_set_attr_sel (CRAdditionalSel *a_this, + CRAttrSel *a_sel) ; -void -cr_additional_sel_dump (CRAdditionalSel *a_this, FILE *a_fp) ; +CRAdditionalSel * cr_additional_sel_prepend (CRAdditionalSel *a_this, + CRAdditionalSel *a_sel) ; -void -cr_additional_sel_destroy (CRAdditionalSel *a_this) ; +guchar * cr_additional_sel_to_string (CRAdditionalSel *a_this) ; + +void cr_additional_sel_dump (CRAdditionalSel *a_this, FILE *a_fp) ; + +void cr_additional_sel_destroy (CRAdditionalSel *a_this) ; G_END_DECLS diff --git a/src/parser/cr-doc-handler.h b/src/parser/cr-doc-handler.h index dde96c8..9fda7bc 100644 --- a/src/parser/cr-doc-handler.h +++ b/src/parser/cr-doc-handler.h @@ -93,9 +93,9 @@ struct _CRDocHandler *of the imported style sheet. */ void (*import_style) (CRDocHandler *a_this, - GList *a_media_list, - GString *a_uri, - GString *a_uri_default_ns) ; + GList *a_media_list, + GString *a_uri, + GString *a_uri_default_ns) ; void (*import_style_result) (CRDocHandler *a_this, GList *a_media_list, diff --git a/src/parser/cr-utils.h b/src/parser/cr-utils.h index 6fb654e..3af7c09 100644 --- a/src/parser/cr-utils.h +++ b/src/parser/cr-utils.h @@ -60,6 +60,8 @@ enum CRStatus { CR_SYNTAX_ERROR, CR_NO_ROOT_NODE_ERROR, CR_NO_TOKEN, + CR_OUT_OF_MEMORY_ERROR, + CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR, CR_ERROR } ; diff --git a/src/seleng/cr-sel-eng.c b/src/seleng/cr-sel-eng.c index 3070aa6..0ec2b6a 100644 --- a/src/seleng/cr-sel-eng.c +++ b/src/seleng/cr-sel-eng.c @@ -3,7 +3,7 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> + * 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 @@ -35,6 +35,32 @@ #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) ; @@ -67,20 +93,14 @@ static void set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, gpointer a_style) ; -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 ; -}; +static gboolean +pseudo_class_add_sel_matches_node (CRSelEng * a_this, + CRAdditionalSel *a_add_sel, + xmlNode *a_node) +{ + return FALSE ; +} /** *@param a_add_sel the class additional selector to consider. @@ -335,7 +355,8 @@ attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, *@return TRUE is a_add_sel matches a_node, FALSE otherwise. */ static gboolean -additional_selector_matches_node (CRAdditionalSel *a_add_sel, +additional_selector_matches_node (CRSelEng *a_this, + CRAdditionalSel *a_add_sel, xmlNode *a_node) { if (!a_add_sel) @@ -385,6 +406,15 @@ additional_selector_matches_node (CRAdditionalSel *a_add_sel, 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 ; } @@ -505,8 +535,9 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, *their xml node counterpart. */ if (cur_sel->add_sel) { - if (additional_selector_matches_node - (cur_sel->add_sel, cur_node) == TRUE) { + if (additional_selector_matches_node + (a_this, cur_sel->add_sel, cur_node) == TRUE) + { goto walk_a_step_in_expr ; } else { goto done ; @@ -528,7 +559,8 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, goto done ; } if (additional_selector_matches_node - (cur_sel->add_sel, cur_node) == TRUE) { + (a_this, cur_sel->add_sel, cur_node) == TRUE) + { goto walk_a_step_in_expr ; } else { goto done ; @@ -946,8 +978,6 @@ put_css_properties_in_hashtable (GHashTable **a_props_hashtable, return CR_OK ; } - - static void set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, gpointer a_style) @@ -960,7 +990,6 @@ set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, cr_style_set_style_from_decl (style, decl) ; } - /**************************************** *PUBLIC METHODS ****************************************/ @@ -995,6 +1024,121 @@ cr_sel_eng_new (void) 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_add_pseudo_class_selector_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_remove_pseudo_class_selector_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 ; +} + +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). diff --git a/src/seleng/cr-sel-eng.h b/src/seleng/cr-sel-eng.h index 7be003a..a19f919 100644 --- a/src/seleng/cr-sel-eng.h +++ b/src/seleng/cr-sel-eng.h @@ -59,10 +59,30 @@ 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_add_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_remove_pseudo_class_selector_handler (CRSelEng *a_this, + guchar *a_pseudo_class_sel_name, + enum CRPseudoType a_pseudo_class_type) ; + +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) ; diff --git a/tests/test7-main.c b/tests/test7-main.c index 4ed3393..4165a53 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -156,7 +156,7 @@ test_layout_box (void) CRBoxView *box_view = NULL ; GtkWidget *window = NULL, *scroll = NULL ; - box_view = cr_box_view_new_from_xml_css_bufs + box_view = cr_box_view_new_from_xml_css_bufs (gv_xmlbuf, gv_cssbuf) ; g_return_val_if_fail (box_view, CR_BAD_PARAM_ERROR) ; |