1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
|
/*
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <limits.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libnsfb.h>
#include <libnsfb_plot.h>
#include <libnsfb_event.h>
#include "desktop/gui.h"
#include "desktop/mouse.h"
#include "desktop/plotters.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
#include "utils/filepath.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/schedule.h"
#include "utils/types.h"
#include "utils/url.h"
#include "utils/utils.h"
#include "desktop/textinput.h"
#include "render/form.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
#include "framebuffer/framebuffer.h"
#include "framebuffer/schedule.h"
#include "framebuffer/findfile.h"
#include "framebuffer/image_data.h"
#include "framebuffer/font.h"
#include "framebuffer/options.h"
#include "content/urldb.h"
#include "desktop/history_core.h"
#include "content/fetch.h"
#define NSFB_TOOLBAR_DEFAULT_LAYOUT "blfsrut"
fbtk_widget_t *fbtk;
struct gui_window *input_window = NULL;
struct gui_window *search_current_window;
struct gui_window *window_list = NULL;
/* private data for browser user widget */
struct browser_widget_s {
struct browser_window *bw; /**< The browser window connected to this gui window */
int scrollx, scrolly; /**< scroll offsets. */
/* Pending window redraw state. */
bool redraw_required; /**< flag indicating the foreground loop
* needs to redraw the browser widget.
*/
bbox_t redraw_box; /**< Area requiring redraw. */
bool pan_required; /**< flag indicating the foreground loop
* needs to pan the window.
*/
int panx, pany; /**< Panning required. */
};
/* queue a redraw operation, co-ordinates are relative to the window */
static void
fb_queue_redraw(struct fbtk_widget_s *widget, int x0, int y0, int x1, int y1)
{
struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
bwidget->redraw_box.x0 = min(bwidget->redraw_box.x0, x0);
bwidget->redraw_box.y0 = min(bwidget->redraw_box.y0, y0);
bwidget->redraw_box.x1 = max(bwidget->redraw_box.x1, x1);
bwidget->redraw_box.y1 = max(bwidget->redraw_box.y1, y1);
if (fbtk_clip_to_widget(widget, &bwidget->redraw_box)) {
bwidget->redraw_required = true;
fbtk_request_redraw(widget);
} else {
bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
bwidget->redraw_box.y1 = bwidget->redraw_box.x1 = -(INT_MAX);
bwidget->redraw_required = false;
}
}
/* queue a window scroll */
static void
widget_scroll_y(struct gui_window *gw, int y, bool abs)
{
struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
int content_height;
int height;
float scale = gw->bw->scale;
LOG(("window scroll"));
if (abs) {
bwidget->pany = y - bwidget->scrolly;
} else {
bwidget->pany += y;
}
bwidget->pan_required = true;
content_height = content_get_height(gw->bw->current_content) * scale;
height = fbtk_get_height(gw->browser);
/* dont pan off the top */
if ((bwidget->scrolly + bwidget->pany) < 0)
bwidget->pany = -bwidget->scrolly;
/* do not pan off the bottom of the content */
if ((bwidget->scrolly + bwidget->pany) > (content_height - height))
bwidget->pany = (content_height - height) - bwidget->scrolly;
fbtk_request_redraw(gw->browser);
fbtk_set_scroll_position(gw->vscroll, bwidget->scrolly + bwidget->pany);
}
/* queue a window scroll */
static void
widget_scroll_x(struct gui_window *gw, int x, bool abs)
{
struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
int content_width;
int width;
float scale = gw->bw->scale;
if (abs) {
bwidget->panx = x - bwidget->scrollx;
} else {
bwidget->panx += x;
}
bwidget->pan_required = true;
content_width = content_get_width(gw->bw->current_content) * scale;
width = fbtk_get_width(gw->browser);
/* dont pan off the left */
if ((bwidget->scrollx + bwidget->panx) < 0)
bwidget->panx = - bwidget->scrollx;
/* do not pan off the right of the content */
if ((bwidget->scrollx + bwidget->panx) > (content_width - width))
bwidget->panx = (content_width - width) - bwidget->scrollx;
fbtk_request_redraw(gw->browser);
fbtk_set_scroll_position(gw->hscroll, bwidget->scrollx + bwidget->panx);
}
static void
fb_pan(fbtk_widget_t *widget,
struct browser_widget_s *bwidget,
struct browser_window *bw)
{
int x;
int y;
int width;
int height;
nsfb_bbox_t srcbox;
nsfb_bbox_t dstbox;
nsfb_t *nsfb = fbtk_get_nsfb(widget);
height = fbtk_get_height(widget);
width = fbtk_get_width(widget);
LOG(("panning %d, %d", bwidget->panx, bwidget->pany));
x = fbtk_get_absx(widget);
y = fbtk_get_absy(widget);
/* if the pan exceeds the viewport size just redraw the whole area */
if (bwidget->pany > height || bwidget->pany < -height ||
bwidget->panx > width || bwidget->panx < -width) {
bwidget->scrolly += bwidget->pany;
bwidget->scrollx += bwidget->panx;
fb_queue_redraw(widget, 0, 0, width, height);
/* ensure we don't try to scroll again */
bwidget->panx = 0;
bwidget->pany = 0;
}
if (bwidget->pany < 0) {
/* pan up by less then viewport height */
srcbox.x0 = x;
srcbox.y0 = y;
srcbox.x1 = srcbox.x0 + width;
srcbox.y1 = srcbox.y0 + height + bwidget->pany;
dstbox.x0 = x;
dstbox.y0 = y - bwidget->pany;
dstbox.x1 = dstbox.x0 + width;
dstbox.y1 = dstbox.y0 + height + bwidget->pany;
/* move part that remains visible up */
nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
/* redraw newly exposed area */
bwidget->scrolly += bwidget->pany;
fb_queue_redraw(widget, 0, 0, width, - bwidget->pany);
}
if (bwidget->pany > 0) {
/* pan down by less then viewport height */
srcbox.x0 = x;
srcbox.y0 = y + bwidget->pany;
srcbox.x1 = srcbox.x0 + width;
srcbox.y1 = srcbox.y0 + height - bwidget->pany;
dstbox.x0 = x;
dstbox.y0 = y;
dstbox.x1 = dstbox.x0 + width;
dstbox.y1 = dstbox.y0 + height - bwidget->pany;
/* move part that remains visible down */
nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
/* redraw newly exposed area */
bwidget->scrolly += bwidget->pany;
fb_queue_redraw(widget, 0, height - bwidget->pany, width, height);
}
if (bwidget->panx < 0) {
/* pan left by less then viewport width */
srcbox.x0 = x;
srcbox.y0 = y;
srcbox.x1 = srcbox.x0 + width + bwidget->panx;
srcbox.y1 = srcbox.y0 + height;
dstbox.x0 = x - bwidget->panx;
dstbox.y0 = y;
dstbox.x1 = dstbox.x0 + width + bwidget->panx;
dstbox.y1 = dstbox.y0 + height;
/* move part that remains visible left */
nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
/* redraw newly exposed area */
bwidget->scrollx += bwidget->panx;
fb_queue_redraw(widget, 0, 0, -bwidget->panx, height);
}
if (bwidget->panx > 0) {
/* pan right by less then viewport width */
srcbox.x0 = x + bwidget->panx;
srcbox.y0 = y;
srcbox.x1 = srcbox.x0 + width - bwidget->panx;
srcbox.y1 = srcbox.y0 + height;
dstbox.x0 = x;
dstbox.y0 = y;
dstbox.x1 = dstbox.x0 + width - bwidget->panx;
dstbox.y1 = dstbox.y0 + height;
/* move part that remains visible right */
nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox);
/* redraw newly exposed area */
bwidget->scrollx += bwidget->panx;
fb_queue_redraw(widget, width - bwidget->panx, 0, width, height);
}
bwidget->pan_required = false;
bwidget->panx = 0;
bwidget->pany = 0;
}
static void
fb_redraw(fbtk_widget_t *widget,
struct browser_widget_s *bwidget,
struct browser_window *bw)
{
int x;
int y;
struct rect clip;
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &fb_plotters
};
LOG(("%d,%d to %d,%d",
bwidget->redraw_box.x0,
bwidget->redraw_box.y0,
bwidget->redraw_box.x1,
bwidget->redraw_box.y1));
x = fbtk_get_absx(widget);
y = fbtk_get_absy(widget);
/* adjust clipping co-ordinates according to window location */
bwidget->redraw_box.y0 += y;
bwidget->redraw_box.y1 += y;
bwidget->redraw_box.x0 += x;
bwidget->redraw_box.x1 += x;
nsfb_claim(fbtk_get_nsfb(widget), &bwidget->redraw_box);
/* redraw bounding box is relative to window */
clip.x0 = bwidget->redraw_box.x0;
clip.y0 = bwidget->redraw_box.y0;
clip.x1 = bwidget->redraw_box.x1;
clip.y1 = bwidget->redraw_box.y1;
browser_window_redraw(bw,
(x - bwidget->scrollx) / bw->scale,
(y - bwidget->scrolly) / bw->scale,
&clip, &ctx);
nsfb_update(fbtk_get_nsfb(widget), &bwidget->redraw_box);
bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
bwidget->redraw_box.y1 = bwidget->redraw_box.x1 = INT_MIN;
bwidget->redraw_required = false;
}
static int
fb_browser_window_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
struct browser_widget_s *bwidget;
bwidget = fbtk_get_userpw(widget);
if (bwidget == NULL) {
LOG(("browser widget from widget %p was null", widget));
return -1;
}
if (bwidget->pan_required) {
fb_pan(widget, bwidget, gw->bw);
}
if (bwidget->redraw_required) {
fb_redraw(widget, bwidget, gw->bw);
} else {
bwidget->redraw_box.x0 = 0;
bwidget->redraw_box.y0 = 0;
bwidget->redraw_box.x1 = fbtk_get_width(widget);
bwidget->redraw_box.y1 = fbtk_get_height(widget);
fb_redraw(widget, bwidget, gw->bw);
}
return 0;
}
static const char *fename;
static int febpp;
static int fewidth;
static int feheight;
static const char *feurl;
static bool
process_cmdline(int argc, char** argv)
{
int opt;
LOG(("argc %d, argv %p", argc, argv));
fename = "sdl";
febpp = 32;
if ((option_window_width != 0) && (option_window_height != 0)) {
fewidth = option_window_width;
feheight = option_window_height;
} else {
fewidth = 800;
feheight = 600;
}
if (option_homepage_url != NULL && option_homepage_url[0] != '\0')
feurl = option_homepage_url;
else
feurl = NETSURF_HOMEPAGE;
while((opt = getopt(argc, argv, "f:b:w:h:")) != -1) {
switch (opt) {
case 'f':
fename = optarg;
break;
case 'b':
febpp = atoi(optarg);
break;
case 'w':
fewidth = atoi(optarg);
break;
case 'h':
feheight = atoi(optarg);
break;
default:
fprintf(stderr,
"Usage: %s [-f frontend] [-b bpp] url\n",
argv[0]);
return false;
}
}
if (optind < argc) {
feurl = argv[optind];
}
return true;
}
static void
gui_init(int argc, char** argv)
{
nsfb_t *nsfb;
option_core_select_menu = true;
if (option_cookie_file == NULL) {
option_cookie_file = strdup("~/.netsurf/Cookies");
LOG(("Using '%s' as Cookies file", option_cookie_file));
}
if (option_cookie_jar == NULL) {
option_cookie_jar = strdup("~/.netsurf/Cookies");
LOG(("Using '%s' as Cookie Jar file", option_cookie_jar));
}
if (option_cookie_file == NULL || option_cookie_jar == NULL)
die("Failed initialising cookie options");
if (process_cmdline(argc,argv) != true)
die("unable to process command line.\n");
nsfb = framebuffer_initialise(fename, fewidth, feheight, febpp);
if (nsfb == NULL)
die("Unable to initialise framebuffer");
framebuffer_set_cursor(&pointer_image);
if (fb_font_init() == false)
die("Unable to initialise the font system");
fbtk = fbtk_init(nsfb);
fbtk_enable_oskb(fbtk);
urldb_load_cookies(option_cookie_file);
}
/** Entry point from OS.
*
* /param argc The number of arguments in the string vector.
* /param argv The argument string vector.
* /return The return code to the OS
*/
int
main(int argc, char** argv)
{
struct browser_window *bw;
char *options;
char *messages;
setbuf(stderr, NULL);
respaths = fb_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"NETSURF_FB_RESPATH":./framebuffer/res:"NETSURF_FB_FONTPATH);
options = filepath_find(respaths, "Choices");
messages = filepath_find(respaths, "messages");
netsurf_init(&argc, &argv, options, messages);
free(messages);
free(options);
gui_init(argc, argv);
LOG(("calling browser_window_create"));
bw = browser_window_create(feurl, 0, 0, true, false);
netsurf_main_loop();
browser_window_destroy(bw);
netsurf_exit();
return 0;
}
void
gui_poll(bool active)
{
nsfb_event_t event;
int timeout; /* timeout in miliseconds */
/* run the scheduler and discover how long to wait for the next event */
timeout = schedule_run();
/* if active do not wait for event, return immediately */
if (active)
timeout = 0;
/* if redraws are pending do not wait for event, return immediately */
if (fbtk_get_redraw_pending(fbtk))
timeout = 0;
if (fbtk_event(fbtk, &event, timeout)) {
if ((event.type == NSFB_EVENT_CONTROL) &&
(event.value.controlcode == NSFB_CONTROL_QUIT))
netsurf_quit = true;
}
fbtk_redraw(fbtk);
}
void
gui_quit(void)
{
LOG(("gui_quit"));
urldb_save_cookies(option_cookie_jar);
framebuffer_finalise();
}
/* called back when click in browser window */
static int
fb_browser_window_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
float scale;
if (cbi->event->type != NSFB_EVENT_KEY_DOWN &&
cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
LOG(("browser window clicked at %d,%d", cbi->x, cbi->y));
switch (cbi->event->type) {
case NSFB_EVENT_KEY_DOWN:
switch (cbi->event->value.keycode) {
case NSFB_KEY_MOUSE_1:
scale = gw->bw->scale;
browser_window_mouse_click(gw->bw,
BROWSER_MOUSE_PRESS_1,
(cbi->x + bwidget->scrollx) / scale,
(cbi->y + bwidget->scrolly) / scale);
break;
case NSFB_KEY_MOUSE_3:
scale = gw->bw->scale;
browser_window_mouse_click(gw->bw,
BROWSER_MOUSE_PRESS_2,
(cbi->x + bwidget->scrollx) / scale,
(cbi->y + bwidget->scrolly) / scale);
break;
case NSFB_KEY_MOUSE_4:
/* scroll up */
scale = gw->bw->scale;
if (browser_window_scroll_at_point(gw->bw,
(cbi->x + bwidget->scrollx) / scale,
(cbi->y + bwidget->scrolly) / scale,
0, -100) == false)
widget_scroll_y(gw, -100, false);
break;
case NSFB_KEY_MOUSE_5:
/* scroll down */
scale = gw->bw->scale;
if (browser_window_scroll_at_point(gw->bw,
(cbi->x + bwidget->scrollx) / scale,
(cbi->y + bwidget->scrolly) / scale,
0, 100) == false)
widget_scroll_y(gw, 100, false);
break;
default:
break;
}
break;
case NSFB_EVENT_KEY_UP:
switch (cbi->event->value.keycode) {
case NSFB_KEY_MOUSE_1:
scale = gw->bw->scale;
browser_window_mouse_click(gw->bw,
BROWSER_MOUSE_CLICK_1,
(cbi->x + bwidget->scrollx) / scale,
(cbi->y + bwidget->scrolly) / scale);
break;
case NSFB_KEY_MOUSE_3:
scale = gw->bw->scale;
browser_window_mouse_click(gw->bw,
BROWSER_MOUSE_CLICK_2,
(cbi->x + bwidget->scrollx) / scale,
(cbi->y + bwidget->scrolly) / scale);
break;
default:
break;
}
break;
default:
break;
}
return 1;
}
/* called back when movement in browser window */
static int
fb_browser_window_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
browser_window_mouse_track(gw->bw, 0,
(cbi->x + bwidget->scrollx) / gw->bw->scale,
(cbi->y + bwidget->scrolly) / gw->bw->scale);
return 0;
}
static int
fb_browser_window_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
static uint8_t modifier = 0;
int ucs4 = -1;
LOG(("got value %d", cbi->event->value.keycode));
switch (cbi->event->type) {
case NSFB_EVENT_KEY_DOWN:
switch (cbi->event->value.keycode) {
case NSFB_KEY_PAGEUP:
if (browser_window_key_press(gw->bw, KEY_PAGE_UP) == false)
widget_scroll_y(gw, -fbtk_get_height(gw->browser), false);
break;
case NSFB_KEY_PAGEDOWN:
if (browser_window_key_press(gw->bw, KEY_PAGE_DOWN) == false)
widget_scroll_y(gw, fbtk_get_height(gw->browser), false);
break;
case NSFB_KEY_RIGHT:
if (browser_window_key_press(gw->bw, KEY_RIGHT) == false)
widget_scroll_x(gw, 100, false);
break;
case NSFB_KEY_LEFT:
if (browser_window_key_press(gw->bw, KEY_LEFT) == false)
widget_scroll_x(gw, -100, false);
break;
case NSFB_KEY_UP:
if (browser_window_key_press(gw->bw, KEY_UP) == false)
widget_scroll_y(gw, -100, false);
break;
case NSFB_KEY_DOWN:
if (browser_window_key_press(gw->bw, KEY_DOWN) == false)
widget_scroll_y(gw, 100, false);
break;
case NSFB_KEY_RSHIFT:
modifier |= 1;
break;
case NSFB_KEY_LSHIFT:
modifier |= 1<<1;
break;
default:
ucs4 = fbtk_keycode_to_ucs4(cbi->event->value.keycode,
modifier);
if (ucs4 != -1)
browser_window_key_press(gw->bw, ucs4);
break;
}
break;
case NSFB_EVENT_KEY_UP:
switch (cbi->event->value.keycode) {
case NSFB_KEY_RSHIFT:
modifier &= ~1;
break;
case NSFB_KEY_LSHIFT:
modifier &= ~(1<<1);
break;
default:
break;
}
break;
default:
break;
}
return 0;
}
static void
fb_update_back_forward(struct gui_window *gw)
{
struct browser_window *bw = gw->bw;
fbtk_set_bitmap(gw->back,
(browser_window_back_available(bw)) ?
&left_arrow : &left_arrow_g);
fbtk_set_bitmap(gw->forward,
(browser_window_forward_available(bw)) ?
&right_arrow : &right_arrow_g);
}
/* left icon click routine */
static int
fb_leftarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
struct browser_window *bw = gw->bw;
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
if (history_back_available(bw->history))
history_back(bw, bw->history);
fb_update_back_forward(gw);
return 1;
}
/* right arrow icon click routine */
static int
fb_rightarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
struct browser_window *bw = gw->bw;
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
if (history_forward_available(bw->history))
history_forward(bw, bw->history);
fb_update_back_forward(gw);
return 1;
}
/* reload icon click routine */
static int
fb_reload_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct browser_window *bw = cbi->context;
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
browser_window_reload(bw, true);
return 1;
}
/* stop icon click routine */
static int
fb_stop_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct browser_window *bw = cbi->context;
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
browser_window_stop(bw);
return 0;
}
static int
fb_osk_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
map_osk();
return 0;
}
/* close browser window icon click routine */
static int
fb_close_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
netsurf_quit = true;
return 0;
}
static int
fb_scroll_callback(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
switch (cbi->type) {
case FBTK_CBT_SCROLLY:
widget_scroll_y(gw, cbi->y, true);
break;
case FBTK_CBT_SCROLLX:
widget_scroll_x(gw, cbi->x, true);
break;
default:
break;
}
return 0;
}
static int
fb_url_enter(void *pw, char *text)
{
struct browser_window *bw = pw;
browser_window_go(bw, text, 0, true);
return 0;
}
static int
fb_url_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
framebuffer_set_cursor(&caret_image);
return 0;
}
static int
set_ptr_default_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
framebuffer_set_cursor(&pointer_image);
return 0;
}
static int
fb_localhistory_btn_clik(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = cbi->context;
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
fb_localhistory_map(gw->localhistory);
return 0;
}
/** Create a toolbar window and populate it with buttons.
*
* The toolbar layout uses a character to define buttons type and position:
* b - back
* l - local history
* f - forward
* s - stop
* r - refresh
* u - url bar expands to fit remaining space
* t - throbber/activity indicator
* c - close the current window
*
* The default layout is "blfsrut" there should be no more than a
* single url bar entry or behaviour will be undefined.
*
* @param gw Parent window
* @param toolbar_height The height in pixels of the toolbar
* @param padding The padding in pixels round each element of the toolbar
* @param frame_col Frame colour.
* @param toolbar_layout A string defining which buttons and controls
* should be added to the toolbar. May be empty
* string to disable the bar..
*
*/
static fbtk_widget_t *
create_toolbar(struct gui_window *gw,
int toolbar_height,
int padding,
colour frame_col,
const char *toolbar_layout)
{
fbtk_widget_t *toolbar;
fbtk_widget_t *widget;
int xpos; /* The position of the next widget. */
int xlhs = 0; /* extent of the left hand side widgets */
int xdir = 1; /* the direction of movement + or - 1 */
const char *itmtype; /* type of the next item */
if (toolbar_layout == NULL) {
toolbar_layout = NSFB_TOOLBAR_DEFAULT_LAYOUT;
}
LOG(("Using toolbar layout %s", toolbar_layout));
itmtype = toolbar_layout;
if (*itmtype == 0) {
return NULL;
}
toolbar = fbtk_create_window(gw->window, 0, 0, 0,
toolbar_height,
frame_col);
if (toolbar == NULL) {
return NULL;
}
fbtk_set_handler(toolbar,
FBTK_CBT_POINTERENTER,
set_ptr_default_move,
NULL);
xpos = padding;
/* loop proceeds creating widget on the left hand side until
* it runs out of layout or encounters a url bar declaration
* wherupon it works backwards from the end of the layout
* untill the space left is for the url bar
*/
while ((itmtype >= toolbar_layout) &&
(*itmtype != 0) &&
(xdir !=0)) {
LOG(("toolbar adding %c", *itmtype));
switch (*itmtype) {
case 'b': /* back */
widget = fbtk_create_button(toolbar,
(xdir == 1) ? xpos :
xpos - left_arrow.width,
padding,
left_arrow.width,
-padding,
frame_col,
&left_arrow,
fb_leftarrow_click,
gw);
gw->back = widget; /* keep reference */
break;
case 'l': /* local history */
widget = fbtk_create_button(toolbar,
(xdir == 1) ? xpos :
xpos - history_image.width,
padding,
history_image.width,
-padding,
frame_col,
&history_image,
fb_localhistory_btn_clik,
gw);
break;
case 'f': /* forward */
widget = fbtk_create_button(toolbar,
(xdir == 1)?xpos :
xpos - right_arrow.width,
padding,
right_arrow.width,
-padding,
frame_col,
&right_arrow,
fb_rightarrow_click,
gw);
gw->forward = widget;
break;
case 'c': /* close the current window */
widget = fbtk_create_button(toolbar,
(xdir == 1)?xpos :
xpos - stop_image_g.width,
padding,
stop_image_g.width,
-padding,
frame_col,
&stop_image_g,
fb_close_click,
gw->bw);
break;
case 's': /* stop */
widget = fbtk_create_button(toolbar,
(xdir == 1)?xpos :
xpos - stop_image.width,
padding,
stop_image.width,
-padding,
frame_col,
&stop_image,
fb_stop_click,
gw->bw);
break;
case 'r': /* reload */
widget = fbtk_create_button(toolbar,
(xdir == 1)?xpos :
xpos - reload.width,
padding,
reload.width,
-padding,
frame_col,
&reload,
fb_reload_click,
gw->bw);
break;
case 't': /* throbber/activity indicator */
widget = fbtk_create_bitmap(toolbar,
(xdir == 1)?xpos :
xpos - throbber0.width,
padding,
throbber0.width,
-padding,
frame_col,
&throbber0);
gw->throbber = widget;
break;
case 'u': /* url bar*/
if (xdir == -1) {
/* met the u going backwards add url
* now we know available extent
*/
widget = fbtk_create_writable_text(toolbar,
xlhs,
padding,
xpos - xlhs,
-padding,
FB_COLOUR_WHITE,
FB_COLOUR_BLACK,
true,
fb_url_enter,
gw->bw);
fbtk_set_handler(widget,
FBTK_CBT_POINTERENTER,
fb_url_move, gw->bw);
gw->url = widget; /* keep reference */
/* toolbar is complete */
xdir = 0;
break;
}
/* met url going forwards, note position and
* reverse direction
*/
itmtype = toolbar_layout + strlen(toolbar_layout);
xdir = -1;
xlhs = xpos;
xpos = (2 * fbtk_get_width(toolbar));
widget = toolbar;
break;
default:
widget = NULL;
xdir = 0;
LOG(("Unknown element %c in toolbar layout", *itmtype));
break;
}
if (widget != NULL) {
xpos += (xdir * (fbtk_get_width(widget) + padding));
}
LOG(("xpos is %d",xpos));
itmtype += xdir;
}
fbtk_set_mapping(toolbar, true);
return toolbar;
}
static void
create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_width)
{
struct browser_widget_s *browser_widget;
browser_widget = calloc(1, sizeof(struct browser_widget_s));
gw->browser = fbtk_create_user(gw->window,
0,
toolbar_height,
-furniture_width,
-furniture_width,
browser_widget);
fbtk_set_handler(gw->browser, FBTK_CBT_REDRAW, fb_browser_window_redraw, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_INPUT, fb_browser_window_input, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_CLICK, fb_browser_window_click, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_POINTERMOVE, fb_browser_window_move, gw);
}
static void
create_normal_browser_window(struct gui_window *gw, int furniture_width)
{
fbtk_widget_t *widget;
fbtk_widget_t *toolbar;
int statusbar_width = 0;
int toolbar_height = option_fb_toolbar_size;
LOG(("Normal window"));
gw->window = fbtk_create_window(fbtk, 0, 0, 0, 0, 0);
statusbar_width = option_toolbar_status_width *
fbtk_get_width(gw->window) / 10000;
/* toolbar */
toolbar = create_toolbar(gw,
toolbar_height,
2,
FB_FRAME_COLOUR,
option_fb_toolbar_layout);
/* set the actually created toolbar height */
if (toolbar != NULL) {
toolbar_height = fbtk_get_height(toolbar);
} else {
toolbar_height = 0;
}
/* status bar */
gw->status = fbtk_create_text(gw->window,
0,
fbtk_get_height(gw->window) - furniture_width,
statusbar_width, furniture_width,
FB_FRAME_COLOUR, FB_COLOUR_BLACK,
false);
fbtk_set_handler(gw->status, FBTK_CBT_POINTERENTER, set_ptr_default_move, NULL);
LOG(("status bar %p at %d,%d", gw->status, fbtk_get_absx(gw->status), fbtk_get_absy(gw->status)));
/* create horizontal scrollbar */
gw->hscroll = fbtk_create_hscroll(gw->window,
statusbar_width,
fbtk_get_height(gw->window) - furniture_width,
fbtk_get_width(gw->window) - statusbar_width - furniture_width,
furniture_width,
FB_SCROLL_COLOUR,
FB_FRAME_COLOUR,
fb_scroll_callback,
gw);
/* fill bottom right area */
if (option_fb_osk == true) {
widget = fbtk_create_text_button(gw->window,
fbtk_get_width(gw->window) - furniture_width,
fbtk_get_height(gw->window) - furniture_width,
furniture_width,
furniture_width,
FB_FRAME_COLOUR, FB_COLOUR_BLACK,
fb_osk_click,
NULL);
fbtk_set_text(widget, "\xe2\x8c\xa8");
} else {
widget = fbtk_create_fill(gw->window,
fbtk_get_width(gw->window) - furniture_width,
fbtk_get_height(gw->window) - furniture_width,
furniture_width,
furniture_width,
FB_FRAME_COLOUR);
fbtk_set_handler(widget, FBTK_CBT_POINTERENTER, set_ptr_default_move, NULL);
}
/* create vertical scrollbar */
gw->vscroll = fbtk_create_vscroll(gw->window,
fbtk_get_width(gw->window) - furniture_width,
toolbar_height,
furniture_width,
fbtk_get_height(gw->window) - toolbar_height - furniture_width,
FB_SCROLL_COLOUR,
FB_FRAME_COLOUR,
fb_scroll_callback,
gw);
/* browser widget */
create_browser_widget(gw, toolbar_height, option_fb_furniture_size);
/* Give browser_window's user widget input focus */
fbtk_set_focus(gw->browser);
}
struct gui_window *
gui_create_browser_window(struct browser_window *bw,
struct browser_window *clone,
bool new_tab)
{
struct gui_window *gw;
gw = calloc(1, sizeof(struct gui_window));
if (gw == NULL)
return NULL;
/* seems we need to associate the gui window with the underlying
* browser window
*/
gw->bw = bw;
create_normal_browser_window(gw, option_fb_furniture_size);
gw->localhistory = fb_create_localhistory(bw, fbtk, option_fb_furniture_size);
/* map and request redraw of gui window */
fbtk_set_mapping(gw->window, true);
return gw;
}
void
gui_window_destroy(struct gui_window *gw)
{
fbtk_destroy_widget(gw->window);
free(gw);
}
void
gui_window_set_title(struct gui_window *g, const char *title)
{
LOG(("%p, %s", g, title));
}
void
gui_window_redraw_window(struct gui_window *g)
{
fb_queue_redraw(g->browser, 0, 0, fbtk_get_width(g->browser), fbtk_get_height(g->browser) );
}
void
gui_window_update_box(struct gui_window *g, const struct rect *rect)
{
struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
fb_queue_redraw(g->browser,
rect->x0 - bwidget->scrollx,
rect->y0 - bwidget->scrolly,
rect->x1 - bwidget->scrollx,
rect->y1 - bwidget->scrolly);
}
bool
gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
{
struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
*sx = bwidget->scrollx / g->bw->scale;
*sy = bwidget->scrolly / g->bw->scale;
return true;
}
void
gui_window_set_scroll(struct gui_window *gw, int sx, int sy)
{
struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser);
assert(bwidget);
widget_scroll_x(gw, sx * gw->bw->scale, true);
widget_scroll_y(gw, sy * gw->bw->scale, true);
}
void
gui_window_scroll_visible(struct gui_window *g, int x0, int y0,
int x1, int y1)
{
LOG(("%s:(%p, %d, %d, %d, %d)", __func__, g, x0, y0, x1, y1));
}
void
gui_window_get_dimensions(struct gui_window *g,
int *width,
int *height,
bool scaled)
{
*width = fbtk_get_width(g->browser);
*height = fbtk_get_height(g->browser);
if (scaled) {
*width /= g->bw->scale;
*height /= g->bw->scale;
}
}
void
gui_window_update_extent(struct gui_window *gw)
{
float scale = gw->bw->scale;
fbtk_set_scroll_parameters(gw->hscroll, 0,
content_get_width(gw->bw->current_content) * scale,
fbtk_get_width(gw->browser), 100);
fbtk_set_scroll_parameters(gw->vscroll, 0,
content_get_height(gw->bw->current_content) * scale,
fbtk_get_height(gw->browser), 100);
}
void
gui_window_set_status(struct gui_window *g, const char *text)
{
fbtk_set_text(g->status, text);
}
void
gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
{
switch (shape) {
case GUI_POINTER_POINT:
framebuffer_set_cursor(&hand_image);
break;
case GUI_POINTER_CARET:
framebuffer_set_cursor(&caret_image);
break;
case GUI_POINTER_MENU:
framebuffer_set_cursor(&menu_image);
break;
case GUI_POINTER_PROGRESS:
framebuffer_set_cursor(&progress_image);
break;
default:
framebuffer_set_cursor(&pointer_image);
break;
}
}
void
gui_window_hide_pointer(struct gui_window *g)
{
}
void
gui_window_set_url(struct gui_window *g, const char *url)
{
fbtk_set_text(g->url, url);
}
static void
throbber_advance(void *pw)
{
struct gui_window *g = pw;
struct fbtk_bitmap *image;
switch (g->throbber_index) {
case 0:
image = &throbber1;
g->throbber_index = 1;
break;
case 1:
image = &throbber2;
g->throbber_index = 2;
break;
case 2:
image = &throbber3;
g->throbber_index = 3;
break;
case 3:
image = &throbber4;
g->throbber_index = 4;
break;
case 4:
image = &throbber5;
g->throbber_index = 5;
break;
case 5:
image = &throbber6;
g->throbber_index = 6;
break;
case 6:
image = &throbber7;
g->throbber_index = 7;
break;
case 7:
image = &throbber8;
g->throbber_index = 0;
break;
default:
return;
}
if (g->throbber_index >= 0) {
fbtk_set_bitmap(g->throbber, image);
schedule(10, throbber_advance, g);
}
}
void
gui_window_start_throbber(struct gui_window *g)
{
g->throbber_index = 0;
schedule(10, throbber_advance, g);
}
void
gui_window_stop_throbber(struct gui_window *gw)
{
gw->throbber_index = -1;
fbtk_set_bitmap(gw->throbber, &throbber0);
fb_update_back_forward(gw);
}
void
gui_window_place_caret(struct gui_window *g, int x, int y, int height)
{
}
void
gui_window_remove_caret(struct gui_window *g)
{
}
void
gui_window_new_content(struct gui_window *g)
{
}
bool
gui_window_scroll_start(struct gui_window *g)
{
return true;
}
bool
gui_window_drag_start(struct gui_window *g, gui_drag_type type,
const struct rect *rect)
{
return true;
}
void
gui_window_save_link(struct gui_window *g, const char *url, const char *title)
{
}
/**
* set favicon
*/
void
gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
{
}
/**
* set gui display of a retrieved favicon representing the search provider
* \param ico may be NULL for local calls; then access current cache from
* search_web_ico()
*/
void
gui_window_set_search_ico(hlcache_handle *ico)
{
}
struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *parent)
{
return NULL;
}
nserror
gui_download_window_data(struct gui_download_window *dw,
const char *data,
unsigned int size)
{
return NSERROR_OK;
}
void
gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
}
void
gui_download_window_done(struct gui_download_window *dw)
{
}
void
gui_drag_save_object(gui_save_type type,
hlcache_handle *c,
struct gui_window *w)
{
}
void
gui_drag_save_selection(struct selection *s, struct gui_window *g)
{
}
void
gui_start_selection(struct gui_window *g)
{
}
void
gui_clear_selection(struct gui_window *g)
{
}
void
gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{
}
bool
gui_empty_clipboard(void)
{
return false;
}
bool
gui_add_to_clipboard(const char *text, size_t length, bool space)
{
return false;
}
bool
gui_commit_clipboard(void)
{
return false;
}
bool
gui_copy_to_clipboard(struct selection *s)
{
return false;
}
void
gui_create_form_select_menu(struct browser_window *bw,
struct form_control *control)
{
}
void
gui_launch_url(const char *url)
{
}
void
gui_cert_verify(const char *url,
const struct ssl_cert_info *certs,
unsigned long num,
nserror (*cb)(bool proceed, void *pw),
void *cbpw)
{
cb(false, cbpw);
}
/*
* Local Variables:
* c-basic-offset:8
* End:
*/
|