From eddae6af0663243a2677674d501f9a87d55798f5 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 30 Jun 2011 15:48:07 +0000 Subject: Remove plotter table global. Pass a redraw context around redraw functions. Knockout could be handled better. Note: untested on most front ends. svn path=/trunk/netsurf/; revision=12543 --- cocoa/BrowserView.m | 7 ++++++- cocoa/HistoryView.m | 7 ++++++- cocoa/Tree.m | 8 +++++++- cocoa/apple_image.m | 6 +++--- cocoa/plotter.h | 2 ++ cocoa/plotter.m | 2 +- cocoa/thumbnail.m | 8 +++++++- 7 files changed, 32 insertions(+), 8 deletions(-) (limited to 'cocoa') diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index 624aded23..7e4e5d649 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -147,6 +147,11 @@ static inline NSRect cocoa_get_caret_rect( BrowserView *view ) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; current_redraw_browser = browser; + + struct redraw_context ctx = { + .interactive = true, + .plot = &cocoa_plotters + }; const NSRect *rects = NULL; NSInteger count = 0; @@ -160,7 +165,7 @@ static inline NSRect cocoa_get_caret_rect( BrowserView *view ) .y1 = cocoa_pt_to_px( NSMaxY( rects[i] ) ) }; - browser_window_redraw(browser, 0, 0, &clip); + browser_window_redraw(browser, 0, 0, &clip, &ctx); } current_redraw_browser = NULL; diff --git a/cocoa/HistoryView.m b/cocoa/HistoryView.m index 65f971d28..a68418416 100644 --- a/cocoa/HistoryView.m +++ b/cocoa/HistoryView.m @@ -56,10 +56,15 @@ { [[NSColor clearColor] set]; [NSBezierPath fillRect: rect]; + + struct redraw_context ctx = { + .interactive = true, + .plot = &cocoa_plotters + }; cocoa_set_clip( rect ); - history_redraw( browser->history ); + history_redraw( browser->history, &ctx ); } - (void) mouseUp: (NSEvent *)theEvent; diff --git a/cocoa/Tree.m b/cocoa/Tree.m index 507dc3658..da03e75dc 100644 --- a/cocoa/Tree.m +++ b/cocoa/Tree.m @@ -19,6 +19,7 @@ #import "cocoa/Tree.h" #import "cocoa/coordinates.h" #import "cocoa/font.h" +#import "cocoa/plotter.h" #import "desktop/tree.h" @@ -124,8 +125,13 @@ static void tree_get_window_dimensions( int *width, int *height, void *data ) - (void) drawRect: (NSRect) rect inView: (NSView *) view; { + struct redraw_context ctx = { + .interactive = true, + .plot = &cocoa_plotters + }; + tree_draw( tree, 0, 0, cocoa_pt_to_px( NSMinX( rect ) ), cocoa_pt_to_px( NSMinY( rect )), - cocoa_pt_to_px( NSWidth( rect ) ), cocoa_pt_to_px( NSHeight( rect ) ) ); + cocoa_pt_to_px( NSWidth( rect ) ), cocoa_pt_to_px( NSHeight( rect ) ), &ctx ); } - (void) mouseAction: (browser_mouse_state)state atPoint: (NSPoint)point; diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m index 61f1c5257..11251d4e9 100644 --- a/cocoa/apple_image.m +++ b/cocoa/apple_image.m @@ -42,7 +42,7 @@ static nserror apple_image_create(const content_handler *handler, static bool apple_image_convert(struct content *c); static void apple_image_destroy(struct content *c); static bool apple_image_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror apple_image_clone(const struct content *old, struct content **newc); static content_type apple_image_content_type(lwc_string *mime_type); @@ -244,7 +244,7 @@ content_type apple_image_content_type(lwc_string *mime_type) */ bool apple_image_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { bitmap_flags_t flags = BITMAPF_NONE; @@ -253,7 +253,7 @@ bool apple_image_redraw(struct content *c, struct content_redraw_data *data, if (data->repeat_y) flags |= BITMAPF_REPEAT_Y; - return plot.bitmap(data->x, data->y, data->width, data->height, + return ctx->plot->bitmap(data->x, data->y, data->width, data->height, c->bitmap, data->background_colour, flags); } diff --git a/cocoa/plotter.h b/cocoa/plotter.h index fbcbc4615..8a26e5246 100644 --- a/cocoa/plotter.h +++ b/cocoa/plotter.h @@ -23,6 +23,8 @@ #import "desktop/plot_style.h" #import "cocoa/coordinates.h" +extern const struct plotter_table cocoa_plotters; + NSColor *cocoa_convert_colour( colour clr ); void cocoa_update_scale_factor( void ); diff --git a/cocoa/plotter.m b/cocoa/plotter.m index fe869751b..1d7fd2a8c 100644 --- a/cocoa/plotter.m +++ b/cocoa/plotter.m @@ -296,7 +296,7 @@ static bool plot_bitmap(int x, int y, int width, int height, return true; } -struct plotter_table plot = { +const struct plotter_table cocoa_plotters = { .clip = plot_clip, .arc = plot_arc, .disc = plot_disc, diff --git a/cocoa/thumbnail.m b/cocoa/thumbnail.m index 01239b9ec..16c944d7d 100644 --- a/cocoa/thumbnail.m +++ b/cocoa/thumbnail.m @@ -30,6 +30,12 @@ bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, { int bwidth = bitmap_get_width( bitmap ); int bheight = bitmap_get_height( bitmap ); + + struct redraw_context ctx = { + .interactive = false, + .plot = &cocoa_plotters + }; + CGColorSpaceRef cspace = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ); CGContextRef bitmapContext = CGBitmapContextCreate( bitmap_get_buffer( bitmap ), bwidth, bheight, @@ -46,7 +52,7 @@ bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: bitmapContext flipped: YES]]; - thumbnail_redraw( content, width, height ); + thumbnail_redraw( content, width, height, &ctx ); [NSGraphicsContext setCurrentContext: nil]; CGContextRelease( bitmapContext ); -- cgit v1.2.3