update invalidate area core window API

slightly extends the invalidate core window API with error return and
whole window invalidation. Also renames it to be more inline with
browser window API call.

cannot quite reuse browser window API yet as that applies scaling
This commit is contained in:
Vincent Sanders 2017-05-23 09:41:29 +01:00
parent bc42b29801
commit ac732fb79d
4 changed files with 59 additions and 40 deletions

View File

@ -34,8 +34,8 @@ The header that defines the callback interface is netsurf/core_window.h
The callback table contains five function pointer interfaces which the The callback table contains five function pointer interfaces which the
frontend must implement for the core. frontend must implement for the core.
- redraw_request - invalidate
request a redraw an area of a window invalidate an area of a window
- update_size - update_size
Update the limits of the window Update the limits of the window
@ -67,27 +67,29 @@ core to provide the necessary interactions with the frontend windowing
system. system.
These actions should ideally use the standard frontend window These actions should ideally use the standard frontend window
processing. So for the GTK frontend when the core calls the redraw processing. So for the GTK frontend when the core calls the invalidate
operation it simply marks the area passed as damaged (using operation it simply marks the area passed as damaged (using
gtk_widget_queue_draw_area()) and lets the standard expose event cause gtk_widget_queue_draw_area()) and lets the standard expose event cause
the redraw to occour. the redraw to occur.
If the frontend needs to redraw an area of a window (perhaps an expose If the frontend needs to redraw an area of a window (perhaps an expose
event occoured) it must call the corewindoe API wrappers event occurred or the window has had an area marked as invalid) it
implementation e.g in the case of ssl certificate viewer must call the core window API wrappers implementation which will
perform the plot operations required to update an area of the window.
e.g in the case of ssl certificate viewer
void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d, void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
int x, int y, struct rect *clip, int x, int y, struct rect *clip,
const struct redraw_context *ctx); const struct redraw_context *ctx);
which will perform the plot operations required to update an area of would perform the plot operations for that SSL data window.
the window for that SSL data.
Usage Usage
----- -----
The usage pattern that is expected is for a frontend to create a core The usage pattern that is expected is for a frontend to create a core
window impementation that implements the necessary five API in a window implementation that implements the necessary five API in a
generic way and allows the frontend to provide the specific generic way and allows the frontend to provide the specific
specialisation for each of the user interface elements it wishes to specialisation for each of the user interface elements it wishes to
use (cookies, SSL viewer etc). use (cookies, SSL viewer etc).
@ -95,7 +97,7 @@ use (cookies, SSL viewer etc).
The GTK frontend for example: The GTK frontend for example:
has source corewindow.[ch] which implement the five core callbacks has source corewindow.[ch] which implement the five core callbacks
using generic GTK operations (redraw_request calls using generic GTK operations (invalidate calls
gtk_widget_queue_draw_area() etc.) and then provides additional gtk_widget_queue_draw_area() etc.) and then provides additional
operations on a GTK drawing area object to attach expose event operations on a GTK drawing area object to attach expose event
processing, keypress processing etc. processing, keypress processing etc.
@ -110,7 +112,7 @@ calls sslcert_viewer_init() directly.
frontend skeleton frontend skeleton
----------------- -----------------
An example core window implementation for a frontend ssl certficiate An example core window implementation for a frontend ssl certificate
viewer is presented here. This implements the suggested usage above viewer is presented here. This implements the suggested usage above
and provides generic corewindow helpers. and provides generic corewindow helpers.
@ -313,8 +315,8 @@ example_cw_draw_event(toolkit_widget *widget,
/** /**
* callback from core to request a redraw * callback from core to request a redraw
*/ */
static void static nserror
example_cw_redraw_request(struct core_window *cw, const struct rect *r) example_cw_invalidate(struct core_window *cw, const struct rect *r)
{ {
struct example_corewindow *example_cw = (struct example_corewindow *)cw; struct example_corewindow *example_cw = (struct example_corewindow *)cw;
@ -362,7 +364,7 @@ example_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
struct core_window_callback_table example_cw_cb_table = { struct core_window_callback_table example_cw_cb_table = {
.redraw_request = example_cw_redraw_request, .invalidate = example_cw_invalidate,
.update_size = example_cw_update_size, .update_size = example_cw_update_size,
.scroll_visible = example_cw_scroll_visible, .scroll_visible = example_cw_scroll_visible,
.get_window_dimensions = example_cw_get_window_dimensions, .get_window_dimensions = example_cw_get_window_dimensions,

View File

@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "utils/errors.h"
#include "netsurf/types.h" #include "netsurf/types.h"
#include "netsurf/core_window.h" #include "netsurf/core_window.h"

View File

@ -315,12 +315,12 @@ static struct treeview_resource treeview_res[TREE_RES_LAST] = {
* \param[in] tree The treeview to request redraw on. * \param[in] tree The treeview to request redraw on.
* \param[in] r rectangle to redraw * \param[in] r rectangle to redraw
*/ */
static inline void treeview__cw_redraw_request( static inline
const struct treeview *tree, void cw_invalidate_area(const struct treeview *tree,
const struct rect *r) const struct rect *r)
{ {
if (tree->cw_t != NULL) { if (tree->cw_t != NULL) {
tree->cw_t->redraw_request(tree->cw_h, r); tree->cw_t->invalidate(tree->cw_h, r);
} }
} }
@ -791,7 +791,7 @@ treeview_create_node_folder(treeview *tree,
r.y0 = treeview_node_y(tree, n); r.y0 = treeview_node_y(tree, n);
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = tree->root->height; r.y1 = tree->root->height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
} }
@ -842,7 +842,7 @@ treeview_update_node_folder(treeview *tree,
r.y0 = treeview_node_y(tree, folder); r.y0 = treeview_node_y(tree, folder);
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = r.y0 + tree_g.line_height; r.y1 = r.y0 + tree_g.line_height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return NSERROR_OK; return NSERROR_OK;
@ -914,7 +914,7 @@ treeview_update_node_entry(treeview *tree,
r.y0 = treeview_node_y(tree, entry); r.y0 = treeview_node_y(tree, entry);
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = r.y0 + entry->height; r.y1 = r.y0 + entry->height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return NSERROR_OK; return NSERROR_OK;
@ -1001,7 +1001,7 @@ treeview_create_node_entry(treeview *tree,
r.y0 = treeview_node_y(tree, n); r.y0 = treeview_node_y(tree, n);
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = tree->root->height; r.y1 = tree->root->height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
} }
@ -1154,7 +1154,7 @@ static void treeview_edit_cancel(treeview *tree, bool redraw)
r.y0 = tree->edit.y; r.y0 = tree->edit.y;
r.x1 = tree->edit.x + tree->edit.w; r.x1 = tree->edit.x + tree->edit.w;
r.y1 = tree->edit.y + tree->edit.h; r.y1 = tree->edit.y + tree->edit.h;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
} }
@ -1496,7 +1496,7 @@ treeview_delete_node(treeview *tree,
if (visible && !(flags & TREE_OPTION_SUPPRESS_REDRAW)) { if (visible && !(flags & TREE_OPTION_SUPPRESS_REDRAW)) {
r.x0 = 0; r.x0 = 0;
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return NSERROR_OK; return NSERROR_OK;
@ -1755,7 +1755,7 @@ nserror treeview_node_expand(treeview *tree, treeview_node *node)
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = tree->root->height; r.y1 = tree->root->height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return res; return res;
@ -1864,7 +1864,7 @@ nserror treeview_node_contract(treeview *tree, treeview_node *node)
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = tree->root->height; r.y1 = tree->root->height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return res; return res;
@ -1911,7 +1911,7 @@ nserror treeview_contract(treeview *tree, bool all)
treeview__cw_update_size(tree, -1, tree->root->height); treeview__cw_update_size(tree, -1, tree->root->height);
/* Redraw */ /* Redraw */
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
return NSERROR_OK; return NSERROR_OK;
} }
@ -1985,7 +1985,7 @@ nserror treeview_expand(treeview *tree, bool only_folders)
r.x1 = REDRAW_MAX; r.x1 = REDRAW_MAX;
r.y1 = tree->root->height; r.y1 = tree->root->height;
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return res; return res;
} }
@ -3182,7 +3182,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
} }
if (redraw) { if (redraw) {
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
return true; return true;
@ -3358,7 +3358,7 @@ static void treeview_textarea_callback(void *data, struct textarea_msg *msg)
r->y1 += tree->edit.y; r->y1 += tree->edit.y;
/* Redraw the textarea */ /* Redraw the textarea */
treeview__cw_redraw_request(tree, r); cw_invalidate_area(tree, r);
break; break;
default: default:
@ -3536,7 +3536,7 @@ void treeview_edit_selection(treeview *tree)
rect.y0 = y; rect.y0 = y;
rect.x1 = REDRAW_MAX; rect.x1 = REDRAW_MAX;
rect.y1 = y + tree_g.line_height; rect.y1 = y + tree_g.line_height;
treeview__cw_redraw_request(tree, &rect); cw_invalidate_area(tree, &rect);
} }
@ -3816,7 +3816,7 @@ treeview_node_mouse_action_cb(treeview_node *node,
} }
if (redraw) { if (redraw) {
treeview__cw_redraw_request(ma->tree, &r); cw_invalidate_area(ma->tree, &r);
} }
*end = true; /* Reached line with click; stop walking tree */ *end = true; /* Reached line with click; stop walking tree */
@ -3878,7 +3878,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state mouse, int x, int y)
tree->move.target_pos = TV_TARGET_NONE; tree->move.target_pos = TV_TARGET_NONE;
treeview__cw_drag_status(tree, CORE_WINDOW_DRAG_NONE); treeview__cw_drag_status(tree, CORE_WINDOW_DRAG_NONE);
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
return; return;
default: default:
/* No drag to end */ /* No drag to end */
@ -3953,7 +3953,7 @@ treeview_mouse_action(treeview *tree, browser_mouse_state mouse, int x, int y)
} }
if (redraw) { if (redraw) {
treeview__cw_redraw_request(tree, &r); cw_invalidate_area(tree, &r);
} }
} else { } else {

View File

@ -20,7 +20,7 @@
* \file * \file
* Interface to core window handling. * Interface to core window handling.
* *
* This provides a generallised API for frontends to implement which * This provides a generalised API for frontends to implement which
* allows them to provide a single implementation for general window * allows them to provide a single implementation for general window
* operations on their platform. * operations on their platform.
* *
@ -35,6 +35,9 @@
struct core_window; struct core_window;
struct rect; struct rect;
/**
* drag status passed to drag_status callback
*/
typedef enum { typedef enum {
CORE_WINDOW_DRAG_NONE, CORE_WINDOW_DRAG_NONE,
CORE_WINDOW_DRAG_SELECTION, CORE_WINDOW_DRAG_SELECTION,
@ -42,15 +45,28 @@ typedef enum {
CORE_WINDOW_DRAG_MOVE CORE_WINDOW_DRAG_MOVE
} core_window_drag_status; } core_window_drag_status;
/** Callbacks to achieve various core window functionality. */ /**
* Callbacks to achieve various core window functionality.
*/
struct core_window_callback_table { struct core_window_callback_table {
/** /**
* Request a redraw of the window * Invalidate an area of a window.
* *
* \param[in] cw the core window object * The specified area of the window should now be considered
* \param[in] r rectangle to redraw * out of date. If the area is NULL the entire window must be
* invalidated. It is expected that the windowing system will
* then subsequently cause redraw/expose operations as
* necessary.
*
* \note the frontend should not attempt to actually start the
* redraw operations as a result of this callback because the
* core redraw functions may already be threaded.
*
* \param[in] cw The core window to invalidate.
* \param[in] rect area to redraw or NULL for the entire window area
* \return NSERROR_OK on success or appropriate error code
*/ */
void (*redraw_request)(struct core_window *cw, const struct rect *r); nserror (*invalidate)(struct core_window *cw, const struct rect *rect);
/** /**
* Update the limits of the window * Update the limits of the window