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