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 2012 Daniel Silverstone <dsilvers@netsurf-browser.org>
  6.  */
  7.  
  8. #include <assert.h>
  9. #include <stdlib.h>
  10.  
  11. #include <dom/html/html_opt_group_element.h>
  12.  
  13. #include "html/html_document.h"
  14. #include "html/html_opt_group_element.h"
  15.  
  16. #include "core/node.h"
  17. #include "core/attr.h"
  18. #include "utils/utils.h"
  19.  
  20. static struct dom_element_protected_vtable _protect_vtable = {
  21.         {
  22.                 DOM_NODE_PROTECT_VTABLE_HTML_OPT_GROUP_ELEMENT
  23.         },
  24.         DOM_HTML_OPT_GROUP_ELEMENT_PROTECT_VTABLE
  25. };
  26.  
  27. /**
  28.  * Create a dom_html_opt_group_element object
  29.  *
  30.  * \param doc  The document object
  31.  * \param ele  The returned element object
  32.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  33.  */
  34. dom_exception _dom_html_opt_group_element_create(struct dom_html_document *doc,
  35.                 dom_string *namespace, dom_string *prefix,
  36.                 struct dom_html_opt_group_element **ele)
  37. {
  38.         struct dom_node_internal *node;
  39.  
  40.         *ele = malloc(sizeof(dom_html_opt_group_element));
  41.         if (*ele == NULL)
  42.                 return DOM_NO_MEM_ERR;
  43.  
  44.         /* Set up vtables */
  45.         node = (struct dom_node_internal *) *ele;
  46.         node->base.vtable = &_dom_html_element_vtable;
  47.         node->vtable = &_protect_vtable;
  48.  
  49.         return _dom_html_opt_group_element_initialise(doc, namespace, prefix, *ele);
  50. }
  51.  
  52. /**
  53.  * Initialise a dom_html_opt_group_element object
  54.  *
  55.  * \param doc  The document object
  56.  * \param ele  The dom_html_opt_group_element object
  57.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  58.  */
  59. dom_exception _dom_html_opt_group_element_initialise(struct dom_html_document *doc,
  60.                 dom_string *namespace, dom_string *prefix,
  61.                 struct dom_html_opt_group_element *ele)
  62. {
  63.         return _dom_html_element_initialise(doc, &ele->base,
  64.                                             doc->memoised[hds_OPTGROUP],
  65.                                             namespace, prefix);
  66. }
  67.  
  68. /**
  69.  * Finalise a dom_html_opt_group_element object
  70.  *
  71.  * \param ele  The dom_html_opt_group_element object
  72.  */
  73. void _dom_html_opt_group_element_finalise(struct dom_html_opt_group_element *ele)
  74. {
  75.         _dom_html_element_finalise(&ele->base);
  76. }
  77.  
  78. /**
  79.  * Destroy a dom_html_opt_group_element object
  80.  *
  81.  * \param ele  The dom_html_opt_group_element object
  82.  */
  83. void _dom_html_opt_group_element_destroy(struct dom_html_opt_group_element *ele)
  84. {
  85.         _dom_html_opt_group_element_finalise(ele);
  86.         free(ele);
  87. }
  88.  
  89. /*-----------------------------------------------------------------------*/
  90. /* Public APIs */
  91.  
  92. /**
  93.  * Get the disabled property
  94.  *
  95.  * \param ele       The dom_html_opt_group_element object
  96.  * \param disabled  The returned status
  97.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  98.  */
  99. dom_exception dom_html_opt_group_element_get_disabled(dom_html_opt_group_element *ele,
  100.                 bool *disabled)
  101. {
  102.         return dom_html_element_get_bool_property(&ele->base, "disabled",
  103.                         SLEN("disabled"), disabled);
  104. }
  105.  
  106. /**
  107.  * Set the disabled property
  108.  *
  109.  * \param ele       The dom_html_opt_group_element object
  110.  * \param disabled  The status
  111.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  112.  */
  113. dom_exception dom_html_opt_group_element_set_disabled(dom_html_opt_group_element *ele,
  114.                 bool disabled)
  115. {
  116.         return dom_html_element_set_bool_property(&ele->base, "disabled",
  117.                         SLEN("disabled"), disabled);
  118. }
  119.  
  120. /*------------------------------------------------------------------------*/
  121. /* The protected virtual functions */
  122.  
  123. /* The virtual function used to parse attribute value, see src/core/element.c
  124.  * for detail */
  125. dom_exception _dom_html_opt_group_element_parse_attribute(dom_element *ele,
  126.                 dom_string *name, dom_string *value,
  127.                 dom_string **parsed)
  128. {
  129.         UNUSED(ele);
  130.         UNUSED(name);
  131.  
  132.         dom_string_ref(value);
  133.         *parsed = value;
  134.  
  135.         return DOM_NO_ERR;
  136. }
  137.  
  138. /* The virtual destroy function, see src/core/node.c for detail */
  139. void _dom_virtual_html_opt_group_element_destroy(dom_node_internal *node)
  140. {
  141.         _dom_html_opt_group_element_destroy((struct dom_html_opt_group_element *) node);
  142. }
  143.  
  144. /* The virtual copy function, see src/core/node.c for detail */
  145. dom_exception _dom_html_opt_group_element_copy(dom_node_internal *old,
  146.                 dom_node_internal **copy)
  147. {
  148.         return _dom_html_element_copy(old, copy);
  149. }
  150.  
  151. /*-----------------------------------------------------------------------*/
  152. /* API functions */
  153.  
  154. #define SIMPLE_GET(attr)                                                \
  155.         dom_exception dom_html_opt_group_element_get_##attr(            \
  156.                 dom_html_opt_group_element *element,                    \
  157.                 dom_string **attr)                                      \
  158.         {                                                               \
  159.                 dom_exception ret;                                      \
  160.                 dom_string *_memo_##attr;                               \
  161.                                                                         \
  162.                 _memo_##attr =                                          \
  163.                         ((struct dom_html_document *)                   \
  164.                          ((struct dom_node_internal *)element)->owner)->\
  165.                         memoised[hds_##attr];                           \
  166.                                                                         \
  167.                 ret = dom_element_get_attribute(element, _memo_##attr, attr); \
  168.                                                                         \
  169.                 return ret;                                             \
  170.         }
  171. #define SIMPLE_SET(attr)                                                \
  172. dom_exception dom_html_opt_group_element_set_##attr(                    \
  173.                 dom_html_opt_group_element *element,                    \
  174.                 dom_string *attr)                                       \
  175.         {                                                               \
  176.                 dom_exception ret;                                      \
  177.                 dom_string *_memo_##attr;                               \
  178.                                                                         \
  179.                 _memo_##attr =                                          \
  180.                         ((struct dom_html_document *)                   \
  181.                          ((struct dom_node_internal *)element)->owner)->\
  182.                         memoised[hds_##attr];                           \
  183.                                                                         \
  184.                 ret = dom_element_set_attribute(element, _memo_##attr, attr); \
  185.                                                                         \
  186.                 return ret;                                             \
  187.         }
  188.  
  189. #define SIMPLE_GET_SET(attr) SIMPLE_GET(attr) SIMPLE_SET(attr)
  190.  
  191. SIMPLE_GET_SET(label);
  192.