Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of Hubbub.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
  6.  */
  7.  
  8. #ifndef hubbub_tree_h_
  9. #define hubbub_tree_h_
  10.  
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15.  
  16. #include <hubbub/functypes.h>
  17.  
  18. /**
  19.  * Create a comment node
  20.  *
  21.  * \param ctx     Client's context
  22.  * \param data    String content of node
  23.  * \param result  Pointer to location to receive created node
  24.  * \return HUBBUB_OK on success, appropriate error otherwise.
  25.  *
  26.  * Postcondition: if successful, result's reference count must be 1.
  27.  */
  28. typedef hubbub_error (*hubbub_tree_create_comment)(void *ctx,
  29.                 const hubbub_string *data,
  30.                 void **result);
  31.  
  32. /**
  33.  * Create a doctype node
  34.  *
  35.  * \param ctx      Client's context
  36.  * \param doctype  Data for doctype node (name, public id, system id)
  37.  * \param result   Pointer to location to receive created node
  38.  * \return HUBBUB_OK on success, appropriate error otherwise.
  39.  *
  40.  * Postcondition: if successful, result's reference count must be 1.
  41.  */
  42. typedef hubbub_error (*hubbub_tree_create_doctype)(void *ctx,
  43.                 const hubbub_doctype *doctype,
  44.                 void **result);
  45.  
  46. /**
  47.  * Create an element node
  48.  *
  49.  * \param ctx     Client's context
  50.  * \param tag     Data for element node (namespace, name, attributes)
  51.  * \param result  Pointer to location to receive created node
  52.  * \return HUBBUB_OK on success, appropriate error otherwise.
  53.  *
  54.  * Postcondition: if successful, result's reference count must be 1.
  55.  */
  56. typedef hubbub_error (*hubbub_tree_create_element)(void *ctx,
  57.                 const hubbub_tag *tag,
  58.                 void **result);
  59.  
  60. /**
  61.  * Create a text node
  62.  *
  63.  * \param ctx     Client's context
  64.  * \param data    String content of node
  65.  * \param result  Pointer to location to receive created node
  66.  * \return HUBBUB_OK on success, appropriate error otherwise.
  67.  *
  68.  * Postcondition: if successful, result's reference count must be 1.
  69.  */
  70. typedef hubbub_error (*hubbub_tree_create_text)(void *ctx,
  71.                 const hubbub_string *data,
  72.                 void **result);
  73.  
  74. /**
  75.  * Increase a node's reference count
  76.  *
  77.  * \param ctx   Client's context
  78.  * \param node  Node to reference
  79.  * \return HUBBUB_OK on success, appropriate error otherwise.
  80.  *
  81.  * Postcondition: node's reference count is one larger than before
  82.  */
  83. typedef hubbub_error (*hubbub_tree_ref_node)(void *ctx, void *node);
  84.  
  85. /**
  86.  * Decrease a node's reference count
  87.  *
  88.  * \param ctx   Client's context
  89.  * \param node  Node to reference
  90.  * \return HUBBUB_OK on success, appropriate error otherwise.
  91.  *
  92.  * Postcondition: If the node's reference count becomes zero, and it has no
  93.  * parent, and it is not the document node, then it is destroyed. Otherwise,
  94.  * the reference count is one less than before.
  95.  */
  96. typedef hubbub_error (*hubbub_tree_unref_node)(void *ctx, void *node);
  97.  
  98. /**
  99.  * Append a node to the end of another's child list
  100.  *
  101.  * \param ctx     Client's context
  102.  * \param parent  The node to append to
  103.  * \param child   The node to append
  104.  * \param result  Pointer to location to receive appended node
  105.  * \return HUBBUB_OK on success, appropriate error otherwise.
  106.  *
  107.  * Postcondition: if successful, result's reference count is increased by 1
  108.  *
  109.  * Important: *result may not == child (e.g. if text nodes got coalesced)
  110.  */
  111. typedef hubbub_error (*hubbub_tree_append_child)(void *ctx,
  112.                 void *parent,
  113.                 void *child,
  114.                 void **result);
  115.  
  116. /**
  117.  * Insert a node into another's child list
  118.  *
  119.  * \param ctx        Client's context
  120.  * \param parent     The node to insert into
  121.  * \param child      The node to insert
  122.  * \param ref_child  The node to insert before
  123.  * \param result     Pointer to location to receive inserted node
  124.  * \return HUBBUB_OK on success, appropriate error otherwise.
  125.  *
  126.  * Postcondition: if successful, result's reference count is increased by 1
  127.  *
  128.  * Important: *result may not == child (e.g. if text nodes got coalesced)
  129.  */
  130. typedef hubbub_error (*hubbub_tree_insert_before)(void *ctx,
  131.                 void *parent,
  132.                 void *child,
  133.                 void *ref_child,
  134.                 void **result);
  135.  
  136. /**
  137.  * Remove a node from another's child list
  138.  *
  139.  * \param ctx     Client context
  140.  * \param parent  The node to remove from
  141.  * \param child   The node to remove
  142.  * \param result  Pointer to location to receive removed node
  143.  * \return HUBBUB_OK on success, appropriate error otherwise.
  144.  *
  145.  * Postcondition: if successful, result's reference count is increased by 1
  146.  */
  147. typedef hubbub_error (*hubbub_tree_remove_child)(void *ctx,
  148.                 void *parent,
  149.                 void *child,
  150.                 void **result);
  151.  
  152. /**
  153.  * Clone a node
  154.  *
  155.  * \param ctx     Client's context
  156.  * \param node    The node to clone
  157.  * \param deep    True to clone entire subtree, false to clone only the node
  158.  * \param result  Pointer to location to receive clone
  159.  * \return HUBBUB_OK on success, appropriate error otherwise.
  160.  *
  161.  * Postcondition: if successful, result's reference count must be 1.
  162.  */
  163. typedef hubbub_error (*hubbub_tree_clone_node)(void *ctx,
  164.                 void *node,
  165.                 bool deep,
  166.                 void **result);
  167.  
  168. /**
  169.  * Move all the children of one node to another
  170.  *
  171.  * \param ctx         Client's context
  172.  * \param node        The initial parent node
  173.  * \param new_parent  The new parent node
  174.  * \return HUBBUB_OK on success, appropriate error otherwise.
  175.  */
  176. typedef hubbub_error (*hubbub_tree_reparent_children)(void *ctx,
  177.                 void *node,
  178.                 void *new_parent);
  179.  
  180. /**
  181.  * Retrieve the parent of a node
  182.  *
  183.  * \param ctx           Client context
  184.  * \param node          Node to retrieve the parent of
  185.  * \param element_only  True if the parent must be an element, false otherwise
  186.  * \param result        Pointer to location to receive parent node
  187.  * \return HUBBUB_OK on success, appropriate error otherwise.
  188.  *
  189.  * If there is a parent node, but it is not an element node and element_only
  190.  * is true, then act as if no parent existed.
  191.  *
  192.  * Postcondition: if there is a parent, then result's reference count must be
  193.  * increased.
  194.  */
  195. typedef hubbub_error (*hubbub_tree_get_parent)(void *ctx,
  196.                 void *node,
  197.                 bool element_only,
  198.                 void **result);
  199.  
  200. /**
  201.  * Determine if a node has children
  202.  *
  203.  * \param ctx     Client's context
  204.  * \param node    The node to inspect
  205.  * \param result  Location to receive result
  206.  * \return HUBBUB_OK on success, appropriate error otherwise.
  207.  */
  208. typedef hubbub_error (*hubbub_tree_has_children)(void *ctx,
  209.                 void *node,
  210.                 bool *result);
  211.  
  212. /**
  213.  * Associate a node with a form
  214.  *
  215.  * \param ctx   Client's context
  216.  * \param form  The form to associate with
  217.  * \param node  The node to associate
  218.  * \return HUBBUB_OK on success, appropriate error otherwise.
  219.  */
  220. typedef hubbub_error (*hubbub_tree_form_associate)(void *ctx,
  221.                 void *form,
  222.                 void *node);
  223.  
  224. /**
  225.  * Add attributes to a node
  226.  *
  227.  * \param ctx           Client's context
  228.  * \param node          The node to add to
  229.  * \param attributes    Array of attributes to add
  230.  * \param n_attributes  Number of entries in array
  231.  * \return HUBBUB_OK on success, appropriate error otherwise.
  232.  */
  233. typedef hubbub_error (*hubbub_tree_add_attributes)(void *ctx,
  234.                 void *node,
  235.                 const hubbub_attribute *attributes,
  236.                 uint32_t n_attributes);
  237.  
  238. /**
  239.  * Notification of the quirks mode of a document
  240.  *
  241.  * \param ctx   Client's context
  242.  * \param mode  The quirks mode
  243.  * \return HUBBUB_OK on success, appropriate error otherwise.
  244.  */
  245. typedef hubbub_error (*hubbub_tree_set_quirks_mode)(void *ctx,
  246.                 hubbub_quirks_mode mode);
  247.  
  248. /**
  249.  * Notification that a potential encoding change is required
  250.  *
  251.  * \param ctx      Client's context
  252.  * \param charset  The new charset for the source data
  253.  * \return HUBBUB_OK to continue using the current input handler,
  254.  *         HUBBUB_ENCODINGCHANGE to stop processing immediately and
  255.  *                               return control to the client,
  256.  *         appropriate error otherwise.
  257.  */
  258. typedef hubbub_error (*hubbub_tree_encoding_change)(void *ctx,
  259.                 const char *encname);
  260.  
  261. /**
  262.  * Complete script processing
  263.  *
  264.  * \param ctx   Client's context
  265.  * \param script The script
  266.  * \return HUBBUB_OK on success, appropriate error otherwise.
  267.  */
  268. typedef hubbub_error (*hubbub_tree_complete_script)(void *ctx, void *script);
  269.  
  270. /**
  271.  * Hubbub tree handler
  272.  */
  273. typedef struct hubbub_tree_handler {
  274.         hubbub_tree_create_comment create_comment;      /**< Create comment */
  275.         hubbub_tree_create_doctype create_doctype;      /**< Create doctype */
  276.         hubbub_tree_create_element create_element;      /**< Create element */
  277.         hubbub_tree_create_text create_text;            /**< Create text */
  278.         hubbub_tree_ref_node ref_node;                  /**< Reference node */
  279.         hubbub_tree_unref_node unref_node;              /**< Unreference node */
  280.         hubbub_tree_append_child append_child;          /**< Append child */
  281.         hubbub_tree_insert_before insert_before;        /**< Insert before */
  282.         hubbub_tree_remove_child remove_child;          /**< Remove child */
  283.         hubbub_tree_clone_node clone_node;              /**< Clone node */
  284.         hubbub_tree_reparent_children reparent_children;/**< Reparent children*/
  285.         hubbub_tree_get_parent get_parent;              /**< Get parent */
  286.         hubbub_tree_has_children has_children;          /**< Has children? */
  287.         hubbub_tree_form_associate form_associate;      /**< Form associate */
  288.         hubbub_tree_add_attributes add_attributes;      /**< Add attributes */
  289.         hubbub_tree_set_quirks_mode set_quirks_mode;    /**< Set quirks mode */
  290.         hubbub_tree_encoding_change encoding_change;    /**< Change encoding */
  291.         hubbub_tree_complete_script complete_script;    /**< Script Complete */
  292.         void *ctx;                                      /**< Context pointer */
  293. } hubbub_tree_handler;
  294.  
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298.  
  299. #endif
  300.  
  301.