NetSurf
gui.c
Go to the documentation of this file.
1/*
2 * Copyright 2008, 2014 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#include <stdint.h>
20#include <limits.h>
21#include <getopt.h>
22#include <assert.h>
23#include <string.h>
24#include <stdbool.h>
25#include <stdlib.h>
26#include <nsutils/time.h>
27
28#include <libnsfb.h>
29#include <libnsfb_plot.h>
30#include <libnsfb_event.h>
31
32#include "utils/utils.h"
33#include "utils/nsoption.h"
34#include "utils/filepath.h"
35#include "utils/log.h"
36#include "utils/messages.h"
38#include "netsurf/keypress.h"
40#include "netsurf/plotters.h"
41#include "netsurf/window.h"
42#include "netsurf/misc.h"
43#include "netsurf/netsurf.h"
44#include "netsurf/cookie_db.h"
45#include "content/fetch.h"
46
47#include "framebuffer/gui.h"
48#include "framebuffer/fbtk.h"
53#include "framebuffer/font.h"
55#include "framebuffer/fetch.h"
56#include "framebuffer/bitmap.h"
59
60
61#define NSFB_TOOLBAR_DEFAULT_LAYOUT "blfsrutc"
62
64
65static bool fb_complete = false;
66
67struct gui_window *input_window = NULL;
69struct gui_window *window_list = NULL;
70
71/* private data for browser user widget */
73 struct browser_window *bw; /**< The browser window connected to this gui window */
74 int scrollx, scrolly; /**< scroll offsets. */
75
76 /* Pending window redraw state. */
77 bool redraw_required; /**< flag indicating the foreground loop
78 * needs to redraw the browser widget.
79 */
80 bbox_t redraw_box; /**< Area requiring redraw. */
81 bool pan_required; /**< flag indicating the foreground loop
82 * needs to pan the window.
83 */
84 int panx, pany; /**< Panning required. */
85};
86
87static struct gui_drag {
88 enum state {
93 int button;
94 int x;
95 int y;
98
99
100/**
101 * Cause an abnormal program termination.
102 *
103 * \note This never returns and is intended to terminate without any cleanup.
104 *
105 * \param error The message to display to the user.
106 */
107static void die(const char *error)
108{
109 fprintf(stderr, "%s\n", error);
110 exit(1);
111}
112
113
114/**
115 * Warn the user of an event.
116 *
117 * \param[in] warning A warning looked up in the message translation table
118 * \param[in] detail Additional text to be displayed or NULL.
119 * \return NSERROR_OK on success or error code if there was a
120 * faliure displaying the message to the user.
121 */
122static nserror fb_warn_user(const char *warning, const char *detail)
123{
124 NSLOG(netsurf, INFO, "%s %s", warning, detail);
125 return NSERROR_OK;
126}
127
128/* queue a redraw operation, co-ordinates are relative to the window */
129static void
130fb_queue_redraw(struct fbtk_widget_s *widget, int x0, int y0, int x1, int y1)
131{
132 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
133
134 bwidget->redraw_box.x0 = min(bwidget->redraw_box.x0, x0);
135 bwidget->redraw_box.y0 = min(bwidget->redraw_box.y0, y0);
136 bwidget->redraw_box.x1 = max(bwidget->redraw_box.x1, x1);
137 bwidget->redraw_box.y1 = max(bwidget->redraw_box.y1, y1);
138
139 if (fbtk_clip_to_widget(widget, &bwidget->redraw_box)) {
140 bwidget->redraw_required = true;
141 fbtk_request_redraw(widget);
142 } else {
143 bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
144 bwidget->redraw_box.y1 = bwidget->redraw_box.x1 = -(INT_MAX);
145 bwidget->redraw_required = false;
146 }
147}
148
149/* queue a window scroll */
150static void
151widget_scroll_y(struct gui_window *gw, int y, bool abs)
152{
153 struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
154 int content_width, content_height;
155 int height;
156
157 NSLOG(netsurf, DEEPDEBUG, "window scroll");
158 if (abs) {
159 bwidget->pany = y - bwidget->scrolly;
160 } else {
161 bwidget->pany += y;
162 }
163
165 &content_width, &content_height);
166
168
169 /* dont pan off the top */
170 if ((bwidget->scrolly + bwidget->pany) < 0)
171 bwidget->pany = -bwidget->scrolly;
172
173 /* do not pan off the bottom of the content */
174 if ((bwidget->scrolly + bwidget->pany) > (content_height - height))
175 bwidget->pany = (content_height - height) - bwidget->scrolly;
176
177 if (bwidget->pany == 0)
178 return;
179
180 bwidget->pan_required = true;
181
183
184 fbtk_set_scroll_position(gw->vscroll, bwidget->scrolly + bwidget->pany);
185}
186
187/* queue a window scroll */
188static void
189widget_scroll_x(struct gui_window *gw, int x, bool abs)
190{
191 struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
192 int content_width, content_height;
193 int width;
194
195 if (abs) {
196 bwidget->panx = x - bwidget->scrollx;
197 } else {
198 bwidget->panx += x;
199 }
200
202 &content_width, &content_height);
203
205
206 /* dont pan off the left */
207 if ((bwidget->scrollx + bwidget->panx) < 0)
208 bwidget->panx = - bwidget->scrollx;
209
210 /* do not pan off the right of the content */
211 if ((bwidget->scrollx + bwidget->panx) > (content_width - width))
212 bwidget->panx = (content_width - width) - bwidget->scrollx;
213
214 if (bwidget->panx == 0)
215 return;
216
217 bwidget->pan_required = true;
218
220
221 fbtk_set_scroll_position(gw->hscroll, bwidget->scrollx + bwidget->panx);
222}
223
224static void
226 struct browser_widget_s *bwidget,
227 struct browser_window *bw)
228{
229 int x;
230 int y;
231 int width;
232 int height;
233 nsfb_bbox_t srcbox;
234 nsfb_bbox_t dstbox;
235
236 nsfb_t *nsfb = fbtk_get_nsfb(widget);
237
238 height = fbtk_get_height(widget);
239 width = fbtk_get_width(widget);
240
241 NSLOG(netsurf, DEEPDEBUG, "panning %d, %d",
242 bwidget->panx, bwidget->pany);
243
244 x = fbtk_get_absx(widget);
245 y = fbtk_get_absy(widget);
246
247 /* if the pan exceeds the viewport size just redraw the whole area */
248 if (bwidget->pany >= height || bwidget->pany <= -height ||
249 bwidget->panx >= width || bwidget->panx <= -width) {
250
251 bwidget->scrolly += bwidget->pany;
252 bwidget->scrollx += bwidget->panx;
253 fb_queue_redraw(widget, 0, 0, width, height);
254
255 /* ensure we don't try to scroll again */
256 bwidget->panx = 0;
257 bwidget->pany = 0;
258 bwidget->pan_required = false;
259 return;
260 }
261
262 if (bwidget->pany < 0) {
263 /* pan up by less then viewport height */
264 srcbox.x0 = x;
265 srcbox.y0 = y;
266 srcbox.x1 = srcbox.x0 + width;
267 srcbox.y1 = srcbox.y0 + height + bwidget->pany;
268
269 dstbox.x0 = x;
270 dstbox.y0 = y - bwidget->pany;
271 dstbox.x1 = dstbox.x0 + width;
272 dstbox.y1 = dstbox.y0 + height + bwidget->pany;
273
274 /* move part that remains visible up */
275 nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
276
277 /* redraw newly exposed area */
278 bwidget->scrolly += bwidget->pany;
279 fb_queue_redraw(widget, 0, 0, width, - bwidget->pany);
280
281 } else if (bwidget->pany > 0) {
282 /* pan down by less then viewport height */
283 srcbox.x0 = x;
284 srcbox.y0 = y + bwidget->pany;
285 srcbox.x1 = srcbox.x0 + width;
286 srcbox.y1 = srcbox.y0 + height - bwidget->pany;
287
288 dstbox.x0 = x;
289 dstbox.y0 = y;
290 dstbox.x1 = dstbox.x0 + width;
291 dstbox.y1 = dstbox.y0 + height - bwidget->pany;
292
293 /* move part that remains visible down */
294 nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
295
296 /* redraw newly exposed area */
297 bwidget->scrolly += bwidget->pany;
298 fb_queue_redraw(widget, 0, height - bwidget->pany,
299 width, height);
300 }
301
302 if (bwidget->panx < 0) {
303 /* pan left by less then viewport width */
304 srcbox.x0 = x;
305 srcbox.y0 = y;
306 srcbox.x1 = srcbox.x0 + width + bwidget->panx;
307 srcbox.y1 = srcbox.y0 + height;
308
309 dstbox.x0 = x - bwidget->panx;
310 dstbox.y0 = y;
311 dstbox.x1 = dstbox.x0 + width + bwidget->panx;
312 dstbox.y1 = dstbox.y0 + height;
313
314 /* move part that remains visible left */
315 nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
316
317 /* redraw newly exposed area */
318 bwidget->scrollx += bwidget->panx;
319 fb_queue_redraw(widget, 0, 0, -bwidget->panx, height);
320
321 } else if (bwidget->panx > 0) {
322 /* pan right by less then viewport width */
323 srcbox.x0 = x + bwidget->panx;
324 srcbox.y0 = y;
325 srcbox.x1 = srcbox.x0 + width - bwidget->panx;
326 srcbox.y1 = srcbox.y0 + height;
327
328 dstbox.x0 = x;
329 dstbox.y0 = y;
330 dstbox.x1 = dstbox.x0 + width - bwidget->panx;
331 dstbox.y1 = dstbox.y0 + height;
332
333 /* move part that remains visible right */
334 nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
335
336 /* redraw newly exposed area */
337 bwidget->scrollx += bwidget->panx;
338 fb_queue_redraw(widget, width - bwidget->panx, 0,
339 width, height);
340 }
341
342 bwidget->pan_required = false;
343 bwidget->panx = 0;
344 bwidget->pany = 0;
345}
346
347static void
349 struct browser_widget_s *bwidget,
350 struct browser_window *bw)
351{
352 int x;
353 int y;
354 int caret_x, caret_y, caret_h;
355 struct rect clip;
356 struct redraw_context ctx = {
357 .interactive = true,
358 .background_images = true,
359 .plot = &fb_plotters
360 };
361 nsfb_t *nsfb = fbtk_get_nsfb(widget);
362
363 x = fbtk_get_absx(widget);
364 y = fbtk_get_absy(widget);
365
366 /* adjust clipping co-ordinates according to window location */
367 bwidget->redraw_box.y0 += y;
368 bwidget->redraw_box.y1 += y;
369 bwidget->redraw_box.x0 += x;
370 bwidget->redraw_box.x1 += x;
371
372 nsfb_claim(nsfb, &bwidget->redraw_box);
373
374 /* redraw bounding box is relative to window */
375 clip.x0 = bwidget->redraw_box.x0;
376 clip.y0 = bwidget->redraw_box.y0;
377 clip.x1 = bwidget->redraw_box.x1;
378 clip.y1 = bwidget->redraw_box.y1;
379
381 x - bwidget->scrollx,
382 y - bwidget->scrolly,
383 &clip, &ctx);
384
385 if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
386 /* This widget has caret, so render it */
387 nsfb_bbox_t line;
388 nsfb_plot_pen_t pen;
389
390 line.x0 = x - bwidget->scrollx + caret_x;
391 line.y0 = y - bwidget->scrolly + caret_y;
392 line.x1 = x - bwidget->scrollx + caret_x;
393 line.y1 = y - bwidget->scrolly + caret_y + caret_h;
394
395 pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
396 pen.stroke_width = 1;
397 pen.stroke_colour = 0xFF0000FF;
398
399 nsfb_plot_line(nsfb, &line, &pen);
400 }
401
402 nsfb_update(fbtk_get_nsfb(widget), &bwidget->redraw_box);
403
404 bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
405 bwidget->redraw_box.y1 = bwidget->redraw_box.x1 = INT_MIN;
406 bwidget->redraw_required = false;
407}
408
409static int
411{
412 struct gui_window *gw = cbi->context;
413 struct browser_widget_s *bwidget;
414
415 bwidget = fbtk_get_userpw(widget);
416 if (bwidget == NULL) {
417 NSLOG(netsurf, INFO,
418 "browser widget from widget %p was null", widget);
419 return -1;
420 }
421
422 if (bwidget->pan_required) {
423 fb_pan(widget, bwidget, gw->bw);
424 }
425
426 if (bwidget->redraw_required) {
427 fb_redraw(widget, bwidget, gw->bw);
428 } else {
429 bwidget->redraw_box.x0 = 0;
430 bwidget->redraw_box.y0 = 0;
431 bwidget->redraw_box.x1 = fbtk_get_width(widget);
432 bwidget->redraw_box.y1 = fbtk_get_height(widget);
433 fb_redraw(widget, bwidget, gw->bw);
434 }
435 return 0;
436}
437
440{
441 struct browser_widget_s *browser_widget;
442
443 if (widget == NULL) {
444 return 0;
445 }
446
447 /* Free private data */
448 browser_widget = fbtk_get_userpw(widget);
449 free(browser_widget);
450
451 return 0;
452}
453
454static void
455framebuffer_surface_iterator(void *ctx, const char *name, enum nsfb_type_e type)
456{
457 const char *arg0 = ctx;
458
459 fprintf(stderr, "%s: %s\n", arg0, name);
460}
461
462static enum nsfb_type_e fetype = NSFB_SURFACE_COUNT;
463static const char *fename;
464static int febpp;
465static int fewidth;
466static int feheight;
467static const char *feurl;
468
469static void
470framebuffer_pick_default_fename(void *ctx, const char *name, enum nsfb_type_e type)
471{
472 if (type < fetype) {
473 fename = name;
474 }
475}
476
477static bool
478process_cmdline(int argc, char** argv)
479{
480 int opt;
481 int option_index;
482 static struct option long_options[] = {
483 {0, 0, 0, 0 }
484 }; /* no long options */
485
486 NSLOG(netsurf, INFO, "argc %d, argv %p", argc, argv);
487
488 nsfb_enumerate_surface_types(framebuffer_pick_default_fename, NULL);
489
490 febpp = 32;
491
492 fewidth = nsoption_int(window_width);
493 if (fewidth <= 0) {
494 fewidth = 800;
495 }
496 feheight = nsoption_int(window_height);
497 if (feheight <= 0) {
498 feheight = 600;
499 }
500
501 if ((nsoption_charp(homepage_url) != NULL) &&
502 (nsoption_charp(homepage_url)[0] != '\0')) {
503 feurl = nsoption_charp(homepage_url);
504 } else {
505 feurl = NETSURF_HOMEPAGE;
506 }
507
508 while((opt = getopt_long(argc, argv, "f:b:w:h:",
509 long_options, &option_index)) != -1) {
510 switch (opt) {
511 case 'f':
512 fename = optarg;
513 break;
514
515 case 'b':
516 febpp = atoi(optarg);
517 break;
518
519 case 'w':
520 fewidth = atoi(optarg);
521 break;
522
523 case 'h':
524 feheight = atoi(optarg);
525 break;
526
527 default:
528 fprintf(stderr,
529 "Usage: %s [-f frontend] [-b bpp] [-w width] [-h height] <url>\n",
530 argv[0]);
531 return false;
532 }
533 }
534
535 if (optind < argc) {
536 feurl = argv[optind];
537 }
538
539 if (nsfb_type_from_name(fename) == NSFB_SURFACE_NONE) {
540 if (strcmp(fename, "?") != 0) {
541 fprintf(stderr,
542 "%s: Unknown surface `%s`\n", argv[0], fename);
543 }
544 fprintf(stderr, "%s: Valid surface names are:\n", argv[0]);
545 nsfb_enumerate_surface_types(framebuffer_surface_iterator, argv[0]);
546 return false;
547 }
548
549 return true;
550}
551
552/**
553 * Set option defaults for framebuffer frontend
554 *
555 * @param defaults The option table to update.
556 * @return error status.
557 */
559{
560 /* Set defaults for absent option strings */
561 nsoption_setnull_charp(cookie_file, strdup("~/.netsurf/Cookies"));
562 nsoption_setnull_charp(cookie_jar, strdup("~/.netsurf/Cookies"));
563
564 if (nsoption_charp(cookie_file) == NULL ||
565 nsoption_charp(cookie_jar) == NULL) {
566 NSLOG(netsurf, INFO, "Failed initialising cookie options");
568 }
569
570 /* set system colours for framebuffer ui */
571 nsoption_set_colour(sys_colour_ActiveBorder, 0x00000000);
572 nsoption_set_colour(sys_colour_ActiveCaption, 0x00ddddcc);
573 nsoption_set_colour(sys_colour_AppWorkspace, 0x00eeeeee);
574 nsoption_set_colour(sys_colour_Background, 0x00aa0000);
575 nsoption_set_colour(sys_colour_ButtonFace, 0x00dddddd);
576 nsoption_set_colour(sys_colour_ButtonHighlight, 0x00cccccc);
577 nsoption_set_colour(sys_colour_ButtonShadow, 0x00bbbbbb);
578 nsoption_set_colour(sys_colour_ButtonText, 0x00000000);
579 nsoption_set_colour(sys_colour_CaptionText, 0x00000000);
580 nsoption_set_colour(sys_colour_GrayText, 0x00777777);
581 nsoption_set_colour(sys_colour_Highlight, 0x00ee0000);
582 nsoption_set_colour(sys_colour_HighlightText, 0x00000000);
583 nsoption_set_colour(sys_colour_InactiveBorder, 0x00000000);
584 nsoption_set_colour(sys_colour_InactiveCaption, 0x00ffffff);
585 nsoption_set_colour(sys_colour_InactiveCaptionText, 0x00cccccc);
586 nsoption_set_colour(sys_colour_InfoBackground, 0x00aaaaaa);
587 nsoption_set_colour(sys_colour_InfoText, 0x00000000);
588 nsoption_set_colour(sys_colour_Menu, 0x00aaaaaa);
589 nsoption_set_colour(sys_colour_MenuText, 0x00000000);
590 nsoption_set_colour(sys_colour_Scrollbar, 0x00aaaaaa);
591 nsoption_set_colour(sys_colour_ThreeDDarkShadow, 0x00555555);
592 nsoption_set_colour(sys_colour_ThreeDFace, 0x00dddddd);
593 nsoption_set_colour(sys_colour_ThreeDHighlight, 0x00aaaaaa);
594 nsoption_set_colour(sys_colour_ThreeDLightShadow, 0x00999999);
595 nsoption_set_colour(sys_colour_ThreeDShadow, 0x00777777);
596 nsoption_set_colour(sys_colour_Window, 0x00aaaaaa);
597 nsoption_set_colour(sys_colour_WindowFrame, 0x00000000);
598 nsoption_set_colour(sys_colour_WindowText, 0x00000000);
599
600 return NSERROR_OK;
601}
602
603
604/**
605 * Ensures output logging stream is correctly configured
606 */
607static bool nslog_stream_configure(FILE *fptr)
608{
609 /* set log stream to be non-buffering */
610 setbuf(fptr, NULL);
611
612 return true;
613}
614
615static void framebuffer_run(void)
616{
617 nsfb_event_t event;
618 int timeout; /* timeout in miliseconds */
619
620 while (fb_complete != true) {
621 /* run the scheduler and discover how long to wait for
622 * the next event.
623 */
624 timeout = schedule_run();
625
626 /* if redraws are pending do not wait for event,
627 * return immediately
628 */
630 timeout = 0;
631
632 if (fbtk_event(fbtk, &event, timeout)) {
633 if ((event.type == NSFB_EVENT_CONTROL) &&
634 (event.value.controlcode == NSFB_CONTROL_QUIT))
635 fb_complete = true;
636 }
637
639 }
640}
641
642static void gui_quit(void)
643{
644 NSLOG(netsurf, INFO, "gui_quit");
645
647
649}
650
651/* called back when click in browser window */
652static int
654{
655 struct gui_window *gw = cbi->context;
656 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
658 int x = cbi->x + bwidget->scrollx;
659 int y = cbi->y + bwidget->scrolly;
660 uint64_t time_now;
661 static struct {
662 enum { CLICK_SINGLE, CLICK_DOUBLE, CLICK_TRIPLE } type;
663 uint64_t time;
664 } last_click;
665
666 if (cbi->event->type != NSFB_EVENT_KEY_DOWN &&
667 cbi->event->type != NSFB_EVENT_KEY_UP)
668 return 0;
669
670 NSLOG(netsurf, DEEPDEBUG, "browser window clicked at %d,%d",
671 cbi->x, cbi->y);
672
673 switch (cbi->event->type) {
674 case NSFB_EVENT_KEY_DOWN:
675 switch (cbi->event->value.keycode) {
676 case NSFB_KEY_MOUSE_1:
679 gui_drag.state = GUI_DRAG_PRESSED;
680 gui_drag.button = 1;
681 gui_drag.x = x;
682 gui_drag.y = y;
683 break;
684
685 case NSFB_KEY_MOUSE_3:
688 gui_drag.state = GUI_DRAG_PRESSED;
689 gui_drag.button = 2;
690 gui_drag.x = x;
691 gui_drag.y = y;
692 break;
693
694 case NSFB_KEY_MOUSE_4:
695 /* scroll up */
697 x, y,
698 0, -100) == false)
699 widget_scroll_y(gw, -100, false);
700 break;
701
702 case NSFB_KEY_MOUSE_5:
703 /* scroll down */
705 x, y,
706 0, 100) == false)
707 widget_scroll_y(gw, 100, false);
708 break;
709
710 default:
711 break;
712
713 }
714
715 break;
716 case NSFB_EVENT_KEY_UP:
717
718 mouse = 0;
719 nsu_getmonotonic_ms(&time_now);
720
721 switch (cbi->event->value.keycode) {
722 case NSFB_KEY_MOUSE_1:
723 if (gui_drag.state == GUI_DRAG_DRAG) {
724 /* End of a drag, rather than click */
725
727 /* need to ungrab pointer */
728 fbtk_tgrab_pointer(widget);
730 }
731
733
734 /* Tell core */
735 browser_window_mouse_track(gw->bw, 0, x, y);
736 break;
737 }
738 /* This is a click;
739 * clear PRESSED state and pass to core */
741 mouse = BROWSER_MOUSE_CLICK_1;
742 break;
743
744 case NSFB_KEY_MOUSE_3:
745 if (gui_drag.state == GUI_DRAG_DRAG) {
746 /* End of a drag, rather than click */
748
750 /* need to ungrab pointer */
751 fbtk_tgrab_pointer(widget);
753 }
754
755 /* Tell core */
756 browser_window_mouse_track(gw->bw, 0, x, y);
757 break;
758 }
759 /* This is a click;
760 * clear PRESSED state and pass to core */
762 mouse = BROWSER_MOUSE_CLICK_2;
763 break;
764
765 default:
766 break;
767
768 }
769
770 /* Determine if it's a double or triple click, allowing
771 * 0.5 seconds (500ms) between clicks
772 */
773 if ((time_now < (last_click.time + 500)) &&
774 (cbi->event->value.keycode != NSFB_KEY_MOUSE_4) &&
775 (cbi->event->value.keycode != NSFB_KEY_MOUSE_5)) {
776 if (last_click.type == CLICK_SINGLE) {
777 /* Set double click */
779 last_click.type = CLICK_DOUBLE;
780
781 } else if (last_click.type == CLICK_DOUBLE) {
782 /* Set triple click */
784 last_click.type = CLICK_TRIPLE;
785 } else {
786 /* Set normal click */
787 last_click.type = CLICK_SINGLE;
788 }
789 } else {
790 last_click.type = CLICK_SINGLE;
791 }
792
793 if (mouse) {
794 browser_window_mouse_click(gw->bw, mouse, x, y);
795 }
796
797 last_click.time = time_now;
798
799 break;
800 default:
801 break;
802
803 }
804 return 1;
805}
806
807/* called back when movement in browser window */
808static int
810{
811 browser_mouse_state mouse = 0;
812 struct gui_window *gw = cbi->context;
813 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
814 int x = cbi->x + bwidget->scrollx;
815 int y = cbi->y + bwidget->scrolly;
816
817 if (gui_drag.state == GUI_DRAG_PRESSED &&
818 (abs(x - gui_drag.x) > 5 ||
819 abs(y - gui_drag.y) > 5)) {
820 /* Drag started */
821 if (gui_drag.button == 1) {
825 } else {
829 }
831 gui_drag.state = GUI_DRAG_DRAG;
832 }
833
834 if (gui_drag.state == GUI_DRAG_DRAG) {
835 /* set up mouse state */
836 mouse |= BROWSER_MOUSE_DRAG_ON;
837
838 if (gui_drag.button == 1)
840 else
842 }
843
844 browser_window_mouse_track(gw->bw, mouse, x, y);
845
846 return 0;
847}
848
849
850static int
852{
853 struct gui_window *gw = cbi->context;
854 static fbtk_modifier_type modifier = FBTK_MOD_CLEAR;
855 int ucs4 = -1;
856
857 NSLOG(netsurf, INFO, "got value %d", cbi->event->value.keycode);
858
859 switch (cbi->event->type) {
860 case NSFB_EVENT_KEY_DOWN:
861 switch (cbi->event->value.keycode) {
862
863 case NSFB_KEY_DELETE:
865 break;
866
867 case NSFB_KEY_PAGEUP:
869 NS_KEY_PAGE_UP) == false)
871 gw->browser), false);
872 break;
873
874 case NSFB_KEY_PAGEDOWN:
876 NS_KEY_PAGE_DOWN) == false)
878 gw->browser), false);
879 break;
880
881 case NSFB_KEY_RIGHT:
882 if (modifier & FBTK_MOD_RCTRL ||
883 modifier & FBTK_MOD_LCTRL) {
884 /* CTRL held */
886 NS_KEY_LINE_END) == false)
887 widget_scroll_x(gw, INT_MAX, true);
888
889 } else if (modifier & FBTK_MOD_RSHIFT ||
890 modifier & FBTK_MOD_LSHIFT) {
891 /* SHIFT held */
893 NS_KEY_WORD_RIGHT) == false)
895 gw->browser), false);
896
897 } else {
898 /* no modifier */
900 NS_KEY_RIGHT) == false)
901 widget_scroll_x(gw, 100, false);
902 }
903 break;
904
905 case NSFB_KEY_LEFT:
906 if (modifier & FBTK_MOD_RCTRL ||
907 modifier & FBTK_MOD_LCTRL) {
908 /* CTRL held */
910 NS_KEY_LINE_START) == false)
911 widget_scroll_x(gw, 0, true);
912
913 } else if (modifier & FBTK_MOD_RSHIFT ||
914 modifier & FBTK_MOD_LSHIFT) {
915 /* SHIFT held */
917 NS_KEY_WORD_LEFT) == false)
919 gw->browser), false);
920
921 } else {
922 /* no modifier */
924 NS_KEY_LEFT) == false)
925 widget_scroll_x(gw, -100, false);
926 }
927 break;
928
929 case NSFB_KEY_UP:
931 NS_KEY_UP) == false)
932 widget_scroll_y(gw, -100, false);
933 break;
934
935 case NSFB_KEY_DOWN:
937 NS_KEY_DOWN) == false)
938 widget_scroll_y(gw, 100, false);
939 break;
940
941 case NSFB_KEY_MINUS:
942 if (modifier & FBTK_MOD_RCTRL ||
943 modifier & FBTK_MOD_LCTRL) {
944 browser_window_set_scale(gw->bw, -0.1, false);
945 }
946 break;
947
948 case NSFB_KEY_EQUALS: /* PLUS */
949 if (modifier & FBTK_MOD_RCTRL ||
950 modifier & FBTK_MOD_LCTRL) {
951 browser_window_set_scale(gw->bw, 0.1, false);
952 }
953 break;
954
955 case NSFB_KEY_0:
956 if (modifier & FBTK_MOD_RCTRL ||
957 modifier & FBTK_MOD_LCTRL) {
958 browser_window_set_scale(gw->bw, 1.0, true);
959 }
960 break;
961
962 case NSFB_KEY_RSHIFT:
963 modifier |= FBTK_MOD_RSHIFT;
964 break;
965
966 case NSFB_KEY_LSHIFT:
967 modifier |= FBTK_MOD_LSHIFT;
968 break;
969
970 case NSFB_KEY_RCTRL:
971 modifier |= FBTK_MOD_RCTRL;
972 break;
973
974 case NSFB_KEY_LCTRL:
975 modifier |= FBTK_MOD_LCTRL;
976 break;
977
978 case NSFB_KEY_y:
979 case NSFB_KEY_z:
980 if (cbi->event->value.keycode == NSFB_KEY_z &&
981 (modifier & FBTK_MOD_RCTRL ||
982 modifier & FBTK_MOD_LCTRL) &&
983 (modifier & FBTK_MOD_RSHIFT ||
984 modifier & FBTK_MOD_LSHIFT)) {
985 /* Z pressed with CTRL and SHIFT held */
987 break;
988
989 } else if (cbi->event->value.keycode == NSFB_KEY_z &&
990 (modifier & FBTK_MOD_RCTRL ||
991 modifier & FBTK_MOD_LCTRL)) {
992 /* Z pressed with CTRL held */
994 break;
995
996 } else if (cbi->event->value.keycode == NSFB_KEY_y &&
997 (modifier & FBTK_MOD_RCTRL ||
998 modifier & FBTK_MOD_LCTRL)) {
999 /* Y pressed with CTRL held */
1001 break;
1002 }
1003 /* Z or Y pressed but not undo or redo; */
1005
1006 default:
1007 ucs4 = fbtk_keycode_to_ucs4(cbi->event->value.keycode,
1008 modifier);
1009 if (ucs4 != -1)
1010 browser_window_key_press(gw->bw, ucs4);
1011 break;
1012 }
1013 break;
1014
1015 case NSFB_EVENT_KEY_UP:
1016 switch (cbi->event->value.keycode) {
1017 case NSFB_KEY_RSHIFT:
1018 modifier &= ~FBTK_MOD_RSHIFT;
1019 break;
1020
1021 case NSFB_KEY_LSHIFT:
1022 modifier &= ~FBTK_MOD_LSHIFT;
1023 break;
1024
1025 case NSFB_KEY_RCTRL:
1026 modifier &= ~FBTK_MOD_RCTRL;
1027 break;
1028
1029 case NSFB_KEY_LCTRL:
1030 modifier &= ~FBTK_MOD_LCTRL;
1031 break;
1032
1033 default:
1034 break;
1035 }
1036 break;
1037
1038 default:
1039 break;
1040 }
1041
1042 return 0;
1043}
1044
1045static void
1047{
1048 struct browser_window *bw = gw->bw;
1049
1056}
1057
1058/* left icon click routine */
1059static int
1061{
1062 struct gui_window *gw = cbi->context;
1063 struct browser_window *bw = gw->bw;
1064
1065 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1066 return 0;
1067
1070
1072
1073 return 1;
1074}
1075
1076/* right arrow icon click routine */
1077static int
1079{
1080 struct gui_window *gw = cbi->context;
1081 struct browser_window *bw = gw->bw;
1082
1083 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1084 return 0;
1085
1088
1090 return 1;
1091
1092}
1093
1094/* reload icon click routine */
1095static int
1097{
1098 struct browser_window *bw = cbi->context;
1099
1100 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1101 return 0;
1102
1104 return 1;
1105}
1106
1107/* stop icon click routine */
1108static int
1110{
1111 struct browser_window *bw = cbi->context;
1112
1113 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1114 return 0;
1115
1117 return 0;
1118}
1119
1120static int
1122{
1123
1124 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1125 return 0;
1126
1127 map_osk();
1128
1129 return 0;
1130}
1131
1132/* close browser window icon click routine */
1133static int
1135{
1136 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1137 return 0;
1138
1139 fb_complete = true;
1140
1141 return 0;
1142}
1143
1144static int
1146{
1147 struct gui_window *gw = cbi->context;
1148
1149 switch (cbi->type) {
1150 case FBTK_CBT_SCROLLY:
1151 widget_scroll_y(gw, cbi->y, true);
1152 break;
1153
1154 case FBTK_CBT_SCROLLX:
1155 widget_scroll_x(gw, cbi->x, true);
1156 break;
1157
1158 default:
1159 break;
1160 }
1161 return 0;
1162}
1163
1164static int
1165fb_url_enter(void *pw, char *text)
1166{
1167 struct browser_window *bw = pw;
1168 nsurl *url;
1169 nserror error;
1170
1171 error = nsurl_create(text, &url);
1172 if (error != NSERROR_OK) {
1173 fb_warn_user("Errorcode:", messages_get_errorcode(error));
1174 } else {
1176 NULL, NULL, NULL);
1177 nsurl_unref(url);
1178 }
1179
1180 return 0;
1181}
1182
1183static int
1185{
1187 return 0;
1188}
1189
1190static int
1192{
1194 return 0;
1195}
1196
1197static int
1199{
1200 struct gui_window *gw = cbi->context;
1201
1202 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1203 return 0;
1204
1206
1207 return 0;
1208}
1209
1210
1211/** Create a toolbar window and populate it with buttons.
1212 *
1213 * The toolbar layout uses a character to define buttons type and position:
1214 * b - back
1215 * l - local history
1216 * f - forward
1217 * s - stop
1218 * r - refresh
1219 * u - url bar expands to fit remaining space
1220 * t - throbber/activity indicator
1221 * c - close the current window
1222 *
1223 * The default layout is "blfsrut" there should be no more than a
1224 * single url bar entry or behaviour will be undefined.
1225 *
1226 * @param gw Parent window
1227 * @param toolbar_height The height in pixels of the toolbar
1228 * @param padding The padding in pixels round each element of the toolbar
1229 * @param frame_col Frame colour.
1230 * @param toolbar_layout A string defining which buttons and controls
1231 * should be added to the toolbar. May be empty
1232 * string to disable the bar..
1233 *
1234 */
1235static fbtk_widget_t *
1237 int toolbar_height,
1238 int padding,
1239 colour frame_col,
1240 const char *toolbar_layout)
1241{
1243 fbtk_widget_t *widget;
1244
1245 int xpos; /* The position of the next widget. */
1246 int xlhs = 0; /* extent of the left hand side widgets */
1247 int xdir = 1; /* the direction of movement + or - 1 */
1248 const char *itmtype; /* type of the next item */
1249
1250 if (toolbar_layout == NULL) {
1251 toolbar_layout = NSFB_TOOLBAR_DEFAULT_LAYOUT;
1252 }
1253
1254 NSLOG(netsurf, INFO, "Using toolbar layout %s", toolbar_layout);
1255
1256 itmtype = toolbar_layout;
1257
1258 /* check for the toolbar being disabled */
1259 if ((*itmtype == 0) || (*itmtype == 'q')) {
1260 return NULL;
1261 }
1262
1263 toolbar = fbtk_create_window(gw->window, 0, 0, 0,
1264 toolbar_height,
1265 frame_col);
1266
1267 if (toolbar == NULL) {
1268 return NULL;
1269 }
1270
1274 NULL);
1275
1276
1277 xpos = padding;
1278
1279 /* loop proceeds creating widget on the left hand side until
1280 * it runs out of layout or encounters a url bar declaration
1281 * wherupon it works backwards from the end of the layout
1282 * untill the space left is for the url bar
1283 */
1284 while ((itmtype >= toolbar_layout) &&
1285 (*itmtype != 0) &&
1286 (xdir !=0)) {
1287
1288 NSLOG(netsurf, INFO, "toolbar adding %c", *itmtype);
1289
1290
1291 switch (*itmtype) {
1292
1293 case 'b': /* back */
1294 widget = fbtk_create_button(toolbar,
1295 (xdir == 1) ? xpos :
1296 xpos - left_arrow.width,
1297 padding,
1299 -padding,
1300 frame_col,
1301 &left_arrow,
1303 gw);
1304 gw->back = widget; /* keep reference */
1305 break;
1306
1307 case 'l': /* local history */
1308 widget = fbtk_create_button(toolbar,
1309 (xdir == 1) ? xpos :
1310 xpos - history_image.width,
1311 padding,
1313 -padding,
1314 frame_col,
1317 gw);
1318 gw->history = widget;
1319 break;
1320
1321 case 'f': /* forward */
1322 widget = fbtk_create_button(toolbar,
1323 (xdir == 1)?xpos :
1324 xpos - right_arrow.width,
1325 padding,
1327 -padding,
1328 frame_col,
1329 &right_arrow,
1331 gw);
1332 gw->forward = widget;
1333 break;
1334
1335 case 'c': /* close the current window */
1336 widget = fbtk_create_button(toolbar,
1337 (xdir == 1)?xpos :
1338 xpos - stop_image_g.width,
1339 padding,
1341 -padding,
1342 frame_col,
1343 &stop_image_g,
1345 gw->bw);
1346 gw->close = widget;
1347 break;
1348
1349 case 's': /* stop */
1350 widget = fbtk_create_button(toolbar,
1351 (xdir == 1)?xpos :
1352 xpos - stop_image.width,
1353 padding,
1355 -padding,
1356 frame_col,
1357 &stop_image,
1359 gw->bw);
1360 gw->stop = widget;
1361 break;
1362
1363 case 'r': /* reload */
1364 widget = fbtk_create_button(toolbar,
1365 (xdir == 1)?xpos :
1366 xpos - reload.width,
1367 padding,
1368 reload.width,
1369 -padding,
1370 frame_col,
1371 &reload,
1373 gw->bw);
1374 gw->reload = widget;
1375 break;
1376
1377 case 't': /* throbber/activity indicator */
1378 widget = fbtk_create_bitmap(toolbar,
1379 (xdir == 1)?xpos :
1380 xpos - throbber0.width,
1381 padding,
1383 -padding,
1384 frame_col,
1385 &throbber0);
1386 gw->throbber = widget;
1387 break;
1388
1389
1390 case 'u': /* url bar*/
1391 if (xdir == -1) {
1392 /* met the u going backwards add url
1393 * now we know available extent
1394 */
1395
1397 xlhs,
1398 padding,
1399 xpos - xlhs,
1400 -padding,
1403 true,
1405 gw->bw);
1406
1407 fbtk_set_handler(widget,
1409 fb_url_move, gw->bw);
1410
1411 gw->url = widget; /* keep reference */
1412
1413 /* toolbar is complete */
1414 xdir = 0;
1415 break;
1416 }
1417 /* met url going forwards, note position and
1418 * reverse direction
1419 */
1420 itmtype = toolbar_layout + strlen(toolbar_layout);
1421 xdir = -1;
1422 xlhs = xpos;
1423 xpos = (2 * fbtk_get_width(toolbar));
1424 widget = toolbar;
1425 break;
1426
1427 default:
1428 widget = NULL;
1429 xdir = 0;
1430 NSLOG(netsurf, INFO,
1431 "Unknown element %c in toolbar layout",
1432 *itmtype);
1433 break;
1434
1435 }
1436
1437 if (widget != NULL) {
1438 xpos += (xdir * (fbtk_get_width(widget) + padding));
1439 }
1440
1441 NSLOG(netsurf, INFO, "xpos is %d", xpos);
1442
1443 itmtype += xdir;
1444 }
1445
1447
1448 return toolbar;
1449}
1450
1451
1452/** Resize a toolbar.
1453 *
1454 * @param gw Parent window
1455 * @param toolbar_height The height in pixels of the toolbar
1456 * @param padding The padding in pixels round each element of the toolbar
1457 * @param toolbar_layout A string defining which buttons and controls
1458 * should be added to the toolbar. May be empty
1459 * string to disable the bar.
1460 */
1461static void
1463 int toolbar_height,
1464 int padding,
1465 const char *toolbar_layout)
1466{
1467 fbtk_widget_t *widget;
1468
1469 int xpos; /* The position of the next widget. */
1470 int xlhs = 0; /* extent of the left hand side widgets */
1471 int xdir = 1; /* the direction of movement + or - 1 */
1472 const char *itmtype; /* type of the next item */
1473 int x = 0, y = 0, w = 0, h = 0;
1474
1475 if (gw->toolbar == NULL) {
1476 return;
1477 }
1478
1479 if (toolbar_layout == NULL) {
1480 toolbar_layout = NSFB_TOOLBAR_DEFAULT_LAYOUT;
1481 }
1482
1483 itmtype = toolbar_layout;
1484
1485 if (*itmtype == 0) {
1486 return;
1487 }
1488
1489 fbtk_set_pos_and_size(gw->toolbar, 0, 0, 0, toolbar_height);
1490
1491 xpos = padding;
1492
1493 /* loop proceeds creating widget on the left hand side until
1494 * it runs out of layout or encounters a url bar declaration
1495 * wherupon it works backwards from the end of the layout
1496 * untill the space left is for the url bar
1497 */
1498 while (itmtype >= toolbar_layout && xdir != 0) {
1499
1500 switch (*itmtype) {
1501 case 'b': /* back */
1502 widget = gw->back;
1503 x = (xdir == 1) ? xpos : xpos - left_arrow.width;
1504 y = padding;
1505 w = left_arrow.width;
1506 h = -padding;
1507 break;
1508
1509 case 'l': /* local history */
1510 widget = gw->history;
1511 x = (xdir == 1) ? xpos : xpos - history_image.width;
1512 y = padding;
1513 w = history_image.width;
1514 h = -padding;
1515 break;
1516
1517 case 'f': /* forward */
1518 widget = gw->forward;
1519 x = (xdir == 1) ? xpos : xpos - right_arrow.width;
1520 y = padding;
1521 w = right_arrow.width;
1522 h = -padding;
1523 break;
1524
1525 case 'c': /* close the current window */
1526 widget = gw->close;
1527 x = (xdir == 1) ? xpos : xpos - stop_image_g.width;
1528 y = padding;
1529 w = stop_image_g.width;
1530 h = -padding;
1531 break;
1532
1533 case 's': /* stop */
1534 widget = gw->stop;
1535 x = (xdir == 1) ? xpos : xpos - stop_image.width;
1536 y = padding;
1537 w = stop_image.width;
1538 h = -padding;
1539 break;
1540
1541 case 'r': /* reload */
1542 widget = gw->reload;
1543 x = (xdir == 1) ? xpos : xpos - reload.width;
1544 y = padding;
1545 w = reload.width;
1546 h = -padding;
1547 break;
1548
1549 case 't': /* throbber/activity indicator */
1550 widget = gw->throbber;
1551 x = (xdir == 1) ? xpos : xpos - throbber0.width;
1552 y = padding;
1553 w = throbber0.width;
1554 h = -padding;
1555 break;
1556
1557
1558 case 'u': /* url bar*/
1559 if (xdir == -1) {
1560 /* met the u going backwards add url
1561 * now we know available extent
1562 */
1563 widget = gw->url;
1564 x = xlhs;
1565 y = padding;
1566 w = xpos - xlhs;
1567 h = -padding;
1568
1569 /* toolbar is complete */
1570 xdir = 0;
1571 break;
1572 }
1573 /* met url going forwards, note position and
1574 * reverse direction
1575 */
1576 itmtype = toolbar_layout + strlen(toolbar_layout);
1577 xdir = -1;
1578 xlhs = xpos;
1579 w = fbtk_get_width(gw->toolbar);
1580 xpos = 2 * w;
1581 widget = gw->toolbar;
1582 break;
1583
1584 default:
1585 widget = NULL;
1586 break;
1587
1588 }
1589
1590 if (widget != NULL) {
1591 if (widget != gw->toolbar)
1592 fbtk_set_pos_and_size(widget, x, y, w, h);
1593 xpos += xdir * (w + padding);
1594 }
1595
1596 itmtype += xdir;
1597 }
1598}
1599
1600/** Routine called when "stripped of focus" event occours for browser widget.
1601 *
1602 * @param widget The widget reciving "stripped of focus" event.
1603 * @param cbi The callback parameters.
1604 * @return The callback result.
1605 */
1606static int
1608{
1609 fbtk_set_caret(widget, false, 0, 0, 0, NULL);
1610
1611 return 0;
1612}
1613
1614static void
1615create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_width)
1616{
1617 struct browser_widget_s *browser_widget;
1618 browser_widget = calloc(1, sizeof(struct browser_widget_s));
1619
1621 0,
1622 toolbar_height,
1623 -furniture_width,
1624 -furniture_width,
1625 browser_widget);
1626
1633}
1634
1635static void
1636resize_browser_widget(struct gui_window *gw, int x, int y,
1637 int width, int height)
1638{
1641}
1642
1643static void
1644create_normal_browser_window(struct gui_window *gw, int furniture_width)
1645{
1646 fbtk_widget_t *widget;
1648 int statusbar_width = 0;
1649 int toolbar_height = nsoption_int(fb_toolbar_size);
1650
1651 NSLOG(netsurf, INFO, "Normal window");
1652
1653 gw->window = fbtk_create_window(fbtk, 0, 0, 0, 0, 0);
1654
1655 statusbar_width = nsoption_int(toolbar_status_size) *
1656 fbtk_get_width(gw->window) / 10000;
1657
1658 /* toolbar */
1659 toolbar = create_toolbar(gw,
1660 toolbar_height,
1661 2,
1663 nsoption_charp(fb_toolbar_layout));
1664 gw->toolbar = toolbar;
1665
1666 /* set the actually created toolbar height */
1667 if (toolbar != NULL) {
1668 toolbar_height = fbtk_get_height(toolbar);
1669 } else {
1670 toolbar_height = 0;
1671 }
1672
1673 /* status bar */
1674 gw->status = fbtk_create_text(gw->window,
1675 0,
1676 fbtk_get_height(gw->window) - furniture_width,
1677 statusbar_width, furniture_width,
1679 false);
1681
1682 NSLOG(netsurf, INFO, "status bar %p at %d,%d", gw->status,
1684
1685 /* create horizontal scrollbar */
1687 statusbar_width,
1688 fbtk_get_height(gw->window) - furniture_width,
1689 fbtk_get_width(gw->window) - statusbar_width - furniture_width,
1690 furniture_width,
1694 gw);
1695
1696 /* fill bottom right area */
1697
1698 if (nsoption_bool(fb_osk) == true) {
1699 widget = fbtk_create_text_button(gw->window,
1700 fbtk_get_width(gw->window) - furniture_width,
1701 fbtk_get_height(gw->window) - furniture_width,
1702 furniture_width,
1703 furniture_width,
1706 NULL);
1707 widget = fbtk_create_button(gw->window,
1708 fbtk_get_width(gw->window) - furniture_width,
1709 fbtk_get_height(gw->window) - furniture_width,
1710 furniture_width,
1711 furniture_width,
1713 &osk_image,
1715 NULL);
1716 } else {
1717 widget = fbtk_create_fill(gw->window,
1718 fbtk_get_width(gw->window) - furniture_width,
1719 fbtk_get_height(gw->window) - furniture_width,
1720 furniture_width,
1721 furniture_width,
1723
1725 }
1726
1727 gw->bottom_right = widget;
1728
1729 /* create vertical scrollbar */
1731 fbtk_get_width(gw->window) - furniture_width,
1732 toolbar_height,
1733 furniture_width,
1734 fbtk_get_height(gw->window) - toolbar_height - furniture_width,
1738 gw);
1739
1740 /* browser widget */
1741 create_browser_widget(gw, toolbar_height, nsoption_int(fb_furniture_size));
1742
1743 /* Give browser_window's user widget input focus */
1745}
1746
1747static void
1748resize_normal_browser_window(struct gui_window *gw, int furniture_width)
1749{
1750 bool resized;
1751 int width, height;
1752 int statusbar_width;
1753 int toolbar_height = fbtk_get_height(gw->toolbar);
1754
1755 /* Resize the main window widget */
1756 resized = fbtk_set_pos_and_size(gw->window, 0, 0, 0, 0);
1757 if (!resized)
1758 return;
1759
1762 statusbar_width = nsoption_int(toolbar_status_size) * width / 10000;
1763
1764 resize_toolbar(gw, toolbar_height, 2,
1765 nsoption_charp(fb_toolbar_layout));
1767 0, height - furniture_width,
1768 statusbar_width, furniture_width);
1770 statusbar_width, height - furniture_width,
1771 width - statusbar_width - furniture_width,
1772 furniture_width);
1774 width - furniture_width, height - furniture_width,
1775 furniture_width, furniture_width);
1777 width - furniture_width,
1778 toolbar_height, furniture_width,
1779 height - toolbar_height - furniture_width);
1781 0, toolbar_height,
1782 width - furniture_width,
1783 height - furniture_width - toolbar_height);
1784}
1785
1787{
1788 gw->next = NULL;
1789 gw->prev = NULL;
1790
1791 if (window_list == NULL) {
1792 window_list = gw;
1793 } else {
1794 window_list->prev = gw;
1795 gw->next = window_list;
1796 window_list = gw;
1797 }
1798}
1799
1801{
1802 struct gui_window *list;
1803
1804 for (list = window_list; list != NULL; list = list->next) {
1805 if (list != gw)
1806 continue;
1807
1808 if (list == window_list) {
1809 window_list = list->next;
1810 if (window_list != NULL)
1811 window_list->prev = NULL;
1812 } else {
1813 list->prev->next = list->next;
1814 if (list->next != NULL) {
1815 list->next->prev = list->prev;
1816 }
1817 }
1818 break;
1819 }
1820}
1821
1822
1823static struct gui_window *
1825 struct gui_window *existing,
1827{
1828 struct gui_window *gw;
1829
1830 gw = calloc(1, sizeof(struct gui_window));
1831
1832 if (gw == NULL)
1833 return NULL;
1834
1835 /* associate the gui window with the underlying browser window
1836 */
1837 gw->bw = bw;
1838
1839 create_normal_browser_window(gw, nsoption_int(fb_furniture_size));
1840
1841 /* map and request redraw of gui window */
1842 fbtk_set_mapping(gw->window, true);
1843
1844 /* Add it to the window list */
1846
1847 return gw;
1848}
1849
1850static void
1852{
1854
1856
1857 free(gw);
1858}
1859
1860
1861/**
1862 * Invalidates an area of a framebuffer browser window
1863 *
1864 * \param g The netsurf window being invalidated.
1865 * \param rect area to redraw or NULL for the entire window area
1866 * \return NSERROR_OK on success or appropriate error code
1867 */
1868static nserror
1870{
1871 struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
1872
1873 if (rect != NULL) {
1875 rect->x0 - bwidget->scrollx,
1876 rect->y0 - bwidget->scrolly,
1877 rect->x1 - bwidget->scrollx,
1878 rect->y1 - bwidget->scrolly);
1879 } else {
1881 0,
1882 0,
1885 }
1886 return NSERROR_OK;
1887}
1888
1889static bool
1890gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
1891{
1892 struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
1893
1894 *sx = bwidget->scrollx;
1895 *sy = bwidget->scrolly;
1896
1897 return true;
1898}
1899
1900/**
1901 * Set the scroll position of a framebuffer browser window.
1902 *
1903 * Scrolls the viewport to ensure the specified rectangle of the
1904 * content is shown. The framebuffer implementation scrolls the contents so
1905 * the specified point in the content is at the top of the viewport.
1906 *
1907 * \param gw gui_window to scroll
1908 * \param rect The rectangle to ensure is shown.
1909 * \return NSERROR_OK on success or apropriate error code.
1910 */
1911static nserror
1912gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
1913{
1914 struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
1915
1916 assert(bwidget);
1917
1918 widget_scroll_x(gw, rect->x0, true);
1919 widget_scroll_y(gw, rect->y0, true);
1920
1921 return NSERROR_OK;
1922}
1923
1924
1925/**
1926 * Find the current dimensions of a framebuffer browser window content area.
1927 *
1928 * \param gw The gui window to measure content area of.
1929 * \param width receives width of window
1930 * \param height receives height of window
1931 * \return NSERROR_OK on sucess and width and height updated.
1932 */
1933static nserror
1935{
1938
1939 return NSERROR_OK;
1940}
1941
1942static void
1944{
1945 int w, h;
1946 browser_window_get_extents(gw->bw, true, &w, &h);
1947
1949 fbtk_get_width(gw->browser), 100);
1950
1952 fbtk_get_height(gw->browser), 100);
1953}
1954
1955static void
1957{
1959}
1960
1961static void
1963{
1964 switch (shape) {
1965 case GUI_POINTER_POINT:
1967 break;
1968
1969 case GUI_POINTER_CARET:
1971 break;
1972
1973 case GUI_POINTER_MENU:
1975 break;
1976
1979 break;
1980
1981 case GUI_POINTER_MOVE:
1983 break;
1984
1985 default:
1987 break;
1988 }
1989}
1990
1991static nserror
1993{
1994 fbtk_set_text(g->url, nsurl_access(url));
1995 return NSERROR_OK;
1996}
1997
1998static void
2000{
2001 struct gui_window *g = pw;
2002 struct fbtk_bitmap *image;
2003
2004 switch (g->throbber_index) {
2005 case 0:
2006 image = &throbber1;
2007 g->throbber_index = 1;
2008 break;
2009
2010 case 1:
2011 image = &throbber2;
2012 g->throbber_index = 2;
2013 break;
2014
2015 case 2:
2016 image = &throbber3;
2017 g->throbber_index = 3;
2018 break;
2019
2020 case 3:
2021 image = &throbber4;
2022 g->throbber_index = 4;
2023 break;
2024
2025 case 4:
2026 image = &throbber5;
2027 g->throbber_index = 5;
2028 break;
2029
2030 case 5:
2031 image = &throbber6;
2032 g->throbber_index = 6;
2033 break;
2034
2035 case 6:
2036 image = &throbber7;
2037 g->throbber_index = 7;
2038 break;
2039
2040 case 7:
2041 image = &throbber8;
2042 g->throbber_index = 0;
2043 break;
2044
2045 default:
2046 return;
2047 }
2048
2049 if (g->throbber_index >= 0) {
2050 fbtk_set_bitmap(g->throbber, image);
2052 }
2053}
2054
2055static void
2057{
2058 g->throbber_index = 0;
2060}
2061
2062static void
2064{
2065 gw->throbber_index = -1;
2067
2069
2070}
2071
2072static void
2074{
2075 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
2076 int c_x, c_y, c_h;
2077
2078 if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
2079 /* browser window already had caret:
2080 * redraw its area to remove it first */
2081 fb_queue_redraw(widget,
2082 c_x - bwidget->scrollx,
2083 c_y - bwidget->scrolly,
2084 c_x + 1 - bwidget->scrollx,
2085 c_y + c_h - bwidget->scrolly);
2086 }
2087}
2088
2089static void
2090gui_window_place_caret(struct gui_window *g, int x, int y, int height,
2091 const struct rect *clip)
2092{
2093 struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
2094
2095 /* set new pos */
2096 fbtk_set_caret(g->browser, true, x, y, height,
2098
2099 /* redraw new caret pos */
2101 x - bwidget->scrollx,
2102 y - bwidget->scrolly,
2103 x + 1 - bwidget->scrollx,
2104 y + height - bwidget->scrolly);
2105}
2106
2107static void
2109{
2110 int c_x, c_y, c_h;
2111
2112 if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
2113 /* browser window owns the caret, so can remove it */
2114 fbtk_set_caret(g->browser, false, 0, 0, 0, NULL);
2115 }
2116}
2117
2118/**
2119 * process miscellaneous window events
2120 *
2121 * \param gw The window receiving the event.
2122 * \param event The event code.
2123 * \return NSERROR_OK when processed ok
2124 */
2125static nserror
2127{
2128 switch (event) {
2131 break;
2132
2135 break;
2136
2139 break;
2140
2143 break;
2144
2145 default:
2146 break;
2147 }
2148 return NSERROR_OK;
2149}
2150
2153 .destroy = gui_window_destroy,
2154 .invalidate = fb_window_invalidate_area,
2155 .get_scroll = gui_window_get_scroll,
2156 .set_scroll = gui_window_set_scroll,
2157 .get_dimensions = gui_window_get_dimensions,
2158 .event = gui_window_event,
2159
2160 .set_url = gui_window_set_url,
2161 .set_status = gui_window_set_status,
2162 .set_pointer = gui_window_set_pointer,
2163 .place_caret = gui_window_place_caret,
2164};
2165
2166
2169
2170 .quit = gui_quit,
2171};
2172
2173/**
2174 * Entry point from OS.
2175 *
2176 * /param argc The number of arguments in the string vector.
2177 * /param argv The argument string vector.
2178 * /return The return code to the OS
2179 */
2180int
2181main(int argc, char** argv)
2182{
2183 struct browser_window *bw;
2184 char *options;
2185 char *messages;
2186 nsurl *url;
2187 nserror ret;
2188 nsfb_t *nsfb;
2189 struct netsurf_table framebuffer_table = {
2191 .window = &framebuffer_window_table,
2192 .corewindow = framebuffer_core_window_table,
2193 .clipboard = framebuffer_clipboard_table,
2194 .fetch = framebuffer_fetch_table,
2195 .utf8 = framebuffer_utf8_table,
2196 .bitmap = framebuffer_bitmap_table,
2197 .layout = framebuffer_layout_table,
2198 };
2199
2200 ret = netsurf_register(&framebuffer_table);
2201 if (ret != NSERROR_OK) {
2202 die("NetSurf operation table failed registration");
2203 }
2204
2205 respaths = fb_init_resource_path(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH);
2206
2207 /* initialise logging. Not fatal if it fails but not much we
2208 * can do about it either.
2209 */
2210 nslog_init(nslog_stream_configure, &argc, argv);
2211
2212 /* user options setup */
2214 if (ret != NSERROR_OK) {
2215 die("Options failed to initialise");
2216 }
2217 options = filepath_find(respaths, "Choices");
2219 free(options);
2220 nsoption_commandline(&argc, argv, nsoptions);
2221
2222 /* message init */
2223 messages = filepath_find(respaths, "Messages");
2224 ret = messages_add_from_file(messages);
2225 free(messages);
2226 if (ret != NSERROR_OK) {
2227 fprintf(stderr, "Message translations failed to load\n");
2228 }
2229
2230 /* common initialisation */
2231 ret = netsurf_init(NULL);
2232 if (ret != NSERROR_OK) {
2233 die("NetSurf failed to initialise");
2234 }
2235
2236 /* Override, since we have no support for non-core SELECT menu */
2237 nsoption_set_bool(core_select_menu, true);
2238
2239 if (process_cmdline(argc,argv) != true)
2240 die("unable to process command line.\n");
2241
2243 if (nsfb == NULL)
2244 die("Unable to initialise framebuffer");
2245
2247
2248 if (fb_font_init() == false)
2249 die("Unable to initialise the font system");
2250
2251 fbtk = fbtk_init(nsfb);
2252
2254
2255 urldb_load_cookies(nsoption_charp(cookie_file));
2256
2257 /* create an initial browser window */
2258
2259 NSLOG(netsurf, INFO, "calling browser_window_create");
2260
2261 ret = nsurl_create(feurl, &url);
2262 if (ret == NSERROR_OK) {
2264 url,
2265 NULL,
2266 NULL,
2267 &bw);
2268 nsurl_unref(url);
2269 }
2270 if (ret != NSERROR_OK) {
2271 fb_warn_user("Errorcode:", messages_get_errorcode(ret));
2272 } else {
2274
2276 }
2277
2278 netsurf_exit();
2279
2280 if (fb_font_finalise() == false)
2281 NSLOG(netsurf, INFO, "Font finalisation failed.");
2282
2283 /* finalise options */
2285
2286 /* finalise logging */
2288
2289 return 0;
2290}
2291
2293{
2294 struct gui_window *gw;
2295 nsfb_t *nsfb = fbtk_get_nsfb(root);
2296
2297 /* Enforce a minimum */
2298 if (width < 300)
2299 width = 300;
2300 if (height < 200)
2301 height = 200;
2302
2303 if (framebuffer_resize(nsfb, width, height, febpp) == false) {
2304 return;
2305 }
2306
2308
2309 fewidth = width;
2310 feheight = height;
2311
2312 for (gw = window_list; gw != NULL; gw = gw->next) {
2314 nsoption_int(fb_furniture_size));
2315 }
2316
2318}
2319
2320
2321/*
2322 * Local Variables:
2323 * c-basic-offset:8
2324 * End:
2325 */
int main(int argc, char **argv)
Normal entry point from OS.
Definition: gui.c:6543
char options[PATH_MAX]
Definition: gui.c:91
struct gui_window * input_window
Definition: gui.c:74
void gui_window_destroy(struct gui_window *gw)
Destroy previously created gui window.
Definition: gui.c:252
void gui_window_set_pointer(struct gui_window *gw, gui_pointer_shape shape)
set the pointer shape
Definition: gui.c:482
struct gui_window * window_list
Definition: gui.c:75
bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy)
Definition: gui.c:414
int schedule_run(void)
Process events up to current time.
Definition: schedule.c:137
nserror browser_window_history_forward(struct browser_window *bw, bool new_window)
Go forward in the history.
nserror browser_window_history_back(struct browser_window *bw, bool new_window)
Go back in the history.
Interface to browser history operations.
Browser window creation and manipulation interface.
nserror browser_window_schedule_reformat(struct browser_window *bw)
Reformat the browser window contents in a safe context.
nserror browser_window_navigate(struct browser_window *bw, struct nsurl *url, struct nsurl *referrer, enum browser_window_nav_flags flags, char *post_urlenc, struct fetch_multipart_data *post_multipart, struct hlcache_handle *parent)
Start fetching a page in a browser window.
bool browser_window_redraw(struct browser_window *bw, int x, int y, const struct rect *clip, const struct redraw_context *ctx)
Redraw an area of a window.
bool browser_window_back_available(struct browser_window *bw)
Check availability of Back action for a given browser window.
void browser_window_mouse_click(struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse clicks in a browser window.
bool browser_window_scroll_at_point(struct browser_window *bw, int x, int y, int scrx, int scry)
Send a scroll request to a browser window at a particular point.
void browser_window_destroy(struct browser_window *bw)
Close and destroy a browser window.
nserror browser_window_reload(struct browser_window *bw, bool all)
Reload the page in a browser window.
bool browser_window_forward_available(struct browser_window *bw)
Check availability of Forward action for a given browser window.
nserror browser_window_get_extents(struct browser_window *bw, bool scaled, int *width, int *height)
Get a browser window's content extents.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
void browser_window_stop(struct browser_window *bw)
Stop all fetching activity in a browser window.
nserror browser_window_set_scale(struct browser_window *bw, float scale, bool absolute)
Sets the scale of a browser window.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
@ BW_NAVIGATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
void browser_window_mouse_track(struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle non-click mouse action in a browser window.
Fetching of data from a URL (interface).
Unified cookie database public interface.
void urldb_save_cookies(const char *filename)
Save persistent cookies to file.
Definition: urldb.c:4448
void urldb_load_cookies(const char *filename)
Load a cookie file into the database.
Definition: urldb.c:4281
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_BAD_PARAMETER
Bad Parameter.
Definition: errors.h:48
@ NSERROR_OK
No error.
Definition: errors.h:30
fbtk_callback fbtk_set_handler(fbtk_widget_t *widget, fbtk_callback_type cbt, fbtk_callback cb, void *pw)
Set a callback handler.
Definition: fbtk.c:693
int fbtk_set_mapping(fbtk_widget_t *widget, bool mapped)
Map a widget and request it is redrawn.
Definition: fbtk.c:127
#define FB_COLOUR_WHITE
Definition: fbtk.h:27
int fbtk_destroy_widget(fbtk_widget_t *widget)
Destroy a widget and all its descendants.
Definition: fbtk.c:282
bool fbtk_get_redraw_pending(fbtk_widget_t *widget)
Determine if there are any redraws pending for a widget.
Definition: fbtk.c:611
@ FBTK_CBT_POINTERMOVE
Definition: fbtk.h:41
@ FBTK_CBT_INPUT
Definition: fbtk.h:40
@ FBTK_CBT_REDRAW
Definition: fbtk.h:44
@ FBTK_CBT_SCROLLY
Definition: fbtk.h:38
@ FBTK_CBT_SCROLLX
Definition: fbtk.h:37
@ FBTK_CBT_POINTERENTER
Definition: fbtk.h:43
@ FBTK_CBT_DESTROY
Definition: fbtk.h:45
@ FBTK_CBT_CLICK
Definition: fbtk.h:39
@ FBTK_CBT_STRIP_FOCUS
Definition: fbtk.h:47
fbtk_widget_t * fbtk_create_writable_text(fbtk_widget_t *window, int x, int y, int width, int height, colour bg, colour fg, bool outline, fbtk_enter_t enter, void *pw)
Create a writable text widget.
Definition: text.c:606
bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int height)
Change the widget's position and size.
Definition: fbtk.c:209
fbtk_widget_t * fbtk_create_vscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg, fbtk_callback callback, void *context)
Create a vertical scroll widget.
Definition: scroll.c:224
void * fbtk_get_userpw(fbtk_widget_t *widget)
Get the user context from a widget.
Definition: user.c:32
void fbtk_request_redraw(fbtk_widget_t *widget)
Indicate a widget should be redrawn.
Definition: fbtk.c:82
void fbtk_enable_oskb(fbtk_widget_t *widget)
enable the on screen keyboard for input
Definition: osk.c:138
int fbtk_get_absx(fbtk_widget_t *widget)
Get a widget's absolute horizontal screen co-ordinate.
Definition: fbtk.c:430
#define FB_COLOUR_BLACK
Definition: fbtk.h:26
#define FB_SCROLL_COLOUR
Definition: fbtk.h:24
int fbtk_get_width(fbtk_widget_t *widget)
Get a widget's width.
Definition: fbtk.c:467
bool fbtk_tgrab_pointer(fbtk_widget_t *widget)
Toggle pointer grab.
Definition: event.c:95
fbtk_modifier_type
Key modifier status.
Definition: fbtk.h:75
@ FBTK_MOD_LSHIFT
Definition: fbtk.h:77
@ FBTK_MOD_RCTRL
Definition: fbtk.h:80
@ FBTK_MOD_RSHIFT
Definition: fbtk.h:78
@ FBTK_MOD_LCTRL
Definition: fbtk.h:79
@ FBTK_MOD_CLEAR
Definition: fbtk.h:76
void fbtk_set_focus(fbtk_widget_t *widget)
Give widget input focus.
Definition: fbtk.c:781
fbtk_widget_t * fbtk_create_fill(fbtk_widget_t *window, int x, int y, int width, int height, colour c)
Create a filled rectangle.
Definition: fill.c:59
fbtk_widget_t * fbtk_create_hscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg, fbtk_callback callback, void *context)
Create a horizontal scroll widget.
Definition: scroll.c:463
bool fbtk_set_scroll_parameters(fbtk_widget_t *widget, int min, int max, int thumb, int page)
Set scoll widget parameters.
Definition: scroll.c:535
#define FB_FRAME_COLOUR
Definition: fbtk.h:25
void fbtk_reposition_hscroll(fbtk_widget_t *scrollh, int x, int y, int width, int height)
Move and/or resize a horizontal scroll widget.
Definition: scroll.c:515
fbtk_widget_t * fbtk_create_user(fbtk_widget_t *window, int x, int y, int width, int height, void *pw)
Create a user widget.
Definition: user.c:43
bool fbtk_set_scroll_position(fbtk_widget_t *widget, int pos)
set scroll widget position.
Definition: scroll.c:565
void map_osk(void)
show the osk.
Definition: osk.c:189
bool fbtk_event(fbtk_widget_t *root, nsfb_event_t *event, int timeout)
Retrive events from the framebuffer input.
Definition: event.c:188
fbtk_widget_t * fbtk_init(nsfb_t *fb)
Initialise widget toolkit.
Definition: fbtk.c:814
fbtk_widget_t * fbtk_create_window(fbtk_widget_t *parent, int x, int y, int width, int height, colour bg)
Create a window widget.
Definition: window.c:66
fbtk_widget_t * fbtk_create_text_button(fbtk_widget_t *window, int x, int y, int width, int height, colour bg, colour fg, fbtk_callback click, void *pw)
Create a button with text.
Definition: text.c:639
fbtk_widget_t * fbtk_create_text(fbtk_widget_t *window, int x, int y, int width, int height, colour bg, colour fg, bool outline)
Create a text widget.
Definition: text.c:581
int fbtk_keycode_to_ucs4(int code, fbtk_modifier_type mods)
Convert a framebuffer keycode to ucs4.
Definition: event.c:301
fbtk_widget_t * fbtk_create_bitmap(fbtk_widget_t *window, int x, int y, int width, int height, colour c, struct fbtk_bitmap *image)
Create a bitmap widget.
Definition: bitmap.c:84
bool fbtk_clip_to_widget(fbtk_widget_t *widget, bbox_t *restrict box)
clip a bounding box to a widgets area.
Definition: fbtk.c:379
void fbtk_set_text(fbtk_widget_t *widget, const char *text)
Change the text of a text widget.
Definition: text.c:542
int fbtk_get_absy(fbtk_widget_t *widget)
Get a widget's absolute vertical screen co-ordinate.
Definition: fbtk.c:445
void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height, void(*remove_caret)(fbtk_widget_t *widget))
Set caret owner and position.
Definition: fbtk.c:252
nsfb_t * fbtk_get_nsfb(fbtk_widget_t *widget)
Retrieve the framebuffer library handle from toolkit widget.
Definition: fbtk.c:802
void fbtk_reposition_vscroll(fbtk_widget_t *scrollv, int x, int y, int width, int height)
Move and/or resize a vertical scroll widget.
Definition: scroll.c:280
int fbtk_redraw(fbtk_widget_t *widget)
Perform any pending widget redraws.
Definition: fbtk.c:669
fbtk_widget_t * fbtk_create_button(fbtk_widget_t *window, int x, int y, int width, int height, colour c, struct fbtk_bitmap *image, fbtk_callback click, void *pw)
Create a button widget with an image.
Definition: bitmap.c:107
int fbtk_get_height(fbtk_widget_t *widget)
Get a widget's height.
Definition: fbtk.c:460
void fbtk_set_bitmap(fbtk_widget_t *widget, struct fbtk_bitmap *image)
Change the bitmap in a widget.
Definition: bitmap.c:72
bool fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height)
Get a widget caret pos, if it owns caret.
Definition: fbtk.c:494
static struct directory * root
Definition: filename.c:55
char * filepath_find(char **respathv, const char *filename)
Searches an array of resource paths for a file.
Definition: filepath.c:129
Utility routines to obtain paths to file resources.
const char * type
Definition: filetype.cpp:44
struct gui_clipboard_table * framebuffer_clipboard_table
Definition: clipboard.c:105
struct core_window_table * framebuffer_core_window_table
Definition: corewindow.c:204
char ** fb_init_resource_path(const char *resource_path)
Create an array of valid paths to search for resources.
Definition: findfile.c:131
static fbtk_widget_t * create_toolbar(struct gui_window *gw, int toolbar_height, int padding, colour frame_col, const char *toolbar_layout)
Create a toolbar window and populate it with buttons.
Definition: gui.c:1236
struct gui_window * search_current_window
Definition: gui.c:68
static int feheight
Definition: gui.c:466
static int fb_osk_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1121
static nserror gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
Set the scroll position of a framebuffer browser window.
Definition: gui.c:1912
static bool process_cmdline(int argc, char **argv)
Definition: gui.c:478
#define NSFB_TOOLBAR_DEFAULT_LAYOUT
Definition: gui.c:61
static void gui_window_set_status(struct gui_window *g, const char *text)
Definition: gui.c:1956
static nserror gui_window_event(struct gui_window *gw, enum gui_window_event event)
process miscellaneous window events
Definition: gui.c:2126
void gui_resize(fbtk_widget_t *root, int width, int height)
Definition: gui.c:2292
static void framebuffer_run(void)
Definition: gui.c:615
static bool fb_complete
Definition: gui.c:65
static void gui_window_remove_caret(struct gui_window *g)
Definition: gui.c:2108
static int fb_reload_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1096
static int fb_browser_window_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:809
static nserror gui_window_get_dimensions(struct gui_window *gw, int *width, int *height)
Find the current dimensions of a framebuffer browser window content area.
Definition: gui.c:1934
static void widget_scroll_y(struct gui_window *gw, int y, bool abs)
Definition: gui.c:151
static void gui_window_add_to_window_list(struct gui_window *gw)
Definition: gui.c:1786
static struct gui_window * gui_window_create(struct browser_window *bw, struct gui_window *existing, gui_window_create_flags flags)
Definition: gui.c:1824
static struct gui_misc_table framebuffer_misc_table
Definition: gui.c:2167
static void fb_update_back_forward(struct gui_window *gw)
Definition: gui.c:1046
static int fb_close_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1134
static void create_normal_browser_window(struct gui_window *gw, int furniture_width)
Definition: gui.c:1644
static void gui_window_start_throbber(struct gui_window *g)
Definition: gui.c:2056
static int fb_url_enter(void *pw, char *text)
Definition: gui.c:1165
static int fb_browser_window_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:410
static void widget_scroll_x(struct gui_window *gw, int x, bool abs)
Definition: gui.c:189
static int fb_rightarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1078
static void throbber_advance(void *pw)
Definition: gui.c:1999
static nserror set_defaults(struct nsoption_s *defaults)
Set option defaults for framebuffer frontend.
Definition: gui.c:558
static nserror gui_window_set_url(struct gui_window *g, nsurl *url)
Definition: gui.c:1992
static void gui_window_stop_throbber(struct gui_window *gw)
Definition: gui.c:2063
static bool nslog_stream_configure(FILE *fptr)
Ensures output logging stream is correctly configured.
Definition: gui.c:607
static int fb_localhistory_btn_clik(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1198
static int fb_browser_window_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:653
static void gui_window_remove_from_window_list(struct gui_window *gw)
Definition: gui.c:1800
static void gui_quit(void)
Definition: gui.c:642
static struct gui_drag gui_drag
static void gui_window_remove_caret_cb(fbtk_widget_t *widget)
Definition: gui.c:2073
static int febpp
Definition: gui.c:464
static int fb_stop_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1109
static int fb_browser_window_strip_focus(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Routine called when "stripped of focus" event occours for browser widget.
Definition: gui.c:1607
static int fb_url_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1184
static void die(const char *error)
Cause an abnormal program termination.
Definition: gui.c:107
static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip)
Definition: gui.c:2090
static int set_ptr_default_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1191
static struct gui_window_table framebuffer_window_table
Definition: gui.c:2151
static void resize_normal_browser_window(struct gui_window *gw, int furniture_width)
Definition: gui.c:1748
static int fb_scroll_callback(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1145
static const char * feurl
Definition: gui.c:467
static void gui_window_update_extent(struct gui_window *gw)
Definition: gui.c:1943
static void resize_browser_widget(struct gui_window *gw, int x, int y, int width, int height)
Definition: gui.c:1636
static void fb_pan(fbtk_widget_t *widget, struct browser_widget_s *bwidget, struct browser_window *bw)
Definition: gui.c:225
static void fb_queue_redraw(struct fbtk_widget_s *widget, int x0, int y0, int x1, int y1)
Definition: gui.c:130
static void framebuffer_pick_default_fename(void *ctx, const char *name, enum nsfb_type_e type)
Definition: gui.c:470
static nserror fb_window_invalidate_area(struct gui_window *g, const struct rect *rect)
Invalidates an area of a framebuffer browser window.
Definition: gui.c:1869
static enum nsfb_type_e fetype
Definition: gui.c:462
static void framebuffer_surface_iterator(void *ctx, const char *name, enum nsfb_type_e type)
Definition: gui.c:455
static int fewidth
Definition: gui.c:465
static nserror fb_warn_user(const char *warning, const char *detail)
Warn the user of an event.
Definition: gui.c:122
static void create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_width)
Definition: gui.c:1615
static int fb_leftarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1060
static const char * fename
Definition: gui.c:463
static void fb_redraw(fbtk_widget_t *widget, struct browser_widget_s *bwidget, struct browser_window *bw)
Definition: gui.c:348
fbtk_widget_t * fbtk
Definition: gui.c:63
static int fb_browser_window_destroy(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:438
static void resize_toolbar(struct gui_window *gw, int toolbar_height, int padding, const char *toolbar_layout)
Resize a toolbar.
Definition: gui.c:1462
static int fb_browser_window_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:851
struct nsfb_bbox_s bbox_t
Definition: gui.h:28
nserror framebuffer_schedule(int tival, void(*callback)(void *p), void *p)
Schedule a callback.
Definition: schedule.c:95
nsfb_t * framebuffer_initialise(const char *fename, int width, int height, int bpp)
Definition: framebuffer.c:577
bool framebuffer_resize(nsfb_t *nsfb, int width, int height, int bpp)
Definition: framebuffer.c:619
const struct plotter_table fb_plotters
framebuffer plot operation table
Definition: framebuffer.c:525
static nsfb_t * nsfb
Definition: framebuffer.c:45
void framebuffer_finalise(void)
Definition: framebuffer.c:638
bool framebuffer_set_cursor(struct fbtk_bitmap *bm)
Definition: framebuffer.c:644
framebuffer interface.
struct gui_bitmap_table * framebuffer_bitmap_table
Definition: bitmap.c:285
struct gui_fetch_table * framebuffer_fetch_table
Definition: fetch.c:100
struct gui_utf8_table * framebuffer_utf8_table
bool fb_font_finalise(void)
Finalise framebuffer font handling.
bool fb_font_init(void)
Initialise framebuffer font handling.
struct gui_layout_table * framebuffer_layout_table
nserror fb_local_history_present(fbtk_widget_t *parent, struct browser_window *bw)
make the local history window visible.
Interface to framebuffer local history manager.
char ** respaths
resource search path vector
Definition: gui.c:92
struct fbtk_bitmap pointer_image
struct fbtk_bitmap left_arrow
struct fbtk_bitmap throbber0
struct fbtk_bitmap move_image
struct fbtk_bitmap right_arrow
struct fbtk_bitmap throbber7
struct fbtk_bitmap menu_image
struct fbtk_bitmap history_image
struct fbtk_bitmap throbber8
struct fbtk_bitmap throbber1
struct fbtk_bitmap right_arrow_g
struct fbtk_bitmap throbber6
struct fbtk_bitmap progress_image
struct fbtk_bitmap throbber4
struct fbtk_bitmap caret_image
struct fbtk_bitmap reload
struct fbtk_bitmap osk_image
struct fbtk_bitmap hand_image
struct fbtk_bitmap throbber2
struct fbtk_bitmap stop_image
struct fbtk_bitmap stop_image_g
struct fbtk_bitmap left_arrow_g
struct fbtk_bitmap throbber5
struct fbtk_bitmap throbber3
Interface to platform-specific miscellaneous browser operation table.
browser_mouse_state
Mouse state: 1 is primary mouse button.
Definition: mouse.h:52
@ BROWSER_MOUSE_PRESS_1
primary button pressed
Definition: mouse.h:59
@ BROWSER_MOUSE_CLICK_2
button 2 clicked.
Definition: mouse.h:72
@ BROWSER_MOUSE_PRESS_2
auxillary button pressed
Definition: mouse.h:61
@ BROWSER_MOUSE_TRIPLE_CLICK
button triple clicked
Definition: mouse.h:83
@ BROWSER_MOUSE_CLICK_1
button 1 clicked.
Definition: mouse.h:70
@ BROWSER_MOUSE_DOUBLE_CLICK
button double clicked
Definition: mouse.h:81
@ BROWSER_MOUSE_DRAG_1
start of button 1 drag
Definition: mouse.h:86
@ BROWSER_MOUSE_HOLDING_2
during button 2 drag
Definition: mouse.h:96
@ BROWSER_MOUSE_HOLDING_1
during button 1 drag
Definition: mouse.h:94
@ BROWSER_MOUSE_DRAG_ON
a drag operation was started and a mouse button is still pressed
Definition: mouse.h:91
@ BROWSER_MOUSE_DRAG_2
start of button 2 drag
Definition: mouse.h:88
gui_pointer_shape
Definition: mouse.h:112
@ GUI_POINTER_MOVE
Definition: mouse.h:126
@ GUI_POINTER_CARET
Definition: mouse.h:115
@ GUI_POINTER_PROGRESS
Definition: mouse.h:131
@ GUI_POINTER_MENU
Definition: mouse.h:116
@ GUI_POINTER_POINT
Definition: mouse.h:114
Target independent plotting interface.
Interface to platform-specific graphical user interface window operations.
gui_window_create_flags
Window creation control flags.
Definition: window.h:66
gui_window_event
Window events.
Definition: window.h:80
@ GW_EVENT_REMOVE_CARET
Remove the caret, if present.
Definition: window.h:98
@ GW_EVENT_STOP_THROBBER
stop the navigation throbber.
Definition: window.h:108
@ GW_EVENT_UPDATE_EXTENT
Update the extent of the inside of a browser window to that of the current content.
Definition: window.h:93
@ GW_EVENT_START_THROBBER
start the navigation throbber.
Definition: window.h:103
Interface to key press operations.
@ NS_KEY_REDO
Definition: keypress.h:71
@ NS_KEY_LINE_START
Definition: keypress.h:57
@ NS_KEY_RIGHT
Definition: keypress.h:51
@ NS_KEY_LEFT
Definition: keypress.h:50
@ NS_KEY_DOWN
Definition: keypress.h:53
@ NS_KEY_WORD_LEFT
Definition: keypress.h:61
@ NS_KEY_PAGE_UP
Definition: keypress.h:65
@ NS_KEY_PAGE_DOWN
Definition: keypress.h:66
@ NS_KEY_UNDO
Definition: keypress.h:70
@ NS_KEY_LINE_END
Definition: keypress.h:58
@ NS_KEY_DELETE_RIGHT
Definition: keypress.h:55
@ NS_KEY_WORD_RIGHT
Definition: keypress.h:63
@ NS_KEY_UP
Definition: keypress.h:52
bool browser_window_key_press(struct browser_window *bw, uint32_t key)
Handle key presses in a browser window.
Definition: textinput.c:107
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
Initialise the logging system.
Definition: log.c:190
void nslog_finalise(void)
Shut down the logging system.
Definition: log.c:299
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
nserror messages_add_from_file(const char *path)
Read keys and values from messages file into the standard Messages hash.
Definition: messages.c:177
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).
NetSurf core interface registration, construction and destruction.
void netsurf_exit(void)
Finalise NetSurf core.
Definition: netsurf.c:232
nserror netsurf_init(const char *store_path)
Initialise netsurf core.
Definition: netsurf.c:107
nserror netsurf_register(struct netsurf_table *table)
Register operation table.
Definition: gui_factory.c:777
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
int width
Definition: gui.c:160
int height
Definition: gui.c:161
@ GUI_DRAG_NONE
Definition: gui.h:69
Interface to utility string handling.
bool pan_required
flag indicating the foreground loop needs to pan the window.
Definition: gui.c:81
bool redraw_required
flag indicating the foreground loop needs to redraw the browser widget.
Definition: gui.c:77
int scrollx
Definition: gui.c:74
int scrolly
scroll offsets.
Definition: gui.c:74
int panx
Definition: gui.c:84
bbox_t redraw_box
Area requiring redraw.
Definition: gui.c:80
struct browser_window * bw
The browser window connected to this gui window.
Definition: gui.c:73
int pany
Panning required.
Definition: gui.c:84
Browser window data.
struct browser_window * bw
framebuffer toolkit bitmaps
Definition: fbtk.h:63
int width
Definition: fbtk.h:64
widget callback information
Definition: fbtk.h:52
enum fbtk_callback_type type
Definition: fbtk.h:53
nsfb_event_t * event
Definition: fbtk.h:55
void * context
Definition: fbtk.h:54
Widget description.
Definition: widget.h:120
Definition: gui.c:87
bool grabbed_pointer
Definition: gui.c:96
state
Definition: gui.c:88
@ GUI_DRAG_PRESSED
Definition: gui.c:90
@ GUI_DRAG_DRAG
Definition: gui.c:91
@ GUI_DRAG_NONE
Definition: gui.c:89
int button
Definition: gui.c:93
int x
Definition: gui.c:94
int y
Definition: gui.c:95
Graphical user interface browser misc function table.
Definition: misc.h:39
nserror(* schedule)(int t, void(*callback)(void *p), void *p)
Schedule a callback.
Definition: misc.h:58
Graphical user interface window function table.
Definition: window.h:137
struct gui_window *(* create)(struct browser_window *bw, struct gui_window *existing, gui_window_create_flags flags)
Create and open a gui window for a browsing context.
Definition: window.h:164
first entry in window list
Definition: gui.c:298
struct gui_window * prev
Previous in linked list.
Definition: gui.h:159
struct fbtk_widget_s * toolbar
Definition: gui.h:46
struct gui_window * next
list for cleanup
Definition: gui.h:159
struct fbtk_widget_s * back
Definition: gui.h:34
struct fbtk_widget_s * bottom_right
Definition: gui.h:47
char * url
Definition: gui.h:154
int throbber_index
Definition: gui.h:49
struct fbtk_widget_s * window
Definition: gui.h:33
struct fbtk_widget_s * reload
Definition: gui.h:38
struct fbtk_widget_s * history
Definition: gui.h:36
struct fbtk_widget_s * close
Definition: gui.h:39
struct fbtk_widget_s * throbber
Definition: gui.h:42
struct fbtk_widget_s * hscroll
Definition: gui.h:43
struct fbtk_widget_s * stop
Definition: gui.h:37
char * status
Definition: gui.h:152
struct fbtk_widget_s * vscroll
Definition: gui.h:44
struct fbtk_widget_s * forward
Definition: gui.h:35
struct s_browser * browser
Definition: gui.h:149
struct browser_window * bw
The 'content' window that is rendered in the gui_window.
Definition: gui.c:316
NetSurf operation function table.
Definition: gui_table.h:48
struct gui_misc_table * misc
Browser table.
Definition: gui_table.h:57
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
struct nsoption_s * nsoptions_default
global default option table.
Definition: nsoption.c:46
static struct nsoption_s defaults[]
The table of compiled in default options.
Definition: nsoption.c:64
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
Definition: nsoption.c:696
struct nsoption_s * nsoptions
global active option table.
Definition: nsoption.c:45
nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
Process commandline and set options approriately.
Definition: nsoption.c:856
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
Definition: nsoption.c:608
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
Definition: nsoption.c:663
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_setnull_charp(OPTION, VALUE)
set string option in default table if currently unset
Definition: nsoption.h:376
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:344
#define nsoption_set_colour(OPTION, VALUE)
set a colour option in the default table
Definition: nsoption.h:355
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
Interface to a number of general purpose functionality.
#define fallthrough
switch fall through
Definition: utils.h:119
#define min(x, y)
Definition: utils.h:46
#define max(x, y)
Definition: utils.h:50
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: plot.c:579
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357