summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--!NetSurf/Resources/de/Messages22
-rw-r--r--!NetSurf/Resources/en/Messages22
-rw-r--r--!NetSurf/Resources/fr/Messages22
-rw-r--r--!NetSurf/Resources/it/Messages22
-rw-r--r--!NetSurf/Resources/nl/Messages22
-rw-r--r--Makefile.sources2
-rwxr-xr-xamiga/plotters.c185
-rw-r--r--image/bmp.c15
-rw-r--r--image/gif.c16
-rw-r--r--image/ico.c16
-rw-r--r--image/jpeg.c13
-rw-r--r--image/mng.c32
-rw-r--r--image/nssprite.c13
-rw-r--r--image/png.c13
-rw-r--r--image/webp.c14
-rw-r--r--javascript/jsapi.c54
-rw-r--r--javascript/jsapi.h44
-rw-r--r--javascript/jsapi/binding.h82
-rw-r--r--javascript/jsapi/console.c2
-rw-r--r--javascript/jsapi/window.c297
-rw-r--r--resources/FatMessages110
-rw-r--r--riscos/content-handlers/artworks.c7
-rw-r--r--riscos/content-handlers/draw.c7
-rw-r--r--riscos/content-handlers/sprite.c7
-rw-r--r--utils/nsurl.c32
-rw-r--r--utils/nsurl.h14
26 files changed, 654 insertions, 431 deletions
diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages
index 35d8cc24f..97e6e8897 100644
--- a/!NetSurf/Resources/de/Messages
+++ b/!NetSurf/Resources/de/Messages
@@ -687,17 +687,17 @@ SelectMenu:Auswahl
# Content titles
#
-DrawTitle:Draw Bild (%lux%lu, %lu bytes)
-GIFTitle:GIF Bild (%lux%lu, %lu bytes)
-BMPTitle:BMP Bild (%lux%lu, %lu bytes)
-ICOTitle:ICO Bild (%lux%lu, %lu bytes)
-JPEGTitle:JPEG Bild (%ux%u, %lu bytes)
-PNGTitle:PNG Bild (%lux%lu, %lu bytes)
-JNGTitle:JNG Bild (%lux%lu, %lu bytes)
-MNGTitle:MNG Bild (%lux%lu, %lu bytes)
-WebPTitle:WebP Bild (%lux%lu, %lu bytes)
-SpriteTitle:Sprite Bild (%lux%lu, %lu bytes)
-ArtWorksTitle:ArtWorks Bild (%lux%lu, %lu bytes)
+GIFTitle:%s (GIF Bild %lux%lu pixels)
+BMPTitle:%s (BMP Bild %lux%lu pixels)
+ICOTitle:%s (ICO Bild %lux%lu pixels)
+PNGTitle:%s (PNG Bild %lux%lu pixels)
+JNGTitle:%s (JNG Bild %lux%lu pixels)
+MNGTitle:%s (MNG Bild %lux%lu pixels)
+JPEGTitle:%s (JPEG Bild %lux%lu pixels)
+WebPTitle:%s (WebP Bild %lux%lu pixels)
+DrawTitle:%s (Drawfile Bild %lux%lu pixels)
+SpriteTitle:%s (Sprite Bild %lux%lu pixels)
+ArtWorksTitle:%s (ArtWorks Bild %lux%lu pixels)
# HTML page character set
#
diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages
index 28e197ef0..7ee99ea80 100644
--- a/!NetSurf/Resources/en/Messages
+++ b/!NetSurf/Resources/en/Messages
@@ -687,17 +687,17 @@ SelectMenu:Select
# Content titles
#
-DrawTitle:Draw image (%lux%lu, %lu bytes)
-GIFTitle:GIF image (%lux%lu, %lu bytes)
-BMPTitle:BMP image (%lux%lu, %lu bytes)
-ICOTitle:ICO image (%lux%lu, %lu bytes)
-JPEGTitle:JPEG image (%ux%u, %lu bytes)
-PNGTitle:PNG image (%lux%lu, %lu bytes)
-JNGTitle:JNG image (%lux%lu, %lu bytes)
-MNGTitle:MNG image (%lux%lu, %lu bytes)
-WebPTitle:WebP image (%lux%lu, %lu bytes)
-SpriteTitle:Sprite image (%lux%lu, %lu bytes)
-ArtWorksTitle:ArtWorks image (%lux%lu, %lu bytes)
+GIFTitle:%s (GIF image %lux%lu pixels)
+BMPTitle:%s (BMP image %lux%lu pixels)
+ICOTitle:%s (ICO image %lux%lu pixels)
+PNGTitle:%s (PNG image %lux%lu pixels)
+JNGTitle:%s (JNG image %lux%lu pixels)
+MNGTitle:%s (MNG image %lux%lu pixels)
+JPEGTitle:%s (JPEG image %lux%lu pixels)
+WebPTitle:%s (WebP image %lux%lu pixels)
+DrawTitle:%s (Drawfile image %lux%lu pixels)
+SpriteTitle:%s (Sprite image %lux%lu pixels)
+ArtWorksTitle:%s (ArtWorks image %lux%lu pixels)
# HTML page character set
#
diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages
index 4be370bfe..f6994131e 100644
--- a/!NetSurf/Resources/fr/Messages
+++ b/!NetSurf/Resources/fr/Messages
@@ -687,17 +687,17 @@ SelectMenu:Sélection
# Content titles
#
-DrawTitle:Image Draw (%lux%lu, %lu octets)
-GIFTitle:Image GIF (%lux%lu, %lu octets)
-BMPTitle:Image BMP (%lux%lu, %lu octets)
-ICOTitle:Image BMP (%lux%lu, %lu octets)
-JPEGTitle:Image JPEG (%ux%u, %lu octets)
-PNGTitle:Image PNG (%lux%lu, %lu octets)
-JNGTitle:Image JNG (%lux%lu, %lu octets)
-MNGTitle:Image MNG (%lux%lu, %lu octets)
-WebPTitle:Image WebP (%lux%lu, %lu octets)
-SpriteTitle:Image Sprite (%lux%lu, %lu octets)
-ArtWorksTitle:Image ArtWorks (%lux%lu, %lu octets)
+GIFTitle:%s (Image GIF %lux%lu pixels)
+BMPTitle:%s (Image BMP %lux%lu pixels)
+ICOTitle:%s (Image BMP %lux%lu pixels)
+PNGTitle:%s (Image PNG %lux%lu pixels)
+JNGTitle:%s (Image JNG %lux%lu pixels)
+MNGTitle:%s (Image MNG %lux%lu pixels)
+JPEGTitle:%s (Image JPEG %lux%lu pixels)
+WebPTitle:%s (Image WebP %lux%lu pixels)
+DrawTitle:%s (Image Drawfile %lux%lu pixels)
+SpriteTitle:%s (Image Sprite %lux%lu pixels)
+ArtWorksTitle:%s (Image ArtWorks %lux%lu pixels)
# HTML page character set
#
diff --git a/!NetSurf/Resources/it/Messages b/!NetSurf/Resources/it/Messages
index 9b670170f..cf0728c7c 100644
--- a/!NetSurf/Resources/it/Messages
+++ b/!NetSurf/Resources/it/Messages
@@ -687,17 +687,17 @@ SelectMenu:Seleziona
# Content titles
#
-DrawTitle:Immagine Draw (%lux%lu, %lu byte)
-GIFTitle:Immagine GIF (%lux%lu, %lu byte)
-BMPTitle:Immagine BMP (%lux%lu, %lu byte)
-ICOTitle:Immagine ICO (%lux%lu, %lu byte)
-JPEGTitle:Immagine JPEG (%ux%u, %lu byte)
-PNGTitle:Immagine PNG (%lux%lu, %lu byte)
-JNGTitle:Immagine JNG (%lux%lu, %lu byte)
-MNGTitle:Immagine MNG (%lux%lu, %lu byte)
-WebPTitle:Immagine WebP (%lux%lu, %lu byte)
-SpriteTitle:Immagine Sprite (%lux%lu, %lu byte)
-ArtWorksTitle:Immagine ArtWorks (%lux%lu, %lu byte)
+GIFTitle:%s (Immagine GIF %lux%lu pixels)
+BMPTitle:%s (Immagine BMP %lux%lu pixels)
+ICOTitle:%s (Immagine ICO %lux%lu pixels)
+PNGTitle:%s (Immagine PNG %lux%lu pixels)
+JNGTitle:%s (Immagine JNG %lux%lu pixels)
+MNGTitle:%s (Immagine MNG %lux%lu pixels)
+JPEGTitle:%s (Immagine JPEG %lux%lu pixels)
+WebPTitle:%s (Immagine WebP %lux%lu pixels)
+DrawTitle:%s (Immagine Drawfile %lux%lu pixels)
+SpriteTitle:%s (Immagine Sprite %lux%lu pixels)
+ArtWorksTitle:%s (Immagine ArtWorks %lux%lu pixels)
# HTML page character set
#
diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages
index 06b8f0c0a..8eda66721 100644
--- a/!NetSurf/Resources/nl/Messages
+++ b/!NetSurf/Resources/nl/Messages
@@ -687,17 +687,17 @@ SelectMenu:Select
# Content titles
#
-DrawTitle:Draw image (%lux%lu, %lu bytes)
-GIFTitle:GIF image (%lux%lu, %lu bytes)
-BMPTitle:BMP image (%lux%lu, %lu bytes)
-ICOTitle:ICO image (%lux%lu, %lu bytes)
-JPEGTitle:JPEG image (%ux%u, %lu bytes)
-PNGTitle:PNG image (%lux%lu, %lu bytes)
-JNGTitle:JNG image (%lux%lu, %lu bytes)
-MNGTitle:MNG image (%lux%lu, %lu bytes)
-WebPTitle:WebP image (%lux%lu, %lu bytes)
-SpriteTitle:Sprite image (%lux%lu, %lu bytes)
-ArtWorksTitle:ArtWorks image (%lux%lu, %lu bytes)
+GIFTitle:%s (GIF image %lux%lu pixels)
+BMPTitle:%s (BMP image %lux%lu pixels)
+ICOTitle:%s (ICO image %lux%lu pixels)
+PNGTitle:%s (PNG image %lux%lu pixels)
+JNGTitle:%s (JNG image %lux%lu pixels)
+MNGTitle:%s (MNG image %lux%lu pixels)
+JPEGTitle:%s (JPEG image %lux%lu pixels)
+WebPTitle:%s (WebP image %lux%lu pixels)
+DrawTitle:%s (Drawfile image %lux%lu pixels)
+SpriteTitle:%s (Sprite image %lux%lu pixels)
+ArtWorksTitle:%s (ArtWorks image %lux%lu pixels)
# HTML page character set
#
diff --git a/Makefile.sources b/Makefile.sources
index 78550318c..32db5e666 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -26,7 +26,7 @@ S_HTTP := challenge.c generics.c primitives.c parameter.c \
S_DESKTOP := cookies.c history_global_core.c hotlist.c knockout.c \
mouse.c options.c plot_style.c print.c search.c searchweb.c \
- scrollbar.c sslcert.c textarea.c thumbnail.c tree.c \
+ scrollbar.c sslcert.c textarea.c thumbnail.c tree.c \
tree_url_node.c version.c
# Javascript source
diff --git a/amiga/plotters.c b/amiga/plotters.c
index ecf5b3902..7347f064d 100755
--- a/amiga/plotters.c
+++ b/amiga/plotters.c
@@ -59,6 +59,11 @@ struct ami_plot_pen {
ULONG pen;
};
+struct bez_point {
+ float x;
+ float y;
+};
+
bool palette_mapped = false;
#ifndef M_PI /* For some reason we don't always get this from math.h */
@@ -74,6 +79,11 @@ bool palette_mapped = false;
#define PATT_DASH 0xCCCC
#define PATT_LINE 0xFFFF
+/* This defines the size of the list for Area* functions.
+ 25000 = 5000 vectors
+ */
+#define AREA_SIZE 25000
+
/* Define the below to get additional debug */
#undef AMI_PLOTTER_DEBUG
@@ -150,7 +160,7 @@ void ami_init_layers(struct gui_globals *gg, ULONG width, ULONG height)
if(!height) height = nsoption_int(redraw_tile_size_y);
gg->layerinfo = NewLayerInfo();
- gg->areabuf = AllocVec(100, MEMF_PRIVATE | MEMF_CLEAR);
+ gg->areabuf = AllocVec(AREA_SIZE, MEMF_PRIVATE | MEMF_CLEAR);
gg->tmprasbuf = AllocVec(width * height, MEMF_PRIVATE | MEMF_CLEAR);
if(palette_mapped == true) {
@@ -181,7 +191,7 @@ void ami_init_layers(struct gui_globals *gg, ULONG width, ULONG height)
if((!gg->areabuf) || (!gg->rp->AreaInfo)) warn_user("NoMemory","");
- InitArea(gg->rp->AreaInfo,gg->areabuf,100/5);
+ InitArea(gg->rp->AreaInfo,gg->areabuf, AREA_SIZE/5);
gg->rp->TmpRas = AllocVec(sizeof(struct TmpRas),MEMF_PRIVATE | MEMF_CLEAR);
if((!gg->tmprasbuf) || (!gg->rp->TmpRas)) warn_user("NoMemory","");
@@ -283,6 +293,18 @@ static void ami_plot_setapen(ULONG colour)
}
}
+static void ami_plot_setopen(ULONG colour)
+{
+ if(palette_mapped == false) {
+ SetRPAttrs(glob->rp, RPTAG_OPenColor,
+ p96EncodeColor(RGBFB_A8B8G8R8, colour),
+ TAG_DONE);
+ } else {
+ ULONG pen = ami_plot_obtain_pen(glob->shared_pens, colour);
+ if(pen != -1) SetOPen(glob->rp, pen);
+ }
+}
+
bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
#ifdef AMI_PLOTTER_DEBUG
@@ -462,14 +484,17 @@ bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style)
ami_plot_setapen(style->fill_colour);
- AreaMove(glob->rp,p[0],p[1]);
-
+ if(AreaMove(glob->rp,p[0],p[1]) == -1)
+ LOG(("AreaMove: vector list full"));
+
for(k=1;k<n;k++)
{
- AreaDraw(glob->rp,p[k*2],p[(k*2)+1]);
+ if(AreaDraw(glob->rp,p[k*2],p[(k*2)+1]) == -1)
+ LOG(("AreaDraw: vector list full"));
}
- AreaEnd(glob->rp);
+ if(AreaEnd(glob->rp) == -1)
+ LOG(("AreaEnd: error"));
}
else
{
@@ -591,6 +616,31 @@ bool ami_disc(int x, int y, int radius, const plot_style_t *style)
return true;
}
+bool ami_arc_gfxlib(int x, int y, int radius, int angle1, int angle2)
+{
+ double angle1_r = (double)(angle1) * (M_PI / 180.0);
+ double angle2_r = (double)(angle2) * (M_PI / 180.0);
+ double angle, b, c;
+ double step = 0.1; //(angle2_r - angle1_r) / ((angle2_r - angle1_r) * (double)radius);
+ int x0, y0, x1, y1;
+
+ x0 = x;
+ y0 = y;
+
+ b = angle1_r;
+ c = angle2_r;
+
+ x1 = (int)(cos(b) * (double)radius);
+ y1 = (int)(sin(b) * (double)radius);
+ Move(glob->rp, x0 + x1, y0 - y1);
+
+ for(angle = (b + step); angle <= c; angle += step) {
+ x1 = (int)(cos(angle) * (double)radius);
+ y1 = (int)(sin(angle) * (double)radius);
+ Draw(glob->rp, x0 + x1, y0 - y1);
+ }
+}
+
bool ami_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
#ifdef AMI_PLOTTER_DEBUG
@@ -598,10 +648,12 @@ bool ami_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_
#endif
if((nsoption_int(cairo_renderer) <= 0) || (palette_mapped == true)) {
- /* TODO: gfx.lib plotter needs arc support */
- /* eg. http://www.crbond.com/primitives.htm CommonFuncsPPC.lha */
+
+ if (angle2 < angle1) angle2 += 360;
+
ami_plot_setapen(style->fill_colour);
- /* DrawArc(glob->rp,x,y,(float)angle1,(float)angle2,radius); */
+
+ ami_arc_gfxlib(x, y, radius, angle1, angle2);
} else {
#ifdef NS_AMIGA_CAIRO
ami_cairo_set_colour(glob->cr, style->fill_colour);
@@ -876,32 +928,36 @@ bool ami_flush(void)
return true;
}
+void ami_bezier(struct bez_point *a, struct bez_point *b, struct bez_point *c,
+ struct bez_point *d, double t, struct bez_point *p) {
+ p->x = pow((1 - t), 3) * a->x + 3 * t * pow((1 -t), 2) * b->x + 3 * (1-t) * pow(t, 2)* c->x + pow (t, 3)* d->x;
+ p->y = pow((1 - t), 3) * a->y + 3 * t * pow((1 -t), 2) * b->y + 3 * (1-t) * pow(t, 2)* c->y + pow (t, 3)* d->y;
+}
+
bool ami_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6])
{
+ unsigned int i;
+ struct bez_point *old_p;
+ struct bez_point start_p, cur_p, p_a, p_b, p_c, p_r;
+
#ifdef AMI_PLOTTER_DEBUG
LOG(("[ami_plotter] Entered ami_path()"));
#endif
+
+ if (n == 0)
+ return true;
+
+ if (p[0] != PLOTTER_PATH_MOVE) {
+ LOG(("Path does not start with move"));
+ return false;
+ }
-/* For SVG only, because it needs Bezier curves we are going to cheat
- and insist on Cairo */
-#ifdef NS_AMIGA_CAIRO
-/* We should probably check if the off-screen bitmap is 32-bit and render
- * using Cairo regardless if it is. For now, we respect user preferences.
- */
if((nsoption_int(cairo_renderer) >= 1) && (palette_mapped == false))
{
- unsigned int i;
+#ifdef NS_AMIGA_CAIRO
cairo_matrix_t old_ctm, n_ctm;
- if (n == 0)
- return true;
-
- if (p[0] != PLOTTER_PATH_MOVE) {
- LOG(("Path does not start with move"));
- return false;
- }
-
/* Save CTM */
cairo_get_matrix(glob->cr, &old_ctm);
@@ -964,8 +1020,87 @@ bool ami_path(const float *p, unsigned int n, colour fill, float width,
ami_cairo_set_colour(glob->cr,c);
cairo_stroke(glob->cr);
}
- }
#endif
+ } else {
+ if (fill != NS_TRANSPARENT) {
+ ami_plot_setapen(fill);
+ if (c != NS_TRANSPARENT)
+ ami_plot_setopen(c);
+ } else {
+ if (c != NS_TRANSPARENT) {
+ ami_plot_setapen(c);
+ } else {
+ return true; /* wholly transparent */
+ }
+ }
+
+ /* Construct path */
+ for (i = 0; i < n; ) {
+ if (p[i] == PLOTTER_PATH_MOVE) {
+ if (fill != NS_TRANSPARENT) {
+ if(AreaMove(glob->rp, p[i+1], p[i+2]) == -1)
+ LOG(("AreaMove: vector list full"));
+ } else {
+ Move(glob->rp, p[i+1], p[i+2]);
+ }
+ /* Keep track for future Bezier curves/closes etc */
+ start_p.x = p[i+1];
+ start_p.y = p[i+2];
+ cur_p.x = start_p.x;
+ cur_p.y = start_p.y;
+ i += 3;
+ } else if (p[i] == PLOTTER_PATH_CLOSE) {
+ if (fill != NS_TRANSPARENT) {
+ if(AreaEnd(glob->rp) == -1)
+ LOG(("AreaEnd: error"));
+ } else {
+ Draw(glob->rp, start_p.x, start_p.y);
+ }
+ i++;
+ } else if (p[i] == PLOTTER_PATH_LINE) {
+ if (fill != NS_TRANSPARENT) {
+ if(AreaDraw(glob->rp, p[i+1], p[i+2]) == -1)
+ LOG(("AreaDraw: vector list full"));
+ } else {
+ Draw(glob->rp, p[i+1], p[i+2]);
+ }
+ cur_p.x = p[i+1];
+ cur_p.y = p[i+2];
+ i += 3;
+ } else if (p[i] == PLOTTER_PATH_BEZIER) {
+ p_a.x = p[i+1];
+ p_a.y = p[i+2];
+ p_b.x = p[i+3];
+ p_b.y = p[i+4];
+ p_c.x = p[i+5];
+ p_c.y = p[i+6];
+
+ for(double t = 0.0; t <= 1.0; t += 0.1) {
+ ami_bezier(&cur_p, &p_a, &p_b, &p_c, t, &p_r);
+ if (fill != NS_TRANSPARENT) {
+ if(AreaDraw(glob->rp, p_r.x, p_r.y) == -1)
+ LOG(("AreaDraw: vector list full"));
+ } else {
+ Draw(glob->rp, p_r.x, p_r.y);
+ }
+ }
+ cur_p.x = p_c.x;
+ cur_p.y = p_c.y;
+ i += 7;
+ } else {
+ LOG(("bad path command %f", p[i]));
+ /* End path for safety if using Area commands */
+ if (fill != NS_TRANSPARENT) {
+ AreaEnd(glob->rp);
+ BNDRYOFF(glob->rp);
+ }
+ return false;
+ }
+ }
+ if (fill != NS_TRANSPARENT)
+ BNDRYOFF(glob->rp);
+ }
+
return true;
}
diff --git a/image/bmp.c b/image/bmp.c
index c23f9dd54..946bca83b 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -132,7 +132,7 @@ static bool nsbmp_convert(struct content *c)
uint32_t swidth;
const char *data;
unsigned long size;
- char title[100];
+ char *title;
/* set the bmp data */
data = content__get_source_data(c, &size);
@@ -156,14 +156,19 @@ static bool nsbmp_convert(struct content *c)
/* Store our content width and description */
c->width = bmp->bmp->width;
c->height = bmp->bmp->height;
- LOG(("BMP width %u height %u", c->width, c->height));
- snprintf(title, sizeof(title), messages_get("BMPTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
swidth = bmp->bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bmp->bitmap) *
bmp->bmp->width;
c->size += (swidth * bmp->bmp->height) + 16 + 44;
+ /* set title text */
+ title = messages_get_buff("BMPTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
+
/* exit as a success */
bmp->bitmap = bmp->bmp->bitmap;
bitmap_modified(bmp->bitmap);
diff --git a/image/gif.c b/image/gif.c
index 93316e03e..704c9710b 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -242,7 +242,7 @@ static bool nsgif_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
- char title[100];
+ char *title;
/* Get the animation */
data = content__get_source_data(c, &size);
@@ -275,14 +275,20 @@ static bool nsgif_convert(struct content *c)
return false;
}
- /* Store our content width and description */
+ /* Store our content width, height and calculate size */
c->width = gif->gif->width;
c->height = gif->gif->height;
- snprintf(title, sizeof(title), messages_get("GIFTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
c->size += (gif->gif->width * gif->gif->height * 4) + 16 + 44;
+ /* set title text */
+ title = messages_get_buff("GIFTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
+
/* Schedule the animation if we have one */
gif->current_frame = 0;
if (gif->gif->frame_count_partial > 1)
diff --git a/image/ico.c b/image/ico.c
index b9abd7d1c..e455a59d9 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -100,7 +100,7 @@ static bool nsico_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
- char title[100];
+ char *title;
/* set the ico data */
data = content__get_source_data(c, &size);
@@ -122,14 +122,20 @@ static bool nsico_convert(struct content *c)
return false;
}
- /* Store our content width and description */
+ /* Store our content width, height and calculate size */
c->width = ico->ico->width;
c->height = ico->ico->height;
- snprintf(title, sizeof(title), messages_get("ICOTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
c->size += (ico->ico->width * ico->ico->height * 4) + 16 + 44;
+ /* set title text */
+ title = messages_get_buff("ICOTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
+
/* select largest icon to ensure one can be selected */
bmp = ico_find(ico->ico, 255, 255);
if (bmp == NULL) {
diff --git a/image/jpeg.c b/image/jpeg.c
index 82fde0dd1..fd18238f7 100644
--- a/image/jpeg.c
+++ b/image/jpeg.c
@@ -289,7 +289,7 @@ static bool nsjpeg_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
- char title[100];
+ char *title;
/* check image header is valid and get width/height */
data = content__get_source_data(c, &size);
@@ -325,9 +325,14 @@ static bool nsjpeg_convert(struct content *c)
image_cache_add(c, NULL, jpeg_cache_convert);
- snprintf(title, sizeof(title), messages_get("JPEGTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
+ /* set title text */
+ title = messages_get_buff("JPEGTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
content_set_ready(c);
content_set_done(c);
diff --git a/image/mng.c b/image/mng.c
index 67625f026..518dc8552 100644
--- a/image/mng.c
+++ b/image/mng.c
@@ -541,7 +541,7 @@ static bool nsmng_convert(struct content *c)
nsmng_content *mng = (nsmng_content *) c;
mng_retcode status;
unsigned long size;
- char title[100];
+ char *title;
assert(c != NULL);
@@ -554,12 +554,15 @@ static bool nsmng_convert(struct content *c)
return nsmng_broadcast_error(mng, -1) == NSERROR_OK;
}
- /* Set the title
- */
- snprintf(title, sizeof(title),
- messages_get("MNGTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
+
+ /* set title text */
+ title = messages_get_buff("MNGTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
c->size += c->width * c->height * 4;
content_set_ready(c);
@@ -599,7 +602,7 @@ static bool nsjpng_convert(struct content *c)
nsmng_content *mng = (nsmng_content *) c;
mng_retcode status;
unsigned long size;
- char title[100];
+ char *title;
mng_handle handle;
assert(c != NULL);
@@ -613,11 +616,14 @@ static bool nsjpng_convert(struct content *c)
return nsmng_broadcast_error(mng, -1) == NSERROR_OK;
}
- /* Set the title */
- snprintf(title, sizeof(title),
- messages_get("PNGTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
+ /* set title text */
+ title = messages_get_buff("PNGTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
c->size += c->width * c->height * 4;
content_set_ready(c);
diff --git a/image/nssprite.c b/image/nssprite.c
index ea05c8fe0..5f05c940a 100644
--- a/image/nssprite.c
+++ b/image/nssprite.c
@@ -98,7 +98,7 @@ static bool nssprite_convert(struct content *c)
const char *data;
unsigned long size;
- char title[100];
+ char *title;
data = content__get_source_data(c, &size);
@@ -144,9 +144,14 @@ static bool nssprite_convert(struct content *c)
c->width = sprite->width;
c->height = sprite->height;
- snprintf(title, sizeof(title), messages_get("SpriteTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
+ /* set title text */
+ title = messages_get_buff("SpriteTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
bitmap_modified(nssprite->bitmap);
diff --git a/image/png.c b/image/png.c
index 6f1d926ee..23c755825 100644
--- a/image/png.c
+++ b/image/png.c
@@ -510,7 +510,7 @@ png_cache_convert_error:
static bool nspng_convert(struct content *c)
{
nspng_content *png_c = (nspng_content *) c;
- char title[100];
+ char *title;
assert(png_c->png != NULL);
assert(png_c->info != NULL);
@@ -519,10 +519,13 @@ static bool nspng_convert(struct content *c)
png_destroy_read_struct(&png_c->png, &png_c->info, 0);
/* set title text */
- snprintf(title, sizeof(title), messages_get("PNGTitle"),
- c->width, c->height, c->size);
-
- content__set_title(c, title);
+ title = messages_get_buff("PNGTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
if (png_c->bitmap != NULL) {
bitmap_set_opaque(png_c->bitmap, bitmap_test_opaque(png_c->bitmap));
diff --git a/image/webp.c b/image/webp.c
index 080cf8bb0..fc4356c01 100644
--- a/image/webp.c
+++ b/image/webp.c
@@ -78,7 +78,7 @@ static bool webp_convert(struct content *c)
unsigned char *imagebuf = NULL;
unsigned long size;
int width = 0, height = 0;
- char title[100];
+ char *title;
int res = 0;
uint8_t *res_p = NULL;
@@ -116,9 +116,15 @@ static bool webp_convert(struct content *c)
c->width = width;
c->height = height;
- snprintf(title, sizeof(title), messages_get("WebPTitle"),
- width, height, size);
- content__set_title(c, title);
+
+ /* set title */
+ title = messages_get_buff("WebPTitle",
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
+ if (title != NULL) {
+ content__set_title(c, title);
+ free(title);
+ }
bitmap_modified(webp->bitmap);
diff --git a/javascript/jsapi.c b/javascript/jsapi.c
index f7ac3eda1..03e7ff5e3 100644
--- a/javascript/jsapi.c
+++ b/javascript/jsapi.c
@@ -17,6 +17,7 @@
*/
#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
#include "content/content.h"
#include "javascript/content.h"
@@ -90,46 +91,31 @@ void js_destroycontext(jscontext *ctx)
}
-
+/** Create new compartment to run scripts within
+ *
+ * This performs the following actions
+ * 1. constructs a new global object by initialising a window class
+ * 2. Instantiate the global a window object
+ */
jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
{
JSContext *cx = (JSContext *)ctx;
- JSObject *window_obj = NULL;
- JSObject *document_obj;
- JSObject *navigator_obj;
- JSObject *console_obj;
- struct html_content *htmlc = doc_priv;
-
- if (cx == NULL)
- goto js_newcompartment_fail;
-
- /* create the window object as the global */
- window_obj = jsapi_new_window(cx, NULL, win_priv);
- if (window_obj == NULL)
- goto js_newcompartment_fail;
-
- /* attach the subclasses off the window global */
- document_obj = jsapi_new_Document(cx, window_obj, htmlc->document, htmlc);
- if (document_obj == NULL)
- goto js_newcompartment_fail;
-
- navigator_obj = jsapi_new_navigator(cx, window_obj);
- if (navigator_obj == NULL)
- goto js_newcompartment_fail;
-
- /* @todo forms, history, location */
+ JSObject *window_proto;
+ JSObject *window;
- console_obj = jsapi_new_console(cx, window_obj);
- if (console_obj == NULL)
- goto js_newcompartment_fail;
-
- return (jsobject *)window_obj;
-
-js_newcompartment_fail:
+ if (cx == NULL) {
+ return NULL;
+ }
- LOG(("New compartment creation failed"));
+ window_proto = jsapi_InitClass_Window(cx, NULL);
+ if (window_proto == NULL) {
+ LOG(("Unable to initialise window class"));
+ return NULL;
+ }
- return NULL;
+ window = jsapi_new_Window(cx, window_proto, NULL, win_priv, doc_priv);
+
+ return (jsobject *)window;
}
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen)
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index 91d9184b4..93c0effdd 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -17,7 +17,7 @@
*/
/** \file
- * spidermonkey jsapi bindings and compatability glue.
+ * spidermonkey jsapi compatability glue.
*/
#ifndef _NETSURF_JAVASCRIPT_JSAPI_H_
@@ -149,47 +149,5 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
#endif
-/** Create a new javascript window object
- *
- * @param cx The javascript context.
- * @param parent The parent object or NULL for new global
- * @param win_priv The private context to set on the object
- * @return new javascript object or NULL on error
- */
-JSObject *jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv);
-
-/** Create a new javascript document object
- *
- * @param cx The javascript context.
- * @param parent The parent object, usually a global window object
- * @param doc_priv The private context to set on the object
- * @return new javascript object or NULL on error
- */
-JSObject *jsapi_new_Document(JSContext *cx, JSObject *parent, dom_document *node, struct html_content *htmlc);
-
-/** Create a new javascript console object
- *
- * @param cx The javascript context.
- * @param parent The parent object, usually a global window object
- * @return new javascript object or NULL on error
- */
-JSObject *jsapi_new_console(JSContext *cx, JSObject *parent);
-
-/** Create a new javascript navigator object
- *
- * @param cx The javascript context.
- * @param parent The parent object, usually a global window object
- * @return new javascript object or NULL on error
- */
-JSObject *jsapi_new_navigator(JSContext *cx, JSObject *parent);
-
-/** Create a new javascript element object
- *
- * @param cx The javascript context.
- * @param parent The parent object, usually a global window object
- * @param doc_priv The private context to set on the object
- * @return new javascript object or NULL on error
- */
-JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct html_content *htmlc, struct dom_element *domelement);
#endif
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
new file mode 100644
index 000000000..b565136af
--- /dev/null
+++ b/javascript/jsapi/binding.h
@@ -0,0 +1,82 @@
+/*
+ * 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/>.
+ */
+
+/** \file
+ * spidermonkey jsapi class bindings
+ */
+
+#ifndef _NETSURF_JAVASCRIPT_JSAPI_BINDING_H_
+#define _NETSURF_JAVASCRIPT_JSAPI_BINDING_H_
+
+JSObject *jsapi_InitClass_Window(JSContext *cx, JSObject *parent);
+
+/** Create a new javascript window object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object or NULL for new global
+ * @param win_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_Window(JSContext *cx,
+ JSObject *window,
+ JSObject *parent,
+ struct browser_window *bw,
+ html_content *htmlc);
+
+
+JSObject *jsapi_InitClass_Document(JSContext *cx, JSObject *parent);
+
+/** Create a new javascript document object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param doc_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_Document(JSContext *cx,
+ JSObject *proto,
+ JSObject *parent,
+ dom_document *node,
+ struct html_content *htmlc);
+
+/** Create a new javascript console object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_Console(JSContext *cx, JSObject *parent);
+
+/** Create a new javascript navigator object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *parent);
+
+/** Create a new javascript element object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param doc_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct html_content *htmlc, struct dom_element *domelement);
+
+#endif
diff --git a/javascript/jsapi/console.c b/javascript/jsapi/console.c
index 6a6d7d3c3..3cd51883d 100644
--- a/javascript/jsapi/console.c
+++ b/javascript/jsapi/console.c
@@ -137,7 +137,7 @@ static JSClass jsclass_console =
};
-JSObject *jsapi_new_console(JSContext *cx, JSObject *parent)
+JSObject *jsapi_new_Console(JSContext *cx, JSObject *parent)
{
return JS_InitClass(cx,
parent,
diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c
index 72d3837d9..476a38324 100644
--- a/javascript/jsapi/window.c
+++ b/javascript/jsapi/window.c
@@ -19,131 +19,33 @@
#include "utils/log.h"
#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
-/* IDL
-
-[NamedPropertiesObject]
-interface Window : EventTarget {
- // the current browsing context
- [Unforgeable] readonly attribute WindowProxy window;
- [Replaceable] readonly attribute WindowProxy self;
- [Unforgeable] readonly attribute Document document;
- attribute DOMString name;
- [PutForwards=href, Unforgeable] readonly attribute Location location;
- readonly attribute History history;
-
- boolean find(optional DOMString aString, optional boolean aCaseSensitive, optional boolean aBackwards, optional boolean aWrapAround, optional boolean aWholeWord, optional boolean aSearchInFrames, optional boolean aShowDialog);
-
- [Replaceable] readonly attribute BarProp locationbar;
- [Replaceable] readonly attribute BarProp menubar;
- [Replaceable] readonly attribute BarProp personalbar;
- [Replaceable] readonly attribute BarProp scrollbars;
- [Replaceable] readonly attribute BarProp statusbar;
- [Replaceable] readonly attribute BarProp toolbar;
- attribute DOMString status;
- void close();
- void stop();
- void focus();
- void blur();
-
- // other browsing contexts
- [Replaceable] readonly attribute WindowProxy frames;
- [Replaceable] readonly attribute unsigned long length;
- [Unforgeable] readonly attribute WindowProxy top;
- attribute WindowProxy? opener;
- readonly attribute WindowProxy parent;
- readonly attribute Element? frameElement;
- WindowProxy open(optional DOMString url, optional DOMString target, optional DOMString features, optional boolean replace);
- getter WindowProxy (unsigned long index);
- getter object (DOMString name);
-
- // the user agent
- readonly attribute Navigator navigator;
- readonly attribute External external;
- readonly attribute ApplicationCache applicationCache;
-
- // user prompts
- void alert(DOMString message);
- boolean confirm(DOMString message);
- DOMString? prompt(DOMString message, optional DOMString default);
- void print();
- any showModalDialog(DOMString url, optional any argument);
-
- // cross-document messaging
- void postMessage(any message, DOMString targetOrigin, optional sequence<Transferable> transfer);
-
- // event handler IDL attributes
- [TreatNonCallableAsNull] attribute Function? onabort;
- [TreatNonCallableAsNull] attribute Function? onafterprint;
- [TreatNonCallableAsNull] attribute Function? onbeforeprint;
- [TreatNonCallableAsNull] attribute Function? onbeforeunload;
- [TreatNonCallableAsNull] attribute Function? onblur;
- [TreatNonCallableAsNull] attribute Function? oncancel;
- [TreatNonCallableAsNull] attribute Function? oncanplay;
- [TreatNonCallableAsNull] attribute Function? oncanplaythrough;
- [TreatNonCallableAsNull] attribute Function? onchange;
- [TreatNonCallableAsNull] attribute Function? onclick;
- [TreatNonCallableAsNull] attribute Function? onclose;
- [TreatNonCallableAsNull] attribute Function? oncontextmenu;
- [TreatNonCallableAsNull] attribute Function? oncuechange;
- [TreatNonCallableAsNull] attribute Function? ondblclick;
- [TreatNonCallableAsNull] attribute Function? ondrag;
- [TreatNonCallableAsNull] attribute Function? ondragend;
- [TreatNonCallableAsNull] attribute Function? ondragenter;
- [TreatNonCallableAsNull] attribute Function? ondragleave;
- [TreatNonCallableAsNull] attribute Function? ondragover;
- [TreatNonCallableAsNull] attribute Function? ondragstart;
- [TreatNonCallableAsNull] attribute Function? ondrop;
- [TreatNonCallableAsNull] attribute Function? ondurationchange;
- [TreatNonCallableAsNull] attribute Function? onemptied;
- [TreatNonCallableAsNull] attribute Function? onended;
- [TreatNonCallableAsNull] attribute Function? onerror;
- [TreatNonCallableAsNull] attribute Function? onfocus;
- [TreatNonCallableAsNull] attribute Function? onhashchange;
- [TreatNonCallableAsNull] attribute Function? oninput;
- [TreatNonCallableAsNull] attribute Function? oninvalid;
- [TreatNonCallableAsNull] attribute Function? onkeydown;
- [TreatNonCallableAsNull] attribute Function? onkeypress;
- [TreatNonCallableAsNull] attribute Function? onkeyup;
- [TreatNonCallableAsNull] attribute Function? onload;
- [TreatNonCallableAsNull] attribute Function? onloadeddata;
- [TreatNonCallableAsNull] attribute Function? onloadedmetadata;
- [TreatNonCallableAsNull] attribute Function? onloadstart;
- [TreatNonCallableAsNull] attribute Function? onmessage;
- [TreatNonCallableAsNull] attribute Function? onmousedown;
- [TreatNonCallableAsNull] attribute Function? onmousemove;
- [TreatNonCallableAsNull] attribute Function? onmouseout;
- [TreatNonCallableAsNull] attribute Function? onmouseover;
- [TreatNonCallableAsNull] attribute Function? onmouseup;
- [TreatNonCallableAsNull] attribute Function? onmousewheel;
- [TreatNonCallableAsNull] attribute Function? onoffline;
- [TreatNonCallableAsNull] attribute Function? ononline;
- [TreatNonCallableAsNull] attribute Function? onpause;
- [TreatNonCallableAsNull] attribute Function? onplay;
- [TreatNonCallableAsNull] attribute Function? onplaying;
- [TreatNonCallableAsNull] attribute Function? onpagehide;
- [TreatNonCallableAsNull] attribute Function? onpageshow;
- [TreatNonCallableAsNull] attribute Function? onpopstate;
- [TreatNonCallableAsNull] attribute Function? onprogress;
- [TreatNonCallableAsNull] attribute Function? onratechange;
- [TreatNonCallableAsNull] attribute Function? onreset;
- [TreatNonCallableAsNull] attribute Function? onresize;
- [TreatNonCallableAsNull] attribute Function? onscroll;
- [TreatNonCallableAsNull] attribute Function? onseeked;
- [TreatNonCallableAsNull] attribute Function? onseeking;
- [TreatNonCallableAsNull] attribute Function? onselect;
- [TreatNonCallableAsNull] attribute Function? onshow;
- [TreatNonCallableAsNull] attribute Function? onstalled;
- [TreatNonCallableAsNull] attribute Function? onstorage;
- [TreatNonCallableAsNull] attribute Function? onsubmit;
- [TreatNonCallableAsNull] attribute Function? onsuspend;
- [TreatNonCallableAsNull] attribute Function? ontimeupdate;
- [TreatNonCallableAsNull] attribute Function? onunload;
- [TreatNonCallableAsNull] attribute Function? onvolumechange;
- [TreatNonCallableAsNull] attribute Function? onwaiting;
+
+struct jsclass_private {
+ struct browser_window *bw;
+ struct html_content *htmlc;
+ JSObject *document_obj;
+ JSObject *navigator_obj;
+ JSObject *console_obj;
};
-*/
+static void jsclass_finalize(JSContext *cx, JSObject *obj);
+static JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp);
+
+JSClass JSClass_Window = {
+ "Window",
+ JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_StrictPropertyStub,
+ JS_EnumerateStub,
+ (JSResolveOp)jsclass_resolve,
+ JS_ConvertStub,
+ jsclass_finalize,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
static JSBool JSAPI_NATIVE(alert, JSContext *cx, uintN argc, jsval *vp)
@@ -254,62 +156,130 @@ static JSBool JSAPI_PROPERTYGET(self, JSContext *cx, JSObject *obj, jsval *vp)
return JS_TRUE;
}
+static JSBool JSAPI_PROPERTYGET(document, JSContext *cx, JSObject *obj, jsval *vp)
+{
+ struct jsclass_private *private;
+
+ private = JS_GetInstancePrivate(cx,
+ obj,
+ &JSClass_Window,
+ NULL);
+ if (private == NULL)
+ return JS_FALSE;
+
+ JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(private->document_obj));
+ return JS_TRUE;
+}
+
static JSPropertySpec jsproperties_window[] =
{
+ JSAPI_PS_RO(document, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
JSAPI_PS_RO(window, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
JSAPI_PS_RO(self, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
JSAPI_PS_END
};
-/* The class of the global object. */
-static JSClass jsclass_window = {
- "window",
- JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
+static JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
+{
+ *objp = NULL;
+ return JS_TRUE;
+}
+static void jsclass_finalize(JSContext *cx, JSObject *obj)
+{ struct jsclass_private *private;
-JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
+ private = JS_GetInstancePrivate(cx, obj, &JSClass_Window, NULL);
+ if (private != NULL) {
+ free(private);
+ }
+}
+
+JSObject *jsapi_InitClass_Window(JSContext *cx, JSObject *parent)
{
JSObject *window = NULL;
+ JSObject *proto;
+
+ window = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL);
+ if (window == NULL) {
+ return NULL;
+ }
+
+ /** @todo reconsider global object handling. future
+ * editions of spidermonkey appear to be removing the
+ * idea of a global so we probably need to handle
+ * global object references internally
+ */
+
+ /* set the contexts global */
+ JS_SetGlobalObject(cx, window);
+
+ /* Populate the global object with the standard globals, like
+ * Object and Array.
+ */
+ if (!JS_InitStandardClasses(cx, window)) {
+ return NULL;
+ }
+
+ /* Initialises all the user javascript classes to make their
+ * prototypes available.
+ */
+ /** @todo should we be managing these prototype objects ourselves */
+ proto = jsapi_InitClass_Document(cx, window);
+ if (proto == NULL) {
+ return NULL;
+ }
+
+ return window;
+}
- if (parent == NULL) {
- window = JS_NewCompartmentAndGlobalObject(cx, &jsclass_window, NULL);
- if (window == NULL) {
- return NULL;
- }
-
- /** @todo reconsider global object handling. future
- * editions of spidermonkey appear to be removing the
- * idea of a global so we probably need to handle
- * global object references internally
- */
-
- /* set the contexts global */
- JS_SetGlobalObject(cx, window);
-
- /* Populate the global object with the standard globals, like
- * Object and Array.
- */
- if (!JS_InitStandardClasses(cx, window)) {
- return NULL;
- }
-
- } else {
- /* @todo sort out windows that are not globals */
- assert(false);
+JSObject *jsapi_new_Window(JSContext *cx,
+ JSObject *window,
+ JSObject *parent,
+ struct browser_window *bw,
+ html_content *htmlc)
+{
+ struct jsclass_private *private;
+
+ /* @todo sort out windows that are not globals */
+ assert(parent == NULL);
+
+ /* create private data */
+ private = malloc(sizeof(struct jsclass_private));
+ if (private == NULL) {
+ return NULL;
+ }
+ private->bw = bw;
+ private->htmlc = htmlc;
+
+
+ /* instantiate the subclasses off the window global */
+ private->document_obj = jsapi_new_Document(cx,
+ NULL,
+ window,
+ htmlc->document,
+ htmlc);
+ if (private->document_obj == NULL) {
+ free(private);
+ return NULL;
+ }
+
+/*
+ private->navigator_obj = jsapi_new_Navigator(cx, window);
+ if (private->navigator_obj == NULL) {
+ free(private);
+ return NULL;
+ }
+*/
+ /** @todo forms, history, location */
+
+ private->console_obj = jsapi_new_Console(cx, window);
+ if (private->console_obj == NULL) {
+ free(private);
+ return NULL;
}
/* private pointer to browsing context */
- if (!JS_SetPrivate(cx, window, win_priv))
+ if (!JS_SetPrivate(cx, window, private))
return NULL;
/* functions */
@@ -321,6 +291,7 @@ JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
if (!JS_DefineProperties(cx, window, jsproperties_window))
return NULL;
+
LOG(("Created new window object %p", window));
return window;
diff --git a/resources/FatMessages b/resources/FatMessages
index c2988a590..70d8f9698 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -2323,61 +2323,61 @@ nl.all.SelectMenu:Select
# Content titles
#
-en.all.DrawTitle:Draw image (%lux%lu, %lu bytes)
-de.all.DrawTitle:Draw Bild (%lux%lu, %lu bytes)
-fr.all.DrawTitle:Image Draw (%lux%lu, %lu octets)
-it.all.DrawTitle:Immagine Draw (%lux%lu, %lu byte)
-nl.all.DrawTitle:Draw image (%lux%lu, %lu bytes)
-en.all.GIFTitle:GIF image (%lux%lu, %lu bytes)
-de.all.GIFTitle:GIF Bild (%lux%lu, %lu bytes)
-fr.all.GIFTitle:Image GIF (%lux%lu, %lu octets)
-it.all.GIFTitle:Immagine GIF (%lux%lu, %lu byte)
-nl.all.GIFTitle:GIF image (%lux%lu, %lu bytes)
-en.all.BMPTitle:BMP image (%lux%lu, %lu bytes)
-de.all.BMPTitle:BMP Bild (%lux%lu, %lu bytes)
-fr.all.BMPTitle:Image BMP (%lux%lu, %lu octets)
-it.all.BMPTitle:Immagine BMP (%lux%lu, %lu byte)
-nl.all.BMPTitle:BMP image (%lux%lu, %lu bytes)
-en.all.ICOTitle:ICO image (%lux%lu, %lu bytes)
-de.all.ICOTitle:ICO Bild (%lux%lu, %lu bytes)
-fr.all.ICOTitle:Image BMP (%lux%lu, %lu octets)
-it.all.ICOTitle:Immagine ICO (%lux%lu, %lu byte)
-nl.all.ICOTitle:ICO image (%lux%lu, %lu bytes)
-en.all.JPEGTitle:JPEG image (%ux%u, %lu bytes)
-de.all.JPEGTitle:JPEG Bild (%ux%u, %lu bytes)
-fr.all.JPEGTitle:Image JPEG (%ux%u, %lu octets)
-it.all.JPEGTitle:Immagine JPEG (%ux%u, %lu byte)
-nl.all.JPEGTitle:JPEG image (%ux%u, %lu bytes)
-en.all.PNGTitle:PNG image (%lux%lu, %lu bytes)
-de.all.PNGTitle:PNG Bild (%lux%lu, %lu bytes)
-fr.all.PNGTitle:Image PNG (%lux%lu, %lu octets)
-it.all.PNGTitle:Immagine PNG (%lux%lu, %lu byte)
-nl.all.PNGTitle:PNG image (%lux%lu, %lu bytes)
-en.all.JNGTitle:JNG image (%lux%lu, %lu bytes)
-de.all.JNGTitle:JNG Bild (%lux%lu, %lu bytes)
-fr.all.JNGTitle:Image JNG (%lux%lu, %lu octets)
-it.all.JNGTitle:Immagine JNG (%lux%lu, %lu byte)
-nl.all.JNGTitle:JNG image (%lux%lu, %lu bytes)
-en.all.MNGTitle:MNG image (%lux%lu, %lu bytes)
-de.all.MNGTitle:MNG Bild (%lux%lu, %lu bytes)
-fr.all.MNGTitle:Image MNG (%lux%lu, %lu octets)
-it.all.MNGTitle:Immagine MNG (%lux%lu, %lu byte)
-nl.all.MNGTitle:MNG image (%lux%lu, %lu bytes)
-en.all.WebPTitle:WebP image (%lux%lu, %lu bytes)
-de.all.WebPTitle:WebP Bild (%lux%lu, %lu bytes)
-fr.all.WebPTitle:Image WebP (%lux%lu, %lu octets)
-it.all.WebPTitle:Immagine WebP (%lux%lu, %lu byte)
-nl.all.WebPTitle:WebP image (%lux%lu, %lu bytes)
-en.all.SpriteTitle:Sprite image (%lux%lu, %lu bytes)
-de.all.SpriteTitle:Sprite Bild (%lux%lu, %lu bytes)
-fr.all.SpriteTitle:Image Sprite (%lux%lu, %lu octets)
-it.all.SpriteTitle:Immagine Sprite (%lux%lu, %lu byte)
-nl.all.SpriteTitle:Sprite image (%lux%lu, %lu bytes)
-en.all.ArtWorksTitle:ArtWorks image (%lux%lu, %lu bytes)
-de.all.ArtWorksTitle:ArtWorks Bild (%lux%lu, %lu bytes)
-fr.all.ArtWorksTitle:Image ArtWorks (%lux%lu, %lu octets)
-it.all.ArtWorksTitle:Immagine ArtWorks (%lux%lu, %lu byte)
-nl.all.ArtWorksTitle:ArtWorks image (%lux%lu, %lu bytes)
+en.all.DrawTitle:%s (Draw image %lux%lu pixels)
+de.all.DrawTitle:%s (Draw Bild %lux%lu pixels)
+fr.all.DrawTitle:%s (Image Draw %lux%lu pixels)
+it.all.DrawTitle:%s (Immagine Draw %lux%lu pixels)
+nl.all.DrawTitle:%s (Draw image %lux%lu pixels)
+en.all.GIFTitle:%s (GIF image %lux%lu pixels)
+de.all.GIFTitle:%s (GIF Bild %lux%lu pixels)
+fr.all.GIFTitle:%s (Image GIF %lux%lu pixels)
+it.all.GIFTitle:%s (Immagine GIF %lux%lu pixels)
+nl.all.GIFTitle:%s (GIF image %lux%lu pixels)
+en.all.BMPTitle:%s (BMP image %lux%lu pixels)
+de.all.BMPTitle:%s (BMP Bild %lux%lu pixels)
+fr.all.BMPTitle:%s (Image BMP %lux%lu pixels)
+it.all.BMPTitle:%s (Immagine BMP %lux%lu pixels)
+nl.all.BMPTitle:%s (BMP image %lux%lu pixels)
+en.all.ICOTitle:%s (ICO image %lux%lu pixels)
+de.all.ICOTitle:%s (ICO Bild %lux%lu pixels)
+fr.all.ICOTitle:%s (Image BMP %lux%lu pixels)
+it.all.ICOTitle:%s (Immagine ICO %lux%lu pixels)
+nl.all.ICOTitle:%s (ICO image %lux%lu pixels)
+en.all.JPEGTitle:%s (JPEG image %lux%lu pixels)
+de.all.JPEGTitle:%s (JPEG Bild %lux%lu pixels)
+fr.all.JPEGTitle:%s (Image JPEG %lux%lu pixels)
+it.all.JPEGTitle:%s (Immagine JPEG %lux%lu pixels)
+nl.all.JPEGTitle:%s (JPEG image %lux%lu pixels)
+en.all.PNGTitle:%s (PNG image %lux%lu pixels)
+de.all.PNGTitle:%s (PNG Bild %lux%lu pixels)
+fr.all.PNGTitle:%s (Image PNG %lux%lu pixels)
+it.all.PNGTitle:%s (Immagine PNG %lux%lu pixels)
+nl.all.PNGTitle:%s (PNG image %lux%lu pixels)
+en.all.JNGTitle:%s (JNG image %lux%lu pixels)
+de.all.JNGTitle:%s (JNG Bild %lux%lu pixels)
+fr.all.JNGTitle:%s (Image JNG %lux%lu pixels)
+it.all.JNGTitle:%s (Immagine JNG %lux%lu pixels)
+nl.all.JNGTitle:%s (JNG image %lux%lu pixels)
+en.all.MNGTitle:%s (MNG image %lux%lu pixels)
+de.all.MNGTitle:%s (MNG Bild %lux%lu pixels)
+fr.all.MNGTitle:%s (Image MNG %lux%lu pixels)
+it.all.MNGTitle:%s (Immagine MNG %lux%lu pixels)
+nl.all.MNGTitle:%s (MNG image %lux%lu pixels)
+en.all.WebPTitle:%s (WebP image %lux%lu pixels)
+de.all.WebPTitle:%s (WebP Bild %lux%lu pixels)
+fr.all.WebPTitle:%s (Image WebP %lux%lu pixels)
+it.all.WebPTitle:%s (Immagine WebP %lux%lu pixels)
+nl.all.WebPTitle:%s (WebP image %lux%lu pixels)
+en.all.SpriteTitle:%s (Sprite image %lux%lu pixels)
+de.all.SpriteTitle:%s (Sprite Bild %lux%lu pixels)
+fr.all.SpriteTitle:%s (Image Sprite %lux%lu pixels)
+it.all.SpriteTitle:%s (Immagine Sprite %lux%lu pixels)
+nl.all.SpriteTitle:%s (Sprite image %lux%lu pixels)
+en.all.ArtWorksTitle:%s (ArtWorks image %lux%lu pixels)
+de.all.ArtWorksTitle:%s (ArtWorks Bild %lux%lu pixels)
+fr.all.ArtWorksTitle:%s (Image ArtWorks %lux%lu pixels)
+it.all.ArtWorksTitle:%s (Immagine ArtWorks %lux%lu pixels)
+nl.all.ArtWorksTitle:%s (ArtWorks image %lux%lu pixels)
# HTML page character set
#
diff --git a/riscos/content-handlers/artworks.c b/riscos/content-handlers/artworks.c
index 66808d42a..af1a3773c 100644
--- a/riscos/content-handlers/artworks.c
+++ b/riscos/content-handlers/artworks.c
@@ -172,7 +172,7 @@ bool artworks_convert(struct content *c)
void *init_routine;
os_error *error;
int used = -1; /* slightly better with older OSLib versions */
- char title[100];
+ char title[512];
/* check whether AWViewer has been seen and we can therefore
locate the ArtWorks rendering modules */
@@ -263,8 +263,9 @@ bool artworks_convert(struct content *c)
c->width = (aw->x1 - aw->x0) / 512;
c->height = (aw->y1 - aw->y0) / 512;
- snprintf(title, sizeof(title), messages_get("ArtWorksTitle"),
- c->width, c->height, source_size);
+ snprintf(title, sizeof(title), messages_get("ArtWorksTitle"),
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
content__set_title(c, title);
content_set_ready(c);
content_set_done(c);
diff --git a/riscos/content-handlers/draw.c b/riscos/content-handlers/draw.c
index d18d580cd..1d5a6b5d3 100644
--- a/riscos/content-handlers/draw.c
+++ b/riscos/content-handlers/draw.c
@@ -113,7 +113,7 @@ bool draw_convert(struct content *c)
const void *data;
os_box bbox;
os_error *error;
- char title[100];
+ char title[512];
source_data = content__get_source_data(c, &source_size);
data = source_data;
@@ -141,8 +141,9 @@ bool draw_convert(struct content *c)
draw->x0 = bbox.x0;
draw->y0 = bbox.y0;
- snprintf(title, sizeof(title), messages_get("DrawTitle"), c->width,
- c->height, source_size);
+ snprintf(title, sizeof(title), messages_get("DrawTitle"),
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
content__set_title(c, title);
content_set_ready(c);
diff --git a/riscos/content-handlers/sprite.c b/riscos/content-handlers/sprite.c
index 9a70ebe75..96642d13d 100644
--- a/riscos/content-handlers/sprite.c
+++ b/riscos/content-handlers/sprite.c
@@ -111,7 +111,7 @@ bool sprite_convert(struct content *c)
const char *source_data;
unsigned long source_size;
const void *sprite_data;
- char title[100];
+ char title[512];
source_data = content__get_source_data(c, &source_size);
@@ -140,8 +140,9 @@ bool sprite_convert(struct content *c)
c->width = w;
c->height = h;
- snprintf(title, sizeof(title), messages_get("SpriteTitle"), c->width,
- c->height, source_size);
+ snprintf(title, sizeof(title), messages_get("SpriteTitle"),
+ nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
+ c->width, c->height);
content__set_title(c, title);
content_set_ready(c);
content_set_done(c);
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 47b7f5451..8c525452a 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -1564,6 +1564,38 @@ const char *nsurl_access(const nsurl *url)
/* exported interface, documented in nsurl.h */
+const char *nsurl_access_leaf(const nsurl *url)
+{
+ size_t path_len;
+ const char *path;
+ const char *leaf;
+
+ if (url->components.path == NULL)
+ return "";
+
+ path = lwc_string_data(url->components.path);
+ path_len = lwc_string_length(url->components.path);
+
+ if (path_len == 0)
+ return "";
+
+ if (path_len == 1 && *path == '/')
+ return "/";
+
+ leaf = path + path_len;
+
+ do {
+ leaf--;
+ } while ((leaf != path) && (*leaf != '/'));
+
+ if (*leaf == '/')
+ leaf++;
+
+ return leaf;
+}
+
+
+/* exported interface, documented in nsurl.h */
size_t nsurl_length(const nsurl *url)
{
assert(url != NULL);
diff --git a/utils/nsurl.h b/utils/nsurl.h
index 068d08b8d..b075c42a1 100644
--- a/utils/nsurl.h
+++ b/utils/nsurl.h
@@ -183,6 +183,20 @@ const char *nsurl_access(const nsurl *url);
/**
+ * Access a URL's path leaf as a string
+ *
+ * \param url NetSurf URL to retrieve a string pointer for.
+ * \return the required string
+ *
+ * The returned string is owned by the NetSurf URL object. It will die
+ * with the NetSurf URL object. Keep a reference to the URL if you need it.
+ *
+ * The returned string has a trailing '\0'.
+ */
+const char *nsurl_access_leaf(const nsurl *url);
+
+
+/**
* Find the length of a NetSurf URL object's URL, as returned by nsurl_access
*
* \param url NetSurf URL to find length of.