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 2007 John-Mark Bell <jmb@netsurf-browser.org>
  6.  */
  7.  
  8. #ifndef dom_core_attr_h_
  9. #define dom_core_attr_h_
  10.  
  11. #include <stdbool.h>
  12.  
  13. #include <dom/core/exceptions.h>
  14. #include <dom/core/node.h>
  15.  
  16. struct dom_element;
  17. struct dom_type_info;
  18. struct dom_node;
  19. struct dom_attr;
  20.  
  21. typedef struct dom_attr dom_attr;
  22.  
  23. /**
  24.  * The attribute type
  25.  */
  26. typedef enum {
  27.         DOM_ATTR_UNSET = 0,
  28.         DOM_ATTR_STRING,
  29.         DOM_ATTR_BOOL,
  30.         DOM_ATTR_SHORT,
  31.         DOM_ATTR_INTEGER
  32. } dom_attr_type;
  33.  
  34. /* DOM Attr vtable */
  35. typedef struct dom_attr_vtable {
  36.         struct dom_node_vtable base;
  37.  
  38.         dom_exception (*dom_attr_get_name)(struct dom_attr *attr,
  39.                         dom_string **result);
  40.         dom_exception (*dom_attr_get_specified)(struct dom_attr *attr,
  41.                         bool *result);
  42.         dom_exception (*dom_attr_get_value)(struct dom_attr *attr,
  43.                         dom_string **result);
  44.         dom_exception (*dom_attr_set_value)(struct dom_attr *attr,
  45.                         dom_string *value);
  46.         dom_exception (*dom_attr_get_owner_element)(struct dom_attr *attr,
  47.                         struct dom_element **result);
  48.         dom_exception (*dom_attr_get_schema_type_info)(struct dom_attr *attr,
  49.                         struct dom_type_info **result);
  50.         dom_exception (*dom_attr_is_id)(struct dom_attr *attr, bool *result);
  51. } dom_attr_vtable;
  52.  
  53. static inline dom_exception dom_attr_get_name(struct dom_attr *attr,
  54.                 dom_string **result)
  55. {
  56.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  57.                         dom_attr_get_name(attr, result);
  58. }
  59. #define dom_attr_get_name(a, r) dom_attr_get_name((struct dom_attr *) (a), (r))
  60.  
  61. static inline dom_exception dom_attr_get_specified(struct dom_attr *attr,
  62.                 bool *result)
  63. {
  64.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  65.                         dom_attr_get_specified(attr, result);
  66. }
  67. #define dom_attr_get_specified(a, r) dom_attr_get_specified( \
  68.                 (struct dom_attr *) (a), (bool *) (r))
  69.  
  70. static inline dom_exception dom_attr_get_value(struct dom_attr *attr,
  71.                 dom_string **result)
  72. {
  73.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  74.                         dom_attr_get_value(attr, result);
  75. }
  76. #define dom_attr_get_value(a, r) dom_attr_get_value((struct dom_attr *) (a), (r))
  77.  
  78. static inline dom_exception dom_attr_set_value(struct dom_attr *attr,
  79.                 dom_string *value)
  80. {
  81.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  82.                         dom_attr_set_value(attr, value);
  83. }
  84. #define dom_attr_set_value(a, v) dom_attr_set_value((struct dom_attr *) (a), (v))
  85.  
  86. static inline dom_exception dom_attr_get_owner_element(struct dom_attr *attr,
  87.                 struct dom_element **result)
  88. {
  89.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  90.                         dom_attr_get_owner_element(attr, result);
  91. }
  92. #define dom_attr_get_owner_element(a, r) dom_attr_get_owner_element(\
  93.                 (struct dom_attr *) (a), (struct dom_element **) (r))
  94.  
  95. static inline dom_exception dom_attr_get_schema_type_info(
  96.                 struct dom_attr *attr, struct dom_type_info **result)
  97. {
  98.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  99.                         dom_attr_get_schema_type_info(attr, result);
  100. }
  101. #define dom_attr_get_schema_type_info(a, r) dom_attr_get_schema_type_info( \
  102.                 (struct dom_attr *) (a), (struct dom_type_info **) (r))
  103.  
  104. static inline dom_exception dom_attr_is_id(struct dom_attr *attr, bool *result)
  105. {
  106.         return ((dom_attr_vtable *) ((dom_node *) attr)->vtable)->
  107.                         dom_attr_is_id(attr, result);
  108. }
  109. #define dom_attr_is_id(a, r) dom_attr_is_id((struct dom_attr *) (a), \
  110.                 (bool *) (r))
  111.  
  112. /*-----------------------------------------------------------------------*/
  113. /**
  114.  * Following are our implementation specific APIs.
  115.  *
  116.  * These APIs are defined for the purpose that there are some attributes in
  117.  * HTML and other DOM module whose type is not DOMString, but uint32_t or
  118.  * boolean, for those types of attributes, clients should call one of the
  119.  * following APIs to set it.
  120.  *
  121.  * When an Attr node is created, its type is unset and it can be turned into
  122.  * any of the four types. Once the type is fixed by calling any of the four
  123.  * APIs:
  124.  * dom_attr_set_value
  125.  * dom_attr_set_integer
  126.  * dom_attr_set_short
  127.  * dom_attr_set_bool
  128.  * it can't be modified in future.
  129.  *
  130.  * For integer/short/bool type of attributes, we provide no string
  131.  * repensentation of them, so when you call dom_attr_get_value on these
  132.  * three type of attribute nodes, you will always get a empty dom_string.
  133.  * If you want to do something with Attr node, you must know its type
  134.  * firstly by calling dom_attr_get_type before you decide to call other
  135.  * dom_attr_get_* functions.
  136.  */
  137. dom_attr_type dom_attr_get_type(dom_attr *a);
  138. dom_exception dom_attr_get_integer(dom_attr *a, uint32_t *value);
  139. dom_exception dom_attr_set_integer(dom_attr *a, uint32_t value);
  140. dom_exception dom_attr_get_short(dom_attr *a, unsigned short *value);
  141. dom_exception dom_attr_set_short(dom_attr *a, unsigned short value);
  142. dom_exception dom_attr_get_bool(dom_attr *a, bool *value);
  143. dom_exception dom_attr_set_bool(dom_attr *a, bool value);
  144. /* Make a attribute node readonly */
  145. void dom_attr_mark_readonly(dom_attr *a);
  146.  
  147. #endif
  148.