summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOle Loots <ole@monochrom.net>2012-11-07 23:36:22 +0100
committerOle Loots <ole@monochrom.net>2012-11-07 23:38:04 +0100
commit9482bb464a157265a555dfa38fcf2dc37ade12fd (patch)
tree8af826c90d8e0b53ea9cb0421bb1466172dec99b
parent5242cd00a4b9ddc6364e107519f1e674e716bc77 (diff)
parent882fd4f5c5eead48d1f056596a6e66329bd9c144 (diff)
downloadnetsurf-9482bb464a157265a555dfa38fcf2dc37ade12fd.tar.gz
netsurf-9482bb464a157265a555dfa38fcf2dc37ade12fd.tar.bz2
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
-rw-r--r--Makefile.sources2
-rw-r--r--Makefile.sources.javascript1
-rw-r--r--amiga/font_scan.c1
-rw-r--r--gtk/Makefile.target12
-rw-r--r--javascript/jsapi/binding.h14
-rw-r--r--javascript/jsapi/dom.bnd5
-rw-r--r--javascript/jsapi/htmldocument.bnd83
-rw-r--r--javascript/jsapi/text.bnd44
-rw-r--r--javascript/jsapi/window.bnd5
-rw-r--r--render/html.c43
-rw-r--r--utils/domutils.c66
-rw-r--r--utils/domutils.h24
12 files changed, 250 insertions, 50 deletions
diff --git a/Makefile.sources b/Makefile.sources
index 32db5e666..50dec8e5a 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -19,7 +19,7 @@ S_RENDER := box.c box_construct.c box_normalise.c \
S_UTILS := base64.c corestrings.c filename.c filepath.c hashtable.c \
libdom.c locale.c log.c messages.c nsurl.c talloc.c url.c \
- utf8.c utils.c useragent.c
+ utf8.c utils.c useragent.c domutils.c
S_HTTP := challenge.c generics.c primitives.c parameter.c \
content-disposition.c content-type.c www-authenticate.c
diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript
index da7c2101e..88412ec57 100644
--- a/Makefile.sources.javascript
+++ b/Makefile.sources.javascript
@@ -19,6 +19,7 @@ JSAPI_BINDING_console := javascript/jsapi/console.bnd
JSAPI_BINDING_location := javascript/jsapi/location.bnd
JSAPI_BINDING_htmlcollection := javascript/jsapi/htmlcollection.bnd
JSAPI_BINDING_nodelist := javascript/jsapi/nodelist.bnd
+JSAPI_BINDING_text := javascript/jsapi/text.bnd
# 1: input file
# 2: output file
diff --git a/amiga/font_scan.c b/amiga/font_scan.c
index 13087716c..4190e681a 100644
--- a/amiga/font_scan.c
+++ b/amiga/font_scan.c
@@ -317,7 +317,6 @@ ULONG ami_font_scan_list(struct MinList *list)
}
}
}
- af++;
}
FreeVec(afh);
} else {
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 08d3bbf47..91ffb526e 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -139,12 +139,12 @@ install-gtk:
$(Q)mkdir -p $(DESTDIR)$(NETSURF_GTK_RESOURCES)throbber
$(Q)mkdir -p $(DESTDIR)$(NETSURF_GTK_RESOURCES)icons
$(Q)mkdir -p $(DESTDIR)$(NETSURF_GTK_BIN)
- $(Q)install -v nsgtk $(DESTDIR)$(NETSURF_GTK_BIN)netsurf
- $(Q)install -v -m 0644 -t $(DESTDIR)$(NETSURF_GTK_RESOURCES) $(GTK_RESOURCES_LIST)
- $(Q)install -v -m 0644 -t $(DESTDIR)$(NETSURF_GTK_RESOURCES)/icons gtk/res/icons/*.png
- $(Q)install -v -m 0644 -t $(DESTDIR)$(NETSURF_GTK_RESOURCES)/throbber gtk/res/throbber/*.png
- $(Q)tar c -h -C gtk/res themes | tar xv -C $(DESTDIR)$(NETSURF_GTK_RESOURCES)
- $(Q)tar c -h -C gtk/res $(GTK_TRANSLATIONS_HTML) | tar xv -C $(DESTDIR)$(NETSURF_GTK_RESOURCES)
+ $(Q)install nsgtk $(DESTDIR)$(NETSURF_GTK_BIN)netsurf
+ $(Q)install -m 0644 $(GTK_RESOURCES_LIST) $(DESTDIR)$(NETSURF_GTK_RESOURCES)
+ $(Q)install -m 0644 gtk/res/icons/*.png $(DESTDIR)$(NETSURF_GTK_RESOURCES)/icons
+ $(Q)install -m 0644 gtk/res/throbber/*.png $(DESTDIR)$(NETSURF_GTK_RESOURCES)/throbber
+ $(Q)tar -c -h -C gtk/res -f - themes | tar -xv -C $(DESTDIR)$(NETSURF_GTK_RESOURCES) -f -
+ $(Q)tar -c -h -C gtk/res -f - $(GTK_TRANSLATIONS_HTML) | tar -xv -C $(DESTDIR)$(NETSURF_GTK_RESOURCES) -f -
$(call split_install_messages, gtk, $(DESTDIR)$(NETSURF_GTK_RESOURCES))
# ----------------------------------------------------------------------------
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index c1006589e..446fb0c51 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -124,4 +124,18 @@ JSObject *jsapi_new_NodeList(JSContext *cx,
dom_nodelist *nodelist,
struct html_content *htmlc);
+
+JSObject *jsapi_InitClass_Text(JSContext *cx, JSObject *parent);
+/** Create a new javascript text object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param node The dom node to use in the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_Text(JSContext *cx,
+ JSObject *prototype,
+ JSObject *parent,
+ dom_text *node);
+
#endif
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index cd252fc27..bf3b44ea3 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -2,6 +2,8 @@
webidlfile "dom.idl";
+/* interface Node members */
+
getter textContent %{
dom_exception exc;
@@ -21,3 +23,6 @@ getter textContent %{
+operation appendChild %{
+/* void * JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv); */
+%}
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 7574512dd..b642cabe6 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -12,6 +12,8 @@ preamble %{
#include "utils/config.h"
#include "utils/log.h"
+#include "utils/corestrings.h"
+#include "utils/domutils.h"
#include "content/urldb.h"
@@ -23,13 +25,13 @@ preamble %{
binding document {
type js_libdom; /* the binding type */
+ interface Document; /* Web IDL interface to generate */
+
/* 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 */
}
api finalise %{
@@ -49,6 +51,61 @@ getter cookie %{
}
%}
+getter documentElement %{
+ dom_exception exc;
+ dom_element *element;
+
+ /* document (html) element */
+ exc = dom_document_get_document_element(private->node, (void *)&element);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (element != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
+ }
+%}
+
+getter head %{
+ dom_node *element;
+ dom_node *head;
+ dom_exception exc;
+
+ /* document (html) element */
+ exc = dom_document_get_document_element(private->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (element != NULL) {
+ head = find_first_named_dom_element(element, corestring_lwc_head) ;
+ if (head != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)head, private->htmlc);
+ }
+ dom_node_unref(element);
+ }
+%}
+
+getter body %{
+ dom_node *element;
+ dom_node *body;
+ dom_exception exc;
+
+ /* document (html) element */
+ exc = dom_document_get_document_element(private->node, &element);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (element != NULL) {
+ body = find_first_named_dom_element(element, corestring_lwc_body) ;
+ if (body != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)body, private->htmlc);
+ }
+ dom_node_unref(element);
+ }
+%}
+
operation getElementById %{
dom_string *elementId_dom;
dom_element *element;
@@ -112,3 +169,25 @@ operation write %{
dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len);
}
%}
+
+/* in dom Document */
+operation createTextNode %{
+ dom_string *data_dom;
+ dom_element *element;
+ dom_exception exc;
+ dom_text *text;
+
+ exc = dom_string_create((unsigned char*)data, data_len, &data_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ exc = dom_document_create_text_node(private->node, data_dom, &text);
+ dom_string_unref(data_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ jsret = jsapi_new_Text(cx, NULL, NULL, text);
+
+%}
diff --git a/javascript/jsapi/text.bnd b/javascript/jsapi/text.bnd
new file mode 100644
index 000000000..53e93803d
--- /dev/null
+++ b/javascript/jsapi/text.bnd
@@ -0,0 +1,44 @@
+/* Binding to generate Text 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 text {
+ type js_libdom; /* the binding type */
+
+ interface Text; /* Web IDL interface to generate */
+
+ private "dom_text *" node;
+}
+
+api finalise %{
+ if (private != NULL) {
+ dom_node_unref(private->node);
+ }
+%}
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index 865cbf3d4..5a7de530f 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -130,6 +130,11 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_Text(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
%}
api new %{
diff --git a/render/html.c b/render/html.c
index 4e79e085e..616ae7b2a 100644
--- a/render/html.c
+++ b/render/html.c
@@ -53,6 +53,7 @@
#include "utils/url.h"
#include "utils/utf8.h"
#include "utils/utils.h"
+#include "utils/domutils.h"
#define CHUNK 4096
@@ -464,6 +465,7 @@ parse_chunk_to_nserror(dom_hubbub_error error)
case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
/* currently only generated by the libdom hubbub binding */
+ return NSERROR_DOM;
default:
/* unknown error */
/** @todo better error handling and reporting */
@@ -2030,46 +2032,7 @@ html_begin_conversion(html_content *htmlc)
}
dom_string_unref(node_name);
- /* ensure the head element is found */
- exc = dom_node_get_first_child(html, &head);
- if ((exc != DOM_NO_ERR) || (head == NULL)) {
- head = NULL;
- LOG(("head element not found"));
- } else {
- dom_node_type node_type;
- dom_node *next_node;
-
- /* find first node thats a element */
- do {
- exc = dom_node_get_node_type(head, &node_type);
-
- if ((exc != DOM_NO_ERR) ||
- (node_type == DOM_ELEMENT_NODE))
- break;
-
- exc = dom_node_get_next_sibling(head, &next_node);
- dom_node_unref(head);
- if (exc == DOM_NO_ERR) {
- head = next_node;
- } else {
- head = NULL;
- }
- } while (head != NULL);
-
- if (head != NULL) {
- exc = dom_node_get_node_name(head, &node_name);
- if ((exc == DOM_NO_ERR) || (node_name != NULL)) {
- if (!dom_string_caseless_lwc_isequal(node_name,
- corestring_lwc_head)) {
- dom_node_unref(head);
- LOG(("head element not found"));
- head = NULL;
- }
- dom_string_unref(node_name);
- }
- }
- }
-
+ head = find_first_named_dom_element(html, corestring_lwc_head);
if (head != NULL) {
if (html_head(htmlc, head) == false) {
msg_data.error = messages_get("NoMemory");
diff --git a/utils/domutils.c b/utils/domutils.c
new file mode 100644
index 000000000..4d32a67d8
--- /dev/null
+++ b/utils/domutils.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "domutils.h"
+
+/* search children of a node for first named element */
+dom_node *find_first_named_dom_element(dom_node *parent, lwc_string *element_name)
+{
+ dom_node *element;
+ dom_exception exc;
+ dom_string *node_name = NULL;
+ dom_node_type node_type;
+ dom_node *next_node;
+
+ exc = dom_node_get_first_child(parent, &element);
+ if ((exc != DOM_NO_ERR) || (element == NULL)) {
+ return NULL;
+ }
+
+ /* find first node thats a element */
+ do {
+ exc = dom_node_get_node_type(element, &node_type);
+
+ if ((exc != DOM_NO_ERR) || (node_type == DOM_ELEMENT_NODE)) {
+ exc = dom_node_get_node_name(element, &node_name);
+ if ((exc == DOM_NO_ERR) || (node_name != NULL)) {
+ if (dom_string_caseless_lwc_isequal(node_name,
+ element_name)) {
+ dom_string_unref(node_name);
+ break;
+ }
+ dom_string_unref(node_name);
+ }
+ }
+
+ exc = dom_node_get_next_sibling(element, &next_node);
+ dom_node_unref(element);
+ if (exc == DOM_NO_ERR) {
+ element = next_node;
+ } else {
+ element = NULL;
+ }
+ } while (element != NULL);
+
+ return element;
+}
diff --git a/utils/domutils.h b/utils/domutils.h
new file mode 100644
index 000000000..ecdf2bc4a
--- /dev/null
+++ b/utils/domutils.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NETSURF_UTILS_DOMUTILS_H_
+#define _NETSURF_UTILS_DOMUTILS_H_
+
+dom_node *find_first_named_dom_element(dom_node *parent, lwc_string *element_name);
+
+#endif