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 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901
|
/*
* htmltable.c ---
*
* This file contains code for layout of tables.
*
*--------------------------------------------------------------------------
* Copyright (c) 2005 Eolas Technologies Inc.
* All rights reserved.
*
* This Open Source project was made possible through the financial support
* of Eolas Technologies Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <ORGANIZATION> nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
static const char rcsid[] = "$Id: htmltable.c,v 1.124 2007/11/03 11:23:16 danielk1977 Exp $";
#include "htmllayout.h"
#define LOG if (pLayout->pTree->options.logcmd && !pLayout->minmaxTest)
struct TableCell {
BoxContext box;
int startrow; /* Index of row cell starts at */
int finrow; /* Index of row cell ends at */
int colspan; /* Number of columns spanned by cell (often 1) */
HtmlNode *pNode; /* Node with "display:table-cell" */
};
typedef struct TableCell TableCell;
typedef struct CellReqWidth CellReqWidth;
struct CellReqWidth {
int eType;
union {
int iVal; /* For CELL_WIDTH_PIXELS */
float fVal; /* For CELL_WIDTH_PERCENT */
} x;
};
#define CELL_WIDTH_AUTO 0
#define CELL_WIDTH_PIXELS 1
#define CELL_WIDTH_PERCENT 2
/*
* Structure used whilst laying out tables. See HtmlTableLayout().
*/
struct TableData {
HtmlNode *pNode; /* <table> node */
LayoutContext *pLayout;
int border_spacing; /* Pixel value of 'border-spacing' property */
int availablewidth; /* Width available between margins for table */
/*
* Determined by:
*
* tableCountCells()
*/
int nCol; /* Total number of columns in table */
int nRow; /* Total number of rows in table */
/*
* The following four arrays are populated by the two-pass algorithm
* implemented by functions:
*
* tableColWidthSingleSpan()
* tableColWidthMultiSpan()
*/
int *aMaxWidth; /* Maximum content width of each column */
int *aMinWidth; /* Minimum content width of each column */
CellReqWidth *aReqWidth; /* Widths requested via CSS */
CellReqWidth *aSingleReqWidth; /* Widths requested by single span cells */
/*
* Determined by:
*
* tableCalculateCellWidths()
*/
int *aWidth; /* Actual widths of each column (calculated) */
int *aY; /* Top y-coord for each row+1, wrt table box */
TableCell *aCell;
int row; /* Current row */
int y; /* y-coord to draw at */
int x; /* x-coord to draw at */
BoxContext *pBox; /* Box to draw into */
HtmlComputedValues *pDefaultProperties;
};
typedef struct TableData TableData;
/* The two types of callbacks made by tableIterate(). */
typedef int (CellCallback)(HtmlNode *, int, int, int, int, void *);
typedef int (RowCallback)(HtmlNode *, int, void *);
/* Iterate through each cell in each row of the table. */
static void tableIterate(HtmlTree*,HtmlNode*, CellCallback, RowCallback, void*);
/* Count the number of rows/columns in the table */
static CellCallback tableCountCells;
/* Populate the aMinWidth, aMaxWidth, aReqWidth and aSingleReqWidth array
* members of the TableData structure.
*/
static CellCallback tableColWidthSingleSpan;
static CellCallback tableColWidthMultiSpan;
/* Figure out the actual column widths (TableData.aWidth[]). */
static void tableCalculateCellWidths(TableData *, int, int);
/* A row and cell callback (used together in a single iteration) to draw
* the table content. All the actual drawing is done here. Everything
* else is just about figuring out column widths.
*/
static CellCallback tableDrawCells;
static RowCallback tableDrawRow;
/*
*---------------------------------------------------------------------------
*
* walkChildren() --
*
* This function is a wrapper around HtmlWalkTree(). It is identical
* in all respects but one - the callback function is not invoked for
* pNode (the root of the tree).
*
* Results:
* None.
*
* Side effects:
* Whatever xCallback() does.
*
*---------------------------------------------------------------------------
*/
#if 0
static void
walkChildren(pTree, pNode, xCallback, pContext)
HtmlTree *pTree;
HtmlNode *pNode;
int (*xCallback)(HtmlTree *, HtmlNode *, ClientData clientData);
ClientData pContext;
{
int i;
int nChild = HtmlNodeNumChildren(pNode);
for (i = 0; i < nChild; i++) {
HtmlNode *pChild = HtmlNodeChild(pNode, i);
xCallback(pTree, pChild, pContext);
}
}
#endif
static void
fixNodeProperties(pData, pNode)
TableData *pData;
HtmlNode *pNode;
{
HtmlElementNode *pElem = (HtmlElementNode *)pNode;
if (!pElem->pPropertyValues) {
if (!pData->pDefaultProperties) {
HtmlTree *pTree = pData->pLayout->pTree;
HtmlComputedValuesCreator sCreator;
HtmlComputedValuesInit(pTree, pNode, 0, &sCreator);
pData->pDefaultProperties = HtmlComputedValuesFinish(&sCreator);
}
pElem->pPropertyValues = pData->pDefaultProperties;
}
}
/*
*---------------------------------------------------------------------------
*
* tableColWidthSingleSpan --
*
* A tableIterate() callback to determine the following for each
* column in the table:
*
* * The minimum content width
* * The maximum content width
* * The requested width (may be in pixels, a percentage or "auto")
*
* This function only considers cells that span a single column (either
* colspan="1" cells, or cells with no explicit colspan value). A second
* tableIterate() loop, with tableColWidthMultiSpan() as the callback
* analyses the cells that span multiple columns.
*
* Results:
* None.
*
* Side effects:
* Populates the following arrays:
*
* TableData.aMinWidth[]
* TableData.aMaxWidth[]
* TableData.aSingleReqWidth[]
*
*---------------------------------------------------------------------------
*/
static int
tableColWidthSingleSpan(pNode, col, colspan, row, rowspan, pContext)
HtmlNode *pNode;
int col;
int colspan;
int row;
int rowspan;
void *pContext;
{
TableData *pData = (TableData *)pContext;
int *aMinWidth = pData->aMinWidth;
int *aMaxWidth = pData->aMaxWidth;
/* Because a cell originates in this column, it's min and max width
* must be at least 1 pixel. It doesn't matter if the cell spans
* multiple columns or not (gleaned from alternative CSS engine
* implementation).
*/
aMaxWidth[col] = MAX(aMaxWidth[col], 1);
aMinWidth[col] = MAX(aMinWidth[col], 1);
if (colspan == 1) {
HtmlComputedValues *pV;
BoxProperties box;
int max;
int min;
/* Note: aReq is an alias for aSingleReqWidth, NOT aReqWidth.
* aReqWidth is populated by the second analysis parse of
* the table - the one that uses tableColWidthMultiSpan().
*/
CellReqWidth *aReq = pData->aSingleReqWidth;
/* Figure out the minimum and maximum widths of the content */
fixNodeProperties(pData, pNode);
pV = HtmlNodeComputedValues(pNode);
blockMinMaxWidth(pData->pLayout, pNode, &min, &max);
nodeGetBoxProperties(pData->pLayout, pNode, 0, &box);
aMinWidth[col] = MAX(aMinWidth[col], min + box.iLeft + box.iRight);
aMaxWidth[col] = MAX(aMaxWidth[col], max + box.iLeft + box.iRight);
assert(aMinWidth[col] <= aMaxWidth[col]);
if (pV->mask & PROP_MASK_WIDTH) {
/* The computed value of the 'width' property is a percentage */
float val = ((float)pV->iWidth) / 100.0;
switch (aReq[col].eType) {
case CELL_WIDTH_AUTO:
case CELL_WIDTH_PIXELS:
aReq[col].eType = CELL_WIDTH_PERCENT;
aReq[col].x.fVal = val;
break;
case CELL_WIDTH_PERCENT:
aReq[col].x.fVal = MAX(aReq[col].x.fVal, val);
break;
}
} else if (pV->iWidth >= 0) {
/* There is a pixel value for the 'width' property */
int val = pV->iWidth + box.iLeft + box.iRight;
switch (aReq[col].eType) {
case CELL_WIDTH_AUTO:
case CELL_WIDTH_PIXELS:
aReq[col].eType = CELL_WIDTH_PIXELS;
aReq[col].x.iVal = MAX(aReq[col].x.iVal, val);
aMaxWidth[col] = MAX(val, aMaxWidth[col]);
break;
case CELL_WIDTH_PERCENT:
break;
}
}
}
return TCL_OK;
}
/*
*---------------------------------------------------------------------------
*
* logWidthsToTable --
*
* This function is only used by LOG{...} blocks (i.e. to debug the
* widget internals). It appends a formatted HTML table to the
* current value of pObj summarizing the values in the following arrays:
*
* pData->aReqWidth
* pData->aMinWidth
* pData->aMaxWidth
*
* Results:
* None.
*
* Side effects:
* Appends to pObj.
*
*---------------------------------------------------------------------------
*/
static void
logWidthsToTable(pData, pObj)
TableData *pData;
Tcl_Obj *pObj;
{
int *aMinWidth = pData->aMinWidth;
int *aMaxWidth = pData->aMaxWidth;
CellReqWidth *aReqWidth = pData->aReqWidth;
int ii;
Tcl_AppendToObj(pObj,
"<table><tr>"
" <th>Col Number"
" <th>Min Content Width"
" <th>Max Content Width"
" <th>Explicit Width"
" <th>Percentage Width", -1);
for (ii = 0; ii < pData->nCol; ii++) {
int jj;
char zPercent[32];
Tcl_AppendToObj(pObj, "<tr><td>", -1);
Tcl_AppendObjToObj(pObj, Tcl_NewIntObj(ii));
for (jj = 0; jj < 3; jj++) {
int val = PIXELVAL_AUTO;
switch (jj) {
case 0: val = aMinWidth[ii]; break;
case 1: val = aMaxWidth[ii]; break;
case 2:
if (aReqWidth[ii].eType == CELL_WIDTH_PIXELS) {
val = aReqWidth[ii].x.iVal;
} else {
val = PIXELVAL_AUTO;
}
break;
default:
assert(0);
}
Tcl_AppendToObj(pObj, "<td>", -1);
if (val != PIXELVAL_AUTO) {
Tcl_AppendObjToObj(pObj, Tcl_NewIntObj(val));
Tcl_AppendToObj(pObj, "px", -1);
} else {
Tcl_AppendToObj(pObj, "N/A", -1);
}
}
Tcl_AppendToObj(pObj, "<td>", -1);
if (aReqWidth[ii].eType == CELL_WIDTH_PERCENT) {
sprintf(zPercent, "%.2f%%", aReqWidth[ii].x.fVal);
} else {
sprintf(zPercent, "N/A");
}
Tcl_AppendToObj(pObj, zPercent, -1);
}
Tcl_AppendToObj(pObj, "</table>", -1);
}
static void
getReqWidth(pNode, pReq)
HtmlNode *pNode;
CellReqWidth *pReq;
{
HtmlComputedValues *pV = HtmlNodeComputedValues(pNode);
if (pV->mask & PROP_MASK_WIDTH) {
/* The computed value of the 'width' property is a percentage */
pReq->eType = CELL_WIDTH_PERCENT;
pReq->x.fVal = ((float)pV->iWidth) / 100.0;
} else if (pV->iWidth > 0) {
pReq->eType = CELL_WIDTH_PIXELS;
pReq->x.iVal = pV->iWidth;
} else {
pReq->eType = CELL_WIDTH_AUTO;
}
}
static void
logMinMaxWidths(pLayout, pNode, col, colspan, aMinWidth, aMaxWidth)
LayoutContext *pLayout;
HtmlNode *pNode;
int col;
int colspan;
int *aMinWidth;
int *aMaxWidth;
{
LOG {
int ii;
HtmlTree *pTree = pLayout->pTree;
Tcl_Obj *pMinWidths = Tcl_NewObj();
Tcl_IncrRefCount(pMinWidths);
Tcl_AppendToObj(pMinWidths, "<tr><th> aMinWidth", -1);
for (ii = col; ii < (col + colspan); ii++) {
Tcl_AppendToObj(pMinWidths, "<td>", 4);
Tcl_AppendObjToObj(pMinWidths, Tcl_NewIntObj(ii));
Tcl_AppendToObj(pMinWidths, ":", 1);
Tcl_AppendObjToObj(
pMinWidths, Tcl_NewIntObj(aMinWidth[ii])
);
}
Tcl_AppendToObj(pMinWidths, "<tr><th> aMaxWidths", -1);
for (ii = col; ii < (col + colspan); ii++) {
Tcl_AppendToObj(pMinWidths, "<td>", 4);
Tcl_AppendObjToObj(pMinWidths, Tcl_NewIntObj(ii));
Tcl_AppendToObj(pMinWidths, ":", 1);
Tcl_AppendObjToObj(
pMinWidths, Tcl_NewIntObj(aMaxWidth[ii])
);
}
HtmlLog(pTree, "LAYOUTENGINE",
"%s tableColWidthMultiSpan() aMinWidth before:"
"<table> %s </table>",
Tcl_GetString(HtmlNodeCommand(pTree, pNode)),
Tcl_GetString(pMinWidths)
);
Tcl_DecrRefCount(pMinWidths);
}
}
/*
*---------------------------------------------------------------------------
*
* tableColWidthMultiSpan --
*
* A tableIterate() callback to analyse the following for each
* cell in the table that spans more than one column:
*
* * The minimum content width
* * The maximum content width
* * The requested width (may be in pixels, a percentage or "auto")
*
* This function updates values set by the tableColWidthSingleSpan()
* loop.
*
* Results:
* None.
*
* Side effects:
* Populates the following arrays:
*
* TableData.aMinWidth[]
* TableData.aMaxWidth[]
* TableData.aReqWidth[]
*
*---------------------------------------------------------------------------
*/
static int
tableColWidthMultiSpan(pNode, col, colspan, row, rowspan, pContext)
HtmlNode *pNode;
int col;
int colspan;
int row;
int rowspan;
void *pContext;
{
TableData *pData = (TableData *)pContext;
int *aMinWidth = pData->aMinWidth;
int *aMaxWidth = pData->aMaxWidth;
CellReqWidth *aReq = pData->aSingleReqWidth;
CellReqWidth *aReqOut = pData->aReqWidth;
/* Because a cell originates in column $col, it's min and max content
* width must be at least 1 pixel. tableColWidthSingleSpan() should
* have taken care of this.
*/
assert(aMaxWidth[col] > 0);
assert(aMinWidth[col] > 0);
if (colspan > 1) {
double fTotalPercent = 0.0; /* Total of spanned percentage widths */
int iTotalMin = 0; /* Total min-width of all spanned cols */
int iTotalMax = 0; /* Total max-width of all spanned cols */
int iTotalPixel = 0; /* Total pixel width of all spanned cols */
int nPixelWidth = 0; /* Number of spanned pixel width cols */
int nPercentWidth = 0; /* Number of spanned percent width cols */
int nAutoWidth = 0; /* Number of spanned auto width cols */
int ii;
/* Minimum, maximum and requested width of the multi-span cell */
int min;
int max;
CellReqWidth req;
BoxProperties box;
/* Retrieve the min, max and requested width of the multi-span cell.
* Adjust min and max so that they take into account the
* 'border-spacing' regions that this cell spans and the borders and
* padding on the cell itself.
*/
getReqWidth(pNode, &req);
blockMinMaxWidth(pData->pLayout, pNode, &min, &max);
min = min - pData->border_spacing * (colspan - 1);
max = max - pData->border_spacing * (colspan - 1);
nodeGetBoxProperties(pData->pLayout, pNode, 0, &box);
min = min + box.iLeft + box.iRight;
max = max + box.iLeft + box.iRight;
for (ii = col; ii < (col + colspan); ii++) {
switch (aReq[ii].eType) {
case CELL_WIDTH_AUTO:
nAutoWidth++;
break;
case CELL_WIDTH_PIXELS:
iTotalPixel += aReq[ii].x.iVal;
nPixelWidth++;
break;
case CELL_WIDTH_PERCENT:
nPercentWidth++;
fTotalPercent += aReq[ii].x.fVal;
break;
}
iTotalMin += aMinWidth[ii];
iTotalMax += aMaxWidth[ii];
}
if (
req.eType == CELL_WIDTH_PERCENT &&
(colspan == nPercentWidth || fTotalPercent > req.x.fVal)
) {
/* We have no means to satisfy this condition, so simply discard
* the percentage width request.
*/
req.eType = CELL_WIDTH_AUTO;
}
if (req.eType == CELL_WIDTH_PERCENT) {
/* Any columns in the spanned set that do not already have
* percentage values are given them, so that the percentages
* add up to that requested by the spanning cell.
*
* If there is more than one column to add a percentage width
* to, the percentages are allocated in proportion to the
* maximum content widths of the columns.
*/
int iMaxNonPercent = 0;
float fRem = req.x.fVal - fTotalPercent;
for (ii = col; ii < (col + colspan); ii++) {
if (aReq[ii].eType != CELL_WIDTH_PERCENT) {
iMaxNonPercent += aMaxWidth[ii];
}
}
for (ii = col; ii < (col + colspan) && iMaxNonPercent > 0; ii++) {
if (aReq[ii].eType != CELL_WIDTH_PERCENT) {
aReqOut[ii].eType = CELL_WIDTH_PERCENT;
aReqOut[ii].x.fVal = fRem * aMaxWidth[ii] / iMaxNonPercent;
iMaxNonPercent -= aMaxWidth[ii];
}
}
assert(iMaxNonPercent == 0);
}
if (min > iTotalMin) {
/* The minimum required width for the spanning cell is greater
* than that of the columns it spans.
*/
int iRem = min;
int iTPW = iTotalPixel;
if (nPixelWidth == colspan) {
/* All spanned columns have explicit pixel widths. In this
* case try to divide up the minimum width of the spanning
* cell according to the ratio between the pixel widths.
* Respect each cells min-width while doing this.
*/
for (ii = col; ii < (col + colspan) && iTPW > 0; ii++) {
int w = MAX(aMinWidth[ii], iRem * aReq[ii].x.iVal / iTPW);
iRem -= w;
aMinWidth[ii] = w;
iTPW -= aReq[ii].x.iVal;
}
assert(iTPW == 0);
} else {
LayoutContext *pLayout = pData->pLayout;
int iMin = iTotalMin;
int iMax = iTotalMax;
LOG {
HtmlTree *pTree = pLayout->pTree;
HtmlLog(pTree, "LAYOUTENGINE",
"%s tableColWidthMultiSpan() Distributing %d pixels."
" iMax=%d iMin=%d.",
Tcl_GetString(HtmlNodeCommand(pTree, pNode)),
iRem, iMin, iMax
);
}
logMinMaxWidths(
pLayout, pNode, col, colspan, aMinWidth, aMaxWidth
);
for (ii = col; iMax >= 0 && ii < (col + colspan); ii++) {
int isFixed = (aReq[ii].eType == CELL_WIDTH_PIXELS);
if (isFixed && nAutoWidth > 0 && iTPW <= iRem) {
int w = MAX(aMinWidth[ii], aReq[ii].x.iVal);
iRem -= w;
iTPW -= aReq[ii].x.iVal;
iMax -= aMaxWidth[ii];
iMin -= aMinWidth[ii];
aMinWidth[ii] = w;
}
}
ii = col;
for (; iMax >= 0 && iMin < iRem && ii < (col + colspan); ii++){
int isFixed = (aReq[ii].eType == CELL_WIDTH_PIXELS);
if (!isFixed || nAutoWidth == 0) {
int w = aMinWidth[ii];
if (iMax) {
assert(aMaxWidth[ii] <= iMax);
w = MAX(w, iRem * aMaxWidth[ii] / iMax);
} else {
w = MAX(w, iRem);
}
assert(w <= iRem);
iMax -= aMaxWidth[ii];
iMin -= aMinWidth[ii];
iRem -= w;
aMinWidth[ii] = w;
}
}
logMinMaxWidths(
pLayout, pNode, col, colspan, aMinWidth, aMaxWidth
);
}
}
if (iTotalMax < max) {
int iM = iTotalMax; /* Current sum of aMaxWidth[] */
int iRem = max; /* Required sum of aMaxWidth[] */
for (ii = col; iM > 0 && iRem > 0 && ii < (col + colspan); ii++){
int w = MAX(aMaxWidth[ii], iRem * aMaxWidth[ii] / iM);
iM -= aMaxWidth[ii];
iRem -= w;
aMaxWidth[ii] = w;
}
}
for (ii = col; ii < (col + colspan); ii++){
aMaxWidth[ii] = MAX(aMaxWidth[ii], aMinWidth[ii]);
}
}
return TCL_OK;
}
/*
*---------------------------------------------------------------------------
*
* tableCountCells --
*
* A callback invoked by the tableIterate() function to figure out
* how many columns are in the table.
*
* Results:
* None.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
tableCountCells(pNode, col, colspan, row, rowspan, pContext)
HtmlNode *pNode;
int col;
int colspan;
int row;
int rowspan;
void *pContext;
{
TableData *pData = (TableData *)pContext;
/* A colspan of 0 is legal (apparently), but Tkhtml just handles it as 1 */
if (colspan==0) {
colspan = 1;
}
if (pData->nCol<(col+colspan)) {
pData->nCol = col+colspan;
}
return TCL_OK;
}
static int
tableCountRows(pNode, row, pContext)
HtmlNode *pNode;
int row;
void *pContext;
{
TableData *pData = (TableData *)pContext;
pData->nRow = row + 1;
return TCL_OK;
}
/*
*---------------------------------------------------------------------------
*
* tableDrawRow --
*
* This is a tableIterate() 'row callback' used while actually drawing
* table data to canvas. See comments above tableDrawCells() for a
* description.
*
* Results:
* None.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
tableDrawRow(pNode, row, pContext)
HtmlNode *pNode;
int row;
void *pContext;
{
TableData *pData = (TableData *)pContext;
LayoutContext *pLayout = pData->pLayout;
int nextrow = row+1;
int x = 0; /* X coordinate to draw content */
int i; /* Column iterator */
const int mmt = pLayout->minmaxTest;
HtmlElementNode *pElem = (HtmlElementNode *)pNode;
assert(!pElem || !HtmlNodeIsText(pNode));
assert(row < pData->nRow);
/* Add the background and border for the table-row, if a node exists. A
* node may not exist if the row is entirely populated by overflow from
* above. For example in the following document, there is no node for the
* second row of the table.
*
* <table><tr><td rowspan=2></table>
*/
CHECK_INTEGER_PLAUSIBILITY(pData->pBox->vc.bottom);
if (pElem && pElem->node.iNode >= 0 && pElem->pPropertyValues) {
int iHeight;
int x1, y1, w1, h1; /* Border coordinates */
x1 = pData->border_spacing;
y1 = pData->aY[row];
h1 = pData->aY[nextrow] - pData->aY[row] - pData->border_spacing;
/* If we have a non-auto 'height' property on the table-row, then
* use it as a minimum height. Such a 'height' does not include
* the border-spacing.
*/
iHeight = PIXELVAL(pElem->pPropertyValues, HEIGHT, 0);
if (iHeight > h1) {
pData->aY[nextrow] += (iHeight - h1);
h1 = iHeight;
}
w1 = 0;
for (i=0; i<pData->nCol; i++) {
w1 += pData->aWidth[i];
}
w1 += ((pData->nCol - 1) * pData->border_spacing);
HtmlLayoutDrawBox(pData->pLayout->pTree,
&pData->pBox->vc, x1, y1, w1, h1, pNode, 0, mmt
);
}
CHECK_INTEGER_PLAUSIBILITY(pData->pBox->vc.bottom);
CHECK_INTEGER_PLAUSIBILITY(pData->pBox->vc.right);
for (i=0; i<pData->nCol; i++) {
TableCell *pCell = &pData->aCell[i];
/* At this point variable x holds the horizontal canvas offset of
* the outside edge of the cell pCell's left border.
*/
x += pData->border_spacing;
if (pCell->finrow == nextrow) {
BoxProperties box;
int x1, y1, w1, h1; /* Border coordinates */
int y;
int k;
HtmlCanvas *pCanvas = &pData->pBox->vc;
x1 = x;
y1 = pData->aY[pCell->startrow];
w1 = 0;
for (k=i; k<(i+pCell->colspan); k++) {
w1 += pData->aWidth[k];
}
w1 += ((pCell->colspan-1) * pData->border_spacing);
h1 = pData->aY[pCell->finrow] - pData->border_spacing - y1;
if (pCell->pNode->iNode >= 0) {
HtmlLayoutDrawBox(pData->pLayout->pTree,
pCanvas, x1, y1, w1, h1, pCell->pNode, 0, mmt
);
}
nodeGetBoxProperties(pLayout, pCell->pNode, 0, &box);
/* Todo: The formulas for the various vertical alignments below
* only work if the top and bottom borders of the cell
* are of the same thickness. Same goes for the padding.
*/
switch (HtmlNodeComputedValues(pCell->pNode)->eVerticalAlign) {
case CSS_CONST_TOP:
case CSS_CONST_BASELINE:
y = pData->aY[pCell->startrow] + box.iTop;
break;
case CSS_CONST_BOTTOM:
y = pData->aY[pCell->finrow] -
pCell->box.height -
box.iBottom -
pData->border_spacing;
break;
default:
y = pData->aY[pCell->startrow];
y += (h1 - box.iTop - box.iBottom - pCell->box.height) / 2;
y += box.iTop;
break;
}
CHECK_INTEGER_PLAUSIBILITY(pCanvas->bottom);
DRAW_CANVAS(pCanvas, &pCell->box.vc, x+box.iLeft, y, pCell->pNode);
CHECK_INTEGER_PLAUSIBILITY(pCanvas->bottom);
memset(pCell, 0, sizeof(TableCell));
}
x += pData->aWidth[i];
}
CHECK_INTEGER_PLAUSIBILITY(pData->pBox->vc.bottom);
CHECK_INTEGER_PLAUSIBILITY(pData->pBox->vc.right);
return TCL_OK;
}
/*
*---------------------------------------------------------------------------
*
* tableDrawCells --
*
* tableIterate() callback to actually draw cells. Drawing uses two
* callbacks. This function is called for each cell in the table
* and the tableDrawRow() function above is called after each row has
* been completed.
*
* This function draws the cell into the BoxContext at location
* aCell[col-number].box in the TableData struct. The border and
* background are not drawn at this stage.
*
* When the tableDrawRow() function is called, it is possible to
* determine the height of the row. This is needed before cell contents
* can be copied into the table canvas, so that the cell can be
* vertically aligned correctly, and so that the cell border and
* background match the height of the row they are in.
*
* Plus a few complications for cells that span multiple rows.
*
* Results:
* None.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
tableDrawCells(pNode, col, colspan, row, rowspan, pContext)
HtmlNode *pNode;
int col;
int colspan;
int row;
int rowspan;
void *pContext;
{
TableData *pData = (TableData *)pContext;
BoxContext *pBox;
BoxProperties box;
int i;
int x = 0;
int y = 0;
int belowY;
LayoutContext *pLayout = pData->pLayout;
int iHeight;
HtmlComputedValues *pV;
fixNodeProperties(pData, pNode);
pV = HtmlNodeComputedValues(pNode);
/* A rowspan of 0 means the cell spans the remainder of the table
* vertically. Similarly, a colspan of 0 means the cell spans the
* remainder of the table horizontally.
*/
if (rowspan<=0) {
rowspan = (pData->nRow-row);
}
if (colspan<=0) {
colspan = (pData->nCol-col);
}
y = pData->aY[row];
if (y==0) {
y = pData->border_spacing * (row+1);
pData->aY[row] = y;
}
for (i=0; i<col; i++) {
x += pData->aWidth[i];
}
x += ((col+1) * pData->border_spacing);
pBox = &pData->aCell[col].box;
assert (pData->aCell[col].finrow==0);
pData->aCell[col].finrow = row+rowspan;
pData->aCell[col].startrow = row;
pData->aCell[col].pNode = pNode;
pData->aCell[col].colspan = colspan;
nodeGetBoxProperties(pData->pLayout, pNode, 0, &box);
pBox->iContaining = pData->aWidth[col] - box.iLeft - box.iRight;
for (i=col+1; i<col+colspan; i++) {
pBox->iContaining += (pData->aWidth[i] + pData->border_spacing);
}
HtmlLayoutNodeContent(pData->pLayout, pBox, pNode);
/* Handle the 'height' property on the table-cell node. The 'height'
* really specifies a minimum height for the row, not the height of the
* table-cell box.
*
* Later: I have now learned that the 'height' property actually refers
* to the minimum height of the cell box. The cell box includes the
* border edge of the box generated by the table cell. See CSS 2.1
* sections 17.5 and 17.5.3.
*/
iHeight = pBox->height + box.iTop + box.iBottom;
iHeight = MAX(PIXELVAL(pV, HEIGHT, 0), iHeight);
belowY = y + iHeight + pData->border_spacing;
LOG {
HtmlTree *pTree = pLayout->pTree;
Tcl_Obj *pCmd = HtmlNodeCommand(pTree, pNode);
if (pCmd) {
HtmlLog(pTree, "LAYOUTENGINE", "%s tableDrawCells() "
"containing=%d actual=%d",
Tcl_GetString(pCmd),
pBox->iContaining, pBox->width
);
}
}
assert(row+rowspan < pData->nRow+1);
pData->aY[row+rowspan] = MAX(pData->aY[row+rowspan], belowY);
for (i=row+rowspan+1; i<=pData->nRow; i++) {
pData->aY[i] = MAX(pData->aY[row+rowspan], pData->aY[i]);
}
CHECK_INTEGER_PLAUSIBILITY(pData->aY[row+rowspan]);
CHECK_INTEGER_PLAUSIBILITY(pBox->vc.bottom);
CHECK_INTEGER_PLAUSIBILITY(pBox->vc.right);
return TCL_OK;
}
/*
* Context object used by the tableIterate() iteration procedure. i.e.
* the functions:
*
* tableIterate()
* rowIterate()
* cellIterate()
*/
struct RowIterateContext {
/* The cell and row callbacks */
int (*xRowCallback)(HtmlNode *, int, void *);
int (*xCallback)(HtmlNode *, int, int, int, int, void *);
ClientData clientData; /* Client data for the callbacks */
/* The following two variables are used to keep track of cells that
* span multiple rows. The array aRowSpan is dynamically allocated as
* needed and freed before tableIterate() returns. The allocated size
* of aRowSpan is stored in nRowSpan.
*
* When iterating through the columns in a row (i.e. <th> or <td> tags
* that are children of a <tr>) if a table cell with a rowspan greater
* than 1 is encountered, then aRowSpan[<col-number>] is set to
* rowspan. */
int nRowSpan;
int *aRowSpan;
int iMaxRow; /* Index of the final row of table */
int iRow; /* The current row number (first row is 0) */
int iCol; /* The current col number (first row is 0) */
};
typedef struct RowIterateContext RowIterateContext;
static void
cellIterate(pTree, pNode, p)
HtmlTree *pTree;
HtmlNode *pNode;
RowIterateContext *p;
{
int nSpan = 1;
int nRSpan = 1;
int col_ok = 0;
char const *zSpan = 0;
HtmlElementNode *pElem = (HtmlElementNode *)pNode;
/* Either this is a synthetic node, or it's 'display' property
* is set to "table-cell" (in HTML <TD> or <TH>).
*/
assert(
0 == HtmlNodeParent(pNode) ||
CSS_CONST_TABLE_CELL == DISPLAY(HtmlNodeComputedValues(pNode))
);
if (pElem->pPropertyValues) {
/* Set nSpan to the number of columns this cell spans */
zSpan = HtmlNodeAttr(pNode, "colspan");
nSpan = zSpan?atoi(zSpan):1;
if (nSpan <= 0) {
nSpan = 1;
}
/* Set nRowSpan to the number of rows this cell spans */
zSpan = HtmlNodeAttr(pNode, "rowspan");
nRSpan = zSpan?atoi(zSpan):1;
if (nRSpan <= 0) {
nRSpan = 1;
}
}
/* Now figure out what column this cell falls in. The
* value of the 'col' variable is where we would like
* to place this cell (i.e. just to the right of the
* previous cell), but that might change based on cells
* from a previous row with a rowspan greater than 1.
* If this is true, we shift the cell one column to the
* right until the above condition is false.
*/
do {
int k;
for (k = p->iCol; k < (p->iCol + nSpan); k++) {
if (k < p->nRowSpan && p->aRowSpan[k]) break;
}
if (k == (p->iCol + nSpan)) {
col_ok = 1;
} else {
p->iCol++;
}
} while (!col_ok);
/* Update the p->aRowSpan array. It grows here if required. */
if (nRSpan!=1) {
int k;
if (p->nRowSpan<(p->iCol+nSpan)) {
int n = p->iCol+nSpan;
p->aRowSpan = (int *)HtmlRealloc(0, (char *)p->aRowSpan,
sizeof(int)*n);
for (k=p->nRowSpan; k<n; k++) {
p->aRowSpan[k] = 0;
}
p->nRowSpan = n;
}
for (k=p->iCol; k<p->iCol+nSpan; k++) {
assert(k < p->nRowSpan);
p->aRowSpan[k] = (nRSpan>1?nRSpan:-1);
}
}
if (p->xCallback) {
p->xCallback(pNode, p->iCol, nSpan, p->iRow, nRSpan, p->clientData);
}
p->iCol += nSpan;
p->iMaxRow = MAX(p->iMaxRow, p->iRow + nRSpan - 1);
}
static int
rowIterate(pTree, pNode, p)
HtmlTree *pTree;
HtmlNode *pNode;
RowIterateContext *p;
{
int k;
int ii;
/* Either this is a synthetic node, or it's 'display' property
* is set to "table-row".
*/
assert(
0 == HtmlNodeParent(pNode) ||
CSS_CONST_TABLE_ROW == DISPLAY(HtmlNodeComputedValues(pNode))
);
if (HtmlNodeIsText(pNode)) return 0;
p->iCol = 0;
for (ii = 0; ii < HtmlNodeNumChildren(pNode); ii++) {
HtmlNode *pCell = HtmlNodeChild(pNode, ii);
HtmlComputedValues *pV = HtmlNodeComputedValues(pCell);
/* Throw away white-space children of the row node. */
if (HtmlNodeIsWhitespace(pCell)) continue;
if (DISPLAY(pV) == CSS_CONST_TABLE_CELL) {
/* Child has "display:table-cell". Good. */
cellIterate(pTree, pCell, p);
} else {
/* Have to create a fake <td> node. Bad. */
int jj;
HtmlElementNode sCell;
memset(&sCell, 0, sizeof(HtmlElementNode));
for (jj = ii + 1; jj < HtmlNodeNumChildren(pNode); jj++) {
HtmlNode *pNextRow = HtmlNodeChild(pNode, jj);
HtmlComputedValues *pV2 = HtmlNodeComputedValues(pNextRow);
if (DISPLAY(pV2) == CSS_CONST_TABLE_CELL) break;
}
sCell.node.iNode = -1;
sCell.nChild = jj - ii;
sCell.apChildren = &((HtmlElementNode *)pNode)->apChildren[ii];
cellIterate(pTree, (HtmlNode *)&sCell, p);
HtmlLayoutInvalidateCache(pTree, (HtmlNode *)&sCell);
ii = jj - 1;
}
}
if (p->xRowCallback) {
p->xRowCallback(pNode, p->iRow, p->clientData);
}
p->iRow++;
for (k=0; k < p->nRowSpan; k++) {
if (p->aRowSpan[k]) p->aRowSpan[k]--;
}
return 0;
}
static void
rowGroupIterate(pTree, pNode, p)
HtmlTree *pTree;
HtmlNode *pNode;
RowIterateContext *p;
{
int ii;
if (!pNode) return;
/* Either this is a synthetic node, or it's 'display' property
* is set to one of "table-row-group", "table-footer-group" or
* "table-header-group".
*/
assert(
0 == HtmlNodeParent(pNode) ||
CSS_CONST_TABLE_ROW_GROUP==DISPLAY(HtmlNodeComputedValues(pNode)) ||
CSS_CONST_TABLE_FOOTER_GROUP==DISPLAY(HtmlNodeComputedValues(pNode)) ||
CSS_CONST_TABLE_HEADER_GROUP==DISPLAY(HtmlNodeComputedValues(pNode))
);
for (ii = 0; ii < HtmlNodeNumChildren(pNode); ii++) {
HtmlNode *pRow = HtmlNodeChild(pNode, ii);
HtmlComputedValues *pV = HtmlNodeComputedValues(pRow);
/* Throw away white-space node children of the <TBODY> node. */
if (HtmlNodeIsWhitespace(pRow)) continue;
if (DISPLAY(pV) == CSS_CONST_TABLE_ROW) {
/* Child has "display:table-row". Good. */
rowIterate(pTree, pRow, p);
} else {
/* Have to create a fake <tr> node. Bad. */
int jj;
HtmlElementNode sRow;
memset(&sRow, 0, sizeof(HtmlElementNode));
for (jj = ii + 1; jj < HtmlNodeNumChildren(pNode); jj++) {
HtmlNode *pNextRow = HtmlNodeChild(pNode, jj);
HtmlComputedValues *pV2 = HtmlNodeComputedValues(pNextRow);
if (DISPLAY(pV2) == CSS_CONST_TABLE_ROW) break;
}
sRow.node.iNode = -1;
sRow.nChild = jj - ii;
sRow.apChildren = &((HtmlElementNode *)pNode)->apChildren[ii];
rowIterate(pTree, &sRow, p);
assert(!sRow.pLayoutCache);
ii = jj - 1;
}
}
}
/*
*---------------------------------------------------------------------------
*
* tableIterate --
*
* Helper function for HtmlTableLayout, used to iterate through cells
* of the table. For the table below, the iteration order is W, X,
* Y, Z.
*
* /-------\
* | W | X | row number = 0
* |-------|
* | Y | Z | row number = 1
* \-------/
*
* For each cell, the function passed as the second argument is
* invoked. The arguments are a pointer to the <td> or <th> node
* that identifies the cell, the column number, the colspan, the row
* number, the rowspan, and a copy of the pContext argument passed to
* iterateTable().
*
* After xCallback has been invoked for each cell in a row, the
* row-callback (xRowCallback) is invoked for the row. The arguments
* to xRowCallback are the <tr> node object, the row number and a
* copy of the pContext argument passed to tableIterate().
*
* TRANSIENT NODES:
*
* Sometimes, the nodes passed to the xCallback or xRowCallback
* callback functions may be allocated on the stack, rather than
* actually part of the document tree. This happens when implicit
* nodes are inserted.
*
* Transient (stack) nodes can be identified by the following test:
*
* if (pNode->pParent == 0) { // Is a transient node }
*
* Because the node structure is allocated on the stack, it should
* not be passed to HtmlDrawBox() etc.
*
* Results:
* None.
*
* Side effects:
* Whatever xCallback does.
*
*---------------------------------------------------------------------------
*/
static void
tableIterate(pTree, pNode, xCallback, xRowCallback, pContext)
HtmlTree *pTree;
HtmlNode *pNode; /* The <table> node */
int (*xCallback)(HtmlNode *, int, int, int, int, void *); /* Callback */
int (*xRowCallback)(HtmlNode *, int, void *); /* Row Callback */
void *pContext; /* pContext of callbacks */
{
int ii;
HtmlNode *pHeader = 0; /* Table header (i.e. <THEAD>) */
HtmlNode *pFooter = 0; /* Table footer (i.e. <TFOOT>) */
RowIterateContext sRowContext;
memset(&sRowContext, 0, sizeof(RowIterateContext));
sRowContext.xRowCallback = xRowCallback;
sRowContext.xCallback = xCallback;
sRowContext.clientData = (ClientData)pContext;
/* Search for the table header and footer blocks. */
for (ii = 0; ii < HtmlNodeNumChildren(pNode); ii++) {
HtmlNode *pChild = HtmlNodeChild(pNode, ii);
switch (DISPLAY(HtmlNodeComputedValues(pChild))) {
case CSS_CONST_TABLE_FOOTER_GROUP:
pFooter = (pFooter ? pFooter : pChild);
break;
case CSS_CONST_TABLE_HEADER_GROUP:
pHeader = (pHeader ? pHeader : pChild);
break;
}
}
rowGroupIterate(pTree, pHeader, &sRowContext);
for (ii = 0; ii < HtmlNodeNumChildren(pNode); ii++) {
HtmlNode *pChild = HtmlNodeChild(pNode, ii);
int eDisplay;
if (pChild == pFooter || pChild == pHeader) continue;
/* Throw away white-space node children of the table node.
* Todo: Is this correct? */
if (HtmlNodeIsWhitespace(pChild)) continue;
eDisplay = DISPLAY(HtmlNodeComputedValues(pChild));
if (
eDisplay == CSS_CONST_TABLE_ROW_GROUP ||
eDisplay == CSS_CONST_TABLE_FOOTER_GROUP ||
eDisplay == CSS_CONST_TABLE_HEADER_GROUP
) {
rowGroupIterate(pTree, pChild, &sRowContext);
} else {
/* Create a transient <TBODY> node */
int jj;
HtmlElementNode sRowGroup;
for (jj = ii + 1; jj < HtmlNodeNumChildren(pNode); jj++) {
HtmlNode *pSibling = HtmlNodeChild(pNode, jj);
eDisplay = DISPLAY(HtmlNodeComputedValues(pSibling));
if (
eDisplay == CSS_CONST_TABLE_ROW_GROUP ||
eDisplay == CSS_CONST_TABLE_FOOTER_GROUP ||
eDisplay == CSS_CONST_TABLE_HEADER_GROUP
) break;
}
memset(&sRowGroup, 0, sizeof(HtmlElementNode));
sRowGroup.node.iNode = -1;
sRowGroup.nChild = jj - ii;
sRowGroup.apChildren = &((HtmlElementNode *)pNode)->apChildren[ii];
rowGroupIterate(pTree, &sRowGroup, &sRowContext);
assert(!sRowGroup.pLayoutCache);
ii = jj - 1;
}
}
rowGroupIterate(pTree, pFooter, &sRowContext);
while (sRowContext.iRow <= sRowContext.iMaxRow && xRowCallback) {
xRowCallback(0, sRowContext.iRow, pContext);
sRowContext.iRow++;
}
HtmlFree(sRowContext.aRowSpan);
}
static void
logWidthStage(nStage, pStageLog, nWidth, aWidth)
int nStage;
Tcl_Obj *pStageLog;
int nWidth;
int *aWidth;
{
int ii;
if (!pStageLog) return;
Tcl_AppendToObj(pStageLog, "<tr><td>Stage ", -1);
Tcl_AppendObjToObj(pStageLog, Tcl_NewIntObj(nStage));
for (ii = 0; ii < nWidth; ii++) {
Tcl_AppendToObj(pStageLog, "<td>", -1);
Tcl_AppendObjToObj(pStageLog, Tcl_NewIntObj(aWidth[ii]));
}
}
static void
tableCalculateCellWidths(pData, availablewidth, isAuto)
TableData *pData;
int availablewidth; /* Total width available for cells */
int isAuto; /* True if the 'width' of the <table> was "auto" */
{
/* The values of the following variables are set in the "analysis loop"
* (the first loop below) and thereafter left unchanged.
*/
int nPercentCol = 0; /* Number of percentage width columns */
double fTotalPercent = 0.0; /* Total of percentage widths */
int nExplicitCol = 0; /* Number of explicit pixel width columns */
int iMaxExplicit = 0; /* Total of max-content-width for explicit cols */
int nAutoCol = 0; /* Number of 'auto' width columns */
int iMaxAuto = 0; /* Total of max-content-width for all 'auto' cols */
int iMinAuto = 0; /* Total of min-content-width for all 'auto' cols */
int ii;
int jj;
int iRemaining = availablewidth;
/* Local handles for the input arrays */
int *aMinWidth = pData->aMinWidth;
int *aMaxWidth = pData->aMaxWidth;
CellReqWidth *aReqWidth = pData->aReqWidth;
/* Local handle for the output array */
int *aWidth = pData->aWidth;
/* Log the inputs to this function. */
LayoutContext *pLayout = pData->pLayout;
Tcl_Obj *pStageLog = 0;
LOG {
HtmlTree *pTree = pLayout->pTree;
Tcl_Obj *pCmd = HtmlNodeCommand(pTree, pData->pNode);
if (pCmd) {
Tcl_Obj *pLog = Tcl_NewObj();
Tcl_IncrRefCount(pLog);
Tcl_AppendToObj(pLog, "Inputs to column width algorithm: ", -1);
Tcl_AppendToObj(pLog, "<p>Available width is ", -1);
Tcl_AppendObjToObj(pLog, Tcl_NewIntObj(availablewidth));
Tcl_AppendToObj(pLog, " (width property was <b>", -1);
Tcl_AppendToObj(pLog, isAuto ? "auto</b>" : "not</b> auto", -1);
Tcl_AppendToObj(pLog, ")</p>", -1);
logWidthsToTable(pData, pLog);
HtmlLog(pTree, "LAYOUTENGINE", "%s tableCalculateCellWidths() %s",
Tcl_GetString(pCmd), Tcl_GetString(pLog)
);
Tcl_DecrRefCount(pLog);
pStageLog = Tcl_NewObj();
Tcl_IncrRefCount(pStageLog);
}
}
/* This loop serves two purposes:
*
* 1. Allocate each column it's minimum content width.
* 2. It is the "analysis loop" refered to above that populates
* local variables used by later stages of the algorithm.
*/
for (ii = 0; ii < pData->nCol; ii++) {
aWidth[ii] = aMinWidth[ii];
iRemaining -= aMinWidth[ii];
switch (aReqWidth[ii].eType) {
case CELL_WIDTH_AUTO:
iMaxAuto += aMaxWidth[ii];
iMinAuto += aMinWidth[ii];
nAutoCol++;
break;
case CELL_WIDTH_PIXELS:
iMaxExplicit += aMaxWidth[ii];
nExplicitCol++;
break;
case CELL_WIDTH_PERCENT:
nPercentCol++;
fTotalPercent += aReqWidth[ii].x.fVal;
break;
}
}
logWidthStage(1, pStageLog, pData->nCol, aWidth);
/* Allocate pixels to percentage width columns */
if (iRemaining > 0) {
for (ii = 0; ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == CELL_WIDTH_PERCENT) {
int iReq = (50 + (aReqWidth[ii].x.fVal * availablewidth)) / 100;
iReq = MAX(0, iReq - aWidth[ii]);
aWidth[ii] += iReq;
iRemaining -= iReq;
}
}
if (fTotalPercent > 100.0) {
int iRemove = (50 + ((fTotalPercent-100.0) * availablewidth)) / 100;
for (ii = pData->nCol - 1; ii >= 0; ii--) {
if (aReqWidth[ii].eType == CELL_WIDTH_PERCENT) {
/* Apparently this is for Gecko compatibility. */
int rem = MIN(aWidth[ii], iRemove);
iRemove -= rem;
rem = MIN(aWidth[ii] - aMinWidth[ii], rem);
iRemaining += rem;
aWidth[ii] -= rem;
}
}
}
}
logWidthStage(2, pStageLog, pData->nCol, aWidth);
/* Allocate pixels to explicit width columns */
for (ii = 0; ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == CELL_WIDTH_PIXELS) {
int iReq = MAX(0, aReqWidth[ii].x.iVal - aWidth[ii]);
aWidth[ii] += iReq;
iRemaining -= iReq;
}
}
logWidthStage(3, pStageLog, pData->nCol, aWidth);
/* Allocate pixels to auto width columns */
if (iRemaining > 0) {
int iMA = iMaxAuto;
iRemaining += iMinAuto;
for (ii = 0; iMA > 0 && ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == CELL_WIDTH_AUTO) {
int w = MAX(aMinWidth[ii], iRemaining*aMaxWidth[ii]/iMA);
aWidth[ii] = w;
iRemaining -= w;
iMA -= aMaxWidth[ii];
}
}
}
logWidthStage(4, pStageLog, pData->nCol, aWidth);
/* Force pixels into fixed columns (subject to max-width) */
if (iRemaining > 0) {
int iME = iMaxExplicit;
for (ii = 0; ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == CELL_WIDTH_PIXELS) {
int w = iRemaining * aMaxWidth[ii] / iME;
iME -= aMaxWidth[ii];
iRemaining -= w;
aWidth[ii] += w;
}
}
}
logWidthStage(5, pStageLog, pData->nCol, aWidth);
/* Force pixels into percent columns (not subject to max-width!) */
if (iRemaining > 0 && fTotalPercent < 100.0) {
float fTP = fTotalPercent;
for (ii = 0; ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == CELL_WIDTH_PERCENT) {
int w = iRemaining * aReqWidth[ii].x.fVal / fTP;
fTP -= aReqWidth[ii].x.fVal;
iRemaining -= w;
aWidth[ii] += w;
}
}
}
logWidthStage(6, pStageLog, pData->nCol, aWidth);
/* Force pixels into any columns (not subject to max-width!) */
if (iRemaining > 0) {
for (ii = 0; ii < pData->nCol; ii++) {
int w = iRemaining / (pData->nCol - ii);
iRemaining -= w;
aWidth[ii] += w;
}
}
logWidthStage(7, pStageLog, pData->nCol, aWidth);
/* If too many pixels have been allocated, take some back from
* the columns. By preference we take pixels from "auto" columns,
* followed by "pixel width" columns and finally "percent width"
* columns.
*
* In pseudo-tcl the outer loop would read:
*
* foreach jj {auto pixels percent} {
* reduce_pixels_in_cols_of_type $jj
* }
*/
assert(CELL_WIDTH_AUTO == 0);
assert(CELL_WIDTH_PIXELS == 1);
assert(CELL_WIDTH_PERCENT == 2);
for (jj = 0; iRemaining < 0 && jj < 3; jj++) {
/* Only reduce columns with CELL_WIDTH_AUTO or CELL_WIDTH_PERCENT */
if (jj != CELL_WIDTH_AUTO || jj != CELL_WIDTH_PERCENT ) {
continue;
};
/* Total allocated, less the total min-content-width, for the cols */
int iAllocLessMin = 0;
for (ii = 0; ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == jj) {
iAllocLessMin += (aWidth[ii] - aMinWidth[ii]);
}
}
for (ii = 0; iAllocLessMin > 0 && ii < pData->nCol; ii++){
if (aReqWidth[ii].eType == jj) {
int iDiff = aWidth[ii] - aMinWidth[ii];
int iReduce = -1 * (iRemaining * iDiff) / iAllocLessMin;
iRemaining += iReduce;
iAllocLessMin -= iDiff;
aWidth[ii] -= iReduce;
}
}
logWidthStage(jj+8, pStageLog, pData->nCol, aWidth);
}
LOG {
HtmlTree *pTree = pLayout->pTree;
Tcl_Obj *pCmd = HtmlNodeCommand(pTree, pData->pNode);
if (pCmd) {
Tcl_Obj *pLog = Tcl_NewObj();
Tcl_IncrRefCount(pLog);
Tcl_AppendToObj(pLog, "<p>Summary of algorithm:</p>", -1);
Tcl_AppendToObj(pLog,
"<ol>"
" <li>Minimum content width allocation."
" <li>Percent width allocation."
" <li>Explicit pixel width allocation."
" <li>Auto width allocation."
" <li>Force pixels into explicit pixel width cols."
" <li>Force pixels into percent width cols."
" <li>Force pixels into auto width cols."
" <li>Reduce auto width cols. (optional)"
" <li>Reduce explicit pixel width cols. (optional)"
" <li>Reduce percent width cols. (optional)"
"</ol>", -1
);
Tcl_AppendToObj(pLog, "<p>Results of column width algorithm:</p>", -1);
Tcl_AppendToObj(pLog, "<table><tr><th></th>", -1);
for (ii = 0; ii < pData->nCol; ii++) {
Tcl_AppendToObj(pLog, "<th>Col ", -1);
Tcl_AppendObjToObj(pLog, Tcl_NewIntObj(ii));
}
Tcl_AppendToObj(pLog, "</tr>", -1);
Tcl_AppendObjToObj(pLog, pStageLog);
Tcl_AppendToObj(pLog, "</table>", -1);
HtmlLog(pTree, "LAYOUTENGINE", "%s tableCalculateCellWidths() %s",
Tcl_GetString(pCmd), Tcl_GetString(pLog)
);
Tcl_DecrRefCount(pLog);
}
}
}
static int
tableCalculateMaxWidth(pData)
TableData *pData;
{
int *aMaxWidth = pData->aMaxWidth;
int *aMinWidth = pData->aMinWidth;
CellReqWidth *aReqWidth = pData->aReqWidth;
int ii;
int ret = 0;
float fTotalPercent = 0.0;
int iMaxNonPercent = 0;
int iPercent = 0;
int bConsiderPercent = 0;
HtmlComputedValues *pV = HtmlNodeComputedValues(pData->pNode);
for (ii = 0; ii < pData->nCol; ii++) {
if (aReqWidth[ii].eType == CELL_WIDTH_PIXELS) {
ret += MAX(aMinWidth[ii], aReqWidth[ii].x.iVal);
} else {
assert(aMaxWidth[ii] >= aMinWidth[ii]);
ret += aMaxWidth[ii];
}
if (aReqWidth[ii].eType == CELL_WIDTH_PERCENT) {
float percent = MIN(aReqWidth[ii].x.fVal, 100.0 - fTotalPercent);
int w = (aMaxWidth[ii] * 100.0) / MAX(percent, 1.0);
iPercent = MAX(iPercent, w);
fTotalPercent += percent;
bConsiderPercent = 1;
} else {
iMaxNonPercent += aMaxWidth[ii];
}
}
#if 0
/* TODO: Including this block breaks the google-groups message page. */
for (p = HtmlNodeParent(pData->pNode); p; p = HtmlNodeParent(p)) {
HtmlComputedValues *pComputed = HtmlNodeComputedValues(p);
if (
PIXELVAL(pComputed, WIDTH, 0) != PIXELVAL_AUTO ||
pComputed->ePosition != CSS_CONST_STATIC
) {
break;
}
if (
pComputed->eDisplay == CSS_CONST_TABLE ||
pComputed->eDisplay == CSS_CONST_TABLE_CELL ||
pComputed->eDisplay == CSS_CONST_TABLE_ROW
) {
bConsiderPercent = 0;
break;
}
}
#endif
if (bConsiderPercent) {
if (fTotalPercent <= 99.0) {
iMaxNonPercent = iMaxNonPercent * 100.0 / (100.0 - fTotalPercent);
} else if (iMaxNonPercent > 0) {
/* If control flows to here, there exists the following:
*
* + There are one or columns with percentage widths, and
* the percentage widths sum to more than 100%.
* + There is at least one other column.
*
* Return something really large for the maximum width in this
* case, as the correct rendering is to make the table consume
* the full width of the containing block.
*/
iMaxNonPercent = 10000;
}
ret = MAX(iMaxNonPercent, ret);
ret = MAX(iPercent, ret);
}
ret = MAX(ret, PIXELVAL(pV, WIDTH, PIXELVAL_AUTO));
return ret;
}
/*
*---------------------------------------------------------------------------
*
* HtmlTableLayout --
*
* Lay out a table node.
*
* Todo: Update this comment.
*
* This is an incomplete implementation of HTML tables - it does not
* support the <col>, <colspan>, <thead>, <tfoot> or <tbody> elements.
* Since the parser just ignores tags that we don't know about, this
* means that all children of the <table> node should have tag-type
* <tr>. Omitting <thead>, <tfoot> and <tbody> is not such a big deal
* since it is optional to format these elements differently anyway,
* but <col> and <colspan> are fairly important.
*
* The table layout algorithm used is described in section 17.5.2.2 of
* the CSS 2.1 spec.
*
* When this function is called, pBox->iContaining contains the width
* available to the table content - not including any margin, border or
* padding on the table itself. Any pixels allocated between the edge of
* the table and the leftmost or rightmost cell due to 'border-spacing' is
* included in pBox->iContaining. If the table element has a computed value
* for width other than 'auto', then pBox->iContaining is the calculated
* 'width' value. Otherwise it is the width available according to the
* width of the containing block.
*
* Results:
* None.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
int
HtmlTableLayout(pLayout, pBox, pNode)
LayoutContext *pLayout;
BoxContext *pBox;
HtmlNode *pNode; /* The node to layout */
{
HtmlTree *pTree = pLayout->pTree;
HtmlComputedValues *pV = HtmlNodeComputedValues(pNode);
int nCol = 0; /* Number of columns in this table */
int i;
int availwidth; /* Total width available for cells */
int *aMinWidth = 0; /* Minimum width for each column */
int *aMaxWidth = 0; /* Minimum width for each column */
int *aWidth = 0; /* Actual width for each column */
int *aY = 0; /* Top y-coord for each row */
TableCell *aCell = 0; /* Array of nCol cells used during drawing */
TableData data;
CellReqWidth *aReqWidth = 0;
CellReqWidth *aSingleReqWidth = 0;
memset(&data, 0, sizeof(struct TableData));
data.pLayout = pLayout;
data.pNode = pNode;
pBox->iContaining = MAX(pBox->iContaining, 0); /* ??? */
assert(pBox->iContaining>=0);
assert(pV->eDisplay==CSS_CONST_TABLE);
/* Read the value of the 'border-spacing' property. 'border-spacing' may
* not take a percentage value, so there is no need to use PIXELVAL().
*/
data.border_spacing = pV->iBorderSpacing;
/* First step is to figure out how many columns this table has.
* There are two ways to do this - by looking at COL or COLGROUP
* children of the table, or by counting the cells in each rows.
* Technically, we should use the first method if one or more COL or
* COLGROUP elements exist. For now though, always use the second
* method.
*/
tableIterate(pTree, pNode, tableCountCells, tableCountRows, &data);
nCol = data.nCol;
LOG {
Tcl_Obj *pCmd = HtmlNodeCommand(pTree, pNode);
if (pCmd) {
HtmlTree *pTree = pLayout->pTree;
HtmlLog(pTree, "LAYOUTENGINE", "%s HtmlTableLayout() "
"Dimensions are %dx%d", Tcl_GetString(pCmd),
data.nCol, data.nRow
);
}
}
/* Allocate arrays for the minimum and maximum widths of each column */
aMinWidth = (int *)HtmlClearAlloc(0, nCol*sizeof(int));
aMaxWidth = (int *)HtmlClearAlloc(0, nCol*sizeof(int));
aWidth = (int *)HtmlClearAlloc(0, nCol*sizeof(int));
aReqWidth = (CellReqWidth *)HtmlClearAlloc(0, nCol*sizeof(CellReqWidth));
aSingleReqWidth =
(CellReqWidth *)HtmlClearAlloc(0, nCol*sizeof(CellReqWidth));
aY = (int *)HtmlClearAlloc(0, (data.nRow+1)*sizeof(int));
aCell = (TableCell *)HtmlClearAlloc(0, data.nCol*sizeof(TableCell));
data.aMaxWidth = aMaxWidth;
data.aMinWidth = aMinWidth;
data.aWidth = aWidth;
data.aReqWidth = aReqWidth;
data.aSingleReqWidth = aSingleReqWidth;
/* Calculate the minimum, maximum, and requested percentage widths of
* each column. The first pass only considers cells that span a single
* column. In this case the min/max width of each column is the maximum of
* the min/max widths for all cells in the column.
*
* If the table contains one or more cells that span more than one
* column, we make a second pass. The min/max widths are increased,
* if necessary, to account for the multi-column cell. In this case,
* the width of each column that the cell spans is increased by
* the same amount (plus or minus a pixel to account for integer
* rounding).
*/
tableIterate(pTree, pNode, tableColWidthSingleSpan, 0, &data);
memcpy(aReqWidth, aSingleReqWidth, nCol*sizeof(CellReqWidth));
tableIterate(pTree, pNode, tableColWidthMultiSpan, 0, &data);
pBox->width = 0;
availwidth = (pBox->iContaining - (nCol+1) * data.border_spacing);
switch (pLayout->minmaxTest) {
case 0:
tableCalculateCellWidths(&data, availwidth, 0);
for (i = 0; i < nCol; i++) {
pBox->width += aWidth[i];
}
data.aY = aY;
data.aCell = aCell;
data.pBox = pBox;
tableIterate(pTree, pNode, tableDrawCells, tableDrawRow, &data);
pBox->height = data.aY[data.nRow];
break;
case MINMAX_TEST_MIN:
for (i = 0; i < nCol; i++) {
pBox->width += aMinWidth[i];
}
break;
case MINMAX_TEST_MAX: {
int minwidth = 0;
pBox->width = tableCalculateMaxWidth(&data);
pBox->width = MIN(pBox->width, availwidth);
for (i = 0; i < nCol; i++) {
minwidth += aMinWidth[i];
}
pBox->width = MAX(pBox->width, minwidth);
break;
}
default:
assert(!"Bad value for LayoutContext.minmaxTest");
}
pBox->width += (data.border_spacing * (nCol+1));
HtmlFree(aMinWidth);
HtmlFree(aMaxWidth);
HtmlFree(aWidth);
HtmlFree(aY);
HtmlFree(aCell);
HtmlFree(aReqWidth);
HtmlFree(aSingleReqWidth);
HtmlComputedValuesRelease(pTree, data.pDefaultProperties);
CHECK_INTEGER_PLAUSIBILITY(pBox->width);
CHECK_INTEGER_PLAUSIBILITY(pBox->height);
CHECK_INTEGER_PLAUSIBILITY(pBox->vc.bottom);
CHECK_INTEGER_PLAUSIBILITY(pBox->vc.right);
LOG {
Tcl_Obj *pCmd = HtmlNodeCommand(pTree, pNode);
if (pCmd) {
HtmlTree *pTree = pLayout->pTree;
HtmlLog(pTree, "LAYOUTENGINE", "%s HtmlTableLayout() "
"Content size is %dx%d", Tcl_GetString(pCmd),
pBox->width, pBox->height
);
}
}
return TCL_OK;
}
|