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 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla XForms support.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
* Allan Beaufour <abeaufour@novell.com>
* Darin Fisher <darin@meer.net>
* Olli Pettay <Olli.Pettay@helsinki.fi>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXFormsModelElement.h"
#include "nsIXTFGenericElementWrapper.h"
#include "nsMemory.h"
#include "nsIDOMElement.h"
#include "nsIDOM3Node.h"
#include "nsIDOMNodeList.h"
#include "nsIVariant.h"
#include "nsString.h"
#include "nsIDocument.h"
#include "nsXFormsAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
#include "nsIDOMEvent.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMXMLDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMXPathResult.h"
#include "nsIXFormsXPathEvaluator.h"
#include "nsIDOMXPathNSResolver.h"
#include "nsIDOMNSXPathExpression.h"
#include "nsIContent.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsIXFormsControl.h"
#include "nsXFormsTypes.h"
#include "nsXFormsXPathParser.h"
#include "nsXFormsXPathAnalyzer.h"
#include "nsIInstanceElementPrivate.h"
#include "nsXFormsUtils.h"
#include "nsXFormsSchemaValidator.h"
#include "nsIXFormsUIWidget.h"
#include "nsIAttribute.h"
#include "nsISchemaLoader.h"
#include "nsISchema.h"
#include "nsAutoPtr.h"
#include "nsIDOMDocumentXBL.h"
#include "nsIProgrammingLanguage.h"
#include "nsDOMError.h"
#include "nsIDOMXPathException.h"
#include "nsXFormsControlStub.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIEventStateManager.h"
#include "nsStringEnumerator.h"
#define XFORMS_LAZY_INSTANCE_BINDING \
"chrome://xforms/content/xforms.xml#xforms-lazy-instance"
#ifdef DEBUG
//#define DEBUG_MODEL
#endif
//------------------------------------------------------------------------------
// Helper function for using XPath to locate an <xsd:schema> element by
// matching its "id" attribute. This is necessary since <xsd:schema> is
// treated as an ordinary XML data node without an "ID" attribute.
static void
GetSchemaElementById(nsIDOMElement *contextNode,
const nsString &id,
nsIDOMElement **resultNode)
{
// search for an element with the given "id" attribute, and then verify
// that the element is in the XML Schema namespace.
nsAutoString expr;
expr.AssignLiteral("//*[@id=\"");
expr.Append(id);
expr.AppendLiteral("\"]");
nsCOMPtr<nsIDOMXPathResult> xpRes;
nsresult rv =
nsXFormsUtils::EvaluateXPath(expr,
contextNode,
contextNode,
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
getter_AddRefs(xpRes));
if (NS_SUCCEEDED(rv) && xpRes) {
nsCOMPtr<nsIDOMNode> node;
xpRes->GetSingleNodeValue(getter_AddRefs(node));
if (node) {
nsAutoString ns;
node->GetNamespaceURI(ns);
if (ns.EqualsLiteral(NS_NAMESPACE_XML_SCHEMA))
CallQueryInterface(node, resultNode);
}
}
}
//------------------------------------------------------------------------------
static void
DeleteVoidArray(void *aObject,
nsIAtom *aPropertyName,
void *aPropertyValue,
void *aData)
{
delete NS_STATIC_CAST(nsVoidArray *, aPropertyValue);
}
static nsresult
AddToModelList(nsIDOMDocument *domDoc, nsXFormsModelElement *model)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
nsVoidArray *models =
NS_STATIC_CAST(nsVoidArray *,
doc->GetProperty(nsXFormsAtoms::modelListProperty));
if (!models) {
models = new nsVoidArray(16);
if (!models)
return NS_ERROR_OUT_OF_MEMORY;
doc->SetProperty(nsXFormsAtoms::modelListProperty, models, DeleteVoidArray);
}
models->AppendElement(model);
return NS_OK;
}
static void
RemoveFromModelList(nsIDOMDocument *domDoc, nsXFormsModelElement *model)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
nsVoidArray *models =
NS_STATIC_CAST(nsVoidArray *,
doc->GetProperty(nsXFormsAtoms::modelListProperty));
if (models)
models->RemoveElement(model);
}
static const nsVoidArray *
GetModelList(nsIDOMDocument *domDoc)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
return NS_STATIC_CAST(nsVoidArray *,
doc->GetProperty(nsXFormsAtoms::modelListProperty));
}
static void
SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
void *aPropertyValue, void *aData)
{
nsISupports *propertyValue = NS_STATIC_CAST(nsISupports*, aPropertyValue);
NS_IF_RELEASE(propertyValue);
}
//------------------------------------------------------------------------------
// --- nsXFormsControlListItem ---
nsXFormsControlListItem::iterator::iterator()
: mCur(0)
{
}
nsXFormsControlListItem::iterator::iterator(const nsXFormsControlListItem::iterator& aCopy)
: mCur(aCopy.mCur)
{
mStack = aCopy.mStack;
}
nsXFormsControlListItem::iterator
nsXFormsControlListItem::iterator::operator=(nsXFormsControlListItem* aCnt)
{
mCur = aCnt;
return *this;
}
bool
nsXFormsControlListItem::iterator::operator!=(const nsXFormsControlListItem* aCnt)
{
return mCur != aCnt;
}
nsXFormsControlListItem::iterator
nsXFormsControlListItem::iterator::operator++()
{
if (!mCur)
return *this;
if (mCur->mFirstChild) {
if (!mCur->mNextSibling) {
mCur = mCur->mFirstChild;
return *this;
}
mStack.AppendElement(mCur->mFirstChild);
}
if (mCur->mNextSibling) {
mCur = mCur->mNextSibling;
} else if (mStack.Count()) {
mCur = (nsXFormsControlListItem*) mStack[mStack.Count() - 1];
mStack.RemoveElementAt(mStack.Count() - 1);
} else {
mCur = nsnull;
}
return *this;
}
nsXFormsControlListItem*
nsXFormsControlListItem::iterator::operator*()
{
return mCur;
}
nsXFormsControlListItem::nsXFormsControlListItem(
nsIXFormsControl* aControl,
nsRefPtrHashtable<nsISupportsHashKey,nsXFormsControlListItem>* aHashtable)
: mNode(aControl),
mNextSibling(nsnull),
mFirstChild(nsnull),
mControlListHash(aHashtable)
{
}
nsXFormsControlListItem::~nsXFormsControlListItem()
{
Clear();
}
nsXFormsControlListItem::nsXFormsControlListItem(const nsXFormsControlListItem& aCopy)
: mNode(aCopy.mNode)
{
if (aCopy.mNextSibling) {
mNextSibling = new nsXFormsControlListItem(*aCopy.mNextSibling);
NS_WARN_IF_FALSE(mNextSibling, "could not new?!");
} else {
mNextSibling = nsnull;
}
if (aCopy.mFirstChild) {
mFirstChild = new nsXFormsControlListItem(*aCopy.mFirstChild);
NS_WARN_IF_FALSE(mFirstChild, "could not new?!");
} else {
mFirstChild = nsnull;
}
}
void
nsXFormsControlListItem::Clear()
{
if (mFirstChild) {
mFirstChild->Clear();
NS_ASSERTION(!(mFirstChild->mFirstChild || mFirstChild->mNextSibling),
"child did not clear members!!");
mFirstChild = nsnull;
}
if (mNextSibling) {
mNextSibling->Clear();
NS_ASSERTION(!(mNextSibling->mFirstChild || mNextSibling->mNextSibling),
"sibling did not clear members!!");
mNextSibling = nsnull;
}
if (mNode) {
/* we won't bother removing each item one by one from the hashtable. This
* approach assumes that we are clearing the whole model's list of controls
* due to the model going away. After the model clears this list, it will
* clear the hashtable all at once.
*/
mControlListHash = nsnull;
mNode = nsnull;
}
}
nsresult
nsXFormsControlListItem::AddControl(nsIXFormsControl *aControl,
nsIXFormsControl *aParent)
{
// Four insertion posibilities:
// 1) Delegate to first child from root node
if (!mNode && mFirstChild) {
return mFirstChild->AddControl(aControl, aParent);
}
// 2) control with no parent
if (!aParent) {
nsRefPtr<nsXFormsControlListItem> newNode =
new nsXFormsControlListItem(aControl, mControlListHash);
NS_ENSURE_TRUE(newNode, NS_ERROR_OUT_OF_MEMORY);
// Empty tree (we have already checked mFirstChild)
if (!mNode) {
mFirstChild = newNode;
nsCOMPtr<nsIDOMElement> ele;
aControl->GetElement(getter_AddRefs(ele));
mControlListHash->Put(ele, newNode);
return NS_OK;
}
if (mNextSibling) {
newNode->mNextSibling = mNextSibling;
}
mNextSibling = newNode;
nsCOMPtr<nsIDOMElement> ele;
aControl->GetElement(getter_AddRefs(ele));
mControlListHash->Put(ele, newNode);
#ifdef DEBUG
nsXFormsControlListItem* next = newNode->mNextSibling;
while (next) {
NS_ASSERTION(aControl != next->mNode,
"Node already in tree!!");
next = next->mNextSibling;
}
#endif
return NS_OK;
}
// Locate parent
nsXFormsControlListItem* parentControl = FindControl(aParent);
NS_ASSERTION(parentControl, "Parent not found?!");
// 3) parentControl has a first child, insert as sibling to that
if (parentControl->mFirstChild) {
return parentControl->mFirstChild->AddControl(aControl, nsnull);
}
// 4) first child for parentControl
nsRefPtr<nsXFormsControlListItem> newNode =
new nsXFormsControlListItem(aControl, mControlListHash);
NS_ENSURE_TRUE(newNode, NS_ERROR_OUT_OF_MEMORY);
parentControl->mFirstChild = newNode;
nsCOMPtr<nsIDOMElement> ele;
aControl->GetElement(getter_AddRefs(ele));
mControlListHash->Put(ele, newNode);
return NS_OK;
}
nsresult
nsXFormsControlListItem::RemoveControl(nsIXFormsControl *aControl,
PRBool &aRemoved)
{
nsXFormsControlListItem* deleteMe = nsnull;
aRemoved = PR_FALSE;
// Try children
if (mFirstChild) {
// The control to remove is our first child
if (mFirstChild->mNode == aControl) {
deleteMe = mFirstChild;
// Fix siblings
if (deleteMe->mNextSibling) {
mFirstChild = deleteMe->mNextSibling;
deleteMe->mNextSibling = nsnull;
} else {
mFirstChild = nsnull;
}
// Fix children
if (deleteMe->mFirstChild) {
if (!mFirstChild) {
mFirstChild = deleteMe->mFirstChild;
} else {
nsXFormsControlListItem *insertPos = mFirstChild;
while (insertPos->mNextSibling) {
insertPos = insertPos->mNextSibling;
}
insertPos->mNextSibling = deleteMe->mFirstChild;
}
deleteMe->mFirstChild = nsnull;
}
} else {
// Run through children
nsresult rv = mFirstChild->RemoveControl(aControl, aRemoved);
NS_ENSURE_SUCCESS(rv, rv);
if (aRemoved)
return rv;
}
}
// Try siblings
if (!deleteMe && mNextSibling) {
if (mNextSibling->mNode == aControl) {
deleteMe = mNextSibling;
// Fix siblings
if (deleteMe->mNextSibling) {
mNextSibling = deleteMe->mNextSibling;
deleteMe->mNextSibling = nsnull;
} else {
mNextSibling = nsnull;
}
// Fix children
if (deleteMe->mFirstChild) {
if (!mNextSibling) {
mNextSibling = deleteMe->mFirstChild;
} else {
nsXFormsControlListItem *insertPos = mNextSibling;
while (insertPos->mNextSibling) {
insertPos = insertPos->mNextSibling;
}
insertPos->mNextSibling = deleteMe->mFirstChild;
}
deleteMe->mFirstChild = nsnull;
}
} else {
// run through siblings
return mNextSibling->RemoveControl(aControl, aRemoved);
}
}
if (deleteMe) {
NS_ASSERTION(!(deleteMe->mNextSibling),
"Deleted control should not have siblings!");
NS_ASSERTION(!(deleteMe->mFirstChild),
"Deleted control should not have children!");
nsCOMPtr<nsIDOMElement> element;
deleteMe->mNode->GetElement(getter_AddRefs(element));
mControlListHash->Remove(element);
aRemoved = PR_TRUE;
}
return NS_OK;
}
nsXFormsControlListItem*
nsXFormsControlListItem::FindControl(nsIXFormsControl *aControl)
{
if (!aControl)
return nsnull;
nsRefPtr<nsXFormsControlListItem> listItem;
nsCOMPtr<nsIDOMElement> element;
aControl->GetElement(getter_AddRefs(element));
mControlListHash->Get(element, getter_AddRefs(listItem));
return listItem;
}
already_AddRefed<nsIXFormsControl>
nsXFormsControlListItem::Control()
{
nsIXFormsControl* res = nsnull;
if (mNode)
NS_ADDREF(res = mNode);
NS_WARN_IF_FALSE(res, "Returning nsnull for a control. Bad sign.");
return res;
}
nsXFormsControlListItem*
nsXFormsControlListItem::begin()
{
// handle root
if (!mNode)
return mFirstChild;
return this;
}
nsXFormsControlListItem*
nsXFormsControlListItem::end()
{
return nsnull;
}
//------------------------------------------------------------------------------
static const nsIID sScriptingIIDs[] = {
NS_IDOMELEMENT_IID,
NS_IDOMEVENTTARGET_IID,
NS_IDOM3NODE_IID,
NS_IXFORMSMODELELEMENT_IID,
NS_IXFORMSNSMODELELEMENT_IID
};
static nsIAtom* sModelPropsList[eModel__count];
// This can be nsVoidArray because elements will remove
// themselves from the list if they are deleted during refresh.
static nsVoidArray* sPostRefreshList = nsnull;
static nsVoidArray* sContainerPostRefreshList = nsnull;
static PRInt32 sRefreshing = 0;
nsPostRefresh::nsPostRefresh()
{
#ifdef DEBUG_smaug
printf("nsPostRefresh\n");
#endif
++sRefreshing;
}
nsPostRefresh::~nsPostRefresh()
{
#ifdef DEBUG_smaug
printf("~nsPostRefresh\n");
#endif
if (sRefreshing != 1) {
--sRefreshing;
return;
}
if (sPostRefreshList) {
while (sPostRefreshList->Count()) {
// Iterating this way because refresh can lead to
// additions/deletions in sPostRefreshList.
// Iterating from last to first saves possibly few memcopies,
// see nsVoidArray::RemoveElementsAt().
PRInt32 last = sPostRefreshList->Count() - 1;
nsIXFormsControl* control =
NS_STATIC_CAST(nsIXFormsControl*, sPostRefreshList->ElementAt(last));
sPostRefreshList->RemoveElementAt(last);
if (control)
control->Refresh();
}
if (sRefreshing == 1) {
delete sPostRefreshList;
sPostRefreshList = nsnull;
}
}
--sRefreshing;
// process sContainerPostRefreshList after we've decremented sRefreshing.
// container->refresh below could ask for ContainerNeedsPostRefresh which
// will add an item to the sContainerPostRefreshList if sRefreshing > 0.
// So keeping this under sRefreshing-- will avoid an infinite loop.
while (sContainerPostRefreshList && sContainerPostRefreshList->Count()) {
PRInt32 last = sContainerPostRefreshList->Count() - 1;
nsIXFormsControl* container =
NS_STATIC_CAST(nsIXFormsControl*, sContainerPostRefreshList->ElementAt(last));
sContainerPostRefreshList->RemoveElementAt(last);
if (container) {
container->Refresh();
}
}
delete sContainerPostRefreshList;
sContainerPostRefreshList = nsnull;
}
const nsVoidArray*
nsPostRefresh::PostRefreshList()
{
return sPostRefreshList;
}
nsresult
nsXFormsModelElement::NeedsPostRefresh(nsIXFormsControl* aControl)
{
if (sRefreshing) {
if (!sPostRefreshList) {
sPostRefreshList = new nsVoidArray();
NS_ENSURE_TRUE(sPostRefreshList, NS_ERROR_OUT_OF_MEMORY);
}
if (sPostRefreshList->IndexOf(aControl) < 0) {
sPostRefreshList->AppendElement(aControl);
}
} else {
// We are not refreshing any models, so the control
// can be refreshed immediately.
aControl->Refresh();
}
return NS_OK;
}
PRBool
nsXFormsModelElement::ContainerNeedsPostRefresh(nsIXFormsControl* aControl)
{
if (sRefreshing) {
if (!sContainerPostRefreshList) {
sContainerPostRefreshList = new nsVoidArray();
if (!sContainerPostRefreshList) {
return PR_FALSE;
}
}
if (sContainerPostRefreshList->IndexOf(aControl) < 0) {
sContainerPostRefreshList->AppendElement(aControl);
}
// return PR_TRUE to show that the control's refresh will be delayed,
// whether as a result of this call or a previous call to this function.
return PR_TRUE;
}
// Delaying the refresh doesn't make any sense. But since this
// function may be called from inside the control node's refresh already,
// we shouldn't just assume that we can call the refresh here. So
// we'll just return PR_FALSE to signal that we couldn't delay the refresh.
return PR_FALSE;
}
void
nsXFormsModelElement::CancelPostRefresh(nsIXFormsControl* aControl)
{
if (sPostRefreshList)
sPostRefreshList->RemoveElement(aControl);
if (sContainerPostRefreshList)
sContainerPostRefreshList->RemoveElement(aControl);
}
nsXFormsModelElement::nsXFormsModelElement()
: mElement(nsnull),
mFormControls(nsnull, &mControlListHash),
mSchemaCount(0),
mSchemaTotal(0),
mPendingInstanceCount(0),
mDocumentLoaded(PR_FALSE),
mRebindAllControls(PR_FALSE),
mInstancesInitialized(PR_FALSE),
mReadyHandled(PR_FALSE),
mLazyModel(PR_FALSE),
mConstructDoneHandled(PR_FALSE),
mProcessingUpdateEvent(PR_FALSE),
mLoopMax(600),
mInstanceDocuments(nsnull)
{
mControlListHash.Init();
}
NS_INTERFACE_MAP_BEGIN(nsXFormsModelElement)
NS_INTERFACE_MAP_ENTRY(nsIXFormsModelElement)
NS_INTERFACE_MAP_ENTRY(nsIXFormsNSModelElement)
NS_INTERFACE_MAP_ENTRY(nsIModelElementPrivate)
NS_INTERFACE_MAP_ENTRY(nsISchemaLoadListener)
NS_INTERFACE_MAP_ENTRY(nsIWebServiceErrorHandler)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
NS_INTERFACE_MAP_ENTRY(nsIXFormsContextControl)
NS_INTERFACE_MAP_END_INHERITING(nsXFormsStubElement)
NS_IMPL_ADDREF_INHERITED(nsXFormsModelElement, nsXFormsStubElement)
NS_IMPL_RELEASE_INHERITED(nsXFormsModelElement, nsXFormsStubElement)
NS_IMETHODIMP
nsXFormsModelElement::OnDestroyed()
{
mElement = nsnull;
mSchemas = nsnull;
if (mInstanceDocuments)
mInstanceDocuments->DropReferences();
mFormControls.Clear();
mControlListHash.Clear();
return NS_OK;
}
void
nsXFormsModelElement::RemoveModelFromDocument()
{
mDocumentLoaded = PR_FALSE;
nsCOMPtr<nsIDOMDocument> domDoc;
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
if (!domDoc)
return;
RemoveFromModelList(domDoc, this);
nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(domDoc);
if (targ) {
targ->RemoveEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this, PR_TRUE);
nsCOMPtr<nsIDOMWindowInternal> window;
nsXFormsUtils::GetWindowFromDocument(domDoc, getter_AddRefs(window));
targ = do_QueryInterface(window);
if (targ) {
targ->RemoveEventListener(NS_LITERAL_STRING("unload"), this, PR_TRUE);
}
}
}
NS_IMETHODIMP
nsXFormsModelElement::GetScriptingInterfaces(PRUint32 *aCount, nsIID ***aArray)
{
return nsXFormsUtils::CloneScriptingInterfaces(sScriptingIIDs,
NS_ARRAY_LENGTH(sScriptingIIDs),
aCount, aArray);
}
NS_IMETHODIMP
nsXFormsModelElement::WillChangeDocument(nsIDOMDocument* aNewDocument)
{
RemoveModelFromDocument();
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::DocumentChanged(nsIDOMDocument* aNewDocument)
{
if (!aNewDocument)
return NS_OK;
AddToModelList(aNewDocument, this);
nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aNewDocument);
if (targ) {
targ->AddEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this, PR_TRUE);
nsCOMPtr<nsIDOMWindowInternal> window;
nsXFormsUtils::GetWindowFromDocument(aNewDocument, getter_AddRefs(window));
targ = do_QueryInterface(window);
if (targ) {
targ->AddEventListener(NS_LITERAL_STRING("unload"), this, PR_TRUE);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::DoneAddingChildren()
{
return InitializeInstances();
}
nsresult
nsXFormsModelElement::InitializeInstances()
{
if (mInstancesInitialized || !mElement) {
return NS_OK;
}
mInstancesInitialized = PR_TRUE;
nsCOMPtr<nsIDOMNodeList> children;
mElement->GetChildNodes(getter_AddRefs(children));
PRUint32 childCount = 0;
if (children) {
children->GetLength(&childCount);
}
nsresult rv;
for (PRUint32 i = 0; i < childCount; ++i) {
nsCOMPtr<nsIDOMNode> child;
children->Item(i, getter_AddRefs(child));
if (nsXFormsUtils::IsXFormsElement(child, NS_LITERAL_STRING("instance"))) {
nsCOMPtr<nsIInstanceElementPrivate> instance(do_QueryInterface(child));
NS_ENSURE_STATE(instance);
rv = instance->Initialize();
NS_ENSURE_SUCCESS(rv, rv);
}
}
// (XForms 4.2.1)
// 1. load xml schemas
nsAutoString schemaList;
mElement->GetAttribute(NS_LITERAL_STRING("schema"), schemaList);
if (!schemaList.IsEmpty()) {
NS_ENSURE_TRUE(mSchemas, NS_ERROR_FAILURE);
// Parse the whitespace-separated list.
nsCOMPtr<nsIContent> content = do_QueryInterface(mElement);
nsRefPtr<nsIURI> baseURI = content->GetBaseURI();
nsRefPtr<nsIURI> docURI = content->GetOwnerDoc() ?
content->GetOwnerDoc()->GetDocumentURI() : nsnull;
nsCStringArray schemas;
schemas.ParseString(NS_ConvertUTF16toUTF8(schemaList).get(), " \t\r\n");
// Increase by 1 to prevent OnLoad from calling FinishConstruction
mSchemaTotal = schemas.Count();
for (PRInt32 i=0; i<mSchemaTotal; ++i) {
rv = NS_OK;
nsCAutoString uriSpec;
nsCOMPtr<nsIURI> newURI;
NS_NewURI(getter_AddRefs(newURI), *schemas[i], nsnull, baseURI);
nsCOMPtr<nsIURL> newURL = do_QueryInterface(newURI);
if (!newURL) {
rv = NS_ERROR_UNEXPECTED;
} else {
// This code is copied from nsXMLEventsManager for extracting an
// element ID from an xsd:anyURI link.
nsCAutoString ref;
newURL->GetRef(ref);
newURL->SetRef(EmptyCString());
PRBool equals = PR_FALSE;
newURL->Equals(docURI, &equals);
if (equals) {
// We will not be able to locate the <xsd:schema> element using the
// getElementById function defined on our document when <xsd:schema>
// is treated as an ordinary XML data node. So, we employ XPath to
// locate it for us.
NS_ConvertUTF8toUTF16 id(ref);
nsCOMPtr<nsIDOMElement> el;
GetSchemaElementById(mElement, id, getter_AddRefs(el));
if (!el) {
// Perhaps the <xsd:schema> element appears after the <xforms:model>
// element in the document, so we'll defer loading it until the
// document has finished loading.
mPendingInlineSchemas.AppendString(id);
} else {
// We have an inline schema in the model element that was
// referenced by the schema attribute. It will be processed
// in FinishConstruction so we skip it now to avoid processing
// it twice and giving invalid 'duplicate schema' errors.
mSchemaTotal--;
i--;
}
} else {
newURI->GetSpec(uriSpec);
rv = mSchemas->LoadAsync(NS_ConvertUTF8toUTF16(uriSpec), this);
}
}
if (NS_FAILED(rv)) {
// this is a fatal error
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaLoadError"), mElement);
// Context Info: 'resource-uri'
// The URI associated with the failed link.
SetContextInfo("resource-uri", NS_ConvertUTF8toUTF16(uriSpec));
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException, nsnull,
nsnull, &mContextInfo);
return NS_OK;
}
}
}
// If all of the children are added and there aren't any instance elements,
// yet, then we need to make sure that one is ready in case the form author
// is using lazy authoring.
// Lazy <xforms:intance> element is created in anonymous content using XBL.
NS_ENSURE_STATE(mInstanceDocuments);
PRUint32 instCount;
mInstanceDocuments->GetLength(&instCount);
if (!instCount) {
#ifdef DEBUG
printf("Creating lazy instance\n");
#endif
nsCOMPtr<nsIDOMDocument> domDoc;
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDOMDocumentXBL> xblDoc(do_QueryInterface(domDoc));
if (xblDoc) {
nsresult rv =
xblDoc->AddBinding(mElement,
NS_LITERAL_STRING(XFORMS_LAZY_INSTANCE_BINDING));
NS_ENSURE_SUCCESS(rv, rv);
mInstanceDocuments->GetLength(&instCount);
nsCOMPtr<nsIDOMNodeList> list;
xblDoc->GetAnonymousNodes(mElement, getter_AddRefs(list));
if (list) {
PRUint32 childCount = 0;
if (list) {
list->GetLength(&childCount);
}
for (PRUint32 i = 0; i < childCount; ++i) {
nsCOMPtr<nsIDOMNode> item;
list->Item(i, getter_AddRefs(item));
nsCOMPtr<nsIInstanceElementPrivate> instance =
do_QueryInterface(item);
if (instance) {
rv = instance->Initialize();
NS_ENSURE_SUCCESS(rv, rv);
mLazyModel = PR_TRUE;
break;
}
}
}
}
NS_WARN_IF_FALSE(mLazyModel, "Installing lazy instance didn't succeed!");
}
// (XForms 4.2.1 - cont)
// 2. construct an XPath data model from inline or external initial instance
// data. This is done by our child instance elements as they are inserted
// into the document, and all of the instances will be processed by this
// point.
// schema and external instance data loads should delay document onload
if (IsComplete()) {
// No need to fire refresh event if we assume that all UI controls
// appear later in the document.
NS_ASSERTION(!mDocumentLoaded, "document should not be loaded yet");
return FinishConstruction();
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled)
{
if (!nsXFormsUtils::EventHandlingAllowed(aEvent, mElement))
return NS_OK;
*aHandled = PR_TRUE;
nsAutoString type;
aEvent->GetType(type);
nsresult rv = NS_OK;
if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Refresh].name)) {
rv = Refresh();
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Revalidate].name)) {
rv = Revalidate();
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Recalculate].name)) {
rv = Recalculate();
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Rebuild].name)) {
rv = Rebuild();
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_ModelConstructDone].name)) {
rv = ConstructDone();
mConstructDoneHandled = PR_TRUE;
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Reset].name)) {
Reset();
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_BindingException].name)) {
// we threw up a popup during the nsXFormsUtils::DispatchEvent that sent
// this error to the model
*aHandled = PR_TRUE;
} else {
*aHandled = PR_FALSE;
}
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"nsXFormsModelElement::HandleDefault() failed!\n");
return rv;
}
nsresult
nsXFormsModelElement::ConstructDone()
{
nsresult rv = InitializeControls();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::OnCreated(nsIXTFGenericElementWrapper *aWrapper)
{
aWrapper->SetNotificationMask(nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT |
nsIXTFElement::NOTIFY_DOCUMENT_CHANGED |
nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN |
nsIXTFElement::NOTIFY_HANDLE_DEFAULT);
nsCOMPtr<nsIDOMElement> node;
aWrapper->GetElementNode(getter_AddRefs(node));
// It's ok to keep a weak pointer to mElement. mElement will have an
// owning reference to this object, so as long as we null out mElement in
// OnDestroyed, it will always be valid.
mElement = node;
NS_ASSERTION(mElement, "Wrapper is not an nsIDOMElement, we'll crash soon");
nsresult rv = mMDG.Init(this);
NS_ENSURE_SUCCESS(rv, rv);
mSchemas = do_CreateInstance(NS_SCHEMALOADER_CONTRACTID);
mInstanceDocuments = new nsXFormsModelInstanceDocuments();
NS_ASSERTION(mInstanceDocuments, "could not create mInstanceDocuments?!");
// Initialize hash tables
NS_ENSURE_TRUE(mNodeToType.Init(), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(mNodeToP3PType.Init(), NS_ERROR_OUT_OF_MEMORY);
// Get eventual user-set loop maximum. Used by RequestUpdateEvent().
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pref) {
PRInt32 val;
if (NS_SUCCEEDED(pref->GetIntPref("xforms.modelLoopMax", &val)))
mLoopMax = val;
}
return NS_OK;
}
// nsIXFormsModelElement
NS_IMETHODIMP
nsXFormsModelElement::GetInstanceDocuments(nsIDOMNodeList **aDocuments)
{
NS_ENSURE_STATE(mInstanceDocuments);
NS_ENSURE_ARG_POINTER(aDocuments);
NS_ADDREF(*aDocuments = mInstanceDocuments);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetInstanceDocument(const nsAString& aInstanceID,
nsIDOMDocument **aDocument)
{
NS_ENSURE_ARG_POINTER(aDocument);
*aDocument = FindInstanceDocument(aInstanceID).get(); // transfer reference
if (*aDocument) {
return NS_OK;
}
const nsPromiseFlatString& flat = PromiseFlatString(aInstanceID);
const PRUnichar *strings[] = { flat.get() };
nsXFormsUtils::ReportError(aInstanceID.IsEmpty() ?
NS_LITERAL_STRING("defInstanceNotFound") :
NS_LITERAL_STRING("instanceNotFound"),
strings, 1, mElement, nsnull);
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_IMETHODIMP
nsXFormsModelElement::Rebuild()
{
#ifdef DEBUG
printf("nsXFormsModelElement::Rebuild()\n");
#endif
// 1 . Clear graph
nsresult rv;
rv = mMDG.Clear();
NS_ENSURE_SUCCESS(rv, rv);
// Clear any type information
NS_ENSURE_TRUE(mNodeToType.IsInitialized() && mNodeToP3PType.IsInitialized(),
NS_ERROR_FAILURE);
mNodeToType.Clear();
mNodeToP3PType.Clear();
// 2. Process bind elements
rv = ProcessBindElements();
NS_ENSURE_SUCCESS(rv, rv);
// 3. If this is not form load, re-attach all elements and validate
// instance documents
if (mReadyHandled) {
mRebindAllControls = PR_TRUE;
ValidateInstanceDocuments();
}
// 4. Rebuild graph
return mMDG.Rebuild();
}
NS_IMETHODIMP
nsXFormsModelElement::Recalculate()
{
#ifdef DEBUG
printf("nsXFormsModelElement::Recalculate()\n");
#endif
return mMDG.Recalculate(&mChangedNodes);
}
void
nsXFormsModelElement::SetSingleState(nsIDOMElement *aElement,
PRBool aState,
nsXFormsEvent aOnEvent)
{
nsXFormsEvent event = aState ? aOnEvent : (nsXFormsEvent) (aOnEvent + 1);
// Dispatch event
nsXFormsUtils::DispatchEvent(aElement, event);
}
NS_IMETHODIMP
nsXFormsModelElement::SetStates(nsIXFormsControl *aControl,
nsIDOMNode *aNode)
{
NS_ENSURE_ARG(aControl);
nsCOMPtr<nsIDOMElement> element;
aControl->GetElement(getter_AddRefs(element));
NS_ENSURE_STATE(element);
nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(element));
NS_ENSURE_STATE(xtfWrap);
PRInt32 iState;
const nsXFormsNodeState* ns = nsnull;
if (aNode) {
ns = mMDG.GetNodeState(aNode);
NS_ENSURE_STATE(ns);
iState = ns->GetIntrinsicState();
nsCOMPtr<nsIContent> content(do_QueryInterface(element));
NS_ENSURE_STATE(content);
PRInt32 rangeState = content->IntrinsicState() &
(NS_EVENT_STATE_INRANGE | NS_EVENT_STATE_OUTOFRANGE);
iState = ns->GetIntrinsicState() | rangeState;
} else {
aControl->GetDefaultIntrinsicState(&iState);
}
nsresult rv = xtfWrap->SetIntrinsicState(iState);
NS_ENSURE_SUCCESS(rv, rv);
// Event dispatching is defined by the bound node, so if there's no bound
// node, there are no events to send. xforms-ready also needs to be handled,
// because these events are not sent before that.
if (!ns || !mReadyHandled)
return NS_OK;
if (ns->ShouldDispatchValid()) {
SetSingleState(element, ns->IsValid(), eEvent_Valid);
}
if (ns->ShouldDispatchReadonly()) {
SetSingleState(element, ns->IsReadonly(), eEvent_Readonly);
}
if (ns->ShouldDispatchRequired()) {
SetSingleState(element, ns->IsRequired(), eEvent_Required);
}
if (ns->ShouldDispatchRelevant()) {
SetSingleState(element, ns->IsRelevant(), eEvent_Enabled);
}
if (ns->ShouldDispatchValueChanged()) {
nsXFormsUtils::DispatchEvent(element, eEvent_ValueChanged);
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::Revalidate()
{
#ifdef DEBUG
printf("nsXFormsModelElement::Revalidate()\n");
#endif
#ifdef DEBUG_MODEL
printf("[%s] Changed nodes:\n", __TIME__);
for (PRInt32 j = 0; j < mChangedNodes.Count(); ++j) {
nsCOMPtr<nsIDOMNode> node = mChangedNodes[j];
nsAutoString name;
node->GetNodeName(name);
printf("\t%s [%p]\n",
NS_ConvertUTF16toUTF8(name).get(),
(void*) node);
}
#endif
// Revalidate nodes
mMDG.Revalidate(&mChangedNodes);
return NS_OK;
}
nsresult
nsXFormsModelElement::RefreshSubTree(nsXFormsControlListItem *aCurrent,
PRBool aForceRebind)
{
nsresult rv;
nsRefPtr<nsXFormsControlListItem> current = aCurrent;
while (current) {
nsCOMPtr<nsIXFormsControl> control(current->Control());
NS_ASSERTION(control, "A tree node without a control?!");
// Get bound node
nsCOMPtr<nsIDOMNode> boundNode;
control->GetBoundNode(getter_AddRefs(boundNode));
PRBool rebind = aForceRebind;
PRBool refresh = PR_FALSE;
PRBool rebindChildren = PR_FALSE;
#ifdef DEBUG_MODEL
nsCOMPtr<nsIDOMElement> controlElement;
control->GetElement(getter_AddRefs(controlElement));
printf("rebind: %d, mRebindAllControls: %d, aForceRebind: %d\n",
rebind, mRebindAllControls, aForceRebind);
if (controlElement) {
printf("Checking control: ");
//DBG_TAGINFO(controlElement);
}
#endif
if (mRebindAllControls || rebind) {
refresh = rebind = PR_TRUE;
} else {
PRBool usesModelBinding = PR_FALSE;
control->GetUsesModelBinding(&usesModelBinding);
#ifdef DEBUG_MODEL
printf("usesModelBinding: %d\n", usesModelBinding);
#endif
nsCOMArray<nsIDOMNode> *deps = nsnull;
if (usesModelBinding) {
if (!boundNode) {
PRBool usesSNB = PR_TRUE;
control->GetUsesSingleNodeBinding(&usesSNB);
// If the control doesn't use single node binding (and can thus be
// bound to many nodes), the above test for boundNode means nothing.
// We'll need to continue on with the work this function does so that
// any controls that this control contains can be tested for whether
// they may need to refresh.
if (usesSNB) {
// If a control uses a model binding, but has no bound node a
// rebuild is the only thing that'll (eventually) change it. We
// don't need to worry about contained controls (like a label)
// since the fact that there is no bound node means that this
// control (and contained controls) need to behave as if
// irrelevant per spec.
current = current->NextSibling();
continue;
}
}
} else {
// Get dependencies
control->GetDependencies(&deps);
}
PRUint32 depCount = deps ? deps->Count() : 0;
#ifdef DEBUG_MODEL
nsAutoString boundName;
if (boundNode)
boundNode->GetNodeName(boundName);
printf("\tDependencies: %d, Bound to: '%s' [%p]\n",
depCount,
NS_ConvertUTF16toUTF8(boundName).get(),
(void*) boundNode);
nsAutoString depNodeName;
for (PRUint32 t = 0; t < depCount; ++t) {
nsCOMPtr<nsIDOMNode> tmpdep = deps->ObjectAt(t);
if (tmpdep) {
tmpdep->GetNodeName(depNodeName);
printf("\t\t%s [%p]\n",
NS_ConvertUTF16toUTF8(depNodeName).get(),
(void*) tmpdep);
}
}
#endif
nsCOMPtr<nsIDOM3Node> curChanged;
// Iterator over changed nodes. Checking for rebind, too. If it ever
// becomes true due to some condition below, we can stop this testing
// since any control that needs to rebind will also refresh.
for (PRInt32 j = 0; j < mChangedNodes.Count() && !rebind; ++j) {
curChanged = do_QueryInterface(mChangedNodes[j]);
// Check whether the bound node is dirty. If so, we need to refresh the
// control (get updated node value from the bound node)
if (!refresh && boundNode) {
curChanged->IsSameNode(boundNode, &refresh);
// Two ways to go here. Keep in mind that controls using model
// binding expressions never needs to have dependencies checked as
// they only rebind on xforms-rebuild
if (refresh && usesModelBinding) {
// 1) If the control needs a refresh, and uses model bindings,
// we can stop checking here
break;
}
if (refresh || usesModelBinding) {
// 2) If either the control needs a refresh or it uses a model
// binding we can continue to next changed node
continue;
}
}
// Check whether any dependencies are dirty. If so, we need to rebind
// the control (re-evaluate it's binding expression)
for (PRUint32 k = 0; k < depCount; ++k) {
/// @note beaufour: I'm not too happy about this ...
/// O(mChangedNodes.Count() * deps->Count()), but using the pointers
/// for sorting and comparing does not work...
curChanged->IsSameNode(deps->ObjectAt(k), &rebind);
if (rebind)
// We need to rebind the control, no need to check any more
break;
}
}
#ifdef DEBUG_MODEL
printf("\trebind: %d, refresh: %d\n", rebind, refresh);
#endif
}
// Handle rebinding
if (rebind) {
rv = control->Bind(&rebindChildren);
NS_ENSURE_SUCCESS(rv, rv);
}
// Handle refreshing
if (rebind || refresh) {
control->Refresh();
// XXX: bug 336608: we should really check the return result, but
// f.x. select1 returns error because of no widget...? so we should
// ensure that an error is only returned when there actually is an
// error, and we should report that on the console... possibly we should
// then continue, instead of bailing totally.
// NS_ENSURE_SUCCESS(rv, rv);
}
// Refresh children
rv = RefreshSubTree(current->FirstChild(), rebindChildren);
NS_ENSURE_SUCCESS(rv, rv);
current = current->NextSibling();
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::Refresh()
{
#ifdef DEBUG
printf("nsXFormsModelElement::Refresh()\n");
#endif
// XXXbeaufour: Can we somehow suspend redraw / "screen update" while doing
// the refresh? That should save a lot of time, and avoid flickering of
// controls.
// Using brackets here to provide a scope for the
// nsPostRefresh. We want to make sure that nsPostRefresh's destructor
// runs (and thus processes the postrefresh and containerpostrefresh lists)
// before we clear the dispatch flags
{
nsPostRefresh postRefresh = nsPostRefresh();
if (!mDocumentLoaded) {
return NS_OK;
}
// Kick off refreshing on root node
nsresult rv = RefreshSubTree(mFormControls.FirstChild(), PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
// Clear refresh structures
mChangedNodes.Clear();
mRebindAllControls = PR_FALSE;
mMDG.ClearDispatchFlags();
return NS_OK;
}
// nsISchemaLoadListener
NS_IMETHODIMP
nsXFormsModelElement::OnLoad(nsISchema* aSchema)
{
mSchemaCount++;
// If there is no model element, then schema loading finished after
// main page failed to load.
if (IsComplete() && mElement) {
nsresult rv = FinishConstruction();
NS_ENSURE_SUCCESS(rv, rv);
MaybeNotifyCompletion();
}
return NS_OK;
}
// nsIWebServiceErrorHandler
NS_IMETHODIMP
nsXFormsModelElement::OnError(nsresult aStatus,
const nsAString &aStatusMessage)
{
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaLoadError"), mElement);
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
return NS_OK;
}
// nsIDOMEventListener
NS_IMETHODIMP
nsXFormsModelElement::HandleEvent(nsIDOMEvent* aEvent)
{
if (!nsXFormsUtils::EventHandlingAllowed(aEvent, mElement))
return NS_OK;
nsAutoString type;
aEvent->GetType(type);
if (type.EqualsLiteral("DOMContentLoaded")) {
return HandleLoad(aEvent);
}else if (type.EqualsLiteral("unload")) {
return HandleUnload(aEvent);
}
return NS_OK;
}
// nsIModelElementPrivate
NS_IMETHODIMP
nsXFormsModelElement::AddFormControl(nsIXFormsControl *aControl,
nsIXFormsControl *aParent)
{
#ifdef DEBUG_MODEL
printf("nsXFormsModelElement::AddFormControl(con: %p, parent: %p)\n",
(void*) aControl, (void*) aParent);
#endif
NS_ENSURE_ARG(aControl);
return mFormControls.AddControl(aControl, aParent);
}
NS_IMETHODIMP
nsXFormsModelElement::RemoveFormControl(nsIXFormsControl *aControl)
{
#ifdef DEBUG_MODEL
printf("nsXFormsModelElement::RemoveFormControl(con: %p)\n",
(void*) aControl);
#endif
NS_ENSURE_ARG(aControl);
PRBool removed;
nsresult rv = mFormControls.RemoveControl(aControl, removed);
NS_WARN_IF_FALSE(removed,
"Tried to remove control that was not in the model");
return rv;
}
NS_IMETHODIMP
nsXFormsModelElement::GetTypeForControl(nsIXFormsControl *aControl,
nsISchemaType **aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = nsnull;
nsCOMPtr<nsIDOMNode> boundNode;
aControl->GetBoundNode(getter_AddRefs(boundNode));
if (!boundNode) {
// if the control isn't bound to instance data, it doesn't make sense to
// return a type. It is perfectly valid for there to be no bound node,
// so no need to use an NS_ENSURE_xxx macro, either.
return NS_ERROR_FAILURE;
}
return GetTypeForNode(boundNode, aType);
}
NS_IMETHODIMP nsXFormsModelElement::GetTypeForNode(nsIDOMNode *aBoundNode,
nsISchemaType **aType)
{
nsAutoString schemaTypeName, schemaTypeNamespace;
nsresult rv = GetTypeFromNode(aBoundNode, schemaTypeName,
schemaTypeNamespace);
NS_ENSURE_SUCCESS(rv, rv);
nsXFormsSchemaValidator validator;
nsCOMPtr<nsISchemaCollection> schemaColl = do_QueryInterface(mSchemas);
if (schemaColl) {
nsCOMPtr<nsISchema> schema;
schemaColl->GetSchema(schemaTypeNamespace, getter_AddRefs(schema));
// if no schema found, then we will only handle built-in types.
if (schema)
validator.LoadSchema(schema);
}
if (validator.GetType(schemaTypeName, schemaTypeNamespace, aType))
rv = NS_OK;
else
rv = NS_ERROR_FAILURE;
return rv;
}
/* static */ nsresult
nsXFormsModelElement::GetTypeAndNSFromNode(nsIDOMNode *aInstanceData,
nsAString &aType, nsAString &aNSUri)
{
// 6.2.1 1. see if the instance data has a schema type.
// if the control has a schema type then we will then
// have to set a MIP node.
nsCOMPtr<nsISchemaType> schemaType;
nsresult rv = GetTypeForNode(aInstanceData, getter_AddRefs(schemaType));
if (rv == NS_OK) {
schemaType->GetTargetNamespace(aNSUri);
schemaType->GetName(aType);
return NS_OK;
}
// 6.2.1 2 & 3
// see if the type is assigned as an xsi:type, or XForms:type
nsAutoString schemaTypePrefix;
rv = nsXFormsUtils::ParseTypeFromNode(aInstanceData, aType, schemaTypePrefix);
// 6.2.1 4. Otherwise it is a string
if (rv == NS_ERROR_NOT_AVAILABLE) {
// if there is no type assigned, then assume that the type is 'string'
aNSUri.Assign(NS_LITERAL_STRING(NS_NAMESPACE_XML_SCHEMA));
aType.Assign(NS_LITERAL_STRING("string"));
rv = NS_OK;
} else {
if (schemaTypePrefix.IsEmpty()) {
aNSUri.AssignLiteral("");
} else {
// get the namespace url from the prefix
nsCOMPtr<nsIDOM3Node> domNode3(do_QueryInterface(mElement, &rv));
NS_ENSURE_SUCCESS(rv, rv);
rv = domNode3->LookupNamespaceURI(schemaTypePrefix, aNSUri);
}
}
return rv;
}
NS_IMETHODIMP
nsXFormsModelElement::InstanceLoadStarted()
{
++mPendingInstanceCount;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::InstanceLoadFinished(PRBool aSuccess,
const nsAString& aURI)
{
if (!aSuccess) {
// This will leave mPendingInstanceCount in an invalid state, which is
// exactly what we want, because this is a fatal error, and processing
// should stop. If we decrease mPendingInstanceCount, the model would
// finish construction, which is wrong.
nsXFormsUtils::ReportError(NS_LITERAL_STRING("instanceLoadError"), mElement);
if (!aURI.IsEmpty()) {
// Context Info: 'resource-uri'
// The resource URI of the link that failed.
nsCOMPtr<nsXFormsContextInfo> contextInfo =
new nsXFormsContextInfo(mElement);
NS_ENSURE_TRUE(contextInfo, NS_ERROR_OUT_OF_MEMORY);
contextInfo->SetStringValue("resource-uri", aURI);
mContextInfo.AppendObject(contextInfo);
}
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException, nsnull,
nsnull, &mContextInfo);
return NS_OK;
}
--mPendingInstanceCount;
if (IsComplete()) {
nsresult rv = FinishConstruction();
if (NS_SUCCEEDED(rv)) {
MaybeNotifyCompletion();
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::FindInstanceElement(const nsAString &aID,
nsIInstanceElementPrivate **aElement)
{
NS_ENSURE_STATE(mInstanceDocuments);
*aElement = nsnull;
PRUint32 instCount;
mInstanceDocuments->GetLength(&instCount);
if (instCount) {
nsCOMPtr<nsIDOMElement> element;
nsAutoString id;
for (PRUint32 i = 0; i < instCount; ++i) {
nsIInstanceElementPrivate* instEle = mInstanceDocuments->GetInstanceAt(i);
instEle->GetElement(getter_AddRefs(element));
if (aID.IsEmpty()) {
NS_ADDREF(instEle);
*aElement = instEle;
break;
} else if (!element) {
// this should only happen if the instance on the list is lazy authored
// and as far as I can tell, a lazy authored instance should be the
// first (and only) instance in the model and unable to have an ID.
// But that isn't clear to me reading the spec, so for now
// we'll play it safe in case the WG more clearly defines lazy authoring
// in the future.
continue;
}
element->GetAttribute(NS_LITERAL_STRING("id"), id);
if (aID.Equals(id)) {
NS_ADDREF(instEle);
*aElement = instEle;
break;
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::SetNodeValue(nsIDOMNode *aNode,
const nsAString &aNodeValue,
PRBool aDoRefresh,
PRBool *aNodeChanged)
{
NS_ENSURE_ARG_POINTER(aNodeChanged);
nsresult rv = mMDG.SetNodeValue(aNode, aNodeValue, aNodeChanged);
NS_ENSURE_SUCCESS(rv, rv);
if (*aNodeChanged && aDoRefresh) {
rv = RequestRecalculate();
NS_ENSURE_SUCCESS(rv, rv);
rv = RequestRevalidate();
NS_ENSURE_SUCCESS(rv, rv);
rv = RequestRefresh();
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::SetNodeContent(nsIDOMNode *aNode,
nsIDOMNode *aNodeContent,
PRBool aDoRebuild)
{
nsresult rv = mMDG.SetNodeContent(aNode, aNodeContent);
NS_ENSURE_SUCCESS(rv, rv);
if (aDoRebuild) {
rv = RequestRebuild();
NS_ENSURE_SUCCESS(rv, rv);
rv = RequestRecalculate();
NS_ENSURE_SUCCESS(rv, rv);
rv = RequestRevalidate();
NS_ENSURE_SUCCESS(rv, rv);
rv = RequestRefresh();
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::ValidateNode(nsIDOMNode *aInstanceNode, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
nsAutoString schemaTypeName, schemaTypeNamespace;
nsresult rv = GetTypeAndNSFromNode(aInstanceNode, schemaTypeName,
schemaTypeNamespace);
NS_ENSURE_SUCCESS(rv, rv);
nsXFormsSchemaValidator validator;
nsCOMPtr<nsISchemaCollection> schemaColl = do_QueryInterface(mSchemas);
if (schemaColl) {
nsCOMPtr<nsISchema> schema;
schemaColl->GetSchema(schemaTypeNamespace, getter_AddRefs(schema));
// if no schema found, then we will only handle built-in types.
if (schema)
validator.LoadSchema(schema);
}
nsCOMPtr<nsISchemaType> type;
rv = validator.GetType(schemaTypeName, schemaTypeNamespace,
getter_AddRefs(type));
NS_ENSURE_SUCCESS(rv, rv);
PRUint16 typevalue = nsISchemaType::SCHEMA_TYPE_SIMPLE;
if (type) {
rv = type->GetSchemaType(&typevalue);
NS_ENSURE_SUCCESS(rv, rv);
}
PRBool isValid = PR_FALSE;
if (typevalue == nsISchemaType::SCHEMA_TYPE_SIMPLE) {
nsAutoString value;
nsXFormsUtils::GetNodeValue(aInstanceNode, value);
isValid = validator.ValidateString(value, schemaTypeName,
schemaTypeNamespace);
} else {
isValid = validator.Validate(aInstanceNode);
}
*aResult = isValid;
return NS_OK;
}
nsresult
nsXFormsModelElement::ValidateDocument(nsIDOMDocument *aInstanceDocument,
PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
NS_ENSURE_ARG(aInstanceDocument);
/*
This will process the instance document and check for schema validity. It
will mark nodes in the document with their schema types using nsIProperty
until it hits a structural schema validation error. So if the instance
document's XML structure is invalid, don't expect type properties to be
set.
Note that if the structure is fine but some simple types nodes (nodes
that contain text only) are invalid (say one has a empty nodeValue but
should be a date), the schema validator will continue processing and add
the type properties. Schema validation will return false at the end.
*/
nsCOMPtr<nsIDOMElement> element;
nsresult rv = aInstanceDocument->GetDocumentElement(getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_STATE(element);
// get namespace from node
nsAutoString nsuri;
element->GetNamespaceURI(nsuri);
nsCOMPtr<nsISchemaCollection> schemaColl = do_QueryInterface(mSchemas);
NS_ENSURE_STATE(schemaColl);
nsCOMPtr<nsISchema> schema;
schemaColl->GetSchema(nsuri, getter_AddRefs(schema));
if (!schema) {
// No schema found, so nothing to validate
*aResult = PR_TRUE;
return NS_OK;
}
nsXFormsSchemaValidator validator;
validator.LoadSchema(schema);
// Validate will validate the node and its subtree, as per the schema
// specification.
*aResult = validator.Validate(element);
return NS_OK;
}
/*
* SUBMIT_SERIALIZE_NODE - node is to be serialized
* SUBMIT_SKIP_NODE - node is not to be serialized
* SUBMIT_ABORT_SUBMISSION - abort submission (invalid node or empty required node)
*/
NS_IMETHODIMP
nsXFormsModelElement::HandleInstanceDataNode(nsIDOMNode *aInstanceDataNode,
unsigned short *aResult)
{
// abort by default
*aResult = SUBMIT_ABORT_SUBMISSION;
const nsXFormsNodeState* ns;
ns = mMDG.GetNodeState(aInstanceDataNode);
NS_ENSURE_STATE(ns);
if (!ns->IsRelevant()) {
// not relevant, thus skip
*aResult = SUBMIT_SKIP_NODE;
} else if (ns->IsRequired()) {
// required and has a value, continue
nsAutoString value;
nsXFormsUtils::GetNodeValue(aInstanceDataNode, value);
if (!value.IsEmpty() && ns->IsValid())
*aResult = SUBMIT_SERIALIZE_NODE;
} else if (ns->IsValid()) {
// valid
*aResult = SUBMIT_SERIALIZE_NODE;
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetLazyAuthored(PRBool *aLazyInstance)
{
*aLazyInstance = mLazyModel;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetIsReady(PRBool *aIsReady)
{
*aIsReady = mReadyHandled;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetTypeFromNode(nsIDOMNode *aInstanceData,
nsAString &aType,
nsAString &aNSUri)
{
// aInstanceData could be an instance data node or it could be an attribute
// on an instance data node (basically the node that a control is bound to).
nsString *typeVal = nsnull;
// Get type stored directly on instance node
nsAutoString typeAttribute;
nsCOMPtr<nsIDOMElement> nodeElem(do_QueryInterface(aInstanceData));
if (nodeElem) {
nodeElem->GetAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XML_SCHEMA_INSTANCE),
NS_LITERAL_STRING("type"), typeAttribute);
if (!typeAttribute.IsEmpty()) {
typeVal = &typeAttribute;
}
}
// If there was no type information on the node itself, check for a type
// bound to the node via \<xforms:bind\>
if (!typeVal && !mNodeToType.Get(aInstanceData, &typeVal)) {
// check if schema validation left us a nsISchemaType*
nsCOMPtr<nsIAtom> key = do_GetAtom("xsdtype");
NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIVariant> xsdType;
// this is stored on the DOM3Node as a property called xsdtype
nsCOMPtr<nsIContent> pContent(do_QueryInterface(aInstanceData));
if (pContent) {
xsdType = static_cast<nsIVariant*>(pContent->GetProperty(key, &rv));
} else {
// see if this is stored on an attribute node
nsCOMPtr<nsIAttribute> pAttribute(do_QueryInterface(aInstanceData));
if (pAttribute) {
xsdType = static_cast<nsIVariant*>(pAttribute->GetProperty(key, &rv));
}
}
if (NS_SUCCEEDED(rv) && xsdType) {
nsCOMPtr<nsISchemaType> type;
nsIID *containedInterface;
if (NS_SUCCEEDED(xsdType->GetAsInterface(&containedInterface,
getter_AddRefs(type))) && type) {
type->GetName(aType);
type->GetTargetNamespace(aNSUri);
return NS_OK;
}
}
// No type information found
return NS_ERROR_NOT_AVAILABLE;
}
// split type (ns:type) into namespace and type.
nsAutoString prefix;
PRInt32 separator = typeVal->FindChar(':');
if ((PRUint32) separator == (typeVal->Length() - 1)) {
const PRUnichar *strings[] = { typeVal->get() };
nsXFormsUtils::ReportError(NS_LITERAL_STRING("missingTypeName"), strings, 1,
mElement, nsnull);
return NS_ERROR_UNEXPECTED;
}
if (separator == kNotFound) {
// no namespace prefix, which is valid. In this case we should follow
// http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#src-qname and pick
// up the default namespace. Which will happen by passing an empty string
// as first parameter to LookupNamespaceURI.
prefix = EmptyString();
aType.Assign(*typeVal);
} else {
prefix.Assign(Substring(*typeVal, 0, separator));
aType.Assign(Substring(*typeVal, ++separator, typeVal->Length()));
if (prefix.IsEmpty()) {
aNSUri = EmptyString();
return NS_OK;
}
}
// get the namespace url from the prefix using instance data node
nsresult rv;
nsCOMPtr<nsIDOM3Node> domNode3 = do_QueryInterface(aInstanceData, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = domNode3->LookupNamespaceURI(prefix, aNSUri);
if (DOMStringIsNull(aNSUri)) {
// if not found using instance data node, use <xf:instance> node
nsCOMPtr<nsIDOMNode> instanceNode;
rv = nsXFormsUtils::GetInstanceNodeForData(aInstanceData,
getter_AddRefs(instanceNode));
NS_ENSURE_SUCCESS(rv, rv);
domNode3 = do_QueryInterface(instanceNode, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = domNode3->LookupNamespaceURI(prefix, aNSUri);
}
return rv;
}
/**
* Poor man's try-catch to make sure that we set mProcessingUpdateEvent to
* when leaving scope. If we actually bail with an error at some time,
* something is pretty rotten, but at least we will not prevent any further
* updates.
*/
class Updating {
private:
nsXFormsModelElement* mModel;
public:
Updating(nsXFormsModelElement* aModel)
: mModel(aModel) { mModel->mProcessingUpdateEvent = PR_TRUE; };
~Updating() { mModel->mProcessingUpdateEvent = PR_FALSE; };
};
nsresult
nsXFormsModelElement::RequestUpdateEvent(nsXFormsEvent aEvent)
{
if (mProcessingUpdateEvent) {
mUpdateEventQueue.AppendElement(NS_INT32_TO_PTR(aEvent));
return NS_OK;
}
Updating upd(this);
// Send the requested event
nsresult rv = nsXFormsUtils::DispatchEvent(mElement, aEvent);
NS_ENSURE_SUCCESS(rv, rv);
// Process queued events
PRInt32 loopCount = 0;
while (mUpdateEventQueue.Count()) {
nsXFormsEvent event =
NS_STATIC_CAST(nsXFormsEvent, NS_PTR_TO_UINT32(mUpdateEventQueue[0]));
NS_ENSURE_TRUE(mUpdateEventQueue.RemoveElementAt(0), NS_ERROR_FAILURE);
rv = nsXFormsUtils::DispatchEvent(mElement, event);
NS_ENSURE_SUCCESS(rv, rv);
++loopCount;
if (mLoopMax && loopCount > mLoopMax) {
// Note: we could also popup a dialog asking the user whether or not to
// continue.
nsXFormsUtils::ReportError(NS_LITERAL_STRING("modelLoopError"), mElement);
nsXFormsUtils::HandleFatalError(mElement, NS_LITERAL_STRING("LoopError"));
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::RequestRebuild()
{
return RequestUpdateEvent(eEvent_Rebuild);
}
NS_IMETHODIMP
nsXFormsModelElement::RequestRecalculate()
{
return RequestUpdateEvent(eEvent_Recalculate);
}
NS_IMETHODIMP
nsXFormsModelElement::RequestRevalidate()
{
return RequestUpdateEvent(eEvent_Revalidate);
}
NS_IMETHODIMP
nsXFormsModelElement::RequestRefresh()
{
return RequestUpdateEvent(eEvent_Refresh);
}
// nsIXFormsContextControl
NS_IMETHODIMP
nsXFormsModelElement::SetContext(nsIDOMNode *aContextNode,
PRInt32 aContextPosition,
PRInt32 aContextSize)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXFormsModelElement::GetContext(nsAString &aModelID,
nsIDOMNode **aContextNode,
PRInt32 *aContextPosition,
PRInt32 *aContextSize)
{
// Adding the nsIXFormsContextControl interface to model to allow
// submission elements to call our binding evaluation methods, like
// EvaluateNodeBinding. If GetContext can get called outside of the binding
// codepath, then this MIGHT lead to problems.
NS_ENSURE_ARG(aContextSize);
NS_ENSURE_ARG(aContextPosition);
*aContextNode = nsnull;
// better get the stuff most likely to fail out of the way first. No sense
// changing the other values that we are returning unless this is successful.
nsresult rv = NS_ERROR_FAILURE;
// Anybody (like a submission element) asking a model element for its context
// for XPath expressions will want the root node of the default instance
// document
nsCOMPtr<nsIDOMDocument> firstInstanceDoc =
FindInstanceDocument(EmptyString());
NS_ENSURE_TRUE(firstInstanceDoc, rv);
nsCOMPtr<nsIDOMElement> firstInstanceRoot;
rv = firstInstanceDoc->GetDocumentElement(getter_AddRefs(firstInstanceRoot));
NS_ENSURE_TRUE(firstInstanceRoot, rv);
nsCOMPtr<nsIDOMNode>rootNode = do_QueryInterface(firstInstanceRoot);
rootNode.swap(*aContextNode);
// found the context, so can finish up assinging the rest of the values that
// we are returning
*aContextPosition = 1;
*aContextSize = 1;
nsAutoString id;
mElement->GetAttribute(NS_LITERAL_STRING("id"), id);
aModelID.Assign(id);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::AddRemoveAbortedControl(nsIXFormsControl *aControl,
PRBool aAdd)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// internal methods
already_AddRefed<nsIDOMDocument>
nsXFormsModelElement::FindInstanceDocument(const nsAString &aID)
{
nsCOMPtr<nsIInstanceElementPrivate> instance;
nsXFormsModelElement::FindInstanceElement(aID, getter_AddRefs(instance));
nsIDOMDocument *doc = nsnull;
if (instance) {
instance->GetInstanceDocument(&doc); // addrefs
}
return doc;
}
nsresult
nsXFormsModelElement::ProcessBindElements()
{
// ProcessBindElements() will go through each xforms:bind element in
// document order and apply all of the Model Item Properties to the
// instance items in the nodeset. This information will also be entered
// in the Master Dependency Graph. Most of this work is done in the
// ProcessBind() method.
nsCOMPtr<nsIDOMDocument> firstInstanceDoc =
FindInstanceDocument(EmptyString());
if (!firstInstanceDoc)
return NS_OK;
nsCOMPtr<nsIDOMElement> firstInstanceRoot;
firstInstanceDoc->GetDocumentElement(getter_AddRefs(firstInstanceRoot));
nsresult rv;
nsCOMPtr<nsIXFormsXPathEvaluator> xpath =
do_CreateInstance("@mozilla.org/dom/xforms-xpath-evaluator;1", &rv);
NS_ENSURE_TRUE(xpath, rv);
nsCOMPtr<nsIDOMNodeList> children;
mElement->GetChildNodes(getter_AddRefs(children));
PRUint32 childCount = 0;
if (children)
children->GetLength(&childCount);
nsAutoString namespaceURI, localName;
for (PRUint32 i = 0; i < childCount; ++i) {
nsCOMPtr<nsIDOMNode> child;
children->Item(i, getter_AddRefs(child));
NS_ASSERTION(child, "there can't be null items in the NodeList!");
child->GetLocalName(localName);
if (localName.EqualsLiteral("bind")) {
child->GetNamespaceURI(namespaceURI);
if (namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
rv = ProcessBind(xpath, firstInstanceRoot, 1, 1,
nsCOMPtr<nsIDOMElement>(do_QueryInterface(child)),
PR_TRUE);
if (NS_FAILED(rv)) {
return NS_OK;
}
}
}
}
return NS_OK;
}
void
nsXFormsModelElement::Reset()
{
BackupOrRestoreInstanceData(PR_TRUE);
nsXFormsUtils::DispatchEvent(mElement, eEvent_Rebuild);
nsXFormsUtils::DispatchEvent(mElement, eEvent_Recalculate);
nsXFormsUtils::DispatchEvent(mElement, eEvent_Revalidate);
nsXFormsUtils::DispatchEvent(mElement, eEvent_Refresh);
}
// This function will restore all of the model's instance data to it's original
// state if the supplied boolean is PR_TRUE. If it is PR_FALSE, this function
// will cause this model's instance data to be backed up.
void
nsXFormsModelElement::BackupOrRestoreInstanceData(PRBool restore)
{
if (!mInstanceDocuments)
return;
PRUint32 instCount;
mInstanceDocuments->GetLength(&instCount);
if (instCount) {
for (PRUint32 i = 0; i < instCount; ++i) {
nsIInstanceElementPrivate *instance =
mInstanceDocuments->GetInstanceAt(i);
// Don't know what to do with error if we get one.
// Restore/BackupOriginalDocument will already output warnings.
if (restore) {
instance->RestoreOriginalDocument();
}
else {
instance->BackupOriginalDocument();
}
}
}
}
nsresult
nsXFormsModelElement::FinishConstruction()
{
// Ensure that FinishConstruction isn't called due to some callback
// or event handler after the model has started going through its
// destruction phase
NS_ENSURE_STATE(mElement);
// process inline schemas that aren't referenced via the schema attribute
nsCOMPtr<nsIDOMNodeList> children;
mElement->GetChildNodes(getter_AddRefs(children));
if (children) {
PRUint32 childCount = 0;
children->GetLength(&childCount);
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIDOMElement> element;
nsAutoString nsURI, localName, targetNamespace;
for (PRUint32 i = 0; i < childCount; ++i) {
children->Item(i, getter_AddRefs(node));
element = do_QueryInterface(node);
if (!element)
continue;
node->GetNamespaceURI(nsURI);
node->GetLocalName(localName);
if (nsURI.EqualsLiteral(NS_NAMESPACE_XML_SCHEMA) &&
localName.EqualsLiteral("schema")) {
if (!IsDuplicateSchema(element)) {
nsCOMPtr<nsISchema> schema;
nsresult rv = mSchemas->ProcessSchemaElement(element, nsnull,
getter_AddRefs(schema));
if (!NS_SUCCEEDED(rv)) {
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaProcessError"),
node);
}
}
}
}
}
// (XForms 4.2.1 - cont)
// 3. if applicable, initialize P3P
// 4. construct instance data from initial instance data. apply all
// <bind> elements in document order.
// we get the instance data from our instance child nodes
// We're done initializing this model.
// 5. Perform an xforms-rebuild, xforms-recalculate, and xforms-revalidate in
// sequence, for this model element. (The xforms-refresh is not performed
// since the user interface has not yet been initialized).
nsXFormsUtils::DispatchEvent(mElement, eEvent_Rebuild);
nsXFormsUtils::DispatchEvent(mElement, eEvent_Recalculate);
nsXFormsUtils::DispatchEvent(mElement, eEvent_Revalidate);
return NS_OK;
}
nsresult
nsXFormsModelElement::InitializeControls()
{
#ifdef DEBUG
printf("nsXFormsModelElement::InitializeControls()\n");
#endif
nsPostRefresh postRefresh = nsPostRefresh();
nsXFormsControlListItem::iterator it;
nsresult rv;
PRBool dummy;
for (it = mFormControls.begin(); it != mFormControls.end(); ++it) {
// Get control
nsCOMPtr<nsIXFormsControl> control = (*it)->Control();
NS_ASSERTION(control, "mFormControls has null control?!");
#ifdef DEBUG_MODEL
printf("\tControl (%p): ", (void*) control);
nsCOMPtr<nsIDOMElement> controlElement;
control->GetElement(getter_AddRefs(controlElement));
// DBG_TAGINFO(controlElement);
#endif
// Rebind
rv = control->Bind(&dummy);
NS_ENSURE_SUCCESS(rv, rv);
// Refresh controls
rv = control->Refresh();
// XXX: Bug 336608, refresh still fails for some controls, for some
// reason.
// NS_ENSURE_SUCCESS(rv, rv);
}
mChangedNodes.Clear();
return NS_OK;
}
void
nsXFormsModelElement::ValidateInstanceDocuments()
{
if (mInstanceDocuments) {
PRUint32 instCount;
mInstanceDocuments->GetLength(&instCount);
if (instCount) {
nsCOMPtr<nsIDOMDocument> document;
for (PRUint32 i = 0; i < instCount; ++i) {
nsIInstanceElementPrivate* instEle =
mInstanceDocuments->GetInstanceAt(i);
nsCOMPtr<nsIXFormsNSInstanceElement> NSInstEle(instEle);
NSInstEle->GetInstanceDocument(getter_AddRefs(document));
NS_ASSERTION(document,
"nsIXFormsNSInstanceElement::GetInstanceDocument returned null?!");
if (document) {
PRBool isValid = PR_FALSE;
ValidateDocument(document, &isValid);
if (!isValid) {
nsCOMPtr<nsIDOMElement> instanceElement;
instEle->GetElement(getter_AddRefs(instanceElement));
nsXFormsUtils::ReportError(NS_LITERAL_STRING("instDocumentInvalid"),
instanceElement);
}
}
}
}
}
}
// NOTE: This function only runs to completion for _one_ of the models in the
// document.
void
nsXFormsModelElement::MaybeNotifyCompletion()
{
nsCOMPtr<nsIDOMDocument> domDoc;
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
const nsVoidArray *models = GetModelList(domDoc);
if (!models) {
NS_NOTREACHED("no model list property");
return;
}
PRInt32 i;
// Nothing to be done if any model is incomplete or hasn't seen
// DOMContentLoaded.
for (i = 0; i < models->Count(); ++i) {
nsXFormsModelElement *model =
NS_STATIC_CAST(nsXFormsModelElement *, models->ElementAt(i));
if (!model->mDocumentLoaded || !model->IsComplete())
return;
// Check validity of |functions=| attribute, if it exists. Since we
// don't support ANY extension functions currently, the existance of
// |functions=| with a non-empty value is an error.
nsCOMPtr<nsIDOMElement> tElement = model->mElement;
nsAutoString extFunctionAtt;
tElement->GetAttribute(NS_LITERAL_STRING("functions"), extFunctionAtt);
if (!extFunctionAtt.IsEmpty()) {
nsXFormsUtils::ReportError(NS_LITERAL_STRING("invalidExtFunction"),
tElement);
// Context Info: 'error-message'
// Error message containing the expression being processed.
nsAutoString errorMsg;
errorMsg.AssignLiteral("Non-existent extension functions: ");
errorMsg.Append(extFunctionAtt);
SetContextInfo("error-message", errorMsg);
nsXFormsUtils::DispatchEvent(tElement, eEvent_ComputeException, nsnull,
nsnull, &mContextInfo);
return;
}
}
// validate the instance documents because we want schemaValidation to add
// schema type properties from the schema file unto our instance document
// elements.
// XXX: wrong location of this call, @see bug 339674
ValidateInstanceDocuments();
// Register deferred binds with the model. It does not bind the controls,
// only bind them to the model they belong to.
nsXFormsModelElement::ProcessDeferredBinds(domDoc);
// Okay, dispatch xforms-model-construct-done
for (i = 0; i < models->Count(); ++i) {
nsXFormsModelElement *model =
NS_STATIC_CAST(nsXFormsModelElement *, models->ElementAt(i));
nsXFormsUtils::DispatchEvent(model->mElement, eEvent_ModelConstructDone);
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
if (doc) {
PRUint32 loadingMessages = NS_PTR_TO_UINT32(
doc->GetProperty(nsXFormsAtoms::externalMessagesProperty));
if (loadingMessages) {
// if we are still waiting for external messages to load, then put off
// the xforms-ready until a model in the document is notified that they
// are finished loading
return;
}
}
// Backup instances and fire xforms-ready
for (i = 0; i < models->Count(); ++i) {
nsXFormsModelElement *model =
NS_STATIC_CAST(nsXFormsModelElement *, models->ElementAt(i));
model->BackupOrRestoreInstanceData(PR_FALSE);
model->mReadyHandled = PR_TRUE;
nsXFormsUtils::DispatchEvent(model->mElement, eEvent_Ready);
}
}
nsresult
nsXFormsModelElement::ProcessBind(nsIXFormsXPathEvaluator *aEvaluator,
nsIDOMNode *aContextNode,
PRInt32 aContextPosition,
PRInt32 aContextSize,
nsIDOMElement *aBindElement,
PRBool aIsOuter)
{
// Get the model item properties specified by this \<bind\>.
nsCOMPtr<nsIDOMNSXPathExpression> props[eModel__count];
nsAutoString propStrings[eModel__count];
nsresult rv;
nsAutoString attrStr;
for (PRUint32 i = 0; i < eModel__count; ++i) {
sModelPropsList[i]->ToString(attrStr);
aBindElement->GetAttribute(attrStr, propStrings[i]);
}
// Find the nodeset that this bind applies to.
nsCOMPtr<nsIDOMXPathResult> result;
nsAutoString expr;
aBindElement->GetAttribute(NS_LITERAL_STRING("nodeset"), expr);
if (expr.IsEmpty()) {
expr = NS_LITERAL_STRING(".");
}
rv = aEvaluator->Evaluate(expr, aContextNode, aContextPosition, aContextSize,
aBindElement, aContextNode,
nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
nsnull, getter_AddRefs(result));
if (NS_FAILED(rv)) {
if (rv == nsIDOMXPathException::INVALID_EXPRESSION_ERR) {
// the xpath expression isn't valid xpath
const nsPromiseFlatString& flat = PromiseFlatString(expr);
const PRUnichar *strings[] = { flat.get() };
nsXFormsUtils::ReportError(NS_LITERAL_STRING("exprParseError"),
strings, 1, aBindElement, nsnull);
// Context Info: 'error-message'
// Error message containing the expression being processed.
nsAutoString errorMsg;
errorMsg.AssignLiteral("Error parsing XPath expression: ");
errorMsg.Append(expr);
SetContextInfo("error-message", errorMsg);
nsXFormsUtils::DispatchEvent(mElement, eEvent_ComputeException, nsnull,
nsnull, &mContextInfo);
} else {
#ifdef DEBUG
printf("xforms-binding-exception: XPath Evaluation failed\n");
#endif
const PRUnichar *strings[] = { expr.get() };
nsXFormsUtils::ReportError(NS_LITERAL_STRING("nodesetEvaluateError"),
strings, 1, aBindElement, aBindElement);
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
}
return rv;
}
NS_ENSURE_STATE(result);
// If this is an outer bind, store the nodeset, as controls binding to this
// bind will need this.
if (aIsOuter) {
nsCOMPtr<nsIContent> content(do_QueryInterface(aBindElement));
NS_ASSERTION(content, "nsIDOMElement not implementing nsIContent?!");
rv = content->SetProperty(nsXFormsAtoms::bind, result,
SupportsDtorFunc);
NS_ENSURE_SUCCESS(rv, rv);
// addref, circumventing nsDerivedSave
NS_ADDREF(NS_STATIC_CAST(nsIDOMXPathResult*, result));
}
PRUint32 snapLen;
rv = result->GetSnapshotLength(&snapLen);
NS_ENSURE_SUCCESS(rv, rv);
// Iterate over resultset
nsCOMArray<nsIDOMNode> deps;
nsCOMPtr<nsIDOMNode> node;
PRUint32 snapItem;
for (snapItem = 0; snapItem < snapLen; ++snapItem) {
rv = result->SnapshotItem(snapItem, getter_AddRefs(node));
NS_ENSURE_SUCCESS(rv, rv);
if (!node) {
NS_WARNING("nsXFormsModelElement::ProcessBind(): Empty node in result set.");
continue;
}
// Apply MIPs
nsXFormsXPathParser parser;
nsXFormsXPathAnalyzer analyzer(aEvaluator, aBindElement, node);
PRBool multiMIP = PR_FALSE;
for (PRUint32 j = 0; j < eModel__count; ++j) {
if (propStrings[j].IsEmpty())
continue;
// type and p3ptype are stored as properties on the instance node
if (j == eModel_type || j == eModel_p3ptype) {
nsClassHashtable<nsISupportsHashKey, nsString> *table;
table = j == eModel_type ? &mNodeToType : &mNodeToP3PType;
NS_ENSURE_TRUE(table->IsInitialized(), NS_ERROR_FAILURE);
// Check for existing value
if (table->Get(node, nsnull)) {
multiMIP = PR_TRUE;
break;
}
// Insert value
nsAutoPtr<nsString> newString(new nsString(propStrings[j]));
NS_ENSURE_TRUE(newString, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(table->Put(node, newString), NS_ERROR_OUT_OF_MEMORY);
// string is succesfully stored in the table, we should not dealloc it
newString.forget();
if (j == eModel_type) {
// Inform MDG that it needs to check type. The only arguments
// actually used are |eModel_constraint| and |node|.
rv = mMDG.AddMIP(eModel_constraint, nsnull, nsnull, PR_FALSE, node, 1,
1);
NS_ENSURE_SUCCESS(rv, rv);
}
} else {
rv = aEvaluator->CreateExpression(propStrings[j], aBindElement, node,
getter_AddRefs(props[j]));
if (NS_FAILED(rv)) {
const PRUnichar *strings[] = { propStrings[j].get() };
nsXFormsUtils::ReportError(NS_LITERAL_STRING("mipParseError"),
strings, 1, aBindElement, aBindElement);
// Context Info: 'error-message'
// Error message containing the expression being processed.
nsAutoString errorMsg;
errorMsg.AssignLiteral("Error while parsing model item property: ");
errorMsg.Append(propStrings[j]);
SetContextInfo("error-message", errorMsg);
nsXFormsUtils::DispatchEvent(mElement, eEvent_ComputeException,
nsnull, nsnull, &mContextInfo);
return rv;
}
// the rest of the MIPs are given to the MDG
nsCOMPtr<nsIDOMNSXPathExpression> expr = props[j];
// Get node dependencies
nsAutoPtr<nsXFormsXPathNode> xNode(parser.Parse(propStrings[j]));
deps.Clear();
rv = analyzer.Analyze(node, xNode, expr, &propStrings[j], &deps,
snapItem + 1, snapLen, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// Insert into MDG
rv = mMDG.AddMIP((ModelItemPropName) j,
expr,
&deps,
parser.UsesDynamicFunc(),
node,
snapItem + 1,
snapLen);
// if the call results in NS_ERROR_ABORT the page has tried to set a
// MIP twice, break and emit an exception.
if (rv == NS_ERROR_ABORT) {
multiMIP = PR_TRUE;
break;
}
NS_ENSURE_SUCCESS(rv, rv);
}
}
// If the attribute is already there, the page sets a MIP twice
// which is illegal, and should result in an xforms-binding-exception.
// @see http://www.w3.org/TR/xforms/slice4.html#evt-modelConstruct
// (item 4, c)
if (multiMIP) {
#ifdef DEBUG
printf("xforms-binding-exception: Multiple MIPs on same node!");
#endif
nsXFormsUtils::ReportError(NS_LITERAL_STRING("multiMIPError"),
aBindElement);
nsXFormsUtils::DispatchEvent(aBindElement,
eEvent_BindingException);
return NS_ERROR_FAILURE;
}
// Now evaluate any child \<bind\> elements.
nsCOMPtr<nsIDOMNodeList> children;
aBindElement->GetChildNodes(getter_AddRefs(children));
if (children) {
PRUint32 childCount = 0;
children->GetLength(&childCount);
nsCOMPtr<nsIDOMNode> child;
nsAutoString value;
for (PRUint32 k = 0; k < childCount; ++k) {
children->Item(k, getter_AddRefs(child));
if (child) {
child->GetLocalName(value);
if (!value.EqualsLiteral("bind"))
continue;
child->GetNamespaceURI(value);
if (!value.EqualsLiteral(NS_NAMESPACE_XFORMS))
continue;
rv = ProcessBind(aEvaluator, node,
snapItem + 1, snapLen,
nsCOMPtr<nsIDOMElement>(do_QueryInterface(child)));
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::AddInstanceElement(nsIInstanceElementPrivate *aInstEle)
{
NS_ENSURE_STATE(mInstanceDocuments);
mInstanceDocuments->AddInstance(aInstEle);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::RemoveInstanceElement(nsIInstanceElementPrivate *aInstEle)
{
NS_ENSURE_STATE(mInstanceDocuments);
mInstanceDocuments->RemoveInstance(aInstEle);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::MessageLoadFinished()
{
// This is our signal that all external message links have been tested. If
// we were waiting for this to send out xforms-ready, then now is the time.
// if this document hasn't processed xforms-model-construct-done, yet (which
// must precede xforms-ready), then we'll send out the xforms-ready later
// as part of our normal handling. If we've already become ready, then this
// event was probably generated by a change in the src attribute on the
// message element. Ignore it in that case.
if (!mConstructDoneHandled || mReadyHandled) {
return NS_OK;
}
nsCOMPtr<nsIDOMDocument> domDoc;
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
const nsVoidArray *models = GetModelList(domDoc);
nsCOMPtr<nsIDocument>doc = do_QueryInterface(domDoc);
nsCOMArray<nsIXFormsControl> *deferredBindList =
NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *,
doc->GetProperty(nsXFormsAtoms::deferredBindListProperty));
// if we've already gotten the xforms-model-construct-done event and not
// yet the xforms-ready, we've hit a window where we may still be
// processing the deferred control binding. If so, we'll leave now and
// leave it to MaybeNotifyCompletion to generate the xforms-ready event.
if (deferredBindList) {
return NS_OK;
}
// if we reached here, then we had to wait on sending out the xforms-ready
// events until the external messages were tested. Now we are finally
// ready to send out xforms-ready to all of the models.
for (int i = 0; i < models->Count(); ++i) {
nsXFormsModelElement *model =
NS_STATIC_CAST(nsXFormsModelElement *, models->ElementAt(i));
model->mReadyHandled = PR_TRUE;
nsXFormsUtils::DispatchEvent(model->mElement, eEvent_Ready);
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetHasDOMContentFired(PRBool *aLoaded)
{
NS_ENSURE_ARG_POINTER(aLoaded);
*aLoaded = mDocumentLoaded;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::ForceRebind(nsIXFormsControl* aControl)
{
if (!aControl) {
return NS_OK;
}
nsXFormsControlListItem* controlItem = mFormControls.FindControl(aControl);
NS_ENSURE_STATE(controlItem);
PRBool rebindChildren;
nsresult rv = aControl->Bind(&rebindChildren);
NS_ENSURE_SUCCESS(rv, rv);
rv = aControl->Refresh();
// XXX: no rv-check, see bug 336608
// Refresh children
return RefreshSubTree(controlItem->FirstChild(), rebindChildren);
}
nsresult
nsXFormsModelElement::GetBuiltinTypeName(PRUint16 aType,
nsAString& aName)
{
switch (aType) {
case nsISchemaBuiltinType::BUILTIN_TYPE_STRING:
aName.AssignLiteral("string");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_BOOLEAN:
aName.AssignLiteral("boolean");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL:
aName.AssignLiteral("decimal");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_FLOAT:
aName.AssignLiteral("float");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_DOUBLE:
aName.AssignLiteral("double");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_DURATION:
aName.AssignLiteral("duration");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_DATETIME:
aName.AssignLiteral("dateTime");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_TIME:
aName.AssignLiteral("time");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_DATE:
aName.AssignLiteral("date");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_GYEARMONTH:
aName.AssignLiteral("gYearMonth");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_GYEAR:
aName.AssignLiteral("gYear");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTHDAY:
aName.AssignLiteral("gMonthDay");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_GDAY:
aName.AssignLiteral("gDay");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTH:
aName.AssignLiteral("gMonth");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY:
aName.AssignLiteral("hexBinary");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY:
aName.AssignLiteral("base64Binary");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI:
aName.AssignLiteral("anyURI");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_QNAME:
aName.AssignLiteral("QName");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NOTATION:
aName.AssignLiteral("NOTATION");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING:
aName.AssignLiteral("normalizedString");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN:
aName.AssignLiteral("token");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_BYTE:
aName.AssignLiteral("byte");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDBYTE:
aName.AssignLiteral("unsignedByte");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER:
aName.AssignLiteral("integer");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NEGATIVEINTEGER:
aName.AssignLiteral("negativeInteger");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER:
aName.AssignLiteral("nonPositiveInteger");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_LONG:
aName.AssignLiteral("long");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER:
aName.AssignLiteral("nonNegativeInteger");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_INT:
aName.AssignLiteral("int");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT:
aName.AssignLiteral("unsignedInt");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG:
aName.AssignLiteral("unsignedLong");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER:
aName.AssignLiteral("positiveInteger");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_SHORT:
aName.AssignLiteral("short");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT:
aName.AssignLiteral("unsignedShort");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_LANGUAGE:
aName.AssignLiteral("language");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN:
aName.AssignLiteral("NMTOKEN");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NAME:
aName.AssignLiteral("Name");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME:
aName.AssignLiteral("NCName");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ID:
aName.AssignLiteral("ID");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREF:
aName.AssignLiteral("IDREF");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY:
aName.AssignLiteral("ENTITY");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREFS:
aName.AssignLiteral("IDREFS");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITIES:
aName.AssignLiteral("ENTITIES");
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKENS:
aName.AssignLiteral("NMTOKENS");
break;
default:
// should never hit here
NS_WARNING("nsXFormsModelElement::GetBuiltinTypeName: Unknown builtin type encountered.");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
nsXFormsModelElement::GetBuiltinTypesNames(PRUint16 aType,
nsStringArray *aNameArray)
{
// This function recursively appends aType (and its base types) to
// aNameArray. So it assumes aType isn't in the array already.
nsAutoString typeString, builtString;
PRUint16 parentType = 0;
// We won't append xsd:anyType as the base of every type since that is kinda
// redundant.
nsresult rv = GetBuiltinTypeName(aType, typeString);
NS_ENSURE_SUCCESS(rv, rv);
switch (aType) {
case nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_STRING;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_BYTE:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_SHORT;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDBYTE:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NEGATIVEINTEGER:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_LONG:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_INT:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_LONG;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_SHORT:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INT;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_LANGUAGE:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NAME:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NAME;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ID:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREF:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREFS:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_IDREF;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITIES:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKENS:
parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN;
break;
}
builtString.AppendLiteral(NS_NAMESPACE_XML_SCHEMA);
builtString.AppendLiteral("#");
builtString.Append(typeString);
aNameArray->AppendString(builtString);
if (parentType)
return GetBuiltinTypesNames(parentType, aNameArray);
return NS_OK;
}
nsresult
nsXFormsModelElement::WalkTypeChainInternal(nsISchemaType *aType,
PRBool aFindRootBuiltin,
PRUint16 *aBuiltinType,
nsStringArray *aTypeArray)
{
PRUint16 schemaTypeValue = 0;
aType->GetSchemaType(&schemaTypeValue);
NS_ENSURE_STATE(schemaTypeValue);
nsresult rv = NS_OK;
nsCOMPtr<nsISchemaSimpleType> simpleType;
if (schemaTypeValue == nsISchemaType::SCHEMA_TYPE_SIMPLE) {
simpleType = do_QueryInterface(aType);
NS_ENSURE_STATE(simpleType);
PRUint16 simpleTypeValue;
simpleType->GetSimpleType(&simpleTypeValue);
NS_ENSURE_STATE(simpleTypeValue);
switch (simpleTypeValue) {
case nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN:
{
nsCOMPtr<nsISchemaBuiltinType> builtinType(do_QueryInterface(aType));
NS_ENSURE_STATE(builtinType);
if (aFindRootBuiltin)
return BuiltinTypeToPrimative(builtinType, aBuiltinType);
PRUint16 builtinTypeVal;
rv = builtinType->GetBuiltinType(&builtinTypeVal);
NS_ENSURE_SUCCESS(rv, rv);
if (aBuiltinType)
*aBuiltinType = builtinTypeVal;
if (aTypeArray)
return GetBuiltinTypesNames(builtinTypeVal, aTypeArray);
return NS_OK;
}
case nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION:
{
nsCOMPtr<nsISchemaRestrictionType> restType(do_QueryInterface(aType));
NS_ENSURE_STATE(restType);
restType->GetBaseType(getter_AddRefs(simpleType));
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_LIST:
{
nsCOMPtr<nsISchemaListType> listType(do_QueryInterface(aType));
NS_ENSURE_STATE(listType);
listType->GetListType(getter_AddRefs(simpleType));
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_UNION:
{
// For now union types aren't supported. A union means that the type
// could be of any type listed in the union and still be valid. But we
// don't know which path it will take since we'd basically have to
// validate the node value to know. Someday we may have to figure out
// how to properly handle this, though we may never need to if no other
// processor supports it. Strictly interpreting the spec, we don't
// need to handle unions as far as determining whether a control can
// bind to data of a given type. Just the types defined in the spec
// and restrictions of those types.
return NS_ERROR_XFORMS_UNION_TYPE;
}
default:
// We only anticipate the 4 types listed above. Definitely an error
// if we get something else.
return NS_ERROR_FAILURE;
}
} else if (schemaTypeValue == nsISchemaType::SCHEMA_TYPE_COMPLEX) {
nsCOMPtr<nsISchemaComplexType> complexType(do_QueryInterface(aType));
NS_ENSURE_STATE(complexType);
PRUint16 complexTypeValue = 0;
complexType->GetDerivation(&complexTypeValue);
NS_ENSURE_STATE(complexTypeValue);
if ((complexTypeValue ==
nsISchemaComplexType::DERIVATION_RESTRICTION_SIMPLE) ||
(complexTypeValue ==
nsISchemaComplexType::DERIVATION_EXTENSION_SIMPLE)) {
complexType->GetSimpleBaseType(getter_AddRefs(simpleType));
} else {
return NS_ERROR_FAILURE;
}
} else {
return NS_ERROR_FAILURE;
}
// For SIMPLE_TYPE_LIST and SIMPLE_TYPE_RESTRICTION we need to go around
// the horn again with the next simpleType. Same with
// DERIVATION_RESTRICTION_SIMPLE and DERIVATION_EXTENSION_SIMPLE. All other
// types should not reach here.
NS_ENSURE_STATE(simpleType);
if (aTypeArray) {
nsAutoString builtString;
rv = aType->GetTargetNamespace(builtString);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString typeName;
rv = aType->GetName(typeName);
NS_ENSURE_SUCCESS(rv, rv);
builtString.AppendLiteral("#");
builtString.Append(typeName);
aTypeArray->AppendString(builtString);
}
return WalkTypeChainInternal(simpleType, aFindRootBuiltin, aBuiltinType,
aTypeArray);
}
nsresult
nsXFormsModelElement::BuiltinTypeToPrimative(nsISchemaBuiltinType *aSchemaType,
PRUint16 *aPrimType)
{
NS_ENSURE_ARG(aSchemaType);
NS_ENSURE_ARG_POINTER(aPrimType);
PRUint16 builtinType = 0;
nsresult rv = aSchemaType->GetBuiltinType(&builtinType);
NS_ENSURE_SUCCESS(rv, rv);
// Note: this won't return BUILTIN_TYPE_ANY since that is the root of all
// types.
switch (builtinType) {
case nsISchemaBuiltinType::BUILTIN_TYPE_STRING:
case nsISchemaBuiltinType::BUILTIN_TYPE_BOOLEAN:
case nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL:
case nsISchemaBuiltinType::BUILTIN_TYPE_FLOAT:
case nsISchemaBuiltinType::BUILTIN_TYPE_DOUBLE:
case nsISchemaBuiltinType::BUILTIN_TYPE_DURATION:
case nsISchemaBuiltinType::BUILTIN_TYPE_DATETIME:
case nsISchemaBuiltinType::BUILTIN_TYPE_TIME:
case nsISchemaBuiltinType::BUILTIN_TYPE_DATE:
case nsISchemaBuiltinType::BUILTIN_TYPE_GYEARMONTH:
case nsISchemaBuiltinType::BUILTIN_TYPE_GYEAR:
case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTHDAY:
case nsISchemaBuiltinType::BUILTIN_TYPE_GDAY:
case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTH:
case nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY:
case nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY:
case nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI:
case nsISchemaBuiltinType::BUILTIN_TYPE_QNAME:
case nsISchemaBuiltinType::BUILTIN_TYPE_NOTATION:
*aPrimType = builtinType;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING:
case nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN:
case nsISchemaBuiltinType::BUILTIN_TYPE_LANGUAGE:
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN:
case nsISchemaBuiltinType::BUILTIN_TYPE_NAME:
case nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME:
case nsISchemaBuiltinType::BUILTIN_TYPE_ID:
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREF:
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY:
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREFS:
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITIES:
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKENS:
*aPrimType = nsISchemaBuiltinType::BUILTIN_TYPE_STRING;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_BYTE:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDBYTE:
case nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_NEGATIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_LONG:
case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_INT:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG:
case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_SHORT:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT:
*aPrimType = nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL;
break;
default:
// should never hit here
NS_WARNING("nsXFormsModelElement::BuiltinTypeToPrimative: Unknown builtin type encountered.");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType,
const nsAString &aNamespace,
nsAString &aTypeList)
{
nsCOMPtr<nsISchemaCollection> schemaColl = do_QueryInterface(mSchemas);
NS_ENSURE_STATE(schemaColl);
nsCOMPtr<nsISchemaType> schemaType;
schemaColl->GetType(aType, aNamespace, getter_AddRefs(schemaType));
NS_ENSURE_STATE(schemaType);
nsStringArray typeArray;
nsresult rv = WalkTypeChainInternal(schemaType, PR_FALSE, nsnull, &typeArray);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIStringEnumerator> stringEnum;
rv = NS_NewStringEnumerator(getter_AddRefs(stringEnum), &typeArray);
if (NS_SUCCEEDED(rv)) {
nsAutoString constructorString;
PRBool hasMore = PR_FALSE;
rv = stringEnum->HasMore(&hasMore);
while (NS_SUCCEEDED(rv) && hasMore) {
nsAutoString tempString;
rv = stringEnum->GetNext(tempString);
if (NS_SUCCEEDED(rv)) {
constructorString.Append(tempString);
stringEnum->HasMore(&hasMore);
if (hasMore) {
constructorString.AppendLiteral(" ");
}
}
}
if (NS_SUCCEEDED(rv)) {
aTypeList.Assign(constructorString);
}
}
}
if (NS_FAILED(rv)) {
aTypeList.Assign(EmptyString());
}
typeArray.Clear();
return rv;
}
NS_IMETHODIMP
nsXFormsModelElement::GetBuiltinTypeNameForControl(nsIXFormsControl *aControl,
nsAString& aTypeName)
{
NS_ENSURE_ARG(aControl);
nsCOMPtr<nsISchemaType> schemaType;
nsresult rv = GetTypeForControl(aControl, getter_AddRefs(schemaType));
NS_ENSURE_SUCCESS(rv, rv);
PRUint16 builtinType;
rv = WalkTypeChainInternal(schemaType, PR_FALSE, &builtinType);
NS_ENSURE_SUCCESS(rv, rv);
return GetBuiltinTypeName(builtinType, aTypeName);
}
NS_IMETHODIMP
nsXFormsModelElement::GetRootBuiltinType(nsISchemaType *aType,
PRUint16 *aBuiltinType)
{
NS_ENSURE_ARG(aType);
NS_ENSURE_ARG_POINTER(aBuiltinType);
return WalkTypeChainInternal(aType, PR_TRUE, aBuiltinType);
}
/* static */ void
nsXFormsModelElement::Startup()
{
sModelPropsList[eModel_type] = nsXFormsAtoms::type;
sModelPropsList[eModel_readonly] = nsXFormsAtoms::readonly;
sModelPropsList[eModel_required] = nsXFormsAtoms::required;
sModelPropsList[eModel_relevant] = nsXFormsAtoms::relevant;
sModelPropsList[eModel_calculate] = nsXFormsAtoms::calculate;
sModelPropsList[eModel_constraint] = nsXFormsAtoms::constraint;
sModelPropsList[eModel_p3ptype] = nsXFormsAtoms::p3ptype;
}
already_AddRefed<nsIDOMElement>
nsXFormsModelElement::GetDOMElement()
{
nsIDOMElement* element = nsnull;
NS_IF_ADDREF(element = mElement);
return element;
}
static void
DeleteBindList(void *aObject,
nsIAtom *aPropertyName,
void *aPropertyValue,
void *aData)
{
delete NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *, aPropertyValue);
}
/* static */ nsresult
nsXFormsModelElement::DeferElementBind(nsIXFormsControl *aControl)
{
NS_ENSURE_ARG_POINTER(aControl);
nsCOMPtr<nsIDOMElement> element;
nsresult rv = aControl->GetElement(getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIContent> content(do_QueryInterface(element));
NS_ASSERTION(content, "nsIDOMElement not implementing nsIContent?!");
nsCOMPtr<nsIDocument> doc = content->GetCurrentDoc();
if (!doc) {
// We do not care about elements without a document. If they get added to
// a document at some point in time, they'll try to bind again.
return NS_OK;
}
// We are using a PRBool on each control to mark whether the control is on the
// deferredBindList. We are running into too many scenarios where a control
// could be added more than once which will lead to inefficiencies because
// calling bind and refresh on some controls is getting pretty expensive.
// We need to keep the document order of the controls AND don't want
// to walk the deferredBindList every time we want to check about adding a
// control.
PRBool onList = PR_FALSE;
aControl->GetOnDeferredBindList(&onList);
if (onList) {
return NS_OK;
}
nsCOMArray<nsIXFormsControl> *deferredBindList =
NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *,
doc->GetProperty(nsXFormsAtoms::deferredBindListProperty));
if (!deferredBindList) {
deferredBindList = new nsCOMArray<nsIXFormsControl>(16);
NS_ENSURE_TRUE(deferredBindList, NS_ERROR_OUT_OF_MEMORY);
doc->SetProperty(nsXFormsAtoms::deferredBindListProperty, deferredBindList,
DeleteBindList);
}
// always append to the end of the list. We need to keep the elements in
// document order when we process the binds later. Otherwise we have trouble
// when an element is trying to bind and should use its parent as a context
// for the xpath evaluation but the parent isn't bound yet.
deferredBindList->AppendObject(aControl);
aControl->SetOnDeferredBindList(PR_TRUE);
return NS_OK;
}
/* static */ void
nsXFormsModelElement::ProcessDeferredBinds(nsIDOMDocument *aDoc)
{
#ifdef DEBUG_MODEL
printf("nsXFormsModelElement::ProcessDeferredBinds()\n");
#endif
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
if (!doc) {
return;
}
nsPostRefresh postRefresh = nsPostRefresh();
doc->SetProperty(nsXFormsAtoms::readyForBindProperty, doc);
nsCOMArray<nsIXFormsControl> *deferredBindList =
NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *,
doc->GetProperty(nsXFormsAtoms::deferredBindListProperty));
if (deferredBindList) {
for (PRInt32 i = 0; i < deferredBindList->Count(); ++i) {
nsIXFormsControl *control = deferredBindList->ObjectAt(i);
if (control) {
control->BindToModel(PR_FALSE);
control->SetOnDeferredBindList(PR_FALSE);
}
}
doc->DeleteProperty(nsXFormsAtoms::deferredBindListProperty);
}
}
nsresult
nsXFormsModelElement::HandleLoad(nsIDOMEvent* aEvent)
{
if (!mInstancesInitialized) {
// XXX This is for Bug 308106. In Gecko 1.8 DoneAddingChildren is not
// called in XUL if the element doesn't have any child nodes.
InitializeInstances();
}
mDocumentLoaded = PR_TRUE;
nsCOMPtr<nsIDOMDocument> document;
mElement->GetOwnerDocument(getter_AddRefs(document));
NS_ENSURE_STATE(document);
nsXFormsUtils::DispatchDeferredEvents(document);
// dispatch xforms-model-construct, xforms-rebuild, xforms-recalculate,
// xforms-revalidate
// We wait until DOMContentLoaded to dispatch xforms-model-construct,
// since the model may have an action handler for this event and Mozilla
// doesn't register XML Event listeners until the document is loaded.
// xforms-model-construct is not cancellable, so always proceed.
nsXFormsUtils::DispatchEvent(mElement, eEvent_ModelConstruct);
if (mPendingInlineSchemas.Count() > 0) {
nsCOMPtr<nsIDOMElement> el;
nsresult rv = NS_OK;
for (PRInt32 i=0; i<mPendingInlineSchemas.Count(); ++i) {
GetSchemaElementById(mElement, *mPendingInlineSchemas[i],
getter_AddRefs(el));
if (!el) {
rv = NS_ERROR_UNEXPECTED;
} else {
// According to section 3.3.1 of the spec, more than one schema per
// namespace isn't allowed, but it also doesn't spell out very well
// what this means a processor should do about it. Since most
// processors ignore this rule and it isn't specifically a fatal error,
// we won't make this a failure here.
if (!IsDuplicateSchema(el)) {
nsCOMPtr<nsISchema> schema;
// no need to observe errors via the callback. instead, rely on
// this method returning a failure code when it encounters errors.
rv = mSchemas->ProcessSchemaElement(el, nsnull,
getter_AddRefs(schema));
if (NS_SUCCEEDED(rv))
mSchemaCount++;
}
}
if (NS_FAILED(rv)) {
// this is a fatal error
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaLoadError"), mElement);
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
return NS_OK;
}
}
if (IsComplete()) {
rv = FinishConstruction();
NS_ENSURE_SUCCESS(rv, rv);
}
mPendingInlineSchemas.Clear();
}
// We may still be waiting on external documents to load.
MaybeNotifyCompletion();
return NS_OK;
}
nsresult
nsXFormsModelElement::HandleUnload(nsIDOMEvent* aEvent)
{
// due to fastback changes, had to move this notification out from under
// model's WillChangeDocument override.
nsXFormsUtils::DispatchEvent(mElement, eEvent_ModelDestruct);
mSchemas = nsnull;
if (mInstanceDocuments)
mInstanceDocuments->DropReferences();
mFormControls.Clear();
mControlListHash.Clear();
return NS_OK;
}
PRBool
nsXFormsModelElement::IsDuplicateSchema(nsIDOMElement *aSchemaElement)
{
nsCOMPtr<nsISchemaCollection> schemaColl = do_QueryInterface(mSchemas);
if (!schemaColl)
return PR_FALSE;
const nsAFlatString& empty = EmptyString();
nsAutoString targetNamespace;
aSchemaElement->GetAttributeNS(empty,
NS_LITERAL_STRING("targetNamespace"),
targetNamespace);
targetNamespace.Trim(" \r\n\t");
nsCOMPtr<nsISchema> schema;
schemaColl->GetSchema(targetNamespace, getter_AddRefs(schema));
if (!schema)
return PR_FALSE;
// A schema with the same target namespace already exists in the
// schema collection and the first instance has already been processed.
// Report an error to the JS console and dispatch the LinkError event,
// but do not consider it a fatal error.
const nsPromiseFlatString& flat = PromiseFlatString(targetNamespace);
const PRUnichar *strings[] = { flat.get() };
nsXFormsUtils::ReportError(NS_LITERAL_STRING("duplicateSchema"),
strings, 1, aSchemaElement, aSchemaElement,
nsnull);
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkError);
return PR_TRUE;
}
nsresult
nsXFormsModelElement::SetContextInfo(const char *aName, const nsAString &aValue)
{
nsCOMPtr<nsXFormsContextInfo> contextInfo = new nsXFormsContextInfo(mElement);
NS_ENSURE_TRUE(contextInfo, NS_ERROR_OUT_OF_MEMORY);
contextInfo->SetStringValue(aName, aValue);
mContextInfo.AppendObject(contextInfo);
return NS_OK;
}
nsresult
NS_NewXFormsModelElement(nsIXTFElement **aResult)
{
*aResult = new nsXFormsModelElement();
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
return NS_OK;
}
// ---------------------------- //
// nsXFormsModelInstanceDocuments
NS_IMPL_ISUPPORTS2(nsXFormsModelInstanceDocuments, nsIDOMNodeList, nsIClassInfo)
nsXFormsModelInstanceDocuments::nsXFormsModelInstanceDocuments()
: mInstanceList(16)
{
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetLength(PRUint32* aLength)
{
*aLength = mInstanceList.Count();
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
*aReturn = nsnull;
nsIInstanceElementPrivate* instance = mInstanceList.SafeObjectAt(aIndex);
if (instance) {
nsCOMPtr<nsIDOMDocument> doc;
if (NS_SUCCEEDED(instance->GetInstanceDocument(getter_AddRefs(doc))) && doc) {
NS_ADDREF(*aReturn = doc);
}
}
return NS_OK;
}
nsIInstanceElementPrivate*
nsXFormsModelInstanceDocuments::GetInstanceAt(PRUint32 aIndex)
{
return mInstanceList.ObjectAt(aIndex);
}
void
nsXFormsModelInstanceDocuments::AddInstance(nsIInstanceElementPrivate *aInst)
{
// always append to the end of the list. We need to keep the elements in
// document order since the first instance element is the default instance
// document for the model.
mInstanceList.AppendObject(aInst);
}
void
nsXFormsModelInstanceDocuments::RemoveInstance(nsIInstanceElementPrivate *aInst)
{
mInstanceList.RemoveObject(aInst);
}
void
nsXFormsModelInstanceDocuments::DropReferences()
{
mInstanceList.Clear();
}
// nsIClassInfo implementation
static const nsIID sInstScriptingIIDs[] = {
NS_IDOMNODELIST_IID
};
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetInterfaces(PRUint32 *aCount,
nsIID * **aArray)
{
return
nsXFormsUtils::CloneScriptingInterfaces(sInstScriptingIIDs,
NS_ARRAY_LENGTH(sInstScriptingIIDs),
aCount, aArray);
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetHelperForLanguage(PRUint32 language,
nsISupports **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetContractID(char * *aContractID)
{
*aContractID = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetClassDescription(char * *aClassDescription)
{
*aClassDescription = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetClassID(nsCID * *aClassID)
{
*aClassID = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetImplementationLanguage(PRUint32 *aLang)
{
*aLang = nsIProgrammingLanguage::CPLUSPLUS;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetFlags(PRUint32 *aFlags)
{
*aFlags = nsIClassInfo::DOM_OBJECT;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelInstanceDocuments::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
{
return NS_ERROR_NOT_AVAILABLE;
}
|