summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-04-26 09:43:18 +0100
committerVincent Sanders <vince@kyllikki.org>2017-04-26 09:43:18 +0100
commitbd932d958b022c5fe02c76e976d3871d8651843b (patch)
tree4022b23875df5be7ad0eaa144325ed96aad1eb4e
parent31d98a1d2e5081ef2ca2d941f7e3b92344185399 (diff)
downloadnetsurf-bd932d958b022c5fe02c76e976d3871d8651843b.tar.gz
netsurf-bd932d958b022c5fe02c76e976d3871d8651843b.tar.bz2
remove reformat from browser window operation table
the reformat callback was completely unecessary and implementations appeared potentialy buggy. This rationalises the API and reduces the number of operations a frontend must provide.
-rw-r--r--desktop/browser.c36
-rw-r--r--desktop/browser_private.h3
-rw-r--r--desktop/gui_factory.c3
-rw-r--r--include/netsurf/browser_window.h33
-rw-r--r--include/netsurf/window.h45
5 files changed, 79 insertions, 41 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 45f300697..73a86c2e3 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1781,6 +1781,27 @@ static void browser_window_destroy_children(struct browser_window *bw)
/**
+ * internal scheduled reformat callback.
+ *
+ * scheduled reformat callback to allow reformats from unthreaded context.
+ *
+ * \param vbw The browser window to be reformatted
+ */
+static void scheduled_reformat(void *vbw)
+{
+ struct browser_window *bw = vbw;
+ int width;
+ int height;
+ nserror res;
+
+ res = guit->window->get_dimensions(bw->window, &width, &height, false);
+ if (res == NSERROR_OK) {
+ browser_window_reformat(bw, false, width, height);
+ }
+}
+
+
+/**
* Release all memory associated with a browser window.
*
* \param bw browser window
@@ -1809,8 +1830,8 @@ static void browser_window_destroy_internal(struct browser_window *bw)
/* The ugly cast here is so the reformat function can be
* passed a gui window pointer in its API rather than void*
*/
- LOG("Clearing schedule %p(%p)", guit->window->reformat, bw->window);
- guit->misc->schedule(-1, (void(*)(void*))guit->window->reformat, bw->window);
+ LOG("Clearing reformat schedule for browser window %p", bw);
+ guit->misc->schedule(-1, scheduled_reformat, bw);
/* If this brower window is not the root window, and has focus, unset
* the root browser window's focus pointer. */
@@ -2574,13 +2595,16 @@ void browser_window_set_pointer(struct browser_window *bw,
guit->window->set_pointer(root->window, gui_shape);
}
+
/* exported function documented in netsurf/browser_window.h */
nserror browser_window_schedule_reformat(struct browser_window *bw)
{
- /* The ugly cast here is so the reformat function can be
- * passed a gui window pointer in its API rather than void*
- */
- guit->misc->schedule(0, (void(*)(void*))guit->window->reformat, bw->window);
+ if (bw->window == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ guit->misc->schedule(0, scheduled_reformat, bw);
+
return NSERROR_OK;
}
diff --git a/desktop/browser_private.h b/desktop/browser_private.h
index 3e9b8467a..5a53e2f0b 100644
--- a/desktop/browser_private.h
+++ b/desktop/browser_private.h
@@ -17,7 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
+/**
+ * \file
* Browser window private structure.
*/
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index e1de21ea1..559823d61 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -176,9 +176,6 @@ static nserror verify_window_register(struct gui_window_table *gwt)
if (gwt->update_extent == NULL) {
return NSERROR_BAD_PARAMETER;
}
- if (gwt->reformat == NULL) {
- return NSERROR_BAD_PARAMETER;
- }
/* fill in the optional entries with defaults */
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index 858d4aeac..c56cf5571 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -296,16 +296,23 @@ void browser_window_reload(struct browser_window *bw, bool all);
*/
void browser_window_destroy(struct browser_window *bw);
+
/**
* Reformat a browser window contents to a new width or height.
*
+ * This API is not safe to call from all contexts and care must be used.
+ *
+ * \warning This API is generally only useful within the browser core
+ * and is only exposed for historical reasons. A frontend almost
+ * certianly actually wants browser_window_schedule_reformat() and not
+ * this.
+ *
* \param bw The browser window to reformat.
* \param background Reformat in the background.
* \param width new width
* \param height new height
*/
-void browser_window_reformat(struct browser_window *bw, bool background,
- int width, int height);
+void browser_window_reformat(struct browser_window *bw, bool background, int width, int height);
/**
@@ -411,6 +418,7 @@ void browser_window_mouse_click(struct browser_window *bw,
void browser_window_mouse_track(struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
+
/**
* Locate a browser window in the specified stack according.
*
@@ -423,21 +431,28 @@ struct browser_window *browser_window_find_target(
struct browser_window *bw, const char *target,
browser_mouse_state mouse);
+
/**
- * Cause the frontends reformat entry to be called in safe context.
+ * Reformat the browser window contents in a safe context.
*
- * The browser_window_reformat call cannot safely be called from some
- * contexts, this call allows for the reformat to happen from a safe
+ * The browser_window_reformat() call cannot safely be called from some
+ * contexts, This interface allows for the reformat to happen from a safe
* top level context.
*
- * The callback is frontend provided as the context information (size
- * etc.) about the windowing toolkit is only available to the
- * frontend.
+ * The reformat uses the window table get_dimensions() callback as the
+ * correct viewport dimensions are only available to the frontend.
+ *
+ * \param bw The browser window to reformat the content of.
+ * \return NSERROR_OK on success else appropriate error code.
*/
nserror browser_window_schedule_reformat(struct browser_window *bw);
-
+/**
+ * callback for select menu widget
+ *
+ * \todo This API needs investigating
+ */
void browser_select_menu_callback(void *client_data,
int x, int y, int width, int height);
diff --git a/include/netsurf/window.h b/include/netsurf/window.h
index 434a79584..b9a68639c 100644
--- a/include/netsurf/window.h
+++ b/include/netsurf/window.h
@@ -23,8 +23,8 @@
* operations.
*/
-#ifndef _NETSURF_WINDOW_H_
-#define _NETSURF_WINDOW_H_
+#ifndef NETSURF_WINDOW_H
+#define NETSURF_WINDOW_H
typedef enum gui_save_type {
GUI_SAVE_SOURCE,
@@ -50,10 +50,13 @@ typedef enum {
GDRAGGING_OTHER
} gui_drag_type;
+/**
+ * Window creation control flags.
+ */
typedef enum {
- GW_CREATE_NONE = 0, /* New window */
- GW_CREATE_CLONE = (1 << 0), /* Clone existing window */
- GW_CREATE_TAB = (1 << 1) /* In same window as existing */
+ GW_CREATE_NONE = 0, /**< New window */
+ GW_CREATE_CLONE = (1 << 0), /**< Clone existing window */
+ GW_CREATE_TAB = (1 << 1) /**< In same window as existing */
} gui_window_create_flags;
struct browser_window;
@@ -90,6 +93,7 @@ struct gui_window_table {
struct gui_window *existing,
gui_window_create_flags flags);
+
/**
* Destroy previously created gui window
*
@@ -97,6 +101,7 @@ struct gui_window_table {
*/
void (*destroy)(struct gui_window *gw);
+
/**
* Invalidate an area of a window.
*
@@ -116,6 +121,7 @@ struct gui_window_table {
*/
nserror (*invalidate)(struct gui_window *g, const struct rect *rect);
+
/**
* Get the scroll position of a browser window.
*
@@ -126,6 +132,7 @@ struct gui_window_table {
*/
bool (*get_scroll)(struct gui_window *g, int *sx, int *sy);
+
/**
* Set the scroll position of a browser window.
*
@@ -135,18 +142,24 @@ struct gui_window_table {
*/
void (*set_scroll)(struct gui_window *g, int sx, int sy);
+
/**
* Find the current dimensions of a browser window's content area.
*
- * @todo The implementations of this are buggy and its only
- * used from frames code.
+ * This is used to determine the actual available drawing size
+ * in pixels. This is used to allow contents that can be
+ * dynamicaly reformatted, such as HTML, to better use the
+ * available space.
*
- * \param g gui_window to measure
- * \param width receives width of window
+ * \param gw The gui window to measure content area of.
+ * \param width receives width of window
* \param height receives height of window
* \param scaled whether to return scaled values
+ * \return NSERROR_OK on sucess and width and height updated
+ * else error code.
*/
- void (*get_dimensions)(struct gui_window *g, int *width, int *height, bool scaled);
+ nserror (*get_dimensions)(struct gui_window *gw, int *width, int *height, bool scaled);
+
/**
* Update the extent of the inside of a browser window to that of the
@@ -159,18 +172,6 @@ struct gui_window_table {
*/
void (*update_extent)(struct gui_window *g);
- /**
- * Reformat a window.
- *
- * This is used to perform reformats when the page contents
- * require reformatting. The reformat is requested using
- * browser_window_schedule_reformat and occurs via a scheduled
- * callback hence from top level context.
- *
- * \param g gui_window to reformat.
- */
- void (*reformat)(struct gui_window *g);
-
/* Optional entries */