move remaining gui operations to table

This commit is contained in:
Vincent Sanders 2014-01-14 23:31:54 +00:00
parent 667d4a0a49
commit 0075eab194
21 changed files with 280 additions and 204 deletions

View File

@ -27,6 +27,9 @@ struct gui_window;
struct gui_window_2;
void gui_start_selection(struct gui_window *g);
void gui_get_clipboard(char **buffer, size_t *length);
void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles);
void ami_clipboard_init(void);
void ami_clipboard_free(void);

View File

@ -27,4 +27,7 @@ void ami_context_menu_free(void);
BOOL ami_context_menu_mouse_trap(struct gui_window_2 *gwin, BOOL trap);
void ami_context_menu_show(struct gui_window_2 *gwin, int x, int y);
void ami_context_menu_show_tree(struct tree *tree, struct Window *win, int type);
void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control);
#endif

View File

@ -624,7 +624,7 @@ void ami_amiupdate(void)
}
}
nsurl *gui_get_resource_url(const char *path)
static nsurl *gui_get_resource_url(const char *path)
{
char buf[1024];
char path2[1024];
@ -5122,6 +5122,12 @@ static struct gui_table ami_gui_table = {
.poll = gui_poll,
.quit = gui_quit,
.set_search_ico = gui_set_search_ico,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.get_clipboard = gui_get_clipboard,
.set_clipboard = gui_set_clipboard,
.cert_verify = gui_cert_verify,
.window = &ami_window_table,
};

View File

@ -25,4 +25,7 @@
void ami_openurl_open(void);
void ami_openurl_close(void);
void gui_launch_url(const char *url);
#endif

View File

@ -19,5 +19,9 @@
#ifndef AMIGA_SSLCERT_H
#define AMIGA_SSLCERT_H
void gui_cert_verify(nsurl *url,
const struct ssl_cert_info *certs, unsigned long num,
nserror (*cb)(bool proceed, void *pw), void *cbpw);
void ami_ssl_free(struct treeview_window *twin);
#endif

View File

@ -659,7 +659,7 @@ static void gui_window_new_content(struct gui_window *w)
* \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
* \param length Byte length of UTF-8 text in buffer
*/
void gui_get_clipboard(char **buffer, size_t *length)
static void gui_get_clipboard(char **buffer, size_t *length)
{
char *clip;
size_t clip_len;
@ -701,7 +701,7 @@ void gui_get_clipboard(char **buffer, size_t *length)
* \param styles Array of styles given to text runs, owned by core, or NULL
* \param n_styles Number of text run styles in array
*/
void gui_set_clipboard(const char *buffer, size_t length,
static void gui_set_clipboard(const char *buffer, size_t length,
nsclipboard_styles styles[], int n_styles)
{
if (length > 0 && buffer != NULL) {
@ -721,22 +721,6 @@ void gui_set_clipboard(const char *buffer, size_t length,
}
}
void gui_create_form_select_menu(struct browser_window *bw,
struct form_control *control)
{
TODO();
}
/**
* Broadcast an URL that we can't handle.
*/
void gui_launch_url(const char *url)
{
TODO();
LOG(("launch file: %s\n", url));
}
void gui_401login_open(nsurl *url, const char *realm,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
@ -756,7 +740,7 @@ void gui_401login_open(nsurl *url, const char *realm,
}
void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
unsigned long num, nserror (*cb)(bool proceed, void *pw),
void *cbpw)
{
@ -913,7 +897,7 @@ static inline void create_cursor(int flags, short mode, void * form,
}
}
nsurl *gui_get_resource_url(const char *path)
static nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
char *raw;
@ -1064,6 +1048,10 @@ static struct gui_window_table atari_window_table = {
static struct gui_table atari_gui_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.get_clipboard = gui_get_clipboard,
.set_clipboard = gui_set_clipboard,
.cert_verify = gui_cert_verify,
.window = &atari_window_table;
};

View File

@ -42,6 +42,7 @@
#include "content/fetchers/resource.h"
#include "content/urldb.h"
#include "desktop/gui.h"
#include "desktop/gui_factory.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
@ -206,7 +207,7 @@ static bool fetch_resource_initialise(lwc_string *scheme)
}
}
e->url = gui_get_resource_url(fetch_resource_paths[i]);
e->url = guit->get_resource_url(fetch_resource_paths[i]);
if (e->url == NULL) {
lwc_string_unref(e->path);
} else {

View File

@ -814,7 +814,7 @@ browser_window_download(struct browser_window *bw,
NULL, NULL, &l);
if (error == NSERROR_NO_FETCH_HANDLER) {
/* no internal handler for this type, call out to frontend */
gui_launch_url(nsurl_access(url));
guit->launch_url(nsurl_access(url));
} else if (error != NSERROR_OK) {
LOG(("Failed to fetch download: %d", error));
} else {
@ -1873,7 +1873,7 @@ nserror browser_window_navigate(struct browser_window *bw,
case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */
/** @todo does this always try and download even unverifiable content? */
gui_launch_url(nsurl_access(url));
guit->launch_url(nsurl_access(url));
break;
default: /* report error to user */

View File

@ -280,7 +280,8 @@ struct gui_table {
/* Mandantory entries */
/** called to let the frontend update its state and run any
/**
* called to let the frontend update its state and run any
* I/O operations.
*/
void (*poll)(bool active);
@ -299,56 +300,58 @@ struct gui_table {
* cache from search_web_ico()
*/
void (*set_search_ico)(hlcache_handle *ico);
/**
* Callback to translate resource to full url.
*
* Transforms a resource: path into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
* the returned nsurl including unrefing it when finished with it.
*
* \param path The path of the resource to locate.
* \return A string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
nsurl* (*get_resource_url)(const char *path);
/**
* core has no fetcher for url
*/
void (*launch_url)(const char *url);
/**
* create a form select menu
*/
void (*create_form_select_menu)(struct browser_window *bw, struct form_control *control);
/**
* Core asks front end for clipboard contents.
*
* \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
* \param length Byte length of UTF-8 text in buffer
*/
void (*get_clipboard)(char **buffer, size_t *length);
/**
* Core tells front end to put given text in clipboard
*
* \param buffer UTF-8 text, owned by core
* \param length Byte length of UTF-8 text in buffer
* \param styles Array of styles given to text runs, owned by core, or NULL
* \param n_styles Number of text run styles in array
*/
void (*set_clipboard)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles);
/**
* verify certificate
*/
void (*cert_verify)(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
};
/**
* Callback to translate resource to full url.
*
* Transforms a resource: path into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
* the returned nsurl including unrefing it when finished with it.
*
* \param path The path of the resource to locate.
* \return A string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
nsurl* gui_get_resource_url(const char *path);
void gui_launch_url(const char *url);
void gui_create_form_select_menu(struct browser_window *bw,
struct form_control *control);
/**
* Core asks front end for clipboard contents.
*
* \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
* \param length Byte length of UTF-8 text in buffer
*/
void gui_get_clipboard(char **buffer, size_t *length);
/**
* Core tells front end to put given text in clipboard
*
* \param buffer UTF-8 text, owned by core
* \param length Byte length of UTF-8 text in buffer
* \param styles Array of styles given to text runs, owned by core, or NULL
* \param n_styles Number of text run styles in array
*/
void gui_set_clipboard(const char *buffer, size_t length,
nsclipboard_styles styles[], int n_styles);
void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
unsigned long num, nserror (*cb)(bool proceed, void *pw),
void *cbpw);
#endif

View File

@ -256,6 +256,40 @@ static void gui_default_set_search_ico(hlcache_handle *ico)
{
}
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
}
static void gui_default_launch_url(const char *url)
{
}
static void gui_default_create_form_select_menu(struct browser_window *bw,
struct form_control *control)
{
}
static void gui_default_get_clipboard(char **buffer, size_t *length)
{
*buffer = NULL;
*length = 0;
}
static void gui_default_set_clipboard(const char *buffer, size_t length,
nsclipboard_styles styles[], int n_styles)
{
}
static void gui_default_cert_verify(nsurl *url,
const struct ssl_cert_info *certs,
unsigned long num,
nserror (*cb)(bool proceed, void *pw),
void *cbpw)
{
cb(false, cbpw);
}
nserror gui_factory_register(struct gui_table *gt)
{
nserror err;
@ -296,6 +330,24 @@ nserror gui_factory_register(struct gui_table *gt)
if (gt->set_search_ico == NULL) {
gt->set_search_ico = gui_default_set_search_ico;
}
if (gt->get_resource_url == NULL) {
gt->get_resource_url = gui_default_get_resource_url;
}
if (gt->launch_url == NULL) {
gt->launch_url = gui_default_launch_url;
}
if (gt->create_form_select_menu == NULL) {
gt->create_form_select_menu = gui_default_create_form_select_menu;
}
if (gt->get_clipboard == NULL) {
gt->get_clipboard = gui_default_get_clipboard;
}
if (gt->set_clipboard == NULL) {
gt->set_clipboard = gui_default_set_clipboard;
}
if (gt->cert_verify == NULL) {
gt->cert_verify = gui_default_cert_verify;
}
guit = gt;

View File

@ -103,7 +103,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query,
/* For now, do nothing, as this query type isn't emitted yet */
break;
case LLCACHE_QUERY_SSL:
gui_cert_verify(query->url, query->data.ssl.certs,
guit->cert_verify(query->url, query->data.ssl.certs,
query->data.ssl.num, cb, cbpw);
break;
}

View File

@ -1417,7 +1417,7 @@ static bool textarea_replace_text_internal(struct textarea *ta, size_t b_start,
/* Place CUTs on clipboard */
if (add_to_clipboard) {
gui_set_clipboard(ta->show->data + b_start, b_end - b_start,
guit->set_clipboard(ta->show->data + b_start, b_end - b_start,
NULL, 0);
}
@ -2484,7 +2484,7 @@ bool textarea_keypress(struct textarea *ta, uint32_t key)
if (readonly)
break;
gui_get_clipboard(&clipboard, &clipboard_length);
guit->get_clipboard(&clipboard, &clipboard_length);
if (clipboard == NULL)
return false;

View File

@ -26,6 +26,7 @@
#include "desktop/browser.h"
#include "desktop/gui.h"
#include "framebuffer/gui.h"
#include "framebuffer/clipboard.h"
#include "utils/log.h"
@ -36,8 +37,6 @@ static struct gui_clipboard {
} gui_clipboard;
/**
* Core asks front end for clipboard contents.
*

26
framebuffer/clipboard.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
*
* 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_FB_CLIPBOARD_H
#define NETSURF_FB_CLIPBOARD_H
void gui_get_clipboard(char **buffer, size_t *length);
void gui_set_clipboard(const char *buffer, size_t length,
nsclipboard_styles styles[], int n_styles);
#endif

View File

@ -29,4 +29,6 @@ extern char **respaths;
*/
char **fb_init_resource(const char *resource_path);
nsurl *gui_get_resource_url(const char *path);
#endif /* NETSURF_FB_FINDFILE_H */

View File

@ -54,6 +54,7 @@
#include "framebuffer/findfile.h"
#include "framebuffer/image_data.h"
#include "framebuffer/font.h"
#include "framebuffer/clipboard.h"
#include "content/urldb.h"
#include "desktop/local_history.h"
@ -1767,27 +1768,6 @@ gui_window_remove_caret(struct gui_window *g)
}
void
gui_create_form_select_menu(struct browser_window *bw,
struct form_control *control)
{
}
void
gui_launch_url(const char *url)
{
}
void
gui_cert_verify(nsurl *url,
const struct ssl_cert_info *certs,
unsigned long num,
nserror (*cb)(bool proceed, void *pw),
void *cbpw)
{
cb(false, cbpw);
}
static struct gui_window_table framebuffer_gui_window_table = {
.create = gui_window_create,
.destroy = gui_window_destroy,
@ -1810,6 +1790,9 @@ static struct gui_window_table framebuffer_gui_window_table = {
static struct gui_table framebuffer_gui_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.get_clipboard = gui_get_clipboard,
.set_clipboard = gui_set_clipboard,
.window = &framebuffer_gui_window_table,
};

View File

@ -30,6 +30,7 @@
#include "content/content.h"
#include "desktop/browser.h"
#include "desktop/gui_factory.h"
#include "desktop/frames.h"
#include "desktop/mouse.h"
#include "utils/nsoption.h"
@ -654,7 +655,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
c);
pointer = BROWSER_POINTER_DEFAULT;
} else if (mouse & BROWSER_MOUSE_CLICK_1)
gui_create_form_select_menu(bw, gadget);
guit->create_form_select_menu(bw, gadget);
break;
case GADGET_CHECKBOX:
status = messages_get("FormCheckbox");

View File

@ -252,7 +252,7 @@ static void ro_msg_save_desktop(wimp_message *message);
static void ro_msg_window_info(wimp_message *message);
static void ro_gui_view_source_bounce(wimp_message *message);
nsurl *gui_get_resource_url(const char *path)
static nsurl *gui_get_resource_url(const char *path)
{
static const char base_url[] = "file:///NetSurf:/Resources/";
size_t path_len, length;
@ -837,91 +837,6 @@ static bool nslog_stream_configure(FILE *fptr)
return true;
}
static struct gui_table riscos_gui_table = {
.poll = gui_poll,
.quit = gui_quit,
};
/** Normal entry point from OS */
int main(int argc, char** argv)
{
char path[40];
int length;
char logging_env[2];
os_var_type type;
int used = -1; /* slightly better with older OSLib versions */
os_error *error;
nserror ret;
/* Consult NetSurf$Logging environment variable to decide if logging
* is required. */
error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING,
&used, NULL, &type);
if (error != NULL || type != os_VARTYPE_STRING || used != -2) {
verbose_log = true;
} else {
error = xos_read_var_val("NetSurf$Logging", logging_env,
sizeof(logging_env), 0, os_VARTYPE_STRING,
&used, NULL, &type);
if (error != NULL || logging_env[0] != '0') {
verbose_log = true;
} else {
verbose_log = false;
}
}
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
/* user options setup */
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
if (ret != NSERROR_OK) {
die("Options failed to initialise");
}
nsoption_read("NetSurf:Choices", NULL);
nsoption_commandline(&argc, argv, NULL);
/* Choose the interface language to use */
ro_gui_choose_language();
/* select language-specific Messages */
if (((length = snprintf(path,
sizeof(path),
"NetSurf:Resources.%s.Messages",
nsoption_charp(language))) < 0) ||
(length >= (int)sizeof(path))) {
die("Failed to locate Messages resource.");
}
/* common initialisation */
riscos_gui_table.window = riscos_gui_window_table;
riscos_gui_table.download = riscos_gui_download_table;
ret = netsurf_init(path, &riscos_gui_table);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
artworks_init();
draw_init();
sprite_init();
/* Load some extra RISC OS specific Messages */
messages_load("NetSurf:Resources.LangNames");
gui_init(argc, argv);
gui_init2(argc, argv);
netsurf_main_loop();
netsurf_exit();
return 0;
}
/**
@ -2272,7 +2187,7 @@ void ro_gui_dump_browser_window(struct browser_window *bw)
* Broadcast an URL that we can't handle.
*/
void gui_launch_url(const char *url)
static void gui_launch_url(const char *url)
{
/* Try ant broadcast first */
ro_url_broadcast(url);
@ -2433,3 +2348,94 @@ bool path_add_part(char *path, int length, const char *newpart)
return true;
}
static struct gui_table riscos_gui_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.get_clipboard = gui_get_clipboard,
.set_clipboard = gui_set_clipboard,
.cert_verify = gui_cert_verify,
};
/** Normal entry point from OS */
int main(int argc, char** argv)
{
char path[40];
int length;
char logging_env[2];
os_var_type type;
int used = -1; /* slightly better with older OSLib versions */
os_error *error;
nserror ret;
/* Consult NetSurf$Logging environment variable to decide if logging
* is required. */
error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING,
&used, NULL, &type);
if (error != NULL || type != os_VARTYPE_STRING || used != -2) {
verbose_log = true;
} else {
error = xos_read_var_val("NetSurf$Logging", logging_env,
sizeof(logging_env), 0, os_VARTYPE_STRING,
&used, NULL, &type);
if (error != NULL || logging_env[0] != '0') {
verbose_log = true;
} else {
verbose_log = false;
}
}
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
/* user options setup */
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
if (ret != NSERROR_OK) {
die("Options failed to initialise");
}
nsoption_read("NetSurf:Choices", NULL);
nsoption_commandline(&argc, argv, NULL);
/* Choose the interface language to use */
ro_gui_choose_language();
/* select language-specific Messages */
if (((length = snprintf(path,
sizeof(path),
"NetSurf:Resources.%s.Messages",
nsoption_charp(language))) < 0) ||
(length >= (int)sizeof(path))) {
die("Failed to locate Messages resource.");
}
/* common initialisation */
riscos_gui_table.window = riscos_gui_window_table;
riscos_gui_table.download = riscos_gui_download_table;
ret = netsurf_init(path, &riscos_gui_table);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
artworks_init();
draw_init();
sprite_init();
/* Load some extra RISC OS specific Messages */
messages_load("NetSurf:Resources.LangNames");
gui_init(argc, argv);
gui_init2(argc, argv);
netsurf_main_loop();
netsurf_exit();
return 0;
}

View File

@ -156,6 +156,7 @@ bool ro_gui_shift_pressed(void);
bool ro_gui_ctrl_pressed(void);
bool ro_gui_alt_pressed(void);
void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape);
void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control);
/* in history.c */
void ro_gui_history_init(void);
@ -201,6 +202,15 @@ extern int ro_plot_origin_y;
/* in theme_install.c */
bool ro_gui_theme_install_apply(wimp_w w);
/* in textselection.c */
void gui_get_clipboard(char **buffer, size_t *length);
void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles);
/* in sslcert.c */
void gui_cert_verify(nsurl *url,
const struct ssl_cert_info *certs, unsigned long num,
nserror (*cb)(bool proceed, void *pw), void *cbpw);
/* icon numbers */
#define ICON_STATUS_RESIZE 0
#define ICON_STATUS_TEXT 1

