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
|
/*
* Copyright (C) 2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "core/css/parser/BisonCSSParser.h"
#include "core/CSSValueKeywords.h"
#include "core/StylePropertyShorthand.h"
#include "core/css/CSSArrayFunctionValue.h"
#include "core/css/CSSAspectRatioValue.h"
#include "core/css/CSSBasicShapes.h"
#include "core/css/CSSBorderImage.h"
#include "core/css/CSSCanvasValue.h"
#include "core/css/CSSCrossfadeValue.h"
#include "core/css/CSSCursorImageValue.h"
#include "core/css/CSSFontFaceSrcValue.h"
#include "core/css/CSSFontFeatureValue.h"
#include "core/css/CSSFunctionValue.h"
#include "core/css/CSSGradientValue.h"
#include "core/css/CSSGridLineNamesValue.h"
#include "core/css/CSSGridTemplateAreasValue.h"
#include "core/css/CSSImageSetValue.h"
#include "core/css/CSSImageValue.h"
#include "core/css/CSSInheritedValue.h"
#include "core/css/CSSInitialValue.h"
#include "core/css/CSSKeyframeRule.h"
#include "core/css/CSSKeyframesRule.h"
#include "core/css/CSSLineBoxContainValue.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSPropertySourceData.h"
#include "core/css/CSSReflectValue.h"
#include "core/css/CSSSelector.h"
#include "core/css/CSSShadowValue.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/CSSTimingFunctionValue.h"
#include "core/css/CSSTransformValue.h"
#include "core/css/CSSUnicodeRangeValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/CSSValuePool.h"
#include "core/css/Counter.h"
#include "core/css/HashTools.h"
#include "core/css/MediaList.h"
#include "core/css/MediaQueryExp.h"
#include "core/css/Pair.h"
#include "core/css/Rect.h"
#include "core/css/StylePropertySet.h"
#include "core/css/StyleRule.h"
#include "core/css/StyleRuleImport.h"
#include "core/css/StyleSheetContents.h"
#include "core/css/parser/CSSParserIdioms.h"
#include "core/dom/Document.h"
#include "core/frame/FrameConsole.h"
#include "core/frame/FrameHost.h"
#include "core/frame/Settings.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/rendering/RenderTheme.h"
#include "platform/FloatConversion.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/BitArray.h"
#include "wtf/HexNumber.h"
#include "wtf/text/StringBuffer.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/text/StringImpl.h"
#include "wtf/text/TextEncoding.h"
#include <limits.h>
#define YYDEBUG 0
#if YYDEBUG > 0
extern int cssyydebug;
#endif
int cssyyparse(WebCore::BisonCSSParser*);
using namespace WTF;
namespace WebCore {
static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
BisonCSSParser::BisonCSSParser(const CSSParserContext& context)
: m_context(context)
, m_important(false)
, m_id(CSSPropertyInvalid)
, m_styleSheet(nullptr)
, m_supportsCondition(false)
, m_selectorListForParseSelector(0)
, m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
, m_hadSyntacticallyValidCSSRule(false)
, m_logErrors(false)
, m_ignoreErrors(false)
, m_defaultNamespace(starAtom)
, m_observer(0)
, m_source(0)
, m_ruleHeaderType(CSSRuleSourceData::UNKNOWN_RULE)
, m_allowImportRules(true)
, m_allowNamespaceDeclarations(true)
, m_inViewport(false)
, m_tokenizer(*this)
{
#if YYDEBUG > 0
cssyydebug = 1;
#endif
}
BisonCSSParser::~BisonCSSParser()
{
clearProperties();
deleteAllValues(m_floatingSelectors);
deleteAllValues(m_floatingSelectorVectors);
deleteAllValues(m_floatingValueLists);
deleteAllValues(m_floatingFunctions);
}
void BisonCSSParser::setupParser(const char* prefix, unsigned prefixLength, const String& string, const char* suffix, unsigned suffixLength)
{
m_tokenizer.setupTokenizer(prefix, prefixLength, string, suffix, suffixLength);
m_ruleHasHeader = true;
}
void BisonCSSParser::parseSheet(StyleSheetContents* sheet, const String& string, const TextPosition& startPosition, CSSParserObserver* observer, bool logErrors)
{
setStyleSheet(sheet);
m_defaultNamespace = starAtom; // Reset the default namespace.
TemporaryChange<CSSParserObserver*> scopedObsever(m_observer, observer);
m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL().isEmpty() && sheet->singleOwnerDocument()->frameHost();
m_ignoreErrors = false;
m_tokenizer.m_lineNumber = 0;
m_startPosition = startPosition;
m_source = &string;
m_tokenizer.m_internal = false;
setupParser("", string, "");
cssyyparse(this);
sheet->shrinkToFit();
m_source = 0;
m_rule = nullptr;
m_lineEndings.clear();
m_ignoreErrors = false;
m_logErrors = false;
m_tokenizer.m_internal = true;
}
PassRefPtrWillBeRawPtr<StyleRuleBase> BisonCSSParser::parseRule(StyleSheetContents* sheet, const String& string)
{
setStyleSheet(sheet);
m_allowNamespaceDeclarations = false;
setupParser("@-internal-rule ", string, "");
cssyyparse(this);
return m_rule.release();
}
PassRefPtrWillBeRawPtr<StyleKeyframe> BisonCSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
{
setStyleSheet(sheet);
setupParser("@-internal-keyframe-rule ", string, "");
cssyyparse(this);
return m_keyframe.release();
}
PassOwnPtr<Vector<double> > BisonCSSParser::parseKeyframeKeyList(const String& string)
{
setupParser("@-internal-keyframe-key-list ", string, "");
cssyyparse(this);
ASSERT(m_valueList);
return StyleKeyframe::createKeyList(m_valueList.get());
}
bool BisonCSSParser::parseSupportsCondition(const String& string)
{
m_supportsCondition = false;
setupParser("@-internal-supports-condition ", string, "");
cssyyparse(this);
return m_supportsCondition;
}
static inline bool isColorPropertyID(CSSPropertyID propertyId)
{
switch (propertyId) {
case CSSPropertyColor:
case CSSPropertyBackgroundColor:
case CSSPropertyBorderBottomColor:
case CSSPropertyBorderLeftColor:
case CSSPropertyBorderRightColor:
case CSSPropertyBorderTopColor:
case CSSPropertyOutlineColor:
case CSSPropertyTextLineThroughColor:
case CSSPropertyTextOverlineColor:
case CSSPropertyTextUnderlineColor:
case CSSPropertyWebkitBorderAfterColor:
case CSSPropertyWebkitBorderBeforeColor:
case CSSPropertyWebkitBorderEndColor:
case CSSPropertyWebkitBorderStartColor:
case CSSPropertyWebkitColumnRuleColor:
case CSSPropertyWebkitTextEmphasisColor:
case CSSPropertyWebkitTextFillColor:
case CSSPropertyWebkitTextStrokeColor:
return true;
case CSSPropertyTextDecorationColor:
return RuntimeEnabledFeatures::css3TextDecorationsEnabled();
default:
return false;
}
}
static bool parseColorValue(MutableStylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
{
ASSERT(!string.isEmpty());
bool quirksMode = isQuirksModeBehavior(cssParserMode);
if (!isColorPropertyID(propertyId))
return false;
CSSParserString cssString;
cssString.init(string);
CSSValueID valueID = cssValueKeywordID(cssString);
bool validPrimitive = false;
if (valueID == CSSValueWebkitText) {
validPrimitive = true;
} else if (valueID == CSSValueCurrentcolor) {
validPrimitive = true;
} else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu
|| (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText)) {
validPrimitive = true;
}
if (validPrimitive) {
RefPtrWillBeRawPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID);
declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
return true;
}
RGBA32 color;
if (!CSSPropertyParser::fastParseColor(color, string, !quirksMode && string[0] != '#'))
return false;
RefPtrWillBeRawPtr<CSSValue> value = cssValuePool().createColorValue(color);
declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
return true;
}
static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
{
switch (propertyId) {
case CSSPropertyFontSize:
case CSSPropertyHeight:
case CSSPropertyWidth:
case CSSPropertyMinHeight:
case CSSPropertyMinWidth:
case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft:
case CSSPropertyPaddingRight:
case CSSPropertyPaddingTop:
case CSSPropertyWebkitLogicalWidth:
case CSSPropertyWebkitLogicalHeight:
case CSSPropertyWebkitMinLogicalWidth:
case CSSPropertyWebkitMinLogicalHeight:
case CSSPropertyWebkitPaddingAfter:
case CSSPropertyWebkitPaddingBefore:
case CSSPropertyWebkitPaddingEnd:
case CSSPropertyWebkitPaddingStart:
acceptsNegativeNumbers = false;
return true;
case CSSPropertyShapeMargin:
acceptsNegativeNumbers = false;
return RuntimeEnabledFeatures::cssShapesEnabled();
case CSSPropertyBottom:
case CSSPropertyLeft:
case CSSPropertyMarginBottom:
case CSSPropertyMarginLeft:
case CSSPropertyMarginRight:
case CSSPropertyMarginTop:
case CSSPropertyRight:
case CSSPropertyTop:
case CSSPropertyWebkitMarginAfter:
case CSSPropertyWebkitMarginBefore:
case CSSPropertyWebkitMarginEnd:
case CSSPropertyWebkitMarginStart:
acceptsNegativeNumbers = true;
return true;
default:
return false;
}
}
template <typename CharacterType>
static inline bool parseSimpleLength(const CharacterType* characters, unsigned length, CSSPrimitiveValue::UnitType& unit, double& number)
{
if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
length -= 2;
unit = CSSPrimitiveValue::CSS_PX;
} else if (length > 1 && characters[length - 1] == '%') {
length -= 1;
unit = CSSPrimitiveValue::CSS_PERCENTAGE;
}
// We rely on charactersToDouble for validation as well. The function
// will set "ok" to "false" if the entire passed-in character range does
// not represent a double.
bool ok;
number = charactersToDouble(characters, length, &ok);
return ok;
}
static bool parseSimpleLengthValue(MutableStylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
{
ASSERT(!string.isEmpty());
bool acceptsNegativeNumbers = false;
// In @viewport, width and height are shorthands, not simple length values.
if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
return false;
unsigned length = string.length();
double number;
CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::CSS_NUMBER;
if (string.is8Bit()) {
if (!parseSimpleLength(string.characters8(), length, unit, number))
return false;
} else {
if (!parseSimpleLength(string.characters16(), length, unit, number))
return false;
}
if (unit == CSSPrimitiveValue::CSS_NUMBER) {
bool quirksMode = isQuirksModeBehavior(cssParserMode);
if (number && !quirksMode)
return false;
unit = CSSPrimitiveValue::CSS_PX;
}
if (number < 0 && !acceptsNegativeNumbers)
return false;
RefPtrWillBeRawPtr<CSSValue> value = cssValuePool().createValue(number, unit);
declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
return true;
}
bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, CSSValueID valueID, const CSSParserContext& parserContext)
{
if (valueID == CSSValueInvalid)
return false;
switch (propertyId) {
case CSSPropertyBackgroundRepeatX: // repeat | no-repeat
case CSSPropertyBackgroundRepeatY: // repeat | no-repeat
return valueID == CSSValueRepeat || valueID == CSSValueNoRepeat;
case CSSPropertyBorderCollapse: // collapse | separate
return valueID == CSSValueCollapse || valueID == CSSValueSeparate;
case CSSPropertyBorderTopStyle: // <border-style>
case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
case CSSPropertyBorderLeftStyle:
case CSSPropertyWebkitBorderAfterStyle:
case CSSPropertyWebkitBorderBeforeStyle:
case CSSPropertyWebkitBorderEndStyle:
case CSSPropertyWebkitBorderStartStyle:
case CSSPropertyWebkitColumnRuleStyle:
return valueID >= CSSValueNone && valueID <= CSSValueDouble;
case CSSPropertyBoxSizing:
return valueID == CSSValueBorderBox || valueID == CSSValueContentBox;
case CSSPropertyCaptionSide: // top | bottom | left | right
return valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom;
case CSSPropertyClear: // none | left | right | both
return valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth;
case CSSPropertyDirection: // ltr | rtl
return valueID == CSSValueLtr || valueID == CSSValueRtl;
case CSSPropertyDisplay:
// inline | block | list-item | inline-block | table |
// inline-table | table-row-group | table-header-group | table-footer-group | table-row |
// table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none
// flex | inline-flex | -webkit-flex | -webkit-inline-flex | grid | inline-grid | lazy-block
return (valueID >= CSSValueInline && valueID <= CSSValueInlineFlex) || valueID == CSSValueWebkitFlex || valueID == CSSValueWebkitInlineFlex || valueID == CSSValueNone
|| (RuntimeEnabledFeatures::cssGridLayoutEnabled() && (valueID == CSSValueGrid || valueID == CSSValueInlineGrid));
case CSSPropertyEmptyCells: // show | hide
return valueID == CSSValueShow || valueID == CSSValueHide;
case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
return valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter;
case CSSPropertyFontStyle: // normal | italic | oblique
return valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique;
case CSSPropertyImageRendering: // auto | optimizeContrast
return valueID == CSSValueAuto || valueID == CSSValueWebkitOptimizeContrast;
case CSSPropertyIsolation: // auto | isolate
return RuntimeEnabledFeatures::cssCompositingEnabled()
&& (valueID == CSSValueAuto || valueID == CSSValueIsolate);
case CSSPropertyListStylePosition: // inside | outside
return valueID == CSSValueInside || valueID == CSSValueOutside;
case CSSPropertyListStyleType:
// See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
// for the list of supported list-style-types.
return (valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone;
case CSSPropertyObjectFit:
return RuntimeEnabledFeatures::objectFitPositionEnabled()
&& (valueID == CSSValueFill || valueID == CSSValueContain || valueID == CSSValueCover || valueID == CSSValueNone || valueID == CSSValueScaleDown);
case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto
return valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble);
case CSSPropertyOverflowWrap: // normal | break-word
case CSSPropertyWordWrap:
return valueID == CSSValueNormal || valueID == CSSValueBreakWord;
case CSSPropertyOverflowX: // visible | hidden | scroll | auto | overlay
return valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay;
case CSSPropertyOverflowY: // visible | hidden | scroll | auto | overlay | -webkit-paged-x | -webkit-paged-y
return valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitPagedX || valueID == CSSValueWebkitPagedY;
case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right
case CSSPropertyPageBreakBefore:
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
return valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight;
case CSSPropertyPageBreakInside: // avoid | auto
case CSSPropertyWebkitColumnBreakInside:
return valueID == CSSValueAuto || valueID == CSSValueAvoid;
case CSSPropertyPointerEvents:
// none | visiblePainted | visibleFill | visibleStroke | visible |
// painted | fill | stroke | auto | all | bounding-box
return valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueBoundingBox);
case CSSPropertyPosition: // static | relative | absolute | fixed | sticky
return valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed
|| (RuntimeEnabledFeatures::cssStickyPositionEnabled() && valueID == CSSValueSticky);
case CSSPropertyResize: // none | both | horizontal | vertical | auto
return valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto;
case CSSPropertyScrollBehavior: // instant | smooth
return RuntimeEnabledFeatures::cssomSmoothScrollEnabled()
&& (valueID == CSSValueInstant || valueID == CSSValueSmooth);
case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation
return valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation;
case CSSPropertyTableLayout: // auto | fixed
return valueID == CSSValueAuto || valueID == CSSValueFixed;
case CSSPropertyTextAlignLast:
// auto | start | end | left | right | center | justify
return RuntimeEnabledFeatures::css3TextEnabled()
&& ((valueID >= CSSValueLeft && valueID <= CSSValueJustify) || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueAuto);
case CSSPropertyTextJustify:
// auto | none | inter-word | distribute
return RuntimeEnabledFeatures::css3TextEnabled()
&& (valueID == CSSValueInterWord || valueID == CSSValueDistribute || valueID == CSSValueAuto || valueID == CSSValueNone);
case CSSPropertyTextLineThroughMode:
case CSSPropertyTextOverlineMode:
case CSSPropertyTextUnderlineMode:
return valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace;
case CSSPropertyTextLineThroughStyle:
case CSSPropertyTextOverlineStyle:
case CSSPropertyTextUnderlineStyle:
return valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave;
case CSSPropertyTextOverflow: // clip | ellipsis
return valueID == CSSValueClip || valueID == CSSValueEllipsis;
case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
return valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision;
case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none
return (valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone;
case CSSPropertyTouchActionDelay: // none | script
return RuntimeEnabledFeatures::cssTouchActionDelayEnabled()
&& (valueID == CSSValueScript || valueID == CSSValueNone);
case CSSPropertyVisibility: // visible | hidden | collapse
return valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse;
case CSSPropertyWebkitAppearance:
return (valueID >= CSSValueCheckbox && valueID <= CSSValueTextarea) || valueID == CSSValueNone;
case CSSPropertyBackfaceVisibility:
case CSSPropertyWebkitBackfaceVisibility:
return valueID == CSSValueVisible || valueID == CSSValueHidden;
case CSSPropertyMixBlendMode:
return RuntimeEnabledFeatures::cssCompositingEnabled()
&& (valueID == CSSValueNormal || valueID == CSSValueMultiply || valueID == CSSValueScreen || valueID == CSSValueOverlay
|| valueID == CSSValueDarken || valueID == CSSValueLighten || valueID == CSSValueColorDodge || valueID == CSSValueColorBurn
|| valueID == CSSValueHardLight || valueID == CSSValueSoftLight || valueID == CSSValueDifference || valueID == CSSValueExclusion
|| valueID == CSSValueHue || valueID == CSSValueSaturation || valueID == CSSValueColor || valueID == CSSValueLuminosity);
case CSSPropertyWebkitBorderFit:
return valueID == CSSValueBorder || valueID == CSSValueLines;
case CSSPropertyWebkitBoxAlign:
return valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline;
case CSSPropertyWebkitBoxDecorationBreak:
return valueID == CSSValueClone || valueID == CSSValueSlice;
case CSSPropertyWebkitBoxDirection:
return valueID == CSSValueNormal || valueID == CSSValueReverse;
case CSSPropertyWebkitBoxLines:
return valueID == CSSValueSingle || valueID == CSSValueMultiple;
case CSSPropertyWebkitBoxOrient:
return valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis;
case CSSPropertyWebkitBoxPack:
return valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify;
case CSSPropertyInternalCallback:
// This property is only injected programmatically, not parsed from stylesheets.
return false;
case CSSPropertyColumnFill:
return RuntimeEnabledFeatures::regionBasedColumnsEnabled()
&& (valueID == CSSValueAuto || valueID == CSSValueBalance);
case CSSPropertyAlignContent:
// FIXME: Per CSS alignment, this property should accept an optional <overflow-position>. We should share this parsing code with 'justify-self'.
return valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround || valueID == CSSValueStretch;
case CSSPropertyAlignItems:
// FIXME: Per CSS alignment, this property should accept the same arguments as 'justify-self' so we should share its parsing code.
return valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch;
case CSSPropertyAlignSelf:
// FIXME: Per CSS alignment, this property should accept the same arguments as 'justify-self' so we should share its parsing code.
return valueID == CSSValueAuto || valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch;
case CSSPropertyFlexDirection:
return valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse;
case CSSPropertyFlexWrap:
return valueID == CSSValueNowrap || valueID == CSSValueWrap || valueID == CSSValueWrapReverse;
case CSSPropertyJustifyContent:
// FIXME: Per CSS alignment, this property should accept an optional <overflow-position>. We should share this parsing code with 'justify-self'.
return valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround;
case CSSPropertyFontKerning:
return valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone;
case CSSPropertyWebkitFontSmoothing:
return valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased;
case CSSPropertyGridAutoFlow:
return RuntimeEnabledFeatures::cssGridLayoutEnabled()
&& (valueID == CSSValueNone || valueID == CSSValueRow || valueID == CSSValueColumn);
case CSSPropertyWebkitLineBreak: // auto | loose | normal | strict | after-white-space
return valueID == CSSValueAuto || valueID == CSSValueLoose || valueID == CSSValueNormal || valueID == CSSValueStrict || valueID == CSSValueAfterWhiteSpace;
case CSSPropertyWebkitMarginAfterCollapse:
case CSSPropertyWebkitMarginBeforeCollapse:
case CSSPropertyWebkitMarginBottomCollapse:
case CSSPropertyWebkitMarginTopCollapse:
return valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard;
case CSSPropertyInternalMarqueeDirection:
return valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
|| valueID == CSSValueUp || valueID == CSSValueAuto;
case CSSPropertyInternalMarqueeStyle:
return valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate;
case CSSPropertyWebkitPrintColorAdjust:
return valueID == CSSValueExact || valueID == CSSValueEconomy;
case CSSPropertyWebkitRtlOrdering:
return valueID == CSSValueLogical || valueID == CSSValueVisual;
case CSSPropertyWebkitRubyPosition:
return valueID == CSSValueBefore || valueID == CSSValueAfter;
case CSSPropertyWebkitTextCombine:
return valueID == CSSValueNone || valueID == CSSValueHorizontal;
case CSSPropertyWebkitTextEmphasisPosition:
return valueID == CSSValueOver || valueID == CSSValueUnder;
case CSSPropertyWebkitTextSecurity: // disc | circle | square | none
return valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone;
case CSSPropertyTransformStyle:
case CSSPropertyWebkitTransformStyle:
return valueID == CSSValueFlat || valueID == CSSValuePreserve3d;
case CSSPropertyWebkitUserDrag: // auto | none | element
return valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement;
case CSSPropertyWebkitUserModify: // read-only | read-write
return valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly;
case CSSPropertyWebkitUserSelect: // auto | none | text | all
return valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText || valueID == CSSValueAll;
case CSSPropertyWebkitWrapFlow:
return RuntimeEnabledFeatures::cssExclusionsEnabled()
&& (valueID == CSSValueAuto || valueID == CSSValueBoth || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueMaximum || valueID == CSSValueClear);
case CSSPropertyWebkitWrapThrough:
return RuntimeEnabledFeatures::cssExclusionsEnabled()
&& (valueID == CSSValueWrap || valueID == CSSValueNone);
case CSSPropertyWebkitWritingMode:
return valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt;
case CSSPropertyWhiteSpace: // normal | pre | nowrap
return valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap;
case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
return valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueBreakWord;
default:
ASSERT_NOT_REACHED();
return false;
}
return false;
}
bool isKeywordPropertyID(CSSPropertyID propertyId)
{
switch (propertyId) {
case CSSPropertyMixBlendMode:
case CSSPropertyIsolation:
case CSSPropertyBackgroundRepeatX:
case CSSPropertyBackgroundRepeatY:
case CSSPropertyBorderBottomStyle:
case CSSPropertyBorderCollapse:
case CSSPropertyBorderLeftStyle:
case CSSPropertyBorderRightStyle:
case CSSPropertyBorderTopStyle:
case CSSPropertyBoxSizing:
case CSSPropertyCaptionSide:
case CSSPropertyClear:
case CSSPropertyDirection:
case CSSPropertyDisplay:
case CSSPropertyEmptyCells:
case CSSPropertyFloat:
case CSSPropertyFontStyle:
case CSSPropertyImageRendering:
case CSSPropertyListStylePosition:
case CSSPropertyListStyleType:
case CSSPropertyObjectFit:
case CSSPropertyOutlineStyle:
case CSSPropertyOverflowWrap:
case CSSPropertyOverflowX:
case CSSPropertyOverflowY:
case CSSPropertyPageBreakAfter:
case CSSPropertyPageBreakBefore:
case CSSPropertyPageBreakInside:
case CSSPropertyPointerEvents:
case CSSPropertyPosition:
case CSSPropertyResize:
case CSSPropertyScrollBehavior:
case CSSPropertySpeak:
case CSSPropertyTableLayout:
case CSSPropertyTextAlignLast:
case CSSPropertyTextJustify:
case CSSPropertyTextLineThroughMode:
case CSSPropertyTextLineThroughStyle:
case CSSPropertyTextOverflow:
case CSSPropertyTextOverlineMode:
case CSSPropertyTextOverlineStyle:
case CSSPropertyTextRendering:
case CSSPropertyTextTransform:
case CSSPropertyTextUnderlineMode:
case CSSPropertyTextUnderlineStyle:
case CSSPropertyTouchActionDelay:
case CSSPropertyVisibility:
case CSSPropertyWebkitAppearance:
case CSSPropertyBackfaceVisibility:
case CSSPropertyWebkitBackfaceVisibility:
case CSSPropertyWebkitBorderAfterStyle:
case CSSPropertyWebkitBorderBeforeStyle:
case CSSPropertyWebkitBorderEndStyle:
case CSSPropertyWebkitBorderFit:
case CSSPropertyWebkitBorderStartStyle:
case CSSPropertyWebkitBoxAlign:
case CSSPropertyWebkitBoxDecorationBreak:
case CSSPropertyWebkitBoxDirection:
case CSSPropertyWebkitBoxLines:
case CSSPropertyWebkitBoxOrient:
case CSSPropertyWebkitBoxPack:
case CSSPropertyInternalCallback:
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
case CSSPropertyWebkitColumnBreakInside:
case CSSPropertyColumnFill:
case CSSPropertyWebkitColumnRuleStyle:
case CSSPropertyAlignContent:
case CSSPropertyFlexDirection:
case CSSPropertyFlexWrap:
case CSSPropertyJustifyContent:
case CSSPropertyFontKerning:
case CSSPropertyWebkitFontSmoothing:
case CSSPropertyGridAutoFlow:
case CSSPropertyWebkitLineBreak:
case CSSPropertyWebkitMarginAfterCollapse:
case CSSPropertyWebkitMarginBeforeCollapse:
case CSSPropertyWebkitMarginBottomCollapse:
case CSSPropertyWebkitMarginTopCollapse:
case CSSPropertyInternalMarqueeDirection:
case CSSPropertyInternalMarqueeStyle:
case CSSPropertyWebkitPrintColorAdjust:
case CSSPropertyWebkitRtlOrdering:
case CSSPropertyWebkitRubyPosition:
case CSSPropertyWebkitTextCombine:
case CSSPropertyWebkitTextEmphasisPosition:
case CSSPropertyWebkitTextSecurity:
case CSSPropertyTransformStyle:
case CSSPropertyWebkitTransformStyle:
case CSSPropertyWebkitUserDrag:
case CSSPropertyWebkitUserModify:
case CSSPropertyWebkitUserSelect:
case CSSPropertyWebkitWrapFlow:
case CSSPropertyWebkitWrapThrough:
case CSSPropertyWebkitWritingMode:
case CSSPropertyWhiteSpace:
case CSSPropertyWordBreak:
case CSSPropertyWordWrap:
return true;
case CSSPropertyAlignItems:
case CSSPropertyAlignSelf:
return !RuntimeEnabledFeatures::cssGridLayoutEnabled();
default:
return false;
}
}
static bool parseKeywordValue(MutableStylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext)
{
ASSERT(!string.isEmpty());
if (!isKeywordPropertyID(propertyId)) {
// All properties accept the values of "initial" and "inherit".
String lowerCaseString = string.lower();
if (lowerCaseString != "initial" && lowerCaseString != "inherit")
return false;
// Parse initial/inherit shorthands using the BisonCSSParser.
if (shorthandForProperty(propertyId).length())
return false;
}
CSSParserString cssString;
cssString.init(string);
CSSValueID valueID = cssValueKeywordID(cssString);
if (!valueID)
return false;
RefPtrWillBeRawPtr<CSSValue> value = nullptr;
if (valueID == CSSValueInherit)
value = cssValuePool().createInheritedValue();
else if (valueID == CSSValueInitial)
value = cssValuePool().createExplicitInitialValue();
else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext))
value = cssValuePool().createIdentifierValue(valueID);
else
return false;
declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
return true;
}
template <typename CharType>
static bool parseTransformTranslateArguments(CharType*& pos, CharType* end, unsigned expectedCount, CSSTransformValue* transformValue)
{
while (expectedCount) {
size_t delimiter = WTF::find(pos, end - pos, expectedCount == 1 ? ')' : ',');
if (delimiter == kNotFound)
return false;
unsigned argumentLength = static_cast<unsigned>(delimiter);
CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::CSS_NUMBER;
double number;
if (!parseSimpleLength(pos, argumentLength, unit, number))
return false;
if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
return false;
transformValue->append(cssValuePool().createValue(number, CSSPrimitiveValue::CSS_PX));
pos += argumentLength + 1;
--expectedCount;
}
return true;
}
template <typename CharType>
static bool parseTransformNumberArguments(CharType*& pos, CharType* end, unsigned expectedCount, CSSTransformValue* transformValue)
{
while (expectedCount) {
size_t delimiter = WTF::find(pos, end - pos, expectedCount == 1 ? ')' : ',');
if (delimiter == kNotFound)
return false;
unsigned argumentLength = static_cast<unsigned>(delimiter);
bool ok;
double number = charactersToDouble(pos, argumentLength, &ok);
if (!ok)
return false;
transformValue->append(cssValuePool().createValue(number, CSSPrimitiveValue::CSS_NUMBER));
pos += argumentLength + 1;
--expectedCount;
}
return true;
}
template <typename CharType>
static PassRefPtrWillBeRawPtr<CSSTransformValue> parseSimpleTransformValue(CharType*& pos, CharType* end)
{
static const int shortestValidTransformStringLength = 12;
if (end - pos < shortestValidTransformStringLength)
return nullptr;
const bool isTranslate = toASCIILower(pos[0]) == 't'
&& toASCIILower(pos[1]) == 'r'
&& toASCIILower(pos[2]) == 'a'
&& toASCIILower(pos[3]) == 'n'
&& toASCIILower(pos[4]) == 's'
&& toASCIILower(pos[5]) == 'l'
&& toASCIILower(pos[6]) == 'a'
&& toASCIILower(pos[7]) == 't'
&& toASCIILower(pos[8]) == 'e';
if (isTranslate) {
CSSTransformValue::TransformOperationType transformType;
unsigned expectedArgumentCount = 1;
unsigned argumentStart = 11;
CharType c9 = toASCIILower(pos[9]);
if (c9 == 'x' && pos[10] == '(') {
transformType = CSSTransformValue::TranslateXTransformOperation;
} else if (c9 == 'y' && pos[10] == '(') {
transformType = CSSTransformValue::TranslateYTransformOperation;
} else if (c9 == 'z' && pos[10] == '(') {
transformType = CSSTransformValue::TranslateZTransformOperation;
} else if (c9 == '(') {
transformType = CSSTransformValue::TranslateTransformOperation;
expectedArgumentCount = 2;
argumentStart = 10;
} else if (c9 == '3' && toASCIILower(pos[10]) == 'd' && pos[11] == '(') {
transformType = CSSTransformValue::Translate3DTransformOperation;
expectedArgumentCount = 3;
argumentStart = 12;
} else {
return nullptr;
}
pos += argumentStart;
RefPtrWillBeRawPtr<CSSTransformValue> transformValue = CSSTransformValue::create(transformType);
if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, transformValue.get()))
return nullptr;
return transformValue.release();
}
const bool isMatrix3d = toASCIILower(pos[0]) == 'm'
&& toASCIILower(pos[1]) == 'a'
&& toASCIILower(pos[2]) == 't'
&& toASCIILower(pos[3]) == 'r'
&& toASCIILower(pos[4]) == 'i'
&& toASCIILower(pos[5]) == 'x'
&& pos[6] == '3'
&& toASCIILower(pos[7]) == 'd'
&& pos[8] == '(';
if (isMatrix3d) {
pos += 9;
RefPtrWillBeRawPtr<CSSTransformValue> transformValue = CSSTransformValue::create(CSSTransformValue::Matrix3DTransformOperation);
if (!parseTransformNumberArguments(pos, end, 16, transformValue.get()))
return nullptr;
return transformValue.release();
}
const bool isScale3d = toASCIILower(pos[0]) == 's'
&& toASCIILower(pos[1]) == 'c'
&& toASCIILower(pos[2]) == 'a'
&& toASCIILower(pos[3]) == 'l'
&& toASCIILower(pos[4]) == 'e'
&& pos[5] == '3'
&& toASCIILower(pos[6]) == 'd'
&& pos[7] == '(';
if (isScale3d) {
pos += 8;
RefPtrWillBeRawPtr<CSSTransformValue> transformValue = CSSTransformValue::create(CSSTransformValue::Scale3DTransformOperation);
if (!parseTransformNumberArguments(pos, end, 3, transformValue.get()))
return nullptr;
return transformValue.release();
}
return nullptr;
}
template <typename CharType>
static PassRefPtrWillBeRawPtr<CSSValueList> parseSimpleTransformList(CharType*& pos, CharType* end)
{
RefPtrWillBeRawPtr<CSSValueList> transformList = nullptr;
while (pos < end) {
while (pos < end && isCSSSpace(*pos))
++pos;
RefPtrWillBeRawPtr<CSSTransformValue> transformValue = parseSimpleTransformValue(pos, end);
if (!transformValue)
return nullptr;
if (!transformList)
transformList = CSSValueList::createSpaceSeparated();
transformList->append(transformValue.release());
if (pos < end) {
if (isCSSSpace(*pos))
return nullptr;
}
}
return transformList.release();
}
static bool parseSimpleTransform(MutableStylePropertySet* properties, CSSPropertyID propertyID, const String& string, bool important)
{
if (propertyID != CSSPropertyTransform && propertyID != CSSPropertyWebkitTransform)
return false;
if (string.isEmpty())
return false;
RefPtrWillBeRawPtr<CSSValueList> transformList = nullptr;
if (string.is8Bit()) {
const LChar* pos = string.characters8();
const LChar* end = pos + string.length();
transformList = parseSimpleTransformList(pos, end);
if (!transformList)
return false;
} else {
const UChar* pos = string.characters16();
const UChar* end = pos + string.length();
transformList = parseSimpleTransformList(pos, end);
if (!transformList)
return false;
}
properties->addParsedProperty(CSSProperty(propertyID, transformList.release(), important));
return true;
}
PassRefPtrWillBeRawPtr<CSSValueList> BisonCSSParser::parseFontFaceValue(const AtomicString& string)
{
if (string.isEmpty())
return nullptr;
RefPtrWillBeRawPtr<MutableStylePropertySet> dummyStyle = MutableStylePropertySet::create();
if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, HTMLQuirksMode, 0))
return nullptr;
RefPtrWillBeRawPtr<CSSValue> fontFamily = dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily);
if (!fontFamily->isValueList())
return nullptr;
return toCSSValueList(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily).get());
}
PassRefPtrWillBeRawPtr<CSSValue> BisonCSSParser::parseAnimationTimingFunctionValue(const String& string)
{
if (string.isEmpty())
return nullptr;
RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
if (!parseValue(style.get(), CSSPropertyTransitionTimingFunction, string, false, HTMLStandardMode, 0))
return nullptr;
RefPtrWillBeRawPtr<CSSValue> value = style->getPropertyCSSValue(CSSPropertyTransitionTimingFunction);
if (!value || value->isInitialValue() || value->isInheritedValue())
return nullptr;
CSSValueList* valueList = toCSSValueList(value.get());
if (valueList->length() > 1)
return nullptr;
return valueList->item(0);
}
bool BisonCSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, const Document& document)
{
ASSERT(!string.isEmpty());
CSSParserContext context(document, UseCounter::getFrom(&document));
if (parseSimpleLengthValue(declaration, propertyID, string, important, context.mode()))
return true;
if (parseColorValue(declaration, propertyID, string, important, context.mode()))
return true;
if (parseKeywordValue(declaration, propertyID, string, important, context))
return true;
BisonCSSParser parser(context);
return parser.parseValue(declaration, propertyID, string, important, static_cast<StyleSheetContents*>(0));
}
bool BisonCSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
{
ASSERT(!string.isEmpty());
if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
return true;
if (parseColorValue(declaration, propertyID, string, important, cssParserMode))
return true;
CSSParserContext context(cssParserMode, 0);
if (contextStyleSheet) {
context = contextStyleSheet->parserContext();
context.setMode(cssParserMode);
}
if (parseKeywordValue(declaration, propertyID, string, important, context))
return true;
if (parseSimpleTransform(declaration, propertyID, string, important))
return true;
BisonCSSParser parser(context);
return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
}
bool BisonCSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
{
// FIXME: Check RuntimeCSSEnabled::isPropertyEnabled or isValueEnabledForProperty.
if (m_context.useCounter())
m_context.useCounter()->count(m_context, propertyID);
setStyleSheet(contextStyleSheet);
setupParser("@-internal-value ", string, "");
m_id = propertyID;
m_important = important;
{
StyleDeclarationScope scope(this, declaration);
cssyyparse(this);
}
m_rule = nullptr;
m_id = CSSPropertyInvalid;
bool ok = false;
if (!m_parsedProperties.isEmpty()) {
ok = true;
declaration->addParsedProperties(m_parsedProperties);
clearProperties();
}
return ok;
}
// The color will only be changed when string contains a valid CSS color, so callers
// can set it to a default color and ignore the boolean result.
bool BisonCSSParser::parseColor(RGBA32& color, const String& string, bool strict)
{
// First try creating a color specified by name, rgba(), rgb() or "#" syntax.
if (CSSPropertyParser::fastParseColor(color, string, strict))
return true;
BisonCSSParser parser(strictCSSParserContext());
// In case the fast-path parser didn't understand the color, try the full parser.
if (!parser.parseColor(string))
return false;
CSSValue* value = parser.m_parsedProperties.first().value();
if (!value->isPrimitiveValue())
return false;
CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
if (!primitiveValue->isRGBColor())
return false;
color = primitiveValue->getRGBA32Value();
return true;
}
bool BisonCSSParser::parseColor(const String& string)
{
setupParser("@-internal-decls color:", string, "");
cssyyparse(this);
m_rule = nullptr;
return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
}
bool BisonCSSParser::parseSystemColor(RGBA32& color, const String& string)
{
CSSParserString cssColor;
cssColor.init(string);
CSSValueID id = cssValueKeywordID(cssColor);
if (!CSSPropertyParser::isSystemColor(id))
return false;
Color parsedColor = RenderTheme::theme().systemColor(id);
color = parsedColor.rgb();
return true;
}
void BisonCSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
{
m_selectorListForParseSelector = &selectorList;
setupParser("@-internal-selector ", string, "");
cssyyparse(this);
m_selectorListForParseSelector = 0;
}
PassRefPtr<ImmutableStylePropertySet> BisonCSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
{
Document& document = element->document();
CSSParserContext context = CSSParserContext(document.elementSheet().contents()->parserContext(), UseCounter::getFrom(&document));
context.setMode((element->isHTMLElement() && !document.inQuirksMode()) ? HTMLStandardMode : HTMLQuirksMode);
return BisonCSSParser(context).parseDeclaration(string, document.elementSheet().contents());
}
PassRefPtr<ImmutableStylePropertySet> BisonCSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
{
setStyleSheet(contextStyleSheet);
setupParser("@-internal-decls ", string, "");
cssyyparse(this);
m_rule = nullptr;
RefPtr<ImmutableStylePropertySet> style = createStylePropertySet();
clearProperties();
return style.release();
}
bool BisonCSSParser::parseDeclaration(MutableStylePropertySet* declaration, const String& string, CSSParserObserver* observer, StyleSheetContents* contextStyleSheet)
{
setStyleSheet(contextStyleSheet);
TemporaryChange<CSSParserObserver*> scopedObsever(m_observer, observer);
setupParser("@-internal-decls ", string, "");
if (m_observer) {
m_observer->startRuleHeader(CSSRuleSourceData::STYLE_RULE, 0);
m_observer->endRuleHeader(1);
m_observer->startRuleBody(0);
}
{
StyleDeclarationScope scope(this, declaration);
cssyyparse(this);
}
m_rule = nullptr;
bool ok = false;
if (!m_parsedProperties.isEmpty()) {
ok = true;
declaration->addParsedProperties(m_parsedProperties);
clearProperties();
}
if (m_observer)
m_observer->endRuleBody(string.length(), false);
return ok;
}
PassRefPtrWillBeRawPtr<MediaQuerySet> BisonCSSParser::parseMediaQueryList(const String& string)
{
ASSERT(!m_mediaList);
// can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
// instead insert one " " (which is caught by maybe_space in CSSGrammar.y)
setupParser("@-internal-medialist ", string, "");
cssyyparse(this);
ASSERT(m_mediaList);
return m_mediaList.release();
}
static inline void filterProperties(bool important, const WillBeHeapVector<CSSProperty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
{
// Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
for (int i = input.size() - 1; i >= 0; --i) {
const CSSProperty& property = input[i];
if (property.isImportant() != important)
continue;
const unsigned propertyIDIndex = property.id() - firstCSSProperty;
if (seenProperties.get(propertyIDIndex))
continue;
seenProperties.set(propertyIDIndex);
output[--unusedEntries] = property;
}
}
PassRefPtr<ImmutableStylePropertySet> BisonCSSParser::createStylePropertySet()
{
BitArray<numCSSProperties> seenProperties;
size_t unusedEntries = m_parsedProperties.size();
WillBeHeapVector<CSSProperty, 256> results(unusedEntries);
// Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties);
if (unusedEntries)
results.remove(0, unusedEntries);
CSSParserMode mode = inViewport() ? CSSViewportRuleMode : m_context.mode();
return ImmutableStylePropertySet::create(results.data(), results.size(), mode);
}
void BisonCSSParser::rollbackLastProperties(int num)
{
ASSERT(num >= 0);
ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
m_parsedProperties.shrink(m_parsedProperties.size() - num);
}
void BisonCSSParser::clearProperties()
{
m_parsedProperties.clear();
m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
}
void BisonCSSParser::setCurrentProperty(CSSPropertyID propId)
{
m_id = propId;
}
bool BisonCSSParser::parseValue(CSSPropertyID propId, bool important)
{
CSSPropertyParser parser(m_valueList, m_context, m_inViewport, m_important, m_parsedProperties, m_ruleHeaderType);
return parser.parseValue(propId, important);
}
class TransformOperationInfo {
public:
TransformOperationInfo(const CSSParserString& name)
: m_type(CSSTransformValue::UnknownTransformOperation)
, m_argCount(1)
, m_allowSingleArgument(false)
, m_unit(CSSPropertyParser::FUnknown)
{
const UChar* characters;
unsigned nameLength = name.length();
const unsigned longestNameLength = 12;
UChar characterBuffer[longestNameLength];
if (name.is8Bit()) {
unsigned length = std::min(longestNameLength, nameLength);
const LChar* characters8 = name.characters8();
for (unsigned i = 0; i < length; ++i)
characterBuffer[i] = characters8[i];
characters = characterBuffer;
} else
characters = name.characters16();
SWITCH(characters, nameLength) {
CASE("skew(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::SkewTransformOperation;
m_allowSingleArgument = true;
m_argCount = 3;
}
CASE("scale(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::ScaleTransformOperation;
m_allowSingleArgument = true;
m_argCount = 3;
}
CASE("skewx(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::SkewXTransformOperation;
}
CASE("skewy(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::SkewYTransformOperation;
}
CASE("matrix(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::MatrixTransformOperation;
m_argCount = 11;
}
CASE("rotate(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::RotateTransformOperation;
}
CASE("scalex(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::ScaleXTransformOperation;
}
CASE("scaley(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::ScaleYTransformOperation;
}
CASE("scalez(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::ScaleZTransformOperation;
}
CASE("scale3d(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::Scale3DTransformOperation;
m_argCount = 5;
}
CASE("rotatex(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::RotateXTransformOperation;
}
CASE("rotatey(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::RotateYTransformOperation;
}
CASE("rotatez(") {
m_unit = CSSPropertyParser::FAngle;
m_type = CSSTransformValue::RotateZTransformOperation;
}
CASE("matrix3d(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::Matrix3DTransformOperation;
m_argCount = 31;
}
CASE("rotate3d(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::Rotate3DTransformOperation;
m_argCount = 7;
}
CASE("translate(") {
m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
m_type = CSSTransformValue::TranslateTransformOperation;
m_allowSingleArgument = true;
m_argCount = 3;
}
CASE("translatex(") {
m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
m_type = CSSTransformValue::TranslateXTransformOperation;
}
CASE("translatey(") {
m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
m_type = CSSTransformValue::TranslateYTransformOperation;
}
CASE("translatez(") {
m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
m_type = CSSTransformValue::TranslateZTransformOperation;
}
CASE("perspective(") {
m_unit = CSSPropertyParser::FNumber;
m_type = CSSTransformValue::PerspectiveTransformOperation;
}
CASE("translate3d(") {
m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
m_type = CSSTransformValue::Translate3DTransformOperation;
m_argCount = 5;
}
}
}
CSSTransformValue::TransformOperationType type() const { return m_type; }
unsigned argCount() const { return m_argCount; }
CSSPropertyParser::Units unit() const { return m_unit; }
bool unknown() const { return m_type == CSSTransformValue::UnknownTransformOperation; }
bool hasCorrectArgCount(unsigned argCount) { return m_argCount == argCount || (m_allowSingleArgument && argCount == 1); }
private:
CSSTransformValue::TransformOperationType m_type;
unsigned m_argCount;
bool m_allowSingleArgument;
CSSPropertyParser::Units m_unit;
};
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseTransform(CSSPropertyID propId)
{
if (!m_valueList)
return nullptr;
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
RefPtrWillBeRawPtr<CSSValue> parsedTransformValue = parseTransformValue(propId, value);
if (!parsedTransformValue)
return nullptr;
list->append(parsedTransformValue.release());
}
return list.release();
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseTransformValue(CSSPropertyID propId, CSSParserValue *value)
{
if (value->unit != CSSParserValue::Function || !value->function)
return nullptr;
// Every primitive requires at least one argument.
CSSParserValueList* args = value->function->args.get();
if (!args)
return nullptr;
// See if the specified primitive is one we understand.
TransformOperationInfo info(value->function->name);
if (info.unknown())
return nullptr;
if (!info.hasCorrectArgCount(args->size()))
return nullptr;
// The transform is a list of functional primitives that specify transform operations.
// We collect a list of CSSTransformValues, where each value specifies a single operation.
// Create the new CSSTransformValue for this operation and add it to our list.
RefPtrWillBeRawPtr<CSSTransformValue> transformValue = CSSTransformValue::create(info.type());
// Snag our values.
CSSParserValue* a = args->current();
unsigned argNumber = 0;
while (a) {
CSSPropertyParser::Units unit = info.unit();
if (info.type() == CSSTransformValue::Rotate3DTransformOperation && argNumber == 3) {
// 4th param of rotate3d() is an angle rather than a bare number, validate it as such
if (!validUnit(a, FAngle, HTMLStandardMode))
return nullptr;
} else if (info.type() == CSSTransformValue::Translate3DTransformOperation && argNumber == 2) {
// 3rd param of translate3d() cannot be a percentage
if (!validUnit(a, FLength, HTMLStandardMode))
return nullptr;
} else if (info.type() == CSSTransformValue::TranslateZTransformOperation && !argNumber) {
// 1st param of translateZ() cannot be a percentage
if (!validUnit(a, FLength, HTMLStandardMode))
return nullptr;
} else if (info.type() == CSSTransformValue::PerspectiveTransformOperation && !argNumber) {
// 1st param of perspective() must be a non-negative number (deprecated) or length.
if ((propId == CSSPropertyWebkitTransform && !validUnit(a, FNumber | FLength | FNonNeg, HTMLStandardMode))
|| (propId == CSSPropertyTransform && !validUnit(a, FLength | FNonNeg, HTMLStandardMode)))
return nullptr;
} else if (!validUnit(a, unit, HTMLStandardMode)) {
return nullptr;
}
// Add the value to the current transform operation.
transformValue->append(createPrimitiveNumericValue(a));
a = args->next();
if (!a)
break;
if (a->unit != CSSParserValue::Operator || a->iValue != ',')
return nullptr;
a = args->next();
argNumber++;
}
return transformValue.release();
}
void BisonCSSParser::ensureLineEndings()
{
if (!m_lineEndings)
m_lineEndings = lineEndings(*m_source);
}
CSSParserSelector* BisonCSSParser::createFloatingSelectorWithTagName(const QualifiedName& tagQName)
{
CSSParserSelector* selector = new CSSParserSelector(tagQName);
m_floatingSelectors.append(selector);
return selector;
}
CSSParserSelector* BisonCSSParser::createFloatingSelector()
{
CSSParserSelector* selector = new CSSParserSelector;
m_floatingSelectors.append(selector);
return selector;
}
PassOwnPtr<CSSParserSelector> BisonCSSParser::sinkFloatingSelector(CSSParserSelector* selector)
{
if (selector) {
size_t index = m_floatingSelectors.reverseFind(selector);
ASSERT(index != kNotFound);
m_floatingSelectors.remove(index);
}
return adoptPtr(selector);
}
Vector<OwnPtr<CSSParserSelector> >* BisonCSSParser::createFloatingSelectorVector()
{
Vector<OwnPtr<CSSParserSelector> >* selectorVector = new Vector<OwnPtr<CSSParserSelector> >;
m_floatingSelectorVectors.append(selectorVector);
return selectorVector;
}
PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > BisonCSSParser::sinkFloatingSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectorVector)
{
if (selectorVector) {
size_t index = m_floatingSelectorVectors.reverseFind(selectorVector);
ASSERT(index != kNotFound);
m_floatingSelectorVectors.remove(index);
}
return adoptPtr(selectorVector);
}
CSSParserValueList* BisonCSSParser::createFloatingValueList()
{
CSSParserValueList* list = new CSSParserValueList;
m_floatingValueLists.append(list);
return list;
}
PassOwnPtr<CSSParserValueList> BisonCSSParser::sinkFloatingValueList(CSSParserValueList* list)
{
if (list) {
size_t index = m_floatingValueLists.reverseFind(list);
ASSERT(index != kNotFound);
m_floatingValueLists.remove(index);
}
return adoptPtr(list);
}
CSSParserFunction* BisonCSSParser::createFloatingFunction()
{
CSSParserFunction* function = new CSSParserFunction;
m_floatingFunctions.append(function);
return function;
}
CSSParserFunction* BisonCSSParser::createFloatingFunction(const CSSParserString& name, PassOwnPtr<CSSParserValueList> args)
{
CSSParserFunction* function = createFloatingFunction();
function->name = name;
function->args = args;
return function;
}
PassOwnPtr<CSSParserFunction> BisonCSSParser::sinkFloatingFunction(CSSParserFunction* function)
{
if (function) {
size_t index = m_floatingFunctions.reverseFind(function);
ASSERT(index != kNotFound);
m_floatingFunctions.remove(index);
}
return adoptPtr(function);
}
CSSParserValue& BisonCSSParser::sinkFloatingValue(CSSParserValue& value)
{
if (value.unit == CSSParserValue::Function) {
size_t index = m_floatingFunctions.reverseFind(value.function);
ASSERT(index != kNotFound);
m_floatingFunctions.remove(index);
}
return value;
}
MediaQueryExp* BisonCSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values)
{
m_floatingMediaQueryExp = MediaQueryExp::createIfValid(mediaFeature, values);
return m_floatingMediaQueryExp.get();
}
PassOwnPtrWillBeRawPtr<MediaQueryExp> BisonCSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* expression)
{
ASSERT_UNUSED(expression, expression == m_floatingMediaQueryExp);
return m_floatingMediaQueryExp.release();
}
WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> >* BisonCSSParser::createFloatingMediaQueryExpList()
{
m_floatingMediaQueryExpList = adoptPtrWillBeNoop(new WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> >);
return m_floatingMediaQueryExpList.get();
}
PassOwnPtrWillBeRawPtr<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > > BisonCSSParser::sinkFloatingMediaQueryExpList(WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> >* list)
{
ASSERT_UNUSED(list, list == m_floatingMediaQueryExpList);
return m_floatingMediaQueryExpList.release();
}
MediaQuery* BisonCSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restrictor, const AtomicString& mediaType, PassOwnPtrWillBeRawPtr<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > > expressions)
{
m_floatingMediaQuery = adoptPtrWillBeNoop(new MediaQuery(restrictor, mediaType, expressions));
return m_floatingMediaQuery.get();
}
MediaQuery* BisonCSSParser::createFloatingMediaQuery(PassOwnPtrWillBeRawPtr<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > > expressions)
{
return createFloatingMediaQuery(MediaQuery::None, AtomicString("all", AtomicString::ConstructFromLiteral), expressions);
}
MediaQuery* BisonCSSParser::createFloatingNotAllQuery()
{
return createFloatingMediaQuery(MediaQuery::Not, AtomicString("all", AtomicString::ConstructFromLiteral), sinkFloatingMediaQueryExpList(createFloatingMediaQueryExpList()));
}
PassOwnPtrWillBeRawPtr<MediaQuery> BisonCSSParser::sinkFloatingMediaQuery(MediaQuery* query)
{
ASSERT_UNUSED(query, query == m_floatingMediaQuery);
return m_floatingMediaQuery.release();
}
WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >* BisonCSSParser::createFloatingKeyframeVector()
{
m_floatingKeyframeVector = adoptPtrWillBeNoop(new WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >());
return m_floatingKeyframeVector.get();
}
PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > > BisonCSSParser::sinkFloatingKeyframeVector(WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >* keyframeVector)
{
ASSERT_UNUSED(keyframeVector, m_floatingKeyframeVector == keyframeVector);
return m_floatingKeyframeVector.release();
}
MediaQuerySet* BisonCSSParser::createMediaQuerySet()
{
RefPtrWillBeRawPtr<MediaQuerySet> queries = MediaQuerySet::create();
MediaQuerySet* result = queries.get();
m_parsedMediaQuerySets.append(queries.release());
return result;
}
StyleRuleBase* BisonCSSParser::createImportRule(const CSSParserString& url, MediaQuerySet* media)
{
if (!media || !m_allowImportRules)
return 0;
RefPtrWillBeRawPtr<StyleRuleImport> rule = StyleRuleImport::create(url, media);
StyleRuleImport* result = rule.get();
m_parsedRules.append(rule.release());
return result;
}
StyleRuleBase* BisonCSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules)
{
m_allowImportRules = m_allowNamespaceDeclarations = false;
RefPtrWillBeRawPtr<StyleRuleMedia> rule = nullptr;
if (rules) {
rule = StyleRuleMedia::create(media ? media : MediaQuerySet::create().get(), *rules);
} else {
RuleList emptyRules;
rule = StyleRuleMedia::create(media ? media : MediaQuerySet::create().get(), emptyRules);
}
StyleRuleMedia* result = rule.get();
m_parsedRules.append(rule.release());
return result;
}
StyleRuleBase* BisonCSSParser::createSupportsRule(bool conditionIsSupported, RuleList* rules)
{
m_allowImportRules = m_allowNamespaceDeclarations = false;
RefPtrWillBeRawPtr<CSSRuleSourceData> data = popSupportsRuleData();
RefPtrWillBeRawPtr<StyleRuleSupports> rule = nullptr;
String conditionText;
unsigned conditionOffset = data->ruleHeaderRange.start + 9;
unsigned conditionLength = data->ruleHeaderRange.length() - 9;
if (m_tokenizer.is8BitSource())
conditionText = String(m_tokenizer.m_dataStart8.get() + conditionOffset, conditionLength).stripWhiteSpace();
else
conditionText = String(m_tokenizer.m_dataStart16.get() + conditionOffset, conditionLength).stripWhiteSpace();
if (rules) {
rule = StyleRuleSupports::create(conditionText, conditionIsSupported, *rules);
} else {
RuleList emptyRules;
rule = StyleRuleSupports::create(conditionText, conditionIsSupported, emptyRules);
}
StyleRuleSupports* result = rule.get();
m_parsedRules.append(rule.release());
return result;
}
void BisonCSSParser::markSupportsRuleHeaderStart()
{
if (!m_supportsRuleDataStack)
m_supportsRuleDataStack = adoptPtrWillBeNoop(new RuleSourceDataList());
RefPtrWillBeRawPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(CSSRuleSourceData::SUPPORTS_RULE);
data->ruleHeaderRange.start = m_tokenizer.tokenStartOffset();
m_supportsRuleDataStack->append(data);
}
void BisonCSSParser::markSupportsRuleHeaderEnd()
{
ASSERT(m_supportsRuleDataStack && !m_supportsRuleDataStack->isEmpty());
if (m_tokenizer.is8BitSource())
m_supportsRuleDataStack->last()->ruleHeaderRange.end = m_tokenizer.tokenStart<LChar>() - m_tokenizer.m_dataStart8.get();
else
m_supportsRuleDataStack->last()->ruleHeaderRange.end = m_tokenizer.tokenStart<UChar>() - m_tokenizer.m_dataStart16.get();
}
PassRefPtrWillBeRawPtr<CSSRuleSourceData> BisonCSSParser::popSupportsRuleData()
{
ASSERT(m_supportsRuleDataStack && !m_supportsRuleDataStack->isEmpty());
RefPtrWillBeRawPtr<CSSRuleSourceData> data = m_supportsRuleDataStack->last();
m_supportsRuleDataStack->removeLast();
return data.release();
}
BisonCSSParser::RuleList* BisonCSSParser::createRuleList()
{
OwnPtrWillBeRawPtr<RuleList> list = adoptPtrWillBeNoop(new RuleList);
RuleList* listPtr = list.get();
m_parsedRuleLists.append(list.release());
return listPtr;
}
BisonCSSParser::RuleList* BisonCSSParser::appendRule(RuleList* ruleList, StyleRuleBase* rule)
{
if (rule) {
if (!ruleList)
ruleList = createRuleList();
ruleList->append(rule);
}
return ruleList;
}
template <typename CharacterType>
ALWAYS_INLINE static void makeLower(const CharacterType* input, CharacterType* output, unsigned length)
{
// FIXME: If we need Unicode lowercasing here, then we probably want the real kind
// that can potentially change the length of the string rather than the character
// by character kind. If we don't need Unicode lowercasing, it would be good to
// simplify this function.
if (charactersAreAllASCII(input, length)) {
// Fast case for all-ASCII.
for (unsigned i = 0; i < length; i++)
output[i] = toASCIILower(input[i]);
} else {
for (unsigned i = 0; i < length; i++)
output[i] = Unicode::toLower(input[i]);
}
}
void BisonCSSParser::tokenToLowerCase(CSSParserString& token)
{
// Since it's our internal token, we know that we created it out
// of our writable work buffers. Therefore the const_cast is just
// ugly and not a potential crash.
size_t length = token.length();
if (token.is8Bit()) {
makeLower(token.characters8(), const_cast<LChar*>(token.characters8()), length);
} else {
makeLower(token.characters16(), const_cast<UChar*>(token.characters16()), length);
}
}
void BisonCSSParser::endInvalidRuleHeader()
{
if (m_ruleHeaderType == CSSRuleSourceData::UNKNOWN_RULE)
return;
CSSParserLocation location;
location.lineNumber = m_tokenizer.m_lineNumber;
location.offset = m_ruleHeaderStartOffset;
if (m_tokenizer.is8BitSource())
location.token.init(m_tokenizer.m_dataStart8.get() + m_ruleHeaderStartOffset, 0);
else
location.token.init(m_tokenizer.m_dataStart16.get() + m_ruleHeaderStartOffset, 0);
reportError(location, m_ruleHeaderType == CSSRuleSourceData::STYLE_RULE ? InvalidSelectorCSSError : InvalidRuleCSSError);
endRuleHeader();
}
void BisonCSSParser::reportError(const CSSParserLocation&, CSSParserError)
{
// FIXME: error reporting temporatily disabled.
}
bool BisonCSSParser::isLoggingErrors()
{
return m_logErrors && !m_ignoreErrors;
}
void BisonCSSParser::logError(const String& message, const CSSParserLocation& location)
{
unsigned lineNumberInStyleSheet;
unsigned columnNumber = 0;
if (InspectorInstrumentation::hasFrontends()) {
ensureLineEndings();
TextPosition tokenPosition = TextPosition::fromOffsetAndLineEndings(location.offset, *m_lineEndings);
lineNumberInStyleSheet = tokenPosition.m_line.zeroBasedInt();
columnNumber = (lineNumberInStyleSheet ? 0 : m_startPosition.m_column.zeroBasedInt()) + tokenPosition.m_column.zeroBasedInt();
} else {
lineNumberInStyleSheet = location.lineNumber;
}
FrameConsole& console = m_styleSheet->singleOwnerDocument()->frame()->console();
console.addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleSheet->baseURL().string(), lineNumberInStyleSheet + m_startPosition.m_line.zeroBasedInt() + 1, columnNumber + 1);
}
StyleRuleKeyframes* BisonCSSParser::createKeyframesRule(const String& name, PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > > popKeyframes, bool isPrefixed)
{
OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > > keyframes = popKeyframes;
m_allowImportRules = m_allowNamespaceDeclarations = false;
RefPtrWillBeRawPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create();
for (size_t i = 0; i < keyframes->size(); ++i)
rule->parserAppendKeyframe(keyframes->at(i));
rule->setName(name);
rule->setVendorPrefixed(isPrefixed);
StyleRuleKeyframes* rulePtr = rule.get();
m_parsedRules.append(rule.release());
return rulePtr;
}
static void recordSelectorStats(const CSSParserContext& context, const CSSSelectorList& selectorList)
{
if (!context.useCounter())
return;
for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector)) {
for (const CSSSelector* current = selector; current ; current = current->tagHistory()) {
UseCounter::Feature feature = UseCounter::NumberOfFeatures;
switch (current->pseudoType()) {
case CSSSelector::PseudoUnresolved:
feature = UseCounter::CSSSelectorPseudoUnresolved;
break;
case CSSSelector::PseudoShadow:
feature = UseCounter::CSSSelectorPseudoShadow;
break;
case CSSSelector::PseudoContent:
feature = UseCounter::CSSSelectorPseudoContent;
break;
case CSSSelector::PseudoHost:
feature = UseCounter::CSSSelectorPseudoHost;
break;
case CSSSelector::PseudoHostContext:
feature = UseCounter::CSSSelectorPseudoHostContext;
break;
default:
break;
}
if (feature != UseCounter::NumberOfFeatures)
context.useCounter()->count(feature);
if (current->relation() == CSSSelector::ShadowDeep)
context.useCounter()->count(UseCounter::CSSDeepCombinator);
if (current->selectorList())
recordSelectorStats(context, *current->selectorList());
}
}
}
StyleRuleBase* BisonCSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors)
{
StyleRule* result = 0;
if (selectors) {
m_allowImportRules = m_allowNamespaceDeclarations = false;
RefPtrWillBeRawPtr<StyleRule> rule = StyleRule::create();
rule->parserAdoptSelectorVector(*selectors);
rule->setProperties(createStylePropertySet());
result = rule.get();
m_parsedRules.append(rule.release());
recordSelectorStats(m_context, result->selectorList());
}
clearProperties();
return result;
}
StyleRuleBase* BisonCSSParser::createFontFaceRule()
{
m_allowImportRules = m_allowNamespaceDeclarations = false;
for (unsigned i = 0; i < m_parsedProperties.size(); ++i) {
CSSProperty& property = m_parsedProperties[i];
if (property.id() == CSSPropertyFontVariant && property.value()->isPrimitiveValue())
property.wrapValueInCommaSeparatedList();
else if (property.id() == CSSPropertyFontFamily && (!property.value()->isValueList() || toCSSValueList(property.value())->length() != 1)) {
// Unlike font-family property, font-family descriptor in @font-face rule
// has to be a value list with exactly one family name. It cannot have a
// have 'initial' value and cannot 'inherit' from parent.
// See http://dev.w3.org/csswg/css3-fonts/#font-family-desc
clearProperties();
return 0;
}
}
RefPtrWillBeRawPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create();
rule->setProperties(createStylePropertySet());
clearProperties();
StyleRuleFontFace* result = rule.get();
m_parsedRules.append(rule.release());
if (m_styleSheet)
m_styleSheet->setHasFontFaceRule(true);
return result;
}
void BisonCSSParser::addNamespace(const AtomicString& prefix, const AtomicString& uri)
{
if (!m_styleSheet || !m_allowNamespaceDeclarations)
return;
m_allowImportRules = false;
m_styleSheet->parserAddNamespace(prefix, uri);
if (prefix.isEmpty() && !uri.isNull())
m_defaultNamespace = uri;
}
QualifiedName BisonCSSParser::determineNameInNamespace(const AtomicString& prefix, const AtomicString& localName)
{
if (!m_styleSheet)
return QualifiedName(prefix, localName, m_defaultNamespace);
return QualifiedName(prefix, localName, m_styleSheet->determineNamespace(prefix));
}
CSSParserSelector* BisonCSSParser::rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector* specifiers)
{
if (m_defaultNamespace != starAtom || specifiers->crossesTreeScopes())
return rewriteSpecifiersWithElementName(nullAtom, starAtom, specifiers, /*tagIsForNamespaceRule*/true);
return specifiers;
}
CSSParserSelector* BisonCSSParser::rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule)
{
AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleSheet ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace;
QualifiedName tag(namespacePrefix, elementName, determinedNamespace);
if (specifiers->crossesTreeScopes())
return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, elementName, specifiers, tagIsForNamespaceRule);
if (specifiers->isContentPseudoElement())
return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, elementName, specifiers, tagIsForNamespaceRule);
// *:host never matches, so we can't discard the * otherwise we can't tell the
// difference between *:host and just :host.
if (tag == anyQName() && !specifiers->hasHostPseudoSelector())
return specifiers;
if (specifiers->pseudoType() != CSSSelector::PseudoCue)
specifiers->prependTagSelector(tag, tagIsForNamespaceRule);
return specifiers;
}
CSSParserSelector* BisonCSSParser::rewriteSpecifiersWithElementNameForCustomPseudoElement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule)
{
if (m_context.useCounter() && specifiers->pseudoType() == CSSSelector::PseudoUserAgentCustomElement)
m_context.useCounter()->count(UseCounter::CSSPseudoElementUserAgentCustomPseudo);
CSSParserSelector* lastShadowPseudo = specifiers;
CSSParserSelector* history = specifiers;
while (history->tagHistory()) {
history = history->tagHistory();
if (history->crossesTreeScopes() || history->hasShadowPseudo())
lastShadowPseudo = history;
}
if (lastShadowPseudo->tagHistory()) {
if (tag != anyQName())
lastShadowPseudo->tagHistory()->prependTagSelector(tag, tagIsForNamespaceRule);
return specifiers;
}
// For shadow-ID pseudo-elements to be correctly matched, the ShadowPseudo combinator has to be used.
// We therefore create a new Selector with that combinator here in any case, even if matching any (host) element in any namespace (i.e. '*').
OwnPtr<CSSParserSelector> elementNameSelector = adoptPtr(new CSSParserSelector(tag));
lastShadowPseudo->setTagHistory(elementNameSelector.release());
lastShadowPseudo->setRelation(CSSSelector::ShadowPseudo);
return specifiers;
}
CSSParserSelector* BisonCSSParser::rewriteSpecifiersWithElementNameForContentPseudoElement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule)
{
CSSParserSelector* last = specifiers;
CSSParserSelector* history = specifiers;
while (history->tagHistory()) {
history = history->tagHistory();
if (history->isContentPseudoElement() || history->relationIsAffectedByPseudoContent())
last = history;
}
if (last->tagHistory()) {
if (tag != anyQName())
last->tagHistory()->prependTagSelector(tag, tagIsForNamespaceRule);
return specifiers;
}
// For shadow-ID pseudo-elements to be correctly matched, the ShadowPseudo combinator has to be used.
// We therefore create a new Selector with that combinator here in any case, even if matching any (host) element in any namespace (i.e. '*').
OwnPtr<CSSParserSelector> elementNameSelector = adoptPtr(new CSSParserSelector(tag));
last->setTagHistory(elementNameSelector.release());
last->setRelation(CSSSelector::SubSelector);
return specifiers;
}
CSSParserSelector* BisonCSSParser::rewriteSpecifiers(CSSParserSelector* specifiers, CSSParserSelector* newSpecifier)
{
if (newSpecifier->crossesTreeScopes()) {
// Unknown pseudo element always goes at the top of selector chain.
newSpecifier->appendTagHistory(CSSSelector::ShadowPseudo, sinkFloatingSelector(specifiers));
return newSpecifier;
}
if (newSpecifier->isContentPseudoElement()) {
newSpecifier->appendTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(specifiers));
return newSpecifier;
}
if (specifiers->crossesTreeScopes()) {
// Specifiers for unknown pseudo element go right behind it in the chain.
specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier), CSSSelector::ShadowPseudo);
return specifiers;
}
if (specifiers->isContentPseudoElement()) {
specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier), CSSSelector::SubSelector);
return specifiers;
}
specifiers->appendTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier));
return specifiers;
}
StyleRuleBase* BisonCSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
{
// FIXME: Margin at-rules are ignored.
m_allowImportRules = m_allowNamespaceDeclarations = false;
StyleRulePage* pageRule = 0;
if (pageSelector) {
RefPtrWillBeRawPtr<StyleRulePage> rule = StyleRulePage::create();
Vector<OwnPtr<CSSParserSelector> > selectorVector;
selectorVector.append(pageSelector);
rule->parserAdoptSelectorVector(selectorVector);
rule->setProperties(createStylePropertySet());
pageRule = rule.get();
m_parsedRules.append(rule.release());
}
clearProperties();
return pageRule;
}
StyleRuleBase* BisonCSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
{
// FIXME: Implement margin at-rule here, using:
// - marginBox: margin box
// - m_parsedProperties: properties at [m_numParsedPropertiesBeforeMarginBox, m_parsedProperties.size()] are for this at-rule.
// Don't forget to also update the action for page symbol in CSSGrammar.y such that margin at-rule data is cleared if page_selector is invalid.
endDeclarationsForMarginBox();
return 0; // until this method is implemented.
}
void BisonCSSParser::startDeclarationsForMarginBox()
{
m_numParsedPropertiesBeforeMarginBox = m_parsedProperties.size();
}
void BisonCSSParser::endDeclarationsForMarginBox()
{
rollbackLastProperties(m_parsedProperties.size() - m_numParsedPropertiesBeforeMarginBox);
m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
}
StyleKeyframe* BisonCSSParser::createKeyframe(CSSParserValueList* keys)
{
OwnPtr<Vector<double> > keyVector = StyleKeyframe::createKeyList(keys);
if (keyVector->isEmpty())
return 0;
RefPtrWillBeRawPtr<StyleKeyframe> keyframe = StyleKeyframe::create();
keyframe->setKeys(keyVector.release());
keyframe->setProperties(createStylePropertySet());
clearProperties();
StyleKeyframe* keyframePtr = keyframe.get();
m_parsedKeyframes.append(keyframe.release());
return keyframePtr;
}
void BisonCSSParser::invalidBlockHit()
{
if (m_styleSheet && !m_hadSyntacticallyValidCSSRule)
m_styleSheet->setHasSyntacticallyValidCSSHeader(false);
}
void BisonCSSParser::startRule()
{
if (!m_observer)
return;
ASSERT(m_ruleHasHeader);
m_ruleHasHeader = false;
}
void BisonCSSParser::endRule(bool valid)
{
if (!m_observer)
return;
if (m_ruleHasHeader)
m_observer->endRuleBody(m_tokenizer.safeUserStringTokenOffset(), !valid);
m_ruleHasHeader = true;
}
void BisonCSSParser::startRuleHeader(CSSRuleSourceData::Type ruleType)
{
resumeErrorLogging();
m_ruleHeaderType = ruleType;
m_ruleHeaderStartOffset = m_tokenizer.safeUserStringTokenOffset();
m_ruleHeaderStartLineNumber = m_tokenizer.m_tokenStartLineNumber;
if (m_observer) {
ASSERT(!m_ruleHasHeader);
m_observer->startRuleHeader(ruleType, m_ruleHeaderStartOffset);
m_ruleHasHeader = true;
}
}
void BisonCSSParser::endRuleHeader()
{
ASSERT(m_ruleHeaderType != CSSRuleSourceData::UNKNOWN_RULE);
m_ruleHeaderType = CSSRuleSourceData::UNKNOWN_RULE;
if (m_observer) {
ASSERT(m_ruleHasHeader);
m_observer->endRuleHeader(m_tokenizer.safeUserStringTokenOffset());
}
}
void BisonCSSParser::startSelector()
{
if (m_observer)
m_observer->startSelector(m_tokenizer.safeUserStringTokenOffset());
}
void BisonCSSParser::endSelector()
{
if (m_observer)
m_observer->endSelector(m_tokenizer.safeUserStringTokenOffset());
}
void BisonCSSParser::startRuleBody()
{
if (m_observer)
m_observer->startRuleBody(m_tokenizer.safeUserStringTokenOffset());
}
void BisonCSSParser::startProperty()
{
resumeErrorLogging();
if (m_observer)
m_observer->startProperty(m_tokenizer.safeUserStringTokenOffset());
}
void BisonCSSParser::endProperty(bool isImportantFound, bool isPropertyParsed, CSSParserError errorType)
{
m_id = CSSPropertyInvalid;
if (m_observer)
m_observer->endProperty(isImportantFound, isPropertyParsed, m_tokenizer.safeUserStringTokenOffset(), errorType);
}
void BisonCSSParser::startEndUnknownRule()
{
if (m_observer)
m_observer->startEndUnknownRule();
}
StyleRuleBase* BisonCSSParser::createViewportRule()
{
// Allow @viewport rules from UA stylesheets even if the feature is disabled.
if (!RuntimeEnabledFeatures::cssViewportEnabled() && !isUASheetBehavior(m_context.mode()))
return 0;
m_allowImportRules = m_allowNamespaceDeclarations = false;
RefPtrWillBeRawPtr<StyleRuleViewport> rule = StyleRuleViewport::create();
rule->setProperties(createStylePropertySet());
clearProperties();
StyleRuleViewport* result = rule.get();
m_parsedRules.append(rule.release());
return result;
}
}
|