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_document_h_
  9. #define dom_core_document_h_
  10.  
  11. #include <stdbool.h>
  12. #include <inttypes.h>
  13. #include <stddef.h>
  14. #include <stdint.h>
  15.  
  16. #include <dom/core/exceptions.h>
  17. #include <dom/core/implementation.h>
  18. #include <dom/core/node.h>
  19.  
  20. struct dom_attr;
  21. struct dom_cdata_section;
  22. struct dom_characterdata;
  23. struct dom_comment;
  24. struct dom_configuration;
  25. struct dom_document_fragment;
  26. struct dom_document_type;
  27. struct dom_element;
  28. struct dom_entity_reference;
  29. struct dom_node;
  30. struct dom_nodelist;
  31. struct dom_processing_instruction;
  32. struct dom_text;
  33. struct lwc_string_s;
  34.  
  35. typedef struct dom_document dom_document;
  36.  
  37. /**
  38.  * Quirks mode flag
  39.  */
  40. typedef enum dom_document_quirks_mode {
  41.         DOM_DOCUMENT_QUIRKS_MODE_NONE,
  42.         DOM_DOCUMENT_QUIRKS_MODE_LIMITED,
  43.         DOM_DOCUMENT_QUIRKS_MODE_FULL
  44. } dom_document_quirks_mode;
  45.  
  46.  
  47. /* DOM Document vtable */
  48. typedef struct dom_document_vtable {
  49.         struct dom_node_vtable base;
  50.  
  51.         dom_exception (*dom_document_get_doctype)(struct dom_document *doc,
  52.                         struct dom_document_type **result);
  53.         dom_exception (*dom_document_get_implementation)(
  54.                         struct dom_document *doc,
  55.                         dom_implementation **result);
  56.         dom_exception (*dom_document_get_document_element)(
  57.                         struct dom_document *doc, struct dom_element **result);
  58.         dom_exception (*dom_document_create_element)(struct dom_document *doc,
  59.                         dom_string *tag_name,
  60.                         struct dom_element **result);
  61.         dom_exception (*dom_document_create_document_fragment)(
  62.                         struct dom_document *doc,
  63.                         struct dom_document_fragment **result);
  64.         dom_exception (*dom_document_create_text_node)(struct dom_document *doc,
  65.                         dom_string *data, struct dom_text **result);
  66.         dom_exception (*dom_document_create_comment)(struct dom_document *doc,
  67.                         dom_string *data, struct dom_comment **result);
  68.         dom_exception (*dom_document_create_cdata_section)(
  69.                         struct dom_document *doc, dom_string *data,
  70.                         struct dom_cdata_section **result);
  71.         dom_exception (*dom_document_create_processing_instruction)(
  72.                         struct dom_document *doc, dom_string *target,
  73.                         dom_string *data,
  74.                         struct dom_processing_instruction **result);
  75.         dom_exception (*dom_document_create_attribute)(struct dom_document *doc,
  76.                         dom_string *name, struct dom_attr **result);
  77.         dom_exception (*dom_document_create_entity_reference)(
  78.                         struct dom_document *doc, dom_string *name,
  79.                         struct dom_entity_reference **result);
  80.         dom_exception (*dom_document_get_elements_by_tag_name)(
  81.                         struct dom_document *doc, dom_string *tagname,
  82.                         struct dom_nodelist **result);
  83.         dom_exception (*dom_document_import_node)(struct dom_document *doc,
  84.                         struct dom_node *node, bool deep,
  85.                         struct dom_node **result);
  86.         dom_exception (*dom_document_create_element_ns)(
  87.                         struct dom_document *doc, dom_string *namespace,
  88.                         dom_string *qname, struct dom_element **result);
  89.         dom_exception (*dom_document_create_attribute_ns)(
  90.                         struct dom_document *doc, dom_string *namespace,
  91.                         dom_string *qname, struct dom_attr **result);
  92.         dom_exception (*dom_document_get_elements_by_tag_name_ns)(
  93.                         struct dom_document *doc, dom_string *namespace,
  94.                         dom_string *localname,
  95.                         struct dom_nodelist **result);
  96.         dom_exception (*dom_document_get_element_by_id)(
  97.                         struct dom_document *doc, dom_string *id,
  98.                         struct dom_element **result);
  99.         dom_exception (*dom_document_get_input_encoding)(
  100.                         struct dom_document *doc, dom_string **result);
  101.         dom_exception (*dom_document_get_xml_encoding)(struct dom_document *doc,
  102.                         dom_string **result);
  103.         dom_exception (*dom_document_get_xml_standalone)(
  104.                         struct dom_document *doc, bool *result);
  105.         dom_exception (*dom_document_set_xml_standalone)(
  106.                         struct dom_document *doc, bool standalone);
  107.         dom_exception (*dom_document_get_xml_version)(struct dom_document *doc,
  108.                         dom_string **result);
  109.         dom_exception (*dom_document_set_xml_version)(struct dom_document *doc,
  110.                         dom_string *version);
  111.         dom_exception (*dom_document_get_strict_error_checking)(
  112.                         struct dom_document *doc, bool *result);
  113.         dom_exception (*dom_document_set_strict_error_checking)(
  114.                         struct dom_document *doc, bool strict);
  115.         dom_exception (*dom_document_get_uri)(struct dom_document *doc,
  116.                         dom_string **result);
  117.         dom_exception (*dom_document_set_uri)(struct dom_document *doc,
  118.                         dom_string *uri);
  119.         dom_exception (*dom_document_adopt_node)(struct dom_document *doc,
  120.                         struct dom_node *node, struct dom_node **result);
  121.         dom_exception (*dom_document_get_dom_config)(struct dom_document *doc,
  122.                         struct dom_configuration **result);
  123.         dom_exception (*dom_document_normalize)(struct dom_document *doc);
  124.         dom_exception (*dom_document_rename_node)(struct dom_document *doc,
  125.                         struct dom_node *node, dom_string *namespace,
  126.                         dom_string *qname, struct dom_node **result);
  127.         dom_exception (*get_quirks_mode)(dom_document *doc,
  128.                                          dom_document_quirks_mode *result);
  129.         dom_exception (*set_quirks_mode)(dom_document *doc,
  130.                                          dom_document_quirks_mode quirks);
  131. } dom_document_vtable;
  132.  
  133. static inline dom_exception dom_document_get_doctype(struct dom_document *doc,
  134.                 struct dom_document_type **result)
  135. {
  136.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  137.                         dom_document_get_doctype(doc, result);
  138. }
  139. #define dom_document_get_doctype(d, r) dom_document_get_doctype( \
  140.                 (dom_document *) (d), (struct dom_document_type **) (r))
  141.  
  142. static inline dom_exception dom_document_get_implementation(
  143.                 struct dom_document *doc, dom_implementation **result)
  144. {
  145.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  146.                         dom_document_get_implementation(doc, result);
  147. }
  148. #define dom_document_get_implementation(d, r) dom_document_get_implementation(\
  149.                 (dom_document *) (d), (dom_implementation **) (r))
  150.  
  151. static inline dom_exception dom_document_get_document_element(
  152.                 struct dom_document *doc, struct dom_element **result)
  153. {
  154.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  155.                         dom_document_get_document_element(doc, result);
  156. }
  157. #define dom_document_get_document_element(d, r) \
  158.                 dom_document_get_document_element((dom_document *) (d), \
  159.                 (struct dom_element **) (r))
  160.  
  161. static inline dom_exception dom_document_create_element(
  162.                 struct dom_document *doc, dom_string *tag_name,
  163.                 struct dom_element **result)
  164. {
  165.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  166.                         dom_document_create_element(doc, tag_name, result);
  167. }
  168. #define dom_document_create_element(d, t, r) dom_document_create_element( \
  169.                 (dom_document *) (d), (t), \
  170.                 (struct dom_element **) (r))
  171.  
  172. static inline dom_exception dom_document_create_document_fragment(
  173.                 struct dom_document *doc,
  174.                 struct dom_document_fragment **result)
  175. {
  176.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  177.                         dom_document_create_document_fragment(doc, result);
  178. }
  179. #define dom_document_create_document_fragment(d, r) \
  180.                 dom_document_create_document_fragment((dom_document *) (d), \
  181.                 (struct dom_document_fragment **) (r))
  182.  
  183. static inline dom_exception dom_document_create_text_node(
  184.                 struct dom_document *doc, dom_string *data,
  185.                 struct dom_text **result)
  186. {
  187.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  188.                         dom_document_create_text_node(doc, data, result);
  189. }
  190. #define dom_document_create_text_node(d, data, r) \
  191.                 dom_document_create_text_node((dom_document *) (d), \
  192.                  (data), (struct dom_text **) (r))
  193.  
  194. static inline dom_exception dom_document_create_comment(
  195.                 struct dom_document *doc, dom_string *data,
  196.                 struct dom_comment **result)
  197. {
  198.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  199.                         dom_document_create_comment(doc, data, result);
  200. }
  201. #define dom_document_create_comment(d, data, r) dom_document_create_comment( \
  202.                 (dom_document *) (d), (data), \
  203.                 (struct dom_comment **) (r))
  204.  
  205. static inline dom_exception dom_document_create_cdata_section(
  206.                 struct dom_document *doc, dom_string *data,
  207.                 struct dom_cdata_section **result)
  208. {
  209.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  210.                         dom_document_create_cdata_section(doc, data, result);
  211. }
  212. #define dom_document_create_cdata_section(d, data, r) \
  213.                 dom_document_create_cdata_section((dom_document *) (d), \
  214.                 (data), (struct dom_cdata_section **) (r))
  215.  
  216. static inline dom_exception dom_document_create_processing_instruction(
  217.                 struct dom_document *doc, dom_string *target,
  218.                 dom_string *data,
  219.                 struct dom_processing_instruction **result)
  220. {
  221.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  222.                         dom_document_create_processing_instruction(doc, target,
  223.                         data, result);
  224. }
  225. #define dom_document_create_processing_instruction(d, t, data, r) \
  226.                 dom_document_create_processing_instruction( \
  227.                 (dom_document *) (d), (t), (data), \
  228.                 (struct dom_processing_instruction **) (r))
  229.  
  230. static inline dom_exception dom_document_create_attribute(
  231.                 struct dom_document *doc, dom_string *name,
  232.                 struct dom_attr **result)
  233. {
  234.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  235.                         dom_document_create_attribute(doc, name, result);
  236. }
  237. #define dom_document_create_attribute(d, n, r) dom_document_create_attribute( \
  238.                 (dom_document *) (d), (n), \
  239.                 (struct dom_attr **) (r))
  240.  
  241. static inline dom_exception dom_document_create_entity_reference(
  242.                 struct dom_document *doc, dom_string *name,
  243.                 struct dom_entity_reference **result)
  244. {
  245.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  246.                         dom_document_create_entity_reference(doc, name,
  247.                         result);
  248. }
  249. #define dom_document_create_entity_reference(d, n, r) \
  250.                 dom_document_create_entity_reference((dom_document *) (d), \
  251.                 (n), (struct dom_entity_reference **) (r))
  252.  
  253. static inline dom_exception dom_document_get_elements_by_tag_name(
  254.                 struct dom_document *doc, dom_string *tagname,
  255.                 struct dom_nodelist **result)
  256. {
  257.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  258.                         dom_document_get_elements_by_tag_name(doc, tagname,
  259.                         result);
  260. }
  261. #define dom_document_get_elements_by_tag_name(d, t, r) \
  262.                 dom_document_get_elements_by_tag_name((dom_document *) (d), \
  263.                 (t), (struct dom_nodelist **) (r))
  264.  
  265. static inline dom_exception dom_document_import_node(struct dom_document *doc,
  266.                 struct dom_node *node, bool deep, struct dom_node **result)
  267. {
  268.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  269.                         dom_document_import_node(doc, node, deep, result);
  270. }
  271. #define dom_document_import_node(d, n, deep, r) dom_document_import_node( \
  272.                 (dom_document *) (d), (dom_node *) (n), (bool) deep, \
  273.                 (dom_node **) (r))
  274.  
  275. static inline dom_exception dom_document_create_element_ns(
  276.                 struct dom_document *doc, dom_string *namespace,
  277.                 dom_string *qname, struct dom_element **result)
  278. {
  279.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  280.                         dom_document_create_element_ns(doc, namespace,
  281.                         qname, result);
  282. }
  283. #define dom_document_create_element_ns(d, n, q, r) \
  284.                 dom_document_create_element_ns((dom_document *) (d), \
  285.                 (n), (q), \
  286.                 (struct dom_element **) (r))
  287.  
  288. static inline dom_exception dom_document_create_attribute_ns
  289.                 (struct dom_document *doc, dom_string *namespace,
  290.                 dom_string *qname, struct dom_attr **result)
  291. {
  292.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  293.                         dom_document_create_attribute_ns(doc, namespace,
  294.                         qname, result);
  295. }
  296. #define dom_document_create_attribute_ns(d, n, q, r) \
  297.                 dom_document_create_attribute_ns((dom_document *) (d), \
  298.                 (n), (q), (struct dom_attr **) (r))
  299.  
  300. static inline dom_exception dom_document_get_elements_by_tag_name_ns(
  301.                 struct dom_document *doc, dom_string *namespace,
  302.                 dom_string *localname, struct dom_nodelist **result)
  303. {
  304.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  305.                         dom_document_get_elements_by_tag_name_ns(doc,
  306.                         namespace, localname, result);
  307. }
  308. #define dom_document_get_elements_by_tag_name_ns(d, n, l, r) \
  309.                 dom_document_get_elements_by_tag_name_ns((dom_document *) (d),\
  310.                 (n), (l), (struct dom_nodelist **) (r))
  311.  
  312. static inline dom_exception dom_document_get_element_by_id(
  313.                 struct dom_document *doc, dom_string *id,
  314.                 struct dom_element **result)
  315. {
  316.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  317.                         dom_document_get_element_by_id(doc, id, result);
  318. }
  319. #define dom_document_get_element_by_id(d, i, r) \
  320.                 dom_document_get_element_by_id((dom_document *) (d), \
  321.                 (i), (struct dom_element **) (r))
  322.  
  323. static inline dom_exception dom_document_get_input_encoding(
  324.                 struct dom_document *doc, dom_string **result)
  325. {
  326.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  327.                         dom_document_get_input_encoding(doc, result);
  328. }
  329. #define dom_document_get_input_encoding(d, r) dom_document_get_input_encoding(\
  330.                 (dom_document *) (d), (r))
  331.  
  332. static inline dom_exception dom_document_get_xml_encoding(
  333.                 struct dom_document *doc, dom_string **result)
  334. {
  335.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  336.                         dom_document_get_xml_encoding(doc, result);
  337. }
  338. #define dom_document_get_xml_encoding(d, r) dom_document_get_xml_encoding( \
  339.                 (dom_document *) (d), (r))
  340.  
  341. static inline dom_exception dom_document_get_xml_standalone(
  342.                 struct dom_document *doc, bool *result)
  343. {
  344.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  345.                         dom_document_get_xml_standalone(doc, result);
  346. }
  347. #define dom_document_get_xml_standalone(d, r) dom_document_get_xml_standalone(\
  348.                 (dom_document *) (d), (bool *) (r))
  349.  
  350. static inline dom_exception dom_document_set_xml_standalone(
  351.                 struct dom_document *doc, bool standalone)
  352. {
  353.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  354.                         dom_document_set_xml_standalone(doc, standalone);
  355. }
  356. #define dom_document_set_xml_standalone(d, s) dom_document_set_xml_standalone(\
  357.                 (dom_document *) (d), (bool) (s))
  358.  
  359. static inline dom_exception dom_document_get_xml_version(
  360.                 struct dom_document *doc, dom_string **result)
  361. {
  362.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  363.                         dom_document_get_xml_version(doc, result);
  364. }
  365. #define dom_document_get_xml_version(d, r) dom_document_get_xml_version( \
  366.                 (dom_document *) (d), (r))
  367.  
  368. static inline dom_exception dom_document_set_xml_version(
  369.                 struct dom_document *doc, dom_string *version)
  370. {
  371.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  372.                         dom_document_set_xml_version(doc, version);
  373. }
  374. #define dom_document_set_xml_version(d, v) dom_document_set_xml_version( \
  375.                 (dom_document *) (d), (v))
  376.  
  377. static inline dom_exception dom_document_get_strict_error_checking(
  378.                 struct dom_document *doc, bool *result)
  379. {
  380.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  381.                         dom_document_get_strict_error_checking(doc, result);
  382. }
  383. #define dom_document_get_strict_error_checking(d, r) \
  384.                 dom_document_get_strict_error_checking((dom_document *) (d), \
  385.                 (bool *) (r))
  386.  
  387. static inline dom_exception dom_document_set_strict_error_checking(
  388.                 struct dom_document *doc, bool strict)
  389. {
  390.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  391.                         dom_document_set_strict_error_checking(doc, strict);
  392. }
  393. #define dom_document_set_strict_error_checking(d, s) \
  394.                 dom_document_set_strict_error_checking((dom_document *) (d), \
  395.                 (bool) (s))
  396.  
  397. static inline dom_exception dom_document_get_uri(struct dom_document *doc,
  398.                 dom_string **result)
  399. {
  400.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  401.                         dom_document_get_uri(doc, result);
  402. }
  403. #define dom_document_get_uri(d, r) dom_document_get_uri((dom_document *) (d), \
  404.                 (r))
  405.  
  406. static inline dom_exception dom_document_set_uri(struct dom_document *doc,
  407.                 dom_string *uri)
  408. {
  409.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  410.                         dom_document_set_uri(doc, uri);
  411. }
  412. #define dom_document_set_uri(d, u) dom_document_set_uri((dom_document *) (d), \
  413.                 (u))
  414.  
  415. static inline dom_exception dom_document_adopt_node(struct dom_document *doc,
  416.                 struct dom_node *node, struct dom_node **result)
  417. {
  418.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  419.                         dom_document_adopt_node(doc, node, result);
  420. }
  421. #define dom_document_adopt_node(d, n, r) dom_document_adopt_node( \
  422.                 (dom_document *) (d), (dom_node *) (n), (dom_node **) (r))
  423.  
  424. static inline dom_exception dom_document_get_dom_config(
  425.                 struct dom_document *doc, struct dom_configuration **result)
  426. {
  427.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  428.                         dom_document_get_dom_config(doc, result);
  429. }
  430. #define dom_document_get_dom_config(d, r) dom_document_get_dom_config( \
  431.                 (dom_document *) (d), (struct dom_configuration **) (r))
  432.  
  433. static inline dom_exception dom_document_normalize(struct dom_document *doc)
  434. {
  435.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  436.                         dom_document_normalize(doc);
  437. }
  438. #define dom_document_normalize(d) dom_document_normalize((dom_document *) (d))
  439.  
  440. static inline dom_exception dom_document_rename_node(struct dom_document *doc,
  441.                 struct dom_node *node,
  442.                 dom_string *namespace, dom_string *qname,
  443.                 struct dom_node **result)
  444. {
  445.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  446.                         dom_document_rename_node(doc, node, namespace, qname,
  447.                         result);
  448. }
  449. #define dom_document_rename_node(d, n, ns, q, r) dom_document_rename_node( \
  450.                 (dom_document *) (d), (ns), \
  451.                 (q), (dom_node **) (r))
  452.  
  453. static inline dom_exception dom_document_get_quirks_mode(
  454.         dom_document *doc, dom_document_quirks_mode *result)
  455. {
  456.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  457.                 get_quirks_mode(doc, result);
  458. }
  459. #define dom_document_get_quirks_mode(d, r) \
  460.         dom_document_get_quirks_mode((dom_document *) (d), (r))
  461.  
  462. static inline dom_exception dom_document_set_quirks_mode(
  463.         dom_document *doc, dom_document_quirks_mode quirks)
  464. {
  465.         return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
  466.                 set_quirks_mode(doc, quirks);
  467. }
  468. #define dom_document_set_quirks_mode(d, q) \
  469.         dom_document_set_quirks_mode((dom_document *) (d), (q))
  470.  
  471. #endif
  472.