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.com>
  6.  */
  7.  
  8. #include <stdlib.h>
  9.  
  10. #include <dom/html/html_body_element.h>
  11.  
  12. #include "html/html_body_element.h"
  13. #include "html/html_document.h"
  14.  
  15. #include "core/node.h"
  16. #include "utils/utils.h"
  17.  
  18. static struct dom_element_protected_vtable _protect_vtable = {
  19.         {
  20.                 DOM_NODE_PROTECT_VTABLE_HTML_BODY_ELEMENT
  21.         },
  22.         DOM_HTML_BODY_ELEMENT_PROTECT_VTABLE
  23. };
  24.  
  25. /**
  26.  * Create a dom_html_body_element object
  27.  *
  28.  * \param doc  The document object
  29.  * \param ele  The returned element object
  30.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  31.  */
  32. dom_exception _dom_html_body_element_create(struct dom_html_document *doc,
  33.                 dom_string *namespace, dom_string *prefix,                            
  34.                 struct dom_html_body_element **ele)
  35. {
  36.         struct dom_node_internal *node;
  37.  
  38.         *ele = malloc(sizeof(dom_html_body_element));
  39.         if (*ele == NULL)
  40.                 return DOM_NO_MEM_ERR;
  41.        
  42.         /* Set up vtables */
  43.         node = (struct dom_node_internal *) *ele;
  44.         node->base.vtable = &_dom_html_element_vtable;
  45.         node->vtable = &_protect_vtable;
  46.  
  47.         return _dom_html_body_element_initialise(doc, namespace, prefix, *ele);
  48. }
  49.  
  50. /**
  51.  * Initialise a dom_html_body_element object
  52.  *
  53.  * \param doc  The document object
  54.  * \param ele  The dom_html_body_element object
  55.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  56.  */
  57. dom_exception _dom_html_body_element_initialise(struct dom_html_document *doc,
  58.                 dom_string *namespace, dom_string *prefix,                            
  59.                 struct dom_html_body_element *ele)
  60. {
  61.         return _dom_html_element_initialise(doc, &ele->base,
  62.                         doc->memoised[hds_BODY], namespace, prefix);
  63. }
  64.  
  65. /**
  66.  * Finalise a dom_html_body_element object
  67.  *
  68.  * \param ele  The dom_html_body_element object
  69.  */
  70. void _dom_html_body_element_finalise(struct dom_html_body_element *ele)
  71. {
  72.         _dom_html_element_finalise(&ele->base);
  73. }
  74.  
  75. /**
  76.  * Destroy a dom_html_body_element object
  77.  *
  78.  * \param ele  The dom_html_body_element object
  79.  */
  80. void _dom_html_body_element_destroy(struct dom_html_body_element *ele)
  81. {
  82.         _dom_html_body_element_finalise(ele);
  83.         free(ele);
  84. }
  85.  
  86. /*------------------------------------------------------------------------*/
  87. /* The protected virtual functions */
  88.  
  89. /* The virtual function used to parse attribute value, see src/core/element.c
  90.  * for detail */
  91. dom_exception _dom_html_body_element_parse_attribute(dom_element *ele,
  92.                 dom_string *name, dom_string *value,
  93.                 dom_string **parsed)
  94. {
  95.         UNUSED(ele);
  96.         UNUSED(name);
  97.  
  98.         dom_string_ref(value);
  99.         *parsed = value;
  100.  
  101.         return DOM_NO_ERR;
  102. }
  103.  
  104. /* The virtual destroy function, see src/core/node.c for detail */
  105. void _dom_virtual_html_body_element_destroy(dom_node_internal *node)
  106. {
  107.         _dom_html_body_element_destroy((struct dom_html_body_element *) node);
  108. }
  109.  
  110. /* The virtual copy function, see src/core/node.c for detail */
  111. dom_exception _dom_html_body_element_copy(dom_node_internal *old,
  112.                 dom_node_internal **copy)
  113. {
  114.         return _dom_html_element_copy(old, copy);
  115. }
  116.  
  117. /*-----------------------------------------------------------------------*/
  118. /* API functions */
  119.  
  120. #define SIMPLE_GET(attr)                                                \
  121.         dom_exception dom_html_body_element_get_##attr(         \
  122.                 dom_html_body_element *element,                 \
  123.                 dom_string **attr)                                      \
  124.         {                                                               \
  125.                 dom_exception ret;                                      \
  126.                 dom_string *_memo_##attr;                               \
  127.                                                                         \
  128.                 _memo_##attr =                                          \
  129.                         ((struct dom_html_document *)                   \
  130.                          ((struct dom_node_internal *)element)->owner)->\
  131.                         memoised[hds_##attr];                           \
  132.                                                                         \
  133.                 ret = dom_element_get_attribute(element, _memo_##attr, attr); \
  134.                                                                         \
  135.                 return ret;                                             \
  136.         }
  137. #define SIMPLE_SET(attr)                                                \
  138. dom_exception dom_html_body_element_set_##attr(                 \
  139.                 dom_html_body_element *element,                 \
  140.                 dom_string *attr)                                       \
  141.         {                                                               \
  142.                 dom_exception ret;                                      \
  143.                 dom_string *_memo_##attr;                               \
  144.                                                                         \
  145.                 _memo_##attr =                                          \
  146.                         ((struct dom_html_document *)                   \
  147.                          ((struct dom_node_internal *)element)->owner)->\
  148.                         memoised[hds_##attr];                           \
  149.                                                                         \
  150.                 ret = dom_element_set_attribute(element, _memo_##attr, attr); \
  151.                                                                         \
  152.                 return ret;                                             \
  153.         }
  154.  
  155. #define SIMPLE_GET_SET(attr) SIMPLE_GET(attr) SIMPLE_SET(attr)
  156.  
  157. SIMPLE_GET_SET(a_link)
  158. SIMPLE_GET_SET(background)
  159. SIMPLE_GET_SET(bg_color)
  160. SIMPLE_GET_SET(link)
  161. SIMPLE_GET_SET(text)
  162. SIMPLE_GET_SET(v_link)
  163.