From 478b57c5d7b683aca78d2fbadc904caf75ddf9b7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 Nov 2012 16:37:29 +0000 Subject: [PATCH 1/6] working docuemnt.cookie --- javascript/jsapi/dom.bnd | 56 ------------------ javascript/jsapi/htmldocument.bnd | 98 ++++++++++++++++++++++++++----- test/js/dom-doc-cookie.html | 9 +++ 3 files changed, 91 insertions(+), 72 deletions(-) create mode 100644 test/js/dom-doc-cookie.html diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd index fdf1f253a..cd252fc27 100644 --- a/javascript/jsapi/dom.bnd +++ b/javascript/jsapi/dom.bnd @@ -2,62 +2,6 @@ webidlfile "dom.idl"; -operation getElementById %{ - dom_string *elementId_dom; - dom_element *element; - dom_exception exc; - - exc = dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_document_get_element_by_id(private->node, elementId_dom, &element); - dom_string_unref(elementId_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (element != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); - } -%} - -/* Dom 4 says this should return a htmlcollection, libdom currently - * returns DOM 3 spec of a nodelist - */ - -operation getElementsByTagName %{ - dom_string *localName_dom; - /* dom_html_collection *collection;*/ - dom_nodelist *nodelist; - dom_exception exc; - - exc = dom_string_create((uint8_t *)localName, localName_len, &localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_document_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist); - dom_string_unref(localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (/*collection*/nodelist != NULL) { - /*jsret = jsapi_new_HTMLCollection(cx, - NULL, - NULL, - collection, - private->htmlc);*/ - jsret = jsapi_new_NodeList(cx, - NULL, - NULL, - nodelist, - private->htmlc); - } - -%} getter textContent %{ dom_exception exc; diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 4cc4971fb..7be8537a2 100644 --- a/javascript/jsapi/htmldocument.bnd +++ b/javascript/jsapi/htmldocument.bnd @@ -13,30 +13,23 @@ preamble %{ #include "utils/config.h" #include "utils/log.h" +#include "content/urldb.h" + #include "javascript/jsapi.h" #include "javascript/jsapi/binding.h" %} -operation write %{ - LOG(("content %p parser %p writing %s", - private->htmlc, private->htmlc->parser, text)); - - if (private->htmlc->parser != NULL) { - dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); - } -%} - binding document { - type js_libdom; /* the binding type */ + type js_libdom; /* the binding type */ - /* parameters to constructor value stored in private - * context structure. - */ - private "dom_document *" node; - private "struct html_content *" htmlc; + /* parameters to constructor value stored in private + * context structure. + */ + private "dom_document *" node; + private "struct html_content *" htmlc; - interface Document; /* Web IDL interface to generate */ + interface Document; /* Web IDL interface to generate */ } api finalise %{ @@ -44,3 +37,76 @@ api finalise %{ dom_node_unref(private->node); } %} + +getter cookie %{ + char *cookie_str; + cookie_str = urldb_get_cookie(llcache_handle_get_url(private->htmlc->base.llcache)); + if (cookie_str != NULL) { + jsret = JS_NewStringCopyN(cx, cookie_str, strlen(cookie_str)); + free(cookie_str); + } +%} + +operation getElementById %{ + dom_string *elementId_dom; + dom_element *element; + dom_exception exc; + + exc = dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + exc = dom_document_get_element_by_id(private->node, elementId_dom, &element); + dom_string_unref(elementId_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + if (element != NULL) { + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); + } +%} + +/* + * + * Dom 4 says this should return a htmlcollection, libdom currently + * returns DOM 3 spec of a nodelist + */ +operation getElementsByTagName %{ + dom_string *localName_dom; + /* dom_html_collection *collection;*/ + dom_nodelist *nodelist; + dom_exception exc; + + exc = dom_string_create((uint8_t *)localName, localName_len, &localName_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + exc = dom_document_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist); + dom_string_unref(localName_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + if (/*collection*/nodelist != NULL) { + /*jsret = jsapi_new_HTMLCollection(cx, + NULL, + NULL, + collection, + private->htmlc);*/ + jsret = jsapi_new_NodeList(cx, + NULL, + NULL, + nodelist, + private->htmlc); + } + +%} + +operation write %{ + if (private->htmlc->parser != NULL) { + dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); + } +%} diff --git a/test/js/dom-doc-cookie.html b/test/js/dom-doc-cookie.html new file mode 100644 index 000000000..b0e69ffb8 --- /dev/null +++ b/test/js/dom-doc-cookie.html @@ -0,0 +1,9 @@ + + +Show cookie + + +

Show cookie

+

+ + From 25f0bcbaee258ba8922ada5d7b33e53a50ae1c78 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2012 16:57:41 +0000 Subject: [PATCH 2/6] Fix it so that the JSAPI bindings are rebuilt if sources are touched --- Makefile | 1 + Makefile.sources.javascript | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 33a10cc17..f512081cd 100644 --- a/Makefile +++ b/Makefile @@ -621,6 +621,7 @@ $(eval $(foreach SOURCE,$(filter %.m,$(SOURCES)), \ ifneq ($(MAKECMDGOALS),clean) -include $(sort $(addprefix $(DEPROOT)/,$(DEPFILES))) +-include $(D_JSAPI_BINDING) endif # And rules to build the objects themselves... diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript index ca0c146ee..ca69da9dc 100644 --- a/Makefile.sources.javascript +++ b/Makefile.sources.javascript @@ -9,6 +9,7 @@ # ---------------------------------------------------------------------------- S_JSAPI_BINDING:= +D_JSAPI_BINDING:= JSAPI_BINDING_htmldocument := javascript/jsapi/htmldocument.bnd JSAPI_BINDING_htmlelement := javascript/jsapi/htmlelement.bnd @@ -25,10 +26,11 @@ JSAPI_BINDING_nodelist := javascript/jsapi/nodelist.bnd define convert_jsapi_binding S_JSAPI_BINDING += $(2) +D_JSAPI_BINDING += $(patsubst %.c,%.d,$(2)) $(2): $(1) $$(VQ)echo " GENBIND: $(1)" - $(Q)nsgenbind -I javascript/WebIDL/ -o $(2) $(1) + $(Q)nsgenbind -I javascript/WebIDL/ -d $(patsubst %.c,%.d,$(2)) -o $(2) $(1) endef @@ -43,7 +45,7 @@ endif ifeq ($(WANT_JS_SOURCE),YES) -S_JSAPI = +S_JSAPI := S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI)) From dfaa29d5b8198800927c27ebbab80b5504697b24 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2012 17:04:43 +0000 Subject: [PATCH 3/6] Ensure we wait for the OBJROOT *BEFORE* we try and build javascript bindings --- Makefile.sources.javascript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript index ca69da9dc..da7c2101e 100644 --- a/Makefile.sources.javascript +++ b/Makefile.sources.javascript @@ -28,7 +28,7 @@ define convert_jsapi_binding S_JSAPI_BINDING += $(2) D_JSAPI_BINDING += $(patsubst %.c,%.d,$(2)) -$(2): $(1) +$(2): $(1) $(OBJROOT)/created $$(VQ)echo " GENBIND: $(1)" $(Q)nsgenbind -I javascript/WebIDL/ -d $(patsubst %.c,%.d,$(2)) -o $(2) $(1) From efd6d11e47ceb7e1d857b0a9d0a3ce2a1cc8b1b7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2012 17:26:42 +0000 Subject: [PATCH 4/6] Unspecified input types are text and so get EX widths --- css/select.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/css/select.c b/css/select.c index b745a2f73..5ad0edcff 100644 --- a/css/select.c +++ b/css/select.c @@ -2511,11 +2511,12 @@ node_presentational_hint_width(nscss_select_ctx *ctx, if (input) { err = dom_element_get_attribute(node, corestring_dom_type, &width); - if ((err != DOM_NO_ERR) || (width == NULL)) { + if (err != DOM_NO_ERR) { return CSS_PROPERTY_NOT_SET; } - if (dom_string_lwc_isequal(width, + if ((width == NULL) || + dom_string_lwc_isequal(width, corestring_lwc_text) || dom_string_lwc_isequal(width, corestring_lwc_password)) { From b23aee2f09e642a0a4896a13c8450c3fa282cb03 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2012 17:29:26 +0000 Subject: [PATCH 5/6] type=search is a new-fangled HTML5 thing which we treat as input and thus give EX width hinting. Closes #3578446 --- css/select.c | 2 ++ utils/corestrings.c | 3 +++ utils/corestrings.h | 1 + 3 files changed, 6 insertions(+) diff --git a/css/select.c b/css/select.c index 5ad0edcff..8854026dd 100644 --- a/css/select.c +++ b/css/select.c @@ -2518,6 +2518,8 @@ node_presentational_hint_width(nscss_select_ctx *ctx, if ((width == NULL) || dom_string_lwc_isequal(width, corestring_lwc_text) || + dom_string_lwc_isequal(width, + corestring_lwc_search) || dom_string_lwc_isequal(width, corestring_lwc_password)) { hint->data.length.unit = CSS_UNIT_EX; diff --git a/utils/corestrings.c b/utils/corestrings.c index 866dfd945..7697786bc 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -87,6 +87,7 @@ lwc_string *corestring_lwc_rectangle; lwc_string *corestring_lwc_refresh; lwc_string *corestring_lwc_reset; lwc_string *corestring_lwc_right; +lwc_string *corestring_lwc_search; lwc_string *corestring_lwc_select; lwc_string *corestring_lwc_src; lwc_string *corestring_lwc_style; @@ -230,6 +231,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(refresh); CSS_LWC_STRING_UNREF(reset); CSS_LWC_STRING_UNREF(right); + CSS_LWC_STRING_UNREF(search); CSS_LWC_STRING_UNREF(select); CSS_LWC_STRING_UNREF(src); CSS_LWC_STRING_UNREF(style); @@ -392,6 +394,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(refresh); CSS_LWC_STRING_INTERN(reset); CSS_LWC_STRING_INTERN(right); + CSS_LWC_STRING_INTERN(search); CSS_LWC_STRING_INTERN(select); CSS_LWC_STRING_INTERN(src); CSS_LWC_STRING_INTERN(style); diff --git a/utils/corestrings.h b/utils/corestrings.h index 27da3fb45..b72c53e7a 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -91,6 +91,7 @@ extern lwc_string *corestring_lwc_rectangle; extern lwc_string *corestring_lwc_refresh; extern lwc_string *corestring_lwc_reset; extern lwc_string *corestring_lwc_right; +extern lwc_string *corestring_lwc_search; extern lwc_string *corestring_lwc_select; extern lwc_string *corestring_lwc_src; extern lwc_string *corestring_lwc_style; From 7a3a2099401c42cc90afdb67890d95a8670f5591 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2012 17:36:17 +0000 Subject: [PATCH 6/6] File input boxen deserve EX width hinting --- css/select.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/css/select.c b/css/select.c index 8854026dd..a52b8b144 100644 --- a/css/select.c +++ b/css/select.c @@ -2520,6 +2520,8 @@ node_presentational_hint_width(nscss_select_ctx *ctx, corestring_lwc_text) || dom_string_lwc_isequal(width, corestring_lwc_search) || + dom_string_lwc_isequal(width, + corestring_lwc_file) || dom_string_lwc_isequal(width, corestring_lwc_password)) { hint->data.length.unit = CSS_UNIT_EX;