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 <assert.h>
  9. #include <stdlib.h>
  10.  
  11. #include "html/html_document.h"
  12. #include "html/html_link_element.h"
  13.  
  14. #include "core/node.h"
  15. #include "core/attr.h"
  16. #include "utils/utils.h"
  17.  
  18. static struct dom_element_protected_vtable _protect_vtable = {
  19.         {
  20.                 DOM_NODE_PROTECT_VTABLE_HTML_LINK_ELEMENT
  21.         },
  22.         DOM_HTML_LINK_ELEMENT_PROTECT_VTABLE
  23. };
  24.  
  25. /**
  26.  * Create a dom_html_link_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_link_element_create(struct dom_html_document *doc,
  33.                 dom_string *namespace, dom_string *prefix,
  34.                 struct dom_html_link_element **ele)
  35. {
  36.         struct dom_node_internal *node;
  37.  
  38.         *ele = malloc(sizeof(dom_html_link_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_link_element_initialise(doc, namespace, prefix, *ele);
  48. }
  49.  
  50. /**
  51.  * Initialise a dom_html_link_element object
  52.  *
  53.  * \param doc  The document object
  54.  * \param ele  The dom_html_link_element object
  55.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  56.  */
  57. dom_exception _dom_html_link_element_initialise(struct dom_html_document *doc,
  58.                 dom_string *namespace, dom_string *prefix,
  59.                 struct dom_html_link_element *ele)
  60. {
  61.         return _dom_html_element_initialise(doc, &ele->base,
  62.                                             doc->memoised[hds_LINK],
  63.                                             namespace, prefix);
  64. }
  65.  
  66. /**
  67.  * Finalise a dom_html_link_element object
  68.  *
  69.  * \param ele  The dom_html_link_element object
  70.  */
  71. void _dom_html_link_element_finalise(struct dom_html_link_element *ele)
  72. {
  73.         _dom_html_element_finalise(&ele->base);
  74. }
  75.  
  76. /**
  77.  * Destroy a dom_html_link_element object
  78.  *
  79.  * \param ele  The dom_html_link_element object
  80.  */
  81. void _dom_html_link_element_destroy(struct dom_html_link_element *ele)
  82. {
  83.         _dom_html_link_element_finalise(ele);
  84.         free(ele);
  85. }
  86.  
  87. /*-----------------------------------------------------------------------*/
  88. /* Public APIs */
  89.  
  90. /**
  91.  * Get the disabled property
  92.  *
  93.  * \param ele       The dom_html_link_element object
  94.  * \param disabled  The returned status
  95.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  96.  */
  97. dom_exception dom_html_link_element_get_disabled(dom_html_link_element *ele,
  98.                 bool *disabled)
  99. {
  100.         return dom_html_element_get_bool_property(&ele->base, "disabled",
  101.                         SLEN("disabled"), disabled);
  102. }
  103.  
  104. /**
  105.  * Set the disabled property
  106.  *
  107.  * \param ele       The dom_html_link_element object
  108.  * \param disabled  The status
  109.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  110.  */
  111. dom_exception dom_html_link_element_set_disabled(dom_html_link_element *ele,
  112.                 bool disabled)
  113. {
  114.         return dom_html_element_set_bool_property(&ele->base, "disabled",
  115.                         SLEN("disabled"), disabled);
  116. }
  117.  
  118. /*------------------------------------------------------------------------*/
  119. /* The protected virtual functions */
  120.  
  121. /* The virtual function used to parse attribute value, see src/core/element.c
  122.  * for detail */
  123. dom_exception _dom_html_link_element_parse_attribute(dom_element *ele,
  124.                 dom_string *name, dom_string *value,
  125.                 dom_string **parsed)
  126. {
  127.         UNUSED(ele);
  128.         UNUSED(name);
  129.  
  130.         dom_string_ref(value);
  131.         *parsed = value;
  132.  
  133.         return DOM_NO_ERR;
  134. }
  135.  
  136. /* The virtual destroy function, see src/core/node.c for detail */
  137. void _dom_virtual_html_link_element_destroy(dom_node_internal *node)
  138. {
  139.         _dom_html_link_element_destroy((struct dom_html_link_element *) node);
  140. }
  141.  
  142. /* The virtual copy function, see src/core/node.c for detail */
  143. dom_exception _dom_html_link_element_copy(dom_node_internal *old,
  144.                 dom_node_internal **copy)
  145. {
  146.         return _dom_html_element_copy(old, copy);
  147. }
  148.  
  149. /*-----------------------------------------------------------------------*/
  150. /* API functions */
  151.  
  152. #define SIMPLE_GET_SET(attr)                                            \
  153.         dom_exception dom_html_link_element_get_##attr(                 \
  154.                 dom_html_link_element *element,                         \
  155.                 dom_string **attr)                                      \
  156.         {                                                               \
  157.                 dom_exception ret;                                      \
  158.                 dom_string *_memo_##attr;                               \
  159.                                                                         \
  160.                 _memo_##attr =                                          \
  161.                         ((struct dom_html_document *)                   \
  162.                          ((struct dom_node_internal *)element)->owner)->\
  163.                         memoised[hds_##attr];                           \
  164.                                                                         \
  165.                 ret = dom_element_get_attribute(element, _memo_##attr, attr); \
  166.                                                                         \
  167.                 return ret;                                             \
  168.         }                                                               \
  169.                                                                         \
  170.         dom_exception dom_html_link_element_set_##attr(                 \
  171.                 dom_html_link_element *element,                         \
  172.                 dom_string *attr)                                       \
  173.         {                                                               \
  174.                 dom_exception ret;                                      \
  175.                 dom_string *_memo_##attr;                               \
  176.                                                                         \
  177.                 _memo_##attr =                                          \
  178.                         ((struct dom_html_document *)                   \
  179.                          ((struct dom_node_internal *)element)->owner)->\
  180.                         memoised[hds_##attr];                           \
  181.                                                                         \
  182.                 ret = dom_element_set_attribute(element, _memo_##attr, attr); \
  183.                                                                         \
  184.                 return ret;                                             \
  185.         }
  186.  
  187. SIMPLE_GET_SET(charset)
  188. SIMPLE_GET_SET(href)
  189. SIMPLE_GET_SET(hreflang)
  190. SIMPLE_GET_SET(media)
  191. SIMPLE_GET_SET(rel)
  192. SIMPLE_GET_SET(rev)
  193. SIMPLE_GET_SET(target)
  194. SIMPLE_GET_SET(type)
  195.