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 --- amiga/dt_anim.c | 8 +- amiga/dt_picture.c | 8 +- amiga/dt_sound.c | 10 +- amiga/gui.c | 14 +- amiga/history_local.c | 6 +- amiga/icon.c | 8 +- amiga/plugin_hack.c | 10 +- amiga/thumbnail.c | 7 +- amiga/tree.c | 6 +- atari/browser.c | 7 +- atari/plot.c | 2 +- atari/plot.h | 2 + atari/treeview.c | 7 +- beos/beos_scaffolding.cpp | 7 +- beos/beos_thumbnail.cpp | 9 +- beos/beos_window.cpp | 8 +- 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 +- content/content.c | 4 +- content/content.h | 5 +- content/content_protected.h | 5 +- desktop/browser.c | 25 +-- desktop/browser.h | 3 +- desktop/history_core.c | 54 +++--- desktop/history_core.h | 5 +- desktop/knockout.c | 74 ++++---- desktop/knockout.h | 3 +- desktop/plotters.h | 4 - desktop/print.c | 10 +- desktop/scrollbar.c | 62 ++++--- desktop/scrollbar.h | 4 +- desktop/textarea.c | 26 +-- desktop/textarea.h | 2 +- desktop/thumbnail.c | 15 +- desktop/thumbnail.h | 4 +- desktop/tree.c | 91 +++++----- desktop/tree.h | 3 +- framebuffer/fbtk/text.c | 6 +- framebuffer/framebuffer.c | 3 +- framebuffer/framebuffer.h | 6 +- framebuffer/gui.c | 6 +- framebuffer/localhistory.c | 7 +- gtk/scaffolding.c | 10 +- gtk/thumbnail.c | 10 +- gtk/treeview.c | 8 +- gtk/window.c | 7 +- image/bmp.c | 4 +- image/gif.c | 4 +- image/ico.c | 4 +- image/jpeg.c | 5 +- image/mng.c | 6 +- image/nssprite.c | 6 +- image/png.c | 4 +- image/rsvg.c | 4 +- image/svg.c | 19 +- image/webp.c | 6 +- monkey/browser.c | 7 +- monkey/plot.c | 2 +- render/form.c | 24 +-- render/form.h | 3 +- render/html.h | 3 +- render/html_internal.h | 2 +- render/html_redraw.c | 348 +++++++++++++++++++++---------------- render/textplain.c | 13 +- riscos/content-handlers/artworks.c | 6 +- riscos/content-handlers/draw.c | 6 +- riscos/content-handlers/sprite.c | 6 +- riscos/gui/url_bar.c | 6 +- riscos/history.c | 8 +- riscos/print.c | 16 +- riscos/save_draw.c | 7 +- riscos/thumbnail.c | 7 +- riscos/treeview.c | 11 +- riscos/window.c | 14 +- utils/types.h | 13 ++ windows/drawable.c | 6 +- windows/localhistory.c | 15 +- windows/plot.c | 2 +- windows/plot.h | 2 + windows/thumbnail.c | 6 +- 85 files changed, 739 insertions(+), 477 deletions(-) diff --git a/amiga/dt_anim.c b/amiga/dt_anim.c index afc1e1108..54f9867d6 100644 --- a/amiga/dt_anim.c +++ b/amiga/dt_anim.c @@ -61,7 +61,8 @@ static bool amiga_dt_anim_convert(struct content *c); static void amiga_dt_anim_reformat(struct content *c, int width, int height); static void amiga_dt_anim_destroy(struct content *c); static bool amiga_dt_anim_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip); + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx); static void amiga_dt_anim_open(struct content *c, struct browser_window *bw, struct content *page, struct box *box, struct object_params *params); @@ -250,7 +251,8 @@ void amiga_dt_anim_destroy(struct content *c) } bool amiga_dt_anim_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip) + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx) { amiga_dt_anim_content *plugin = (amiga_dt_anim_content *) c; @@ -263,7 +265,7 @@ bool amiga_dt_anim_redraw(struct content *c, 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/amiga/dt_picture.c b/amiga/dt_picture.c index 589642197..ebf8ba3fe 100644 --- a/amiga/dt_picture.c +++ b/amiga/dt_picture.c @@ -54,7 +54,8 @@ static nserror amiga_dt_picture_create(const content_handler *handler, static bool amiga_dt_picture_convert(struct content *c); static void amiga_dt_picture_destroy(struct content *c); static bool amiga_dt_picture_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip); + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx); static nserror amiga_dt_picture_clone(const struct content *old, struct content **newc); static content_type amiga_dt_picture_content_type(lwc_string *mime_type); @@ -220,7 +221,8 @@ void amiga_dt_picture_destroy(struct content *c) } bool amiga_dt_picture_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip) + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx) { LOG(("amiga_dt_picture_redraw")); bitmap_flags_t flags = BITMAPF_NONE; @@ -230,7 +232,7 @@ bool amiga_dt_picture_redraw(struct content *c, 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/amiga/dt_sound.c b/amiga/dt_sound.c index 6d35f3061..5f5c68d0c 100644 --- a/amiga/dt_sound.c +++ b/amiga/dt_sound.c @@ -50,7 +50,8 @@ static nserror amiga_dt_sound_create(const content_handler *handler, static bool amiga_dt_sound_convert(struct content *c); static void amiga_dt_sound_destroy(struct content *c); static bool amiga_dt_sound_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip); + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx); static void amiga_dt_sound_open(struct content *c, struct browser_window *bw, struct content *page, struct box *box, struct object_params *params); @@ -193,7 +194,8 @@ void amiga_dt_sound_destroy(struct content *c) } bool amiga_dt_sound_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip) + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx) { plot_style_t pstyle = { .fill_type = PLOT_OP_TYPE_SOLID, @@ -206,10 +208,10 @@ bool amiga_dt_sound_redraw(struct content *c, /* this should be some sort of play/stop control */ - plot.rectangle(data->x, data->y, data->x + data->width, + ctx->plot->rectangle(data->x, data->y, data->x + data->width, data->y + data->height, &pstyle); - return plot.text(data->x, data->y+20, + return ctx->plot->text(data->x, data->y+20, lwc_string_data(content__get_mime_type(c)), lwc_string_length(content__get_mime_type(c)), plot_style_font); diff --git a/amiga/gui.c b/amiga/gui.c index 0d99b9848..38b2b5c46 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -3194,6 +3194,10 @@ void ami_do_redraw_limits(struct gui_window *g, struct browser_window *bw, struct rect clip; struct RastPort *temprp; int posx, posy; + struct redraw_context ctx = { + .interactive = true, + .plot = &amiplot + }; if(!g) return; if(browser_window_redraw_ready(bw) == false) return; @@ -3228,7 +3232,6 @@ void ami_do_redraw_limits(struct gui_window *g, struct browser_window *bw, if((x1-x0)+(xoffset+x0-sx)>(width)) x1 = (width-(x0-sx)+x0); if((y1-y0)+(yoffset+y0-sy)>(height)) y1 = (height-(y0-sy)+y0); - plot = amiplot; glob = &browserglob; if(option_direct_render == false) @@ -3252,7 +3255,7 @@ void ami_do_redraw_limits(struct gui_window *g, struct browser_window *bw, posy = bbox->Top - sy; } - if(browser_window_redraw(bw, posx, posy, &clip)) + if(browser_window_redraw(bw, posx, posy, &clip, &ctx)) { ami_clearclipreg(&browserglob); @@ -3404,8 +3407,11 @@ void ami_do_redraw(struct gui_window_2 *g) else { struct rect clip; + struct redraw_context ctx = { + .interactive = true, + .plot = &amiplot + }; - plot = amiplot; glob = &browserglob; if(option_direct_render == false) @@ -3425,7 +3431,7 @@ void ami_do_redraw(struct gui_window_2 *g) clip.y1 = bbox->Top + bbox->Height; } - if(browser_window_redraw(g->bw, clip.x0 - hcurrent, clip.y0 - vcurrent, &clip)) + if(browser_window_redraw(g->bw, clip.x0 - hcurrent, clip.y0 - vcurrent, &clip, &ctx)) { ami_clearclipreg(&browserglob); diff --git a/amiga/history_local.c b/amiga/history_local.c index b23748606..cba981c3b 100755 --- a/amiga/history_local.c +++ b/amiga/history_local.c @@ -157,6 +157,10 @@ void ami_history_redraw(struct history_window *hw) { struct IBox *bbox; ULONG xs,ys; + struct redraw_context ctx = { + .interactive = true, + .plot = &amiplot + }; GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox); GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs); @@ -168,7 +172,7 @@ void ami_history_redraw(struct history_window *hw) RectFill(glob->rp, 0, 0, bbox->Width - 1, bbox->Height - 1); history_redraw_rectangle(history_current, xs, ys, - bbox->Width + xs, bbox->Height + ys, 0, 0); + bbox->Width + xs, bbox->Height + ys, 0, 0, &ctx); glob = &browserglob; diff --git a/amiga/icon.c b/amiga/icon.c index 74cef1b26..5205956f5 100644 --- a/amiga/icon.c +++ b/amiga/icon.c @@ -64,7 +64,8 @@ static nserror amiga_icon_create(const content_handler *handler, static bool amiga_icon_convert(struct content *c); static void amiga_icon_destroy(struct content *c); static bool amiga_icon_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip); + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx); static nserror amiga_icon_clone(const struct content *old, struct content **newc); static content_type amiga_icon_content_type(lwc_string *mime_type); @@ -286,7 +287,8 @@ void amiga_icon_destroy(struct content *c) */ bool amiga_icon_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip) + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx) { bitmap_flags_t flags = BITMAPF_NONE; @@ -295,7 +297,7 @@ bool amiga_icon_redraw(struct content *c, 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/amiga/plugin_hack.c b/amiga/plugin_hack.c index c10eb0772..72cba5e60 100644 --- a/amiga/plugin_hack.c +++ b/amiga/plugin_hack.c @@ -46,7 +46,8 @@ static bool amiga_plugin_hack_convert(struct content *c); static void amiga_plugin_hack_reformat(struct content *c, int width, int height); static void amiga_plugin_hack_destroy(struct content *c); static bool amiga_plugin_hack_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip); + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx); static void amiga_plugin_hack_open(struct content *c, struct browser_window *bw, struct content *page, struct box *box, struct object_params *params); @@ -143,7 +144,8 @@ void amiga_plugin_hack_destroy(struct content *c) } bool amiga_plugin_hack_redraw(struct content *c, - struct content_redraw_data *data, const struct rect *clip) + struct content_redraw_data *data, const struct rect *clip, + const struct redraw_context *ctx) { plot_style_t pstyle = { .fill_type = PLOT_OP_TYPE_SOLID, @@ -154,10 +156,10 @@ bool amiga_plugin_hack_redraw(struct content *c, LOG(("amiga_plugin_hack_redraw")); - plot.rectangle(data->x, data->y, data->x + data->width, + ctx->plot->rectangle(data->x, data->y, data->x + data->width, data->y + data->height, &pstyle); - return plot.text(data->x, data->y+20, + return ctx->plot->text(data->x, data->y+20, lwc_string_data(content__get_mime_type(c)), lwc_string_length(content__get_mime_type(c)), plot_style_font); diff --git a/amiga/thumbnail.c b/amiga/thumbnail.c index be15877de..af0375ba8 100755 --- a/amiga/thumbnail.c +++ b/amiga/thumbnail.c @@ -42,6 +42,10 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, struct BitScaleArgs bsa; int plot_width; int plot_height; + struct redraw_context ctx = { + .interactive = false, + .plot = &amiplot + }; plot_width = MIN(content_get_width(content), 1024); plot_height = ((plot_width * bitmap->height) + (bitmap->width / 2)) / @@ -55,9 +59,8 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, bitmap->nativebmheight = bitmap->height; ami_clearclipreg(&browserglob); current_redraw_browser = curbw; - plot = amiplot; - thumbnail_redraw(content, plot_width, plot_height); + thumbnail_redraw(content, plot_width, plot_height, &ctx); current_redraw_browser = NULL; diff --git a/amiga/tree.c b/amiga/tree.c index c474a99bd..efd8f450c 100755 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -1235,6 +1235,10 @@ void ami_tree_redraw_request(int x, int y, int width, int height, void *data) struct treeview_window *twin = data; struct IBox *bbox; int pos_x, pos_y; + struct redraw_context ctx = { + .interactive = true, + .plot = &amiplot + }; if(!twin->win) return; // if(tree_get_redraw(twin->tree) == false) return; @@ -1249,7 +1253,7 @@ void ami_tree_redraw_request(int x, int y, int width, int height, void *data) if(x - pos_x + width > bbox->Width) width = bbox->Width - (x - pos_x); if(y - pos_y + height > bbox->Height) height = bbox->Height - (y - pos_y); - tree_draw(twin->tree, -pos_x, -pos_y, x, y, width, height); + tree_draw(twin->tree, -pos_x, -pos_y, x, y, width, height, &ctx); BltBitMapRastPort(twin->globals.bm, x - pos_x, y - pos_y, twin->win->RPort, bbox->Left + x - pos_x, bbox->Top + y - pos_y, width, height, 0x0C0); diff --git a/atari/browser.c b/atari/browser.c index d5c86fbe2..ed2f644aa 100755 --- a/atari/browser.c +++ b/atari/browser.c @@ -903,6 +903,11 @@ static void browser_redraw_content( struct gui_window * gw, int xoff, int yoff ) CMP_BROWSER b = gw->browser; struct rect clip; + struct redraw_context ctx = { + .interactive = true, + .plot = &atari_plotters + }; + LOG(("%s : %d,%d - %d,%d\n", b->bw->name, b->redraw.area.x0, b->redraw.area.y0, b->redraw.area.x1, b->redraw.area.y1 )); @@ -915,7 +920,7 @@ static void browser_redraw_content( struct gui_window * gw, int xoff, int yoff ) a.y1 = b->redraw.area.y1; browser_window_redraw( b->bw, -b->scroll.current.x, - -b->scroll.current.y, &a ); + -b->scroll.current.y, &a, &ctx ); current_redraw_browser = NULL; } diff --git a/atari/plot.c b/atari/plot.c index 16e19149c..1a6ce4b44 100755 --- a/atari/plot.c +++ b/atari/plot.c @@ -238,7 +238,7 @@ static bool plot_path(const float *p, unsigned int n, colour fill, float width, -struct plotter_table plot = { +const struct plotter_table atari_plotter = { .rectangle = plot_rectangle, .line = plot_line, .polygon = plot_polygon, diff --git a/atari/plot.h b/atari/plot.h index 7be7d6aa3..02d9f37a9 100755 --- a/atari/plot.h +++ b/atari/plot.h @@ -24,6 +24,8 @@ struct rect; +extern const struct plotter_table atari_plotters; + int atari_plotter_init( char*, char * ); int atari_plotter_finalise( void ); void plot_set_knockout( int set ); diff --git a/atari/treeview.c b/atari/treeview.c index aaa3621af..9b925f6dc 100755 --- a/atari/treeview.c +++ b/atari/treeview.c @@ -312,6 +312,11 @@ void atari_treeview_redraw( NSTREEVIEW tv) GRECT work; WindGetGrect( tv->window, WF_WORKXYWH, &work ); + struct redraw_context ctx = { + .interactive = true, + .plot = &atari_plotters + }; + plotter->resize(plotter, work.g_w, work.g_h); plotter->move(plotter, work.g_x, work.g_y ); @@ -339,7 +344,7 @@ void atari_treeview_redraw( NSTREEVIEW tv) if (rc_intersect((GRECT *)&tv->rdw_area,(GRECT *)&todo)) { tree_draw(tv->tree, -tv->window->xpos*16, -tv->window->ypos*16, - todo[0], todo[1], todo[2], todo[3] + todo[0], todo[1], todo[2], todo[3], &ctx ); } if (wind_get(tv->window->handle, WF_NEXTXYWH, diff --git a/beos/beos_scaffolding.cpp b/beos/beos_scaffolding.cpp index 63c0be4dc..6693dc1c7 100644 --- a/beos/beos_scaffolding.cpp +++ b/beos/beos_scaffolding.cpp @@ -1384,6 +1384,11 @@ gboolean nsbeos_history_expose_event(beosWidget *widget, struct beos_history_window *hw = (struct beos_history_window *)g; struct browser_window *bw = nsbeos_get_browser_for_gui(hw->g->top_level); + struct redraw_context ctx = { + .interactive = true, + .plot = &nsbeos_plotters + }; + current_widget = widget; current_drawable = widget->window; current_gc = gdk_gc_new(current_drawable); @@ -1392,7 +1397,7 @@ gboolean nsbeos_history_expose_event(beosWidget *widget, #endif plot = nsbeos_plotters; - history_redraw(bw->history); + history_redraw(bw->history, &ctx); g_object_unref(current_gc); #ifdef CAIRO_VERSION diff --git a/beos/beos_thumbnail.cpp b/beos/beos_thumbnail.cpp index 88e291c44..3d49d5c10 100644 --- a/beos/beos_thumbnail.cpp +++ b/beos/beos_thumbnail.cpp @@ -71,6 +71,11 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, int big_height; int depth; + struct redraw_context ctx = { + .interactive = false, + .plot = &nsbeos_plotters + }; + assert(content); assert(bitmap); @@ -116,10 +121,8 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, /* impose our view on the content... */ nsbeos_current_gc_set(view); - plot = nsbeos_plotters; - /* render the content */ - thumbnail_redraw(content, big_width, big_height); + thumbnail_redraw(content, big_width, big_height, &ctx); view->Sync(); view->UnlockLooper(); diff --git a/beos/beos_window.cpp b/beos/beos_window.cpp index fc2c568e2..d7153fb79 100644 --- a/beos/beos_window.cpp +++ b/beos/beos_window.cpp @@ -920,6 +920,11 @@ void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message) float scale = g->bw->scale; struct rect clip; + struct redraw_context ctx = { + .interactive = true, + .plot = &nsbeos_plotters + }; + assert(g); assert(g->bw); @@ -947,7 +952,6 @@ void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message) if (view->Window()) view->Window()->BeginViewTransaction(); - plot = nsbeos_plotters; current_redraw_browser = g->bw; clip.x0 = (int)updateRect.left; @@ -955,7 +959,7 @@ void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message) clip.x1 = (int)updateRect.right + 1; clip.y1 = (int)updateRect.bottom + 1; - browser_window_redraw(g->bw, 0, 0, &clip); + browser_window_redraw(g->bw, 0, 0, &clip, &ctx); current_redraw_browser = NULL; 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 ); diff --git a/content/content.c b/content/content.c index 3aed46f36..1f7003404 100644 --- a/content/content.c +++ b/content/content.c @@ -490,7 +490,7 @@ void content__request_redraw(struct content *c, */ bool content_redraw(hlcache_handle *h, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { struct content *c = hlcache_handle_get_content(h); @@ -506,7 +506,7 @@ bool content_redraw(hlcache_handle *h, struct content_redraw_data *data, return true; } - return c->handler->redraw(c, data, clip); + return c->handler->redraw(c, data, clip, ctx); } diff --git a/content/content.h b/content/content.h index 39f784904..ca267060c 100644 --- a/content/content.h +++ b/content/content.h @@ -33,6 +33,7 @@ #include "utils/config.h" #include "utils/errors.h" #include "utils/http.h" +#include "utils/types.h" #include "content/content_factory.h" #include "content/content_type.h" #include "desktop/mouse.h" @@ -45,6 +46,8 @@ struct llcache_handle; struct hlcache_handle; struct object_params; struct rect; +struct redraw_context; + /** Status of a content */ typedef enum { @@ -149,7 +152,7 @@ void content_mouse_track(struct hlcache_handle *h, struct browser_window *bw, void content_mouse_action(struct hlcache_handle *h, struct browser_window *bw, browser_mouse_state mouse, int x, int y); bool content_redraw(struct hlcache_handle *h, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); void content_open(struct hlcache_handle *h, struct browser_window *bw, struct content *page, struct box *box, struct object_params *params); diff --git a/content/content_protected.h b/content/content_protected.h index 688010ec8..bc2079017 100644 --- a/content/content_protected.h +++ b/content/content_protected.h @@ -36,6 +36,8 @@ struct bitmap; struct content; +struct rect; +struct redraw_context; struct content_handler { nserror (*create)(const content_handler *handler, @@ -55,7 +57,8 @@ struct content_handler { void (*mouse_action)(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y); bool (*redraw)(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, + const struct redraw_context *ctx); void (*open)(struct content *c, struct browser_window *bw, struct content *page, struct box *box, diff --git a/desktop/browser.c b/desktop/browser.c index 1f09465b1..827896835 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -94,8 +94,9 @@ static void browser_window_mouse_drag_end(struct browser_window *bw, /* exported interface, documented in browser.h */ bool browser_window_redraw(struct browser_window *bw, int x, int y, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { + struct redraw_context new_ctx = *ctx; int width = 0; int height = 0; bool plot_ok = true; @@ -109,17 +110,20 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y, if (bw->current_content == NULL) { /* Browser window has no content, render blank fill */ - plot.clip(clip); - return plot.rectangle(clip->x0, clip->y0, clip->x1, clip->y1, + ctx->plot->clip(clip); + return ctx->plot->rectangle(clip->x0, clip->y0, + clip->x1, clip->y1, plot_style_fill_white); } - /* Browser window has content */ if (bw->browser_window_type != BROWSER_WINDOW_IFRAME && - plot.option_knockout) - knockout_plot_start(&plot); + ctx->plot->option_knockout) { + knockout_plot_start(ctx, &new_ctx); + } - plot.clip(clip); + /* Browser window has content */ + + new_ctx.plot->clip(clip); content_type = content_get_type(bw->current_content); if (content_type != CONTENT_HTML && content_type != CONTENT_TEXTPLAIN) { @@ -129,7 +133,7 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y, /* Non-HTML may not fill viewport to extents, so plot white * background fill */ - plot_ok &= plot.rectangle(clip->x0, clip->y0, + plot_ok &= new_ctx.plot->rectangle(clip->x0, clip->y0, clip->x1, clip->y1, plot_style_fill_white); } @@ -145,11 +149,12 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y, data.repeat_y = false; /* Render the content */ - plot_ok &= content_redraw(bw->current_content, &data, clip); + plot_ok &= content_redraw(bw->current_content, &data, clip, &new_ctx); if (bw->browser_window_type != BROWSER_WINDOW_IFRAME && - plot.option_knockout) + ctx->plot->option_knockout) { knockout_plot_end(); + } return plot_ok; } diff --git a/desktop/browser.h b/desktop/browser.h index 39d6bf942..136f97f0f 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -268,6 +268,7 @@ bool browser_window_stop_available(struct browser_window *bw); * \param x coordinate for top-left of redraw * \param y coordinate for top-left of redraw * \param clip clip rectangle coordinates + * \param ctx redraw context * \return true if successful, false otherwise * * The clip rectangle is guaranteed to be filled to its extents, so there is @@ -280,7 +281,7 @@ bool browser_window_stop_available(struct browser_window *bw); * Units for x, y and clip are pixels. */ bool browser_window_redraw(struct browser_window *bw, int x, int y, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); /** * Check whether browser window is ready for redraw diff --git a/desktop/history_core.c b/desktop/history_core.c index 581b072dc..70e8f158c 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -89,7 +89,7 @@ static int history_layout_subtree(struct history *history, static bool history_redraw_entry(struct history *history, struct history_entry *entry, int x0, int y0, int x1, int y1, - int x, int y, bool clip); + int x, int y, bool clip, const struct redraw_context *ctx); static struct history_entry *history_find_position(struct history_entry *entry, int x, int y); static bool history_enumerate_entry(const struct history *history, @@ -558,40 +558,39 @@ void history_size(struct history *history, int *width, int *height) /** * Redraw a history. * - * \param history history to render - * - * The current plotter is used. + * \param history history to render + * \param ctx current redraw context */ -bool history_redraw(struct history *history) +bool history_redraw(struct history *history, const struct redraw_context *ctx) { if (!history->start) return true; - return history_redraw_entry(history, history->start, 0, 0, 0, 0, 0, 0, false); + return history_redraw_entry(history, history->start, 0, 0, 0, 0, 0, 0, + false, ctx); } /** * Redraw part of a history. * - * \param history history to render - * \param x0 left X co-ordinate of redraw area - * \param y0 top Y co-ordinate of redraw area - * \param x1 right X co-ordinate of redraw area - * \param y1 lower Y co-ordinate of redraw area - * \param x start X co-ordinate on plot canvas - * \param y start Y co-ordinate on plot canvas - * - * The current plotter is used. + * \param history history to render + * \param x0 left X co-ordinate of redraw area + * \param y0 top Y co-ordinate of redraw area + * \param x1 right X co-ordinate of redraw area + * \param y1 lower Y co-ordinate of redraw area + * \param x start X co-ordinate on plot canvas + * \param y start Y co-ordinate on plot canvas + * \param ctx current redraw context */ bool history_redraw_rectangle(struct history *history, int x0, int y0, int x1, int y1, - int x, int y) + int x, int y, const struct redraw_context *ctx) { if (!history->start) return true; return history_redraw_entry(history, history->start, - x0, y0, x1, y1, x, y, true); + x0, y0, x1, y1, x, y, true, ctx); } /** @@ -599,13 +598,15 @@ bool history_redraw_rectangle(struct history *history, * * \param history history containing the entry * \param history_entry entry to render + * \param ctx current redraw context */ bool history_redraw_entry(struct history *history, struct history_entry *entry, int x0, int y0, int x1, int y1, - int x, int y, bool clip) + int x, int y, bool clip, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; size_t char_offset; int actual_x; struct history_entry *child; @@ -626,14 +627,14 @@ bool history_redraw_entry(struct history *history, rect.y0 = y0 + yoffset; rect.x1 = x1 + xoffset; rect.y1 = y1 + yoffset; - if(!plot.clip(&rect)) + if(!plot->clip(&rect)) return false; } - if (!plot.bitmap(entry->x + xoffset, entry->y + yoffset, WIDTH, HEIGHT, + if (!plot->bitmap(entry->x + xoffset, entry->y + yoffset, WIDTH, HEIGHT, entry->bitmap, 0xffffff, 0)) return false; - if (!plot.rectangle(entry->x - 1 + xoffset, + if (!plot->rectangle(entry->x - 1 + xoffset, entry->y - 1 + yoffset, entry->x + xoffset + WIDTH, entry->y + yoffset + HEIGHT, @@ -649,29 +650,30 @@ bool history_redraw_entry(struct history *history, fstyle.foreground = c; fstyle.weight = entry == history->current ? 900 : 400; - if (!plot.text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset, + if (!plot->text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset, entry->page.title, char_offset, &fstyle)) return false; for (child = entry->forward; child; child = child->next) { - if (!plot.line(entry->x + WIDTH + xoffset, + if (!plot->line(entry->x + WIDTH + xoffset, entry->y + HEIGHT / 2 + yoffset, entry->x + WIDTH + tailsize + xoffset, entry->y + HEIGHT / 2 + yoffset, plot_style_stroke_history)) return false; - if (!plot.line(entry->x + WIDTH + tailsize + xoffset, + if (!plot->line(entry->x + WIDTH + tailsize + xoffset, entry->y + HEIGHT / 2 + yoffset, child->x - tailsize +xoffset, child->y + HEIGHT / 2 + yoffset, plot_style_stroke_history)) return false; - if (!plot.line(child->x - tailsize + xoffset, + if (!plot->line(child->x - tailsize + xoffset, child->y + HEIGHT / 2 + yoffset, child->x + xoffset, child->y + HEIGHT / 2 + yoffset, plot_style_stroke_history)) return false; - if (!history_redraw_entry(history, child, x0, y0, x1, y1, x, y, clip)) + if (!history_redraw_entry(history, child, x0, y0, x1, y1, x, y, + clip, ctx)) return false; } diff --git a/desktop/history_core.h b/desktop/history_core.h index be09fb1cb..883ee9cea 100644 --- a/desktop/history_core.h +++ b/desktop/history_core.h @@ -41,9 +41,10 @@ void history_forward(struct browser_window *bw, struct history *history); bool history_back_available(struct history *history); bool history_forward_available(struct history *history); void history_size(struct history *history, int *width, int *height); -bool history_redraw(struct history *history); +bool history_redraw(struct history *history, const struct redraw_context *ctx); bool history_redraw_rectangle(struct history *history, - int x0, int y0, int x1, int y1, int x, int y); + int x0, int y0, int x1, int y1, int x, int y, + const struct redraw_context *ctx); bool history_click(struct browser_window *bw, struct history *history, int x, int y, bool new_window); const char *history_position_url(struct history *history, int x, int y); diff --git a/desktop/knockout.c b/desktop/knockout.c index 5d0ecbc2a..0385ee80b 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -80,7 +80,6 @@ struct knockout_box; struct knockout_entry; -static void knockout_set_plotters(void); static void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *box); static bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_style); static bool knockout_plot_bitmap_recursive(struct knockout_box *box, @@ -228,15 +227,18 @@ static int nested_depth = 0; /** * Start a knockout plotting session * - * \param plotter the plotter to use + * \param ctx the redraw context with real plotter table + * \param knk_ctx updated to copy of ctx, with plotter table replaced * \return true on success, false otherwise */ -bool knockout_plot_start(struct plotter_table *plotter) +bool knockout_plot_start(const struct redraw_context *ctx, + struct redraw_context *knk_ctx) { /* check if we're recursing */ if (nested_depth++ > 0) { /* we should already have the knockout renderer as default */ - assert(plotter->rectangle == knockout_plotters.rectangle); + assert(ctx->plot->rectangle == knockout_plotters.rectangle); + *knk_ctx = *ctx; return true; } @@ -244,9 +246,12 @@ bool knockout_plot_start(struct plotter_table *plotter) if (knockout_entry_cur > 0) knockout_plot_end(); - /* take over the plotter */ - real_plot = *plotter; - knockout_set_plotters(); + /* get copy of real plotter table */ + real_plot = *(ctx->plot); + + /* set up knockout rendering context */ + *knk_ctx = *ctx; + knk_ctx->plot = &knockout_plotters; return true; } @@ -286,13 +291,10 @@ bool knockout_plot_flush(void) knockout_polygon_cur, KNOCKOUT_POLYGONS)); #endif - /* release our plotter */ - plot = real_plot; - for (i = 0; i < knockout_entry_cur; i++) { switch (knockout_entries[i].type) { case KNOCKOUT_PLOT_RECTANGLE: - success &= plot.rectangle( + success &= real_plot.rectangle( knockout_entries[i].data.rectangle.x0, knockout_entries[i].data.rectangle.y0, knockout_entries[i].data.rectangle.x1, @@ -300,7 +302,7 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.rectangle.plot_style); break; case KNOCKOUT_PLOT_LINE: - success &= plot.line( + success &= real_plot.line( knockout_entries[i].data.line.x0, knockout_entries[i].data.line.y0, knockout_entries[i].data.line.x1, @@ -308,7 +310,7 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.line.plot_style); break; case KNOCKOUT_PLOT_POLYGON: - success &= plot.polygon( + success &= real_plot.polygon( knockout_entries[i].data.polygon.p, knockout_entries[i].data.polygon.n, &knockout_entries[i].data.polygon.plot_style); @@ -319,7 +321,7 @@ bool knockout_plot_flush(void) success &= knockout_plot_fill_recursive(box, &knockout_entries[i].data.fill.plot_style); else if (!knockout_entries[i].box->deleted) - success &= plot.rectangle( + success &= real_plot.rectangle( knockout_entries[i].data.fill.x0, knockout_entries[i].data.fill.y0, knockout_entries[i].data.fill.x1, @@ -327,11 +329,11 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.fill.plot_style); break; case KNOCKOUT_PLOT_CLIP: - success &= plot.clip( + success &= real_plot.clip( &knockout_entries[i].data.clip); break; case KNOCKOUT_PLOT_TEXT: - success &= plot.text( + success &= real_plot.text( knockout_entries[i].data.text.x, knockout_entries[i].data.text.y, knockout_entries[i].data.text.text, @@ -339,14 +341,14 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.text.font_style); break; case KNOCKOUT_PLOT_DISC: - success &= plot.disc( + success &= real_plot.disc( knockout_entries[i].data.disc.x, knockout_entries[i].data.disc.y, knockout_entries[i].data.disc.radius, &knockout_entries[i].data.disc.plot_style); break; case KNOCKOUT_PLOT_ARC: - success &= plot.arc( + success &= real_plot.arc( knockout_entries[i].data.arc.x, knockout_entries[i].data.arc.y, knockout_entries[i].data.arc.radius, @@ -360,7 +362,7 @@ bool knockout_plot_flush(void) success &= knockout_plot_bitmap_recursive(box, &knockout_entries[i]); } else if (!knockout_entries[i].box->deleted) { - success &= plot.bitmap( + success &= real_plot.bitmap( knockout_entries[i].data. bitmap.x, knockout_entries[i].data. @@ -378,11 +380,11 @@ bool knockout_plot_flush(void) } break; case KNOCKOUT_PLOT_GROUP_START: - success &= plot.group_start( + success &= real_plot.group_start( knockout_entries[i].data.group_start.name); break; case KNOCKOUT_PLOT_GROUP_END: - success &= plot.group_end(); + success &= real_plot.group_end(); break; } } @@ -392,26 +394,10 @@ bool knockout_plot_flush(void) knockout_polygon_cur = 0; knockout_list = NULL; - /* re-instate knockout plotters if we are still active */ - if (nested_depth > 0) - knockout_set_plotters(); return success; } -/** - * Override the current plotters with the knockout plotters - */ -void knockout_set_plotters(void) -{ - plot = knockout_plotters; - if (!real_plot.group_start) - plot.group_start = NULL; - if (!real_plot.group_end) - plot.group_end = NULL; -} - - /** * Knockout a section of previous rendering * @@ -548,7 +534,7 @@ bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_s if (parent->child) knockout_plot_fill_recursive(parent->child, plot_style); else - success &= plot.rectangle(parent->bbox.x0, + success &= real_plot.rectangle(parent->bbox.x0, parent->bbox.y0, parent->bbox.x1, parent->bbox.y1, @@ -570,8 +556,8 @@ bool knockout_plot_bitmap_recursive(struct knockout_box *box, if (parent->child) knockout_plot_bitmap_recursive(parent->child, entry); else { - success &= plot.clip(&parent->bbox); - success &= plot.bitmap(entry->data.bitmap.x, + success &= real_plot.clip(&parent->bbox); + success &= real_plot.bitmap(entry->data.bitmap.x, entry->data.bitmap.y, entry->data.bitmap.width, entry->data.bitmap.height, @@ -810,6 +796,10 @@ bool knockout_plot_bitmap(int x, int y, int width, int height, bool knockout_plot_group_start(const char *name) { + if (real_plot.group_start == NULL) { + return true; + } + knockout_entries[knockout_entry_cur].data.group_start.name = name; knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_GROUP_START; if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) @@ -819,6 +809,10 @@ bool knockout_plot_group_start(const char *name) bool knockout_plot_group_end(void) { + if (real_plot.group_end == NULL) { + return true; + } + knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_GROUP_END; if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) knockout_plot_flush(); diff --git a/desktop/knockout.h b/desktop/knockout.h index a3951a501..a6b61d836 100644 --- a/desktop/knockout.h +++ b/desktop/knockout.h @@ -26,7 +26,8 @@ #include "desktop/plotters.h" -bool knockout_plot_start(struct plotter_table *plotter); +bool knockout_plot_start(const struct redraw_context *ctx, + struct redraw_context *knk_ctx); bool knockout_plot_end(void); extern const struct plotter_table knockout_plotters; diff --git a/desktop/plotters.h b/desktop/plotters.h index ff5e8a9c7..448cedef5 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -27,7 +27,6 @@ #include "css/css.h" #include "content/content.h" #include "desktop/plot_style.h" -#include "utils/types.h" struct bitmap; @@ -137,9 +136,6 @@ struct plotter_table { bool option_knockout; /**< set if knockout rendering is required */ }; -/** Current plotters, must be assigned before use. */ -extern struct plotter_table plot; - enum path_command { PLOTTER_PATH_MOVE, PLOTTER_PATH_CLOSE, diff --git a/desktop/print.c b/desktop/print.c index 373c338fa..c6c361108 100644 --- a/desktop/print.c +++ b/desktop/print.c @@ -34,6 +34,7 @@ #include "render/box.h" #include "utils/log.h" #include "utils/talloc.h" +#include "utils/types.h" /* Default print settings */ #define DEFAULT_PAGE_WIDTH 595 @@ -123,8 +124,11 @@ bool print_draw_next_page(const struct printer *printer, { struct rect clip; struct content_redraw_data data; - - plot = *(printer->plotter); + struct redraw_context ctx = { + .interactive = false, + .plot = printer->plotter + }; + html_redraw_printing_top_cropped = INT_MAX; clip.x0 = 0; @@ -145,7 +149,7 @@ bool print_draw_next_page(const struct printer *printer, html_redraw_printing_border = clip.y1; printer->print_next_page(); - if (!content_redraw(printed_content, &data, &clip)) + if (!content_redraw(printed_content, &data, &clip, &ctx)) return false; done_height += page_content_height - diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index 1c99b14a6..6dd9b0b15 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -139,13 +139,17 @@ void scrollbar_destroy(struct scrollbar *s) * \param y1 bottom border of the outline * \param c base colour of the outline, the other colours are created by * lightening or darkening this one + * \param ctx current redraw context * \param inset true for inset outline, false for an outset one * \return */ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, - int x1, int y1, colour c, bool inset) + int x1, int y1, colour c, bool inset, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; + static plot_style_t c0 = { .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_width = 1, @@ -171,12 +175,12 @@ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, c2.stroke_colour = blend_colour(c0.stroke_colour, c1.stroke_colour); /* Plot the outline */ - if (!plot.line(x0, y0, x1, y0, &c0)) return false; - if (!plot.line(x1, y0, x1, y1 + 1, &c1)) return false; - if (!plot.line(x1, y0, x1, y0 + 1, &c2)) return false; - if (!plot.line(x1, y1, x0, y1, &c1)) return false; - if (!plot.line(x0, y1, x0, y0, &c0)) return false; - if (!plot.line(x0, y1, x0, y1 + 1, &c2)) return false; + if (!plot->line(x0, y0, x1, y0, &c0)) return false; + if (!plot->line(x1, y0, x1, y1 + 1, &c1)) return false; + if (!plot->line(x1, y0, x1, y0 + 1, &c2)) return false; + if (!plot->line(x1, y1, x0, y1, &c1)) return false; + if (!plot->line(x0, y1, x0, y0, &c0)) return false; + if (!plot->line(x0, y1, x0, y1 + 1, &c2)) return false; return true; } @@ -186,8 +190,10 @@ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, * Exported function. Documented in scrollbar.h */ bool scrollbar_redraw(struct scrollbar *s, int x, int y, - const struct rect *clip, float scale) + const struct rect *clip, float scale, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int w = SCROLLBAR_WIDTH; int bar_pos, bar_c0, bar_c1; int v[6]; /* array of triangle vertices */ @@ -237,17 +243,17 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, /* scrollbar outline */ if (!scrollbar_redraw_scrollbar_rectangle(x0, y0, x1, y1, - scrollbar_widget_bg_colour, true)) + scrollbar_widget_bg_colour, true, ctx)) return false; /* left arrow icon border */ if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, y0 + 1, x0 + w - 2, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; /* left arrow icon background */ - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, y0 + 2, x0 + w - 2, y1 - 1, @@ -260,10 +266,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y0 + w / 4; v[4] = x0 + w * 3 / 4; v[5] = y0 + w * 3 / 4; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; /* scrollbar well background */ - if (!plot.rectangle(x0 + w - 1, + if (!plot->rectangle(x0 + w - 1, y0 + 1, x1 - w + 2, y1, @@ -274,9 +280,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, y0 + 1, bar_c1, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; - if (!plot.rectangle(bar_c0 + 1, + if (!plot->rectangle(bar_c0 + 1, y0 + 2, bar_c1, y1 - 1, @@ -287,10 +293,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, y0 + 1, x1 - 1, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; /* right arrow icon background */ - if (!plot.rectangle(x1 - w + 3, + if (!plot->rectangle(x1 - w + 3, y0 + 2, x1 - 1, y1 - 1, @@ -303,7 +309,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y0 + w / 4; v[4] = x1 - w * 3 / 4 + 1; v[5] = y0 + w * 3 / 4; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; } else { /* scrollbar is vertical */ @@ -311,7 +317,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, /* outline */ if (!scrollbar_redraw_scrollbar_rectangle(x0, y0, x1, y1, scrollbar_widget_bg_colour, - true)) + true, ctx)) return false; /* top arrow background */ if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, @@ -319,9 +325,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, x1 - 1, y0 + w - 2, scrollbar_widget_fg_colour, - false)) + false, ctx)) return false; - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, y0 + 2, x1 - 1, y0 + w - 2, @@ -334,10 +340,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y0 + w * 3 / 4; v[4] = x0 + w * 3 / 4; v[5] = y0 + w * 3 / 4; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; /* scrollbar well background */ - if (!plot.rectangle(x0 + 1, + if (!plot->rectangle(x0 + 1, y0 + w - 1, x1, y1 - w + 2, @@ -348,9 +354,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, bar_c0, x1 - 1, bar_c1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, bar_c0 + 1, x1 - 1, bar_c1, @@ -361,9 +367,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, y1 - w + 2, x1 - 1, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, y1 - w + 3, x1 - 1, y1 - 1, @@ -376,7 +382,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y1 - w * 3 / 4 + 1; v[4] = x0 + w * 3 / 4; v[5] = y1 - w * 3 / 4 + 1; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; } diff --git a/desktop/scrollbar.h b/desktop/scrollbar.h index 66bf83cf2..7c5307fff 100644 --- a/desktop/scrollbar.h +++ b/desktop/scrollbar.h @@ -93,10 +93,12 @@ void scrollbar_destroy(struct scrollbar *s); * \param y the Y coordinate to draw the scrollbar at * \param clip the clipping rectangle * \param scale scale for the redraw + * \param ctx current redraw context * \return true on succes false otherwise */ bool scrollbar_redraw(struct scrollbar *s, int x, int y, - const struct rect *clip, float scale); + const struct rect *clip, float scale, + const struct redraw_context *ctx); /** * Set the scroll value of the scrollbar. diff --git a/desktop/textarea.c b/desktop/textarea.c index 2feef0e6c..ccde1d976 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -720,14 +720,16 @@ bool textarea_reflow(struct text_area *ta, unsigned int line) * Handle redraw requests for text areas * * \param redraw Redraw request block - * \param x0 left X coordinate of redraw area - * \param y0 top Y coordinate of redraw area - * \param x1 right X coordinate of redraw area - * \param y1 bottom Y coordinate of redraw area + * \param x0 left X coordinate of redraw area + * \param y0 top Y coordinate of redraw area + * \param x1 right X coordinate of redraw area + * \param y1 bottom Y coordinate of redraw area + * \param ctx current redraw context */ void textarea_redraw(struct text_area *ta, int x, int y, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int line0, line1, line; int chars, offset, text_y_offset, text_y_offset_baseline; unsigned int c_pos, c_len, b_start, b_end, line_len; @@ -775,9 +777,9 @@ void textarea_redraw(struct text_area *ta, int x, int y, if (r.y1 > y + ta->vis_height) r.y1 = y + ta->vis_height; - plot.clip(&r); - plot.rectangle(r.x0, r.y0, r.x1, r.y1, &plot_style_fill_bg); - plot.rectangle(x, y, + plot->clip(&r); + plot->rectangle(r.x0, r.y0, r.x1, r.y1, &plot_style_fill_bg); + plot->rectangle(x, y, x + ta->vis_width - 1, y + ta->vis_height - 1, &pstyle_stroke_border); @@ -785,7 +787,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, r.x0 = x + MARGIN_LEFT; if (r.x1 > x + ta->vis_width - MARGIN_RIGHT) r.x1 = x + ta->vis_width - MARGIN_RIGHT; - plot.clip(&r); + plot->clip(&r); if (line0 > 0) c_pos = utf8_bounded_length(ta->text, @@ -869,7 +871,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, b_start]), b_end, &r.x1); r.x1 += r.x0; - plot.rectangle(r.x0 - ta->scroll_x, y + + plot->rectangle(r.x0 - ta->scroll_x, y + line * ta->line_height + 1 - ta->scroll_y + text_y_offset, r.x1 - ta->scroll_x, @@ -887,7 +889,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, (ta->flags & TEXTAREA_READONLY) ? READONLY_BG : BACKGROUND_COL, - plot.text(x + MARGIN_LEFT - ta->scroll_x, + plot->text(x + MARGIN_LEFT - ta->scroll_x, r.y0 - ta->scroll_y, ta->text + ta->lines[line].b_start, ta->lines[line].b_length, @@ -904,7 +906,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, y += ta->caret_y + text_y_offset; if (y + caret_height >= clip->y0 && y <= clip->y1) /* Caret in vertical clip range; plot */ - plot.line(x + ta->caret_x, y + ta->caret_y, + plot->line(x + ta->caret_x, y + ta->caret_y, x + ta->caret_x, y + ta->caret_y + ta->line_height, &pstyle_stroke_caret); diff --git a/desktop/textarea.h b/desktop/textarea.h index 304b1ebfe..d8ec5c588 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -47,7 +47,7 @@ int textarea_get_text(struct text_area *ta, char *buf, unsigned int len); bool textarea_set_caret(struct text_area *ta, int caret); int textarea_get_caret(struct text_area *ta); void textarea_redraw(struct text_area *ta, int x, int y, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); bool textarea_keypress(struct text_area *ta, uint32_t key); bool textarea_mouse_action(struct text_area *ta, browser_mouse_state mouse, int x, int y); diff --git a/desktop/thumbnail.c b/desktop/thumbnail.c index 6f5fd0318..b88065adb 100644 --- a/desktop/thumbnail.c +++ b/desktop/thumbnail.c @@ -57,8 +57,9 @@ static float thumbnail_get_redraw_scale(struct hlcache_handle *content, /* exported interface, documented in thumbnail.h */ bool thumbnail_redraw(struct hlcache_handle *content, - int width, int height) + int width, int height, const struct redraw_context *ctx) { + struct redraw_context new_ctx = *ctx; struct rect clip; struct content_redraw_data data; float scale; @@ -66,8 +67,8 @@ bool thumbnail_redraw(struct hlcache_handle *content, assert(content); - if (plot.option_knockout) - knockout_plot_start(&plot); + if (ctx->plot->option_knockout) + knockout_plot_start(ctx, &new_ctx); /* No selection */ current_redraw_browser = NULL; @@ -78,10 +79,10 @@ bool thumbnail_redraw(struct hlcache_handle *content, clip.x1 = width; clip.y1 = height; - plot.clip(&clip); + new_ctx.plot->clip(&clip); /* Plot white background */ - plot_ok &= plot.rectangle(clip.x0, clip.y0, clip.x1, clip.y1, + plot_ok &= new_ctx.plot->rectangle(clip.x0, clip.y0, clip.x1, clip.y1, plot_style_fill_white); /* Find the scale we're using */ @@ -99,9 +100,9 @@ bool thumbnail_redraw(struct hlcache_handle *content, data.repeat_y = false; /* Render the content */ - plot_ok &= content_redraw(content, &data, &clip); + plot_ok &= content_redraw(content, &data, &clip, &new_ctx); - if (plot.option_knockout) + if (ctx->plot->option_knockout) knockout_plot_end(); return plot_ok; diff --git a/desktop/thumbnail.h b/desktop/thumbnail.h index 71efdd81e..655c25339 100644 --- a/desktop/thumbnail.h +++ b/desktop/thumbnail.h @@ -24,6 +24,7 @@ #define _NETSURF_DESKTOP_THUMBNAIL_H_ #include +#include "utils/types.h" struct hlcache_handle; struct bitmap; @@ -37,6 +38,7 @@ struct bitmap; * \param content The content to redraw for thumbnail * \param width The thumbnail width * \param height The thumbnail height + * \param ctx current redraw context * \return true if successful, false otherwise * * The thumbnail is guaranteed to be filled to its width/height extents, so @@ -45,7 +47,7 @@ struct bitmap; * Units for width and height are pixels. */ bool thumbnail_redraw(struct hlcache_handle *content, - int width, int height); + int width, int height, const struct redraw_context *ctx); /* In platform specific thumbnail.c. */ diff --git a/desktop/tree.c b/desktop/tree.c index 0bf9ba625..c33f29df8 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -1570,14 +1570,17 @@ struct node *tree_node_get_next(struct node *node) /** * Draws an element's expansion icon * - * \param tree the tree to draw the expansion for - * \param element the element to draw the expansion for + * \param tree the tree to draw the expansion for + * \param element the element to draw the expansion for * \param tree_x X coordinate of the tree * \param tree_y Y coordinate of the tree + * \param ctx current redraw context */ static void tree_draw_node_expansion_toggle(struct tree *tree, - struct node *node, int tree_x, int tree_y) + struct node *node, int tree_x, int tree_y, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int x, y; assert(tree != NULL); @@ -1586,15 +1589,15 @@ static void tree_draw_node_expansion_toggle(struct tree *tree, if ((node->child != NULL) || (node->data.next != NULL)) { x = tree_x + node->box.x - (NODE_INSTEP / 2) - 4; y = tree_y + node->box.y + (TREE_LINE_HEIGHT - 9) / 2; - plot.rectangle(x, y, x + 9, y + 9, + plot->rectangle(x, y, x + 9, y + 9, &plot_style_fill_tree_furniture); - plot.rectangle(x , y, x + 8, y + 8, - &plot_style_stroke_tree_furniture); - plot.line(x + 2, y + 4, x + 7, y + 4, - &plot_style_stroke_tree_furniture); + plot->rectangle(x , y, x + 8, y + 8, + &plot_style_stroke_tree_furniture); + plot->line(x + 2, y + 4, x + 7, y + 4, + &plot_style_stroke_tree_furniture); if (!node->expanded) - plot.line(x + 4, y + 2, x + 4, y + 7, - &plot_style_stroke_tree_furniture); + plot->line(x + 4, y + 2, x + 4, y + 7, + &plot_style_stroke_tree_furniture); } @@ -1609,12 +1612,13 @@ static void tree_draw_node_expansion_toggle(struct tree *tree, * \param tree_x X coordinate to draw the tree at (wrt plot origin) * \param tree_y Y coordinate to draw the tree at (wrt plot origin) * \param clip clipping rectangle (wrt plot origin) + * \param ctx current redraw context */ static void tree_draw_node_element(struct tree *tree, struct node_element *element, int tree_x, int tree_y, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { - + const struct plotter_table *plot = ctx->plot; struct bitmap *bitmap = NULL; int x, y, width; bool selected = false; @@ -1657,7 +1661,7 @@ static void tree_draw_node_element(struct tree *tree, /* Valid clip rectangles only */ struct content_redraw_data data; - plot.clip(&c); + plot->clip(&c); data.x = x; data.y = y + icon_inset; @@ -1669,10 +1673,10 @@ static void tree_draw_node_element(struct tree *tree, data.repeat_x = false; data.repeat_y = false; - content_redraw(icon, &data, &c); + content_redraw(icon, &data, &c, ctx); /* Restore previous clipping area */ - plot.clip(clip); + plot->clip(clip); } } @@ -1689,14 +1693,14 @@ static void tree_draw_node_element(struct tree *tree, if (selected) { fstyle = &plot_fstyle_selected; - plot.rectangle(x, y, x + width, + plot->rectangle(x, y, x + width, y + element->box.height, &plot_style_fill_tree_selected); } else { fstyle = &plot_fstyle; } - plot.text(x + 4, y + (TREE_LINE_HEIGHT * 3 + 2) / 4, + plot->text(x + 4, y + (TREE_LINE_HEIGHT * 3 + 2) / 4, element->text, strlen(element->text), fstyle); break; @@ -1704,11 +1708,11 @@ static void tree_draw_node_element(struct tree *tree, bitmap = element->bitmap; if (bitmap == NULL) break; - plot.bitmap(x, y, element->box.width - 1, + plot->bitmap(x, y, element->box.width - 1, element->box.height - 2, bitmap, 0xFFFFFF, BITMAPF_NONE); if (!(tree->flags & TREE_NO_FURNITURE)) - plot.rectangle(x, y, x + element->box.width - 1, + plot->rectangle(x, y, x + element->box.width - 1, y + element->box.height - 3, &plot_style_stroke_tree_furniture); @@ -1726,10 +1730,13 @@ static void tree_draw_node_element(struct tree *tree, * \param tree_x X coordinate to draw the tree at (wrt plot origin) * \param tree_y Y coordinate to draw the tree at (wrt plot origin) * \param clip clipping rectangle (wrt plot origin) + * \param ctx current redraw context */ static void tree_draw_node(struct tree *tree, struct node *node, - int tree_x, int tree_y, struct rect clip) + int tree_x, int tree_y, struct rect clip, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; struct node_element *element; struct node *parent; int x0, y0, x1, y1; @@ -1766,7 +1773,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, } /* Set up the clipping area */ - plot.clip(&clip); + plot->clip(&clip); /* Draw node's furniture */ if (!(tree->flags & TREE_NO_FURNITURE)) { @@ -1777,7 +1784,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, x0 = x1 = tree_x + node->box.x - (NODE_INSTEP / 2); y0 = tree_y + node->previous->box.y; y1 = tree_y + node->box.y + (TREE_LINE_HEIGHT / 2); - plot.line(x0, y0, x1, y1, + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); } if (node->next != NULL) { @@ -1786,7 +1793,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, x0 = x1 = tree_x + node->box.x - (NODE_INSTEP / 2); y0 = tree_y + node->box.y + (TREE_LINE_HEIGHT / 2); y1 = tree_y + node->next->box.y; - plot.line(x0, y0, x1, y1, + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); } @@ -1798,7 +1805,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, y0 = tree_y + parent->data.box.y + parent->data.box.height; y1 = y0 + (TREE_LINE_HEIGHT / 2); - plot.line(x0, y0, x1, y1, + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); } /* Line from expansion toggle to icon */ @@ -1806,9 +1813,10 @@ static void tree_draw_node(struct tree *tree, struct node *node, x1 = x0 + (NODE_INSTEP / 2) - 2; y0 = y1 = tree_y + node->data.box.y + node->data.box.height - (TREE_LINE_HEIGHT / 2); - plot.line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); - tree_draw_node_expansion_toggle(tree, node, tree_x, tree_y); + tree_draw_node_expansion_toggle(tree, node, + tree_x, tree_y, ctx); } /* Draw node's element(s) @@ -1818,12 +1826,12 @@ static void tree_draw_node(struct tree *tree, struct node *node, element = element->next) { /* Draw each element of expanded node */ tree_draw_node_element(tree, element, tree_x, tree_y, - &clip); + &clip, ctx); } } else { /* Draw main title element of node */ tree_draw_node_element(tree, &node->data, tree_x, tree_y, - &clip); + &clip, ctx); } } @@ -1836,9 +1844,11 @@ static void tree_draw_node(struct tree *tree, struct node *node, * \param tree_x X coordinate to draw the tree at (wrt plot origin) * \param tree_y Y coordinate to draw the tree at (wrt plot origin) * \param clip clipping rectangle (wrt plot origin) + * \param ctx current redraw context */ static void tree_draw_tree(struct tree *tree, struct node *node, - int tree_x, int tree_y, struct rect clip) + int tree_x, int tree_y, struct rect clip, + const struct redraw_context *ctx) { struct node *child; @@ -1858,11 +1868,11 @@ static void tree_draw_tree(struct tree *tree, struct node *node, return; /* Draw current child */ - tree_draw_node(tree, child, tree_x, tree_y, clip); + tree_draw_node(tree, child, tree_x, tree_y, clip, ctx); /* And its children */ if ((child->child != NULL) && (child->expanded)) { /* Child has children and they are visible */ - tree_draw_tree(tree, child, tree_x, tree_y, clip); + tree_draw_tree(tree, child, tree_x, tree_y, clip, ctx); } } } @@ -1878,35 +1888,38 @@ static void tree_draw_tree(struct tree *tree, struct node *node, * \param clip_y minimum y of the clipping rectangle (wrt tree origin) * \param clip_width width of the clipping rectangle * \param clip_height height of the clipping rectangle + * \param ctx current redraw context */ void tree_draw(struct tree *tree, int x, int y, - int clip_x, int clip_y, int clip_width, int clip_height) + int clip_x, int clip_y, int clip_width, int clip_height, + const struct redraw_context *ctx) { + struct redraw_context new_ctx = *ctx; struct rect clip; assert(tree != NULL); assert(tree->root != NULL); /* Start knockout rendering if it's available for this plotter */ - if (plot.option_knockout) - knockout_plot_start(&plot); + if (ctx->plot->option_knockout) + knockout_plot_start(ctx, &new_ctx); /* Set up clip rectangle */ clip.x0 = x + clip_x; clip.y0 = y + clip_y; clip.x1 = clip.x0 + clip_width; clip.y1 = clip.y0 + clip_height; - plot.clip(&clip); + new_ctx.plot->clip(&clip); /* Flat fill extents of clipping area */ - plot.rectangle(clip.x0, clip.y0, clip.x1, clip.y1, + new_ctx.plot->rectangle(clip.x0, clip.y0, clip.x1, clip.y1, &plot_style_fill_tree_background); /* don't draw empty trees or trees with redraw flag set to false */ if (tree->root->child != NULL && tree->redraw) { /* Draw the tree */ - tree_draw_tree(tree, tree->root, x, y, clip); + tree_draw_tree(tree, tree->root, x, y, clip, &new_ctx); /* Draw textarea, if present */ if (tree->editing != NULL) { @@ -1914,12 +1927,12 @@ void tree_draw(struct tree *tree, int x, int y, y = y + tree->editing->box.y; if (tree->editing->type == NODE_ELEMENT_TEXT_PLUS_ICON) x += NODE_INSTEP; - textarea_redraw(tree->textarea, x, y, &clip); + textarea_redraw(tree->textarea, x, y, &clip, &new_ctx); } } /* Rendering complete */ - if (plot.option_knockout) + if (ctx->plot->option_knockout) knockout_plot_end(); } diff --git a/desktop/tree.h b/desktop/tree.h index 0fb904bb7..e3dc8c98a 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -177,7 +177,8 @@ struct node *tree_node_get_child(struct node *node); struct node *tree_node_get_next(struct node *node); void tree_draw(struct tree *tree, int x, int y, - int clip_x, int clip_y, int clip_width, int clip_height); + int clip_x, int clip_y, int clip_width, int clip_height, + const struct redraw_context *ctx); struct node_element *tree_node_find_element(struct node *node, unsigned int flag, struct node_element *after); diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c index 18b8e9ae5..f50a5ad59 100644 --- a/framebuffer/fbtk/text.c +++ b/framebuffer/fbtk/text.c @@ -29,10 +29,10 @@ #include "utils/log.h" #include "desktop/browser.h" -#include "desktop/plotters.h" #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" +#include "framebuffer/framebuffer.h" #include "framebuffer/image_data.h" #include "widget.h" @@ -109,7 +109,7 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi ) * system for the baseline is to the "higher value * pixel co-ordinate" due to this the + 1 is neccessary. */ - plot.text(bbox.x0 + padding, + fb_plotters.text(bbox.x0 + padding, bbox.y0 + (((fh * 3) + 3)/4) + padding + 1, widget->u.text.text, strlen(widget->u.text.text), @@ -207,7 +207,7 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi ) * system for the baseline is to the "higher value * pixel co-ordinate" due to this the + 1 is neccessary. */ - plot.text(bbox.x0 + border, + fb_plotters.text(bbox.x0 + border, bbox.y0 + (((fh * 3) + 3)/4) + border + 1, widget->u.text.text, strlen(widget->u.text.text), diff --git a/framebuffer/framebuffer.c b/framebuffer/framebuffer.c index 535f63c85..218a912e7 100644 --- a/framebuffer/framebuffer.c +++ b/framebuffer/framebuffer.c @@ -30,7 +30,6 @@ #include "utils/log.h" #include "desktop/browser.h" -#include "desktop/plotters.h" #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" @@ -342,7 +341,7 @@ framebuffer_plot_clip(const struct rect *clip) return nsfb_plot_set_clip(nsfb, &nsfb_clip); } -struct plotter_table plot = { +const struct plotter_table fb_plotters = { .clip = framebuffer_plot_clip, .arc = framebuffer_plot_arc, .disc = framebuffer_plot_disc, diff --git a/framebuffer/framebuffer.h b/framebuffer/framebuffer.h index a61a746e7..aec6a689f 100644 --- a/framebuffer/framebuffer.h +++ b/framebuffer/framebuffer.h @@ -1,5 +1,7 @@ +#include "desktop/plotters.h" + +extern const struct plotter_table fb_plotters; + nsfb_t *framebuffer_initialise(const char *fename, int width, int height, int bpp); void framebuffer_finalise(void); bool framebuffer_set_cursor(struct bitmap *bm); - - diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 7df3a9173..644a917e0 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -307,6 +307,10 @@ fb_redraw(fbtk_widget_t *widget, int x; int y; struct rect clip; + struct redraw_context ctx = { + .interactive = true, + .plot = &fb_plotters + }; LOG(("%d,%d to %d,%d", bwidget->redraw_box.x0, @@ -336,7 +340,7 @@ fb_redraw(fbtk_widget_t *widget, browser_window_redraw(bw, (x - bwidget->scrollx) / bw->scale, (y - bwidget->scrolly) / bw->scale, - &clip); + &clip, &ctx); current_redraw_browser = NULL; diff --git a/framebuffer/localhistory.c b/framebuffer/localhistory.c index d8f2b048d..78c1a8d90 100644 --- a/framebuffer/localhistory.c +++ b/framebuffer/localhistory.c @@ -61,6 +61,11 @@ localhistory_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi) struct gui_localhistory *glh = cbi->context; nsfb_bbox_t rbox; + struct redraw_context ctx = { + .interactive = true, + .plot = &fb_plotters + }; + rbox.x0 = fbtk_get_absx(widget); rbox.y0 = fbtk_get_absy(widget); @@ -76,7 +81,7 @@ localhistory_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi) glh->scrolly, fbtk_get_width(widget) + glh->scrollx, fbtk_get_height(widget) + glh->scrolly, - 0, 0); + 0, 0, &ctx); nsfb_update(fbtk_get_nsfb(widget), &rbox); diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 5a149ffab..269aa27ac 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -1507,21 +1507,25 @@ static gboolean nsgtk_history_expose_event(GtkWidget *widget, struct browser_window *bw = gui_window_get_browser_window(hw->g->top_level); + struct redraw_context ctx = { + .interactive = true, + .plot = &nsgtk_plotters + }; + current_widget = widget; current_drawable = widget->window; current_gc = gdk_gc_new(current_drawable); #ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); #endif - plot = nsgtk_plotters; clip.x0 = event->area.x; clip.y0 = event->area.y; clip.x1 = event->area.x + event->area.width; clip.y1 = event->area.y + event->area.height; - plot.clip(&clip); + ctx.plot->clip(&clip); - history_redraw(bw->history); + history_redraw(bw->history, &ctx); current_widget = NULL; g_object_unref(current_gc); diff --git a/gtk/thumbnail.c b/gtk/thumbnail.c index 3561ea05b..c70c06546 100644 --- a/gtk/thumbnail.c +++ b/gtk/thumbnail.c @@ -61,6 +61,11 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, GdkPixbuf *big; double scale; + struct redraw_context ctx = { + .interactive = false, + .plot = &nsgtk_plotters + }; + assert(content); assert(bitmap); @@ -95,9 +100,6 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, gdk_drawable_set_colormap(pixmap, gdk_colormap_get_system()); - /* set the plotting functions up */ - plot = nsgtk_plotters; - /* set to plot to pixmap */ current_drawable = pixmap; current_gc = gdk_gc_new(current_drawable); @@ -106,7 +108,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, #endif /* render the content */ - thumbnail_redraw(content, cwidth, cheight); + thumbnail_redraw(content, cwidth, cheight, &ctx); /* get the pixbuf we rendered the content into */ big = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, diff --git a/gtk/treeview.c b/gtk/treeview.c index a56a28dfd..a6fc4010b 100644 --- a/gtk/treeview.c +++ b/gtk/treeview.c @@ -168,6 +168,10 @@ gboolean nsgtk_tree_window_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer g) { struct tree *tree = (struct tree *) g; + struct redraw_context ctx = { + .interactive = true, + .plot = &nsgtk_plotters + }; int x, y, width, height; x = event->area.x; @@ -181,17 +185,15 @@ gboolean nsgtk_tree_window_expose_event(GtkWidget *widget, #ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); #endif - plot = nsgtk_plotters; current_widget = widget; current_drawable = widget->window; current_gc = gdk_gc_new(current_drawable); #ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); #endif - plot = nsgtk_plotters; tree_set_redraw(tree, true); - tree_draw(tree, 0, 0, x, y, width, height); + tree_draw(tree, 0, 0, x, y, width, height, &ctx); current_widget = NULL; g_object_unref(current_gc); diff --git a/gtk/window.c b/gtk/window.c index 47e2a8dee..dade0e5bf 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -158,6 +158,10 @@ static gboolean nsgtk_window_expose_event(GtkWidget *widget, struct gui_window *g = data; struct gui_window *z; struct rect clip; + struct redraw_context ctx = { + .interactive = true, + .plot = &nsgtk_plotters + }; assert(g); assert(g->bw); @@ -175,7 +179,6 @@ static gboolean nsgtk_window_expose_event(GtkWidget *widget, current_cr = gdk_cairo_create(current_drawable); #endif - plot = nsgtk_plotters; current_redraw_browser = g->bw; clip.x0 = event->area.x; @@ -183,7 +186,7 @@ static gboolean nsgtk_window_expose_event(GtkWidget *widget, clip.x1 = event->area.x + event->area.width; clip.y1 = event->area.y + event->area.height; - browser_window_redraw(g->bw, 0, 0, &clip); + browser_window_redraw(g->bw, 0, 0, &clip, &ctx); current_redraw_browser = NULL; diff --git a/image/bmp.c b/image/bmp.c index d209621ba..816884e83 100644 --- a/image/bmp.c +++ b/image/bmp.c @@ -198,7 +198,7 @@ static bool nsbmp_convert(struct content *c) } static bool nsbmp_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { nsbmp_content *bmp = (nsbmp_content *) c; bitmap_flags_t flags = BITMAPF_NONE; @@ -214,7 +214,7 @@ static bool nsbmp_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/image/gif.c b/image/gif.c index 0a3dccf31..38ba03dda 100644 --- a/image/gif.c +++ b/image/gif.c @@ -339,7 +339,7 @@ static gif_result nsgif_get_frame(struct content *c) } static bool nsgif_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { nsgif_content *gif = (nsgif_content *) c; bitmap_flags_t flags = BITMAPF_NONE; @@ -358,7 +358,7 @@ static bool nsgif_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/image/ico.c b/image/ico.c index a64f76e70..cae5e07f5 100644 --- a/image/ico.c +++ b/image/ico.c @@ -158,7 +158,7 @@ static bool nsico_convert(struct content *c) static bool nsico_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { nsico_content *ico = (nsico_content *) c; struct bmp_image *bmp = ico_find(ico->ico, data->width, data->height); @@ -175,7 +175,7 @@ static bool nsico_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/image/jpeg.c b/image/jpeg.c index 544840241..58fb43e22 100644 --- a/image/jpeg.c +++ b/image/jpeg.c @@ -39,6 +39,7 @@ #include "utils/log.h" #include "utils/messages.h" #include "utils/talloc.h" +#include "utils/types.h" #include "utils/utils.h" #define JPEG_INTERNAL_OPTIONS @@ -278,7 +279,7 @@ static void nsjpeg_destroy(struct content *c) * Redraw a CONTENT_JPEG with appropriate tiling. */ static bool nsjpeg_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; @@ -287,7 +288,7 @@ static bool nsjpeg_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/image/mng.c b/image/mng.c index 731f5f14e..0ba084f6a 100644 --- a/image/mng.c +++ b/image/mng.c @@ -68,7 +68,7 @@ static bool nsmng_process_data(struct content *c, const char *data, static bool nsmng_convert(struct content *c); static void nsmng_destroy(struct content *c); static bool nsmng_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror nsmng_clone(const struct content *old, struct content **newc); static content_type nsmng_content_type(lwc_string *mime_type); @@ -686,7 +686,7 @@ void nsmng_destroy(struct content *c) bool nsmng_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { nsmng_content *mng = (nsmng_content *) c; bool ret; @@ -705,7 +705,7 @@ bool nsmng_redraw(struct content *c, struct content_redraw_data *data, if (data->repeat_y) flags |= BITMAPF_REPEAT_Y; - ret = plot.bitmap(data->x, data->y, data->width, data->height, + ret = ctx->plot->bitmap(data->x, data->y, data->width, data->height, c->bitmap, data->background_colour, flags); /* Check if we need to restart the animation diff --git a/image/nssprite.c b/image/nssprite.c index 0eff2a148..3282e821b 100644 --- a/image/nssprite.c +++ b/image/nssprite.c @@ -51,7 +51,7 @@ static nserror nssprite_create(const content_handler *handler, static bool nssprite_convert(struct content *c); static void nssprite_destroy(struct content *c); static bool nssprite_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror nssprite_clone(const struct content *old, struct content **newc); static content_type nssprite_content_type(lwc_string *mime_type); @@ -239,7 +239,7 @@ void nssprite_destroy(struct content *c) */ bool nssprite_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; @@ -248,7 +248,7 @@ bool nssprite_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/image/png.c b/image/png.c index a0475aa2f..57cd50146 100644 --- a/image/png.c +++ b/image/png.c @@ -363,7 +363,7 @@ static void nspng_destroy(struct content *c) static bool nspng_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { nspng_content *png_c = (nspng_content *) c; bitmap_flags_t flags = BITMAPF_NONE; @@ -375,7 +375,7 @@ static bool nspng_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, png_c->bitmap, data->background_colour, flags); } diff --git a/image/rsvg.c b/image/rsvg.c index 39bec0190..5af3c1bc2 100644 --- a/image/rsvg.c +++ b/image/rsvg.c @@ -230,7 +230,7 @@ static bool rsvg_convert(struct content *c) } static bool rsvg_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; @@ -241,7 +241,7 @@ static bool rsvg_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/image/svg.c b/image/svg.c index d53013033..cc1762ddb 100644 --- a/image/svg.c +++ b/image/svg.c @@ -52,7 +52,7 @@ static bool svg_convert(struct content *c); static void svg_destroy(struct content *c); static void svg_reformat(struct content *c, int width, int height); static bool svg_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror svg_clone(const struct content *old, struct content **newc); static content_type svg_content_type(lwc_string *mime_type); @@ -217,7 +217,8 @@ void svg_reformat(struct content *c, int width, int height) static bool svg_redraw_internal(struct content *c, int x, int y, int width, int height, const struct rect *clip, - float scale, colour background_colour) + const struct redraw_context *ctx, float scale, + colour background_colour) { svg_content *svg = (svg_content *) c; float transform[6]; @@ -243,7 +244,7 @@ static bool svg_redraw_internal(struct content *c, int x, int y, for (i = 0; i != diagram->shape_count; i++) { if (diagram->shape[i].path) { - ok = plot.path(diagram->shape[i].path, + ok = ctx->plot->path(diagram->shape[i].path, diagram->shape[i].path_length, BGR(diagram->shape[i].fill), diagram->shape[i].stroke_width, @@ -264,7 +265,7 @@ static bool svg_redraw_internal(struct content *c, int x, int y, fstyle.foreground = 0x000000; fstyle.size = (8 * FONT_SIZE_SCALE) * scale; - ok = plot.text(px, py, + ok = ctx->plot->text(px, py, diagram->shape[i].text, strlen(diagram->shape[i].text), &fstyle); @@ -284,7 +285,7 @@ static bool svg_redraw_internal(struct content *c, int x, int y, */ bool svg_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { int x = data->x; int y = data->y; @@ -297,8 +298,10 @@ bool svg_redraw(struct content *c, struct content_redraw_data *data, if ((data->repeat_x == false) && (data->repeat_y == false)) { /* Simple case: SVG is not tiled */ - return svg_redraw_internal(c, x, y, data->width, data->height, - clip, data->scale, data->background_colour); + return svg_redraw_internal(c, x, y, + data->width, data->height, + clip, ctx, data->scale, + data->background_colour); } else { /* Tiled redraw required. SVG repeats to extents of clip * rectangle, in x, y or both directions */ @@ -325,7 +328,7 @@ bool svg_redraw(struct content *c, struct content_redraw_data *data, for (x = x0; x < x1; x += data->width) { if (!svg_redraw_internal(c, x, y, data->width, data->height, - clip, data->scale, + clip, ctx, data->scale, data->background_colour)) { return false; } diff --git a/image/webp.c b/image/webp.c index 8702b0a3b..cabd40a3f 100644 --- a/image/webp.c +++ b/image/webp.c @@ -48,7 +48,7 @@ static nserror webp_create(const content_handler *handler, static bool webp_convert(struct content *c); static void webp_destroy(struct content *c); static bool webp_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror webp_clone(const struct content *old, struct content **newc); static content_type webp_content_type(lwc_string *mime_type); @@ -212,7 +212,7 @@ void webp_destroy(struct content *c) */ bool webp_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; @@ -221,7 +221,7 @@ bool webp_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/monkey/browser.c b/monkey/browser.c index d17b952ad..41165679f 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -27,6 +27,7 @@ #include "utils/log.h" #include "monkey/browser.h" +#include "monkey/plot.h" static uint32_t win_ctr = 0; @@ -466,6 +467,10 @@ monkey_window_handle_redraw(int argc, char **argv) { struct gui_window *gw; struct rect clip; + struct redraw_context ctx = { + .interactive = true, + .plot = &monkey_plotters + }; if (argc != 3 && argc != 7) { fprintf(stdout, "ERROR WINDOW REDRAW ARGS BAD"); @@ -492,7 +497,7 @@ monkey_window_handle_redraw(int argc, char **argv) } LOG(("Issue redraw")); - browser_window_redraw(gw->bw, gw->scrollx, gw->scrolly, &clip); + browser_window_redraw(gw->bw, gw->scrollx, gw->scrolly, &clip, &ctx); } static void diff --git a/monkey/plot.c b/monkey/plot.c index 539f41fbe..c93a9a8ec 100644 --- a/monkey/plot.c +++ b/monkey/plot.c @@ -83,7 +83,7 @@ monkey_plot_clip(const struct rect *clip) return true; } -struct plotter_table plot = { +const struct plotter_table monkey_plotters = { .clip = monkey_plot_clip, .arc = monkey_plot_arc, .disc = monkey_plot_disc, diff --git a/render/form.c b/render/form.c index 10fe3a2be..dd150adde 100644 --- a/render/form.c +++ b/render/form.c @@ -977,15 +977,15 @@ void form_free_select_menu(struct form_control *control) * \param x the X coordinate to draw the menu at * \param x the Y coordinate to draw the menu at * \param scale current redraw scale - * \param clip_x0 minimum x of clipping rectangle - * \param clip_y0 minimum y of clipping rectangle - * \param clip_x1 maximum x of clipping rectangle - * \param clip_y1 maximum y of clipping rectangle + * \param clip clipping rectangle + * \param ctx current redraw context * \return true on success, false otherwise */ bool form_redraw_select_menu(struct form_control *control, int x, int y, - float scale, const struct rect *clip) + float scale, const struct rect *clip, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; struct box *box; struct form_select_menu *menu = control->data.select.menu; struct form_option *option; @@ -1038,9 +1038,9 @@ bool form_redraw_select_menu(struct form_control *control, int x, int y, r.y0 = y0; r.x1 = x1 + 1; r.y1 = y1 + 1; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; - if (!plot.rectangle(x0, y0, x1, y1 ,plot_style_stroke_darkwbasec)) + if (!plot->rectangle(x0, y0, x1, y1 ,plot_style_stroke_darkwbasec)) return false; @@ -1054,9 +1054,9 @@ bool form_redraw_select_menu(struct form_control *control, int x, int y, r.y0 = y0; r.x1 = x1 + 1; r.y1 = y1 + 1; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; - if (!plot.rectangle(x0, y0, x1 + 1, y1 + 1, + if (!plot->rectangle(x0, y0, x1 + 1, y1 + 1, plot_style_fill_lightwbasec)) return false; option = control->data.select.items; @@ -1078,7 +1078,7 @@ bool form_redraw_select_menu(struct form_control *control, int x, int y, if (option->selected) { y2 = y + item_y - scroll; y3 = y + item_y + line_height_with_spacing - scroll; - if (!plot.rectangle(x0, (y0 > y2 ? y0 : y2), + if (!plot->rectangle(x0, (y0 > y2 ? y0 : y2), scrollbar_x + 1, (y3 < y1 + 1 ? y3 : y1 + 1), &plot_style_fill_selected)) @@ -1086,7 +1086,7 @@ bool form_redraw_select_menu(struct form_control *control, int x, int y, } y2 = text_pos_offset + item_y; - if (!plot.text(text_x, y2, option->text, + if (!plot->text(text_x, y2, option->text, strlen(option->text), &plot_fstyle_entry)) return false; @@ -1097,7 +1097,7 @@ bool form_redraw_select_menu(struct form_control *control, int x, int y, if (!scrollbar_redraw(menu->scrollbar, x_cp + menu->width - SCROLLBAR_WIDTH, y_cp, - clip, scale)) + clip, scale, ctx)) return false; return true; diff --git a/render/form.h b/render/form.h index 535b91942..e2f9f63b6 100644 --- a/render/form.h +++ b/render/form.h @@ -161,7 +161,8 @@ void form_select_menu_callback(void *client_data, int x, int y, int width, int height); void form_free_select_menu(struct form_control *control); bool form_redraw_select_menu(struct form_control *control, int x, int y, - float scale, const struct rect *clip); + float scale, const struct rect *clip, + const struct redraw_context *ctx); bool form_clip_inside_select_menu(struct form_control *control, float scale, const struct rect *clip); const char *form_select_mouse_action(struct form_control *control, diff --git a/render/html.h b/render/html.h index 426541342..ba55a6cdd 100644 --- a/render/html.h +++ b/render/html.h @@ -158,7 +158,8 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, const struct rect *clip, int height, float scale, - bool excluded); + bool excluded, + const struct redraw_context *ctx); xmlDoc *html_get_document(struct hlcache_handle *h); struct box *html_get_box_tree(struct hlcache_handle *h); diff --git a/render/html_internal.h b/render/html_internal.h index a177e3999..038055114 100644 --- a/render/html_internal.h +++ b/render/html_internal.h @@ -104,7 +104,7 @@ void html_set_status(html_content *c, const char *extra); /* in render/html_redraw.c */ bool html_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); /* in render/html_interaction.c */ void html_mouse_track(struct content *c, struct browser_window *bw, diff --git a/render/html_redraw.c b/render/html_redraw.c index 3cd297238..2ab7b4df1 100644 --- a/render/html_redraw.c +++ b/render/html_redraw.c @@ -55,42 +55,51 @@ static bool html_redraw_box(html_content *html, struct box *box, int x, int y, const struct rect *clip, float scale, - colour current_background_color); + colour current_background_color, + const struct redraw_context *ctx); static bool html_redraw_box_children(html_content *html, struct box *box, int x_parent, int y_parent, const struct rect *clip, - float scale, colour current_background_color); + float scale, colour current_background_color, + const struct redraw_context *ctx); static bool html_redraw_text_box(struct box *box, int x, int y, const struct rect *clip, float scale, - colour current_background_color); + colour current_background_color, + const struct redraw_context *ctx); static bool html_redraw_caret(struct caret *caret, - colour current_background_color, float scale); + colour current_background_color, float scale, + const struct redraw_context *ctx); static bool html_redraw_borders(struct box *box, int x_parent, int y_parent, int p_width, int p_height, const struct rect *clip, - float scale); + float scale, const struct redraw_context *ctx); static bool html_redraw_inline_borders(struct box *box, struct rect b, - const struct rect *clip, float scale, bool first, bool last); + const struct rect *clip, float scale, bool first, bool last, + const struct redraw_context *ctx); static bool html_redraw_border_plot(const int side, const int *p, colour c, enum css_border_style_e style, int thickness, bool rectangular, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static bool html_redraw_checkbox(int x, int y, int width, int height, - bool selected); + bool selected, const struct redraw_context *ctx); static bool html_redraw_radio(int x, int y, int width, int height, - bool selected); + bool selected, const struct redraw_context *ctx); static bool html_redraw_file(int x, int y, int width, int height, - struct box *box, float scale, colour background_colour); + struct box *box, float scale, colour background_colour, + const struct redraw_context *ctx); static bool html_redraw_background(int x, int y, struct box *box, float scale, const struct rect *clip, colour *background_colour, - struct box *background); + struct box *background, const struct redraw_context *ctx); static bool html_redraw_inline_background(int x, int y, struct box *box, float scale, const struct rect *clip, struct rect b, - bool first, bool last, colour *background_colour); + bool first, bool last, colour *background_colour, + const struct redraw_context *ctx); static bool html_redraw_text_decoration(struct box *box, int x_parent, int y_parent, float scale, - colour background_colour); + colour background_colour, const struct redraw_context *ctx); static bool html_redraw_text_decoration_inline(struct box *box, int x, int y, - float scale, colour colour, float ratio); + float scale, colour colour, float ratio, + const struct redraw_context *ctx); static bool html_redraw_text_decoration_block(struct box *box, int x, int y, - float scale, colour colour, float ratio); + float scale, colour colour, float ratio, + const struct redraw_context *ctx); bool html_redraw_debug = false; @@ -100,13 +109,14 @@ bool html_redraw_debug = false; * \param c content of type CONTENT_HTML * \param data redraw data for this content redraw * \param clip current clip region + * \param ctx current redraw context * \return true if successful, false otherwise * * x, y, clip_[xy][01] are in target coordinates. */ bool html_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { html_content *html = (html_content *) c; struct box *box; @@ -125,8 +135,7 @@ bool html_redraw(struct content *c, struct content_redraw_data *data, */ select = false; select_only = false; - if (current_redraw_browser != NULL && - html->visible_select_menu != NULL) { + if (ctx->interactive && html->visible_select_menu != NULL) { struct form_control *control = html->visible_select_menu; select = true; /* check if the redraw rectangle is completely inside of the @@ -137,16 +146,17 @@ bool html_redraw(struct content *c, struct content_redraw_data *data, if (!select_only) { /* clear to background colour */ - result = plot.clip(clip); + result = ctx->plot->clip(clip); if (html->background_colour != NS_TRANSPARENT) pstyle_fill_bg.fill_colour = html->background_colour; - result &= plot.rectangle(clip->x0, clip->y0, clip->x1, clip->y1, + result &= ctx->plot->rectangle(clip->x0, clip->y0, + clip->x1, clip->y1, &pstyle_fill_bg); result &= html_redraw_box(html, box, data->x, data->y, clip, - data->scale, pstyle_fill_bg.fill_colour); + data->scale, pstyle_fill_bg.fill_colour, ctx); } if (select) { @@ -159,7 +169,7 @@ bool html_redraw(struct content *c, struct content_redraw_data *data, box->padding[BOTTOM] + box->padding[TOP]; result &= form_redraw_select_menu(html->visible_select_menu, data->x + menu_x, data->y + menu_y, - data->scale, clip); + data->scale, clip, ctx); } return result; @@ -241,7 +251,7 @@ static struct box *html_redraw_find_bg_box(struct box *box) * \param clip clip rectangle * \param scale scale for redraw * \param current_background_color background colour under this box - * \param inline_depth depth of nested inlines inside an inline container + * \param ctx current redraw context * \return true if successful, false otherwise * * x, y, clip_[xy][01] are in target coordinates. @@ -250,8 +260,10 @@ static struct box *html_redraw_find_bg_box(struct box *box) bool html_redraw_box(html_content *html, struct box *box, int x_parent, int y_parent, const struct rect *clip, float scale, - colour current_background_color) + colour current_background_color, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int x, y; int width, height; int padding_left, padding_top, padding_width, padding_height; @@ -377,15 +389,15 @@ bool html_redraw_box(html_content *html, struct box *box, /* if visibility is hidden render children only */ if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) { - if ((plot.group_start) && (!plot.group_start("hidden box"))) + if ((plot->group_start) && (!plot->group_start("hidden box"))) return false; if (!html_redraw_box_children(html, box, x_parent, y_parent, - &r, scale, current_background_color)) + &r, scale, current_background_color, ctx)) return false; - return ((!plot.group_end) || (plot.group_end())); + return ((!plot->group_end) || (plot->group_end())); } - if ((plot.group_start) && (!plot.group_start("vis box"))) + if ((plot->group_start) && (!plot->group_start("vis box"))) return false; if (box->type == BOX_BLOCK || box->type == BOX_INLINE_BLOCK || @@ -398,14 +410,14 @@ bool html_redraw_box(html_content *html, struct box *box, /* no point trying to draw 0-width/height boxes */ if (r.x0 == r.x1 || r.y0 == r.y1) /* not an error */ - return ((!plot.group_end) || (plot.group_end())); + return ((!plot->group_end) || (plot->group_end())); /* clip to it */ - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; } else { /* clip box is fine, clip to it */ r = *clip; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; } @@ -455,10 +467,10 @@ bool html_redraw_box(html_content *html, struct box *box, if ((p.x0 < p.x1) && (p.y0 < p.y1)) { /* plot background */ if (!html_redraw_background(x, y, box, scale, &p, - ¤t_background_color, bg_box)) + ¤t_background_color, bg_box, ctx)) return false; /* restore previous graphics window */ - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; } } @@ -472,7 +484,7 @@ bool html_redraw_box(html_content *html, struct box *box, border_bottom || border_left)) { if (!html_redraw_borders(box, x_parent, y_parent, padding_width, padding_height, &r, - scale)) + scale, ctx)) return false; } @@ -530,13 +542,13 @@ bool html_redraw_box(html_content *html, struct box *box, if (!html_redraw_inline_background( x, y, box, scale, &p, b, first, false, - ¤t_background_color)) + ¤t_background_color, ctx)) return false; /* restore previous graphics window */ - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; if (!html_redraw_inline_borders(box, b, &r, - scale, first, false)) + scale, first, false, ctx)) return false; /* reset coords */ b.x0 = ib_x - ib_b_left; @@ -562,12 +574,13 @@ bool html_redraw_box(html_content *html, struct box *box, /* plot background and borders for last rectangle of * the inline */ if (!html_redraw_inline_background(x, ib_y, box, scale, &p, b, - first, true, ¤t_background_color)) + first, true, ¤t_background_color, ctx)) return false; /* restore previous graphics window */ - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; - if (!html_redraw_inline_borders(box, b, &r, scale, first, true)) + if (!html_redraw_inline_borders(box, b, &r, scale, first, true, + ctx)) return false; } @@ -589,19 +602,19 @@ bool html_redraw_box(html_content *html, struct box *box, margin_bottom = box->margin[BOTTOM] * scale; } /* Content edge -- blue */ - if (!plot.rectangle(x + padding_left, + if (!plot->rectangle(x + padding_left, y + padding_top, x + padding_left + width, y + padding_top + height, plot_style_content_edge)) return false; /* Padding edge -- red */ - if (!plot.rectangle(x, y, + if (!plot->rectangle(x, y, x + padding_width, y + padding_height, plot_style_padding_edge)) return false; /* Margin edge -- yellow */ - if (!plot.rectangle( + if (!plot->rectangle( x - border_left - margin_left, y - border_top - margin_top, x + padding_width + border_right + @@ -626,10 +639,10 @@ bool html_redraw_box(html_content *html, struct box *box, if (clip->x1 < r.x1) r.x1 = clip->x1; if (clip->y1 < r.y1) r.y1 = clip->y1; if (r.x1 <= r.x0 || r.y1 <= r.y0) - return ((!plot.group_end) || (plot.group_end())); + return ((!plot->group_end) || (plot->group_end())); if (box->type == BOX_BLOCK || box->type == BOX_INLINE_BLOCK || box->type == BOX_TABLE_CELL || box->object) { - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; } } @@ -639,7 +652,7 @@ bool html_redraw_box(html_content *html, struct box *box, css_computed_text_decoration(box->style) != CSS_TEXT_DECORATION_NONE) if (!html_redraw_text_decoration(box, x_parent, y_parent, - scale, current_background_color)) + scale, current_background_color, ctx)) return false; if (box->object && width != 0 && height != 0) { @@ -657,47 +670,45 @@ bool html_redraw_box(html_content *html, struct box *box, obj_data.repeat_x = false; obj_data.repeat_y = false; - if (!content_redraw(box->object, &obj_data, &r)) + if (!content_redraw(box->object, &obj_data, &r, ctx)) return false; } else if (box->iframe) { /* Offset is passed to browser window redraw unscaled */ browser_window_redraw(box->iframe, (x + padding_left) / scale, - (y + padding_top) / scale, &r); + (y + padding_top) / scale, &r, ctx); } else if (box->gadget && box->gadget->type == GADGET_CHECKBOX) { if (!html_redraw_checkbox(x + padding_left, y + padding_top, - width, height, - box->gadget->selected)) + width, height, box->gadget->selected, ctx)) return false; } else if (box->gadget && box->gadget->type == GADGET_RADIO) { if (!html_redraw_radio(x + padding_left, y + padding_top, - width, height, - box->gadget->selected)) + width, height, box->gadget->selected, ctx)) return false; } else if (box->gadget && box->gadget->type == GADGET_FILE) { if (!html_redraw_file(x + padding_left, y + padding_top, width, height, box, scale, - current_background_color)) + current_background_color, ctx)) return false; } else if (box->text) { if (!html_redraw_text_box(box, x, y, &r, scale, - current_background_color)) + current_background_color, ctx)) return false; } else { if (!html_redraw_box_children(html, box, x_parent, y_parent, &r, - scale, current_background_color)) + scale, current_background_color, ctx)) return false; } if (box->type == BOX_BLOCK || box->type == BOX_INLINE_BLOCK || box->type == BOX_TABLE_CELL || box->type == BOX_INLINE) - if (!plot.clip(clip)) + if (!plot->clip(clip)) return false; /* list marker */ @@ -707,7 +718,7 @@ bool html_redraw_box(html_content *html, struct box *box, scrollbar_get_offset(box->scroll_x), y_parent + box->y - scrollbar_get_offset(box->scroll_y), - clip, scale, current_background_color)) + clip, scale, current_background_color, ctx)) return false; /* scrollbars */ @@ -731,21 +742,21 @@ bool html_redraw_box(html_content *html, struct box *box, x_parent + box->x, y_parent + box->y + box->padding[TOP] + box->height + box->padding[BOTTOM] - - SCROLLBAR_WIDTH, clip, scale); + SCROLLBAR_WIDTH, clip, scale, ctx); if (box->scroll_y != NULL) scrollbar_redraw(box->scroll_y, x_parent + box->x + box->padding[LEFT] + box->width + box->padding[RIGHT] - SCROLLBAR_WIDTH, - y_parent + box->y, clip, scale); + y_parent + box->y, clip, scale, ctx); } if (box->type == BOX_BLOCK || box->type == BOX_INLINE_BLOCK || box->type == BOX_TABLE_CELL || box->type == BOX_INLINE) - if (!plot.clip(clip)) + if (!plot->clip(clip)) return false; - return ((!plot.group_end) || (plot.group_end())); + return ((!plot->group_end) || (plot->group_end())); } @@ -759,13 +770,15 @@ bool html_redraw_box(html_content *html, struct box *box, * \param clip clip rectangle * \param scale scale for redraw * \param current_background_color background colour under this box + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_box_children(html_content *html, struct box *box, int x_parent, int y_parent, const struct rect *clip, float scale, - colour current_background_color) + colour current_background_color, + const struct redraw_context *ctx) { struct box *c; @@ -777,7 +790,8 @@ bool html_redraw_box_children(html_content *html, struct box *box, scrollbar_get_offset(box->scroll_x), y_parent + box->y - scrollbar_get_offset(box->scroll_y), - clip, scale, current_background_color)) + clip, scale, current_background_color, + ctx)) return false; } for (c = box->float_children; c; c = c->next_float) @@ -786,7 +800,8 @@ bool html_redraw_box_children(html_content *html, struct box *box, scrollbar_get_offset(box->scroll_x), y_parent + box->y - scrollbar_get_offset(box->scroll_y), - clip, scale, current_background_color)) + clip, scale, current_background_color, + ctx)) return false; return true; @@ -803,12 +818,14 @@ bool html_redraw_box_children(html_content *html, struct box *box, * \param clip current clip rectangle * \param scale current scale setting (1.0 = 100%) * \param current_background_color + * \param ctx current redraw context * \return true iff successful and redraw should proceed */ bool html_redraw_text_box(struct box *box, int x, int y, const struct rect *clip, float scale, - colour current_background_color) + colour current_background_color, + const struct redraw_context *ctx) { bool excluded = (box->object != NULL); plot_font_style_t fstyle; @@ -818,14 +835,14 @@ bool html_redraw_text_box(struct box *box, int x, int y, if (!text_redraw(box->text, box->length, box->byte_offset, box->space, &fstyle, x, y, - clip, box->height, scale, excluded)) + clip, box->height, scale, excluded, ctx)) return false; /* does this textbox contain the ghost caret? */ if (ghost_caret.defined && box == ghost_caret.text_box) { if (!html_redraw_caret(&ghost_caret, current_background_color, - scale)) + scale, ctx)) return false; } return true; @@ -846,14 +863,17 @@ bool html_redraw_text_box(struct box *box, int x, int y, * \param height height of text string * \param scale current display scale (1.0 = 100%) * \param excluded exclude this text string from the selection + * \param ctx current redraw context * \return true iff successful and redraw should proceed */ bool text_redraw(const char *utf8_text, size_t utf8_len, size_t offset, int space, const plot_font_style_t *fstyle, int x, int y, const struct rect *clip, int height, - float scale, bool excluded) + float scale, bool excluded, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; bool highlighted = false; plot_font_style_t plot_fstyle = *fstyle; @@ -923,7 +943,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, /* draw any text preceding highlighted portion */ if (start_idx > 0 && - !plot.text(x, y + (int) (height * 0.75 * scale), + !plot->text(x, y + (int)(height * 0.75 * scale), utf8_text, start_idx, &plot_fstyle)) return false; @@ -934,7 +954,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, pstyle_fill_hback = plot_style_fill_black; /* highlighted portion */ - if (!plot.rectangle(x + startx, y, x + endx, + if (!plot->rectangle(x + startx, y, x + endx, y + height * scale, pstyle_fill_hback)) return false; @@ -948,7 +968,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, r.y0 = clip->y0; r.x1 = px1; r.y1 = clip->y1; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; clip_changed = true; } else { @@ -962,7 +982,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, pstyle_fill_hback->fill_colour ^ 0xffffff; if (text_visible && - !plot.text(x, y + (int) (height * 0.75 * scale), + !plot->text(x, y + (int)(height * 0.75 * scale), utf8_text, endtxt_idx, &fstyle_hback)) return false; @@ -976,12 +996,12 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, r.y0 = clip->y0; r.x1 = clip->x1; r.y1 = clip->y1; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; clip_changed = true; - if (!plot.text(x, y + (int) + if (!plot->text(x, y + (int) (height * 0.75 * scale), utf8_text, utf8_len, &plot_fstyle)) @@ -990,13 +1010,13 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, } if (clip_changed && - !plot.clip(clip)) + !plot->clip(clip)) return false; } } if (!highlighted) { - if (!plot.text(x, y + (int) (height * 0.75 * scale), + if (!plot->text(x, y + (int) (height * 0.75 * scale), utf8_text, utf8_len, &plot_fstyle)) return false; @@ -1011,23 +1031,25 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, * \param c structure describing text caret * \param current_background_color background colour under the caret * \param scale current scale setting (1.0 = 100%) + * \param ctx current redraw context * \return true iff successful and redraw should proceed */ bool html_redraw_caret(struct caret *c, colour current_background_color, - float scale) + float scale, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int xc = c->x, y = c->y; int h = c->height - 1; int w = (h + 7) / 8; - return (plot.line(xc * scale, y * scale, + return (plot->line(xc * scale, y * scale, xc * scale, (y + h) * scale, plot_style_caret) && - plot.line((xc - w) * scale, y * scale, + plot->line((xc - w) * scale, y * scale, (xc + w) * scale, y * scale, plot_style_caret) && - plot.line((xc - w) * scale, (y + h) * scale, + plot->line((xc - w) * scale, (y + h) * scale, (xc + w) * scale, (y + h) * scale, plot_style_caret)); } @@ -1042,11 +1064,13 @@ bool html_redraw_caret(struct caret *c, colour current_background_color, * \param p_width width of padding box * \param p_height height of padding box * \param scale scale for redraw + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, - int p_width, int p_height, const struct rect *clip, float scale) + int p_width, int p_height, const struct rect *clip, float scale, + const struct redraw_context *ctx) { unsigned int sides[] = { LEFT, RIGHT, TOP, BOTTOM }; int top = box->border[TOP].width; @@ -1131,7 +1155,8 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, if (!html_redraw_border_plot(side, z, col, box->border[side].style, box->border[side].width * scale, - square_end_1 && square_end_2, clip)) + square_end_1 && square_end_2, + clip, ctx)) return false; break; case RIGHT: @@ -1167,7 +1192,8 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, if (!html_redraw_border_plot(side, z, col, box->border[side].style, box->border[side].width * scale, - square_end_1 && square_end_2, clip)) + square_end_1 && square_end_2, + clip, ctx)) return false; break; case TOP: @@ -1208,7 +1234,8 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, if (!html_redraw_border_plot(side, z, col, box->border[side].style, box->border[side].width * scale, - square_end_1 && square_end_2, clip)) + square_end_1 && square_end_2, + clip, ctx)) return false; break; case BOTTOM: @@ -1249,7 +1276,8 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, if (!html_redraw_border_plot(side, z, col, box->border[side].style, box->border[side].width * scale, - square_end_1 && square_end_2, clip)) + square_end_1 && square_end_2, + clip, ctx)) return false; break; default: @@ -1271,11 +1299,13 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, * \param scale scale for redraw * \param first true if this is the first rectangle associated with the inline * \param last true if this is the last rectangle associated with the inline + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_inline_borders(struct box *box, struct rect b, - const struct rect *clip, float scale, bool first, bool last) + const struct rect *clip, float scale, bool first, bool last, + const struct redraw_context *ctx) { int top = box->border[TOP].width; int right = box->border[RIGHT].width; @@ -1344,7 +1374,8 @@ bool html_redraw_inline_borders(struct box *box, struct rect b, if (!html_redraw_border_plot(LEFT, z, col, box->border[LEFT].style, - left, square_end_1 && square_end_2, clip)) + left, square_end_1 && square_end_2, + clip, ctx)) return false; } @@ -1381,7 +1412,8 @@ bool html_redraw_inline_borders(struct box *box, struct rect b, if (!html_redraw_border_plot(RIGHT, z, col, box->border[RIGHT].style, - right, square_end_1 && square_end_2, clip)) + right, square_end_1 && square_end_2, + clip, ctx)) return false; } @@ -1419,7 +1451,8 @@ bool html_redraw_inline_borders(struct box *box, struct rect b, if (!html_redraw_border_plot(TOP, z, col, box->border[TOP].style, - top, square_end_1 && square_end_2, clip)) + top, square_end_1 && square_end_2, + clip, ctx)) return false; } @@ -1457,7 +1490,8 @@ bool html_redraw_inline_borders(struct box *box, struct rect b, if (!html_redraw_border_plot(BOTTOM, z, col, box->border[BOTTOM].style, - bottom, square_end_1 && square_end_2, clip)) + bottom, square_end_1 && square_end_2, + clip, ctx)) return false; } @@ -1486,19 +1520,21 @@ static plot_style_t plot_style_fillbdr_dlight = { /** * Draw one border. * - * \param side index of border side (TOP, RIGHT, BOTTOM, LEFT) - * \param p array of precomputed border vertices - * \param c colour for border - * \param style border line style - * \param thickness border thickness - * \param rectangular whether border is rectangular + * \param side index of border side (TOP, RIGHT, BOTTOM, LEFT) + * \param p array of precomputed border vertices + * \param c colour for border + * \param style border line style + * \param thickness border thickness + * \param rectangular whether border is rectangular + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_border_plot(const int side, const int *p, colour c, enum css_border_style_e style, int thickness, bool rectangular, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int z[8]; /* Vertices of border part */ unsigned int light = side; plot_style_t *plot_style_bdr_in; @@ -1521,7 +1557,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, plot_style_bdr.stroke_type = PLOT_OP_TYPE_DOT; /* fall through */ case CSS_BORDER_STYLE_DASHED: - if (!plot.line((p[0] + p[2]) / 2, + if (!plot->line((p[0] + p[2]) / 2, (p[1] + p[3]) / 2, (p[4] + p[6]) / 2, (p[5] + p[7]) / 2, @@ -1552,12 +1588,12 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, &plot_style_fillbdr)) return false; } } else { - if (!plot.polygon(p, 4, &plot_style_fillbdr)) + if (!plot->polygon(p, 4, &plot_style_fillbdr)) return false; } break; @@ -1571,7 +1607,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, z[5] = (p[7] * 2 + p[5]) / 3; z[6] = p[6]; z[7] = p[7]; - if (!plot.polygon(z, 4, &plot_style_fillbdr)) + if (!plot->polygon(z, 4, &plot_style_fillbdr)) return false; z[0] = p[2]; z[1] = p[3]; @@ -1581,7 +1617,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, z[5] = (p[5] * 2 + p[7]) / 3; z[6] = p[4]; z[7] = p[5]; - if (!plot.polygon(z, 4, &plot_style_fillbdr)) + if (!plot->polygon(z, 4, &plot_style_fillbdr)) return false; break; @@ -1619,7 +1655,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_in)) return false; } @@ -1639,7 +1675,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_out)) return false; } @@ -1660,7 +1696,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_in)) return false; } @@ -1677,7 +1713,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_out)) return false; } @@ -1693,13 +1729,13 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, z[5] = (p[7] + p[5]) / 2; z[6] = p[6]; z[7] = p[7]; - if (!plot.polygon(z, 4, plot_style_bdr_in)) + if (!plot->polygon(z, 4, plot_style_bdr_in)) return false; z[0] = p[2]; z[1] = p[3]; z[6] = p[4]; z[7] = p[5]; - if (!plot.polygon(z, 4, plot_style_bdr_out)) + if (!plot->polygon(z, 4, plot_style_bdr_out)) return false; } break; @@ -1753,7 +1789,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_in)) return false; } @@ -1773,7 +1809,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_out)) return false; } @@ -1794,7 +1830,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_in)) return false; } @@ -1811,7 +1847,7 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, y1 = (clip->y1 < y1) ? clip->y1 : y1; if ((x0 < x1) && (y0 < y1)) { /* valid clip rectangles only */ - if (!plot.rectangle(x0, y0, x1, y1, + if (!plot->rectangle(x0, y0, x1, y1, plot_style_bdr_out)) return false; } @@ -1827,13 +1863,13 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, z[5] = (p[7] + p[5]) / 2; z[6] = p[6]; z[7] = p[7]; - if (!plot.polygon(z, 4, plot_style_bdr_in)) + if (!plot->polygon(z, 4, plot_style_bdr_in)) return false; z[0] = p[2]; z[1] = p[3]; z[6] = p[4]; z[7] = p[5]; - if (!plot.polygon(z, 4, plot_style_bdr_out)) + if (!plot->polygon(z, 4, plot_style_bdr_out)) return false; } break; @@ -1851,41 +1887,44 @@ bool html_redraw_border_plot(const int side, const int *p, colour c, * \param width dimensions of checkbox * \param height dimensions of checkbox * \param selected the checkbox is selected + * \param ctx current redraw context * \return true if successful, false otherwise */ -bool html_redraw_checkbox(int x, int y, int width, int height, bool selected) +bool html_redraw_checkbox(int x, int y, int width, int height, bool selected, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; double z = width * 0.15; if (z == 0) z = 1; - if (!(plot.rectangle(x, y, x + width, y + height, + if (!(plot->rectangle(x, y, x + width, y + height, plot_style_fill_wbasec) && - plot.line(x, y, x + width, y, plot_style_stroke_darkwbasec) && - plot.line(x, y, x, y + height, plot_style_stroke_darkwbasec) && - plot.line(x + width, y, x + width, y + height, + plot->line(x, y, x + width, y, plot_style_stroke_darkwbasec) && + plot->line(x, y, x, y + height, plot_style_stroke_darkwbasec) && + plot->line(x + width, y, x + width, y + height, plot_style_stroke_lightwbasec) && - plot.line(x, y + height, x + width, y + height, + plot->line(x, y + height, x + width, y + height, plot_style_stroke_lightwbasec))) return false; if (selected) { if (width < 12 || height < 12) { /* render a solid box instead of a tick */ - if (!plot.rectangle(x + z + z, y + z + z, + if (!plot->rectangle(x + z + z, y + z + z, x + width - z, y + height - z, plot_style_fill_wblobc)) return false; } else { /* render a tick, as it'll fit comfortably */ - if (!(plot.line(x + width - z, + if (!(plot->line(x + width - z, y + z, x + (z * 3), y + height - z, plot_style_stroke_wblobc) && - plot.line(x + (z * 3), + plot->line(x + (z * 3), y + height - z, x + z + z, y + (height / 2), @@ -1905,19 +1944,23 @@ bool html_redraw_checkbox(int x, int y, int width, int height, bool selected) * \param width dimensions of radio icon * \param height dimensions of radio icon * \param selected the radio icon is selected + * \param ctx current redraw context * \return true if successful, false otherwise */ -bool html_redraw_radio(int x, int y, int width, int height, bool selected) +bool html_redraw_radio(int x, int y, int width, int height, bool selected, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; + /* plot background of radio button */ - if (!plot.disc(x + width * 0.5, + if (!plot->disc(x + width * 0.5, y + height * 0.5, width * 0.5 - 1, plot_style_fill_wbasec)) return false; /* plot dark arc */ - if (!plot.arc(x + width * 0.5, + if (!plot->arc(x + width * 0.5, y + height * 0.5, width * 0.5 - 1, 45, @@ -1926,7 +1969,7 @@ bool html_redraw_radio(int x, int y, int width, int height, bool selected) return false; /* plot light arc */ - if (!plot.arc(x + width * 0.5, + if (!plot->arc(x + width * 0.5, y + height * 0.5, width * 0.5 - 1, 225, @@ -1936,7 +1979,7 @@ bool html_redraw_radio(int x, int y, int width, int height, bool selected) if (selected) { /* plot selection blob */ - if (!plot.disc(x + width * 0.5, + if (!plot->disc(x + width * 0.5, y + height * 0.5, width * 0.3 - 1, plot_style_fill_wblobc)) @@ -1957,11 +2000,13 @@ bool html_redraw_radio(int x, int y, int width, int height, bool selected) * \param box box of input * \param scale scale for redraw * \param background_colour current background colour + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_file(int x, int y, int width, int height, - struct box *box, float scale, colour background_colour) + struct box *box, float scale, colour background_colour, + const struct redraw_context *ctx) { int text_width; const char *text; @@ -1985,7 +2030,7 @@ bool html_redraw_file(int x, int y, int width, int height, else x = x + 4; - return plot.text(x, y + height * 0.75, text, length, &fstyle); + return ctx->plot->text(x, y + height * 0.75, text, length, &fstyle); } @@ -1999,6 +2044,7 @@ bool html_redraw_file(int x, int y, int width, int height, * \param clip current clip rectangle * \param background_colour current background colour * \param background box containing background details (usually ::box) + * \param ctx current redraw context * \return true if successful, false otherwise * * The reason for the presence of ::background is the backwards compatibility @@ -2008,8 +2054,9 @@ bool html_redraw_file(int x, int y, int width, int height, bool html_redraw_background(int x, int y, struct box *box, float scale, const struct rect *clip, colour *background_colour, - struct box *background) + struct box *background, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; bool repeat_x = false; bool repeat_y = false; bool plot_colour = true; @@ -2159,7 +2206,7 @@ bool html_redraw_background(int x, int y, struct box *box, float scale, *background_colour = nscss_color_to_ns(bgcol); pstyle_fill_bg.fill_colour = *background_colour; if (plot_colour) - if (!plot.rectangle(r.x0, r.y0, r.x1, r.y1, + if (!plot->rectangle(r.x0, r.y0, r.x1, r.y1, &pstyle_fill_bg)) return false; } @@ -2184,7 +2231,7 @@ bool html_redraw_background(int x, int y, struct box *box, float scale, if ((r.x0 < r.x1) && (r.y0 < r.y1)) { struct content_redraw_data bg_data; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; bg_data.x = x; @@ -2197,7 +2244,7 @@ bool html_redraw_background(int x, int y, struct box *box, float scale, bg_data.repeat_y = repeat_y; if (!content_redraw(background->background, - &bg_data, &r)) + &bg_data, &r, ctx)) return false; } } @@ -2222,13 +2269,15 @@ bool html_redraw_background(int x, int y, struct box *box, float scale, * \param first true if this is the first rectangle associated with the inline * \param last true if this is the last rectangle associated with the inline * \param background_colour updated to current background colour if plotted + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_inline_background(int x, int y, struct box *box, float scale, const struct rect *clip, struct rect b, bool first, bool last, - colour *background_colour) + colour *background_colour, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; struct rect r = *clip; bool repeat_x = false; bool repeat_y = false; @@ -2308,7 +2357,7 @@ bool html_redraw_inline_background(int x, int y, struct box *box, float scale, pstyle_fill_bg.fill_colour = *background_colour; if (plot_colour) - if (!plot.rectangle(r.x0, r.y0, r.x1, r.y1, + if (!plot->rectangle(r.x0, r.y0, r.x1, r.y1, &pstyle_fill_bg)) return false; } @@ -2333,7 +2382,7 @@ bool html_redraw_inline_background(int x, int y, struct box *box, float scale, if ((r.x0 < r.x1) && (r.y0 < r.y1)) { struct content_redraw_data bg_data; - if (!plot.clip(&r)) + if (!plot->clip(&r)) return false; bg_data.x = x; @@ -2345,7 +2394,7 @@ bool html_redraw_inline_background(int x, int y, struct box *box, float scale, bg_data.repeat_x = repeat_x; bg_data.repeat_y = repeat_y; - if (!content_redraw(box->background, &bg_data, &r)) + if (!content_redraw(box->background, &bg_data, &r, ctx)) return false; } } @@ -2362,12 +2411,13 @@ bool html_redraw_inline_background(int x, int y, struct box *box, float scale, * \param y_parent y coordinate of parent of box * \param scale scale for redraw * \param background_colour current background colour + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_text_decoration(struct box *box, int x_parent, int y_parent, float scale, - colour background_colour) + colour background_colour, const struct redraw_context *ctx) { static const enum css_text_decoration_e decoration[] = { CSS_TEXT_DECORATION_UNDERLINE, CSS_TEXT_DECORATION_OVERLINE, @@ -2392,7 +2442,7 @@ bool html_redraw_text_decoration(struct box *box, decoration[i]) if (!html_redraw_text_decoration_inline(box, x_parent, y_parent, scale, - fgcol, line_ratio[i])) + fgcol, line_ratio[i], ctx)) return false; } else { for (i = 0; i != NOF_ELEMENTS(decoration); i++) @@ -2402,7 +2452,7 @@ bool html_redraw_text_decoration(struct box *box, x_parent + box->x, y_parent + box->y, scale, - fgcol, line_ratio[i])) + fgcol, line_ratio[i], ctx)) return false; } @@ -2419,12 +2469,15 @@ bool html_redraw_text_decoration(struct box *box, * \param scale scale for redraw * \param colour colour for decorations * \param ratio position of line as a ratio of line height + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_text_decoration_inline(struct box *box, int x, int y, - float scale, colour colour, float ratio) + float scale, colour colour, float ratio, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; struct box *c; plot_style_t plot_style_box = { .stroke_type = PLOT_OP_TYPE_SOLID, @@ -2436,7 +2489,7 @@ bool html_redraw_text_decoration_inline(struct box *box, int x, int y, c = c->next) { if (c->type != BOX_TEXT) continue; - if (!plot.line((x + c->x) * scale, + if (!plot->line((x + c->x) * scale, (y + c->y + c->height * ratio) * scale, (x + c->x + c->width) * scale, (y + c->y + c->height * ratio) * scale, @@ -2456,12 +2509,15 @@ bool html_redraw_text_decoration_inline(struct box *box, int x, int y, * \param scale scale for redraw * \param colour colour for decorations * \param ratio position of line as a ratio of line height + * \param ctx current redraw context * \return true if successful, false otherwise */ bool html_redraw_text_decoration_block(struct box *box, int x, int y, - float scale, colour colour, float ratio) + float scale, colour colour, float ratio, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; struct box *c; plot_style_t plot_style_box = { .stroke_type = PLOT_OP_TYPE_SOLID, @@ -2471,7 +2527,7 @@ bool html_redraw_text_decoration_block(struct box *box, int x, int y, /* draw through text descendants */ for (c = box->children; c; c = c->next) { if (c->type == BOX_TEXT) { - if (!plot.line((x + c->x) * scale, + if (!plot->line((x + c->x) * scale, (y + c->y + c->height * ratio) * scale, (x + c->x + c->width) * scale, (y + c->y + c->height * ratio) * scale, @@ -2481,7 +2537,7 @@ bool html_redraw_text_decoration_block(struct box *box, int x, int y, c->type == BOX_BLOCK) { if (!html_redraw_text_decoration_block(c, x + c->x, y + c->y, - scale, colour, ratio)) + scale, colour, ratio, ctx)) return false; } } diff --git a/render/textplain.c b/render/textplain.c index 5859ebd43..aa4dba56c 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -103,7 +103,7 @@ static void textplain_mouse_action(struct content *c, struct browser_window *bw, static void textplain_reformat(struct content *c, int width, int height); static void textplain_destroy(struct content *c); static bool textplain_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror textplain_clone(const struct content *old, struct content **newc); static content_type textplain_content_type(lwc_string *mime_type); @@ -669,16 +669,18 @@ void textplain_mouse_action(struct content *c, struct browser_window *bw, * \param c content of type CONTENT_TEXTPLAIN * \param data redraw data for this content redraw * \param clip current clip region + * \param ctx current redraw context * \return true if successful, false otherwise * * x, y, clip_[xy][01] are in target coordinates. */ bool textplain_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { textplain_content *text = (textplain_content *) c; struct browser_window *bw = current_redraw_browser; + const struct plotter_table *plot = ctx->plot; char *utf8_data = text->utf8_data; long lineno; int x = data->x; @@ -703,7 +705,7 @@ bool textplain_redraw(struct content *c, struct content_redraw_data *data, if (line1 < line0) line1 = line0; - if (!plot.rectangle(clip->x0, clip->y0, clip->x1, clip->y1, + if (!plot->rectangle(clip->x0, clip->y0, clip->x1, clip->y1, plot_style_fill_white)) return false; @@ -745,7 +747,8 @@ bool textplain_redraw(struct content *c, struct content_redraw_data *data, line[lineno].start + offset, 0, &textplain_style, tx, y + (lineno * scaled_line_height), - clip, line_height, data->scale, false)) + clip, line_height, data->scale, false, + ctx)) return false; if (next_offset >= length) @@ -787,7 +790,7 @@ bool textplain_redraw(struct content *c, struct content_redraw_data *data, if (highlighted) { int sy = y + (lineno * scaled_line_height); - if (!plot.rectangle(tx, sy, + if (!plot->rectangle(tx, sy, ntx, sy + scaled_line_height, plot_style_highlight)) return false; diff --git a/riscos/content-handlers/artworks.c b/riscos/content-handlers/artworks.c index 0747a3de0..ffbd7835e 100644 --- a/riscos/content-handlers/artworks.c +++ b/riscos/content-handlers/artworks.c @@ -111,7 +111,7 @@ static nserror artworks_create(const content_handler *handler, static bool artworks_convert(struct content *c); static void artworks_destroy(struct content *c); static bool artworks_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror artworks_clone(const struct content *old, struct content **newc); static content_type artworks_content_type(lwc_string *mime_type); @@ -330,7 +330,7 @@ void artworks_destroy(struct content *c) */ bool artworks_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { static const ns_os_vdu_var_list vars = { os_MODEVAR_XEIG_FACTOR, @@ -353,7 +353,7 @@ bool artworks_redraw(struct content *c, struct content_redraw_data *data, int clip_x1 = clip->x1; int clip_y1 = clip->y1; - if (plot.flush && !plot.flush()) + if (ctx->plot->flush && !ctx->plot->flush()) return false; /* pick up render addresses again in case they've changed diff --git a/riscos/content-handlers/draw.c b/riscos/content-handlers/draw.c index e8a9d654a..5f3865921 100644 --- a/riscos/content-handlers/draw.c +++ b/riscos/content-handlers/draw.c @@ -51,7 +51,7 @@ static nserror draw_create(const content_handler *handler, static bool draw_convert(struct content *c); static void draw_destroy(struct content *c); static bool draw_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror draw_clone(const struct content *old, struct content **newc); static content_type draw_content_type(lwc_string *mime_type); @@ -207,7 +207,7 @@ void draw_destroy(struct content *c) */ bool draw_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { draw_content *draw = (draw_content *) c; os_trfm matrix; @@ -216,7 +216,7 @@ bool draw_redraw(struct content *c, struct content_redraw_data *data, const void *src_data; os_error *error; - if (plot.flush && !plot.flush()) + if (ctx->plot->flush && !ctx->plot->flush()) return false; if (!c->width || !c->height) diff --git a/riscos/content-handlers/sprite.c b/riscos/content-handlers/sprite.c index f10c0166f..9260703f4 100644 --- a/riscos/content-handlers/sprite.c +++ b/riscos/content-handlers/sprite.c @@ -53,7 +53,7 @@ static nserror sprite_create(const content_handler *handler, static bool sprite_convert(struct content *c); static void sprite_destroy(struct content *c); static bool sprite_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); static nserror sprite_clone(const struct content *old, struct content **newc); static content_type sprite_content_type(lwc_string *mime_type); @@ -207,11 +207,11 @@ void sprite_destroy(struct content *c) */ bool sprite_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { sprite_content *sprite = (sprite_content *) c; - if (plot.flush && !plot.flush()) + if (ctx->plot->flush && !ctx->plot->flush()) return false; return image_redraw(sprite->data, diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index d92e8fc8d..6614a8ac5 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -582,6 +582,10 @@ void ro_gui_url_bar_redraw(struct url_bar *url_bar, wimp_draw *redraw) xwimp_plot_icon(&icon); } else { struct content_redraw_data data; + struct redraw_context ctx = { + .interactive = true, + .plot = &ro_plotters + }; xwimp_set_colour(wimp_COLOUR_WHITE); xos_plot(os_MOVE_TO, @@ -611,7 +615,7 @@ void ro_gui_url_bar_redraw(struct url_bar *url_bar, wimp_draw *redraw) data.repeat_x = false; data.repeat_y = false; - content_redraw(url_bar->favicon_content, &data, &clip); + content_redraw(url_bar->favicon_content, &data, &clip, &ctx); } } diff --git a/riscos/history.c b/riscos/history.c index 93cd65ab7..09770f90f 100644 --- a/riscos/history.c +++ b/riscos/history.c @@ -139,8 +139,10 @@ void ro_gui_history_redraw(wimp_draw *redraw) { osbool more; os_error *error; - - plot = ro_plotters; + struct redraw_context ctx = { + .interactive = true, + .plot = &ro_plotters + }; error = xwimp_redraw_window(redraw, &more); if (error) { @@ -152,7 +154,7 @@ void ro_gui_history_redraw(wimp_draw *redraw) while (more) { ro_plot_origin_x = redraw->box.x0 - redraw->xscroll; ro_plot_origin_y = redraw->box.y1 - redraw->yscroll; - history_redraw(history_current); + history_redraw(history_current, &ctx); error = xwimp_get_rectangle(redraw, &more); if (error) { LOG(("xwimp_get_rectangle: 0x%x: %s", diff --git a/riscos/print.c b/riscos/print.c index 18c6db9cd..639fa5be0 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -618,8 +618,6 @@ bool print_document(struct gui_window *g, const char *filename) goto error; } - plot = ro_plotters; - plot.option_knockout = false; ro_gui_current_redraw_gui = g; current_redraw_browser = NULL; /* we don't want to print the selection */ @@ -689,6 +687,11 @@ bool print_document(struct gui_window *g, const char *filename) while (more) { struct content_redraw_data data; + /* TODO: turn knockout off for print */ + struct redraw_context ctx = { + .interactive = false, + .plot = &ro_plotters + }; LOG(("redrawing area: [(%d, %d), (%d, %d)]", b.x0, b.y0, b.x1, b.y1)); @@ -706,7 +709,7 @@ bool print_document(struct gui_window *g, const char *filename) data.repeat_x = false; data.repeat_y = false; - if (!content_redraw(h, &data, &clip)) { + if (!content_redraw(h, &data, &clip, &ctx)) { error_message = "redraw error"; goto error; } @@ -805,6 +808,10 @@ const char *print_declare_fonts(hlcache_handle *h) struct content_redraw_data data; const char *error_message = 0; os_error *error; + struct redraw_context ctx = { + .interactive = false, + .plot = &print_fonts_plotters + }; free(print_fonts_list); print_fonts_list = 0; @@ -823,8 +830,7 @@ const char *print_declare_fonts(hlcache_handle *h) data.repeat_x = false; data.repeat_y = false; - plot = print_fonts_plotters; - if (!content_redraw(h, &data, &clip)) { + if (!content_redraw(h, &data, &clip, &ctx)) { if (print_fonts_error) return print_fonts_error; return "Declaring fonts failed."; diff --git a/riscos/save_draw.c b/riscos/save_draw.c index 5c8f61a3d..76fcca4d9 100644 --- a/riscos/save_draw.c +++ b/riscos/save_draw.c @@ -93,6 +93,10 @@ bool save_as_draw(hlcache_handle *h, const char *path) struct content_redraw_data data; size_t drawfile_size; os_error *error; + struct redraw_context ctx = { + .interactive = true, + .plot = &ro_plotters + }; ro_save_draw_diagram = pencil_create(); if (!ro_save_draw_diagram) { @@ -115,8 +119,7 @@ bool save_as_draw(hlcache_handle *h, const char *path) data.repeat_x = false; data.repeat_y = false; - plot = ro_save_draw_plotters; - if (!content_redraw(h, &data, &clip)) { + if (!content_redraw(h, &data, &clip, &ctx)) { pencil_free(ro_save_draw_diagram); return false; } diff --git a/riscos/thumbnail.c b/riscos/thumbnail.c index 92fa0cdb2..c6e2b0d8e 100644 --- a/riscos/thumbnail.c +++ b/riscos/thumbnail.c @@ -86,6 +86,10 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, osspriteop_area *sprite_area = NULL; osspriteop_header *sprite_header = NULL; _kernel_oserror *error; + struct redraw_context ctx = { + .interactive = false, + .plot = &ro_plotters + }; assert(content); assert(bitmap); @@ -110,7 +114,6 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, } /* set up the plotters */ - plot = ro_plotters; ro_plot_origin_x = 0; ro_plot_origin_y = bitmap->height * 2; @@ -125,7 +128,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, colourtrans_set_gcol(os_COLOUR_WHITE, colourtrans_SET_BG_GCOL, os_ACTION_OVERWRITE, 0); - thumbnail_redraw(content, bitmap->width, bitmap->height); + thumbnail_redraw(content, bitmap->width, bitmap->height, &ctx); thumbnail_restore_output(save_area); rufl_invalidate_cache(); diff --git a/riscos/treeview.c b/riscos/treeview.c index 0206a7c29..c5f1cd526 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -357,8 +357,6 @@ void ro_treeview_redraw(wimp_draw *redraw) */ } - plot = ro_plotters; - error = xwimp_redraw_window(redraw, &more); if (error) { LOG(("xwimp_redraw_window: 0x%x: %s", @@ -380,7 +378,11 @@ void ro_treeview_redraw(wimp_draw *redraw) void ro_treeview_redraw_loop(wimp_draw *redraw, ro_treeview *tv, osbool more) { - os_error *error; + os_error *error; + struct redraw_context ctx = { + .interactive = true, + .plot = &ro_plotters + }; while (more) { ro_plot_origin_x = redraw->box.x0 - redraw->xscroll; @@ -394,7 +396,8 @@ void ro_treeview_redraw_loop(wimp_draw *redraw, ro_treeview *tv, osbool more) ((ro_plot_origin_y+tv->origin.y) -redraw->clip.y1)/2, (redraw->clip.x1 - redraw->clip.x0)/2, - (redraw->clip.y1 - redraw->clip.y0)/2); + (redraw->clip.y1 - redraw->clip.y0)/2, + &ctx); /* Put the graphcis window back how the Wimp set it. */ clip.x0 = (redraw->clip.x0 - ro_plot_origin_x) / 2; diff --git a/riscos/window.c b/riscos/window.c index 2a727643e..3caf12cd3 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -1665,6 +1665,10 @@ void ro_gui_window_redraw(wimp_draw *redraw) osbool more; struct gui_window *g = (struct gui_window *)ro_gui_wimp_event_get_user_data(redraw->w); os_error *error; + struct redraw_context ctx = { + .interactive = true, + .plot = &ro_plotters + }; /* We can't render locked contents. If the browser window is not * ready for redraw, do nothing. Else, in the case of buffered @@ -1672,7 +1676,6 @@ void ro_gui_window_redraw(wimp_draw *redraw) if (!browser_window_redraw_ready(g->bw)) return; - plot = ro_plotters; ro_gui_current_redraw_gui = g; current_redraw_browser = g->bw; @@ -1705,7 +1708,7 @@ void ro_gui_window_redraw(wimp_draw *redraw) if (ro_gui_current_redraw_gui->option.buffer_everything) ro_gui_buffer_open(redraw); - browser_window_redraw(g->bw, 0, 0, &clip); + browser_window_redraw(g->bw, 0, 0, &clip, &ctx); if (ro_gui_current_redraw_gui->option.buffer_everything) ro_gui_buffer_close(); @@ -4317,6 +4320,10 @@ void ro_gui_window_update_boxes(void) struct update_box *cur; struct gui_window *g; const union content_msg_data *data; + struct redraw_context ctx = { + .interactive = true, + .plot = &ro_plotters + }; for (cur = pending_updates; cur != NULL; cur = cur->next) { g = cur->g; @@ -4344,7 +4351,6 @@ void ro_gui_window_update_boxes(void) ro_gui_current_redraw_gui = g; current_redraw_browser = g->bw; - plot = ro_plotters; ro_plot_origin_x = update.box.x0 - update.xscroll; ro_plot_origin_y = update.box.y1 - update.yscroll; @@ -4357,7 +4363,7 @@ void ro_gui_window_update_boxes(void) if (use_buffer) ro_gui_buffer_open(&update); - browser_window_redraw(g->bw, 0, 0, &clip); + browser_window_redraw(g->bw, 0, 0, &clip, &ctx); if (use_buffer) ro_gui_buffer_close(); diff --git a/utils/types.h b/utils/types.h index 40427b658..2e77cade4 100644 --- a/utils/types.h +++ b/utils/types.h @@ -23,10 +23,23 @@ #ifndef _NETSURF_UTILS_TYPES_H_ #define _NETSURF_UTILS_TYPES_H_ +struct plotter_table; + /* Rectangle coordinates */ struct rect { int x0, y0; /* Top left */ int x1, y1; /* Bottom right */ }; + +/* Redraw context */ +struct redraw_context { + /** Redraw to show interactive features, such as active selections + * etc. Should be off for printing. */ + bool interactive; + + /** Current plotters, must be assigned before use. */ + const struct plotter_table *plot; +}; + #endif diff --git a/windows/drawable.c b/windows/drawable.c index 5b2dea967..cdb9cc2b4 100644 --- a/windows/drawable.c +++ b/windows/drawable.c @@ -305,6 +305,10 @@ nsws_drawable_paint(struct gui_window *gw, HWND hwnd) { struct rect clip; PAINTSTRUCT ps; + struct redraw_context ctx = { + .interactive = true, + .plot = &win_plotters + }; BeginPaint(hwnd, &ps); @@ -319,7 +323,7 @@ nsws_drawable_paint(struct gui_window *gw, HWND hwnd) browser_window_redraw(gw->bw, -gw->scrollx / gw->bw->scale, -gw->scrolly / gw->bw->scale, - &clip); + &clip, &ctx); } EndPaint(hwnd, &ps); diff --git a/windows/localhistory.c b/windows/localhistory.c index bd59f4c8a..e7b79cb8e 100644 --- a/windows/localhistory.c +++ b/windows/localhistory.c @@ -78,7 +78,11 @@ static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct g static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw) { - HDC tmp_hdc; + HDC tmp_hdc; + struct redraw_context ctx = { + .interactive = true, + .plot = &win_plotters + }; LOG(("gui window %p", gw)); @@ -90,7 +94,7 @@ static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window tmp_hdc = plot_hdc; plot_hdc = GetDC(l->hwnd); - history_redraw(gw->bw->history); + history_redraw(gw->bw->history, &ctx); ReleaseDC(l->hwnd, plot_hdc); @@ -268,6 +272,11 @@ nsws_localhistory_event_callback(HWND hwnd, UINT msg, case WM_PAINT: { PAINTSTRUCT ps; HDC hdc, tmp_hdc; + struct redraw_context ctx = { + .interactive = true, + .plot = &win_plotters + }; + hdc = BeginPaint(hwnd, &ps); if (gw->bw != NULL) { /* set global HDC for the plotters */ @@ -280,7 +289,7 @@ nsws_localhistory_event_callback(HWND hwnd, UINT msg, gw->localhistory->hscroll + (ps.rcPaint.right - ps.rcPaint.left), gw->localhistory->vscroll + (ps.rcPaint.bottom - ps.rcPaint.top), ps.rcPaint.left, - ps.rcPaint.top); + ps.rcPaint.top, &ctx); plot_hdc = tmp_hdc; diff --git a/windows/plot.c b/windows/plot.c index 491b89bcc..2898fae27 100644 --- a/windows/plot.c +++ b/windows/plot.c @@ -846,7 +846,7 @@ static bool path(const float *p, unsigned int n, colour fill, float width, return true; } -struct plotter_table plot = { +const struct plotter_table win_plotters = { .rectangle = rectangle, .line = line, .polygon = polygon, diff --git a/windows/plot.h b/windows/plot.h index dc0ac0386..044f4be47 100644 --- a/windows/plot.h +++ b/windows/plot.h @@ -18,6 +18,8 @@ #include #include "desktop/gui.h" + +extern const struct plotter_table win_plotters; extern HDC plot_hdc; diff --git a/windows/thumbnail.c b/windows/thumbnail.c index ec44bbb2f..565ee3de1 100644 --- a/windows/thumbnail.c +++ b/windows/thumbnail.c @@ -38,6 +38,10 @@ thumbnail_create(hlcache_handle *content, int width; int height; HDC hdc, bufferdc, minidc; + struct redraw_context ctx = { + .interactive = false, + .plot = &win_plotters + }; struct bitmap *fsbitmap; @@ -67,7 +71,7 @@ thumbnail_create(hlcache_handle *content, hdc = plot_hdc; plot_hdc = bufferdc; - thumbnail_redraw(content, width, height); + thumbnail_redraw(content, width, height, &ctx); plot_hdc = hdc; /* scale bitmap bufferbm into minibm */ -- cgit v1.2.3