NetSurf
cookies.c
Go to the documentation of this file.
1/*
2 * Copyright 2016 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 win32 cookie manager.
22 */
23
24#include <stdint.h>
25#include <stdlib.h>
26#include <windows.h>
27
28#include "utils/log.h"
29#include "utils/nsoption.h"
30#include "netsurf/keypress.h"
31#include "netsurf/plotters.h"
33
34#include "windows/plot.h"
35#include "windows/corewindow.h"
36#include "windows/cookies.h"
37#include "windows/gui.h"
38
39
42};
43
44static struct nsw32_cookie_window *cookie_window = NULL;
45
46/**
47 * callback for keypress on cookie window
48 *
49 * \param nsw32_cw The nsw32 core window structure.
50 * \param nskey The netsurf key code
51 * \return NSERROR_OK on success otherwise apropriate error code
52 */
53static nserror
54nsw32_cookie_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
55{
56 if (cookie_manager_keypress(nskey)) {
57 return NSERROR_OK;
58 }
60}
61
62
63/**
64 * callback for mouse action on cookie window
65 *
66 * \param nsw32_cw The nsw32 core window structure.
67 * \param mouse_state netsurf mouse state on event
68 * \param x location of event
69 * \param y location of event
70 * \return NSERROR_OK on success otherwise apropriate error code
71 */
72static nserror
74 browser_mouse_state mouse_state,
75 int x, int y)
76{
77 cookie_manager_mouse_action(mouse_state, x, y);
78
79 return NSERROR_OK;
80}
81
82
83/**
84 * callback on draw event for cookie window
85 *
86 * \param nsw32_cw The nsw32 core window structure.
87 * \param scrollx The horizontal scroll offset.
88 * \param scrolly The vertical scroll offset.
89 * \param r The rectangle of the window that needs updating.
90 * \return NSERROR_OK on success otherwise apropriate error code
91 */
92static nserror
94 int scrollx,
95 int scrolly,
96 struct rect *r)
97{
98 struct redraw_context ctx = {
99 .interactive = true,
100 .background_images = true,
101 .plot = &win_plotters
102 };
103
104 cookie_manager_redraw(-scrollx, -scrolly, r, &ctx);
105
106 return NSERROR_OK;
107}
108
109
110/**
111 * callback on close event for cookie window
112 *
113 * \param nsw32_cw The nsw32 core window structure.
114 * \return NSERROR_OK on success otherwise apropriate error code
115 */
116static nserror
118{
119 ShowWindow(nsw32_cw->hWnd, SW_HIDE);
120
121 return NSERROR_OK;
122}
123
124
125/**
126 * Creates the window for the cookie tree.
127 *
128 * \param hInstance The application instance
129 * \return NSERROR_OK on success else appropriate error code on faliure.
130 */
131static nserror nsw32_cookie_init(HINSTANCE hInstance)
132{
133 struct nsw32_cookie_window *ncwin;
134 nserror res;
135
136 if (cookie_window != NULL) {
137 return NSERROR_OK;
138 }
139
140 ncwin = calloc(1, sizeof(*ncwin));
141 if (ncwin == NULL) {
142 return NSERROR_NOMEM;
143 }
144
145 ncwin->core.title = "NetSurf Cookies";
146 ncwin->core.draw = nsw32_cookie_draw;
147 ncwin->core.key = nsw32_cookie_key;
150
151 res = nsw32_corewindow_init(hInstance, NULL, &ncwin->core);
152 if (res != NSERROR_OK) {
153 free(ncwin);
154 return res;
155 }
156
157 res = cookie_manager_init((struct core_window *)ncwin);
158 if (res != NSERROR_OK) {
159 free(ncwin);
160 return res;
161 }
162
163 /* memoise window so it can be represented when necessary
164 * instead of recreating every time.
165 */
166 cookie_window = ncwin;
167
168 return NSERROR_OK;
169}
170
171
172/* exported interface documented in windows/cookie.h */
173nserror nsw32_cookies_present(const char *search_term)
174{
175 nserror res;
176
178 if (res == NSERROR_OK) {
179 ShowWindow(cookie_window->core.hWnd, SW_SHOWNORMAL);
180 if (search_term != NULL) {
181 res = cookie_manager_set_search_string(search_term);
182 }
183 }
184 return res;
185}
186
187
188/* exported interface documented in windows/cookie.h */
190{
191 nserror res;
192
193 if (cookie_window == NULL) {
194 return NSERROR_OK;
195 }
196
197 res = cookie_manager_fini();
198 if (res == NSERROR_OK) {
200 DestroyWindow(cookie_window->core.hWnd);
201 free(cookie_window);
202 cookie_window = NULL;
203 }
204
205 return res;
206}
void cookie_manager_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the cookies manager.
void cookie_manager_mouse_action(enum browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
nserror cookie_manager_init(void *core_window_handle)
Initialise the cookie manager.
nserror cookie_manager_fini(void)
Finalise the cookie manager.
nserror cookie_manager_set_search_string(const char *string)
Set the cookie manager search string.
bool cookie_manager_keypress(uint32_t key)
Key press handling.
Cookie Manager (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
browser_mouse_state
Mouse state: 1 is primary mouse button.
Definition: mouse.h:52
Target independent plotting interface.
Interface to key press operations.
#define ShowWindow(...)
Definition: os3support.h:172
nsw32 core window state
Definition: corewindow.h:29
nserror(* close)(struct nsw32_corewindow *nsw32_cw)
callback for window close event
Definition: corewindow.h:82
const char * title
window title
Definition: corewindow.h:40
nserror(* key)(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
callback for keypress on nsw32 core window
Definition: corewindow.h:63
nserror(* mouse)(struct nsw32_corewindow *nsw32_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on nsw32 core window
Definition: corewindow.h:74
HWND hWnd
window handle
Definition: corewindow.h:31
nserror(* draw)(struct nsw32_corewindow *nsw32_cw, int scrollx, int scrolly, struct rect *r)
callback to draw on drawable area of nsw32 core window
Definition: corewindow.h:52
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
Option reading and saving interface.
nserror nsw32_cookies_present(const char *search_term)
make the cookie window visible.
Definition: cookies.c:173
static nserror nsw32_cookie_init(HINSTANCE hInstance)
Creates the window for the cookie tree.
Definition: cookies.c:131
static nserror nsw32_cookie_close(struct nsw32_corewindow *nsw32_cw)
callback on close event for cookie window
Definition: cookies.c:117
static nserror nsw32_cookie_draw(struct nsw32_corewindow *nsw32_cw, int scrollx, int scrolly, struct rect *r)
callback on draw event for cookie window
Definition: cookies.c:93
static nserror nsw32_cookie_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
callback for keypress on cookie window
Definition: cookies.c:54
nserror nsw32_cookies_finalise(void)
Free any resources allocated for the cookie window.
Definition: cookies.c:189
static nserror nsw32_cookie_mouse(struct nsw32_corewindow *nsw32_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action on cookie window
Definition: cookies.c:73
static struct nsw32_cookie_window * cookie_window
Definition: cookies.c:44
Interface to win32 cookie viewing using nsw32 core windows.
nserror nsw32_corewindow_init(HINSTANCE hInstance, HWND hWndParent, struct nsw32_corewindow *nsw32_cw)
initialise elements of nsw32 core window.
Definition: corewindow.c:519
nserror nsw32_corewindow_fini(struct nsw32_corewindow *nsw32_cw)
finalise elements of nsw32 core window.
Definition: corewindow.c:577
HINSTANCE hinst
win32 application instance handle.
Definition: gui.c:45
const struct plotter_table win_plotters
win32 API plot operation table
Definition: plot.c:1040