Subversion Repositories Kolibri OS

Rev

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

  1. Hubbub treebuilding interface
  2. =============================
  3.  
  4. Introduction
  5. ------------
  6.  
  7.   hubbub uses an interface to build a tree.  this is what the functions should
  8.   do.
  9.  
  10. Types
  11. -----
  12.  
  13.   hubbub_string
  14.   -------------
  15.  
  16.  
  17. Reference counting
  18. ------------------
  19.  
  20.   The callback interface provides hooks to allow tree nodes to be reference
  21.   counted.  There is, however, no requirement that the client actually performs
  22.   reference counting.  It is perfectly acceptable to use some other object use
  23.   tracking scheme (e.g. garbage collection).  The descriptions below describe
  24.   the expected reference counting behaviour, regardless.
  25.  
  26.  
  27. Callback behaviour
  28. ------------------
  29.  
  30.   The first parameter to all callbacks is the context passed to the library
  31.   on initialisation.
  32.  
  33.   All node creation functions should return 0 on success, and something else
  34.   on failure.
  35.  
  36.  
  37.   Node creation
  38.   -------------
  39.  
  40.   | int hubbub_tree_create_comment(void *ctx,
  41.   |                                const hubbub_string *data,
  42.   |                                void **result);
  43.   |
  44.   | int hubbub_tree_create_doctype(void *ctx,
  45.   |                                const hubbub_doctype *doctype,
  46.   |                                void **result);
  47.   |
  48.   | int hubbub_tree_create_element(void *ctx,
  49.   |                                const hubbub_tag *tag,
  50.   |                                void **result);
  51.   |
  52.   | int hubbub_tree_create_text(void *ctx,
  53.   |                             const hubbub_string *data,
  54.   |                             void **result);
  55.  
  56.   All node creation functions must create a node with the information passed
  57.   in their second argument, and place a pointer to that node in *result.  The
  58.   reference count of the created node must be set to 1.
  59.  
  60.  
  61.   | int hubbub_tree_clone_node(void *ctx,
  62.   |                            void *node,
  63.   |                            bool deep,
  64.   |                            void **result);
  65.  
  66.   If deep == false, then this function must duplicate "node" and none of its
  67.   children, and place a pointer to the clone in *result.  It must also set the
  68.   reference count of the clone to 1.  The clone must be isolated from the
  69.   document tree (it must have no parent or sibling nodes).
  70.  
  71.   If deep == true, then this function must duplicate "node" and all of its
  72.   children.  A pointer to the clone of "node" must be placed in *result.  The
  73.   reference count of the clone must be set to 1.  The reference count of all
  74.   other created nodes must be set to 0. The clone must also be isolated from
  75.   the document tree (it must have no parent or sibling nodes).
  76.  
  77.  
  78.  
  79.   Reference counting
  80.   ------------------
  81.  
  82.   | int hubbub_tree_ref_node(void *ctx, void *node);
  83.   | int hubbub_tree_unref_node(void *ctx, void *node);
  84.  
  85.   These functions should increase and decrease the reference count of "node",
  86.   respectively.  If the reference count of "node" falls to zero, and it is
  87.   isolated from the document tree (it has no parent or sibling nodes), then
  88.   it must be destroyed.
  89.  
  90.  
  91.  
  92.   Tree manipulation
  93.   -----------------
  94.  
  95.   | int hubbub_tree_append_child(void *ctx,
  96.   |                              void *parent,
  97.   |                              void *child,
  98.   |                              void **result);
  99.  
  100.   This function must append the node "child" to the end of the list of children
  101.   of the node "parent", and place a pointer to the newly-inserted node in
  102.   *result.
  103.  
  104.   If the node "child" is a text node, and the last child node of "parent" is
  105.   also a text node, then instead the text of "child" must be appended to that
  106.   node, and a pointer to the node thus appended to must be placed in *result.
  107.  
  108.   In any case, the reference count of the node pointed to by *result at the end
  109.   of these steps must be incremented.
  110.  
  111.  
  112.   | int hubbub_tree_insert_before(void *ctx,
  113.   |                               void *parent,
  114.   |                               void *child,
  115.   |                               void *ref_child,
  116.   |                               void **result);
  117.  
  118.   This function must insert the node "child" into the list of children of
  119.   "parent" immediately before the node "ref_child", and place a pointer to the
  120.   newly-inserted node in *result.
  121.  
  122.   If the node "child" is a text node, and the node "ref_child" or the node
  123.   before "ref_child" is also a text node, then instead the text of "child" must
  124.   be prepended to the text of "ref_child", or appended to the text of node
  125.   before "ref_node", and a pointer to the node thus appended to must be placed
  126.   in *result.
  127.  
  128.   In any case, the reference count of the node pointed to by *result at the end
  129.   of these steps must be incremented.
  130.  
  131.  
  132.   | int hubbub_tree_remove_child(void *ctx,
  133.   |                              void *parent,
  134.   |                              void *child,
  135.   |                              void **result);
  136.  
  137.   This function must remove the node "child" from the document tree.  It must
  138.   increment the reference count of the node "child", and place a pointer to
  139.   the newly-removed node in *result.
  140.  
  141.  
  142.   | int hubbub_tree_reparent_children(void *ctx,
  143.   |                                   void *node,
  144.   |                                   void *new_parent);
  145.  
  146.   This function must detach all children from "node" and insert them into
  147.   "new_parent" in the same order as they were found in "node".
  148.  
  149.   | int hubbub_tree_get_parent(void *ctx,
  150.   |                            void *node,
  151.   |                            bool element_only,
  152.   |                            void **result);
  153.  
  154.   This function must retrieve the parent of "node".  If there is no parent
  155.   node, then NULL must be placed in *result.  Otherwise, it must increment
  156.   the reference count of the parent, and place a pointer to the parent in
  157.   *result.
  158.  
  159.   If "element_only" == true and the retrieved parent is not an element node,
  160.   then act as if no parent exists.
  161.  
  162.   | int hubbub_tree_has_children(void *ctx,
  163.   |                              void *node,
  164.   |                              bool *result);
  165.  
  166.   If "node" has any child nodes attached to it, then *result must be set to
  167.   true.  Otherwise, *result must be set to false.  
  168.  
  169.   | int hubbub_tree_form_associate(void *ctx,
  170.   |                                void *form,
  171.   |                                void *node);
  172.  
  173.   This function must associate "node" with the node "form" (which is the
  174.   currently active form element).
  175.  
  176.   | int hubbub_tree_add_attributes(void *ctx,
  177.   |                                void *node,
  178.   |                                const hubbub_attribute *attributes,
  179.   |                                uint32_t n_attributes);
  180.  
  181.   For each attribute in the array "attributes", this function must check to
  182.   see if there is such an attribute already present on "node".  If there is
  183.   not such an attribute, then the attribute must be added to "node".
  184.  
  185.   | int hubbub_tree_set_quirks_mode(void *ctx,
  186.   |                                 hubbub_quirks_mode mode);
  187.  
  188.   This function must set the quirks mode flag of the document to "mode".
  189.  
  190.   | int hubbub_tree_encoding_change(void *ctx,
  191.   |                                 const char *name);
  192.  
  193.   This function is called when a meta tag which specifies a charset is seen
  194.   in the treebuilder. [1]  The client is responsible for checking if the
  195.   encoding the document is being processed as should actually be changed, and
  196.   if it should, this function should return 1.  In this case, the parser
  197.   instance will return the error code HUBBUB_ENCODINGCHANGE when it returns
  198.   from parsing the chunk that triggered the encoding change.  The parser
  199.   instance should then be destroyed and a new one created with that encoding
  200.   specified.
  201.  
  202.   [1] http://www.whatwg.org/specs/web-apps/current-work/#in-head
  203.