mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-04 18:16:16 +03:00
add HTMLElement interface binding
This commit is contained in:
parent
8f08f820f4
commit
2b8cdf1f29
@ -11,6 +11,7 @@
|
|||||||
S_JSAPI_BINDING:=
|
S_JSAPI_BINDING:=
|
||||||
|
|
||||||
JSAPI_BINDING_htmldocument := javascript/jsapi/bindings/htmldocument.bnd
|
JSAPI_BINDING_htmldocument := javascript/jsapi/bindings/htmldocument.bnd
|
||||||
|
JSAPI_BINDING_htmlelement := javascript/jsapi/bindings/htmlelement.bnd
|
||||||
JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd
|
JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd
|
||||||
JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd
|
JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd
|
||||||
JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd
|
JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd
|
||||||
@ -31,8 +32,8 @@ endef
|
|||||||
# Javascript sources
|
# Javascript sources
|
||||||
ifeq ($(NETSURF_USE_JS),YES)
|
ifeq ($(NETSURF_USE_JS),YES)
|
||||||
|
|
||||||
S_JSAPI = htmlelement.c
|
S_JSAPI =
|
||||||
#htmldocument.c window.c navigator.c console.c
|
# htmlelement.c htmldocument.c window.c navigator.c console.c
|
||||||
|
|
||||||
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
|
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent);
|
|||||||
*/
|
*/
|
||||||
JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
|
JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
|
||||||
|
|
||||||
|
JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent);
|
||||||
/** Create a new javascript element object
|
/** Create a new javascript element object
|
||||||
*
|
*
|
||||||
* @param cx The javascript context.
|
* @param cx The javascript context.
|
||||||
@ -83,6 +84,10 @@ JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
|
|||||||
* @param doc_priv The private context to set on the object
|
* @param doc_priv The private context to set on the object
|
||||||
* @return new javascript object or NULL on error
|
* @return new javascript object or NULL on error
|
||||||
*/
|
*/
|
||||||
JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct html_content *htmlc, struct dom_element *domelement);
|
JSObject *jsapi_new_HTMLElement(JSContext *cx,
|
||||||
|
JSObject *prototype,
|
||||||
|
JSObject *parent,
|
||||||
|
dom_element *node,
|
||||||
|
struct html_content *htmlc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
/* test binding for document - must be included */
|
/* DOM bindings entries */
|
||||||
|
|
||||||
webidlfile "dom.idl";
|
webidlfile "dom.idl";
|
||||||
|
|
||||||
operation getElementById %{
|
operation getElementById %{
|
||||||
dom_string *elementId_dom;
|
dom_string *elementId_dom;
|
||||||
dom_element *element;
|
dom_element *element;
|
||||||
|
dom_exception exc;
|
||||||
|
|
||||||
|
LOG(("elementId_len %d elementId %s",elementId_len,elementId));
|
||||||
|
|
||||||
dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
|
dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
|
||||||
|
LOG(("dom string %p", elementId_dom));
|
||||||
|
|
||||||
dom_document_get_element_by_id(private->node, elementId_dom, &element);
|
|
||||||
|
|
||||||
jsretval = OBJECT_TO_JSVAL(jsapi_new_element(cx, JS_GetGlobalObject(cx), private->htmlc, element));
|
exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
|
||||||
|
if ((exc == DOM_NO_ERR) && (element != NULL)) {
|
||||||
|
jsret = jsapi_new_HTMLElement(cx, NULL, JS_GetGlobalObject(cx), element, private->htmlc);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
getter textContent %{
|
||||||
|
dom_exception exc;
|
||||||
|
dom_string *content;
|
||||||
|
|
||||||
|
exc = dom_node_get_text_content(private->node, &content);
|
||||||
|
if ((exc == DOM_NO_ERR) && (content != NULL)) {
|
||||||
|
jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content));
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
51
javascript/jsapi/bindings/htmlelement.bnd
Normal file
51
javascript/jsapi/bindings/htmlelement.bnd
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* Binding to generate HTMLElement interface
|
||||||
|
*
|
||||||
|
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
|
||||||
|
*
|
||||||
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||||
|
*
|
||||||
|
* Released under the terms of the MIT License,
|
||||||
|
* http://www.opensource.org/licenses/mit-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dom.bnd"
|
||||||
|
|
||||||
|
webidlfile "html.idl";
|
||||||
|
|
||||||
|
hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
|
||||||
|
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
|
||||||
|
hdrcomment "Released under the terms of the MIT License,";
|
||||||
|
hdrcomment " http://www.opensource.org/licenses/mit-license";
|
||||||
|
|
||||||
|
preamble %{
|
||||||
|
|
||||||
|
#include <dom/dom.h>
|
||||||
|
|
||||||
|
#include "utils/config.h"
|
||||||
|
#include "utils/log.h"
|
||||||
|
|
||||||
|
#include "javascript/jsapi.h"
|
||||||
|
#include "javascript/jsapi/binding.h"
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
binding htmlelement {
|
||||||
|
type js_libdom; /* the binding type */
|
||||||
|
|
||||||
|
interface HTMLElement; /* Web IDL interface to generate */
|
||||||
|
|
||||||
|
/* private members:
|
||||||
|
* - stored in private context structure.
|
||||||
|
* - passed as parameters to constructor and stored automatically.
|
||||||
|
* - are *not* considered for property getters/setters.
|
||||||
|
*
|
||||||
|
* internal members:
|
||||||
|
* - value stored in private context structure
|
||||||
|
* - not passed to constructor
|
||||||
|
* - must be instantiated by constructor
|
||||||
|
* - are considered for property getters/setters.
|
||||||
|
*/
|
||||||
|
private "dom_element *" node;
|
||||||
|
private "struct html_content *" htmlc;
|
||||||
|
}
|
||||||
|
|
@ -76,22 +76,22 @@ binding navigator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getter appName %{
|
getter appName %{
|
||||||
jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME));
|
jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
getter appCodeName %{
|
getter appCodeName %{
|
||||||
jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME));
|
jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
getter appVersion %{
|
getter appVersion %{
|
||||||
jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, netsurf_version));
|
jsret = JS_NewStringCopyZ(cx, netsurf_version);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
getter language %{
|
getter language %{
|
||||||
const char *alang = nsoption_charp(accept_language);
|
const char *alang = nsoption_charp(accept_language);
|
||||||
|
|
||||||
if (alang != NULL) {
|
if (alang != NULL) {
|
||||||
jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, alang));
|
jsret = JS_NewStringCopyZ(cx, alang);
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
@ -109,12 +109,12 @@ getter platform %{
|
|||||||
platstr = malloc(platstrlen);
|
platstr = malloc(platstrlen);
|
||||||
if (platstr != NULL) {
|
if (platstr != NULL) {
|
||||||
snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
|
snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
|
||||||
jsretval = STRING_TO_JSVAL(JS_NewStringCopyN(cx, platstr, platstrlen - 1));
|
jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1);
|
||||||
free(platstr);
|
free(platstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
getter userAgent %{
|
getter userAgent %{
|
||||||
jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, user_agent_string()));
|
jsret = JS_NewStringCopyZ(cx, user_agent_string());
|
||||||
%}
|
%}
|
||||||
|
@ -31,11 +31,11 @@ operation prompt %{
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
getter window %{
|
getter window %{
|
||||||
jsretval = OBJECT_TO_JSVAL(obj);
|
jsret = obj;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
getter self %{
|
getter self %{
|
||||||
jsretval = OBJECT_TO_JSVAL(obj);
|
jsret = obj;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
api init %{
|
api init %{
|
||||||
@ -90,6 +90,11 @@ api init %{
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user_proto = jsapi_InitClass_HTMLElement(cx, prototype);
|
||||||
|
if (user_proto == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
api new %{
|
api new %{
|
||||||
|
Loading…
Reference in New Issue
Block a user