NetSurf
local_history.c
Go to the documentation of this file.
1/*
2 * Copyright 2017 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 framebuffer local history manager.
22 */
23
24#include <stdint.h>
25#include <stdbool.h>
26#include <stdlib.h>
27#include <limits.h>
28
29#include <libnsfb.h>
30#include <libnsfb_plot.h>
31#include <libnsfb_event.h>
32
33#include "utils/log.h"
34#include "netsurf/keypress.h"
35#include "netsurf/plotters.h"
37
38#include "framebuffer/gui.h"
39#include "framebuffer/fbtk.h"
43
46
48};
49
51
52
53/**
54 * callback for mouse action on local history window
55 *
56 * \param fb_cw The fb core window structure.
57 * \param mouse_state netsurf mouse state on event
58 * \param x location of event
59 * \param y location of event
60 * \return NSERROR_OK on success otherwise apropriate error code
61 */
62static nserror
64 browser_mouse_state mouse_state,
65 int x, int y)
66{
67 struct fb_local_history_window *lhw;
68 /* technically degenerate container of */
69 lhw = (struct fb_local_history_window *)fb_cw;
70
71 local_history_mouse_action(lhw->session, mouse_state, x, y);
72
73 if (mouse_state != BROWSER_MOUSE_HOVER) {
74 fbtk_set_mapping(lhw->core.wnd, false);
75 }
76
77 return NSERROR_OK;
78}
79
80
81/**
82 * callback for keypress on local history window
83 *
84 * \param fb_cw The fb core window structure.
85 * \param nskey The netsurf key code
86 * \return NSERROR_OK on success otherwise apropriate error code
87 */
88static nserror
89fb_local_history_key(struct fb_corewindow *fb_cw, uint32_t nskey)
90{
91 struct fb_local_history_window *lhw;
92 /* technically degenerate container of */
93 lhw = (struct fb_local_history_window *)fb_cw;
94
95 if (local_history_keypress(lhw->session, nskey)) {
96 return NSERROR_OK;
97 }
99}
100
101
102/**
103 * callback on draw event for local history window
104 *
105 * \param fb_cw The fb core window structure.
106 * \param r The rectangle of the window that needs updating.
107 * \return NSERROR_OK on success otherwise apropriate error code
108 */
109static nserror
110fb_local_history_draw(struct fb_corewindow *fb_cw, struct rect *r)
111{
112 struct redraw_context ctx = {
113 .interactive = true,
114 .background_images = true,
115 .plot = &fb_plotters
116 };
117 struct fb_local_history_window *lhw;
118
119 /* technically degenerate container of */
120 lhw = (struct fb_local_history_window *)fb_cw;
121
122 local_history_redraw(lhw->session, 0, 0, r, &ctx);
123
124 return NSERROR_OK;
125}
126
127/**
128 * Creates the window for the local history view.
129 *
130 * \return NSERROR_OK on success else appropriate error code on faliure.
131 */
132static nserror
134 struct browser_window *bw,
135 struct fb_local_history_window **win_out)
136{
137 struct fb_local_history_window *ncwin;
138 nserror res;
139
140 /* memoise window so it can be represented when necessary
141 * instead of recreating every time.
142 */
143 if ((*win_out) != NULL) {
144 res = local_history_set((*win_out)->session, bw);
145 return res;
146 }
147
148 ncwin = calloc(1, sizeof(*ncwin));
149 if (ncwin == NULL) {
150 return NSERROR_NOMEM;
151 }
152
156
157 res = fb_corewindow_init(parent, &ncwin->core);
158 if (res != NSERROR_OK) {
159 free(ncwin);
160 return res;
161 }
162
163 res = local_history_init(ncwin->core.cb_table,
164 (struct core_window *)ncwin,
165 bw,
166 &ncwin->session);
167 if (res != NSERROR_OK) {
168 free(ncwin);
169 return res;
170 }
171
172 *win_out = ncwin;
173
174 return NSERROR_OK;
175}
176
177
178/* exported function documented gtk/history.h */
180 struct browser_window *bw)
181{
182 nserror res;
183 int prnt_width, prnt_height;
184 int width, height;
185
187 if (res == NSERROR_OK) {
188
189 prnt_width = fbtk_get_width(parent);
190 prnt_height = fbtk_get_height(parent);
191
192 /* resize history widget ensureing the drawing area is
193 * no larger than parent window
194 */
196 &width,
197 &height);
198 if (width > prnt_width) {
199 width = prnt_width;
200 }
201 if (height > prnt_height) {
202 height = prnt_height;
203 }
204 /* should update scroll area with contents */
205
209 }
210
211 return res;
212}
213
214
215/* exported function documented gtk/history.h */
217{
218 nserror res = NSERROR_OK;
219
220 if (local_history_window != NULL) {
222
224 }
225
226 return res;
227}
228
229
230/* exported function documented gtk/history.h */
232{
233 nserror res;
234
235 if (local_history_window == NULL) {
236 return NSERROR_OK;
237 }
238
240 if (res == NSERROR_OK) {
242 //gtk_widget_destroy(GTK_WIDGET(local_history_window->wnd));
245 }
246
247 return res;
248
249}
nserror local_history_init(struct core_window_callback_table *cw_t, void *core_window_handle, struct browser_window *bw, struct local_history_session **session)
Initialise the local history.
nserror local_history_redraw(struct local_history_session *session, int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the local history.
nserror local_history_scroll_to_cursor(struct local_history_session *session)
Scroll the local history window to ensure the current cursor is shown.
nserror local_history_get_size(struct local_history_session *session, int *width, int *height)
get size of local history content area.
nserror local_history_set(struct local_history_session *session, struct browser_window *bw)
Change the browser window to draw local history for.
nserror local_history_fini(struct local_history_session *session)
Finalise the local history.
bool local_history_keypress(struct local_history_session *session, uint32_t key)
Key press handling.
nserror local_history_mouse_action(struct local_history_session *session, enum browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
wimp_w parent
Definition: dialog.c:88
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
int fbtk_set_mapping(fbtk_widget_t *widget, bool mapped)
Map a widget and request it is redrawn.
Definition: fbtk.c:127
int fbtk_get_width(fbtk_widget_t *widget)
Get a widget's width.
Definition: fbtk.c:467
int fbtk_set_zorder(fbtk_widget_t *widget, int z)
Set the z order of a widget.
Definition: fbtk.c:181
int fbtk_get_height(fbtk_widget_t *widget)
Get a widget's height.
Definition: fbtk.c:460
nserror fb_corewindow_init(fbtk_widget_t *parent, struct fb_corewindow *fb_cw)
initialise elements of fb core window.
Definition: corewindow.c:205
nserror fb_corewindow_fini(struct fb_corewindow *fb_cw)
finalise elements of fb core window.
Definition: corewindow.c:277
const struct plotter_table fb_plotters
framebuffer plot operation table
Definition: framebuffer.c:525
framebuffer interface.
static nserror fb_local_history_draw(struct fb_corewindow *fb_cw, struct rect *r)
callback on draw event for local history window
nserror fb_local_history_destroy(void)
Destroys the local history window and performs any other necessary cleanup actions.
static nserror fb_local_history_mouse(struct fb_corewindow *fb_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action on local history window
Definition: local_history.c:63
static nserror fb_local_history_init(fbtk_widget_t *parent, struct browser_window *bw, struct fb_local_history_window **win_out)
Creates the window for the local history view.
nserror fb_local_history_present(fbtk_widget_t *parent, struct browser_window *bw)
make the local history window visible.
nserror fb_local_history_hide(void)
hide the local history window from being visible.
static struct fb_local_history_window * local_history_window
Definition: local_history.c:50
static nserror fb_local_history_key(struct fb_corewindow *fb_cw, uint32_t nskey)
callback for keypress on local history window
Definition: local_history.c:89
Interface to framebuffer local history manager.
browser_mouse_state
Mouse state.
Definition: mouse.h:43
@ BROWSER_MOUSE_HOVER
No mouse buttons pressed, May be used to indicate hover or end of drag.
Definition: mouse.h:47
Target independent plotting interface.
Interface to key press operations.
int width
Definition: gui.c:159
int height
Definition: gui.c:160
Browser window data.
fb core window state
Definition: corewindow.h:27
struct core_window_callback_table * cb_table
table of callbacks for core window operations
Definition: corewindow.h:53
struct fbtk_widget_s * wnd
framebuffer toolkit window.
Definition: corewindow.h:32
nserror(* key)(struct fb_corewindow *fb_cw, uint32_t nskey)
callback for keypress on fb core window
Definition: corewindow.h:73
nserror(* draw)(struct fb_corewindow *fb_cw, struct rect *r)
callback to draw on drawable area of fb core window
Definition: corewindow.h:62
nserror(* mouse)(struct fb_corewindow *fb_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on fb core window
Definition: corewindow.h:84
struct local_history_session * session
Definition: local_history.c:47
struct fb_corewindow core
Definition: local_history.c:45
Widget description.
Definition: widget.h:120
local history viewer context
Definition: local_history.c:50
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59