summaryrefslogtreecommitdiff
path: root/cocoa
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-05-06 20:40:09 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-05-06 20:40:09 +0000
commite71691bae890040b83cfd54a2d9a1097d5026866 (patch)
tree96b2680dc6559ca0ab88fa0b6a533c13b7c9487e /cocoa
parente77b1a29550e4753f771848705975295a6ebe99e (diff)
downloadnetsurf-e71691bae890040b83cfd54a2d9a1097d5026866.tar.gz
netsurf-e71691bae890040b83cfd54a2d9a1097d5026866.tar.bz2
Merge branches/jmb/content-factory to trunk
svn path=/trunk/netsurf/; revision=12283
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/NetsurfApp.m5
-rw-r--r--cocoa/apple_image.h30
-rw-r--r--cocoa/apple_image.m142
-rw-r--r--cocoa/gui.m5
-rw-r--r--cocoa/save.m2
5 files changed, 150 insertions, 34 deletions
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 8897eb4b4..631d56b6c 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#import "cocoa/apple_image.h"
#import "cocoa/NetsurfApp.h"
#import "cocoa/gui.h"
#import "cocoa/plotter.h"
@@ -178,6 +179,8 @@ int main( int argc, char **argv )
option_ca_bundle = strdup( [[[NSBundle mainBundle] pathForResource: @"ca-bundle" ofType: @""] UTF8String] );
netsurf_init(&argc, &argv, options, messages);
+
+ apple_image_init();
NSApplication *app = cocoa_prepare_app();
@@ -191,6 +194,8 @@ int main( int argc, char **argv )
[app run];
netsurf_exit();
+
+ apple_image_fini();
return 0;
}
diff --git a/cocoa/apple_image.h b/cocoa/apple_image.h
index 1611cf52a..5d329c1c5 100644
--- a/cocoa/apple_image.h
+++ b/cocoa/apple_image.h
@@ -20,34 +20,18 @@
#ifndef _NETSURF_COCOA_APPLE_IMAGE_H_
#define _NETSURF_COCOA_APPLE_IMAGE_H_
-#ifdef WITH_APPLE_IMAGE
-
-#ifdef WITH_JPEG
-#error "Don't define WITH_JPEG and WITH_APPLE_IMAGE"
-#endif
-
#include "utils/config.h"
-#include "desktop/plot_style.h"
-
-struct bitmap;
-struct content;
-struct rect;
+#include "utils/errors.h"
-struct content_apple_image_data {
-};
+#ifdef WITH_APPLE_IMAGE
-bool apple_image_convert(struct content *c);
-void apple_image_destroy(struct content *c);
+nserror apple_image_init(void);
+void apple_image_fini(void);
-bool apple_image_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour);
-bool apple_image_redraw_tiled(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour,
- bool repeat_x, bool repeat_y);
+#else
-bool apple_image_clone(const struct content *old, struct content *new_content);
+#define apple_image_init() NSERROR_OK
+#define apple_image_fini() ((void) 0)
#endif /* WITH_APPLE_IMAGE */
diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m
index cdf3e537b..ab971667d 100644
--- a/cocoa/apple_image.m
+++ b/cocoa/apple_image.m
@@ -24,6 +24,119 @@
#include "content/content_protected.h"
#include "image/bitmap.h"
#include "desktop/plotters.h"
+#include "utils/talloc.h"
+
+typedef struct apple_image_content {
+ struct content base;
+} apple_image_content;
+
+static nserror apple_image_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c);
+static bool apple_image_convert(struct content *c);
+static void apple_image_destroy(struct content *c);
+static bool apple_image_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour);
+static bool apple_image_redraw_tiled(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour,
+ bool repeat_x, bool repeat_y);
+static nserror apple_image_clone(const struct content *old,
+ struct content **newc);
+static content_type apple_image_content_type(lwc_string *mime_type);
+
+static const content_handler apple_image_content_handler = {
+ apple_image_create,
+ NULL,
+ apple_image_convert,
+ NULL,
+ apple_image_destroy,
+ NULL,
+ NULL,
+ NULL,
+ apple_image_redraw,
+ apple_image_redraw_tiled,
+ NULL,
+ NULL,
+ apple_image_clone,
+ NULL,
+ apple_image_content_type,
+ false
+};
+
+static const char *apple_image_types[] = {
+ "image/jpeg",
+ "image/jpg",
+ "image/pjpeg"
+};
+
+static lwc_string *apple_image_mime_types[NOF_ELEMENTS(apple_image_types)];
+
+nserror apple_image_init(void)
+{
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
+
+ for (i = 0; i < NOF_ELEMENTS(apple_image_mime_types); i++) {
+ lerror = lwc_intern_string(apple_image_types[i],
+ strlen(apple_image_types[i]),
+ &apple_image_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
+ error = content_factory_register_handler(
+ apple_image_mime_types[i],
+ &apple_image_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ apple_image_fini();
+
+ return error;
+}
+
+void apple_image_fini(void)
+{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(apple_image_mime_types); i++) {
+ if (apple_image_mime_types[i] != NULL)
+ lwc_string_unref(apple_image_mime_types[i]);
+ }
+}
+
+nserror apple_image_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ apple_image_content *ai;
+ nserror error;
+
+ ai = talloc_zero(0, apple_image_content);
+ if (ai == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&ai->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(ai);
+ return error;
+ }
+
+ *c = (struct content *) ai;
+
+ return NSERROR_OK;
+}
/**
* Convert a CONTENT_APPLE_IMAGE for display.
@@ -67,18 +180,37 @@ void apple_image_destroy(struct content *c)
}
-bool apple_image_clone(const struct content *old, struct content *new_content)
+nserror apple_image_clone(const struct content *old, struct content **newc)
{
+ apple_image_content *ai;
+ nserror error;
+
+ ai = talloc_zero(0, apple_image_content);
+ if (ai == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &ai->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&ai->base);
+ return error;
+ }
+
if (old->status == CONTENT_STATUS_READY ||
old->status == CONTENT_STATUS_DONE) {
- new_content->width = old->width;
- new_content->height = old->height;
- new_content->bitmap = (void *)[(id)old->bitmap retain];
+ ai->base.width = old->width;
+ ai->base.height = old->height;
+ ai->base.bitmap = (void *)[(id)old->bitmap retain];
}
+
+ *newc = (struct content *) ai;
- return true;
+ return NSERROR_OK;
}
+content_type apple_image_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
+}
/**
* Redraw a CONTENT_APPLE_IMAGE.
diff --git a/cocoa/gui.m b/cocoa/gui.m
index f3a0b04a2..0ffc44543 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -258,11 +258,6 @@ void gui_window_stop_throbber(struct gui_window *g)
void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
{
-#ifdef WITH_BMP
- if (icon != NULL && content_get_type( icon ) == CONTENT_ICO)
- nsico_set_bitmap_from_size( icon, 16, 16 );
-#endif
-
NSBitmapImageRep *bmp = icon != NULL ? (NSBitmapImageRep *)content_get_bitmap( icon ) : NULL;
NSImage *image = nil;
diff --git a/cocoa/save.m b/cocoa/save.m
index a91a29810..9ee2f4cd8 100644
--- a/cocoa/save.m
+++ b/cocoa/save.m
@@ -23,7 +23,7 @@
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
bool save_complete_gui_save(const char *path, const char *filename,
- size_t len, const char *sourcedata, content_type type)
+ size_t len, const char *sourcedata, lwc_string *mime_type)
{
UNIMPL();
return false;