NetSurf
page_info.c
Go to the documentation of this file.
1/*
2 * Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Implementation of gtk certificate viewing using gtk core windows.
22 */
23
24#include <stdint.h>
25#include <stdlib.h>
26#include <gtk/gtk.h>
27
28#include "utils/log.h"
29#include "utils/messages.h"
30#include "netsurf/keypress.h"
31#include "netsurf/plotters.h"
32#include "netsurf/misc.h"
34#include "desktop/page-info.h"
36
37#include "gtk/plotters.h"
38#include "gtk/scaffolding.h"
39#include "gtk/resources.h"
40#include "gtk/page_info.h"
41#include "gtk/corewindow.h"
42
43
44/**
45 * GTK certificate viewing window context
46 */
48 /** GTK core window context */
50 /** GTK builder for window */
51 GtkBuilder *builder;
52 /** GTK window being shown */
53 GtkWindow *dlg;
54 /** Core page-info window */
55 struct page_info *pi;
56};
57
58
59/**
60 * destroy a previously created page information window
61 */
62static gboolean
63nsgtk_pi_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
64{
65 struct nsgtk_pi_window *pi_win;
66 pi_win = (struct nsgtk_pi_window *)data;
67
68 page_info_destroy(pi_win->pi);
69
71 gtk_widget_destroy(GTK_WIDGET(pi_win->dlg));
72 g_object_unref(G_OBJECT(pi_win->builder));
73 free(pi_win);
74
75 return FALSE;
76}
77
78/**
79 * Called to cause the page-info window to close cleanly
80 */
81static void
83{
84 nsgtk_pi_delete_event(NULL, NULL, pw);
85}
86
87/**
88 * callback for mouse action for certificate verify on core window
89 *
90 * \param nsgtk_cw The nsgtk core window structure.
91 * \param mouse_state netsurf mouse state on event
92 * \param x location of event
93 * \param y location of event
94 * \return NSERROR_OK on success otherwise appropriate error code
95 */
96static nserror
98 browser_mouse_state mouse_state,
99 int x, int y)
100{
101 struct nsgtk_pi_window *pi_win;
102 bool did_something = false;
103 /* technically degenerate container of */
104 pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
105
106 if (page_info_mouse_action(pi_win->pi, mouse_state, x, y, &did_something) == NSERROR_OK) {
107 if (did_something == true) {
108 /* Something happened so we need to close ourselves */
110 }
111 }
112
113 return NSERROR_OK;
114}
115
116/**
117 * callback for keypress for certificate verify on core window
118 *
119 * \param nsgtk_cw The nsgtk core window structure.
120 * \param nskey The netsurf key code
121 * \return NSERROR_OK on success otherwise appropriate error code
122 */
123static nserror
124nsgtk_pi_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
125{
126 struct nsgtk_pi_window *pi_win;
127
128 /* technically degenerate container of */
129 pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
130
131 if (page_info_keypress(pi_win->pi, nskey)) {
132 return NSERROR_OK;
133 }
135}
136
137/**
138 * callback on draw event for certificate verify on core window
139 *
140 * \param nsgtk_cw The nsgtk core window structure.
141 * \param r The rectangle of the window that needs updating.
142 * \return NSERROR_OK on success otherwise appropriate error code
143 */
144static nserror
145nsgtk_pi_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
146{
147 struct redraw_context ctx = {
148 .interactive = true,
149 .background_images = true,
150 .plot = &nsgtk_plotters
151 };
152 struct nsgtk_pi_window *pi_win;
153
154 /* technically degenerate container of */
155 pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
156
157 page_info_redraw(pi_win->pi, 0, 0, r, &ctx);
158
159 return NSERROR_OK;
160}
161
162/* exported interface documented in gtk/page_info.h */
164{
165 struct nsgtk_pi_window *ncwin;
166 nserror res;
168
169 ncwin = calloc(1, sizeof(struct nsgtk_pi_window));
170 if (ncwin == NULL) {
171 return NSERROR_NOMEM;
172 }
173
174 res = nsgtk_builder_new_from_resname("pageinfo", &ncwin->builder);
175 if (res != NSERROR_OK) {
176 NSLOG(netsurf, CRITICAL, "Page Info UI builder init failed %s", messages_get_errorcode(res));
177 free(ncwin);
178 return res;
179 }
180
181 gtk_builder_connect_signals(ncwin->builder, NULL);
182
183 ncwin->dlg = GTK_WINDOW(gtk_builder_get_object(ncwin->builder,
184 "PGIWindow"));
185
186 /* Configure for transient behaviour */
187 gtk_window_set_type_hint(GTK_WINDOW(ncwin->dlg),
188 GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
189
190 gtk_window_set_modal(GTK_WINDOW(ncwin->dlg), TRUE);
191
192 gtk_window_group_add_window(gtk_window_get_group(scaffwin),
193 GTK_WINDOW(ncwin->dlg));
194
195 gtk_window_set_transient_for(GTK_WINDOW(ncwin->dlg), scaffwin);
196
197 gtk_window_set_screen(GTK_WINDOW(ncwin->dlg),
198 gtk_widget_get_screen(GTK_WIDGET(scaffwin)));
199
200 /* Attempt to place the window in the right place */
202 ncwin);
203
204 ncwin->core.drawing_area = GTK_DRAWING_AREA(
205 gtk_builder_get_object(ncwin->builder, "PGIDrawingArea"));
206
207 /* make the delete event call our destructor */
208 g_signal_connect(G_OBJECT(ncwin->dlg),
209 "delete_event",
210 G_CALLBACK(nsgtk_pi_delete_event),
211 ncwin);
212 /* Ditto if we lose the grab */
213 g_signal_connect(G_OBJECT(ncwin->dlg),
214 "grab-broken-event",
215 G_CALLBACK(nsgtk_pi_delete_event),
216 ncwin);
217 /* Handle button press events */
218 g_signal_connect(G_OBJECT(ncwin->dlg),
219 "button-press-event",
220 G_CALLBACK(nsgtk_pi_delete_event),
221 ncwin);
222
223 /* initialise GTK core window */
224 ncwin->core.draw = nsgtk_pi_draw;
225 ncwin->core.key = nsgtk_pi_key;
226 ncwin->core.mouse = nsgtk_pi_mouse;
227
228 res = nsgtk_corewindow_init(&ncwin->core);
229 if (res != NSERROR_OK) {
230 g_object_unref(G_OBJECT(ncwin->dlg));
231 free(ncwin);
232 return res;
233 }
234
235 res = page_info_create((struct core_window *)ncwin, bw, &ncwin->pi);
236 if (res != NSERROR_OK) {
237 g_object_unref(G_OBJECT(ncwin->dlg));
238 free(ncwin);
239 return res;
240 }
241
242 gtk_widget_show(GTK_WIDGET(ncwin->dlg));
243
244 gtk_widget_grab_focus(GTK_WIDGET(ncwin->dlg));
245
246 return NSERROR_OK;
247}
248
249/* exported interface documented in gtk/page_info.h */
250void
252{
253 NSLOG(netsurf, INFO, "win=%p x=%d y=%d", win, x, y);
254
255 gtk_window_move(GTK_WINDOW(win->dlg), x, y);
256}
Browser window creation and manipulation interface.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOT_IMPLEMENTED
Functionality is not implemented.
Definition: errors.h:61
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
Target independent plotting GTK+ interface.
nserror nsgtk_corewindow_init(struct nsgtk_corewindow *nsgtk_cw)
initialise elements of gtk core window.
Definition: corewindow.c:733
nserror nsgtk_corewindow_fini(struct nsgtk_corewindow *nsgtk_cw)
finalise elements of gtk core window.
Definition: corewindow.c:786
const struct plotter_table nsgtk_plotters
GTK plotter table.
Definition: plotters.c:647
struct netsurf_table * guit
The global interface table.
Definition: gui_factory.c:50
Interface to core interface table.
Interface to platform-specific miscellaneous browser operation table.
browser_mouse_state
Mouse state: 1 is primary mouse button.
Definition: mouse.h:52
Target independent plotting interface.
Interface to key press operations.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
Localised message support (interface).
nserror page_info_destroy(struct page_info *pi)
Destroy a page info corewindow.
Definition: page-info.c:570
nserror page_info_redraw(const struct page_info *pi, int x, int y, const struct rect *clip, const struct redraw_context *ctx)
Redraw the page info window.
Definition: page-info.c:620
nserror page_info_create(struct core_window *cw_h, struct browser_window *bw, struct page_info **pi_out)
Create a page info corewindow.
Definition: page-info.c:537
bool page_info_keypress(struct page_info *pi, int32_t key)
Key press handling.
Definition: page-info.c:814
nserror page_info_mouse_action(struct page_info *pi, enum browser_mouse_state mouse, int x, int y, bool *did_something)
Mouse action handling.
Definition: page-info.c:753
Pave info viewer window interface.
static gboolean nsgtk_pi_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
destroy a previously created page information window
Definition: page_info.c:63
void nsgtk_page_info_set_position(struct nsgtk_pi_window *win, int x, int y)
Position the given page information window at the given coordinates.
Definition: page_info.c:251
static nserror nsgtk_pi_mouse(struct nsgtk_corewindow *nsgtk_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action for certificate verify on core window
Definition: page_info.c:97
nserror nsgtk_page_info(struct browser_window *bw)
Page information window.
Definition: page_info.c:163
static nserror nsgtk_pi_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
callback for keypress for certificate verify on core window
Definition: page_info.c:124
static nserror nsgtk_pi_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
callback on draw event for certificate verify on core window
Definition: page_info.c:145
static void nsgtk_pi_close_callback(void *pw)
Called to cause the page-info window to close cleanly.
Definition: page_info.c:82
nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out)
Create gtk builder object for the named ui resource.
Definition: resources.c:526
Interface to gtk builtin resource handling.
GtkWindow * nsgtk_scaffolding_window(struct nsgtk_scaffolding *g)
Get the gtk window for a scaffolding.
Definition: scaffolding.c:1310
nserror nsgtk_scaffolding_position_page_info(struct nsgtk_scaffolding *gs, struct nsgtk_pi_window *win)
Position the page-info popup in the right place.
Definition: scaffolding.c:1593
struct nsgtk_scaffolding * nsgtk_current_scaffolding(void)
Obtain the most recently used scaffolding element.
Definition: scaffolding.c:1473
Browser window data.
nserror(* schedule)(int t, void(*callback)(void *p), void *p)
Schedule a callback.
Definition: misc.h:58
struct gui_misc_table * misc
Browser table.
Definition: gui_table.h:57
nsgtk core window state
Definition: corewindow.h:41
nserror(* key)(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
callback for keypress on nsgtk core window
Definition: corewindow.h:76
nserror(* draw)(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
callback to draw on drawable area of nsgtk core window
Definition: corewindow.h:65
nserror(* mouse)(struct nsgtk_corewindow *nsgtk_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on nsgtk core window
Definition: corewindow.h:87
GtkDrawingArea * drawing_area
GTK drawable widget.
Definition: corewindow.h:44
GTK certificate viewing window context.
Definition: page_info.c:47
struct nsgtk_corewindow core
GTK core window context.
Definition: page_info.c:49
struct page_info * pi
Core page-info window.
Definition: page_info.c:55
GtkBuilder * builder
GTK builder for window.
Definition: page_info.c:51
GtkWindow * dlg
GTK window being shown.
Definition: page_info.c:53
The page info window structure.
Definition: page-info.c:238
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59