Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* Binding to generate HTMLcollection interface
  2.  *
  3.  * The js_libdom (javascript to libdom) binding type is currently the
  4.  * only one implemented and this principly describes that binding.
  5.  *
  6.  * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
  7.  *
  8.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  9.  *
  10.  * Released under the terms of the MIT License,
  11.  *         http://www.opensource.org/licenses/mit-license
  12.  */
  13.  
  14. /* The hdrcomment are added into the geenrated output comment header */
  15. hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
  16. hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
  17. hdrcomment "Released under the terms of the MIT License,";
  18. hdrcomment "        http://www.opensource.org/licenses/mit-license";
  19.  
  20. preamble %{
  21.  
  22. #include <dom/dom.h>
  23.        
  24. #include "utils/config.h"
  25. #include "utils/log.h"
  26. #include "javascript/jsapi.h"
  27. #include "render/html_internal.h"
  28.  
  29. #include "htmlelement.h"
  30. #include "htmlcollection.h"
  31.  
  32. %}
  33.  
  34. webidlfile "dom.idl";
  35.  
  36. binding htmlcollection {
  37.     type js_libdom; /* the binding type */
  38.  
  39.     interface HTMLCollection; /* The WebIDL interface to generate a binding for */
  40.  
  41.     private "dom_html_collection *" collection;
  42.     private "struct html_content *" htmlc;
  43. }
  44.  
  45. getter length %{
  46.         dom_exception err;
  47.  
  48.         err = dom_html_collection_get_length(private->collection, &jsret);
  49.         if (err != DOM_NO_ERR) {
  50.                 return JS_FALSE;
  51.         }
  52.         %}
  53.  
  54. operation item %{
  55.         dom_exception err;
  56.         dom_node *domnode;
  57.  
  58.         err = dom_html_collection_item(private->collection, index, &domnode);
  59.         if (err != DOM_NO_ERR)  {
  60.                 return JS_FALSE;
  61.         }
  62.  
  63.         if (domnode != NULL) {
  64.                 jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
  65.         }
  66.         %}
  67.  
  68. operation namedItem %{
  69.         dom_exception err;
  70.         dom_node *domnode;
  71.         dom_string *name_dom;
  72.  
  73.         err = dom_string_create((uint8_t *)name, name_len, &name_dom);
  74.         if (err != DOM_NO_ERR) {
  75.                 return JS_FALSE;
  76.         }
  77.  
  78.         err = dom_html_collection_named_item(private->collection, name_dom, &domnode);
  79.         if (err != DOM_NO_ERR)  {
  80.                 return JS_FALSE;
  81.         }
  82.  
  83.         if (domnode != NULL) {
  84.                 jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
  85.         }
  86.  
  87. %}
  88.  
  89. api finalise %{
  90.         if (private != NULL) {
  91.                 dom_html_collection_unref(private->collection);
  92.         }
  93. %}
  94.