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_button_element.h>
  12.  
  13. #include "html/html_document.h"
  14. #include "html/html_button_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_BUTTON_ELEMENT
  23.         },
  24.         DOM_HTML_BUTTON_ELEMENT_PROTECT_VTABLE
  25. };
  26.  
  27. /**
  28.  * Create a dom_html_button_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_button_element_create(struct dom_html_document *doc,
  35.                 dom_string *namespace, dom_string *prefix,
  36.                 struct dom_html_button_element **ele)
  37. {
  38.         struct dom_node_internal *node;
  39.  
  40.         *ele = malloc(sizeof(dom_html_button_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_button_element_initialise(doc, namespace, prefix, *ele);
  50. }
  51.  
  52. /**
  53.  * Initialise a dom_html_button_element object
  54.  *
  55.  * \param doc  The document object
  56.  * \param ele  The dom_html_button_element object
  57.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  58.  */
  59. dom_exception _dom_html_button_element_initialise(struct dom_html_document *doc,
  60.                 dom_string *namespace, dom_string *prefix,
  61.                 struct dom_html_button_element *ele)
  62. {
  63.         ele->form = NULL;
  64.  
  65.         return _dom_html_element_initialise(doc, &ele->base,
  66.                                             doc->memoised[hds_BUTTON],
  67.                                             namespace, prefix);
  68. }
  69.  
  70. /**
  71.  * Finalise a dom_html_button_element object
  72.  *
  73.  * \param ele  The dom_html_button_element object
  74.  */
  75. void _dom_html_button_element_finalise(struct dom_html_button_element *ele)
  76. {
  77.         _dom_html_element_finalise(&ele->base);
  78. }
  79.  
  80. /**
  81.  * Destroy a dom_html_button_element object
  82.  *
  83.  * \param ele  The dom_html_button_element object
  84.  */
  85. void _dom_html_button_element_destroy(struct dom_html_button_element *ele)
  86. {
  87.         _dom_html_button_element_finalise(ele);
  88.         free(ele);
  89. }
  90.  
  91. /*-----------------------------------------------------------------------*/
  92. /* Public APIs */
  93.  
  94. /**
  95.  * Get the disabled property
  96.  *
  97.  * \param ele       The dom_html_button_element object
  98.  * \param disabled  The returned status
  99.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  100.  */
  101. dom_exception dom_html_button_element_get_disabled(dom_html_button_element *ele,
  102.                 bool *disabled)
  103. {
  104.         return dom_html_element_get_bool_property(&ele->base, "disabled",
  105.                         SLEN("disabled"), disabled);
  106. }
  107.  
  108. /**
  109.  * Set the disabled property
  110.  *
  111.  * \param ele       The dom_html_button_element object
  112.  * \param disabled  The status
  113.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  114.  */
  115. dom_exception dom_html_button_element_set_disabled(dom_html_button_element *ele,
  116.                 bool disabled)
  117. {
  118.         return dom_html_element_set_bool_property(&ele->base, "disabled",
  119.                         SLEN("disabled"), disabled);
  120. }
  121.  
  122. /*------------------------------------------------------------------------*/
  123. /* The protected virtual functions */
  124.  
  125. /* The virtual function used to parse attribute value, see src/core/element.c
  126.  * for detail */
  127. dom_exception _dom_html_button_element_parse_attribute(dom_element *ele,
  128.                 dom_string *name, dom_string *value,
  129.                 dom_string **parsed)
  130. {
  131.         UNUSED(ele);
  132.         UNUSED(name);
  133.  
  134.         dom_string_ref(value);
  135.         *parsed = value;
  136.  
  137.         return DOM_NO_ERR;
  138. }
  139.  
  140. /* The virtual destroy function, see src/core/node.c for detail */
  141. void _dom_virtual_html_button_element_destroy(dom_node_internal *node)
  142. {
  143.         _dom_html_button_element_destroy((struct dom_html_button_element *) node);
  144. }
  145.  
  146. /* The virtual copy function, see src/core/node.c for detail */
  147. dom_exception _dom_html_button_element_copy(dom_node_internal *old,
  148.                 dom_node_internal **copy)
  149. {
  150.         return _dom_html_element_copy(old, copy);
  151. }
  152.  
  153. /*-----------------------------------------------------------------------*/
  154. /* API functions */
  155.  
  156. #define SIMPLE_GET(attr)                                                \
  157.         dom_exception dom_html_button_element_get_##attr(               \
  158.                 dom_html_button_element *element,                       \
  159.                 dom_string **attr)                                      \
  160.         {                                                               \
  161.                 dom_exception ret;                                      \
  162.                 dom_string *_memo_##attr;                               \
  163.                                                                         \
  164.                 _memo_##attr =                                          \
  165.                         ((struct dom_html_document *)                   \
  166.                          ((struct dom_node_internal *)element)->owner)->\
  167.                         memoised[hds_##attr];                           \
  168.                                                                         \
  169.                 ret = dom_element_get_attribute(element, _memo_##attr, attr); \
  170.                                                                         \
  171.                 return ret;                                             \
  172.         }                                                              
  173. #define SIMPLE_SET(attr)                                                \
  174. dom_exception dom_html_button_element_set_##attr(                       \
  175.                 dom_html_button_element *element,                       \
  176.                 dom_string *attr)                                       \
  177.         {                                                               \
  178.                 dom_exception ret;                                      \
  179.                 dom_string *_memo_##attr;                               \
  180.                                                                         \
  181.                 _memo_##attr =                                          \
  182.                         ((struct dom_html_document *)                   \
  183.                          ((struct dom_node_internal *)element)->owner)->\
  184.                         memoised[hds_##attr];                           \
  185.                                                                         \
  186.                 ret = dom_element_set_attribute(element, _memo_##attr, attr); \
  187.                                                                         \
  188.                 return ret;                                             \
  189.         }
  190.  
  191. #define SIMPLE_GET_SET(attr) SIMPLE_GET(attr) SIMPLE_SET(attr)
  192.  
  193. SIMPLE_GET_SET(access_key);
  194. SIMPLE_GET_SET(name);
  195. SIMPLE_GET(type);
  196. SIMPLE_GET_SET(value);
  197.  
  198. dom_exception dom_html_button_element_get_tab_index(
  199.         dom_html_button_element *button, int32_t *tab_index)
  200. {
  201.         return dom_html_element_get_int32_t_property(&button->base, "tabindex",
  202.                         SLEN("tabindex"), tab_index);
  203. }
  204.  
  205. dom_exception dom_html_button_element_set_tab_index(
  206.         dom_html_button_element *button, uint32_t tab_index)
  207. {
  208.         return dom_html_element_set_int32_t_property(&button->base, "tabindex",
  209.                         SLEN("tabindex"), tab_index);
  210. }
  211.  
  212. dom_exception dom_html_button_element_get_form(
  213.         dom_html_button_element *button, dom_html_form_element **form)
  214. {
  215.         *form = button->form;
  216.        
  217.         if (*form != NULL)
  218.                 dom_node_ref(*form);
  219.        
  220.         return DOM_NO_ERR;
  221. }
  222.  
  223. dom_exception _dom_html_button_element_set_form(
  224.         dom_html_button_element *button, dom_html_form_element *form)
  225. {
  226.         button->form = form;
  227.        
  228.         return DOM_NO_ERR;
  229. }
  230.  
  231.