2015-04-12 19:55:46 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Implementation of gtk certificate viewing using gtk core windows.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2015-04-12 19:55:46 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "utils/log.h"
|
2020-03-11 11:32:52 +03:00
|
|
|
#include "utils/messages.h"
|
2016-07-31 14:19:37 +03:00
|
|
|
#include "netsurf/keypress.h"
|
|
|
|
#include "netsurf/plotters.h"
|
2020-05-08 22:42:49 +03:00
|
|
|
#include "netsurf/misc.h"
|
2019-12-01 19:20:42 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2020-02-24 23:46:11 +03:00
|
|
|
#include "desktop/page-info.h"
|
2020-05-08 22:42:49 +03:00
|
|
|
#include "desktop/gui_internal.h"
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
#include "gtk/plotters.h"
|
2015-04-12 19:55:46 +03:00
|
|
|
#include "gtk/scaffolding.h"
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "gtk/resources.h"
|
2019-12-01 19:20:42 +03:00
|
|
|
#include "gtk/page_info.h"
|
2016-07-31 14:19:37 +03:00
|
|
|
#include "gtk/corewindow.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GTK certificate viewing window context
|
|
|
|
*/
|
2020-02-23 20:25:04 +03:00
|
|
|
struct nsgtk_pi_window {
|
2016-07-31 14:19:37 +03:00
|
|
|
/** GTK core window context */
|
|
|
|
struct nsgtk_corewindow core;
|
|
|
|
/** GTK builder for window */
|
|
|
|
GtkBuilder *builder;
|
2020-03-11 11:32:52 +03:00
|
|
|
/** GTK window being shown */
|
|
|
|
GtkWindow *dlg;
|
2020-02-24 23:46:11 +03:00
|
|
|
/** Core page-info window */
|
|
|
|
struct page_info *pi;
|
2016-07-31 14:19:37 +03:00
|
|
|
};
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2020-02-23 19:06:52 +03:00
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
/**
|
2020-03-11 11:32:52 +03:00
|
|
|
* destroy a previously created page information window
|
2016-07-31 14:19:37 +03:00
|
|
|
*/
|
2020-03-11 11:32:52 +03:00
|
|
|
static gboolean
|
|
|
|
nsgtk_pi_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
|
2016-07-31 14:19:37 +03:00
|
|
|
{
|
2020-03-11 11:32:52 +03:00
|
|
|
struct nsgtk_pi_window *pi_win;
|
|
|
|
pi_win = (struct nsgtk_pi_window *)data;
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2020-02-24 23:46:11 +03:00
|
|
|
page_info_destroy(pi_win->pi);
|
2020-03-11 11:32:52 +03:00
|
|
|
|
|
|
|
nsgtk_corewindow_fini(&pi_win->core);
|
2020-02-24 23:46:11 +03:00
|
|
|
gtk_widget_destroy(GTK_WIDGET(pi_win->dlg));
|
|
|
|
g_object_unref(G_OBJECT(pi_win->builder));
|
|
|
|
free(pi_win);
|
|
|
|
|
2015-04-12 19:55:46 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-08 22:42:49 +03:00
|
|
|
/**
|
|
|
|
* Called to cause the page-info window to close cleanly
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nsgtk_pi_close_callback(void *pw)
|
|
|
|
{
|
|
|
|
nsgtk_pi_delete_event(NULL, NULL, pw);
|
|
|
|
}
|
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
/**
|
|
|
|
* callback for mouse action for certificate verify on core window
|
|
|
|
*
|
|
|
|
* \param nsgtk_cw The nsgtk core window structure.
|
|
|
|
* \param mouse_state netsurf mouse state on event
|
|
|
|
* \param x location of event
|
|
|
|
* \param y location of event
|
2016-10-26 15:58:51 +03:00
|
|
|
* \return NSERROR_OK on success otherwise appropriate error code
|
2016-07-31 14:19:37 +03:00
|
|
|
*/
|
|
|
|
static nserror
|
2020-02-23 20:25:04 +03:00
|
|
|
nsgtk_pi_mouse(struct nsgtk_corewindow *nsgtk_cw,
|
2016-07-31 14:19:37 +03:00
|
|
|
browser_mouse_state mouse_state,
|
|
|
|
int x, int y)
|
|
|
|
{
|
2020-02-23 20:25:04 +03:00
|
|
|
struct nsgtk_pi_window *pi_win;
|
2020-05-08 22:42:49 +03:00
|
|
|
bool did_something = false;
|
2016-07-31 14:19:37 +03:00
|
|
|
/* technically degenerate container of */
|
2020-02-23 20:25:04 +03:00
|
|
|
pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
|
2016-07-31 14:19:37 +03:00
|
|
|
|
2020-05-08 22:42:49 +03:00
|
|
|
if (page_info_mouse_action(pi_win->pi, mouse_state, x, y, &did_something) == NSERROR_OK) {
|
|
|
|
if (did_something == true) {
|
|
|
|
/* Something happened so we need to close ourselves */
|
|
|
|
guit->misc->schedule(0, nsgtk_pi_close_callback, pi_win);
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 14:19:37 +03:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* callback for keypress for certificate verify on core window
|
|
|
|
*
|
|
|
|
* \param nsgtk_cw The nsgtk core window structure.
|
|
|
|
* \param nskey The netsurf key code
|
2016-10-26 15:58:51 +03:00
|
|
|
* \return NSERROR_OK on success otherwise appropriate error code
|
2016-07-31 14:19:37 +03:00
|
|
|
*/
|
|
|
|
static nserror
|
2020-02-23 20:25:04 +03:00
|
|
|
nsgtk_pi_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
|
2015-04-12 19:55:46 +03:00
|
|
|
{
|
2020-02-23 20:25:04 +03:00
|
|
|
struct nsgtk_pi_window *pi_win;
|
2016-07-31 14:19:37 +03:00
|
|
|
|
|
|
|
/* technically degenerate container of */
|
2020-02-23 20:25:04 +03:00
|
|
|
pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
|
2016-07-31 14:19:37 +03:00
|
|
|
|
2020-02-24 23:46:11 +03:00
|
|
|
if (page_info_keypress(pi_win->pi, nskey)) {
|
2016-07-31 14:19:37 +03:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
return NSERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* callback on draw event for certificate verify on core window
|
|
|
|
*
|
|
|
|
* \param nsgtk_cw The nsgtk core window structure.
|
|
|
|
* \param r The rectangle of the window that needs updating.
|
2016-10-26 15:58:51 +03:00
|
|
|
* \return NSERROR_OK on success otherwise appropriate error code
|
2016-07-31 14:19:37 +03:00
|
|
|
*/
|
|
|
|
static nserror
|
2020-02-23 20:25:04 +03:00
|
|
|
nsgtk_pi_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
|
2016-07-31 14:19:37 +03:00
|
|
|
{
|
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.background_images = true,
|
|
|
|
.plot = &nsgtk_plotters
|
|
|
|
};
|
2020-02-23 20:25:04 +03:00
|
|
|
struct nsgtk_pi_window *pi_win;
|
2016-07-31 14:19:37 +03:00
|
|
|
|
|
|
|
/* technically degenerate container of */
|
2020-02-23 20:25:04 +03:00
|
|
|
pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
|
2016-07-31 14:19:37 +03:00
|
|
|
|
2020-02-24 23:46:11 +03:00
|
|
|
page_info_redraw(pi_win->pi, 0, 0, r, &ctx);
|
2016-07-31 14:19:37 +03:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-01 19:20:42 +03:00
|
|
|
/* exported interface documented in gtk/page_info.h */
|
|
|
|
nserror nsgtk_page_info(struct browser_window *bw)
|
2016-07-31 14:19:37 +03:00
|
|
|
{
|
2020-02-23 20:25:04 +03:00
|
|
|
struct nsgtk_pi_window *ncwin;
|
2015-06-13 13:31:23 +03:00
|
|
|
nserror res;
|
2020-05-08 22:42:49 +03:00
|
|
|
GtkWindow *scaffwin = nsgtk_scaffolding_window(nsgtk_current_scaffolding());
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2020-03-11 11:32:52 +03:00
|
|
|
ncwin = calloc(1, sizeof(struct nsgtk_pi_window));
|
2016-07-31 14:19:37 +03:00
|
|
|
if (ncwin == NULL) {
|
2016-07-31 03:24:57 +03:00
|
|
|
return NSERROR_NOMEM;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 11:32:52 +03:00
|
|
|
res = nsgtk_builder_new_from_resname("pageinfo", &ncwin->builder);
|
2015-06-13 13:31:23 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2020-03-11 11:32:52 +03:00
|
|
|
NSLOG(netsurf, CRITICAL, "Page Info UI builder init failed %s", messages_get_errorcode(res));
|
2016-07-31 14:19:37 +03:00
|
|
|
free(ncwin);
|
|
|
|
return res;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
gtk_builder_connect_signals(ncwin->builder, NULL);
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2020-03-11 11:32:52 +03:00
|
|
|
ncwin->dlg = GTK_WINDOW(gtk_builder_get_object(ncwin->builder,
|
|
|
|
"PGIWindow"));
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2020-05-08 22:42:49 +03:00
|
|
|
/* Configure for transient behaviour */
|
|
|
|
gtk_window_set_type_hint(GTK_WINDOW(ncwin->dlg),
|
|
|
|
GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
|
|
|
|
|
|
|
|
gtk_window_set_modal(GTK_WINDOW(ncwin->dlg), TRUE);
|
|
|
|
|
|
|
|
gtk_window_group_add_window(gtk_window_get_group(scaffwin),
|
|
|
|
GTK_WINDOW(ncwin->dlg));
|
|
|
|
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(ncwin->dlg), scaffwin);
|
|
|
|
|
|
|
|
gtk_window_set_screen(GTK_WINDOW(ncwin->dlg),
|
|
|
|
gtk_widget_get_screen(GTK_WIDGET(scaffwin)));
|
2016-07-31 14:19:37 +03:00
|
|
|
|
2020-05-08 22:46:37 +03:00
|
|
|
/* Attempt to place the window in the right place */
|
|
|
|
nsgtk_scaffolding_position_page_info(nsgtk_current_scaffolding(),
|
|
|
|
ncwin);
|
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
ncwin->core.drawing_area = GTK_DRAWING_AREA(
|
2020-03-11 11:32:52 +03:00
|
|
|
gtk_builder_get_object(ncwin->builder, "PGIDrawingArea"));
|
2016-07-31 14:19:37 +03:00
|
|
|
|
|
|
|
/* make the delete event call our destructor */
|
|
|
|
g_signal_connect(G_OBJECT(ncwin->dlg),
|
|
|
|
"delete_event",
|
2020-02-23 20:25:04 +03:00
|
|
|
G_CALLBACK(nsgtk_pi_delete_event),
|
2016-07-31 14:19:37 +03:00
|
|
|
ncwin);
|
2020-05-08 22:42:49 +03:00
|
|
|
/* Ditto if we lose the grab */
|
|
|
|
g_signal_connect(G_OBJECT(ncwin->dlg),
|
|
|
|
"grab-broken-event",
|
|
|
|
G_CALLBACK(nsgtk_pi_delete_event),
|
|
|
|
ncwin);
|
|
|
|
/* Handle button press events */
|
|
|
|
g_signal_connect(G_OBJECT(ncwin->dlg),
|
|
|
|
"button-press-event",
|
|
|
|
G_CALLBACK(nsgtk_pi_delete_event),
|
|
|
|
ncwin);
|
2016-07-31 14:19:37 +03:00
|
|
|
|
|
|
|
/* initialise GTK core window */
|
2020-02-23 20:25:04 +03:00
|
|
|
ncwin->core.draw = nsgtk_pi_draw;
|
|
|
|
ncwin->core.key = nsgtk_pi_key;
|
|
|
|
ncwin->core.mouse = nsgtk_pi_mouse;
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
res = nsgtk_corewindow_init(&ncwin->core);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
g_object_unref(G_OBJECT(ncwin->dlg));
|
|
|
|
free(ncwin);
|
|
|
|
return res;
|
|
|
|
}
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2020-02-24 23:46:11 +03:00
|
|
|
res = page_info_create(ncwin->core.cb_table,
|
|
|
|
(struct core_window *)ncwin,
|
|
|
|
bw, &ncwin->pi);
|
2016-07-31 14:19:37 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
g_object_unref(G_OBJECT(ncwin->dlg));
|
|
|
|
free(ncwin);
|
|
|
|
return res;
|
|
|
|
}
|
2015-04-12 19:55:46 +03:00
|
|
|
|
2016-07-31 14:19:37 +03:00
|
|
|
gtk_widget_show(GTK_WIDGET(ncwin->dlg));
|
2016-07-31 03:24:57 +03:00
|
|
|
|
2020-05-08 22:42:49 +03:00
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(ncwin->dlg));
|
|
|
|
|
2016-07-31 03:24:57 +03:00
|
|
|
return NSERROR_OK;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|
2020-05-08 22:46:37 +03:00
|
|
|
|
|
|
|
/* exported interface documented in gtk/page_info.h */
|
|
|
|
void
|
|
|
|
nsgtk_page_info_set_position(struct nsgtk_pi_window *win, int x, int y)
|
|
|
|
{
|
|
|
|
NSLOG(netsurf, INFO, "win=%p x=%d y=%d", win, x, y);
|
|
|
|
|
|
|
|
gtk_window_move(GTK_WINDOW(win->dlg), x, y);
|
|
|
|
}
|