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 libdom.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
  6.  */
  7.  
  8. #include <stdlib.h>
  9.  
  10. #include "events/mutation_name_event.h"
  11. #include "core/document.h"
  12.  
  13. #include "utils/utils.h"
  14.  
  15. static void _virtual_dom_mutation_name_event_destroy(struct dom_event *evt);
  16.  
  17. static struct dom_event_private_vtable _event_vtable = {
  18.         _virtual_dom_mutation_name_event_destroy
  19. };
  20.  
  21. /* Constructor */
  22. dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
  23.                 struct dom_mutation_name_event **evt)
  24. {
  25.         *evt = malloc(sizeof(dom_mutation_name_event));
  26.         if (*evt == NULL)
  27.                 return DOM_NO_MEM_ERR;
  28.        
  29.         ((struct dom_event *) *evt)->vtable = &_event_vtable;
  30.  
  31.         return _dom_mutation_name_event_initialise(doc, *evt);
  32. }
  33.  
  34. /* Destructor */
  35. void _dom_mutation_name_event_destroy(struct dom_mutation_name_event *evt)
  36. {
  37.         _dom_mutation_name_event_finalise(evt);
  38.  
  39.         free(evt);
  40. }
  41.  
  42. /* Initialise function */
  43. dom_exception _dom_mutation_name_event_initialise(struct dom_document *doc,
  44.                 struct dom_mutation_name_event *evt)
  45. {
  46.         evt->prev_namespace = NULL;
  47.         evt->prev_nodename = NULL;
  48.  
  49.         return _dom_event_initialise(doc, (dom_event *) evt);
  50. }
  51.  
  52. /* Finalise function */
  53. void _dom_mutation_name_event_finalise(struct dom_mutation_name_event *evt)
  54. {
  55.         dom_string_unref(evt->prev_namespace);
  56.         dom_string_unref(evt->prev_nodename);
  57.  
  58.         _dom_event_finalise((dom_event *) evt);
  59. }
  60.  
  61. /* The virtual destroy function */
  62. void _virtual_dom_mutation_name_event_destroy(struct dom_event *evt)
  63. {
  64.         _dom_mutation_name_event_destroy((dom_mutation_name_event *) evt);
  65. }
  66.  
  67. /*----------------------------------------------------------------------*/
  68. /* The public API */
  69.  
  70. /**
  71.  * Get the previous namespace
  72.  *
  73.  * \param evt        The Event object
  74.  * \param namespace  The previous namespace of this event
  75.  * \return DOM_NO_ERR.
  76.  */
  77. dom_exception _dom_mutation_name_event_get_prev_namespace(
  78.                 dom_mutation_name_event *evt, dom_string **namespace)
  79. {
  80.         *namespace = evt->prev_namespace;
  81.         dom_string_ref(*namespace);
  82.  
  83.         return DOM_NO_ERR;
  84. }
  85.  
  86. /**
  87.  * Get the previous node name
  88.  *
  89.  * \param evt   The Event object
  90.  * \param name  The previous node name
  91.  * \return DOM_NO_ERR.
  92.  */
  93. dom_exception _dom_mutation_name_event_get_prev_node_name(
  94.                 dom_mutation_name_event *evt, dom_string **name)
  95. {
  96.         *name = evt->prev_nodename;
  97.         dom_string_ref(*name);
  98.  
  99.         return DOM_NO_ERR;
  100. }
  101.  
  102. /**
  103.  * Initialise the MutationNameEvent
  104.  *
  105.  * \param evt         The Event object
  106.  * \param type        The type of this UIEvent
  107.  * \param bubble      Whether this event can bubble
  108.  * \param cancelable  Whether this event is cancelable
  109.  * \param node        The node whose name change
  110.  * \param prev_ns     The old namespace
  111.  * \param prev_name   The old name
  112.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  113.  */
  114. dom_exception _dom_mutation_name_event_init(dom_mutation_name_event *evt,
  115.                 dom_string *type, bool bubble, bool cancelable,
  116.                 struct dom_node *node, dom_string *prev_ns,
  117.                 dom_string *prev_name)
  118. {
  119.         evt->prev_namespace = prev_ns;
  120.         dom_string_ref(prev_ns);
  121.  
  122.         evt->prev_nodename = prev_name;
  123.         dom_string_ref(prev_name);
  124.  
  125.         return _dom_mutation_event_init((dom_mutation_event *) evt, type,
  126.                         bubble, cancelable, node, NULL, NULL, NULL,
  127.                         DOM_MUTATION_MODIFICATION);
  128. }
  129.  
  130. /**
  131.  * Initialise the MutationNameEvent with namespace
  132.  *
  133.  * \param evt         The Event object
  134.  * \param namespace   The namespace
  135.  * \param type        The type of this UIEvent
  136.  * \param bubble      Whether this event can bubble
  137.  * \param cancelable  Whether this event is cancelable
  138.  * \param node        The node whose name change
  139.  * \param prev_ns     The old namespace
  140.  * \param prev_name   The old name
  141.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  142.  */
  143. dom_exception _dom_mutation_name_event_init_ns(dom_mutation_name_event *evt,
  144.                 dom_string *namespace, dom_string *type,
  145.                 bool bubble, bool cancelable, struct dom_node *node,
  146.                 dom_string *prev_ns, dom_string *prev_name)
  147. {
  148.         evt->prev_namespace = prev_ns;
  149.         dom_string_ref(prev_ns);
  150.  
  151.         evt->prev_nodename = prev_name;
  152.         dom_string_ref(prev_name);
  153.  
  154.         return _dom_mutation_event_init_ns((dom_mutation_event *) evt,
  155.                         namespace, type, bubble, cancelable, node, NULL,
  156.                         NULL, NULL, DOM_MUTATION_MODIFICATION);
  157. }
  158.  
  159.