View File

@ -1729,7 +1729,7 @@ static void gui_window_remove_caret(struct gui_window *w)
* \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
* \param length Byte length of UTF-8 text in buffer
*/
void gui_get_clipboard(char **buffer, size_t *length)
static void gui_get_clipboard(char **buffer, size_t *length)
{
/* TODO: Implement this */
HANDLE clipboard_handle;
@ -1751,7 +1751,7 @@ void gui_get_clipboard(char **buffer, size_t *length)
* \param styles Array of styles given to text runs, owned by core, or NULL
* \param n_styles Number of text run styles in array
*/
void gui_set_clipboard(const char *buffer, size_t length,
static void gui_set_clipboard(const char *buffer, size_t length,
nsclipboard_styles styles[], int n_styles)
{
/* TODO: Implement this */
@ -1777,19 +1777,6 @@ void gui_set_clipboard(const char *buffer, size_t length,
}
void gui_create_form_select_menu(struct browser_window *bw,
struct form_control *control)
{
}
void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
unsigned long num,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
cb(false, cbpw);
}
/**
* Create the main window class.
*/
@ -1844,6 +1831,8 @@ static struct gui_window_table win32_window_table = {
static struct gui_table gui_table = {
.poll = gui_poll,
.get_clipboard = gui_get_clipboard,
.set_clipboard = gui_set_clipboard,
.window = &win32_window_table,
};

View File

@ -41,7 +41,7 @@ static char **respaths; /** resource search path vector. */
char *options_file_location;
nsurl *gui_get_resource_url(const char *path)
static nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
char *raw;
@ -56,10 +56,6 @@ nsurl *gui_get_resource_url(const char *path)
return url;
}
void gui_launch_url(const char *url)
{
}
/**
* Ensures output logging stream is available
*/
@ -156,6 +152,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
messages = filepath_find(respaths, "messages");
win32_gui_table->download = nsgtk_gui_download_table;
win32_gui_table->get_resource_url = get_resource_url;
ret = netsurf_init(messages, win32_gui_table);
free(messages);