Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/3940a078b118b0b81b1d799d8b83a8753aa0d3ea
...commit
http://git.netsurf-browser.org/netsurf.git/commit/3940a078b118b0b81b1d799d8b83a8753aa0d3ea
...tree
http://git.netsurf-browser.org/netsurf.git/tree/3940a078b118b0b81b1d799d8b83a8753aa0d3ea
The branch, master has been updated
via 3940a078b118b0b81b1d799d8b83a8753aa0d3ea (commit)
via 2adf0a9c44a0ebb0dc9060aa5f3e27f65e21875d (commit)
from af5f4a570453c2d0b1dcfd06044ad3abb3bd4325 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=3940a078b118b0b81b1d799d8b83a8753aa0d3ea
commit 3940a078b118b0b81b1d799d8b83a8753aa0d3ea
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>
add some example code to aid in explaining the core window interface
diff --git a/Docs/core-window-interface b/Docs/core-window-interface
index 0d5f7bc..0267f37 100644
--- a/Docs/core-window-interface
+++ b/Docs/core-window-interface
@@ -77,8 +77,8 @@ event occoured) it must call the corewindoe API wrappers
implementation e.g in the case of ssl certificate viewer
void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
- int x, int y, struct rect *clip,
- const struct redraw_context *ctx);
+ int x, int y, struct rect *clip,
+ const struct redraw_context *ctx);
which will perform the plot operations required to update an area of
the window for that SSL data.
@@ -105,4 +105,573 @@ itself, this is purely the gtk wrapper) is used by
ssl_cert.c which
creates a nsgtk_crtvrfy_window structure containing the
nsgtk_corewindow structure. It attaches actual GTK window handles to
this structure and populates elements of nsgtk_corewindow and then
-calls sslcert_viewer_init() directly.
\ No newline at end of file
+calls sslcert_viewer_init() directly.
+
+frontend skeleton
+-----------------
+
+An example core window implementation for a frontend ssl certficiate
+viewer is presented here. This implements the suggested usage above
+and provides generic corewindow helpers.
+
+
+frontends/example/corewindow.h
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EXAMPLE_COREWINDOW_H
+#define EXAMPLE_COREWINDOW_H
+
+#include "netsurf/core_window.h"
+
+/**
+ * example core window state
+ */
+struct example_corewindow {
+
+
+ /*
+ * Any variables common to any frontend window would go here.
+ * e.g. drawing area handles, toolkit pointers or other state
+ */
+ example_toolkit_widget *tk_widget;
+
+
+
+ /** drag status set by core */
+ core_window_drag_status drag_staus;
+
+ /** table of callbacks for core window operations */
+ struct core_window_callback_table *cb_table;
+
+ /**
+ * callback to draw on drawable area of example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+ nserror (*draw)(struct example_corewindow *example_cw, struct rect *r);
+
+ /**
+ * callback for keypress on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
+ */
+ nserror (*key)(struct example_corewindow *example_cw, uint32_t nskey);
+
+ /**
+ * callback for mouse event on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
+ */
+ nserror (*mouse)(struct example_corewindow *example_cw,
browser_mouse_state mouse_state, int x, int y);
+};
+
+/**
+ * initialise elements of example core window.
+ *
+ * As a pre-requisite the draw, key and mouse callbacks must be defined
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful initialisation otherwise error code.
+ */
+nserror example_corewindow_init(struct example_corewindow *example_cw);
+
+/**
+ * finalise elements of example core window.
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful finalisation otherwise error code.
+ */
+nserror example_corewindow_fini(struct example_corewindow *example_cw);
+
+#endif
+
+frontends/example/corewindow.c
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * EXAMPLE generic core window interface.
+ *
+ * Provides interface for core renderers to the example toolkit drawable area.
+ *
+ * This module is an object that must be encapsulated. Client users
+ * should embed a struct example_corewindow at the beginning of their
+ * context for this display surface, fill in relevant data and then
+ * call example_corewindow_init()
+ *
+ * The example core window structure requires the callback for draw, key and
+ * mouse operations.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+#include "utils/log.h"
+#include "utils/utils.h"
+#include "utils/messages.h"
+#include "utils/utf8.h"
+#include "netsurf/keypress.h"
+#include "netsurf/mouse.h"
+#include "desktop/plot_style.h"
+
+/* extremely likely there will be additional headers required in a real
frontend */
+#include "example/corewindow.h"
+
+
+/* toolkit event handlers that do generic things and call internal callbacks */
+
+
+static bool
+example_cw_mouse_press_event(toolkit_widget *widget, toolkit_button bt, int x,
int y, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)ctx;
+
+ example_cw->mouse(example_cw, state, x, y);
+
+ return true;
+}
+
+static bool
+example_cw_keyrelease_event(toolkit_widget *widget, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)ctx;
+
+ example_cw->key(example_cw, keycode);
+
+ return true;
+}
+
+
+
+/* signal handler for toolkit window redraw */
+static bool
+example_cw_draw_event(toolkit_widget *widget,
+ toolkit_area *tk_area,
+ void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)ctx;
+ struct rect clip;
+
+ clip.x0 = tk_area.x;
+ clip.y0 = tk_area.y;
+ clip.x1 = tk_area.width;
+ clip.y1 = tk_area.height;
+
+ example_cw->draw(example_cw, &clip);
+
+ return true;
+}
+
+
+/**
+ * callback from core to request a redraw
+ */
+static void
+example_cw_redraw_request(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+ toolkit_widget_queue_draw_area(example_cw->widget,
+ r->x0, r->y0,
+ r->x1 - r->x0, r->y1 - r->y0);
+}
+
+
+static void
+example_cw_update_size(struct core_window *cw, int width, int height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+
toolkit_widget_set_size_request(EXAMPLE_WIDGET(example_cw->drawing_area),
+ width, height);
+}
+
+
+static void
+example_cw_scroll_visible(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+ toolkit_scroll_widget(example_cw->widget, r);
+}
+
+
+static void
+example_cw_get_window_dimensions(struct core_window *cw, int *width, int
*height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+ *width = toolkit_get_widget_width(example_cw->widget);
+ *height = toolkit_get_widget_height(example_cw->widget);
+}
+
+
+static void
+example_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+ example_cw->drag_staus = ds;
+}
+
+
+struct core_window_callback_table example_cw_cb_table = {
+ .redraw_request = example_cw_redraw_request,
+ .update_size = example_cw_update_size,
+ .scroll_visible = example_cw_scroll_visible,
+ .get_window_dimensions = example_cw_get_window_dimensions,
+ .drag_status = example_cw_drag_status
+};
+
+/* exported function documented example/corewindow.h */
+nserror example_corewindow_init(struct example_corewindow *example_cw)
+{
+ /* setup the core window callback table */
+ example_cw->cb_table = &example_cw_cb_table;
+
+ /* frontend toolkit specific method of causing example_cw_draw_event
to be called when a drawing operation is required */
+ toolkit_connect_draw_event(example_cw->tk_widget,
+ example_cw_draw_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_button_press_event to be called when a button press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_button_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_button_release_event to be called when a button release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_button_release_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_motion_notify_event to be called when there is motion over the
widget */
+ toolkit_connect_motion_event(example_cw->tk_widget,
+ example_cw_motion_notify_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_key_press_event to be called when a key press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_key_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_key_release_event to be called when a key release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_key_release_event,
+ example_cw);
+
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/corewindow.h */
+nserror example_corewindow_fini(struct example_corewindow *example_cw)
+{
+ return NSERROR_OK;
+}
+
+
+frontends/example/ssl_cert.h
+----------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_EXAMPLE_SSL_CERT_H
+#define NETSURF_EXAMPLE_SSL_CERT_H 1
+
+struct nsurl;
+struct ssl_cert_info;
+
+/**
+ * Prompt the user to verify a certificate with issuse.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ * \return NSERROR_OK or error code if prompt creation failed.
+ */
+nserror example_cert_verify(struct nsurl *url, const struct ssl_cert_info
*certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
+
+#endif
+
+frontends/example/ssl_cert.c
+----------------------------
+
+/*
+ * Copyright 2015 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Implementation of example certificate viewing using example core windows.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "desktop/sslcert_viewer.h"
+
+#include "example/corewindow.h"
+
+
+/**
+ * EXAMPLE certificate viewing window context
+ */
+struct example_crtvrfy_window {
+ /** example core window context */
+ struct example_corewindow core;
+
+ /** SSL certificate viewer context data */
+ struct sslcert_session_data *ssl_data;
+};
+
+/**
+ * destroy a previously created certificate view
+ */
+static nserror example_crtvrfy_destroy(struct example_crtvrfy_window
*crtvrfy_win)
+{
+ nserror res;
+
+ res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+ if (res == NSERROR_OK) {
+ res = example_corewindow_fini(&crtvrfy_win->core);
+ toolkit_windown_destroy(crtvrfy_win->window);
+ free(crtvrfy_win);
+ }
+ return res;
+}
+
+static void
+example_crtvrfy_accept(ExampleButton *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_accept(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+static void
+example_crtvrfy_reject(ExampleWidget *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_reject(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+
+/**
+ * callback for mouse action for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_mouse(struct example_corewindow *example_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
+
+ return NSERROR_OK;
+}
+
+/**
+ * callback for keypress for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_key(struct example_corewindow *example_cw, uint32_t nskey)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
+}
+
+/**
+ * callback on draw event for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_draw(struct example_corewindow *example_cw, struct rect *r)
+{
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &example_plotters
+ };
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx);
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/ssl_cert.h */
+nserror example_cert_verify(struct nsurl *url,
+ const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw),
+ void *cbpw)
+{
+ struct example_crtvrfy_window *ncwin;
+ nserror res;
+
+ ncwin = malloc(sizeof(struct example_crtvrfy_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ res = toolkit_create_window(&ncwin->window);
+ if (res != NSERROR_OK) {
+ LOG("SSL UI builder init failed");
+ free(ncwin);
+ return res;
+ }
+
+ /* store the widget that the toolkit is drawing into */
+ ncwin->core.widget = toolkit_get_widget(ncwin->window,
"SSLDrawingArea"));
+
+ /* would typicaly setup toolkit accept/reject buttons etc. here */
+ toolkit_connect_button_press(ncwin->tk_accept_button,
+ example_crtvrfy_accept,
+ ncwin);
+
+
+ /* initialise example core window */
+ ncwin->core.draw = example_crtvrfy_draw;
+ ncwin->core.key = example_crtvrfy_key;
+ ncwin->core.mouse = example_crtvrfy_mouse;
+
+ res = example_corewindow_init(&ncwin->core);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* initialise certificate viewing interface */
+ res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+ &ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = sslcert_viewer_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ toolkit_widget_show(ncwin->window);
+
+ return NSERROR_OK;
+}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=2adf0a9c44a0ebb0dc9060aa5f3e27f65e21875d
commit 2adf0a9c44a0ebb0dc9060aa5f3e27f65e21875d
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>
clean up documentation of GTK core window interfaces
diff --git a/frontends/gtk/cookies.c b/frontends/gtk/cookies.c
index d0fae97..dc77e1c 100644
--- a/frontends/gtk/cookies.c
+++ b/frontends/gtk/cookies.c
@@ -183,7 +183,7 @@ static void nsgtk_cookies_init_menu(struct
nsgtk_cookie_window *ncwin)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -200,7 +200,7 @@ nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -216,7 +216,7 @@ nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw,
uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
@@ -235,7 +235,7 @@ nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw,
struct rect *r)
/**
* Creates the window for the cookies tree.
*
- * \return NSERROR_OK on success else appropriate error code on faliure.
+ * \return NSERROR_OK on success else appropriate error code on failure.
*/
static nserror nsgtk_cookies_init(void)
{
diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c
index e60f2c4..a992601 100644
--- a/frontends/gtk/corewindow.c
+++ b/frontends/gtk/corewindow.c
@@ -23,7 +23,6 @@
* Provides interface for core renderers to the gtk toolkit drawable area.
* \todo should the interface really be called coredrawable?
*
-
* This module is an object that must be encapsulated. Client users
* should embed a struct nsgtk_corewindow at the beginning of their
* context for this display surface, fill in relevant data and then
@@ -54,6 +53,9 @@
/**
* Convert GDK mouse event to netsurf mouse state
+ *
+ * \param event The GDK mouse event to convert.
+ * \return The netsurf mouse state.
*/
static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
{
@@ -92,12 +94,16 @@ static browser_mouse_state
nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
return ms;
}
+
/**
* gtk event on mouse button press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk event for a mouse button transition to pressed from
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_button_press_event(GtkWidget *widget,
@@ -122,6 +128,17 @@ nsgtk_cw_button_press_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse button release.
+ *
+ * Service gtk event for a mouse button transition from pressed to
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_button_release_event(GtkWidget *widget,
GdkEventButton *event,
@@ -185,9 +202,20 @@ nsgtk_cw_button_release_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse movement.
+ *
+ * Service gtk motion-notify-event for mouse movement above a widget.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The motion event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_motion_notify_event(GtkWidget *widget,
- GdkEventMotion *event, gpointer g)
+ GdkEventMotion *event,
+ gpointer g)
{
struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)g;
struct nsgtk_corewindow_mouse *mouse = &nsgtk_cw->mouse_state;
@@ -265,11 +293,11 @@ nsgtk_cw_motion_notify_event(GtkWidget *widget,
/**
- * Deal with keypress events not handled but input method or callback
+ * Deal with keypress events not handled buy input method or callback
*
* \param nsgtk_cw nsgtk core window key event happened in.
* \param nskey The netsurf keycode of the event.
- * \return NSERROR_OK on sucess otherwise an error code.
+ * \return NSERROR_OK on success otherwise an error code.
*/
static nserror nsgtk_cw_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
@@ -359,9 +387,12 @@ static nserror nsgtk_cw_key(struct nsgtk_corewindow
*nsgtk_cw, uint32_t nskey)
/**
* gtk event on key press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk key-press-event for key transition on a widget from
+ * released to pressed.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
@@ -397,6 +428,16 @@ nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey
*event, gpointer g)
}
+/**
+ * gtk event on key release.
+ *
+ * Service gtk key-release-event for key transition on a widget from
+ * pressed to released.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
{
@@ -406,6 +447,15 @@ nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey
*event, gpointer g)
}
+/**
+ * gtk event handler for input method commit.
+ *
+ * Service gtk commit for input method commit action.
+ *
+ * \param ctx The gtk input method context the event occurred for.
+ * \param str The resulting string from the input method.
+ * \param g The context pointer passed when the event was registered.
+ */
static void
nsgtk_cw_input_method_commit(GtkIMContext *ctx, const gchar *str, gpointer g)
{
@@ -428,7 +478,15 @@ nsgtk_cw_input_method_commit(GtkIMContext *ctx, const
gchar *str, gpointer g)
#if GTK_CHECK_VERSION(3,0,0)
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 3
+ *
+ * \param widget The GTK widget to redraw.
+ * \param cr The cairo drawing context of the widget
+ * \param data The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
{
@@ -458,7 +516,15 @@ nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr,
gpointer data)
#else
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 2
+ *
+ * \param widget The GTK widget to redraw.
+ * \param event The GDK expose event
+ * \param g The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget,
GdkEventExpose *event,
@@ -485,8 +551,12 @@ nsgtk_cw_draw_event(GtkWidget *widget,
#endif
+
/**
- * callback from core to request a redraw
+ * redraw window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs redrawing.
*/
static void
nsgtk_cw_redraw_request(struct core_window *cw, const struct rect *r)
@@ -499,6 +569,13 @@ nsgtk_cw_redraw_request(struct core_window *cw, const
struct rect *r)
}
+/**
+ * update window size core window callback
+ *
+ * \param cw core window handle.
+ * \param width New widget width.
+ * \param height New widget height.
+ */
static void
nsgtk_cw_update_size(struct core_window *cw, int width, int height)
{
@@ -509,6 +586,12 @@ nsgtk_cw_update_size(struct core_window *cw, int width,
int height)
}
+/**
+ * scroll window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs scrolling.
+ */
static void
nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
{
@@ -536,6 +619,13 @@ nsgtk_cw_scroll_visible(struct core_window *cw, const
struct rect *r)
}
+/**
+ * get window size core window callback
+ *
+ * \param cw core window handle.
+ * \param[out] width The width value to update
+ * \param[out] height The height value to update
+ */
static void
nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
{
@@ -554,9 +644,16 @@ nsgtk_cw_get_window_dimensions(struct core_window *cw, int
*width, int *height)
vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled);
g_object_get(vadj, "page-size", &page, NULL);
*height = page;
- }}
+ }
+}
+/**
+ * update window drag status core window callback
+ *
+ * \param cw core window handle.
+ * \param ds The new drag status.
+ */
static void
nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
{
@@ -565,7 +662,10 @@ nsgtk_cw_drag_status(struct core_window *cw,
core_window_drag_status ds)
}
-struct core_window_callback_table nsgtk_cw_cb_table = {
+/**
+ * core window callback table for nsgtk
+ */
+static struct core_window_callback_table nsgtk_cw_cb_table = {
.redraw_request = nsgtk_cw_redraw_request,
.update_size = nsgtk_cw_update_size,
.scroll_visible = nsgtk_cw_scroll_visible,
@@ -626,6 +726,7 @@ nserror nsgtk_corewindow_init(struct nsgtk_corewindow
*nsgtk_cw)
return NSERROR_OK;
}
+/* exported interface documented in gtk/corewindow.h */
nserror nsgtk_corewindow_fini(struct nsgtk_corewindow *nsgtk_cw)
{
g_object_unref(nsgtk_cw->input_method);
diff --git a/frontends/gtk/corewindow.h b/frontends/gtk/corewindow.h
index cfb865e..90bfd61 100644
--- a/frontends/gtk/corewindow.h
+++ b/frontends/gtk/corewindow.h
@@ -58,7 +58,7 @@ struct nsgtk_corewindow {
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
nserror (*draw)(struct nsgtk_corewindow *nsgtk_cw, struct rect *r);
@@ -69,7 +69,7 @@ struct nsgtk_corewindow {
* \param nskey The netsurf key code.
* \return NSERROR_OK if key processed,
* NSERROR_NOT_IMPLEMENTED if key not processed
- * otherwise apropriate error code
+ * otherwise appropriate error code
*/
nserror (*key)(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey);
@@ -80,7 +80,7 @@ struct nsgtk_corewindow {
* \param mouse_state mouse state
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on sucess otherwise apropriate error code.
+ * \return NSERROR_OK on success otherwise appropriate error code.
*/
nserror (*mouse)(struct nsgtk_corewindow *nsgtk_cw, browser_mouse_state
mouse_state, int x, int y);
};
diff --git a/frontends/gtk/ssl_cert.c b/frontends/gtk/ssl_cert.c
index 8270b15..5388f01 100644
--- a/frontends/gtk/ssl_cert.c
+++ b/frontends/gtk/ssl_cert.c
@@ -104,7 +104,7 @@ nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event,
gpointer data)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -125,7 +125,7 @@ nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -146,7 +146,7 @@ nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw,
uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
-----------------------------------------------------------------------
Summary of changes:
Docs/core-window-interface | 575 +++++++++++++++++++++++++++++++++++++++++++-
frontends/gtk/cookies.c | 8 +-
frontends/gtk/corewindow.c | 131 ++++++++--
frontends/gtk/corewindow.h | 6 +-
frontends/gtk/ssl_cert.c | 6 +-
5 files changed, 698 insertions(+), 28 deletions(-)
diff --git a/Docs/core-window-interface b/Docs/core-window-interface
index 0d5f7bc..0267f37 100644
--- a/Docs/core-window-interface
+++ b/Docs/core-window-interface
@@ -77,8 +77,8 @@ event occoured) it must call the corewindoe API wrappers
implementation e.g in the case of ssl certificate viewer
void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
- int x, int y, struct rect *clip,
- const struct redraw_context *ctx);
+ int x, int y, struct rect *clip,
+ const struct redraw_context *ctx);
which will perform the plot operations required to update an area of
the window for that SSL data.
@@ -105,4 +105,573 @@ itself, this is purely the gtk wrapper) is used by
ssl_cert.c which
creates a nsgtk_crtvrfy_window structure containing the
nsgtk_corewindow structure. It attaches actual GTK window handles to
this structure and populates elements of nsgtk_corewindow and then
-calls sslcert_viewer_init() directly.
\ No newline at end of file
+calls sslcert_viewer_init() directly.
+
+frontend skeleton
+-----------------
+
+An example core window implementation for a frontend ssl certficiate
+viewer is presented here. This implements the suggested usage above
+and provides generic corewindow helpers.
+
+
+frontends/example/corewindow.h
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EXAMPLE_COREWINDOW_H
+#define EXAMPLE_COREWINDOW_H
+
+#include "netsurf/core_window.h"
+
+/**
+ * example core window state
+ */
+struct example_corewindow {
+
+
+ /*
+ * Any variables common to any frontend window would go here.
+ * e.g. drawing area handles, toolkit pointers or other state
+ */
+ example_toolkit_widget *tk_widget;
+
+
+
+ /** drag status set by core */
+ core_window_drag_status drag_staus;
+
+ /** table of callbacks for core window operations */
+ struct core_window_callback_table *cb_table;
+
+ /**
+ * callback to draw on drawable area of example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+ nserror (*draw)(struct example_corewindow *example_cw, struct rect *r);
+
+ /**
+ * callback for keypress on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
+ */
+ nserror (*key)(struct example_corewindow *example_cw, uint32_t nskey);
+
+ /**
+ * callback for mouse event on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
+ */
+ nserror (*mouse)(struct example_corewindow *example_cw,
browser_mouse_state mouse_state, int x, int y);
+};
+
+/**
+ * initialise elements of example core window.
+ *
+ * As a pre-requisite the draw, key and mouse callbacks must be defined
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful initialisation otherwise error code.
+ */
+nserror example_corewindow_init(struct example_corewindow *example_cw);
+
+/**
+ * finalise elements of example core window.
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful finalisation otherwise error code.
+ */
+nserror example_corewindow_fini(struct example_corewindow *example_cw);
+
+#endif
+
+frontends/example/corewindow.c
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * EXAMPLE generic core window interface.
+ *
+ * Provides interface for core renderers to the example toolkit drawable area.
+ *
+ * This module is an object that must be encapsulated. Client users
+ * should embed a struct example_corewindow at the beginning of their
+ * context for this display surface, fill in relevant data and then
+ * call example_corewindow_init()
+ *
+ * The example core window structure requires the callback for draw, key and
+ * mouse operations.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+#include "utils/log.h"
+#include "utils/utils.h"
+#include "utils/messages.h"
+#include "utils/utf8.h"
+#include "netsurf/keypress.h"
+#include "netsurf/mouse.h"
+#include "desktop/plot_style.h"
+
+/* extremely likely there will be additional headers required in a real
frontend */
+#include "example/corewindow.h"
+
+
+/* toolkit event handlers that do generic things and call internal callbacks */
+
+
+static bool
+example_cw_mouse_press_event(toolkit_widget *widget, toolkit_button bt, int x,
int y, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)ctx;
+
+ example_cw->mouse(example_cw, state, x, y);
+
+ return true;
+}
+
+static bool
+example_cw_keyrelease_event(toolkit_widget *widget, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)ctx;
+
+ example_cw->key(example_cw, keycode);
+
+ return true;
+}
+
+
+
+/* signal handler for toolkit window redraw */
+static bool
+example_cw_draw_event(toolkit_widget *widget,
+ toolkit_area *tk_area,
+ void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)ctx;
+ struct rect clip;
+
+ clip.x0 = tk_area.x;
+ clip.y0 = tk_area.y;
+ clip.x1 = tk_area.width;
+ clip.y1 = tk_area.height;
+
+ example_cw->draw(example_cw, &clip);
+
+ return true;
+}
+
+
+/**
+ * callback from core to request a redraw
+ */
+static void
+example_cw_redraw_request(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+ toolkit_widget_queue_draw_area(example_cw->widget,
+ r->x0, r->y0,
+ r->x1 - r->x0, r->y1 - r->y0);
+}
+
+
+static void
+example_cw_update_size(struct core_window *cw, int width, int height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+
toolkit_widget_set_size_request(EXAMPLE_WIDGET(example_cw->drawing_area),
+ width, height);
+}
+
+
+static void
+example_cw_scroll_visible(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+ toolkit_scroll_widget(example_cw->widget, r);
+}
+
+
+static void
+example_cw_get_window_dimensions(struct core_window *cw, int *width, int
*height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+
+ *width = toolkit_get_widget_width(example_cw->widget);
+ *height = toolkit_get_widget_height(example_cw->widget);
+}
+
+
+static void
+example_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow
*)cw;
+ example_cw->drag_staus = ds;
+}
+
+
+struct core_window_callback_table example_cw_cb_table = {
+ .redraw_request = example_cw_redraw_request,
+ .update_size = example_cw_update_size,
+ .scroll_visible = example_cw_scroll_visible,
+ .get_window_dimensions = example_cw_get_window_dimensions,
+ .drag_status = example_cw_drag_status
+};
+
+/* exported function documented example/corewindow.h */
+nserror example_corewindow_init(struct example_corewindow *example_cw)
+{
+ /* setup the core window callback table */
+ example_cw->cb_table = &example_cw_cb_table;
+
+ /* frontend toolkit specific method of causing example_cw_draw_event
to be called when a drawing operation is required */
+ toolkit_connect_draw_event(example_cw->tk_widget,
+ example_cw_draw_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_button_press_event to be called when a button press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_button_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_button_release_event to be called when a button release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_button_release_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_motion_notify_event to be called when there is motion over the
widget */
+ toolkit_connect_motion_event(example_cw->tk_widget,
+ example_cw_motion_notify_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_key_press_event to be called when a key press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_key_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing
example_cw_key_release_event to be called when a key release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_key_release_event,
+ example_cw);
+
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/corewindow.h */
+nserror example_corewindow_fini(struct example_corewindow *example_cw)
+{
+ return NSERROR_OK;
+}
+
+
+frontends/example/ssl_cert.h
+----------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_EXAMPLE_SSL_CERT_H
+#define NETSURF_EXAMPLE_SSL_CERT_H 1
+
+struct nsurl;
+struct ssl_cert_info;
+
+/**
+ * Prompt the user to verify a certificate with issuse.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ * \return NSERROR_OK or error code if prompt creation failed.
+ */
+nserror example_cert_verify(struct nsurl *url, const struct ssl_cert_info
*certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
+
+#endif
+
+frontends/example/ssl_cert.c
+----------------------------
+
+/*
+ * Copyright 2015 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Implementation of example certificate viewing using example core windows.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "desktop/sslcert_viewer.h"
+
+#include "example/corewindow.h"
+
+
+/**
+ * EXAMPLE certificate viewing window context
+ */
+struct example_crtvrfy_window {
+ /** example core window context */
+ struct example_corewindow core;
+
+ /** SSL certificate viewer context data */
+ struct sslcert_session_data *ssl_data;
+};
+
+/**
+ * destroy a previously created certificate view
+ */
+static nserror example_crtvrfy_destroy(struct example_crtvrfy_window
*crtvrfy_win)
+{
+ nserror res;
+
+ res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+ if (res == NSERROR_OK) {
+ res = example_corewindow_fini(&crtvrfy_win->core);
+ toolkit_windown_destroy(crtvrfy_win->window);
+ free(crtvrfy_win);
+ }
+ return res;
+}
+
+static void
+example_crtvrfy_accept(ExampleButton *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_accept(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+static void
+example_crtvrfy_reject(ExampleWidget *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_reject(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+
+/**
+ * callback for mouse action for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_mouse(struct example_corewindow *example_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
+
+ return NSERROR_OK;
+}
+
+/**
+ * callback for keypress for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_key(struct example_corewindow *example_cw, uint32_t nskey)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
+}
+
+/**
+ * callback on draw event for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_draw(struct example_corewindow *example_cw, struct rect *r)
+{
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &example_plotters
+ };
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx);
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/ssl_cert.h */
+nserror example_cert_verify(struct nsurl *url,
+ const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw),
+ void *cbpw)
+{
+ struct example_crtvrfy_window *ncwin;
+ nserror res;
+
+ ncwin = malloc(sizeof(struct example_crtvrfy_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ res = toolkit_create_window(&ncwin->window);
+ if (res != NSERROR_OK) {
+ LOG("SSL UI builder init failed");
+ free(ncwin);
+ return res;
+ }
+
+ /* store the widget that the toolkit is drawing into */
+ ncwin->core.widget = toolkit_get_widget(ncwin->window,
"SSLDrawingArea"));
+
+ /* would typicaly setup toolkit accept/reject buttons etc. here */
+ toolkit_connect_button_press(ncwin->tk_accept_button,
+ example_crtvrfy_accept,
+ ncwin);
+
+
+ /* initialise example core window */
+ ncwin->core.draw = example_crtvrfy_draw;
+ ncwin->core.key = example_crtvrfy_key;
+ ncwin->core.mouse = example_crtvrfy_mouse;
+
+ res = example_corewindow_init(&ncwin->core);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* initialise certificate viewing interface */
+ res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+ &ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = sslcert_viewer_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ toolkit_widget_show(ncwin->window);
+
+ return NSERROR_OK;
+}
diff --git a/frontends/gtk/cookies.c b/frontends/gtk/cookies.c
index d0fae97..dc77e1c 100644
--- a/frontends/gtk/cookies.c
+++ b/frontends/gtk/cookies.c
@@ -183,7 +183,7 @@ static void nsgtk_cookies_init_menu(struct
nsgtk_cookie_window *ncwin)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -200,7 +200,7 @@ nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -216,7 +216,7 @@ nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw,
uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
@@ -235,7 +235,7 @@ nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw,
struct rect *r)
/**
* Creates the window for the cookies tree.
*
- * \return NSERROR_OK on success else appropriate error code on faliure.
+ * \return NSERROR_OK on success else appropriate error code on failure.
*/
static nserror nsgtk_cookies_init(void)
{
diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c
index e60f2c4..a992601 100644
--- a/frontends/gtk/corewindow.c
+++ b/frontends/gtk/corewindow.c
@@ -23,7 +23,6 @@
* Provides interface for core renderers to the gtk toolkit drawable area.
* \todo should the interface really be called coredrawable?
*
-
* This module is an object that must be encapsulated. Client users
* should embed a struct nsgtk_corewindow at the beginning of their
* context for this display surface, fill in relevant data and then
@@ -54,6 +53,9 @@
/**
* Convert GDK mouse event to netsurf mouse state
+ *
+ * \param event The GDK mouse event to convert.
+ * \return The netsurf mouse state.
*/
static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
{
@@ -92,12 +94,16 @@ static browser_mouse_state
nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
return ms;
}
+
/**
* gtk event on mouse button press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk event for a mouse button transition to pressed from
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_button_press_event(GtkWidget *widget,
@@ -122,6 +128,17 @@ nsgtk_cw_button_press_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse button release.
+ *
+ * Service gtk event for a mouse button transition from pressed to
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_button_release_event(GtkWidget *widget,
GdkEventButton *event,
@@ -185,9 +202,20 @@ nsgtk_cw_button_release_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse movement.
+ *
+ * Service gtk motion-notify-event for mouse movement above a widget.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The motion event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_motion_notify_event(GtkWidget *widget,
- GdkEventMotion *event, gpointer g)
+ GdkEventMotion *event,
+ gpointer g)
{
struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)g;
struct nsgtk_corewindow_mouse *mouse = &nsgtk_cw->mouse_state;
@@ -265,11 +293,11 @@ nsgtk_cw_motion_notify_event(GtkWidget *widget,
/**
- * Deal with keypress events not handled but input method or callback
+ * Deal with keypress events not handled buy input method or callback
*
* \param nsgtk_cw nsgtk core window key event happened in.
* \param nskey The netsurf keycode of the event.
- * \return NSERROR_OK on sucess otherwise an error code.
+ * \return NSERROR_OK on success otherwise an error code.
*/
static nserror nsgtk_cw_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
@@ -359,9 +387,12 @@ static nserror nsgtk_cw_key(struct nsgtk_corewindow
*nsgtk_cw, uint32_t nskey)
/**
* gtk event on key press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk key-press-event for key transition on a widget from
+ * released to pressed.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
@@ -397,6 +428,16 @@ nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey
*event, gpointer g)
}
+/**
+ * gtk event on key release.
+ *
+ * Service gtk key-release-event for key transition on a widget from
+ * pressed to released.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
{
@@ -406,6 +447,15 @@ nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey
*event, gpointer g)
}
+/**
+ * gtk event handler for input method commit.
+ *
+ * Service gtk commit for input method commit action.
+ *
+ * \param ctx The gtk input method context the event occurred for.
+ * \param str The resulting string from the input method.
+ * \param g The context pointer passed when the event was registered.
+ */
static void
nsgtk_cw_input_method_commit(GtkIMContext *ctx, const gchar *str, gpointer g)
{
@@ -428,7 +478,15 @@ nsgtk_cw_input_method_commit(GtkIMContext *ctx, const
gchar *str, gpointer g)
#if GTK_CHECK_VERSION(3,0,0)
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 3
+ *
+ * \param widget The GTK widget to redraw.
+ * \param cr The cairo drawing context of the widget
+ * \param data The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
{
@@ -458,7 +516,15 @@ nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr,
gpointer data)
#else
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 2
+ *
+ * \param widget The GTK widget to redraw.
+ * \param event The GDK expose event
+ * \param g The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget,
GdkEventExpose *event,
@@ -485,8 +551,12 @@ nsgtk_cw_draw_event(GtkWidget *widget,
#endif
+
/**
- * callback from core to request a redraw
+ * redraw window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs redrawing.
*/
static void
nsgtk_cw_redraw_request(struct core_window *cw, const struct rect *r)
@@ -499,6 +569,13 @@ nsgtk_cw_redraw_request(struct core_window *cw, const
struct rect *r)
}
+/**
+ * update window size core window callback
+ *
+ * \param cw core window handle.
+ * \param width New widget width.
+ * \param height New widget height.
+ */
static void
nsgtk_cw_update_size(struct core_window *cw, int width, int height)
{
@@ -509,6 +586,12 @@ nsgtk_cw_update_size(struct core_window *cw, int width,
int height)
}
+/**
+ * scroll window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs scrolling.
+ */
static void
nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
{
@@ -536,6 +619,13 @@ nsgtk_cw_scroll_visible(struct core_window *cw, const
struct rect *r)
}
+/**
+ * get window size core window callback
+ *
+ * \param cw core window handle.
+ * \param[out] width The width value to update
+ * \param[out] height The height value to update
+ */
static void
nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
{
@@ -554,9 +644,16 @@ nsgtk_cw_get_window_dimensions(struct core_window *cw, int
*width, int *height)
vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled);
g_object_get(vadj, "page-size", &page, NULL);
*height = page;
- }}
+ }
+}
+/**
+ * update window drag status core window callback
+ *
+ * \param cw core window handle.
+ * \param ds The new drag status.
+ */
static void
nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
{
@@ -565,7 +662,10 @@ nsgtk_cw_drag_status(struct core_window *cw,
core_window_drag_status ds)
}
-struct core_window_callback_table nsgtk_cw_cb_table = {
+/**
+ * core window callback table for nsgtk
+ */
+static struct core_window_callback_table nsgtk_cw_cb_table = {
.redraw_request = nsgtk_cw_redraw_request,
.update_size = nsgtk_cw_update_size,
.scroll_visible = nsgtk_cw_scroll_visible,
@@ -626,6 +726,7 @@ nserror nsgtk_corewindow_init(struct nsgtk_corewindow
*nsgtk_cw)
return NSERROR_OK;
}
+/* exported interface documented in gtk/corewindow.h */
nserror nsgtk_corewindow_fini(struct nsgtk_corewindow *nsgtk_cw)
{
g_object_unref(nsgtk_cw->input_method);
diff --git a/frontends/gtk/corewindow.h b/frontends/gtk/corewindow.h
index cfb865e..90bfd61 100644
--- a/frontends/gtk/corewindow.h
+++ b/frontends/gtk/corewindow.h
@@ -58,7 +58,7 @@ struct nsgtk_corewindow {
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
nserror (*draw)(struct nsgtk_corewindow *nsgtk_cw, struct rect *r);
@@ -69,7 +69,7 @@ struct nsgtk_corewindow {
* \param nskey The netsurf key code.
* \return NSERROR_OK if key processed,
* NSERROR_NOT_IMPLEMENTED if key not processed
- * otherwise apropriate error code
+ * otherwise appropriate error code
*/
nserror (*key)(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey);
@@ -80,7 +80,7 @@ struct nsgtk_corewindow {
* \param mouse_state mouse state
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on sucess otherwise apropriate error code.
+ * \return NSERROR_OK on success otherwise appropriate error code.
*/
nserror (*mouse)(struct nsgtk_corewindow *nsgtk_cw, browser_mouse_state
mouse_state, int x, int y);
};
diff --git a/frontends/gtk/ssl_cert.c b/frontends/gtk/ssl_cert.c
index 8270b15..5388f01 100644
--- a/frontends/gtk/ssl_cert.c
+++ b/frontends/gtk/ssl_cert.c
@@ -104,7 +104,7 @@ nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event,
gpointer data)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -125,7 +125,7 @@ nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -146,7 +146,7 @@ nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw,
uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org