Subversion Repositories Kolibri OS

Rev

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

  1. /* Binding to generate NodeList interface
  2.  *
  3.  * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * Released under the terms of the MIT License,
  8.  *         http://www.opensource.org/licenses/mit-license
  9.  */
  10.  
  11. /* The hdrcomment are added into the geenrated output comment header */
  12. hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
  13. hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
  14. hdrcomment "Released under the terms of the MIT License,";
  15. hdrcomment "        http://www.opensource.org/licenses/mit-license";
  16.  
  17. preamble %{
  18.  
  19. #include <dom/dom.h>
  20.        
  21. #include "utils/config.h"
  22. #include "utils/log.h"
  23. #include "javascript/jsapi.h"
  24. #include "render/html_internal.h"
  25.  
  26. #include "nodelist.h"
  27. #include "htmlelement.h"
  28.  
  29. %}
  30.  
  31. webidlfile "dom.idl";
  32.  
  33. binding nodelist {
  34.         type js_libdom; /* the binding type */
  35.  
  36.         interface NodeList; /* The WebIDL interface to generate a binding for */
  37.  
  38.         private "dom_nodelist *" nodelist;
  39.         private "struct html_content *" htmlc;
  40. }
  41.  
  42. api finalise %{
  43.         if (private != NULL) {
  44.                 dom_nodelist_unref(private->nodelist);
  45.         }
  46. %}
  47.  
  48. /* default handler for numericaly indexed property values */
  49. api getproperty %{
  50.         jsval queryprop;
  51.         int idx;
  52.         JSObject *jsret = NULL; /* Node */
  53.         dom_exception err;
  54.         dom_node *domnode;
  55.  
  56.         JSAPI_PROP_IDVAL(cx, &queryprop);
  57.         if (JSVAL_IS_INT(queryprop)) {
  58.                 idx = JSVAL_TO_INT(queryprop);
  59.                 JSDBG("Index was %d", idx);
  60.  
  61.  
  62.                 err = dom_nodelist_item(private->nodelist, idx, &domnode);
  63.                 if (err != DOM_NO_ERR)  {
  64.                         return JS_FALSE;
  65.                 }
  66.  
  67.                 if (domnode != NULL) {
  68.                         jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
  69.  
  70.                         JSDBG("return object:%p", jsret);
  71.  
  72.                         JSAPI_PROP_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsret));
  73.                 }
  74.         }
  75. %}
  76.  
  77. getter length %{
  78.         dom_exception err;
  79.  
  80.         err = dom_nodelist_get_length(private->nodelist, &jsret);
  81.         if (err != DOM_NO_ERR) {
  82.                 return JS_FALSE;
  83.         }
  84. %}
  85.  
  86. operation item %{
  87.         dom_exception err;
  88.         dom_node *domnode;
  89.  
  90.         err = dom_nodelist_item(private->nodelist, index, &domnode);
  91.         if (err != DOM_NO_ERR)  {
  92.                 return JS_FALSE;
  93.         }
  94.  
  95.         if (domnode != NULL) {
  96.                 jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
  97.         }
  98. %}
  99.  
  100.