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 int idx;
561 static const struct {
562 enum nsoption_e nsc;
563 colour c;
564 } sys_colour_defaults[]= {
565 { NSOPTION_sys_colour_AccentColor, 0x00666666},
566 { NSOPTION_sys_colour_AccentColorText, 0x00ffffff},
567 { NSOPTION_sys_colour_ActiveText, 0x000000ee},
568 { NSOPTION_sys_colour_ButtonBorder, 0x00aaaaaa},
569 { NSOPTION_sys_colour_ButtonFace, 0x00dddddd},
570 { NSOPTION_sys_colour_ButtonText, 0x00000000},
571 { NSOPTION_sys_colour_Canvas, 0x00aaaaaa},
572 { NSOPTION_sys_colour_CanvasText, 0x00000000},
573 { NSOPTION_sys_colour_Field, 0x00f1f1f1},
574 { NSOPTION_sys_colour_FieldText, 0x00000000},
575 { NSOPTION_sys_colour_GrayText, 0x00777777},
576 { NSOPTION_sys_colour_Highlight, 0x00ee0000},
577 { NSOPTION_sys_colour_HighlightText, 0x00000000},
578 { NSOPTION_sys_colour_LinkText, 0x00ee0000},
579 { NSOPTION_sys_colour_Mark, 0x0000ffff},
580 { NSOPTION_sys_colour_MarkText, 0x00000000},
581 { NSOPTION_sys_colour_SelectedItem, 0x00e48435},
582 { NSOPTION_sys_colour_SelectedItemText, 0x00ffffff},
583 { NSOPTION_sys_colour_VisitedText, 0x008b1a55},
584 { NSOPTION_LISTEND, 0},
585 };
586
587 /* Set defaults for absent option strings */
588 nsoption_setnull_charp(cookie_file, strdup("~/.netsurf/Cookies"));
589 nsoption_setnull_charp(cookie_jar, strdup("~/.netsurf/Cookies"));
590
591 if (nsoption_charp(cookie_file) == NULL ||
592 nsoption_charp(cookie_jar) == NULL) {
593 NSLOG(netsurf, INFO, "Failed initialising cookie options");
595 }
596
597 /* set system colours for framebuffer ui */
598 for (idx=0; sys_colour_defaults[idx].nsc != NSOPTION_LISTEND; idx++) {
599 defaults[sys_colour_defaults[idx].nsc].value.c = sys_colour_defaults[idx].c;
600 }
601 return NSERROR_OK;
602}
603
604
605/**
606 * Ensures output logging stream is correctly configured
607 */
608static bool nslog_stream_configure(FILE *fptr)
609{
610 /* set log stream to be non-buffering */
611 setbuf(fptr, NULL);
612
613 return true;
614}
615
616static void framebuffer_run(void)
617{
618 nsfb_event_t event;
619 int timeout; /* timeout in miliseconds */
620
621 while (fb_complete != true) {
622 /* run the scheduler and discover how long to wait for
623 * the next event.
624 */
625 timeout = schedule_run();
626
627 /* if redraws are pending do not wait for event,
628 * return immediately
629 */
631 timeout = 0;
632
633 if (fbtk_event(fbtk, &event, timeout)) {
634 if ((event.type == NSFB_EVENT_CONTROL) &&
635 (event.value.controlcode == NSFB_CONTROL_QUIT))
636 fb_complete = true;
637 }
638
640 }
641}
642
643static void gui_quit(void)
644{
645 NSLOG(netsurf, INFO, "gui_quit");
646
648
650}
651
652/* called back when click in browser window */
653static int
655{
656 struct gui_window *gw = cbi->context;
657 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
659 int x = cbi->x + bwidget->scrollx;
660 int y = cbi->y + bwidget->scrolly;
661 uint64_t time_now;
662 static struct {
663 enum { CLICK_SINGLE, CLICK_DOUBLE, CLICK_TRIPLE } type;
664 uint64_t time;
665 } last_click;
666
667 if (cbi->event->type != NSFB_EVENT_KEY_DOWN &&
668 cbi->event->type != NSFB_EVENT_KEY_UP)
669 return 0;
670
671 NSLOG(netsurf, DEEPDEBUG, "browser window clicked at %d,%d",
672 cbi->x, cbi->y);
673
674 switch (cbi->event->type) {
675 case NSFB_EVENT_KEY_DOWN:
676 switch (cbi->event->value.keycode) {
677 case NSFB_KEY_MOUSE_1:
680 gui_drag.state = GUI_DRAG_PRESSED;
681 gui_drag.button = 1;
682 gui_drag.x = x;
683 gui_drag.y = y;
684 break;
685
686 case NSFB_KEY_MOUSE_3:
689 gui_drag.state = GUI_DRAG_PRESSED;
690 gui_drag.button = 2;
691 gui_drag.x = x;
692 gui_drag.y = y;
693 break;
694
695 case NSFB_KEY_MOUSE_4:
696 /* scroll up */
698 x, y,
699 0, -100) == false)
700 widget_scroll_y(gw, -100, false);
701 break;
702
703 case NSFB_KEY_MOUSE_5:
704 /* scroll down */
706 x, y,
707 0, 100) == false)
708 widget_scroll_y(gw, 100, false);
709 break;
710
711 default:
712 break;
713
714 }
715
716 break;
717 case NSFB_EVENT_KEY_UP:
718
719 mouse = 0;
720 nsu_getmonotonic_ms(&time_now);
721
722 switch (cbi->event->value.keycode) {
723 case NSFB_KEY_MOUSE_1:
724 if (gui_drag.state == GUI_DRAG_DRAG) {
725 /* End of a drag, rather than click */
726
728 /* need to ungrab pointer */
729 fbtk_tgrab_pointer(widget);
731 }
732
734
735 /* Tell core */
736 browser_window_mouse_track(gw->bw, 0, x, y);
737 break;
738 }
739 /* This is a click;
740 * clear PRESSED state and pass to core */
742 mouse = BROWSER_MOUSE_CLICK_1;
743 break;
744
745 case NSFB_KEY_MOUSE_3:
746 if (gui_drag.state == GUI_DRAG_DRAG) {
747 /* End of a drag, rather than click */
749
751 /* need to ungrab pointer */
752 fbtk_tgrab_pointer(widget);
754 }
755
756 /* Tell core */
757 browser_window_mouse_track(gw->bw, 0, x, y);
758 break;
759 }
760 /* This is a click;
761 * clear PRESSED state and pass to core */
763 mouse = BROWSER_MOUSE_CLICK_2;
764 break;
765
766 default:
767 break;
768
769 }
770
771 /* Determine if it's a double or triple click, allowing
772 * 0.5 seconds (500ms) between clicks
773 */
774 if ((time_now < (last_click.time + 500)) &&
775 (cbi->event->value.keycode != NSFB_KEY_MOUSE_4) &&
776 (cbi->event->value.keycode != NSFB_KEY_MOUSE_5)) {
777 if (last_click.type == CLICK_SINGLE) {
778 /* Set double click */
780 last_click.type = CLICK_DOUBLE;
781
782 } else if (last_click.type == CLICK_DOUBLE) {
783 /* Set triple click */
785 last_click.type = CLICK_TRIPLE;
786 } else {
787 /* Set normal click */
788 last_click.type = CLICK_SINGLE;
789 }
790 } else {
791 last_click.type = CLICK_SINGLE;
792 }
793
794 if (mouse) {
795 browser_window_mouse_click(gw->bw, mouse, x, y);
796 }
797
798 last_click.time = time_now;
799
800 break;
801 default:
802 break;
803
804 }
805 return 1;
806}
807
808/* called back when movement in browser window */
809static int
811{
812 browser_mouse_state mouse = 0;
813 struct gui_window *gw = cbi->context;
814 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
815 int x = cbi->x + bwidget->scrollx;
816 int y = cbi->y + bwidget->scrolly;
817
818 if (gui_drag.state == GUI_DRAG_PRESSED &&
819 (abs(x - gui_drag.x) > 5 ||
820 abs(y - gui_drag.y) > 5)) {
821 /* Drag started */
822 if (gui_drag.button == 1) {
826 } else {
830 }
832 gui_drag.state = GUI_DRAG_DRAG;
833 }
834
835 if (gui_drag.state == GUI_DRAG_DRAG) {
836 /* set up mouse state */
837 mouse |= BROWSER_MOUSE_DRAG_ON;
838
839 if (gui_drag.button == 1)
841 else
843 }
844
845 browser_window_mouse_track(gw->bw, mouse, x, y);
846
847 return 0;
848}
849
850
851static int
853{
854 struct gui_window *gw = cbi->context;
855 static fbtk_modifier_type modifier = FBTK_MOD_CLEAR;
856 int ucs4 = -1;
857
858 NSLOG(netsurf, INFO, "got value %d", cbi->event->value.keycode);
859
860 switch (cbi->event->type) {
861 case NSFB_EVENT_KEY_DOWN:
862 switch (cbi->event->value.keycode) {
863
864 case NSFB_KEY_DELETE:
866 break;
867
868 case NSFB_KEY_PAGEUP:
870 NS_KEY_PAGE_UP) == false)
872 gw->browser), false);
873 break;
874
875 case NSFB_KEY_PAGEDOWN:
877 NS_KEY_PAGE_DOWN) == false)
879 gw->browser), false);
880 break;
881
882 case NSFB_KEY_RIGHT:
883 if (modifier & FBTK_MOD_RCTRL ||
884 modifier & FBTK_MOD_LCTRL) {
885 /* CTRL held */
887 NS_KEY_LINE_END) == false)
888 widget_scroll_x(gw, INT_MAX, true);
889
890 } else if (modifier & FBTK_MOD_RSHIFT ||
891 modifier & FBTK_MOD_LSHIFT) {
892 /* SHIFT held */
894 NS_KEY_WORD_RIGHT) == false)
896 gw->browser), false);
897
898 } else {
899 /* no modifier */
901 NS_KEY_RIGHT) == false)
902 widget_scroll_x(gw, 100, false);
903 }
904 break;
905
906 case NSFB_KEY_LEFT:
907 if (modifier & FBTK_MOD_RCTRL ||
908 modifier & FBTK_MOD_LCTRL) {
909 /* CTRL held */
911 NS_KEY_LINE_START) == false)
912 widget_scroll_x(gw, 0, true);
913
914 } else if (modifier & FBTK_MOD_RSHIFT ||
915 modifier & FBTK_MOD_LSHIFT) {
916 /* SHIFT held */
918 NS_KEY_WORD_LEFT) == false)
920 gw->browser), false);
921
922 } else {
923 /* no modifier */
925 NS_KEY_LEFT) == false)
926 widget_scroll_x(gw, -100, false);
927 }
928 break;
929
930 case NSFB_KEY_UP:
932 NS_KEY_UP) == false)
933 widget_scroll_y(gw, -100, false);
934 break;
935
936 case NSFB_KEY_DOWN:
938 NS_KEY_DOWN) == false)
939 widget_scroll_y(gw, 100, false);
940 break;
941
942 case NSFB_KEY_MINUS:
943 if (modifier & FBTK_MOD_RCTRL ||
944 modifier & FBTK_MOD_LCTRL) {
945 browser_window_set_scale(gw->bw, -0.1, false);
946 }
947 break;
948
949 case NSFB_KEY_EQUALS: /* PLUS */
950 if (modifier & FBTK_MOD_RCTRL ||
951 modifier & FBTK_MOD_LCTRL) {
952 browser_window_set_scale(gw->bw, 0.1, false);
953 }
954 break;
955
956 case NSFB_KEY_0:
957 if (modifier & FBTK_MOD_RCTRL ||
958 modifier & FBTK_MOD_LCTRL) {
959 browser_window_set_scale(gw->bw, 1.0, true);
960 }
961 break;
962
963 case NSFB_KEY_RSHIFT:
964 modifier |= FBTK_MOD_RSHIFT;
965 break;
966
967 case NSFB_KEY_LSHIFT:
968 modifier |= FBTK_MOD_LSHIFT;
969 break;
970
971 case NSFB_KEY_RCTRL:
972 modifier |= FBTK_MOD_RCTRL;
973 break;
974
975 case NSFB_KEY_LCTRL:
976 modifier |= FBTK_MOD_LCTRL;
977 break;
978
979 case NSFB_KEY_y:
980 case NSFB_KEY_z:
981 if (cbi->event->value.keycode == NSFB_KEY_z &&
982 (modifier & FBTK_MOD_RCTRL ||
983 modifier & FBTK_MOD_LCTRL) &&
984 (modifier & FBTK_MOD_RSHIFT ||
985 modifier & FBTK_MOD_LSHIFT)) {
986 /* Z pressed with CTRL and SHIFT held */
988 break;
989
990 } else if (cbi->event->value.keycode == NSFB_KEY_z &&
991 (modifier & FBTK_MOD_RCTRL ||
992 modifier & FBTK_MOD_LCTRL)) {
993 /* Z pressed with CTRL held */
995 break;
996
997 } else if (cbi->event->value.keycode == NSFB_KEY_y &&
998 (modifier & FBTK_MOD_RCTRL ||
999 modifier & FBTK_MOD_LCTRL)) {
1000 /* Y pressed with CTRL held */
1002 break;
1003 }
1004 /* Z or Y pressed but not undo or redo; */
1006
1007 default:
1008 ucs4 = fbtk_keycode_to_ucs4(cbi->event->value.keycode,
1009 modifier);
1010 if (ucs4 != -1)
1011 browser_window_key_press(gw->bw, ucs4);
1012 break;
1013 }
1014 break;
1015
1016 case NSFB_EVENT_KEY_UP:
1017 switch (cbi->event->value.keycode) {
1018 case NSFB_KEY_RSHIFT:
1019 modifier &= ~FBTK_MOD_RSHIFT;
1020 break;
1021
1022 case NSFB_KEY_LSHIFT:
1023 modifier &= ~FBTK_MOD_LSHIFT;
1024 break;
1025
1026 case NSFB_KEY_RCTRL:
1027 modifier &= ~FBTK_MOD_RCTRL;
1028 break;
1029
1030 case NSFB_KEY_LCTRL:
1031 modifier &= ~FBTK_MOD_LCTRL;
1032 break;
1033
1034 default:
1035 break;
1036 }
1037 break;
1038
1039 default:
1040 break;
1041 }
1042
1043 return 0;
1044}
1045
1046static void
1048{
1049 struct browser_window *bw = gw->bw;
1050
1057}
1058
1059/* left icon click routine */
1060static int
1062{
1063 struct gui_window *gw = cbi->context;
1064 struct browser_window *bw = gw->bw;
1065
1066 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1067 return 0;
1068
1071
1073
1074 return 1;
1075}
1076
1077/* right arrow icon click routine */
1078static int
1080{
1081 struct gui_window *gw = cbi->context;
1082 struct browser_window *bw = gw->bw;
1083
1084 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1085 return 0;
1086
1089
1091 return 1;
1092
1093}
1094
1095/* reload icon click routine */
1096static int
1098{
1099 struct browser_window *bw = cbi->context;
1100
1101 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1102 return 0;
1103
1105 return 1;
1106}
1107
1108/* stop icon click routine */
1109static int
1111{
1112 struct browser_window *bw = cbi->context;
1113
1114 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1115 return 0;
1116
1118 return 0;
1119}
1120
1121static int
1123{
1124
1125 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1126 return 0;
1127
1128 map_osk();
1129
1130 return 0;
1131}
1132
1133/* close browser window icon click routine */
1134static int
1136{
1137 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1138 return 0;
1139
1140 fb_complete = true;
1141
1142 return 0;
1143}
1144
1145static int
1147{
1148 struct gui_window *gw = cbi->context;
1149
1150 switch (cbi->type) {
1151 case FBTK_CBT_SCROLLY:
1152 widget_scroll_y(gw, cbi->y, true);
1153 break;
1154
1155 case FBTK_CBT_SCROLLX:
1156 widget_scroll_x(gw, cbi->x, true);
1157 break;
1158
1159 default:
1160 break;
1161 }
1162 return 0;
1163}
1164
1165static int
1166fb_url_enter(void *pw, char *text)
1167{
1168 struct browser_window *bw = pw;
1169 nsurl *url;
1170 nserror error;
1171
1172 error = nsurl_create(text, &url);
1173 if (error != NSERROR_OK) {
1174 fb_warn_user("Errorcode:", messages_get_errorcode(error));
1175 } else {
1177 NULL, NULL, NULL);
1178 nsurl_unref(url);
1179 }
1180
1181 return 0;
1182}
1183
1184static int
1186{
1188 return 0;
1189}
1190
1191static int
1193{
1195 return 0;
1196}
1197
1198static int
1200{
1201 struct gui_window *gw = cbi->context;
1202
1203 if (cbi->event->type != NSFB_EVENT_KEY_UP)
1204 return 0;
1205
1207
1208 return 0;
1209}
1210
1211
1212/** Create a toolbar window and populate it with buttons.
1213 *
1214 * The toolbar layout uses a character to define buttons type and position:
1215 * b - back
1216 * l - local history
1217 * f - forward
1218 * s - stop
1219 * r - refresh
1220 * u - url bar expands to fit remaining space
1221 * t - throbber/activity indicator
1222 * c - close the current window
1223 *
1224 * The default layout is "blfsrut" there should be no more than a
1225 * single url bar entry or behaviour will be undefined.
1226 *
1227 * @param gw Parent window
1228 * @param toolbar_height The height in pixels of the toolbar
1229 * @param padding The padding in pixels round each element of the toolbar
1230 * @param frame_col Frame colour.
1231 * @param toolbar_layout A string defining which buttons and controls
1232 * should be added to the toolbar. May be empty
1233 * string to disable the bar..
1234 *
1235 */
1236static fbtk_widget_t *
1238 int toolbar_height,
1239 int padding,
1240 colour frame_col,
1241 const char *toolbar_layout)
1242{
1244 fbtk_widget_t *widget;
1245
1246 int xpos; /* The position of the next widget. */
1247 int xlhs = 0; /* extent of the left hand side widgets */
1248 int xdir = 1; /* the direction of movement + or - 1 */
1249 const char *itmtype; /* type of the next item */
1250
1251 if (toolbar_layout == NULL) {
1252 toolbar_layout = NSFB_TOOLBAR_DEFAULT_LAYOUT;
1253 }
1254
1255 NSLOG(netsurf, INFO, "Using toolbar layout %s", toolbar_layout);
1256
1257 itmtype = toolbar_layout;
1258
1259 /* check for the toolbar being disabled */
1260 if ((*itmtype == 0) || (*itmtype == 'q')) {
1261 return NULL;
1262 }
1263
1264 toolbar = fbtk_create_window(gw->window, 0, 0, 0,
1265 toolbar_height,
1266 frame_col);
1267
1268 if (toolbar == NULL) {
1269 return NULL;
1270 }
1271
1275 NULL);
1276
1277
1278 xpos = padding;
1279
1280 /* loop proceeds creating widget on the left hand side until
1281 * it runs out of layout or encounters a url bar declaration
1282 * wherupon it works backwards from the end of the layout
1283 * untill the space left is for the url bar
1284 */
1285 while ((itmtype >= toolbar_layout) &&
1286 (*itmtype != 0) &&
1287 (xdir !=0)) {
1288
1289 NSLOG(netsurf, INFO, "toolbar adding %c", *itmtype);
1290
1291
1292 switch (*itmtype) {
1293
1294 case 'b': /* back */
1295 widget = fbtk_create_button(toolbar,
1296 (xdir == 1) ? xpos :
1297 xpos - left_arrow.width,
1298 padding,
1300 -padding,
1301 frame_col,
1302 &left_arrow,
1304 gw);
1305 gw->back = widget; /* keep reference */
1306 break;
1307
1308 case 'l': /* local history */
1309 widget = fbtk_create_button(toolbar,
1310 (xdir == 1) ? xpos :
1311 xpos - history_image.width,
1312 padding,
1314 -padding,
1315 frame_col,
1318 gw);
1319 gw->history = widget;
1320 break;
1321
1322 case 'f': /* forward */
1323 widget = fbtk_create_button(toolbar,
1324 (xdir == 1)?xpos :
1325 xpos - right_arrow.width,
1326 padding,
1328 -padding,
1329 frame_col,
1330 &right_arrow,
1332 gw);
1333 gw->forward = widget;
1334 break;
1335
1336 case 'c': /* close the current window */
1337 widget = fbtk_create_button(toolbar,
1338 (xdir == 1)?xpos :
1339 xpos - stop_image_g.width,
1340 padding,
1342 -padding,
1343 frame_col,
1344 &stop_image_g,
1346 gw->bw);
1347 gw->close = widget;
1348 break;
1349
1350 case 's': /* stop */
1351 widget = fbtk_create_button(toolbar,
1352 (xdir == 1)?xpos :
1353 xpos - stop_image.width,
1354 padding,
1356 -padding,
1357 frame_col,
1358 &stop_image,
1360 gw->bw);
1361 gw->stop = widget;
1362 break;
1363
1364 case 'r': /* reload */
1365 widget = fbtk_create_button(toolbar,
1366 (xdir == 1)?xpos :
1367 xpos - reload.width,
1368 padding,
1369 reload.width,
1370 -padding,
1371 frame_col,
1372 &reload,
1374 gw->bw);
1375 gw->reload = widget;
1376 break;
1377
1378 case 't': /* throbber/activity indicator */
1379 widget = fbtk_create_bitmap(toolbar,
1380 (xdir == 1)?xpos :
1381 xpos - throbber0.width,
1382 padding,
1384 -padding,
1385 frame_col,
1386 &throbber0);
1387 gw->throbber = widget;
1388 break;
1389
1390
1391 case 'u': /* url bar*/
1392 if (xdir == -1) {
1393 /* met the u going backwards add url
1394 * now we know available extent
1395 */
1396
1398 xlhs,
1399 padding,
1400 xpos - xlhs,
1401 -padding,
1404 true,
1406 gw->bw);
1407
1408 fbtk_set_handler(widget,
1410 fb_url_move, gw->bw);
1411
1412 gw->url = widget; /* keep reference */
1413
1414 /* toolbar is complete */
1415 xdir = 0;
1416 break;
1417 }
1418 /* met url going forwards, note position and
1419 * reverse direction
1420 */
1421 itmtype = toolbar_layout + strlen(toolbar_layout);
1422 xdir = -1;
1423 xlhs = xpos;
1424 xpos = (2 * fbtk_get_width(toolbar));
1425 widget = toolbar;
1426 break;
1427
1428 default:
1429 widget = NULL;
1430 xdir = 0;
1431 NSLOG(netsurf, INFO,
1432 "Unknown element %c in toolbar layout",
1433 *itmtype);
1434 break;
1435
1436 }
1437
1438 if (widget != NULL) {
1439 xpos += (xdir * (fbtk_get_width(widget) + padding));
1440 }
1441
1442 NSLOG(netsurf, INFO, "xpos is %d", xpos);
1443
1444 itmtype += xdir;
1445 }
1446
1448
1449 return toolbar;
1450}
1451
1452
1453/** Resize a toolbar.
1454 *
1455 * @param gw Parent window
1456 * @param toolbar_height The height in pixels of the toolbar
1457 * @param padding The padding in pixels round each element of the toolbar
1458 * @param toolbar_layout A string defining which buttons and controls
1459 * should be added to the toolbar. May be empty
1460 * string to disable the bar.
1461 */
1462static void
1464 int toolbar_height,
1465 int padding,
1466 const char *toolbar_layout)
1467{
1468 fbtk_widget_t *widget;
1469
1470 int xpos; /* The position of the next widget. */
1471 int xlhs = 0; /* extent of the left hand side widgets */
1472 int xdir = 1; /* the direction of movement + or - 1 */
1473 const char *itmtype; /* type of the next item */
1474 int x = 0, y = 0, w = 0, h = 0;
1475
1476 if (gw->toolbar == NULL) {
1477 return;
1478 }
1479
1480 if (toolbar_layout == NULL) {
1481 toolbar_layout = NSFB_TOOLBAR_DEFAULT_LAYOUT;
1482 }
1483
1484 itmtype = toolbar_layout;
1485
1486 if (*itmtype == 0) {
1487 return;
1488 }
1489
1490 fbtk_set_pos_and_size(gw->toolbar, 0, 0, 0, toolbar_height);
1491
1492 xpos = padding;
1493
1494 /* loop proceeds creating widget on the left hand side until
1495 * it runs out of layout or encounters a url bar declaration
1496 * wherupon it works backwards from the end of the layout
1497 * untill the space left is for the url bar
1498 */
1499 while (itmtype >= toolbar_layout && xdir != 0) {
1500
1501 switch (*itmtype) {
1502 case 'b': /* back */
1503 widget = gw->back;
1504 x = (xdir == 1) ? xpos : xpos - left_arrow.width;
1505 y = padding;
1506 w = left_arrow.width;
1507 h = -padding;
1508 break;
1509
1510 case 'l': /* local history */
1511 widget = gw->history;
1512 x = (xdir == 1) ? xpos : xpos - history_image.width;
1513 y = padding;
1514 w = history_image.width;
1515 h = -padding;
1516 break;
1517
1518 case 'f': /* forward */
1519 widget = gw->forward;
1520 x = (xdir == 1) ? xpos : xpos - right_arrow.width;
1521 y = padding;
1522 w = right_arrow.width;
1523 h = -padding;
1524 break;
1525
1526 case 'c': /* close the current window */
1527 widget = gw->close;
1528 x = (xdir == 1) ? xpos : xpos - stop_image_g.width;
1529 y = padding;
1530 w = stop_image_g.width;
1531 h = -padding;
1532 break;
1533
1534 case 's': /* stop */
1535 widget = gw->stop;
1536 x = (xdir == 1) ? xpos : xpos - stop_image.width;
1537 y = padding;
1538 w = stop_image.width;
1539 h = -padding;
1540 break;
1541
1542 case 'r': /* reload */
1543 widget = gw->reload;
1544 x = (xdir == 1) ? xpos : xpos - reload.width;
1545 y = padding;
1546 w = reload.width;
1547 h = -padding;
1548 break;
1549
1550 case 't': /* throbber/activity indicator */
1551 widget = gw->throbber;
1552 x = (xdir == 1) ? xpos : xpos - throbber0.width;
1553 y = padding;
1554 w = throbber0.width;
1555 h = -padding;
1556 break;
1557
1558
1559 case 'u': /* url bar*/
1560 if (xdir == -1) {
1561 /* met the u going backwards add url
1562 * now we know available extent
1563 */
1564 widget = gw->url;
1565 x = xlhs;
1566 y = padding;
1567 w = xpos - xlhs;
1568 h = -padding;
1569
1570 /* toolbar is complete */
1571 xdir = 0;
1572 break;
1573 }
1574 /* met url going forwards, note position and
1575 * reverse direction
1576 */
1577 itmtype = toolbar_layout + strlen(toolbar_layout);
1578 xdir = -1;
1579 xlhs = xpos;
1580 w = fbtk_get_width(gw->toolbar);
1581 xpos = 2 * w;
1582 widget = gw->toolbar;
1583 break;
1584
1585 default:
1586 widget = NULL;
1587 break;
1588
1589 }
1590
1591 if (widget != NULL) {
1592 if (widget != gw->toolbar)
1593 fbtk_set_pos_and_size(widget, x, y, w, h);
1594 xpos += xdir * (w + padding);
1595 }
1596
1597 itmtype += xdir;
1598 }
1599}
1600
1601/** Routine called when "stripped of focus" event occours for browser widget.
1602 *
1603 * @param widget The widget reciving "stripped of focus" event.
1604 * @param cbi The callback parameters.
1605 * @return The callback result.
1606 */
1607static int
1609{
1610 fbtk_set_caret(widget, false, 0, 0, 0, NULL);
1611
1612 return 0;
1613}
1614
1615static void
1616create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_width)
1617{
1618 struct browser_widget_s *browser_widget;
1619 browser_widget = calloc(1, sizeof(struct browser_widget_s));
1620
1622 0,
1623 toolbar_height,
1624 -furniture_width,
1625 -furniture_width,
1626 browser_widget);
1627
1634}
1635
1636static void
1637resize_browser_widget(struct gui_window *gw, int x, int y,
1638 int width, int height)
1639{
1642}
1643
1644static void
1645create_normal_browser_window(struct gui_window *gw, int furniture_width)
1646{
1647 fbtk_widget_t *widget;
1649 int statusbar_width = 0;
1650 int toolbar_height = nsoption_int(fb_toolbar_size);
1651
1652 NSLOG(netsurf, INFO, "Normal window");
1653
1654 gw->window = fbtk_create_window(fbtk, 0, 0, 0, 0, 0);
1655
1656 statusbar_width = nsoption_int(toolbar_status_size) *
1657 fbtk_get_width(gw->window) / 10000;
1658
1659 /* toolbar */
1660 toolbar = create_toolbar(gw,
1661 toolbar_height,
1662 2,
1664 nsoption_charp(fb_toolbar_layout));
1665 gw->toolbar = toolbar;
1666
1667 /* set the actually created toolbar height */
1668 if (toolbar != NULL) {
1669 toolbar_height = fbtk_get_height(toolbar);
1670 } else {
1671 toolbar_height = 0;
1672 }
1673
1674 /* status bar */
1675 gw->status = fbtk_create_text(gw->window,
1676 0,
1677 fbtk_get_height(gw->window) - furniture_width,
1678 statusbar_width, furniture_width,
1680 false);
1682
1683 NSLOG(netsurf, INFO, "status bar %p at %d,%d", gw->status,
1685
1686 /* create horizontal scrollbar */
1688 statusbar_width,
1689 fbtk_get_height(gw->window) - furniture_width,
1690 fbtk_get_width(gw->window) - statusbar_width - furniture_width,
1691 furniture_width,
1695 gw);
1696
1697 /* fill bottom right area */
1698
1699 if (nsoption_bool(fb_osk) == true) {
1700 widget = fbtk_create_text_button(gw->window,
1701 fbtk_get_width(gw->window) - furniture_width,
1702 fbtk_get_height(gw->window) - furniture_width,
1703 furniture_width,
1704 furniture_width,
1707 NULL);
1708 widget = fbtk_create_button(gw->window,
1709 fbtk_get_width(gw->window) - furniture_width,
1710 fbtk_get_height(gw->window) - furniture_width,
1711 furniture_width,
1712 furniture_width,
1714 &osk_image,
1716 NULL);
1717 } else {
1718 widget = fbtk_create_fill(gw->window,
1719 fbtk_get_width(gw->window) - furniture_width,
1720 fbtk_get_height(gw->window) - furniture_width,
1721 furniture_width,
1722 furniture_width,
1724
1726 }
1727
1728 gw->bottom_right = widget;
1729
1730 /* create vertical scrollbar */
1732 fbtk_get_width(gw->window) - furniture_width,
1733 toolbar_height,
1734 furniture_width,
1735 fbtk_get_height(gw->window) - toolbar_height - furniture_width,
1739 gw);
1740
1741 /* browser widget */
1742 create_browser_widget(gw, toolbar_height, nsoption_int(fb_furniture_size));
1743
1744 /* Give browser_window's user widget input focus */
1746}
1747
1748static void
1749resize_normal_browser_window(struct gui_window *gw, int furniture_width)
1750{
1751 bool resized;
1752 int width, height;
1753 int statusbar_width;
1754 int toolbar_height = fbtk_get_height(gw->toolbar);
1755
1756 /* Resize the main window widget */
1757 resized = fbtk_set_pos_and_size(gw->window, 0, 0, 0, 0);
1758 if (!resized)
1759 return;
1760
1763 statusbar_width = nsoption_int(toolbar_status_size) * width / 10000;
1764
1765 resize_toolbar(gw, toolbar_height, 2,
1766 nsoption_charp(fb_toolbar_layout));
1768 0, height - furniture_width,
1769 statusbar_width, furniture_width);
1771 statusbar_width, height - furniture_width,
1772 width - statusbar_width - furniture_width,
1773 furniture_width);
1775 width - furniture_width, height - furniture_width,
1776 furniture_width, furniture_width);
1778 width - furniture_width,
1779 toolbar_height, furniture_width,
1780 height - toolbar_height - furniture_width);
1782 0, toolbar_height,
1783 width - furniture_width,
1784 height - furniture_width - toolbar_height);
1785}
1786
1788{
1789 gw->next = NULL;
1790 gw->prev = NULL;
1791
1792 if (window_list == NULL) {
1793 window_list = gw;
1794 } else {
1795 window_list->prev = gw;
1796 gw->next = window_list;
1797 window_list = gw;
1798 }
1799}
1800
1802{
1803 struct gui_window *list;
1804
1805 for (list = window_list; list != NULL; list = list->next) {
1806 if (list != gw)
1807 continue;
1808
1809 if (list == window_list) {
1810 window_list = list->next;
1811 if (window_list != NULL)
1812 window_list->prev = NULL;
1813 } else {
1814 list->prev->next = list->next;
1815 if (list->next != NULL) {
1816 list->next->prev = list->prev;
1817 }
1818 }
1819 break;
1820 }
1821}
1822
1823
1824static struct gui_window *
1826 struct gui_window *existing,
1828{
1829 struct gui_window *gw;
1830
1831 gw = calloc(1, sizeof(struct gui_window));
1832
1833 if (gw == NULL)
1834 return NULL;
1835
1836 /* associate the gui window with the underlying browser window
1837 */
1838 gw->bw = bw;
1839
1840 create_normal_browser_window(gw, nsoption_int(fb_furniture_size));
1841
1842 /* map and request redraw of gui window */
1843 fbtk_set_mapping(gw->window, true);
1844
1845 /* Add it to the window list */
1847
1848 return gw;
1849}
1850
1851static void
1853{
1855
1857
1858 free(gw);
1859}
1860
1861
1862/**
1863 * Invalidates an area of a framebuffer browser window
1864 *
1865 * \param g The netsurf window being invalidated.
1866 * \param rect area to redraw or NULL for the entire window area
1867 * \return NSERROR_OK on success or appropriate error code
1868 */
1869static nserror
1871{
1872 struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
1873
1874 if (rect != NULL) {
1876 rect->x0 - bwidget->scrollx,
1877 rect->y0 - bwidget->scrolly,
1878 rect->x1 - bwidget->scrollx,
1879 rect->y1 - bwidget->scrolly);
1880 } else {
1882 0,
1883 0,
1886 }
1887 return NSERROR_OK;
1888}
1889
1890static bool
1891gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
1892{
1893 struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
1894
1895 *sx = bwidget->scrollx;
1896 *sy = bwidget->scrolly;
1897
1898 return true;
1899}
1900
1901/**
1902 * Set the scroll position of a framebuffer browser window.
1903 *
1904 * Scrolls the viewport to ensure the specified rectangle of the
1905 * content is shown. The framebuffer implementation scrolls the contents so
1906 * the specified point in the content is at the top of the viewport.
1907 *
1908 * \param gw gui_window to scroll
1909 * \param rect The rectangle to ensure is shown.
1910 * \return NSERROR_OK on success or apropriate error code.
1911 */
1912static nserror
1913gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
1914{
1915 struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
1916
1917 assert(bwidget);
1918
1919 widget_scroll_x(gw, rect->x0, true);
1920 widget_scroll_y(gw, rect->y0, true);
1921
1922 return NSERROR_OK;
1923}
1924
1925
1926/**
1927 * Find the current dimensions of a framebuffer browser window content area.
1928 *
1929 * \param gw The gui window to measure content area of.
1930 * \param width receives width of window
1931 * \param height receives height of window
1932 * \return NSERROR_OK on sucess and width and height updated.
1933 */
1934static nserror
1936{
1939
1940 return NSERROR_OK;
1941}
1942
1943static void
1945{
1946 int w, h;
1947 browser_window_get_extents(gw->bw, true, &w, &h);
1948
1950 fbtk_get_width(gw->browser), 100);
1951
1953 fbtk_get_height(gw->browser), 100);
1954}
1955
1956static void
1958{
1960}
1961
1962static void
1964{
1965 switch (shape) {
1966 case GUI_POINTER_POINT:
1968 break;
1969
1970 case GUI_POINTER_CARET:
1972 break;
1973
1974 case GUI_POINTER_MENU:
1976 break;
1977
1980 break;
1981
1982 case GUI_POINTER_MOVE:
1984 break;
1985
1986 default:
1988 break;
1989 }
1990}
1991
1992static nserror
1994{
1995 fbtk_set_text(g->url, nsurl_access(url));
1996 return NSERROR_OK;
1997}
1998
1999static void
2001{
2002 struct gui_window *g = pw;
2003 struct fbtk_bitmap *image;
2004
2005 switch (g->throbber_index) {
2006 case 0:
2007 image = &throbber1;
2008 g->throbber_index = 1;
2009 break;
2010
2011 case 1:
2012 image = &throbber2;
2013 g->throbber_index = 2;
2014 break;
2015
2016 case 2:
2017 image = &throbber3;
2018 g->throbber_index = 3;
2019 break;
2020
2021 case 3:
2022 image = &throbber4;
2023 g->throbber_index = 4;
2024 break;
2025
2026 case 4:
2027 image = &throbber5;
2028 g->throbber_index = 5;
2029 break;
2030
2031 case 5:
2032 image = &throbber6;
2033 g->throbber_index = 6;
2034 break;
2035
2036 case 6:
2037 image = &throbber7;
2038 g->throbber_index = 7;
2039 break;
2040
2041 case 7:
2042 image = &throbber8;
2043 g->throbber_index = 0;
2044 break;
2045
2046 default:
2047 return;
2048 }
2049
2050 if (g->throbber_index >= 0) {
2051 fbtk_set_bitmap(g->throbber, image);
2053 }
2054}
2055
2056static void
2058{
2059 g->throbber_index = 0;
2061}
2062
2063static void
2065{
2066 gw->throbber_index = -1;
2068
2070
2071}
2072
2073static void
2075{
2076 struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
2077 int c_x, c_y, c_h;
2078
2079 if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
2080 /* browser window already had caret:
2081 * redraw its area to remove it first */
2082 fb_queue_redraw(widget,
2083 c_x - bwidget->scrollx,
2084 c_y - bwidget->scrolly,
2085 c_x + 1 - bwidget->scrollx,
2086 c_y + c_h - bwidget->scrolly);
2087 }
2088}
2089
2090static void
2091gui_window_place_caret(struct gui_window *g, int x, int y, int height,
2092 const struct rect *clip)
2093{
2094 struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
2095
2096 /* set new pos */
2097 fbtk_set_caret(g->browser, true, x, y, height,
2099
2100 /* redraw new caret pos */
2102 x - bwidget->scrollx,
2103 y - bwidget->scrolly,
2104 x + 1 - bwidget->scrollx,
2105 y + height - bwidget->scrolly);
2106}
2107
2108static void
2110{
2111 int c_x, c_y, c_h;
2112
2113 if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
2114 /* browser window owns the caret, so can remove it */
2115 fbtk_set_caret(g->browser, false, 0, 0, 0, NULL);
2116 }
2117}
2118
2119/**
2120 * process miscellaneous window events
2121 *
2122 * \param gw The window receiving the event.
2123 * \param event The event code.
2124 * \return NSERROR_OK when processed ok
2125 */
2126static nserror
2128{
2129 switch (event) {
2132 break;
2133
2136 break;
2137
2140 break;
2141
2144 break;
2145
2146 default:
2147 break;
2148 }
2149 return NSERROR_OK;
2150}
2151
2154 .destroy = gui_window_destroy,
2155 .invalidate = fb_window_invalidate_area,
2156 .get_scroll = gui_window_get_scroll,
2157 .set_scroll = gui_window_set_scroll,
2158 .get_dimensions = gui_window_get_dimensions,
2159 .event = gui_window_event,
2160
2161 .set_url = gui_window_set_url,
2162 .set_status = gui_window_set_status,
2163 .set_pointer = gui_window_set_pointer,
2164 .place_caret = gui_window_place_caret,
2165};
2166
2167
2170
2171 .quit = gui_quit,
2172};
2173
2174/**
2175 * Entry point from OS.
2176 *
2177 * /param argc The number of arguments in the string vector.
2178 * /param argv The argument string vector.
2179 * /return The return code to the OS
2180 */
2181int
2182main(int argc, char** argv)
2183{
2184 struct browser_window *bw;
2185 char *options;
2186 char *messages;
2187 nsurl *url;
2188 nserror ret;
2189 nsfb_t *nsfb;
2190 struct netsurf_table framebuffer_table = {
2192 .window = &framebuffer_window_table,
2193 .corewindow = framebuffer_core_window_table,
2194 .clipboard = framebuffer_clipboard_table,
2195 .fetch = framebuffer_fetch_table,
2196 .utf8 = framebuffer_utf8_table,
2197 .bitmap = framebuffer_bitmap_table,
2198 .layout = framebuffer_layout_table,
2199 };
2200
2201 ret = netsurf_register(&framebuffer_table);
2202 if (ret != NSERROR_OK) {
2203 die("NetSurf operation table failed registration");
2204 }
2205
2206 respaths = fb_init_resource_path(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH);
2207
2208 /* initialise logging. Not fatal if it fails but not much we
2209 * can do about it either.
2210 */
2211 nslog_init(nslog_stream_configure, &argc, argv);
2212
2213 /* user options setup */
2215 if (ret != NSERROR_OK) {
2216 die("Options failed to initialise");
2217 }
2218 options = filepath_find(respaths, "Choices");
2220 free(options);
2221 nsoption_commandline(&argc, argv, nsoptions);
2222
2223 /* message init */
2224 messages = filepath_find(respaths, "Messages");
2225 ret = messages_add_from_file(messages);
2226 free(messages);
2227 if (ret != NSERROR_OK) {
2228 fprintf(stderr, "Message translations failed to load\n");
2229 }
2230
2231 /* common initialisation */
2232 ret = netsurf_init(NULL);
2233 if (ret != NSERROR_OK) {
2234 die("NetSurf failed to initialise");
2235 }
2236
2237 /* Override, since we have no support for non-core SELECT menu */
2238 nsoption_set_bool(core_select_menu, true);
2239
2240 if (process_cmdline(argc,argv) != true)
2241 die("unable to process command line.\n");
2242
2244 if (nsfb == NULL)
2245 die("Unable to initialise framebuffer");
2246
2248
2249 if (fb_font_init() == false)
2250 die("Unable to initialise the font system");
2251
2252 fbtk = fbtk_init(nsfb);
2253
2255
2256 urldb_load_cookies(nsoption_charp(cookie_file));
2257
2258 /* create an initial browser window */
2259
2260 NSLOG(netsurf, INFO, "calling browser_window_create");
2261
2262 ret = nsurl_create(feurl, &url);
2263 if (ret == NSERROR_OK) {
2265 url,
2266 NULL,
2267 NULL,
2268 &bw);
2269 nsurl_unref(url);
2270 }
2271 if (ret != NSERROR_OK) {
2272 fb_warn_user("Errorcode:", messages_get_errorcode(ret));
2273 } else {
2275
2277 }
2278
2279 netsurf_exit();
2280
2281 if (fb_font_finalise() == false)
2282 NSLOG(netsurf, INFO, "Font finalisation failed.");
2283
2284 /* finalise options */
2286
2287 /* finalise logging */
2289
2290 return 0;
2291}
2292
2294{
2295 struct gui_window *gw;
2296 nsfb_t *nsfb = fbtk_get_nsfb(root);
2297
2298 /* Enforce a minimum */
2299 if (width < 300)
2300 width = 300;
2301 if (height < 200)
2302 height = 200;
2303
2304 if (framebuffer_resize(nsfb, width, height, febpp) == false) {
2305 return;
2306 }
2307
2309
2310 fewidth = width;
2311 feheight = height;
2312
2313 for (gw = window_list; gw != NULL; gw = gw->next) {
2315 nsoption_int(fb_furniture_size));
2316 }
2317
2319}
2320
2321
2322/*
2323 * Local Variables:
2324 * c-basic-offset:8
2325 * End:
2326 */
int main(int argc, char **argv)
Normal entry point from OS.
Definition: gui.c:6539
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:4444
void urldb_load_cookies(const char *filename)
Load a cookie file into the database.
Definition: urldb.c:4277
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:1237
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:1122
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:1913
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:1957
static nserror gui_window_event(struct gui_window *gw, enum gui_window_event event)
process miscellaneous window events
Definition: gui.c:2127
void gui_resize(fbtk_widget_t *root, int width, int height)
Definition: gui.c:2293
static void framebuffer_run(void)
Definition: gui.c:616
static bool fb_complete
Definition: gui.c:65
static void gui_window_remove_caret(struct gui_window *g)
Definition: gui.c:2109
static int fb_reload_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1097
static int fb_browser_window_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:810
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:1935
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:1787
static struct gui_window * gui_window_create(struct browser_window *bw, struct gui_window *existing, gui_window_create_flags flags)
Definition: gui.c:1825
static struct gui_misc_table framebuffer_misc_table
Definition: gui.c:2168
static void fb_update_back_forward(struct gui_window *gw)
Definition: gui.c:1047
static int fb_close_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1135
static void create_normal_browser_window(struct gui_window *gw, int furniture_width)
Definition: gui.c:1645
static void gui_window_start_throbber(struct gui_window *g)
Definition: gui.c:2057
static int fb_url_enter(void *pw, char *text)
Definition: gui.c:1166
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:1079
static void throbber_advance(void *pw)
Definition: gui.c:2000
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:1993
static void gui_window_stop_throbber(struct gui_window *gw)
Definition: gui.c:2064
static bool nslog_stream_configure(FILE *fptr)
Ensures output logging stream is correctly configured.
Definition: gui.c:608
static int fb_localhistory_btn_clik(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1199
static int fb_browser_window_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:654
static void gui_window_remove_from_window_list(struct gui_window *gw)
Definition: gui.c:1801
static void gui_quit(void)
Definition: gui.c:643
static struct gui_drag gui_drag
static void gui_window_remove_caret_cb(fbtk_widget_t *widget)
Definition: gui.c:2074
static int febpp
Definition: gui.c:464
static int fb_stop_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1110
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:1608
static int fb_url_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1185
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:2091
static int set_ptr_default_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1192
static struct gui_window_table framebuffer_window_table
Definition: gui.c:2152
static void resize_normal_browser_window(struct gui_window *gw, int furniture_width)
Definition: gui.c:1749
static int fb_scroll_callback(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1146
static const char * feurl
Definition: gui.c:467
static void gui_window_update_extent(struct gui_window *gw)
Definition: gui.c:1944
static void resize_browser_widget(struct gui_window *gw, int x, int y, int width, int height)
Definition: gui.c:1637
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:1870
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:1616
static int fb_leftarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:1061
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:1463
static int fb_browser_window_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: gui.c:852
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:263
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:161
int height
Definition: gui.c:162
@ 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
union nsoption_s::@149 value
colour c
Definition: nsoption.h:122
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:698
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:858
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
Definition: nsoption.c:610
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
Definition: nsoption.c:665
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:335
#define nsoption_setnull_charp(OPTION, VALUE)
set string option in default table if currently unset
Definition: nsoption.h:380
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:317
nsoption_e
Definition: nsoption.h:133
@ NSOPTION_LISTEND
Definition: nsoption.h:154
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:348
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:308
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