r10731 tlsa - /trunk/netsurf/render/html_redraw.c
by netsurf@semichrome.net
Author: tlsa
Date: Mon Aug 30 17:43:01 2010
New Revision: 10731
URL: http://source.netsurf-browser.org?rev=10731&view=rev
Log:
Redraw object scrollbars if required.
Modified:
trunk/netsurf/render/html_redraw.c
Modified: trunk/netsurf/render/html_redraw.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/html_redraw.c?rev=...
==============================================================================
--- trunk/netsurf/render/html_redraw.c (original)
+++ trunk/netsurf/render/html_redraw.c Mon Aug 30 17:43:01 2010
@@ -704,17 +704,18 @@
return false;
/* scrollbars */
- if (current_redraw_browser && box->style && box->type != BOX_BR &&
+ if (current_redraw_browser && ((box->style && box->type != BOX_BR &&
box->type != BOX_TABLE && box->type != BOX_INLINE &&
(css_computed_overflow(box->style) ==
CSS_OVERFLOW_SCROLL ||
css_computed_overflow(box->style) ==
- CSS_OVERFLOW_AUTO)) {
+ CSS_OVERFLOW_AUTO)) || (box->object &&
+ content_get_type(box->object) == CONTENT_HTML))) {
has_x_scroll = box_hscrollbar_present(box);
has_y_scroll = box_vscrollbar_present(box);
- if (!box_handle_scrollbars(current_redraw_browser,box,
+ if (!box_handle_scrollbars(current_redraw_browser, box,
has_x_scroll, has_y_scroll))
return false;
13 years
r10730 tlsa - /trunk/netsurf/render/layout.c
by netsurf@semichrome.net
Author: tlsa
Date: Mon Aug 30 17:30:43 2010
New Revision: 10730
URL: http://source.netsurf-browser.org?rev=10730&view=rev
Log:
Fix object descendants and make space for scrollbars if required.
Modified:
trunk/netsurf/render/layout.c
Modified: trunk/netsurf/render/layout.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/layout.c?rev=10730...
==============================================================================
--- trunk/netsurf/render/layout.c (original)
+++ trunk/netsurf/render/layout.c Mon Aug 30 17:30:43 2010
@@ -1009,7 +1009,9 @@
overflow = css_computed_overflow(box->style);
- if (overflow == CSS_OVERFLOW_SCROLL || overflow == CSS_OVERFLOW_AUTO) {
+ if (overflow == CSS_OVERFLOW_SCROLL || overflow == CSS_OVERFLOW_AUTO ||
+ (box->object &&
+ content_get_type(box->object) == CONTENT_HTML)) {
/* make space for scrollbars, unless height/width are AUTO */
if (which == BOTTOM && box->height != AUTO &&
(overflow == CSS_OVERFLOW_SCROLL ||
@@ -4496,6 +4498,13 @@
box->descendant_y1 = box->padding[TOP] + box->height +
box->padding[BOTTOM] + box->border[BOTTOM].width;
+ if (box->object && content_get_type(box->object) == CONTENT_HTML) {
+ if (box->descendant_x1 < content_get_width(box->object))
+ box->descendant_x1 = content_get_width(box->object);
+ if (box->descendant_y1 < content_get_height(box->object))
+ box->descendant_y1 = content_get_height(box->object);
+ }
+
if (box->type == BOX_INLINE || box->type == BOX_TEXT)
return;
13 years
r10729 tlsa - /trunk/netsurf/render/layout.c
by netsurf@semichrome.net
Author: tlsa
Date: Mon Aug 30 17:09:49 2010
New Revision: 10729
URL: http://source.netsurf-browser.org?rev=10729&view=rev
Log:
Don't special case height to content height when object's content is HTML.
Modified:
trunk/netsurf/render/layout.c
Modified: trunk/netsurf/render/layout.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/layout.c?rev=10729...
==============================================================================
--- trunk/netsurf/render/layout.c (original)
+++ trunk/netsurf/render/layout.c Mon Aug 30 17:09:49 2010
@@ -809,8 +809,8 @@
if (content_get_type(block->object) == CONTENT_HTML) {
content_reformat(block->object, block->width, 1);
- block->height = content_get_height(block->object);
} else {
+ /* Non-HTML objects */
/* this case handled already in
* layout_block_find_dimensions() */
}
13 years
r10728 tlsa - /trunk/netsurf/render/html_redraw.c
by netsurf@semichrome.net
Author: tlsa
Date: Mon Aug 30 16:47:54 2010
New Revision: 10728
URL: http://source.netsurf-browser.org?rev=10728&view=rev
Log:
Fix clipping to exclude border for objects.
Modified:
trunk/netsurf/render/html_redraw.c
Modified: trunk/netsurf/render/html_redraw.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/html_redraw.c?rev=...
==============================================================================
--- trunk/netsurf/render/html_redraw.c (original)
+++ trunk/netsurf/render/html_redraw.c Mon Aug 30 16:47:54 2010
@@ -625,9 +625,10 @@
return false;
}
- /* clip to the padding edge for boxes with overflow hidden or scroll */
- if (box->style && css_computed_overflow(box->style) !=
- CSS_OVERFLOW_VISIBLE) {
+ /* clip to the padding edge for objects, or boxes with overflow hidden
+ * or scroll */
+ if (box->object || (box->style && css_computed_overflow(box->style) !=
+ CSS_OVERFLOW_VISIBLE)) {
r.x0 = x;
r.y0 = y;
r.x1 = x + padding_width;
13 years
r10727 vince - in /branches/vince/netsurf-file-fetcher: Makefile.sources content/fetch.c content/fetchers/fetch_curl.c content/fetchers/fetch_file.c content/fetchers/fetch_file.h
by netsurf@semichrome.net
Author: vince
Date: Mon Aug 30 15:50:49 2010
New Revision: 10727
URL: http://source.netsurf-browser.org?rev=10727&view=rev
Log:
simple first pass at file fetcher implementation
Added:
branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.c
branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.h
Modified:
branches/vince/netsurf-file-fetcher/Makefile.sources
branches/vince/netsurf-file-fetcher/content/fetch.c
branches/vince/netsurf-file-fetcher/content/fetchers/fetch_curl.c
Modified: branches/vince/netsurf-file-fetcher/Makefile.sources
URL: http://source.netsurf-browser.org/branches/vince/netsurf-file-fetcher/Mak...
==============================================================================
--- branches/vince/netsurf-file-fetcher/Makefile.sources (original)
+++ branches/vince/netsurf-file-fetcher/Makefile.sources Mon Aug 30 15:50:49 2010
@@ -6,7 +6,7 @@
#
S_CONTENT := content.c fetch.c hlcache.c llcache.c urldb.c \
- fetchers/fetch_curl.c fetchers/fetch_data.c
+ fetchers/fetch_curl.c fetchers/fetch_data.c fetchers/fetch_file.c
S_CSS := css.c dump.c internal.c select.c utils.c
S_RENDER := box.c box_construct.c box_normalise.c directory.c favicon.c \
font.c form.c html.c html_interaction.c html_redraw.c \
Modified: branches/vince/netsurf-file-fetcher/content/fetch.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-file-fetcher/con...
==============================================================================
--- branches/vince/netsurf-file-fetcher/content/fetch.c (original)
+++ branches/vince/netsurf-file-fetcher/content/fetch.c Mon Aug 30 15:50:49 2010
@@ -38,6 +38,7 @@
#include "content/fetch.h"
#include "content/fetchers/fetch_curl.h"
#include "content/fetchers/fetch_data.h"
+#include "content/fetchers/fetch_file.h"
#include "content/urldb.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
@@ -106,6 +107,7 @@
{
fetch_curl_register();
fetch_data_register();
+ fetch_file_register();
fetch_active = false;
}
Modified: branches/vince/netsurf-file-fetcher/content/fetchers/fetch_curl.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-file-fetcher/con...
==============================================================================
--- branches/vince/netsurf-file-fetcher/content/fetchers/fetch_curl.c (original)
+++ branches/vince/netsurf-file-fetcher/content/fetchers/fetch_curl.c Mon Aug 30 15:50:49 2010
@@ -217,7 +217,10 @@
data = curl_version_info(CURLVERSION_NOW);
- for (i = 0; data->protocols[i]; i++)
+ for (i = 0; data->protocols[i]; i++) {
+ if (strcmp(data->protocols[i], "file") == 0)
+ continue; /* do not use curl for file: */
+
if (!fetch_add_fetcher(data->protocols[i],
fetch_curl_initialise,
fetch_curl_setup,
@@ -229,6 +232,7 @@
LOG(("Unable to register cURL fetcher for %s",
data->protocols[i]));
}
+ }
return;
curl_easy_setopt_failed:
@@ -1153,64 +1157,6 @@
messages_get("Not2xx"), 0,
FETCH_ERROR_HTTP_NOT2);
return true;
- }
-
- /* find MIME type from filetype for local files */
- if (strncmp(f->url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN) == 0) {
- struct stat s;
- char *url_path = url_to_path(f->url);
-
- LOG(("Obtaining mime type for file %s", url_path));
-
- if (url_path != NULL && stat(url_path, &s) == 0) {
- /* file: URL and file exists */
- char header[64];
- const char *type;
-
- /* create etag */
- snprintf(header, sizeof header,
- "ETag: \"%10" PRId64 "\"",
- (int64_t) s.st_mtime);
- /* And send it to the header handler */
- fetch_send_callback(FETCH_HEADER, f->fetch_handle,
- header, strlen(header),
- FETCH_ERROR_NO_ERROR);
-
- /* create Content-Type */
- type = fetch_filetype(url_path);
- snprintf(header, sizeof header,
- "Content-Type: %s", type);
- /* Send it to the header handler */
- fetch_send_callback(FETCH_HEADER, f->fetch_handle,
- header, strlen(header),
- FETCH_ERROR_NO_ERROR);
-
- /* create Content-Length */
- snprintf(header, sizeof header,
- "Content-Length: %" PRId64,
- (int64_t) s.st_size);
- /* Send it to the header handler */
- fetch_send_callback(FETCH_HEADER, f->fetch_handle,
- header, strlen(header),
- FETCH_ERROR_NO_ERROR);
-
- /* don't set last modified time so as to ensure that
- * local files are revalidated at all times. */
-
- /* Report not modified, if appropriate */
- if (f->last_modified && f->file_etag &&
- f->last_modified > s.st_mtime &&
- f->file_etag == s.st_mtime) {
- fetch_send_callback(FETCH_NOTMODIFIED,
- f->fetch_handle, 0, 0,
- FETCH_ERROR_NO_ERROR);
- free(url_path);
- return true;
- }
- }
-
- if (url_path != NULL)
- free(url_path);
}
if (f->abort)
Added: branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-file-fetcher/con...
==============================================================================
--- branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.c (added)
+++ branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.c Mon Aug 30 15:50:49 2010
@@ -1,0 +1,510 @@
+/*
+ * Copyright 2010 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * 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/>.
+ */
+
+/* file: URL handling. Based on the data fetcher by Rob Kendrik */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <string.h>
+#include <strings.h>
+#include <time.h>
+#include <stdio.h>
+#include <dirent.h>
+
+#include "utils/config.h"
+#include "content/fetch.h"
+#include "content/fetchers/fetch_file.h"
+#include "content/urldb.h"
+#include "desktop/netsurf.h"
+#include "desktop/options.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/url.h"
+#include "utils/utils.h"
+#include "utils/ring.h"
+#include "utils/base64.h"
+
+/** Context for a fetch */
+struct fetch_file_context {
+ struct fetch_file_context *r_next, *r_prev;
+
+ struct fetch *parent_fetch;
+
+ bool aborted; /**< Flag indicating fetch has been aborted */
+ bool locked; /* Flag indicating entry is already entered */
+
+ char *path;
+ char *mimetype;
+ char *data;
+};
+
+static struct fetch_file_context *ring = NULL;
+
+/** callback to initialise the file fetcher. */
+static bool fetch_file_initialise(const char *scheme)
+{
+ LOG(("fetch_file_initialise called for %s", scheme));
+ return true;
+}
+
+/** callback to initialise the file fetcher. */
+static void fetch_file_finalise(const char *scheme)
+{
+ LOG(("fetch_file_finalise called for %s", scheme));
+}
+
+/** callback to set up a file fetch context. */
+static void *
+fetch_file_setup(struct fetch *parent_fetch,
+ const char *url,
+ bool only_2xx,
+ const char *post_urlenc,
+ const struct fetch_multipart_data *post_multipart,
+ const char **headers)
+{
+ struct fetch_file_context *ctx = calloc(1, sizeof(*ctx));
+
+ if (ctx == NULL)
+ return NULL;
+
+ ctx->parent_fetch = parent_fetch;
+ url_path(url, &ctx->path);
+
+ if (ctx->path == NULL) {
+ free(ctx);
+ return NULL;
+ }
+
+ RING_INSERT(ring, ctx);
+
+ LOG(("created context %p from parent fetch %p, url %s, only_2xx %d, post_urlenc %s, post_multipart %p, headers %p", ctx,parent_fetch,url, only_2xx,post_urlenc,post_multipart,headers));
+
+ return ctx;
+}
+
+/** callback to free a file fetch */
+static void fetch_file_free(void *ctx)
+{
+ struct fetch_file_context *c = ctx;
+ LOG(("context %p",ctx));
+
+ free(c->path);
+ free(c->data);
+ free(c->mimetype);
+ RING_REMOVE(ring, c);
+ free(ctx);
+}
+
+/** callback to start a file fetch */
+static bool fetch_file_start(void *ctx)
+{
+ LOG(("context %p",ctx));
+ return true;
+}
+
+/** callback to abort a file fetch */
+static void fetch_file_abort(void *ctx)
+{
+ struct fetch_file_context *c = ctx;
+ LOG(("context %p",ctx));
+
+ /* To avoid the poll loop having to deal with the fetch context
+ * disappearing from under it, we simply flag the abort here.
+ * The poll loop itself will perform the appropriate cleanup.
+ */
+ c->aborted = true;
+}
+
+static void fetch_file_send_callback(fetch_msg msg,
+ struct fetch_file_context *c, const void *data,
+ unsigned long size, fetch_error_code errorcode)
+{
+ c->locked = true;
+ fetch_send_callback(msg, c->parent_fetch, data, size, errorcode);
+ c->locked = false;
+}
+
+/* process a file fetch */
+static void fetch_file_process(struct fetch_file_context *ctx)
+{
+ int filefd;
+ struct stat filestat;
+ char header[64];
+ int res;
+
+ filefd = open(ctx->path, O_RDONLY);
+ if (filefd < 0) {
+ /* find error and set headers */
+ return;
+ }
+
+ if (fstat(filefd, &filestat) != 0) {
+ /* find error and set headers */
+ close(filefd);
+ return;
+ }
+
+ if (S_ISDIR(filestat.st_mode)) {
+ /* directory listing */
+ DIR *scandir;
+ struct dirent* ent;
+
+ /* fetch is going to be successful */
+ fetch_set_http_code(ctx->parent_fetch, 200);
+
+ /* content type */
+ snprintf(header, sizeof header, "Content-Type: text/html");
+ fetch_file_send_callback(FETCH_HEADER, ctx, header, strlen(header), FETCH_ERROR_NO_ERROR);
+
+ scandir = fdopendir(filefd);
+
+ while ((ent = readdir(scandir)) != NULL) {
+ snprintf(header, sizeof header, "<p>%s</p>", ent->d_name);
+
+ fetch_file_send_callback(FETCH_DATA,
+ ctx, header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+ }
+
+ closedir(scandir);
+
+ fetch_file_send_callback(FETCH_FINISHED, ctx, 0, 0, FETCH_ERROR_NO_ERROR);
+
+ return;
+ }
+
+ if (!S_ISREG(filestat.st_mode)) {
+ /* not a file respose */
+ close(filefd);
+ return;
+ }
+
+ /* just a plain old file */
+
+ ctx->data = malloc(filestat.st_size);
+ if (ctx->data == NULL) {
+ fetch_file_send_callback(FETCH_ERROR, ctx,
+ "Unable to allocate memory for file data",
+ 0, FETCH_ERROR_MEMORY);
+ return;
+ }
+
+ res = read(filefd, ctx->data, filestat.st_size);
+ if (res != filestat.st_size) {
+ fetch_file_send_callback(FETCH_ERROR, ctx,
+ "Unable to read file",
+ 0, FETCH_ERROR_MEMORY);
+ return;
+ }
+
+ ctx->mimetype = strdup(fetch_filetype(ctx->path));
+
+ LOG(("setting MIME type to %s, length to %zd",
+ ctx->mimetype, filestat.st_size));
+
+ /* fetch is going to be successful */
+ fetch_set_http_code(ctx->parent_fetch, 200);
+
+ /* Any callback can result in the fetch being aborted.
+ * Therefore, we _must_ check for this after _every_ call to
+ * fetch_file_send_callback().
+ */
+
+ /* content type */
+ snprintf(header, sizeof header, "Content-Type: %s", ctx->mimetype);
+ fetch_file_send_callback(FETCH_HEADER, ctx, header, strlen(header), FETCH_ERROR_NO_ERROR);
+
+ if (ctx->aborted)
+ goto fetch_file_process_aborted;
+
+ /* content length */
+ snprintf(header, sizeof header, "Content-Length: %zd",filestat.st_size);
+ fetch_file_send_callback(FETCH_HEADER, ctx, header, strlen(header), FETCH_ERROR_NO_ERROR);
+
+ if (ctx->aborted)
+ goto fetch_file_process_aborted;
+
+ /* create etag */
+ snprintf(header, sizeof header, "ETag: \"%10" PRId64 "\"", (int64_t) filestat.st_mtime);
+ fetch_file_send_callback(FETCH_HEADER, ctx, header, strlen(header), FETCH_ERROR_NO_ERROR);
+
+ if (ctx->aborted)
+ goto fetch_file_process_aborted;
+
+ fetch_file_send_callback(FETCH_DATA,
+ ctx, ctx->data, filestat.st_size,
+ FETCH_ERROR_NO_ERROR);
+
+ if (ctx->aborted)
+ goto fetch_file_process_aborted;
+
+ fetch_file_send_callback(FETCH_FINISHED, ctx, 0, 0, FETCH_ERROR_NO_ERROR);
+
+fetch_file_process_aborted:
+
+ close(filefd);
+ return;
+
+#ifdef curl_file_mimetype
+ /* find MIME type from filetype for local files */
+ if (strncmp(f->url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN) == 0) {
+ struct stat s;
+ char *url_path = url_to_path(f->url);
+
+ LOG(("Obtaining mime type for file %s", url_path));
+
+ if (url_path != NULL && stat(url_path, &s) == 0) {
+ /* file: URL and file exists */
+ char header[64];
+ const char *type;
+
+ /* create etag */
+ snprintf(header, sizeof header,
+ "ETag: \"%10" PRId64 "\"",
+ (int64_t) s.st_mtime);
+ /* And send it to the header handler */
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+ header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+
+ /* create Content-Type */
+ type = fetch_filetype(url_path);
+ snprintf(header, sizeof header,
+ "Content-Type: %s", type);
+ /* Send it to the header handler */
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+ header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+
+ /* create Content-Length */
+ snprintf(header, sizeof header,
+ "Content-Length: %" PRId64,
+ (int64_t) s.st_size);
+ /* Send it to the header handler */
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+ header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+
+ /* don't set last modified time so as to ensure that
+ * local files are revalidated at all times. */
+
+ /* Report not modified, if appropriate */
+ if (f->last_modified && f->file_etag &&
+ f->last_modified > s.st_mtime &&
+ f->file_etag == s.st_mtime) {
+ fetch_send_callback(FETCH_NOTMODIFIED,
+ f->fetch_handle, 0, 0,
+ FETCH_ERROR_NO_ERROR);
+ free(url_path);
+ return true;
+ }
+ }
+
+ if (url_path != NULL)
+ free(url_path);
+ }
+#endif
+#ifdef eeek
+ char *params;
+ char *comma;
+ char *unescaped;
+ int templen;
+
+ /* format of a data: URL is:
+ * data:[<mimetype>][;base64],<data>
+ * The mimetype is optional. If it is missing, the , before the
+ * data must still be there.
+ */
+ /* Only processO_RDONLY, non-aborted fetches */
+ if (!c->aborted && fetch_file_process(c) == true) {
+ char header[64];
+
+ fetch_set_http_code(c->parent_fetch, 200);
+ LOG(("setting data: MIME type to %s, length to %zd",
+ c->mimetype, c->datalen));
+ /* Any callback can result in the fetch being aborted.
+ * Therefore, we _must_ check for this after _every_
+ * call to fetch_file_send_callback().
+ */
+ snprintf(header, sizeof header, "Content-Type: %s",
+ c->mimetype);
+ fetch_file_send_callback(FETCH_HEADER, c, header,
+ strlen(header), FETCH_ERROR_NO_ERROR);
+
+ snprintf(header, sizeof header, "Content-Length: %zd",
+ c->datalen);
+ fetch_file_send_callback(FETCH_HEADER, c, header,
+ strlen(header), FETCH_ERROR_NO_ERROR);
+
+ if (!c->aborted) {
+ fetch_file_send_callback(FETCH_DATA,
+ c, c->data, c->datalen,
+ FETCH_ERROR_NO_ERROR);
+ }
+ if (!c->aborted) {
+ fetch_file_send_callback(FETCH_FINISHED,
+ c, 0, 0, FETCH_ERROR_NO_ERROR);
+ }
+ } else {
+ LOG(("Processing of %s failed!", c->path));
+
+ /* Ensure that we're unlocked here. If we aren't,
+ * then fetch_file_process() is broken.
+ */
+ assert(c->locked == false);
+ }
+
+
+ LOG(("*** Processing %s", c->path));
+ if (strlen(c->url) < 6) {
+ /* 6 is the minimum possible length (data:,) */
+ fetch_file_send_callback(FETCH_ERROR, c,
+ "Malformed data: URL", 0, FETCH_ERROR_URL);
+ return false;
+ }
+
+ /* skip the data: part */
+ params = c->url + SLEN("data:");
+
+ /* find the comma */
+ if ( (comma = strchr(params, ',')) == NULL) {
+ fetch_file_send_callback(FETCH_ERROR, c,
+ "Malformed data: URL", 0, FETCH_ERROR_URL);
+ return false;
+ }
+
+ if (params[0] == ',') {
+ /* there is no mimetype here, assume text/plain */
+ c->mimetype = strdup("text/plain;charset=US-ASCII");
+ } else {
+ /* make a copy of everything between data: and the comma */
+ c->mimetype = strndup(params, comma - params);
+ }
+
+ if (c->mimetype == NULL) {
+ fetch_file_send_callback(FETCH_ERROR, c,
+ "Unable to allocate memory for mimetype in data: URL",
+ 0, FETCH_ERROR_MEMORY);
+ return false;
+ }
+
+ if (strcmp(c->mimetype + strlen(c->mimetype) - 7, ";base64") == 0) {
+ c->base64 = true;
+ c->mimetype[strlen(c->mimetype) - 7] = '\0';
+ } else {
+ c->base64 = false;
+ }
+
+ /* we URL unescape the data first, just incase some insane page
+ * decides to nest URL and base64 encoding. Like, say, Acid2.
+ */
+ templen = c->datalen;
+ unescaped = curl_easy_unescape(curl, comma + 1, 0, &templen);
+ c->datalen = templen;
+ if (unescaped == NULL) {
+ fetch_file_send_callback(FETCH_ERROR, c,
+ "Unable to URL decode data: URL", 0,
+ FETCH_ERROR_ENCODING);
+ return false;
+ }
+
+ if (c->base64) {
+ c->data = malloc(c->datalen); /* safe: always gets smaller */
+ if (base64_decode(unescaped, c->datalen, c->data,
+ &(c->datalen)) == false) {
+ fetch_file_send_callback(FETCH_ERROR, c,
+ "Unable to Base64 decode data: URL", 0,
+ FETCH_ERROR_ENCODING);
+ curl_free(unescaped);
+ return false;
+ }
+ } else {
+ c->data = malloc(c->datalen);
+ if (c->data == NULL) {
+ fetch_file_send_callback(FETCH_ERROR, c,
+ "Unable to allocate memory for data: URL", 0,
+ FETCH_ERROR_MEMORY);
+ curl_free(unescaped);
+ return false;
+ }
+ memcpy(c->data, unescaped, c->datalen);
+ }
+
+ curl_free(unescaped);
+#endif
+}
+
+/** callback to poll for additional file fetch contents */
+static void fetch_file_poll(const char *scheme)
+{
+ struct fetch_file_context *c, *next;
+
+ if (ring == NULL) return;
+
+ /* Iterate over ring, processing each pending fetch */
+ c = ring;
+ do {
+ /* Take a copy of the next pointer as we may destroy
+ * the ring item we're currently processing */
+ next = c->r_next;
+
+ /* Ignore fetches that have been flagged as locked.
+ * This allows safe re-entrant calls to this function.
+ * Re-entrancy can occur if, as a result of a callback,
+ * the interested party causes fetch_poll() to be called
+ * again.
+ */
+ if (c->locked == true) {
+ continue;
+ }
+
+ LOG(("polling unlocked context %p",c));
+
+ /* Only process non-aborted fetches */
+ if (!c->aborted) {
+ /* file fetchs can be processed in one go */
+ fetch_file_process(c);
+ }
+
+
+ fetch_remove_from_queues(c->parent_fetch);
+ fetch_free(c->parent_fetch);
+
+ /* Advance to next ring entry, exiting if we've reached
+ * the start of the ring or the ring has become empty
+ */
+ } while ( (c = next) != ring && ring != NULL);
+}
+
+void fetch_file_register(void)
+{
+ fetch_add_fetcher("file",
+ fetch_file_initialise,
+ fetch_file_setup,
+ fetch_file_start,
+ fetch_file_abort,
+ fetch_file_free,
+ fetch_file_poll,
+ fetch_file_finalise);
+}
Added: branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-file-fetcher/con...
==============================================================================
--- branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.h (added)
+++ branches/vince/netsurf-file-fetcher/content/fetchers/fetch_file.h Mon Aug 30 15:50:49 2010
@@ -1,0 +1,28 @@
+/*
+ * Copyright 2010 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * 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/>.
+ */
+
+/** \file
+ * file: URL method handler
+ */
+
+#ifndef NETSURF_CONTENT_FETCHERS_FETCH_FILE_H
+#define NETSURF_CONTENT_FETCHERS_FETCH_FILE_H
+
+void fetch_file_register(void);
+
+#endif
13 years
r10725 jmb - /trunk/dom/src/core/characterdata.c
by netsurf@semichrome.net
Author: jmb
Date: Mon Aug 30 08:39:49 2010
New Revision: 10725
URL: http://source.netsurf-browser.org?rev=10725&view=rev
Log:
Jump through hoops to conform to the spec: apparently, it requires unsigned values to be considered as signed
Modified:
trunk/dom/src/core/characterdata.c
Modified: trunk/dom/src/core/characterdata.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.c?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.c (original)
+++ trunk/dom/src/core/characterdata.c Mon Aug 30 08:39:49 2010
@@ -179,8 +179,9 @@
* \param count The number of characters to extract
* \param data Pointer to location to receive substring
* \return DOM_NO_ERR on success,
- * DOM_INDEX_SIZE_ERR if ::offset is greater than the number of
- * characters in ::cdata.
+ * DOM_INDEX_SIZE_ERR if ::offset is negative or greater than the
+ * number of characters in ::cdata or
+ * ::count is negative.
*
* The returned string will have its reference count increased. It is
* the responsibility of the caller to unref the string once it has
@@ -195,6 +196,10 @@
{
struct dom_node_internal *c = (struct dom_node_internal *) cdata;
uint32_t len, end;
+
+ if ((signed long) offset < 0 || (signed long) count < 0) {
+ return DOM_INDEX_SIZE_ERR;
+ }
if (c->value != NULL) {
len = dom_string_length(c->value);
@@ -260,8 +265,9 @@
* \param offset The character offset to insert at
* \param data The data to insert
* \return DOM_NO_ERR on success,
- * DOM_INDEX_SIZE_ERR if ::offset is greater than the
- * number of characters in ::cdata,
+ * DOM_INDEX_SIZE_ERR if ::offset is negative or greater
+ * than the number of characters in
+ * ::cdata,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
dom_exception _dom_characterdata_insert_data(struct dom_characterdata *cdata,
@@ -274,6 +280,10 @@
if (_dom_node_readonly(c)) {
return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if ((signed long) offset < 0) {
+ return DOM_INDEX_SIZE_ERR;
}
if (c->value != NULL) {
@@ -316,8 +326,9 @@
* \param offset The character offset to start deletion from
* \param count The number of characters to delete
* \return DOM_NO_ERR on success,
- * DOM_INDEX_SIZE_ERR if ::offset is greater than the
- * number of characters in ::cdata,
+ * DOM_INDEX_SIZE_ERR if ::offset is negative or greater
+ * than the number of characters in
+ * ::cdata or ::count is negative,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
dom_exception _dom_characterdata_delete_data(struct dom_characterdata *cdata,
@@ -330,6 +341,10 @@
if (_dom_node_readonly(c)) {
return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if ((signed long) offset < 0 || (signed long) count < 0) {
+ return DOM_INDEX_SIZE_ERR;
}
if (c->value != NULL) {
@@ -375,8 +390,9 @@
* \param count The number of characters to replace
* \param data The replacement data
* \return DOM_NO_ERR on success,
- * DOM_INDEX_SIZE_ERR if ::offset is greater than the
- * number of characters in ::cdata,
+ * DOM_INDEX_SIZE_ERR if ::offset is negative or greater
+ * than the number of characters in
+ * ::cdata or ::count is negative,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
dom_exception _dom_characterdata_replace_data(struct dom_characterdata *cdata,
@@ -390,6 +406,10 @@
if (_dom_node_readonly(c)) {
return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if ((signed long) offset < 0 || (signed long) count < 0) {
+ return DOM_INDEX_SIZE_ERR;
}
if (c->value != NULL) {
13 years
r10724 jmb - in /trunk/dom: ./ include/dom/bootstrap/ include/dom/core/ include/dom/events/ include/dom/html/ src/bootstrap/ src/core/ src/events/ src/html/
by netsurf@semichrome.net
Author: jmb
Date: Mon Aug 30 08:06:19 2010
New Revision: 10724
URL: http://source.netsurf-browser.org?rev=10724&view=rev
Log:
Merge branches/struggleyb/libdom-html to trunk.
A few additional fixes to reduce the number of regressions to single figures.
Added:
trunk/dom/include/dom/html/
- copied from r10721, branches/struggleyb/libdom-html/include/dom/html/
trunk/dom/src/html/
- copied from r10721, branches/struggleyb/libdom-html/src/html/
Modified:
trunk/dom/Makefile
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/include/dom/core/attr.h
trunk/dom/include/dom/core/exceptions.h
trunk/dom/include/dom/events/document_event.h
trunk/dom/include/dom/html/html_document.h
trunk/dom/src/bootstrap/implementation.c
trunk/dom/src/core/attr.c
trunk/dom/src/core/attr.h
trunk/dom/src/core/document.c
trunk/dom/src/core/document.h
trunk/dom/src/core/document_type.c
trunk/dom/src/core/document_type.h
trunk/dom/src/core/element.c
trunk/dom/src/core/element.h
trunk/dom/src/core/node.c
trunk/dom/src/core/node.h
trunk/dom/src/events/event_target.c
trunk/dom/src/events/event_target.h
trunk/dom/src/html/Makefile
trunk/dom/src/html/html_document.c
trunk/dom/src/html/html_document.h
trunk/dom/src/html/html_element.c
Modified: trunk/dom/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/Makefile?rev=10724&r1=10723&r...
==============================================================================
--- trunk/dom/Makefile (original)
+++ trunk/dom/Makefile Mon Aug 30 08:06:19 2010
@@ -14,7 +14,7 @@
-Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Wnested-externs -Werror -pedantic
CFLAGS := -std=c99 -D_BSD_SOURCE -I$(CURDIR)/include/ \
- -I$(CURDIR)/src $(WARNFLAGS) $(CFLAGS)
+ -I$(CURDIR)/src -I$(CURDIR)/binding $(WARNFLAGS) $(CFLAGS)
# Parserutils & wapcaplet
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Mon Aug 30 08:06:19 2010
@@ -243,21 +243,4 @@
/* Register a source with the DOM library */
dom_exception dom_register_source(struct dom_implementation_source *source);
-/* Create a DOM document */
-dom_exception dom_document_create(struct dom_implementation *impl,
- dom_alloc alloc, void *pw,
- dom_events_default_action_fetcher daf,
- struct dom_document **doc);
-
-/* Set a document's buffer */
-void dom_document_set_buffer(struct dom_document *doc, uint8_t *buffer,
- size_t buffer_len);
-
-/* Create a DOM document type */
-dom_exception dom_document_type_create(struct dom_string *qname,
- struct dom_string *public_id,
- struct dom_string *system_id,
- dom_alloc alloc, void *pw,
- struct dom_document_type **doctype);
-
#endif
Modified: trunk/dom/include/dom/core/attr.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/attr.h?rev=1...
==============================================================================
--- trunk/dom/include/dom/core/attr.h (original)
+++ trunk/dom/include/dom/core/attr.h Mon Aug 30 08:06:19 2010
@@ -20,6 +20,17 @@
struct dom_string;
typedef struct dom_attr dom_attr;
+
+/**
+ * The attribute type
+ */
+typedef enum {
+ DOM_ATTR_UNSET = 0,
+ DOM_ATTR_STRING,
+ DOM_ATTR_BOOL,
+ DOM_ATTR_SHORT,
+ DOM_ATTR_INTEGER
+} dom_attr_type;
/* DOM Attr vtable */
typedef struct dom_attr_vtable {
@@ -102,4 +113,39 @@
#define dom_attr_is_id(a, r) dom_attr_is_id((struct dom_attr *) (a), \
(bool *) (r))
+/*-----------------------------------------------------------------------*/
+/**
+ * Following are our implementation specific APIs.
+ *
+ * These APIs are defined for the purpose that there are some attributes in
+ * HTML and other DOM module whose type is not DOMString, but unsigned long or
+ * boolean, for those types of attributes, clients should call one of the
+ * following APIs to set it.
+ *
+ * When an Attr node is created, its type is unset and it can be turned into
+ * any of the four types. Once the type is fixed by calling any of the four
+ * APIs:
+ * dom_attr_set_value
+ * dom_attr_set_integer
+ * dom_attr_set_short
+ * dom_attr_set_bool
+ * it can't be modified in future.
+ *
+ * For integer/short/bool type of attributes, we provide no string
+ * repensentation of them, so when you call dom_attr_get_value on these
+ * three type of attribute nodes, you will always get a empty dom_string.
+ * If you want to do something with Attr node, you must know its type
+ * firstly by calling dom_attr_get_type before you decide to call other
+ * dom_attr_get_* functions.
+ */
+dom_attr_type dom_attr_get_type(dom_attr *a);
+dom_exception dom_attr_get_integer(dom_attr *a, unsigned long *value);
+dom_exception dom_attr_set_integer(dom_attr *a, unsigned long value);
+dom_exception dom_attr_get_short(dom_attr *a, unsigned short *value);
+dom_exception dom_attr_set_short(dom_attr *a, unsigned short value);
+dom_exception dom_attr_get_bool(dom_attr *a, bool *value);
+dom_exception dom_attr_set_bool(dom_attr *a, bool value);
+/* Make a attribute node readonly */
+void dom_attr_mark_readonly(dom_attr *a);
+
#endif
Modified: trunk/dom/include/dom/core/exceptions.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/exceptions.h...
==============================================================================
--- trunk/dom/include/dom/core/exceptions.h (original)
+++ trunk/dom/include/dom/core/exceptions.h Mon Aug 30 08:06:19 2010
@@ -44,7 +44,8 @@
DOM_UNSPECIFIED_EVENT_TYPE_ERR = DOM_EXCEPTION_CLASS_EVENT + 0,
DOM_DISPATCH_REQUEST_ERR = DOM_EXCEPTION_CLASS_EVENT + 1,
- DOM_NO_MEM_ERR = DOM_EXCEPTION_CLASS_INTERNAL + 0
+ DOM_NO_MEM_ERR = DOM_EXCEPTION_CLASS_INTERNAL + 0,
+ DOM_ATTR_WRONG_TYPE_ERR = DOM_EXCEPTION_CLASS_INTERNAL + 1
/* our own internal error */
} dom_exception;
Modified: trunk/dom/include/dom/events/document_event.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/events/document_e...
==============================================================================
--- trunk/dom/include/dom/events/document_event.h (original)
+++ trunk/dom/include/dom/events/document_event.h Mon Aug 30 08:06:19 2010
@@ -7,6 +7,8 @@
#ifndef dom_events_document_event_h_
#define dom_events_document_event_h_
+
+#include <stdbool.h>
#include <dom/core/exceptions.h>
@@ -18,15 +20,68 @@
typedef struct dom_document dom_document_event;
/**
+ * The callback function which is used to process the default action of any
+ * event.
+ *
+ * As ::dom_default_action_phase defines, we have three points in our
+ * implementation where these kinds of callbacks get invoked.
+ *
+ * When the implementation start to dispatch certain event, it firstly invoke
+ * the following callback, which should process the event before the normal
+ * event flow.
+ *
+ * Take a MousePressed event on a check box object as example:
+ * 1. The 'pressed' event is generated by OS and catched by our UI code;
+ * 2. The UI code dispatch the event to DOM;
+ * 3. DOM trys to dispatch the event as what the spec said;
+ * 4. Before the real event flow happens, DOM get the
+ * dom_default_action_callback function from the
+ * dom_events_default_action_fetcher with param
+ * DOM_DEFAULT_ACTION_STARTED, and then call it;
+ * 5. The callback function invoke some System-denpendent API to make the
+ * checkbox checked and then return;
+ * 6. Normal event flow goes on.
+ * 7. When the implementation reach the end of the event flow, it check whether
+ * the event's default action is prevented, if it is, then go to step 8,
+ * else go to step 9.
+ * 8. The event's default action get prevented, DOM get the
+ * dom_default_action_callback function from the
+ * dom_events_default_action_fetcher with param
+ * DOM_DEFAULT_ACTION_PREVENTED, and then call it.
+ * 8. The event's default action does not get prevented, DOM get the
+ * dom_default_action_callback function from the
+ * dom_events_default_action_fetcher with param
+ * DOM_DEFAULT_ACTION_END, and then call it.
+ *
+ * @note: the point here is that we want the UI related stuff to be done
+ * within the default action code. The DOM only take care of the content tree
+ * and the event flow itself.
+ */
+typedef void (*dom_default_action_callback)(struct dom_event *evt, void *pw);
+
+/**
+ * The default action phase
+ *
+ * @note: we define the following three values to fetch three different types
+ * of dom_default_action_callback function and their private data.
+ */
+typedef enum {
+ DOM_DEFAULT_ACTION_STARTED = 0,
+ DOM_DEFAULT_ACTION_PREVENTED,
+ DOM_DEFAULT_ACTION_END
+} dom_default_action_phase;
+
+/**
* The default action fetcher
*
- * @note: When the implementation reach the end of the event flow, it will call
- * this function to get the default action handler. If it does not return a
- * NULL, the returned dom_event_listener will be invoked as the event is not
- * canceled.
+ * \param type The type of the event
+ * \param phase The phase of the default action callback
+ * \param pw The return privat data of the callback function
+ * \return a callback function, NULL if there is none.
*/
-typedef struct dom_event_listener *(*dom_events_default_action_fetcher)
- (struct lwc_string_s *name, struct lwc_string_s *type);
+typedef dom_default_action_callback (*dom_events_default_action_fetcher)
+ (struct lwc_string_s *type, dom_default_action_phase phase,
+ void **pw);
dom_exception _dom_document_event_create_event(dom_document_event *de,
struct dom_string *type, struct dom_event **evt);
Modified: trunk/dom/include/dom/html/html_document.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/html/html_documen...
==============================================================================
--- trunk/dom/include/dom/html/html_document.h (original)
+++ trunk/dom/include/dom/html/html_document.h Mon Aug 30 08:06:19 2010
@@ -12,8 +12,8 @@
#include <dom/functypes.h>
#include <dom/events/document_event.h>
-struct lwc_context_s;
struct dom_element;
+struct dom_html_collection;
struct dom_html_element;
struct dom_nodelist;
@@ -42,7 +42,7 @@
/* Create a HTMLDocument */
dom_exception dom_html_document_create(dom_alloc alloc, void *pw, dom_msg msg,
- void *msg_pw, struct lwc_context_s *ctx,
+ void *msg_pw,
dom_events_default_action_fetcher daf, dom_ui_handler ui,
dom_parser_type pt, dom_html_document **doc);
@@ -70,15 +70,15 @@
dom_exception dom_html_document_set_body(dom_html_document *doc,
struct dom_html_element *body);
dom_exception dom_html_document_get_images(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_applets(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_links(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_forms(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_anchors(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_cookie(dom_html_document *doc,
struct dom_string **cookie);
dom_exception dom_html_document_set_cookie(dom_html_document *doc,
Modified: trunk/dom/src/bootstrap/implementation.c
URL: http://source.netsurf-browser.org/trunk/dom/src/bootstrap/implementation....
==============================================================================
--- trunk/dom/src/bootstrap/implementation.c (original)
+++ trunk/dom/src/bootstrap/implementation.c Mon Aug 30 08:06:19 2010
@@ -23,6 +23,7 @@
#include <libwapcaplet/libwapcaplet.h>
#include "core/node.h"
+#include "core/document.h"
#include "core/document_type.h"
#include "utils/utils.h"
@@ -231,7 +232,7 @@
return DOM_NAMESPACE_ERR;
/* Create the doctype */
- err = dom_document_type_create(qname, public_id, system_id,
+ err = _dom_document_type_create(qname, public_id, system_id,
alloc, pw, &d);
if (err != DOM_NO_ERR)
return err;
@@ -308,7 +309,7 @@
}
/* Create document object */
- err = dom_document_create(impl, alloc, pw, daf, &d);
+ err = _dom_document_create(impl, alloc, pw, daf, &d);
if (err != DOM_NO_ERR)
return err;
Modified: trunk/dom/src/core/attr.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/attr.c?rev=10724&r1=...
==============================================================================
--- trunk/dom/src/core/attr.c (original)
+++ trunk/dom/src/core/attr.c Mon Aug 30 08:06:19 2010
@@ -19,12 +19,13 @@
#include "core/document.h"
#include "core/entity_ref.h"
#include "core/node.h"
+#include "core/element.h"
#include "utils/utils.h"
struct dom_element;
/**
- * DOM node attribute
+ * DOM attribute node
*/
struct dom_attr {
struct dom_node_internal base; /**< Base node */
@@ -35,6 +36,16 @@
struct dom_type_info *schema_type_info; /**< Type information */
bool is_id; /**< Whether this attribute is a ID attribute */
+
+ dom_attr_type type; /**< The type of this attribute */
+
+ union {
+ unsigned long lvalue;
+ unsigned short svalue;
+ bool bvalue;
+ } value; /**< The special type value of this attribute */
+
+ bool read_only; /**< Whether this attribute is readonly */
};
/* The vtable for dom_attr node */
@@ -62,7 +73,7 @@
* \param name The (local) name of the node to create
* \param namespace The namespace URI of the attribute, or NULL
* \param prefix The namespace prefix of the attribute, or NULL
- * \param specified Whtether this attribute is specified
+ * \param specified Whether this attribute is specified
* \param result Pointer to location to receive created attribute
* \return DOM_NO_ERR on success,
* DOM_NO_MEM_ERR on memory exhaustion.
@@ -127,6 +138,9 @@
a->specified = specified;
a->schema_type_info = NULL;
a->is_id = false;
+ /* The attribute type is unset when it is created */
+ a->type = DOM_ATTR_UNSET;
+ a->read_only = false;
*result = a;
@@ -165,6 +179,206 @@
_dom_document_alloc(doc, attr, 0);
}
+/*-----------------------------------------------------------------------*/
+/* Following are our implementation specific APIs */
+
+/**
+ * Get the Attr Node type
+ *
+ * \param a The attribute node
+ * \return the type
+ */
+dom_attr_type dom_attr_get_type(dom_attr *a)
+{
+ return a->type;
+}
+
+/**
+ * Get the integer value of this attribute
+ *
+ * \param a The attribute object
+ * \param value The returned value
+ * \return DOM_NO_ERR on success,
+ * DOM_ATTR_WRONG_TYPE_ERR if the attribute node is not a integer
+ * attribute
+ */
+dom_exception dom_attr_get_integer(dom_attr *a, unsigned long *value)
+{
+ if (a->type != DOM_ATTR_INTEGER)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ *value = a->value.lvalue;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Set the integer value of this attribute
+ *
+ * \param a The attribute object
+ * \param value The new value
+ * \return DOM_NO_ERR on success,
+ * DOM_ATTR_WRONG_TYPE_ERR if the attribute node is not a integer
+ * attribute
+ */
+dom_exception dom_attr_set_integer(dom_attr *a, unsigned long value)
+{
+ /* If this is the first set method, we should fix this attribute
+ * type */
+ if (a->type == DOM_ATTR_UNSET)
+ a->type = DOM_ATTR_INTEGER;
+
+ if (a->type != DOM_ATTR_INTEGER)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ if (a->value.lvalue == value)
+ return DOM_NO_ERR;
+
+ a->value.lvalue = value;
+
+ struct dom_document *doc = dom_node_get_owner(a);
+ struct dom_node_internal *ele = dom_node_get_parent(a);
+ bool success = true;
+ dom_exception err;
+ err = _dom_dispatch_attr_modified_event(doc, ele, NULL, NULL,
+ (dom_event_target *) a, NULL,
+ DOM_MUTATION_MODIFICATION, &success);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ success = true;
+ err = _dom_dispatch_subtree_modified_event(doc,
+ (dom_event_target *) a, &success);
+ return err;
+}
+
+/**
+ * Get the short value of this attribute
+ *
+ * \param a The attribute object
+ * \param value The returned value
+ * \return DOM_NO_ERR on success,
+ * DOM_ATTR_WRONG_TYPE_ERR if the attribute node is not a short
+ * attribute
+ */
+dom_exception dom_attr_get_short(dom_attr *a, unsigned short *value)
+{
+ if (a->type != DOM_ATTR_SHORT)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ *value = a->value.svalue;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Set the short value of this attribute
+ *
+ * \param a The attribute object
+ * \param value The new value
+ * \return DOM_NO_ERR on success,
+ * DOM_ATTR_WRONG_TYPE_ERR if the attribute node is not a short
+ * attribute
+ */
+dom_exception dom_attr_set_short(dom_attr *a, unsigned short value)
+{
+ /* If this is the first set method, we should fix this attribute
+ * type */
+ if (a->type == DOM_ATTR_UNSET)
+ a->type = DOM_ATTR_SHORT;
+
+ if (a->type != DOM_ATTR_SHORT)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ if (a->value.svalue == value)
+ return DOM_NO_ERR;
+
+ a->value.svalue = value;
+
+ struct dom_document *doc = dom_node_get_owner(a);
+ struct dom_node_internal *ele = dom_node_get_parent(a);
+ bool success = true;
+ dom_exception err;
+ err = _dom_dispatch_attr_modified_event(doc, ele, NULL, NULL,
+ (dom_event_target *) a, NULL,
+ DOM_MUTATION_MODIFICATION, &success);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ success = true;
+ err = _dom_dispatch_subtree_modified_event(doc,
+ (dom_event_target *) a, &success);
+ return err;
+}
+
+/**
+ * Get the bool value of this attribute
+ *
+ * \param a The attribute object
+ * \param value The returned value
+ * \return DOM_NO_ERR on success,
+ * DOM_ATTR_WRONG_TYPE_ERR if the attribute node is not a bool
+ * attribute
+ */
+dom_exception dom_attr_get_bool(dom_attr *a, bool *value)
+{
+ if (a->type != DOM_ATTR_BOOL)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ *value = a->value.bvalue;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Set the bool value of this attribute
+ *
+ * \param a The attribute object
+ * \param value The new value
+ * \return DOM_NO_ERR on success,
+ * DOM_ATTR_WRONG_TYPE_ERR if the attribute node is not a bool
+ * attribute
+ */
+dom_exception dom_attr_set_bool(dom_attr *a, bool value)
+{
+ /* If this is the first set method, we should fix this attribute
+ * type */
+ if (a->type == DOM_ATTR_UNSET)
+ a->type = DOM_ATTR_BOOL;
+
+ if (a->type != DOM_ATTR_BOOL)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ if (a->value.bvalue == value)
+ return DOM_NO_ERR;
+
+ a->value.bvalue = value;
+
+ struct dom_document *doc = dom_node_get_owner(a);
+ struct dom_node_internal *ele = dom_node_get_parent(a);
+ bool success = true;
+ dom_exception err;
+ err = _dom_dispatch_attr_modified_event(doc, ele, NULL, NULL,
+ (dom_event_target *) a, NULL,
+ DOM_MUTATION_MODIFICATION, &success);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ success = true;
+ err = _dom_dispatch_subtree_modified_event(doc,
+ (dom_event_target *) a, &success);
+ return err;
+}
+
+/**
+ * Set the node as a readonly attribute
+ *
+ * \param a The attribute
+ */
+void dom_attr_mark_readonly(dom_attr *a)
+{
+ a->read_only = true;
+}
/* -------------------------------------------------------------------- */
@@ -225,6 +439,18 @@
NULL, 0, &value);
if (err != DOM_NO_ERR) {
return err;
+ }
+
+ /* Force unknown types to strings, if necessary */
+ if (attr->type == DOM_ATTR_UNSET && a->first_child != NULL) {
+ attr->type = DOM_ATTR_STRING;
+ }
+
+ /* If this attribute node is not a string one, we just return an empty
+ * string */
+ if (attr->type != DOM_ATTR_STRING) {
+ *result = value;
+ return DOM_NO_ERR;
}
/* Traverse children, building a string representation as we go */
@@ -298,10 +524,33 @@
if (_dom_node_readonly(a))
return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ /* If this is the first set method, we should fix this attribute
+ * type */
+ if (attr->type == DOM_ATTR_UNSET)
+ attr->type = DOM_ATTR_STRING;
+
+ if (attr->type != DOM_ATTR_STRING)
+ return DOM_ATTR_WRONG_TYPE_ERR;
+
+ dom_string *name = NULL;
+
+ err = _dom_attr_get_name(attr, &name);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ dom_string *parsed = NULL;
+ err = dom_element_parse_attribute(a->parent, name, value, &parsed);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(name);
+ return err;
+ }
+
/* Create text node containing new value */
- err = dom_document_create_text_node(a->owner, value, &text);
+ err = dom_document_create_text_node(a->owner, parsed, &text);
if (err != DOM_NO_ERR)
return err;
+
+ dom_string_unref(parsed);
/* Destroy children of this node */
for (c = a->first_child; c != NULL; c = d) {
@@ -561,3 +810,14 @@
attr->specified = specified;
}
+/**
+ * Whether this attribute node is readonly
+ *
+ * \param a The node
+ * \return true if this Attr is readonly, false otherwise
+ */
+bool _dom_attr_readonly(const dom_attr *a)
+{
+ return a->read_only;
+}
+
Modified: trunk/dom/src/core/attr.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/attr.h?rev=10724&r1=...
==============================================================================
--- trunk/dom/src/core/attr.h (original)
+++ trunk/dom/src/core/attr.h Mon Aug 30 08:06:19 2010
@@ -8,7 +8,7 @@
#ifndef dom_internal_core_attr_h_
#define dom_internal_core_attr_h_
-#include <dom/core/exceptions.h>
+#include <dom/core/attr.h>
struct dom_document;
struct dom_string;
@@ -24,7 +24,7 @@
struct dom_document *doc, struct lwc_string_s *name,
struct lwc_string_s *namespace, struct lwc_string_s *prefix,
bool specified, struct dom_attr **result);
-void _dom_attr_finalise(dom_document *doc, struct dom_attr *attr);
+void _dom_attr_finalise(struct dom_document *doc, struct dom_attr *attr);
/* Virtual functions for dom_attr */
dom_exception _dom_attr_get_name(struct dom_attr *attr,
@@ -117,5 +117,6 @@
void _dom_attr_set_isid(struct dom_attr *attr, bool is_id);
void _dom_attr_set_specified(struct dom_attr *attr, bool specified);
+bool _dom_attr_readonly(const dom_attr *a);
#endif
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=10724...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Mon Aug 30 08:06:19 2010
@@ -76,13 +76,14 @@
* \param pw Pointer to client-specific private data
* \param doc Pointer to location to receive created document
* \param daf The default action fetcher
+ * \param daf The default action fetcher
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
*
* ::impl will have its reference count increased.
*
* The returned document will already be referenced.
*/
-dom_exception dom_document_create(struct dom_implementation *impl,
+dom_exception _dom_document_create(struct dom_implementation *impl,
dom_alloc alloc, void *pw,
dom_events_default_action_fetcher daf,
struct dom_document **doc)
@@ -184,6 +185,8 @@
if (doc->id_name != NULL)
lwc_string_unref(doc->id_name);
+
+ _dom_document_event_internal_finalise(doc, &doc->dei);
_dom_document_event_internal_finalise(doc, &doc->dei);
Modified: trunk/dom/src/core/document.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.h?rev=10724...
==============================================================================
--- trunk/dom/src/core/document.h (original)
+++ trunk/dom/src/core/document.h Mon Aug 30 08:06:19 2010
@@ -12,6 +12,7 @@
#include <stddef.h>
#include <dom/core/node.h>
+#include <dom/core/document.h>
#include "core/string.h"
#include "core/node.h"
@@ -65,6 +66,12 @@
dom_document_event_internal dei;
/**< The DocumentEVent interface */
};
+
+/* Create a DOM document */
+dom_exception _dom_document_create(struct dom_implementation *impl,
+ dom_alloc alloc, void *pw,
+ dom_events_default_action_fetcher daf,
+ struct dom_document **doc);
/* Initialise the document */
dom_exception _dom_document_initialise(struct dom_document *doc,
@@ -194,6 +201,28 @@
_dom_document_rename_node
/* End of vtable */
+/**
+ * The internal used vtable for document
+ */
+struct dom_document_protected_vtable {
+ struct dom_node_protect_vtable base;
+ dom_exception (*dom_document_get_base)(dom_document *doc,
+ struct dom_string **base_uri);
+ /* Get the document's base uri */
+};
+
+typedef struct dom_document_protected_vtable dom_document_protected_vtable;
+
+/* Get the document's base URI */
+static inline dom_exception dom_document_get_base(dom_document *doc,
+ struct dom_string **base_uri)
+{
+ struct dom_node_internal *node = (struct dom_node_internal *) doc;
+ return ((dom_document_protected_vtable *) node->vtable)->
+ dom_document_get_base(doc, base_uri);
+}
+#define dom_document_get_base(d, b) dom_document_get_base( \
+ (dom_document *) (d), (struct dom_string **) (b))
/* Following comes the protected vtable */
void _dom_document_destroy(struct dom_node_internal *node);
Modified: trunk/dom/src/core/document_type.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document_type.c?rev=...
==============================================================================
--- trunk/dom/src/core/document_type.c (original)
+++ trunk/dom/src/core/document_type.c Mon Aug 30 08:06:19 2010
@@ -64,7 +64,7 @@
* explicitly. The client must unref the doctype once it has
* finished with it.
*/
-dom_exception dom_document_type_create(struct dom_string *qname,
+dom_exception _dom_document_type_create(struct dom_string *qname,
struct dom_string *public_id, struct dom_string *system_id,
dom_alloc alloc, void *pw,
struct dom_document_type **doctype)
Modified: trunk/dom/src/core/document_type.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document_type.h?rev=...
==============================================================================
--- trunk/dom/src/core/document_type.h (original)
+++ trunk/dom/src/core/document_type.h Mon Aug 30 08:06:19 2010
@@ -12,6 +12,12 @@
struct dom_resource_mgr;
struct dom_implementation;
+/* Create a DOM document type */
+dom_exception _dom_document_type_create(struct dom_string *qname,
+ struct dom_string *public_id,
+ struct dom_string *system_id,
+ dom_alloc alloc, void *pw,
+ struct dom_document_type **doctype);
/* Destroy a document type */
void _dom_document_type_destroy(struct dom_node_internal *doctypenode);
dom_exception _dom_document_type_initialise(struct dom_document_type *doctype,
Modified: trunk/dom/src/core/element.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.c?rev=10724&...
==============================================================================
--- trunk/dom/src/core/element.c (original)
+++ trunk/dom/src/core/element.c Mon Aug 30 08:06:19 2010
@@ -35,14 +35,17 @@
#define CHAINS_NAMESPACE 7
#define CHAINS_NS_ATTRIBUTES 31
-static struct dom_element_vtable element_vtable = {
+struct dom_element_vtable _dom_element_vtable = {
{
DOM_NODE_VTABLE_ELEMENT
},
DOM_ELEMENT_VTABLE
};
-static struct dom_node_protect_vtable element_protect_vtable = {
+static struct dom_element_protected_vtable element_protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_ELEMENT
+ },
DOM_ELEMENT_PROTECT_VTABLE
};
@@ -145,7 +148,7 @@
return DOM_NO_MEM_ERR;
/* Initialise the vtables */
- (*result)->base.base.vtable = &element_vtable;
+ (*result)->base.base.vtable = &_dom_element_vtable;
(*result)->base.vtable = &element_protect_vtable;
return _dom_element_initialise(doc, *result, name, namespace, prefix);
@@ -1109,6 +1112,44 @@
/*----------------------------------------------------------------------*/
/* The protected virtual functions */
+/**
+ * The virtual function to parse some dom attribute
+ *
+ * \param ele The element object
+ * \param name The name of the attribute
+ * \param value The new value of the attribute
+ * \param parsed The parsed value of the attribute
+ * \return DOM_NO_ERR on success.
+ *
+ * @note: This virtual method is provided to serve as a template method.
+ * When any attribute is set or added, the attribute's value should be
+ * checked to make sure that it is a valid one. And the child class of
+ * dom_element may to do some special stuff on the attribute is set. Take
+ * some integer attribute as example:
+ *
+ * 1. The client call dom_element_set_attribute("size", "10.1"), but the
+ * size attribute may only accept an integer, and only the specific
+ * dom_element know this. And the dom_attr_set_value method, which is
+ * called by dom_element_set_attribute should call the this virtual
+ * template method.
+ * 2. The overload virtual function of following one will truncate the
+ * "10.1" to "10" to make sure it is a integer. And of course, the
+ * overload method may also save the integer as a 'int' C type for
+ * later easy accessing by any client.
+ */
+dom_exception _dom_element_parse_attribute(dom_element *ele,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_string **parsed)
+{
+ UNUSED(ele);
+ UNUSED(name);
+
+ dom_string_ref(value);
+ *parsed = value;
+
+ return DOM_NO_ERR;
+}
+
/* The destroy virtual function of dom_element */
void __dom_element_destroy(struct dom_node_internal *node)
{
@@ -1296,9 +1337,13 @@
if (err != DOM_NO_ERR)
return err;
+ /* Set its parent, so that value parsing works */
+ dom_node_set_parent(attr, element);
+
/* Set its value */
err = dom_attr_set_value(attr, value);
if (err != DOM_NO_ERR) {
+ dom_node_set_parent(attr, NULL);
dom_node_unref(attr);
return err;
}
@@ -1310,6 +1355,7 @@
(dom_event_target *) attr, name,
DOM_MUTATION_ADDITION, &success);
if (err != DOM_NO_ERR) {
+ dom_node_set_parent(attr, NULL);
dom_node_unref(attr);
return err;
}
@@ -1319,6 +1365,7 @@
(dom_event_target *) element,
DOM_MUTATION_ADDITION, &success);
if (err != DOM_NO_ERR) {
+ dom_node_set_parent(attr, NULL);
dom_node_unref(attr);
return err;
}
@@ -1326,11 +1373,11 @@
added = _dom_hash_add(hs, str, attr, false);
if (added == false) {
/* If we failed at this step, there must be no memory */
+ dom_node_set_parent(attr, NULL);
dom_node_unref(attr);
return DOM_NO_MEM_ERR;
}
- dom_node_set_parent(attr, element);
dom_node_unref(attr);
dom_node_remove_pending(attr);
Modified: trunk/dom/src/core/element.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.h?rev=10724&...
==============================================================================
--- trunk/dom/src/core/element.h (original)
+++ trunk/dom/src/core/element.h Mon Aug 30 08:06:19 2010
@@ -10,7 +10,9 @@
#include <stdbool.h>
-#include <dom/core/exceptions.h>
+#include <dom/core/element.h>
+
+#include "core/node.h"
struct dom_document;
struct dom_element;
@@ -175,8 +177,41 @@
_dom_node_set_user_data, \
_dom_node_get_user_data
+/**
+ * The internal used vtable for element
+ */
+struct dom_element_protected_vtable {
+ struct dom_node_protect_vtable base;
+
+ dom_exception (*dom_element_parse_attribute)(dom_element *ele,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_string **parsed);
+ /**< Called by dom_attr_set_value, and used to check
+ * whether the new attribute value is valid and
+ * return a valid on if it is not
+ */
+};
+
+typedef struct dom_element_protected_vtable dom_element_protected_vtable;
+
+/* Parse the attribute's value */
+static inline dom_exception dom_element_parse_attribute(dom_element *ele,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_string **parsed)
+{
+ struct dom_node_internal *node = (struct dom_node_internal *) ele;
+ return ((dom_element_protected_vtable *) node->vtable)->
+ dom_element_parse_attribute(ele, name, value, parsed);
+}
+#define dom_element_parse_attribute(e, n, v, p) dom_element_parse_attribute( \
+ (dom_element *) (e), (struct dom_string *) (n), \
+ (struct dom_string *) (v), (struct dom_string **) (p))
+
/* The protected virtual function */
+dom_exception _dom_element_parse_attribute(dom_element *ele,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_string **parsed);
void __dom_element_destroy(dom_node_internal *node);
dom_exception _dom_element_alloc(struct dom_document *doc,
struct dom_node_internal *n, struct dom_node_internal **ret);
@@ -184,6 +219,9 @@
struct dom_node_internal *old);
#define DOM_ELEMENT_PROTECT_VTABLE \
+ _dom_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_ELEMENT \
__dom_element_destroy, \
_dom_element_alloc, \
_dom_element_copy
@@ -192,4 +230,6 @@
dom_exception _dom_element_get_id(struct dom_element *ele,
struct lwc_string_s **id);
+extern struct dom_element_vtable _dom_element_vtable;
+
#endif
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=10724&r1=...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Mon Aug 30 08:06:19 2010
@@ -1491,10 +1491,10 @@
dom_exception _dom_node_get_base(dom_node_internal *node,
struct dom_string **result)
{
- UNUSED(node);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_document *doc = node->owner;
+ assert(doc != NULL);
+
+ return dom_document_get_base(doc, result);
}
/**
@@ -2072,6 +2072,10 @@
if (n->type == DOM_DOCUMENT_TYPE_NODE ||
n->type == DOM_NOTATION_NODE)
return true;
+
+ /* Some Attr node are readonly */
+ if (n->type == DOM_ATTRIBUTE_NODE)
+ return _dom_attr_readonly((const dom_attr *) n);
/* Entity ns and their descendants are read only
* EntityReference ns and their descendants are read only */
@@ -2363,6 +2367,25 @@
}
/**
+ * Create a lwc_string using the node's owner's lwc_context
+ *
+ * \param node The node object
+ * \param data The string data
+ * \param len The length of the string data
+ * \param str The returned lwc_string
+ * \return DOM_NO_ERR on success, appropirate dom_exception on failure.
+ */
+dom_exception _dom_node_create_lwcstring(dom_node_internal *node,
+ const uint8_t *data, size_t len, struct lwc_string_s **str)
+{
+ dom_document *doc = dom_node_get_owner(node);
+
+ assert(doc != NULL);
+
+ return _dom_document_create_lwcstring(doc, data, len, str);
+}
+
+/**
* Try to destroy this node.
*
* \param node The node to destroy
Modified: trunk/dom/src/core/node.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.h?rev=10724&r1=...
==============================================================================
--- trunk/dom/src/core/node.h (original)
+++ trunk/dom/src/core/node.h Mon Aug 30 08:06:19 2010
@@ -286,6 +286,8 @@
struct dom_string *str, struct lwc_string_s **intern);
void _dom_node_unref_intern_string(dom_node_internal *node,
struct lwc_string_s *inter);
+dom_exception _dom_node_create_lwcstring(dom_node_internal *node,
+ const uint8_t *data, size_t len, struct lwc_string_s **str);
/* Try to destroy the node, if its refcnt is not zero, then append it to the
* owner document's pending list */
Modified: trunk/dom/src/events/event_target.c
URL: http://source.netsurf-browser.org/trunk/dom/src/events/event_target.c?rev...
==============================================================================
--- trunk/dom/src/events/event_target.c (original)
+++ trunk/dom/src/events/event_target.c Mon Aug 30 08:06:19 2010
@@ -255,11 +255,8 @@
}
dom_string_unref(type);
- lwc_string *t = evt->type;
dom_event_target_entry list;
dom_event_target *target = et;
-
- assert(t != NULL);
*success = true;
@@ -286,6 +283,17 @@
/* Fill the target of the event */
evt->target = et;
evt->phase = DOM_CAPTURING_PHASE;
+
+ /* The started callback of default action */
+ struct dom_document_event_internal *dei = &doc->dei;
+ void *pw = NULL;
+ if (dei->actions != NULL) {
+ dom_default_action_callback cb = dei->actions(evt->type,
+ DOM_DEFAULT_ACTION_STARTED, &pw);
+ if (cb != NULL) {
+ cb(evt, pw);
+ }
+ }
/* The capture phase */
struct list_entry *e = list.entry.prev;
@@ -329,32 +337,26 @@
goto cleanup;
}
- struct dom_document_event_internal *dei = &doc->dei;
- if (dei->actions == NULL || evt->prevent_default == true)
- goto cleanup;
-
- /* The default action */
- struct dom_string *nodename;
- err = dom_node_get_node_name(et, &nodename);
- if (err != DOM_NO_ERR) {
- ret = err;
- goto cleanup;
- }
- lwc_string *lnodename = NULL;
- err = dom_string_get_intern(nodename, &lnodename);
- if (err != DOM_NO_ERR) {
- dom_string_unref(nodename);
- ret = err;
- goto cleanup;
- }
-
- dom_event_listener *da = dei->actions(lnodename, t);
- if (da != NULL) {
- da->handler(evt, da->pw);
- }
-
- dom_string_unref(nodename);
- lwc_string_unref(lnodename);
+ if (dei->actions == NULL)
+ goto cleanup;
+
+ /* The end callback of default action */
+ if (evt->prevent_default != true) {
+ dom_default_action_callback cb = dei->actions(evt->type,
+ DOM_DEFAULT_ACTION_END, &pw);
+ if (cb != NULL) {
+ cb(evt, pw);
+ }
+ }
+
+ /* The prevented callback of default action */
+ if (evt->prevent_default != true) {
+ dom_default_action_callback cb = dei->actions(evt->type,
+ DOM_DEFAULT_ACTION_PREVENTED, &pw);
+ if (cb != NULL) {
+ cb(evt, pw);
+ }
+ }
cleanup:
if (evt->prevent_default == true) {
@@ -707,9 +709,10 @@
/**
* Dispatch a DOMCharacterDataModified event
*
- * \param et The EventTarget object
- * \param prev The preValue of the DOMCharacterData
- * \param new The newValue of the DOMCharacterData
+ * \param et The EventTarget object
+ * \param prev The preValue of the DOMCharacterData
+ * \param new The newValue of the DOMCharacterData
+ * \param success Whether this event's default handler get called
* \return DOM_NO_ERR on success, appropirate dom_exception on failure.
*
* TODO:
@@ -761,7 +764,7 @@
*
* \param doc The Document
* \param et The EventTarget object
- * \param success The newValue of the DOMCharacterData
+ * \param success Whether this event's default handler get called
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_dispatch_subtree_modified_event(struct dom_document *doc,
@@ -802,3 +805,51 @@
return err;
}
+/**
+ * Dispatch a generic event
+ *
+ * \param doc The Document
+ * \param et The EventTarget object
+ * \param name The name of the event
+ * \param len The length of the name string
+ * \param bubble Whether this event bubbles
+ * \param cancelable Whether this event can be cancelable
+ * \param success Whether this event's default handler get called
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_dispatch_generic_event(struct dom_document *doc,
+ dom_event_target *et, const uint8_t *name, size_t len,
+ bool bubble, bool cancelable, bool *success)
+{
+ struct dom_event *evt;
+ dom_exception err;
+
+ err = _dom_event_create(doc, &evt);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ lwc_string *type = NULL;
+ err = _dom_document_create_lwcstring(doc, name, len, &type);
+ if (err != DOM_NO_ERR)
+ goto cleanup;
+
+ dom_string *t = NULL;
+ err = _dom_document_create_string_from_lwcstring(doc, type, &t);
+ _dom_document_unref_lwcstring(doc, type);
+ if (err != DOM_NO_ERR)
+ goto cleanup;
+
+ err = dom_event_init(evt, t, bubble, cancelable);
+ dom_string_unref(t);
+ if (err != DOM_NO_ERR) {
+ goto cleanup;
+ }
+
+ err = dom_event_target_dispatch_event(et, evt, success);
+
+cleanup:
+ _dom_event_destroy(doc, evt);
+
+ return err;
+}
+
Modified: trunk/dom/src/events/event_target.h
URL: http://source.netsurf-browser.org/trunk/dom/src/events/event_target.h?rev...
==============================================================================
--- trunk/dom/src/events/event_target.h (original)
+++ trunk/dom/src/events/event_target.h Mon Aug 30 08:06:19 2010
@@ -85,4 +85,8 @@
dom_exception _dom_dispatch_subtree_modified_event(struct dom_document *doc,
dom_event_target *et, bool *success);
+/* Dispatch a generic event */
+dom_exception _dom_dispatch_generic_event(struct dom_document *doc,
+ dom_event_target *et, const uint8_t *name, size_t len,
+ bool bubble, bool cancelable, bool *success);
#endif
Modified: trunk/dom/src/html/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/src/html/Makefile?rev=10724&r...
==============================================================================
--- trunk/dom/src/html/Makefile (original)
+++ trunk/dom/src/html/Makefile Mon Aug 30 08:06:19 2010
@@ -1,10 +1,12 @@
# Sources
DIR_SOURCES := \
- html_collection.c html_options_collection.c html_element.c \
- html_html_element.c html_head_element.c html_link_element.c \
- html_title_element.c html_meta_element.c html_base_element.c \
- html_isindex_element.c html_style_element.c html_body_element.c \
- html_form_element.c html_select_element.c html_optgroup_element.c \
+ html_document.c html_collection.c html_options_collection.c \
+ html_element.c html_html_element.c html_head_element.c \
+ html_link_element.c html_title_element.c html_meta_element.c \
+ html_base_element.c html_isindex_element.c html_style_element.c \
+ html_body_element.c html_form_element.c html_select_element.c
+
+UNINMPLEMENTED_SOURCES := html_optgroup_element.c \
html_option_element.c html_input_element.c html_textarea_element.c \
html_button_element.c html_label_element.c html_fieldset_element.c \
html_legend_element.c html_ulist_element.c html_olist_element.c \
Modified: trunk/dom/src/html/html_document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/html/html_document.c?rev=...
==============================================================================
--- trunk/dom/src/html/html_document.c (original)
+++ trunk/dom/src/html/html_document.c Mon Aug 30 08:06:19 2010
@@ -5,13 +5,16 @@
* Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
*/
+#include <assert.h>
+
#include "html/html_document.h"
#include "core/string.h"
+#include "utils/utils.h"
/* Create a HTMLDocument */
dom_exception dom_html_document_create(dom_alloc alloc, void *pw, dom_msg msg,
- void *msg_pw, struct lwc_context_s *ctx,
+ void *msg_pw,
dom_events_default_action_fetcher daf, dom_ui_handler ui,
dom_parser_type pt, dom_html_document **doc)
{
@@ -20,18 +23,26 @@
if (*doc == NULL)
return DOM_NO_MEM_ERR;
- return _dom_html_document_initialise(*doc, alloc, pw, msn, msg_pw,
- ctx, daf, ui, pt);
+ return _dom_html_document_initialise(*doc, alloc, pw, msg, msg_pw,
+ daf, ui, pt);
}
/* Initialise a HTMLDocument */
dom_exception _dom_html_document_initialise(dom_html_document *doc,
dom_alloc alloc, void *pw, dom_msg msg, void *msg_pw,
- struct lwc_context_s *ctx,
dom_events_default_action_fetcher daf, dom_ui_handler ui,
dom_parser_type pt)
{
-
+ UNUSED(doc);
+ UNUSED(alloc);
+ UNUSED(pw);
+ UNUSED(msg);
+ UNUSED(msg_pw);
+ UNUSED(daf);
+ UNUSED(ui);
+ UNUSED(pt);
+
+ return DOM_NO_ERR;
}
/* Finalise a HTMLDocument */
@@ -63,6 +74,10 @@
dom_exception dom_html_document_get_title(dom_html_document *doc,
struct dom_string **title)
{
+ UNUSED(doc);
+ UNUSED(title);
+
+ return DOM_NO_ERR;
}
dom_exception dom_html_document_set_title(dom_html_document *doc,
@@ -78,15 +93,15 @@
dom_exception dom_html_document_set_body(dom_html_document *doc,
struct dom_html_element *body);
dom_exception dom_html_document_get_images(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_applets(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_links(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_forms(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_anchors(dom_html_document *doc,
- struct dom_html_collectoin **col);
+ struct dom_html_collection **col);
dom_exception dom_html_document_get_cookie(dom_html_document *doc,
struct dom_string **cookie);
dom_exception dom_html_document_set_cookie(dom_html_document *doc,
Modified: trunk/dom/src/html/html_document.h
URL: http://source.netsurf-browser.org/trunk/dom/src/html/html_document.h?rev=...
==============================================================================
--- trunk/dom/src/html/html_document.h (original)
+++ trunk/dom/src/html/html_document.h Mon Aug 30 08:06:19 2010
@@ -8,7 +8,7 @@
#ifndef dom_internal_html_document_h_
#define dom_internal_html_document_h_
-#include <dom/core/html_document.h>
+#include <dom/html/html_document.h>
#include "core/document.h"
@@ -36,7 +36,6 @@
/* Initialise a HTMLDocument */
dom_exception _dom_html_document_initialise(dom_html_document *doc,
dom_alloc alloc, void *pw, dom_msg msg, void *msg_pw,
- struct lwc_context_s *ctx,
dom_events_default_action_fetcher daf, dom_ui_handler ui,
dom_parser_type pt);
/* Finalise a HTMLDocument */
Modified: trunk/dom/src/html/html_element.c
URL: http://source.netsurf-browser.org/trunk/dom/src/html/html_element.c?rev=1...
==============================================================================
--- trunk/dom/src/html/html_element.c (original)
+++ trunk/dom/src/html/html_element.c Mon Aug 30 08:06:19 2010
@@ -56,6 +56,8 @@
UNUSED(ret);
assert("Should never be here" == NULL);
+
+ return DOM_NO_MEM_ERR;
}
/* The virtual copy function, see src/core/node.c for detail */
@@ -135,31 +137,33 @@
if (err != DOM_NO_ERR)
goto cleanup1;
- dom_node *res = NULL;
if (a != NULL && has == false) {
+ dom_attr *res = NULL;
+
err = dom_element_remove_attribute_node(ele, a, &res);
if (err != DOM_NO_ERR)
goto cleanup2;
+
dom_node_unref(res);
} else if (a == NULL && has == true) {
+ dom_attr *res = NULL;
lwc_string *lstr = NULL;
- lwc_context *ctx = _dom_document_get_intern_context(doc);
- assert(ctx != NULL);
-
- err = _dom_string_intern(str, ctx, &lstr);
+
+ err = _dom_string_intern(str, &lstr);
if (err != DOM_NO_ERR)
goto cleanup1;
err = _dom_attr_create(doc, lstr, NULL, NULL, true, &a);
if (err != DOM_NO_ERR) {
- lwc_context_string_unref(ctx, lstr);
+ lwc_string_unref(lstr);
goto cleanup1;
}
- lwc_context_string_unref(ctx, lstr);
+ lwc_string_unref(lstr);
err = dom_element_set_attribute_node(ele, a, &res);
if (err != DOM_NO_ERR)
goto cleanup2;
+
dom_node_unref(res);
}
13 years
r10723 chris_y - /trunk/netsurf/amiga/plotters.c
by netsurf@semichrome.net
Author: chris_y
Date: Mon Aug 30 07:25:38 2010
New Revision: 10723
URL: http://source.netsurf-browser.org?rev=10723&view=rev
Log:
Revert accidental change which was causing corruption down the right-hand side of
images
Modified:
trunk/netsurf/amiga/plotters.c
Modified: trunk/netsurf/amiga/plotters.c
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/plotters.c?rev=1072...
==============================================================================
--- trunk/netsurf/amiga/plotters.c (original)
+++ trunk/netsurf/amiga/plotters.c Mon Aug 30 07:25:38 2010
@@ -555,8 +555,8 @@
COMPTAG_DestY,glob->rect.MinY,
COMPTAG_DestWidth,glob->rect.MaxX - glob->rect.MinX + 1,
COMPTAG_DestHeight,glob->rect.MaxY - glob->rect.MinY + 1,
- // COMPTAG_SrcWidth,width,
- // COMPTAG_SrcHeight,height,
+ COMPTAG_SrcWidth,width,
+ COMPTAG_SrcHeight,height,
COMPTAG_OffsetX,x,
COMPTAG_OffsetY,y,
TAG_DONE);
13 years
r10722 chris_y - in /trunk/netsurf/amiga: options.h plotters.c
by netsurf@semichrome.net
Author: chris_y
Date: Mon Aug 30 06:00:24 2010
New Revision: 10722
URL: http://source.netsurf-browser.org?rev=10722&view=rev
Log:
Debug plotters. It appears that the odd slowness on some sites (eg. sourceforge.net)
can be eliminated by setting option_cache_bitmaps to 2, so make that the default.
Modified:
trunk/netsurf/amiga/options.h
trunk/netsurf/amiga/plotters.c
Modified: trunk/netsurf/amiga/options.h
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/options.h?rev=10722...
==============================================================================
--- trunk/netsurf/amiga/options.h (original)
+++ trunk/netsurf/amiga/options.h Mon Aug 30 06:00:24 2010
@@ -58,7 +58,7 @@
char *option_hotlist_file = 0; \
char *option_use_pubscreen = 0; \
char *option_modeid = 0; \
-int option_cache_bitmaps = 1; \
+int option_cache_bitmaps = 2; \
char *option_theme = 0; \
bool option_no_iframes = false; \
bool option_utf8_clipboard = false; \
Modified: trunk/netsurf/amiga/plotters.c
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/plotters.c?rev=1072...
==============================================================================
--- trunk/netsurf/amiga/plotters.c (original)
+++ trunk/netsurf/amiga/plotters.c Mon Aug 30 06:00:24 2010
@@ -58,6 +58,9 @@
#define PATT_DASH 0xCCCC
#define PATT_LINE 0xFFFF
+/* Define the below to get additional debug */
+#undef AMI_PLOTTER_DEBUG
+
struct plotter_table plot;
const struct plotter_table amiplot = {
.rectangle = ami_rectangle,
@@ -197,6 +200,10 @@
bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_rectangle()"));
+ #endif
+
if (style->fill_type != PLOT_OP_TYPE_NONE) {
#ifndef NS_AMIGA_CAIRO_ALL
@@ -279,6 +286,10 @@
bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_line()"));
+ #endif
+
#ifndef NS_AMIGA_CAIRO_ALL
glob->rp.PenWidth = style->stroke_width;
glob->rp.PenHeight = style->stroke_width;
@@ -340,6 +351,10 @@
bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_polygon()"));
+ #endif
+
int k;
#ifndef NS_AMIGA_CAIRO
ULONG cx,cy;
@@ -380,6 +395,10 @@
bool ami_clip(int x0, int y0, int x1, int y1)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_clip()"));
+ #endif
+
struct Region *reg = NULL;
if(glob->rp.Layer)
@@ -410,12 +429,20 @@
bool ami_text(int x, int y, const char *text, size_t length,
const plot_font_style_t *fstyle)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_text()"));
+ #endif
+
ami_unicode_text(&glob->rp,text,length,fstyle,x,y);
return true;
}
bool ami_disc(int x, int y, int radius, const plot_style_t *style)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_disc()"));
+ #endif
+
#ifndef NS_AMIGA_CAIRO_ALL
if (style->fill_type != PLOT_OP_TYPE_NONE) {
SetRPAttrs(&glob->rp,
@@ -464,6 +491,10 @@
bool ami_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_arc()"));
+ #endif
+
#ifdef NS_AMIGA_CAIRO
ami_cairo_set_colour(glob->cr, style->fill_colour);
ami_cairo_set_solid(glob->cr);
@@ -490,6 +521,10 @@
static bool ami_bitmap(int x, int y, int width, int height, struct bitmap *bitmap)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_bitmap()"));
+ #endif
+
struct BitMap *tbm;
if(!width || !height) return true;
@@ -504,10 +539,15 @@
if(!tbm) return true;
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] ami_bitmap() got native bitmap"));
+ #endif
+
if(GfxBase->lib_Version >= 53) // AutoDoc says v52, but this function isn't in OS4.0, so checking for v53 (OS4.1)
{
uint32 comptype = COMPOSITE_Src;
- if(!bitmap->opaque) comptype = COMPOSITE_Src_Over_Dest;
+ if(!bitmap->opaque)
+ comptype = COMPOSITE_Src_Over_Dest;
CompositeTags(comptype,tbm,glob->rp.BitMap,
COMPTAG_Flags,COMPFLAG_IgnoreDestAlpha,
@@ -515,8 +555,8 @@
COMPTAG_DestY,glob->rect.MinY,
COMPTAG_DestWidth,glob->rect.MaxX - glob->rect.MinX + 1,
COMPTAG_DestHeight,glob->rect.MaxY - glob->rect.MinY + 1,
- COMPTAG_SrcWidth,width,
- COMPTAG_SrcHeight,height,
+ // COMPTAG_SrcWidth,width,
+ // COMPTAG_SrcHeight,height,
COMPTAG_OffsetX,x,
COMPTAG_OffsetY,y,
TAG_DONE);
@@ -548,12 +588,16 @@
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_bitmap_tile()"));
+ #endif
+
int xf,yf,xm,ym,oy,ox;
struct BitMap *tbm = NULL;
struct Hook *bfh = NULL;
struct bfbitmap bfbm;
- bool repeat_x = (flags & BITMAPF_REPEAT_X);
- bool repeat_y = (flags & BITMAPF_REPEAT_Y);
+ bool repeat_x = (flags & BITMAPF_REPEAT_X);
+ bool repeat_y = (flags & BITMAPF_REPEAT_Y);
if(!(repeat_x || repeat_y))
return ami_bitmap(x, y, width, height, bitmap);
@@ -683,23 +727,37 @@
bool ami_group_start(const char *name)
{
/** optional */
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_group_start()"));
+ #endif
+
return false;
}
bool ami_group_end(void)
{
/** optional */
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_group_end()"));
+ #endif
return false;
}
bool ami_flush(void)
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_flush()"));
+ #endif
return true;
}
bool ami_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6])
{
+ #ifdef AMI_PLOTTER_DEBUG
+ LOG(("[ami_plotter] Entered ami_path()"));
+ #endif
+
/* For SVG only, because it needs Bezier curves we are going to cheat
and insist on Cairo */
#ifdef NS_AMIGA_CAIRO
13 years