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
|
/*
* Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2011 Adobe Systems Incorporated. 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 "RenderStyle.h"
#include "ContentData.h"
#include "CursorList.h"
#include "CSSPropertyNames.h"
#include "Font.h"
#include "FontSelector.h"
#include "Pagination.h"
#include "QuotesData.h"
#include "RenderObject.h"
#include "ScaleTransformOperation.h"
#include "ShadowData.h"
#include "StyleImage.h"
#include "StyleInheritedData.h"
#include "StyleResolver.h"
#if ENABLE(TOUCH_EVENTS)
#include "RenderTheme.h"
#endif
#include <wtf/MathExtras.h>
#include <wtf/StdLibExtras.h>
#include <algorithm>
#if ENABLE(IOS_TEXT_AUTOSIZING)
#include <wtf/text/StringHash.h>
#endif
#if ENABLE(TEXT_AUTOSIZING)
#include "TextAutosizer.h"
#endif
namespace WebCore {
struct SameSizeAsBorderValue {
RGBA32 m_color;
unsigned m_width;
};
#if CPU(M68K)
COMPILE_ASSERT(sizeof(BorderValue) <= sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
#else
COMPILE_ASSERT(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), BorderValue_should_not_grow);
#endif
struct SameSizeAsRenderStyle : public RefCounted<SameSizeAsRenderStyle> {
void* dataRefs[7];
void* ownPtrs[1];
#if ENABLE(SVG)
void* dataRefSvgStyle;
#endif
struct InheritedFlags {
unsigned m_bitfields[2];
} inherited_flags;
struct NonInheritedFlags {
unsigned m_bitfields[2];
} noninherited_flags;
};
#if CPU(M68K)
COMPILE_ASSERT(sizeof(RenderStyle) <= sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
#else
COMPILE_ASSERT(sizeof(RenderStyle) == sizeof(SameSizeAsRenderStyle), RenderStyle_should_stay_small);
#endif
inline RenderStyle& defaultStyle()
{
static RenderStyle& style = RenderStyle::createDefaultStyle().leakRef();
return style;
}
PassRef<RenderStyle> RenderStyle::create()
{
return adoptRef(*new RenderStyle());
}
PassRef<RenderStyle> RenderStyle::createDefaultStyle()
{
return adoptRef(*new RenderStyle(true));
}
PassRef<RenderStyle> RenderStyle::createAnonymousStyleWithDisplay(const RenderStyle* parentStyle, EDisplay display)
{
auto newStyle = RenderStyle::create();
newStyle.get().inheritFrom(parentStyle);
newStyle.get().inheritUnicodeBidiFrom(parentStyle);
newStyle.get().setDisplay(display);
return newStyle;
}
PassRef<RenderStyle> RenderStyle::clone(const RenderStyle* other)
{
return adoptRef(*new RenderStyle(*other));
}
PassRef<RenderStyle> RenderStyle::createStyleInheritingFromPseudoStyle(const RenderStyle& pseudoStyle)
{
ASSERT(pseudoStyle.styleType() == BEFORE || pseudoStyle.styleType() == AFTER);
// Images are special and must inherit the pseudoStyle so the width and height of
// the pseudo element doesn't change the size of the image. In all other cases we
// can just share the style.
auto style = RenderStyle::create();
style.get().inheritFrom(&pseudoStyle);
return style;
}
ALWAYS_INLINE RenderStyle::RenderStyle()
: m_box(defaultStyle().m_box)
, visual(defaultStyle().visual)
, m_background(defaultStyle().m_background)
, surround(defaultStyle().surround)
, rareNonInheritedData(defaultStyle().rareNonInheritedData)
, rareInheritedData(defaultStyle().rareInheritedData)
, inherited(defaultStyle().inherited)
#if ENABLE(SVG)
, m_svgStyle(defaultStyle().m_svgStyle)
#endif
{
setBitDefaults(); // Would it be faster to copy this from the default style?
COMPILE_ASSERT((sizeof(InheritedFlags) <= 8), InheritedFlags_does_not_grow);
COMPILE_ASSERT((sizeof(NonInheritedFlags) <= 8), NonInheritedFlags_does_not_grow);
}
ALWAYS_INLINE RenderStyle::RenderStyle(bool)
: m_box(StyleBoxData::create())
, visual(StyleVisualData::create())
, m_background(StyleBackgroundData::create())
, surround(StyleSurroundData::create())
, rareNonInheritedData(StyleRareNonInheritedData::create())
, rareInheritedData(StyleRareInheritedData::create())
, inherited(StyleInheritedData::create())
#if ENABLE(SVG)
, m_svgStyle(SVGRenderStyle::create())
#endif
{
setBitDefaults();
}
ALWAYS_INLINE RenderStyle::RenderStyle(const RenderStyle& o)
: RefCounted<RenderStyle>()
, m_box(o.m_box)
, visual(o.visual)
, m_background(o.m_background)
, surround(o.surround)
, rareNonInheritedData(o.rareNonInheritedData)
, rareInheritedData(o.rareInheritedData)
, inherited(o.inherited)
#if ENABLE(SVG)
, m_svgStyle(o.m_svgStyle)
#endif
, inherited_flags(o.inherited_flags)
, noninherited_flags(o.noninherited_flags)
{
}
void RenderStyle::inheritFrom(const RenderStyle* inheritParent, IsAtShadowBoundary isAtShadowBoundary)
{
if (isAtShadowBoundary == AtShadowBoundary) {
// Even if surrounding content is user-editable, shadow DOM should act as a single unit, and not necessarily be editable
EUserModify currentUserModify = userModify();
rareInheritedData = inheritParent->rareInheritedData;
setUserModify(currentUserModify);
} else
rareInheritedData = inheritParent->rareInheritedData;
inherited = inheritParent->inherited;
inherited_flags = inheritParent->inherited_flags;
#if ENABLE(SVG)
if (m_svgStyle != inheritParent->m_svgStyle)
m_svgStyle.access()->inheritFrom(inheritParent->m_svgStyle.get());
#endif
}
void RenderStyle::copyNonInheritedFrom(const RenderStyle* other)
{
m_box = other->m_box;
visual = other->visual;
m_background = other->m_background;
surround = other->surround;
rareNonInheritedData = other->rareNonInheritedData;
// The flags are copied one-by-one because noninherited_flags contains a bunch of stuff other than real style data.
noninherited_flags._effectiveDisplay = other->noninherited_flags._effectiveDisplay;
noninherited_flags._originalDisplay = other->noninherited_flags._originalDisplay;
noninherited_flags._overflowX = other->noninherited_flags._overflowX;
noninherited_flags._overflowY = other->noninherited_flags._overflowY;
noninherited_flags._vertical_align = other->noninherited_flags._vertical_align;
noninherited_flags._clear = other->noninherited_flags._clear;
noninherited_flags._position = other->noninherited_flags._position;
noninherited_flags._floating = other->noninherited_flags._floating;
noninherited_flags._table_layout = other->noninherited_flags._table_layout;
noninherited_flags._unicodeBidi = other->noninherited_flags._unicodeBidi;
noninherited_flags._page_break_before = other->noninherited_flags._page_break_before;
noninherited_flags._page_break_after = other->noninherited_flags._page_break_after;
noninherited_flags._page_break_inside = other->noninherited_flags._page_break_inside;
noninherited_flags.explicitInheritance = other->noninherited_flags.explicitInheritance;
#if ENABLE(SVG)
if (m_svgStyle != other->m_svgStyle)
m_svgStyle.access()->copyNonInheritedFrom(other->m_svgStyle.get());
#endif
ASSERT(zoom() == initialZoom());
}
bool RenderStyle::operator==(const RenderStyle& o) const
{
// compare everything except the pseudoStyle pointer
return inherited_flags == o.inherited_flags
&& noninherited_flags == o.noninherited_flags
&& m_box == o.m_box
&& visual == o.visual
&& m_background == o.m_background
&& surround == o.surround
&& rareNonInheritedData == o.rareNonInheritedData
&& rareInheritedData == o.rareInheritedData
&& inherited == o.inherited
#if ENABLE(SVG)
&& m_svgStyle == o.m_svgStyle
#endif
;
}
bool RenderStyle::isStyleAvailable() const
{
return this != StyleResolver::styleNotYetAvailable();
}
bool RenderStyle::hasUniquePseudoStyle() const
{
if (!m_cachedPseudoStyles || styleType() != NOPSEUDO)
return false;
for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
if (pseudoStyle->unique())
return true;
}
return false;
}
RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
{
if (!m_cachedPseudoStyles || !m_cachedPseudoStyles->size())
return 0;
if (styleType() != NOPSEUDO)
return 0;
for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
if (pseudoStyle->styleType() == pid)
return pseudoStyle;
}
return 0;
}
RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
{
if (!pseudo)
return 0;
ASSERT(pseudo->styleType() > NOPSEUDO);
RenderStyle* result = pseudo.get();
if (!m_cachedPseudoStyles)
m_cachedPseudoStyles = adoptPtr(new PseudoStyleCache);
m_cachedPseudoStyles->append(pseudo);
return result;
}
void RenderStyle::removeCachedPseudoStyle(PseudoId pid)
{
if (!m_cachedPseudoStyles)
return;
for (size_t i = 0; i < m_cachedPseudoStyles->size(); ++i) {
RenderStyle* pseudoStyle = m_cachedPseudoStyles->at(i).get();
if (pseudoStyle->styleType() == pid) {
m_cachedPseudoStyles->remove(i);
return;
}
}
}
bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
{
return inherited_flags != other->inherited_flags
|| inherited != other->inherited
#if ENABLE(SVG)
|| m_svgStyle->inheritedNotEqual(other->m_svgStyle.get())
#endif
|| rareInheritedData != other->rareInheritedData;
}
#if ENABLE(IOS_TEXT_AUTOSIZING)
inline unsigned computeFontHash(const Font& font)
{
unsigned hashCodes[2] = {
CaseFoldingHash::hash(font.fontDescription().firstFamily().impl()),
static_cast<unsigned>(font.fontDescription().specifiedSize())
};
return StringHasher::computeHash(reinterpret_cast<UChar*>(hashCodes), 2 * sizeof(unsigned) / sizeof(UChar));
}
uint32_t RenderStyle::hashForTextAutosizing() const
{
// FIXME: Not a very smart hash. Could be improved upon. See <https://bugs.webkit.org/show_bug.cgi?id=121131>.
uint32_t hash = 0;
hash ^= rareNonInheritedData->m_appearance;
hash ^= rareNonInheritedData->marginBeforeCollapse;
hash ^= rareNonInheritedData->marginAfterCollapse;
hash ^= rareNonInheritedData->lineClamp.value();
hash ^= rareInheritedData->overflowWrap;
hash ^= rareInheritedData->nbspMode;
hash ^= rareInheritedData->lineBreak;
hash ^= WTF::FloatHash<float>::hash(inherited->specifiedLineHeight.value());
hash ^= computeFontHash(inherited->font);
hash ^= inherited->horizontal_border_spacing;
hash ^= inherited->vertical_border_spacing;
hash ^= inherited_flags._box_direction;
hash ^= inherited_flags.m_rtlOrdering;
hash ^= noninherited_flags._position;
hash ^= noninherited_flags._floating;
hash ^= rareNonInheritedData->textOverflow;
hash ^= rareInheritedData->textSecurity;
return hash;
}
bool RenderStyle::equalForTextAutosizing(const RenderStyle* other) const
{
return rareNonInheritedData->m_appearance == other->rareNonInheritedData->m_appearance
&& rareNonInheritedData->marginBeforeCollapse == other->rareNonInheritedData->marginBeforeCollapse
&& rareNonInheritedData->marginAfterCollapse == other->rareNonInheritedData->marginAfterCollapse
&& rareNonInheritedData->lineClamp == other->rareNonInheritedData->lineClamp
&& rareInheritedData->textSizeAdjust == other->rareInheritedData->textSizeAdjust
&& rareInheritedData->overflowWrap == other->rareInheritedData->overflowWrap
&& rareInheritedData->nbspMode == other->rareInheritedData->nbspMode
&& rareInheritedData->lineBreak == other->rareInheritedData->lineBreak
&& rareInheritedData->textSecurity == other->rareInheritedData->textSecurity
&& inherited->specifiedLineHeight == other->inherited->specifiedLineHeight
&& inherited->font.equalForTextAutoSizing(other->inherited->font)
&& inherited->horizontal_border_spacing == other->inherited->horizontal_border_spacing
&& inherited->vertical_border_spacing == other->inherited->vertical_border_spacing
&& inherited_flags._box_direction == other->inherited_flags._box_direction
&& inherited_flags.m_rtlOrdering == other->inherited_flags.m_rtlOrdering
&& noninherited_flags._position == other->noninherited_flags._position
&& noninherited_flags._floating == other->noninherited_flags._floating
&& rareNonInheritedData->textOverflow == other->rareNonInheritedData->textOverflow;
}
#endif // ENABLE(IOS_TEXT_AUTOSIZING)
bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
{
// This is a fast check that only looks if the data structures are shared.
return inherited_flags == other->inherited_flags
&& inherited.get() == other->inherited.get()
#if ENABLE(SVG)
&& m_svgStyle.get() == other->m_svgStyle.get()
#endif
&& rareInheritedData.get() == other->rareInheritedData.get();
}
static bool positionChangeIsMovementOnly(const LengthBox& a, const LengthBox& b, const Length& width)
{
// If any unit types are different, then we can't guarantee
// that this was just a movement.
if (a.left().type() != b.left().type()
|| a.right().type() != b.right().type()
|| a.top().type() != b.top().type()
|| a.bottom().type() != b.bottom().type())
return false;
// Only one unit can be non-auto in the horizontal direction and
// in the vertical direction. Otherwise the adjustment of values
// is changing the size of the box.
if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto())
return false;
if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
return false;
// If our width is auto and left or right is specified then this
// is not just a movement - we need to resize to our container.
if ((!a.left().isIntrinsicOrAuto() || !a.right().isIntrinsicOrAuto()) && width.isIntrinsicOrAuto())
return false;
// One of the units is fixed or percent in both directions and stayed
// that way in the new style. Therefore all we are doing is moving.
return true;
}
bool RenderStyle::changeRequiresLayout(const RenderStyle* other, unsigned& changedContextSensitiveProperties) const
{
if (m_box->width() != other->m_box->width()
|| m_box->minWidth() != other->m_box->minWidth()
|| m_box->maxWidth() != other->m_box->maxWidth()
|| m_box->height() != other->m_box->height()
|| m_box->minHeight() != other->m_box->minHeight()
|| m_box->maxHeight() != other->m_box->maxHeight())
return true;
if (m_box->verticalAlign() != other->m_box->verticalAlign() || noninherited_flags._vertical_align != other->noninherited_flags._vertical_align)
return true;
if (m_box->boxSizing() != other->m_box->boxSizing())
return true;
if (surround->margin != other->surround->margin)
return true;
if (surround->padding != other->surround->padding)
return true;
if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
if (rareNonInheritedData->m_appearance != other->rareNonInheritedData->m_appearance
|| rareNonInheritedData->marginBeforeCollapse != other->rareNonInheritedData->marginBeforeCollapse
|| rareNonInheritedData->marginAfterCollapse != other->rareNonInheritedData->marginAfterCollapse
|| rareNonInheritedData->lineClamp != other->rareNonInheritedData->lineClamp
|| rareNonInheritedData->textOverflow != other->rareNonInheritedData->textOverflow)
return true;
if (rareNonInheritedData->m_regionFragment != other->rareNonInheritedData->m_regionFragment)
return true;
if (rareNonInheritedData->m_wrapFlow != other->rareNonInheritedData->m_wrapFlow
|| rareNonInheritedData->m_wrapThrough != other->rareNonInheritedData->m_wrapThrough)
return true;
#if ENABLE(CSS_SHAPES)
if (rareNonInheritedData->m_shapeMargin != other->rareNonInheritedData->m_shapeMargin
|| rareNonInheritedData->m_shapePadding != other->rareNonInheritedData->m_shapePadding)
return true;
#endif
if (rareNonInheritedData->m_deprecatedFlexibleBox.get() != other->rareNonInheritedData->m_deprecatedFlexibleBox.get()
&& *rareNonInheritedData->m_deprecatedFlexibleBox.get() != *other->rareNonInheritedData->m_deprecatedFlexibleBox.get())
return true;
if (rareNonInheritedData->m_flexibleBox.get() != other->rareNonInheritedData->m_flexibleBox.get()
&& *rareNonInheritedData->m_flexibleBox.get() != *other->rareNonInheritedData->m_flexibleBox.get())
return true;
if (rareNonInheritedData->m_order != other->rareNonInheritedData->m_order
|| rareNonInheritedData->m_alignContent != other->rareNonInheritedData->m_alignContent
|| rareNonInheritedData->m_alignItems != other->rareNonInheritedData->m_alignItems
|| rareNonInheritedData->m_alignSelf != other->rareNonInheritedData->m_alignSelf
|| rareNonInheritedData->m_justifyContent != other->rareNonInheritedData->m_justifyContent)
return true;
// FIXME: We should add an optimized form of layout that just recomputes visual overflow.
if (!rareNonInheritedData->shadowDataEquivalent(*other->rareNonInheritedData.get()))
return true;
if (!rareNonInheritedData->reflectionDataEquivalent(*other->rareNonInheritedData.get()))
return true;
if (rareNonInheritedData->m_multiCol.get() != other->rareNonInheritedData->m_multiCol.get()
&& *rareNonInheritedData->m_multiCol.get() != *other->rareNonInheritedData->m_multiCol.get())
return true;
if (rareNonInheritedData->m_transform.get() != other->rareNonInheritedData->m_transform.get()
&& *rareNonInheritedData->m_transform.get() != *other->rareNonInheritedData->m_transform.get()) {
#if USE(ACCELERATED_COMPOSITING)
changedContextSensitiveProperties |= ContextSensitivePropertyTransform;
// Don't return; keep looking for another change
#else
UNUSED_PARAM(changedContextSensitiveProperties);
return true;
#endif
}
if (rareNonInheritedData->m_grid.get() != other->rareNonInheritedData->m_grid.get()
|| rareNonInheritedData->m_gridItem.get() != other->rareNonInheritedData->m_gridItem.get())
return true;
#if !USE(ACCELERATED_COMPOSITING)
if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D
|| rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility
|| rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective
|| rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX
|| rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
return true;
}
#endif
#if ENABLE(DASHBOARD_SUPPORT)
// If regions change, trigger a relayout to re-calc regions.
if (rareNonInheritedData->m_dashboardRegions != other->rareNonInheritedData->m_dashboardRegions)
return true;
#endif
#if ENABLE(CSS_SHAPES)
if (rareNonInheritedData->m_shapeInside != other->rareNonInheritedData->m_shapeInside)
return true;
#endif
}
if (rareInheritedData.get() != other->rareInheritedData.get()) {
if (rareInheritedData->highlight != other->rareInheritedData->highlight
|| rareInheritedData->indent != other->rareInheritedData->indent
#if ENABLE(CSS3_TEXT)
|| rareInheritedData->m_textAlignLast != other->rareInheritedData->m_textAlignLast
|| rareInheritedData->m_textIndentLine != other->rareInheritedData->m_textIndentLine
#endif
|| rareInheritedData->m_effectiveZoom != other->rareInheritedData->m_effectiveZoom
#if ENABLE(IOS_TEXT_AUTOSIZING)
|| rareInheritedData->textSizeAdjust != other->rareInheritedData->textSizeAdjust
#endif
|| rareInheritedData->wordBreak != other->rareInheritedData->wordBreak
|| rareInheritedData->overflowWrap != other->rareInheritedData->overflowWrap
|| rareInheritedData->nbspMode != other->rareInheritedData->nbspMode
|| rareInheritedData->lineBreak != other->rareInheritedData->lineBreak
|| rareInheritedData->textSecurity != other->rareInheritedData->textSecurity
|| rareInheritedData->hyphens != other->rareInheritedData->hyphens
|| rareInheritedData->hyphenationLimitBefore != other->rareInheritedData->hyphenationLimitBefore
|| rareInheritedData->hyphenationLimitAfter != other->rareInheritedData->hyphenationLimitAfter
|| rareInheritedData->hyphenationString != other->rareInheritedData->hyphenationString
|| rareInheritedData->locale != other->rareInheritedData->locale
|| rareInheritedData->m_rubyPosition != other->rareInheritedData->m_rubyPosition
|| rareInheritedData->textEmphasisMark != other->rareInheritedData->textEmphasisMark
|| rareInheritedData->textEmphasisPosition != other->rareInheritedData->textEmphasisPosition
|| rareInheritedData->textEmphasisCustomMark != other->rareInheritedData->textEmphasisCustomMark
|| rareInheritedData->m_textOrientation != other->rareInheritedData->m_textOrientation
|| rareInheritedData->m_tabSize != other->rareInheritedData->m_tabSize
|| rareInheritedData->m_lineBoxContain != other->rareInheritedData->m_lineBoxContain
|| rareInheritedData->m_lineGrid != other->rareInheritedData->m_lineGrid
#if ENABLE(CSS_IMAGE_ORIENTATION)
|| rareInheritedData->m_imageOrientation != other->rareInheritedData->m_imageOrientation
#endif
#if ENABLE(CSS_IMAGE_RESOLUTION)
|| rareInheritedData->m_imageResolutionSource != other->rareInheritedData->m_imageResolutionSource
|| rareInheritedData->m_imageResolutionSnap != other->rareInheritedData->m_imageResolutionSnap
|| rareInheritedData->m_imageResolution != other->rareInheritedData->m_imageResolution
#endif
|| rareInheritedData->m_lineSnap != other->rareInheritedData->m_lineSnap
|| rareInheritedData->m_lineAlign != other->rareInheritedData->m_lineAlign
#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
|| rareInheritedData->useTouchOverflowScrolling != other->rareInheritedData->useTouchOverflowScrolling
#endif
|| rareInheritedData->listStyleImage != other->rareInheritedData->listStyleImage)
return true;
if (!rareInheritedData->shadowDataEquivalent(*other->rareInheritedData.get()))
return true;
if (textStrokeWidth() != other->textStrokeWidth())
return true;
}
#if ENABLE(TEXT_AUTOSIZING)
if (visual->m_textAutosizingMultiplier != other->visual->m_textAutosizingMultiplier)
return true;
#endif
if (inherited->line_height != other->inherited->line_height
#if ENABLE(IOS_TEXT_AUTOSIZING)
|| inherited->specifiedLineHeight != other->inherited->specifiedLineHeight
#endif
|| inherited->font != other->inherited->font
|| inherited->horizontal_border_spacing != other->inherited->horizontal_border_spacing
|| inherited->vertical_border_spacing != other->inherited->vertical_border_spacing
|| inherited_flags._box_direction != other->inherited_flags._box_direction
|| inherited_flags.m_rtlOrdering != other->inherited_flags.m_rtlOrdering
|| noninherited_flags._position != other->noninherited_flags._position
|| noninherited_flags._floating != other->noninherited_flags._floating
|| noninherited_flags._originalDisplay != other->noninherited_flags._originalDisplay)
return true;
if (((int)noninherited_flags._effectiveDisplay) >= TABLE) {
if (inherited_flags._border_collapse != other->inherited_flags._border_collapse
|| inherited_flags._empty_cells != other->inherited_flags._empty_cells
|| inherited_flags._caption_side != other->inherited_flags._caption_side
|| noninherited_flags._table_layout != other->noninherited_flags._table_layout)
return true;
// In the collapsing border model, 'hidden' suppresses other borders, while 'none'
// does not, so these style differences can be width differences.
if (inherited_flags._border_collapse
&& ((borderTopStyle() == BHIDDEN && other->borderTopStyle() == BNONE)
|| (borderTopStyle() == BNONE && other->borderTopStyle() == BHIDDEN)
|| (borderBottomStyle() == BHIDDEN && other->borderBottomStyle() == BNONE)
|| (borderBottomStyle() == BNONE && other->borderBottomStyle() == BHIDDEN)
|| (borderLeftStyle() == BHIDDEN && other->borderLeftStyle() == BNONE)
|| (borderLeftStyle() == BNONE && other->borderLeftStyle() == BHIDDEN)
|| (borderRightStyle() == BHIDDEN && other->borderRightStyle() == BNONE)
|| (borderRightStyle() == BNONE && other->borderRightStyle() == BHIDDEN)))
return true;
}
if (noninherited_flags._effectiveDisplay == LIST_ITEM) {
if (inherited_flags._list_style_type != other->inherited_flags._list_style_type
|| inherited_flags._list_style_position != other->inherited_flags._list_style_position)
return true;
}
if (inherited_flags._text_align != other->inherited_flags._text_align
|| inherited_flags._text_transform != other->inherited_flags._text_transform
|| inherited_flags._direction != other->inherited_flags._direction
|| inherited_flags._white_space != other->inherited_flags._white_space
|| noninherited_flags._clear != other->noninherited_flags._clear
|| noninherited_flags._unicodeBidi != other->noninherited_flags._unicodeBidi)
return true;
// Check block flow direction.
if (inherited_flags.m_writingMode != other->inherited_flags.m_writingMode)
return true;
// Check text combine mode.
if (rareNonInheritedData->m_textCombine != other->rareNonInheritedData->m_textCombine)
return true;
// Overflow returns a layout hint.
if (noninherited_flags._overflowX != other->noninherited_flags._overflowX
|| noninherited_flags._overflowY != other->noninherited_flags._overflowY)
return true;
// If our border widths change, then we need to layout. Other changes to borders
// only necessitate a repaint.
if (borderLeftWidth() != other->borderLeftWidth()
|| borderTopWidth() != other->borderTopWidth()
|| borderBottomWidth() != other->borderBottomWidth()
|| borderRightWidth() != other->borderRightWidth())
return true;
// If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
const CounterDirectiveMap* mapA = rareNonInheritedData->m_counterDirectives.get();
const CounterDirectiveMap* mapB = other->rareNonInheritedData->m_counterDirectives.get();
if (!(mapA == mapB || (mapA && mapB && *mapA == *mapB)))
return true;
if ((visibility() == COLLAPSE) != (other->visibility() == COLLAPSE))
return true;
if (rareNonInheritedData->hasOpacity() != other->rareNonInheritedData->hasOpacity()) {
// FIXME: We would like to use SimplifiedLayout here, but we can't quite do that yet.
// We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
// to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
// In addition we need to solve the floating object issue when layers come and go. Right now
// a full layout is necessary to keep floating object lists sane.
return true;
}
#if ENABLE(CSS_FILTERS)
if (rareNonInheritedData->hasFilters() != other->rareNonInheritedData->hasFilters())
return true;
#endif
const QuotesData* quotesDataA = rareInheritedData->quotes.get();
const QuotesData* quotesDataB = other->rareInheritedData->quotes.get();
if (!(quotesDataA == quotesDataB || (quotesDataA && quotesDataB && *quotesDataA == *quotesDataB)))
return true;
if (position() != StaticPosition) {
if (surround->offset != other->surround->offset) {
// FIXME: We would like to use SimplifiedLayout for relative positioning, but we can't quite do that yet.
// We need to make sure SimplifiedLayout can operate correctly on RenderInlines (we will need
// to add a selfNeedsSimplifiedLayout bit in order to not get confused and taint every line).
if (position() != AbsolutePosition)
return true;
// Optimize for the case where a positioned layer is moving but not changing size.
if (!positionChangeIsMovementOnly(surround->offset, other->surround->offset, m_box->width()))
return true;
}
}
return false;
}
bool RenderStyle::changeRequiresPositionedLayoutOnly(const RenderStyle* other, unsigned&) const
{
if (position() == StaticPosition)
return false;
if (surround->offset != other->surround->offset) {
// Optimize for the case where a positioned layer is moving but not changing size.
if (position() == AbsolutePosition && positionChangeIsMovementOnly(surround->offset, other->surround->offset, m_box->width()))
return true;
}
return false;
}
bool RenderStyle::changeRequiresLayerRepaint(const RenderStyle* other, unsigned& changedContextSensitiveProperties) const
{
if (position() != StaticPosition) {
if (m_box->zIndex() != other->m_box->zIndex()
|| m_box->hasAutoZIndex() != other->m_box->hasAutoZIndex()
|| visual->clip != other->visual->clip
|| visual->hasClip != other->visual->hasClip)
return true;
}
#if ENABLE(CSS_COMPOSITING)
if (rareNonInheritedData->m_effectiveBlendMode != other->rareNonInheritedData->m_effectiveBlendMode)
return true;
#endif
if (rareNonInheritedData->opacity != other->rareNonInheritedData->opacity) {
#if USE(ACCELERATED_COMPOSITING)
changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
// Don't return; keep looking for another change.
#else
UNUSED_PARAM(changedContextSensitiveProperties);
return true;
#endif
}
#if ENABLE(CSS_FILTERS)
if (rareNonInheritedData->m_filter.get() != other->rareNonInheritedData->m_filter.get()
&& *rareNonInheritedData->m_filter.get() != *other->rareNonInheritedData->m_filter.get()) {
#if USE(ACCELERATED_COMPOSITING)
changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
// Don't return; keep looking for another change.
#else
return true;
#endif
}
#endif
if (rareNonInheritedData->m_mask != other->rareNonInheritedData->m_mask
|| rareNonInheritedData->m_maskBoxImage != other->rareNonInheritedData->m_maskBoxImage)
return true;
return false;
}
bool RenderStyle::changeRequiresRepaint(const RenderStyle* other, unsigned&) const
{
if (inherited_flags._visibility != other->inherited_flags._visibility
|| inherited_flags.m_printColorAdjust != other->inherited_flags.m_printColorAdjust
|| inherited_flags._insideLink != other->inherited_flags._insideLink
|| surround->border != other->surround->border
|| !m_background->isEquivalentForPainting(*other->m_background)
|| rareInheritedData->userModify != other->rareInheritedData->userModify
|| rareInheritedData->userSelect != other->rareInheritedData->userSelect
|| rareNonInheritedData->userDrag != other->rareNonInheritedData->userDrag
|| rareNonInheritedData->m_borderFit != other->rareNonInheritedData->m_borderFit
|| rareNonInheritedData->m_objectFit != other->rareNonInheritedData->m_objectFit
|| rareInheritedData->m_imageRendering != other->rareInheritedData->m_imageRendering)
return true;
#if ENABLE(CSS_SHAPES)
// FIXME: The current spec is being reworked to remove dependencies between exclusions and affected
// content. There's a proposal to use floats instead. In that case, wrap-shape should actually relayout
// the parent container. For sure, I will have to revisit this code, but for now I've added this in order
// to avoid having diff() == StyleDifferenceEqual where wrap-shapes actually differ.
// Tracking bug: https://bugs.webkit.org/show_bug.cgi?id=62991
if (rareNonInheritedData->m_shapeOutside != other->rareNonInheritedData->m_shapeOutside)
return true;
#endif
if (rareNonInheritedData->m_clipPath != other->rareNonInheritedData->m_clipPath)
return true;
return false;
}
bool RenderStyle::changeRequiresRepaintIfTextOrBorderOrOutline(const RenderStyle* other, unsigned&) const
{
if (inherited->color != other->inherited->color
|| inherited_flags._text_decorations != other->inherited_flags._text_decorations
|| visual->textDecoration != other->visual->textDecoration
|| rareNonInheritedData->m_textDecorationStyle != other->rareNonInheritedData->m_textDecorationStyle
|| rareNonInheritedData->m_textDecorationColor != other->rareNonInheritedData->m_textDecorationColor
|| rareInheritedData->m_textDecorationSkip != other->rareInheritedData->m_textDecorationSkip
|| rareInheritedData->textFillColor != other->rareInheritedData->textFillColor
|| rareInheritedData->textStrokeColor != other->rareInheritedData->textStrokeColor
|| rareInheritedData->textEmphasisColor != other->rareInheritedData->textEmphasisColor
|| rareInheritedData->textEmphasisFill != other->rareInheritedData->textEmphasisFill)
return true;
return false;
}
bool RenderStyle::changeRequiresRecompositeLayer(const RenderStyle* other, unsigned&) const
{
#if USE(ACCELERATED_COMPOSITING)
if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D
|| rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility
|| rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective
|| rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX
|| rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
return true;
}
#else
UNUSED_PARAM(other);
#endif
return false;
}
StyleDifference RenderStyle::diff(const RenderStyle* other, unsigned& changedContextSensitiveProperties) const
{
changedContextSensitiveProperties = ContextSensitivePropertyNone;
#if ENABLE(SVG)
StyleDifference svgChange = StyleDifferenceEqual;
if (m_svgStyle != other->m_svgStyle) {
svgChange = m_svgStyle->diff(other->m_svgStyle.get());
if (svgChange == StyleDifferenceLayout)
return svgChange;
}
#endif
if (changeRequiresLayout(other, changedContextSensitiveProperties))
return StyleDifferenceLayout;
#if ENABLE(SVG)
// SVGRenderStyle::diff() might have returned StyleDifferenceRepaint, eg. if fill changes.
// If eg. the font-size changed at the same time, we're not allowed to return StyleDifferenceRepaint,
// but have to return StyleDifferenceLayout, that's why this if branch comes after all branches
// that are relevant for SVG and might return StyleDifferenceLayout.
if (svgChange != StyleDifferenceEqual)
return svgChange;
#endif
if (changeRequiresPositionedLayoutOnly(other, changedContextSensitiveProperties))
return StyleDifferenceLayoutPositionedMovementOnly;
if (changeRequiresLayerRepaint(other, changedContextSensitiveProperties))
return StyleDifferenceRepaintLayer;
if (changeRequiresRepaint(other, changedContextSensitiveProperties))
return StyleDifferenceRepaint;
#if USE(ACCELERATED_COMPOSITING)
if (changeRequiresRecompositeLayer(other, changedContextSensitiveProperties))
return StyleDifferenceRecompositeLayer;
#endif
if (changeRequiresRepaintIfTextOrBorderOrOutline(other, changedContextSensitiveProperties))
return StyleDifferenceRepaintIfTextOrBorderOrOutline;
// Cursors are not checked, since they will be set appropriately in response to mouse events,
// so they don't need to cause any repaint or layout.
// Animations don't need to be checked either. We always set the new style on the RenderObject, so we will get a chance to fire off
// the resulting transition properly.
return StyleDifferenceEqual;
}
bool RenderStyle::diffRequiresRepaint(const RenderStyle* style) const
{
unsigned changedContextSensitiveProperties = 0;
return changeRequiresRepaint(style, changedContextSensitiveProperties);
}
void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
{
StyleVisualData* data = visual.access();
data->clip.m_top = top;
data->clip.m_right = right;
data->clip.m_bottom = bottom;
data->clip.m_left = left;
}
void RenderStyle::addCursor(PassRefPtr<StyleImage> image, const IntPoint& hotSpot)
{
if (!rareInheritedData.access()->cursorData)
rareInheritedData.access()->cursorData = CursorList::create();
rareInheritedData.access()->cursorData->append(CursorData(image, hotSpot));
}
void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
{
rareInheritedData.access()->cursorData = other;
}
void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
{
if (rareInheritedData->quotes == q || (rareInheritedData->quotes && q && *rareInheritedData->quotes == *q))
return;
rareInheritedData.access()->quotes = q;
}
void RenderStyle::clearCursorList()
{
if (rareInheritedData->cursorData)
rareInheritedData.access()->cursorData = 0;
}
void RenderStyle::clearContent()
{
if (rareNonInheritedData->m_content)
rareNonInheritedData.access()->m_content = nullptr;
}
void RenderStyle::appendContent(std::unique_ptr<ContentData> contentData)
{
auto& content = rareNonInheritedData.access()->m_content;
ContentData* lastContent = content.get();
while (lastContent && lastContent->next())
lastContent = lastContent->next();
if (lastContent)
lastContent->setNext(std::move(contentData));
else
content = std::move(contentData);
}
void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
{
if (!image)
return;
if (add) {
appendContent(std::make_unique<ImageContentData>(image));
return;
}
rareNonInheritedData.access()->m_content = std::make_unique<ImageContentData>(image);
if (!rareNonInheritedData.access()->m_altText.isNull())
rareNonInheritedData.access()->m_content->setAltText(rareNonInheritedData.access()->m_altText);
}
void RenderStyle::setContent(const String& string, bool add)
{
auto& content = rareNonInheritedData.access()->m_content;
if (add) {
ContentData* lastContent = content.get();
while (lastContent && lastContent->next())
lastContent = lastContent->next();
if (lastContent) {
// We attempt to merge with the last ContentData if possible.
if (lastContent->isText()) {
TextContentData* textContent = static_cast<TextContentData*>(lastContent);
textContent->setText(textContent->text() + string);
} else
lastContent->setNext(std::make_unique<TextContentData>(string));
if (!rareNonInheritedData.access()->m_altText.isNull())
lastContent->setAltText(rareNonInheritedData.access()->m_altText);
return;
}
}
content = std::make_unique<TextContentData>(string);
if (!rareNonInheritedData.access()->m_altText.isNull())
content->setAltText(rareNonInheritedData.access()->m_altText);
}
void RenderStyle::setContent(std::unique_ptr<CounterContent> counter, bool add)
{
if (!counter)
return;
if (add) {
appendContent(std::make_unique<CounterContentData>(std::move(counter)));
return;
}
rareNonInheritedData.access()->m_content = std::make_unique<CounterContentData>(std::move(counter));
}
void RenderStyle::setContent(QuoteType quote, bool add)
{
if (add) {
appendContent(std::make_unique<QuoteContentData>(quote));
return;
}
rareNonInheritedData.access()->m_content = std::make_unique<QuoteContentData>(quote);
}
void RenderStyle::setContentAltText(const String& string)
{
rareNonInheritedData.access()->m_altText = string;
if (rareNonInheritedData.access()->m_content)
rareNonInheritedData.access()->m_content->setAltText(string);
}
const String& RenderStyle::contentAltText() const
{
return rareNonInheritedData->m_altText;
}
inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation>>& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
{
// transform-origin brackets the transform with translate operations.
// Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
// in that case.
if (applyOrigin != RenderStyle::IncludeTransformOrigin)
return false;
unsigned size = transformOperations.size();
for (unsigned i = 0; i < size; ++i) {
TransformOperation::OperationType type = transformOperations[i]->type();
if (type != TransformOperation::TRANSLATE_X
&& type != TransformOperation::TRANSLATE_Y
&& type != TransformOperation::TRANSLATE
&& type != TransformOperation::TRANSLATE_Z
&& type != TransformOperation::TRANSLATE_3D)
return true;
}
return false;
}
void RenderStyle::applyTransform(TransformationMatrix& transform, const LayoutSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
{
// FIXME: when subpixel layout is supported (bug 71143) the body of this function could be replaced by
// applyTransform(transform, FloatRect(FloatPoint(), borderBoxSize), applyOrigin);
const Vector<RefPtr<TransformOperation>>& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
if (applyTransformOrigin)
transform.translate3d(floatValueForLength(transformOriginX(), borderBoxSize.width()), floatValueForLength(transformOriginY(), borderBoxSize.height()), transformOriginZ());
unsigned size = transformOperations.size();
for (unsigned i = 0; i < size; ++i)
transformOperations[i]->apply(transform, borderBoxSize);
if (applyTransformOrigin)
transform.translate3d(-floatValueForLength(transformOriginX(), borderBoxSize.width()), -floatValueForLength(transformOriginY(), borderBoxSize.height()), -transformOriginZ());
}
void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, ApplyTransformOrigin applyOrigin) const
{
const Vector<RefPtr<TransformOperation>>& transformOperations = rareNonInheritedData->m_transform->m_operations.operations();
bool applyTransformOrigin = requireTransformOrigin(transformOperations, applyOrigin);
float offsetX = transformOriginX().type() == Percent ? boundingBox.x() : 0;
float offsetY = transformOriginY().type() == Percent ? boundingBox.y() : 0;
if (applyTransformOrigin) {
transform.translate3d(floatValueForLength(transformOriginX(), boundingBox.width()) + offsetX,
floatValueForLength(transformOriginY(), boundingBox.height()) + offsetY,
transformOriginZ());
}
unsigned size = transformOperations.size();
for (unsigned i = 0; i < size; ++i)
transformOperations[i]->apply(transform, boundingBox.size());
if (applyTransformOrigin) {
transform.translate3d(-floatValueForLength(transformOriginX(), boundingBox.width()) - offsetX,
-floatValueForLength(transformOriginY(), boundingBox.height()) - offsetY,
-transformOriginZ());
}
}
void RenderStyle::setPageScaleTransform(float scale)
{
if (scale == 1)
return;
TransformOperations transform;
transform.operations().append(ScaleTransformOperation::create(scale, scale, ScaleTransformOperation::SCALE));
setTransform(transform);
setTransformOriginX(Length(0, Fixed));
setTransformOriginY(Length(0, Fixed));
}
void RenderStyle::setTextShadow(PassOwnPtr<ShadowData> shadowData, bool add)
{
ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
StyleRareInheritedData* rareData = rareInheritedData.access();
if (!add) {
rareData->textShadow = shadowData;
return;
}
shadowData->setNext(rareData->textShadow.release());
rareData->textShadow = shadowData;
}
void RenderStyle::setBoxShadow(PassOwnPtr<ShadowData> shadowData, bool add)
{
StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
if (!add) {
rareData->m_boxShadow = shadowData;
return;
}
shadowData->setNext(rareData->m_boxShadow.release());
rareData->m_boxShadow = shadowData;
}
static RoundedRect::Radii calcRadiiFor(const BorderData& border, IntSize size, RenderView* renderView)
{
return RoundedRect::Radii(
IntSize(valueForLength(border.topLeft().width(), size.width(), renderView),
valueForLength(border.topLeft().height(), size.height(), renderView)),
IntSize(valueForLength(border.topRight().width(), size.width(), renderView),
valueForLength(border.topRight().height(), size.height(), renderView)),
IntSize(valueForLength(border.bottomLeft().width(), size.width(), renderView),
valueForLength(border.bottomLeft().height(), size.height(), renderView)),
IntSize(valueForLength(border.bottomRight().width(), size.width(), renderView),
valueForLength(border.bottomRight().height(), size.height(), renderView)));
}
static float calcConstraintScaleFor(const IntRect& rect, const RoundedRect::Radii& radii)
{
// Constrain corner radii using CSS3 rules:
// http://www.w3.org/TR/css3-background/#the-border-radius
float factor = 1;
unsigned radiiSum;
// top
radiiSum = static_cast<unsigned>(radii.topLeft().width()) + static_cast<unsigned>(radii.topRight().width()); // Casts to avoid integer overflow.
if (radiiSum > static_cast<unsigned>(rect.width()))
factor = std::min(static_cast<float>(rect.width()) / radiiSum, factor);
// bottom
radiiSum = static_cast<unsigned>(radii.bottomLeft().width()) + static_cast<unsigned>(radii.bottomRight().width());
if (radiiSum > static_cast<unsigned>(rect.width()))
factor = std::min(static_cast<float>(rect.width()) / radiiSum, factor);
// left
radiiSum = static_cast<unsigned>(radii.topLeft().height()) + static_cast<unsigned>(radii.bottomLeft().height());
if (radiiSum > static_cast<unsigned>(rect.height()))
factor = std::min(static_cast<float>(rect.height()) / radiiSum, factor);
// right
radiiSum = static_cast<unsigned>(radii.topRight().height()) + static_cast<unsigned>(radii.bottomRight().height());
if (radiiSum > static_cast<unsigned>(rect.height()))
factor = std::min(static_cast<float>(rect.height()) / radiiSum, factor);
ASSERT(factor <= 1);
return factor;
}
StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->listStyleImage.get(); }
void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
{
if (rareInheritedData->listStyleImage != v)
rareInheritedData.access()->listStyleImage = v;
}
Color RenderStyle::color() const { return inherited->color; }
Color RenderStyle::visitedLinkColor() const { return inherited->visitedLinkColor; }
void RenderStyle::setColor(const Color& v) { SET_VAR(inherited, color, v); }
void RenderStyle::setVisitedLinkColor(const Color& v) { SET_VAR(inherited, visitedLinkColor, v); }
short RenderStyle::horizontalBorderSpacing() const { return inherited->horizontal_border_spacing; }
short RenderStyle::verticalBorderSpacing() const { return inherited->vertical_border_spacing; }
void RenderStyle::setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horizontal_border_spacing, v); }
void RenderStyle::setVerticalBorderSpacing(short v) { SET_VAR(inherited, vertical_border_spacing, v); }
RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, RenderView* renderView, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
IntRect snappedBorderRect(pixelSnappedIntRect(borderRect));
RoundedRect roundedRect(snappedBorderRect);
if (hasBorderRadius()) {
RoundedRect::Radii radii = calcRadiiFor(surround->border, snappedBorderRect.size(), renderView);
radii.scale(calcConstraintScaleFor(snappedBorderRect, radii));
roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
}
return roundedRect;
}
RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
bool horizontal = isHorizontalWritingMode();
int leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
int rightWidth = (!horizontal || includeLogicalRightEdge) ? borderRightWidth() : 0;
int topWidth = (horizontal || includeLogicalLeftEdge) ? borderTopWidth() : 0;
int bottomWidth = (horizontal || includeLogicalRightEdge) ? borderBottomWidth() : 0;
return getRoundedInnerBorderFor(borderRect, topWidth, bottomWidth, leftWidth, rightWidth, includeLogicalLeftEdge, includeLogicalRightEdge);
}
RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect,
int topWidth, int bottomWidth, int leftWidth, int rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
LayoutRect innerRect(borderRect.x() + leftWidth,
borderRect.y() + topWidth,
borderRect.width() - leftWidth - rightWidth,
borderRect.height() - topWidth - bottomWidth);
RoundedRect roundedRect(pixelSnappedIntRect(innerRect));
if (hasBorderRadius()) {
RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includeLogicalLeftEdge, includeLogicalRightEdge);
}
return roundedRect;
}
static bool allLayersAreFixed(const FillLayer* layer)
{
bool allFixed = true;
for (const FillLayer* currLayer = layer; currLayer; currLayer = currLayer->next())
allFixed &= (currLayer->image() && currLayer->attachment() == FixedBackgroundAttachment);
return layer && allFixed;
}
bool RenderStyle::hasEntirelyFixedBackground() const
{
return allLayersAreFixed(backgroundLayers());
}
const CounterDirectiveMap* RenderStyle::counterDirectives() const
{
return rareNonInheritedData->m_counterDirectives.get();
}
CounterDirectiveMap& RenderStyle::accessCounterDirectives()
{
OwnPtr<CounterDirectiveMap>& map = rareNonInheritedData.access()->m_counterDirectives;
if (!map)
map = adoptPtr(new CounterDirectiveMap);
return *map;
}
const CounterDirectives RenderStyle::getCounterDirectives(const AtomicString& identifier) const
{
if (const CounterDirectiveMap* directives = counterDirectives())
return directives->get(identifier);
return CounterDirectives();
}
const AtomicString& RenderStyle::hyphenString() const
{
ASSERT(hyphens() != HyphensNone);
const AtomicString& hyphenationString = rareInheritedData.get()->hyphenationString;
if (!hyphenationString.isNull())
return hyphenationString;
// FIXME: This should depend on locale.
DEFINE_STATIC_LOCAL(AtomicString, hyphenMinusString, (&hyphenMinus, 1));
DEFINE_STATIC_LOCAL(AtomicString, hyphenString, (&hyphen, 1));
return font().primaryFontHasGlyphForCharacter(hyphen) ? hyphenString : hyphenMinusString;
}
const AtomicString& RenderStyle::textEmphasisMarkString() const
{
switch (textEmphasisMark()) {
case TextEmphasisMarkNone:
return nullAtom;
case TextEmphasisMarkCustom:
return textEmphasisCustomMark();
case TextEmphasisMarkDot: {
DEFINE_STATIC_LOCAL(AtomicString, filledDotString, (&bullet, 1));
DEFINE_STATIC_LOCAL(AtomicString, openDotString, (&whiteBullet, 1));
return textEmphasisFill() == TextEmphasisFillFilled ? filledDotString : openDotString;
}
case TextEmphasisMarkCircle: {
DEFINE_STATIC_LOCAL(AtomicString, filledCircleString, (&blackCircle, 1));
DEFINE_STATIC_LOCAL(AtomicString, openCircleString, (&whiteCircle, 1));
return textEmphasisFill() == TextEmphasisFillFilled ? filledCircleString : openCircleString;
}
case TextEmphasisMarkDoubleCircle: {
DEFINE_STATIC_LOCAL(AtomicString, filledDoubleCircleString, (&fisheye, 1));
DEFINE_STATIC_LOCAL(AtomicString, openDoubleCircleString, (&bullseye, 1));
return textEmphasisFill() == TextEmphasisFillFilled ? filledDoubleCircleString : openDoubleCircleString;
}
case TextEmphasisMarkTriangle: {
DEFINE_STATIC_LOCAL(AtomicString, filledTriangleString, (&blackUpPointingTriangle, 1));
DEFINE_STATIC_LOCAL(AtomicString, openTriangleString, (&whiteUpPointingTriangle, 1));
return textEmphasisFill() == TextEmphasisFillFilled ? filledTriangleString : openTriangleString;
}
case TextEmphasisMarkSesame: {
DEFINE_STATIC_LOCAL(AtomicString, filledSesameString, (&sesameDot, 1));
DEFINE_STATIC_LOCAL(AtomicString, openSesameString, (&whiteSesameDot, 1));
return textEmphasisFill() == TextEmphasisFillFilled ? filledSesameString : openSesameString;
}
case TextEmphasisMarkAuto:
ASSERT_NOT_REACHED();
return nullAtom;
}
ASSERT_NOT_REACHED();
return nullAtom;
}
#if ENABLE(DASHBOARD_SUPPORT)
const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
{
DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, emptyList, ());
return emptyList;
}
const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
{
DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, noneList, ());
static bool noneListInitialized = false;
if (!noneListInitialized) {
StyleDashboardRegion region;
region.label = "";
region.offset.m_top = Length();
region.offset.m_right = Length();
region.offset.m_bottom = Length();
region.offset.m_left = Length();
region.type = StyleDashboardRegion::None;
noneList.append(region);
noneListInitialized = true;
}
return noneList;
}
#endif
void RenderStyle::adjustAnimations()
{
AnimationList* animationList = rareNonInheritedData->m_animations.get();
if (!animationList)
return;
// Get rid of empty animations and anything beyond them
for (size_t i = 0; i < animationList->size(); ++i) {
if (animationList->animation(i).isEmpty()) {
animationList->resize(i);
break;
}
}
if (animationList->isEmpty()) {
clearAnimations();
return;
}
// Repeat patterns into layers that don't have some properties set.
animationList->fillUnsetProperties();
}
void RenderStyle::adjustTransitions()
{
AnimationList* transitionList = rareNonInheritedData->m_transitions.get();
if (!transitionList)
return;
// Get rid of empty transitions and anything beyond them
for (size_t i = 0; i < transitionList->size(); ++i) {
if (transitionList->animation(i).isEmpty()) {
transitionList->resize(i);
break;
}
}
if (transitionList->isEmpty()) {
clearTransitions();
return;
}
// Repeat patterns into layers that don't have some properties set.
transitionList->fillUnsetProperties();
// Make sure there are no duplicate properties. This is an O(n^2) algorithm
// but the lists tend to be very short, so it is probably ok
for (size_t i = 0; i < transitionList->size(); ++i) {
for (size_t j = i+1; j < transitionList->size(); ++j) {
if (transitionList->animation(i).property() == transitionList->animation(j).property()) {
// toss i
transitionList->remove(i);
j = i;
}
}
}
}
AnimationList* RenderStyle::accessAnimations()
{
if (!rareNonInheritedData.access()->m_animations)
rareNonInheritedData.access()->m_animations = adoptPtr(new AnimationList());
return rareNonInheritedData->m_animations.get();
}
AnimationList* RenderStyle::accessTransitions()
{
if (!rareNonInheritedData.access()->m_transitions)
rareNonInheritedData.access()->m_transitions = adoptPtr(new AnimationList());
return rareNonInheritedData->m_transitions.get();
}
const Animation* RenderStyle::transitionForProperty(CSSPropertyID property) const
{
if (transitions()) {
for (size_t i = 0; i < transitions()->size(); ++i) {
const Animation& p = transitions()->animation(i);
if (p.animationMode() == Animation::AnimateAll || p.property() == property) {
return &p;
}
}
}
return 0;
}
const Font& RenderStyle::font() const { return inherited->font; }
const FontMetrics& RenderStyle::fontMetrics() const { return inherited->font.fontMetrics(); }
const FontDescription& RenderStyle::fontDescription() const { return inherited->font.fontDescription(); }
float RenderStyle::specifiedFontSize() const { return fontDescription().specifiedSize(); }
float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
int RenderStyle::fontSize() const { return inherited->font.pixelSize(); }
const Length& RenderStyle::wordSpacing() const { return rareInheritedData->wordSpacing; }
float RenderStyle::letterSpacing() const { return inherited->font.letterSpacing(); }
bool RenderStyle::setFontDescription(const FontDescription& v)
{
if (inherited->font.fontDescription() != v) {
inherited.access()->font = Font(v, inherited->font.letterSpacing(), inherited->font.wordSpacing());
return true;
}
return false;
}
#if ENABLE(IOS_TEXT_AUTOSIZING)
const Length& RenderStyle::specifiedLineHeight() const { return inherited->specifiedLineHeight; }
void RenderStyle::setSpecifiedLineHeight(Length v) { SET_VAR(inherited, specifiedLineHeight, v); }
#else
const Length& RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
#endif
Length RenderStyle::lineHeight() const
{
const Length& lh = inherited->line_height;
#if ENABLE(TEXT_AUTOSIZING)
// Unlike fontDescription().computedSize() and hence fontSize(), this is
// recalculated on demand as we only store the specified line height.
// FIXME: Should consider scaling the fixed part of any calc expressions
// too, though this involves messily poking into CalcExpressionLength.
float multiplier = textAutosizingMultiplier();
if (multiplier > 1 && lh.isFixed())
return Length(TextAutosizer::computeAutosizedFontSize(lh.value(), multiplier), Fixed);
#endif
return lh;
}
void RenderStyle::setLineHeight(Length specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
int RenderStyle::computedLineHeight(RenderView* renderView) const
{
const Length& lh = lineHeight();
// Negative value means the line height is not set. Use the font's built-in spacing.
if (lh.isNegative())
return fontMetrics().lineSpacing();
if (lh.isPercent())
return minimumValueForLength(lh, fontSize());
if (lh.isViewportPercentage())
return valueForLength(lh, 0, renderView);
return lh.value();
}
void RenderStyle::setWordSpacing(Length v)
{
float fontWordSpacing;
switch (v.type()) {
case Auto:
fontWordSpacing = 0;
FALLTHROUGH;
case Percent:
fontWordSpacing = v.getFloatValue() * font().spaceWidth() / 100;
break;
case Fixed:
fontWordSpacing = v.getFloatValue();
break;
case Calculated:
fontWordSpacing = v.nonNanCalculatedValue(maxValueForCssLength);
break;
default:
ASSERT_NOT_REACHED();
fontWordSpacing = 0;
break;
}
inherited.access()->font.setWordSpacing(fontWordSpacing);
rareInheritedData.access()->wordSpacing = std::move(v);
}
void RenderStyle::setLetterSpacing(float v) { inherited.access()->font.setLetterSpacing(v); }
void RenderStyle::setFontSize(float size)
{
// size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
// zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
ASSERT(std::isfinite(size));
if (!std::isfinite(size) || size < 0)
size = 0;
else
size = std::min(maximumAllowedFontSize, size);
FontSelector* currentFontSelector = font().fontSelector();
FontDescription desc(fontDescription());
desc.setSpecifiedSize(size);
desc.setComputedSize(size);
#if ENABLE(TEXT_AUTOSIZING)
float multiplier = textAutosizingMultiplier();
if (multiplier > 1) {
float autosizedFontSize = TextAutosizer::computeAutosizedFontSize(size, multiplier);
desc.setComputedSize(min(maximumAllowedFontSize, autosizedFontSize));
}
#endif
setFontDescription(desc);
font().update(currentFontSelector);
}
void RenderStyle::getShadowExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
{
top = 0;
right = 0;
bottom = 0;
left = 0;
for ( ; shadow; shadow = shadow->next()) {
if (shadow->style() == Inset)
continue;
int extentAndSpread = shadow->paintingExtent() + shadow->spread();
top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
}
}
LayoutBoxExtent RenderStyle::getShadowInsetExtent(const ShadowData* shadow) const
{
LayoutUnit top = 0;
LayoutUnit right = 0;
LayoutUnit bottom = 0;
LayoutUnit left = 0;
for ( ; shadow; shadow = shadow->next()) {
if (shadow->style() == Normal)
continue;
int extentAndSpread = shadow->paintingExtent() + shadow->spread();
top = std::max<LayoutUnit>(top, shadow->y() + extentAndSpread);
right = std::min<LayoutUnit>(right, shadow->x() - extentAndSpread);
bottom = std::min<LayoutUnit>(bottom, shadow->y() - extentAndSpread);
left = std::max<LayoutUnit>(left, shadow->x() + extentAndSpread);
}
return LayoutBoxExtent(top, right, bottom, left);
}
void RenderStyle::getShadowHorizontalExtent(const ShadowData* shadow, LayoutUnit &left, LayoutUnit &right) const
{
left = 0;
right = 0;
for ( ; shadow; shadow = shadow->next()) {
if (shadow->style() == Inset)
continue;
int extentAndSpread = shadow->paintingExtent() + shadow->spread();
left = std::min<LayoutUnit>(left, shadow->x() - extentAndSpread);
right = std::max<LayoutUnit>(right, shadow->x() + extentAndSpread);
}
}
void RenderStyle::getShadowVerticalExtent(const ShadowData* shadow, LayoutUnit &top, LayoutUnit &bottom) const
{
top = 0;
bottom = 0;
for ( ; shadow; shadow = shadow->next()) {
if (shadow->style() == Inset)
continue;
int extentAndSpread = shadow->paintingExtent() + shadow->spread();
top = std::min<LayoutUnit>(top, shadow->y() - extentAndSpread);
bottom = std::max<LayoutUnit>(bottom, shadow->y() + extentAndSpread);
}
}
Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) const
{
Color result;
EBorderStyle borderStyle = BNONE;
switch (colorProperty) {
case CSSPropertyBackgroundColor:
return visitedLink ? visitedLinkBackgroundColor() : backgroundColor(); // Background color doesn't fall back.
case CSSPropertyBorderLeftColor:
result = visitedLink ? visitedLinkBorderLeftColor() : borderLeftColor();
borderStyle = borderLeftStyle();
break;
case CSSPropertyBorderRightColor:
result = visitedLink ? visitedLinkBorderRightColor() : borderRightColor();
borderStyle = borderRightStyle();
break;
case CSSPropertyBorderTopColor:
result = visitedLink ? visitedLinkBorderTopColor() : borderTopColor();
borderStyle = borderTopStyle();
break;
case CSSPropertyBorderBottomColor:
result = visitedLink ? visitedLinkBorderBottomColor() : borderBottomColor();
borderStyle = borderBottomStyle();
break;
case CSSPropertyColor:
result = visitedLink ? visitedLinkColor() : color();
break;
case CSSPropertyOutlineColor:
result = visitedLink ? visitedLinkOutlineColor() : outlineColor();
break;
case CSSPropertyWebkitColumnRuleColor:
result = visitedLink ? visitedLinkColumnRuleColor() : columnRuleColor();
break;
case CSSPropertyWebkitTextDecorationColor:
// Text decoration color fallback is handled in RenderObject::decorationColor.
return visitedLink ? visitedLinkTextDecorationColor() : textDecorationColor();
case CSSPropertyWebkitTextEmphasisColor:
result = visitedLink ? visitedLinkTextEmphasisColor() : textEmphasisColor();
break;
case CSSPropertyWebkitTextFillColor:
result = visitedLink ? visitedLinkTextFillColor() : textFillColor();
break;
case CSSPropertyWebkitTextStrokeColor:
result = visitedLink ? visitedLinkTextStrokeColor() : textStrokeColor();
break;
default:
ASSERT_NOT_REACHED();
break;
}
if (!result.isValid()) {
if (!visitedLink && (borderStyle == INSET || borderStyle == OUTSET || borderStyle == RIDGE || borderStyle == GROOVE))
result.setRGB(238, 238, 238);
else
result = visitedLink ? visitedLinkColor() : color();
}
return result;
}
Color RenderStyle::visitedDependentColor(int colorProperty) const
{
Color unvisitedColor = colorIncludingFallback(colorProperty, false);
if (insideLink() != InsideVisitedLink)
return unvisitedColor;
Color visitedColor = colorIncludingFallback(colorProperty, true);
// Text decoration color validity is preserved (checked in RenderObject::decorationColor).
if (colorProperty == CSSPropertyWebkitTextDecorationColor)
return visitedColor;
// FIXME: Technically someone could explicitly specify the color transparent, but for now we'll just
// assume that if the background color is transparent that it wasn't set. Note that it's weird that
// we're returning unvisited info for a visited link, but given our restriction that the alpha values
// have to match, it makes more sense to return the unvisited background color if specified than it
// does to return black. This behavior matches what Firefox 4 does as well.
if (colorProperty == CSSPropertyBackgroundColor && visitedColor == Color::transparent)
return unvisitedColor;
// Take the alpha from the unvisited color, but get the RGB values from the visited color.
return Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), unvisitedColor.alpha());
}
const BorderValue& RenderStyle::borderBefore() const
{
switch (writingMode()) {
case TopToBottomWritingMode:
return borderTop();
case BottomToTopWritingMode:
return borderBottom();
case LeftToRightWritingMode:
return borderLeft();
case RightToLeftWritingMode:
return borderRight();
}
ASSERT_NOT_REACHED();
return borderTop();
}
const BorderValue& RenderStyle::borderAfter() const
{
switch (writingMode()) {
case TopToBottomWritingMode:
return borderBottom();
case BottomToTopWritingMode:
return borderTop();
case LeftToRightWritingMode:
return borderRight();
case RightToLeftWritingMode:
return borderLeft();
}
ASSERT_NOT_REACHED();
return borderBottom();
}
const BorderValue& RenderStyle::borderStart() const
{
if (isHorizontalWritingMode())
return isLeftToRightDirection() ? borderLeft() : borderRight();
return isLeftToRightDirection() ? borderTop() : borderBottom();
}
const BorderValue& RenderStyle::borderEnd() const
{
if (isHorizontalWritingMode())
return isLeftToRightDirection() ? borderRight() : borderLeft();
return isLeftToRightDirection() ? borderBottom() : borderTop();
}
unsigned short RenderStyle::borderBeforeWidth() const
{
switch (writingMode()) {
case TopToBottomWritingMode:
return borderTopWidth();
case BottomToTopWritingMode:
return borderBottomWidth();
case LeftToRightWritingMode:
return borderLeftWidth();
case RightToLeftWritingMode:
return borderRightWidth();
}
ASSERT_NOT_REACHED();
return borderTopWidth();
}
unsigned short RenderStyle::borderAfterWidth() const
{
switch (writingMode()) {
case TopToBottomWritingMode:
return borderBottomWidth();
case BottomToTopWritingMode:
return borderTopWidth();
case LeftToRightWritingMode:
return borderRightWidth();
case RightToLeftWritingMode:
return borderLeftWidth();
}
ASSERT_NOT_REACHED();
return borderBottomWidth();
}
unsigned short RenderStyle::borderStartWidth() const
{
if (isHorizontalWritingMode())
return isLeftToRightDirection() ? borderLeftWidth() : borderRightWidth();
return isLeftToRightDirection() ? borderTopWidth() : borderBottomWidth();
}
unsigned short RenderStyle::borderEndWidth() const
{
if (isHorizontalWritingMode())
return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
}
void RenderStyle::setMarginStart(Length margin)
{
if (isHorizontalWritingMode()) {
if (isLeftToRightDirection())
setMarginLeft(margin);
else
setMarginRight(margin);
} else {
if (isLeftToRightDirection())
setMarginTop(margin);
else
setMarginBottom(margin);
}
}
void RenderStyle::setMarginEnd(Length margin)
{
if (isHorizontalWritingMode()) {
if (isLeftToRightDirection())
setMarginRight(margin);
else
setMarginLeft(margin);
} else {
if (isLeftToRightDirection())
setMarginBottom(margin);
else
setMarginTop(margin);
}
}
TextEmphasisMark RenderStyle::textEmphasisMark() const
{
TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
if (mark != TextEmphasisMarkAuto)
return mark;
if (isHorizontalWritingMode())
return TextEmphasisMarkDot;
return TextEmphasisMarkSesame;
}
#if ENABLE(TOUCH_EVENTS)
Color RenderStyle::initialTapHighlightColor()
{
return RenderTheme::tapHighlightColor();
}
#endif
LayoutBoxExtent RenderStyle::imageOutsets(const NinePieceImage& image) const
{
return LayoutBoxExtent(NinePieceImage::computeOutset(image.outset().top(), borderTopWidth()),
NinePieceImage::computeOutset(image.outset().right(), borderRightWidth()),
NinePieceImage::computeOutset(image.outset().bottom(), borderBottomWidth()),
NinePieceImage::computeOutset(image.outset().left(), borderLeftWidth()));
}
void RenderStyle::getFontAndGlyphOrientation(FontOrientation& fontOrientation, NonCJKGlyphOrientation& glyphOrientation)
{
if (isHorizontalWritingMode()) {
fontOrientation = Horizontal;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
return;
}
switch (textOrientation()) {
case TextOrientationVerticalRight:
fontOrientation = Vertical;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
return;
case TextOrientationUpright:
fontOrientation = Vertical;
glyphOrientation = NonCJKGlyphOrientationUpright;
return;
case TextOrientationSideways:
if (writingMode() == LeftToRightWritingMode) {
// FIXME: This should map to sideways-left, which is not supported yet.
fontOrientation = Vertical;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
return;
}
fontOrientation = Horizontal;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
return;
case TextOrientationSidewaysRight:
fontOrientation = Horizontal;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
return;
default:
ASSERT_NOT_REACHED();
fontOrientation = Horizontal;
glyphOrientation = NonCJKGlyphOrientationVerticalRight;
return;
}
}
void RenderStyle::setBorderImageSource(PassRefPtr<StyleImage> image)
{
if (surround->border.m_image.image() == image.get())
return;
surround.access()->border.m_image.setImage(image);
}
void RenderStyle::setBorderImageSlices(LengthBox slices)
{
if (surround->border.m_image.imageSlices() == slices)
return;
surround.access()->border.m_image.setImageSlices(slices);
}
void RenderStyle::setBorderImageWidth(LengthBox slices)
{
if (surround->border.m_image.borderSlices() == slices)
return;
surround.access()->border.m_image.setBorderSlices(slices);
}
void RenderStyle::setBorderImageOutset(LengthBox outset)
{
if (surround->border.m_image.outset() == outset)
return;
surround.access()->border.m_image.setOutset(outset);
}
void RenderStyle::setColumnStylesFromPaginationMode(const Pagination::Mode& paginationMode)
{
if (paginationMode == Pagination::Unpaginated)
return;
switch (paginationMode) {
case Pagination::LeftToRightPaginated:
setColumnAxis(HorizontalColumnAxis);
if (isHorizontalWritingMode())
setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
else
setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
break;
case Pagination::RightToLeftPaginated:
setColumnAxis(HorizontalColumnAxis);
if (isHorizontalWritingMode())
setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
else
setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
break;
case Pagination::TopToBottomPaginated:
setColumnAxis(VerticalColumnAxis);
if (isHorizontalWritingMode())
setColumnProgression(isFlippedBlocksWritingMode() ? ReverseColumnProgression : NormalColumnProgression);
else
setColumnProgression(isLeftToRightDirection() ? NormalColumnProgression : ReverseColumnProgression);
break;
case Pagination::BottomToTopPaginated:
setColumnAxis(VerticalColumnAxis);
if (isHorizontalWritingMode())
setColumnProgression(isFlippedBlocksWritingMode() ? NormalColumnProgression : ReverseColumnProgression);
else
setColumnProgression(isLeftToRightDirection() ? ReverseColumnProgression : NormalColumnProgression);
break;
case Pagination::Unpaginated:
ASSERT_NOT_REACHED();
break;
}
}
} // namespace WebCore
|