1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
|
/*
* 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 "third_party/blink/renderer/core/style/computed_style.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "build/build_config.h"
#include "cc/input/overscroll_behavior.h"
#include "third_party/blink/renderer/core/animation/css/css_animation_data.h"
#include "third_party/blink/renderer/core/animation/css/css_transition_data.h"
#include "third_party/blink/renderer/core/css/css_paint_value.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/css_property_equality.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
#include "third_party/blink/renderer/core/css/properties/longhand.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/layout/custom/layout_worklet.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/layout/text_autosizer.h"
#include "third_party/blink/renderer/core/style/applied_text_decoration.h"
#include "third_party/blink/renderer/core/style/border_edge.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/style/computed_style_initial_values.h"
#include "third_party/blink/renderer/core/style/content_data.h"
#include "third_party/blink/renderer/core/style/cursor_data.h"
#include "third_party/blink/renderer/core/style/data_equivalency.h"
#include "third_party/blink/renderer/core/style/quotes_data.h"
#include "third_party/blink/renderer/core/style/shadow_list.h"
#include "third_party/blink/renderer/core/style/style_difference.h"
#include "third_party/blink/renderer/core/style/style_image.h"
#include "third_party/blink/renderer/core/style/style_inherited_variables.h"
#include "third_party/blink/renderer/core/style/style_non_inherited_variables.h"
#include "third_party/blink/renderer/core/style/style_ray.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/font_selector.h"
#include "third_party/blink/renderer/platform/geometry/float_rounded_rect.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
#include "third_party/blink/renderer/platform/graphics/path.h"
#include "third_party/blink/renderer/platform/length_functions.h"
#include "third_party/blink/renderer/platform/text/capitalize.h"
#include "third_party/blink/renderer/platform/transforms/rotate_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/scale_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/translate_transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/saturated_arithmetic.h"
#include "third_party/blink/renderer/platform/wtf/size_assertions.h"
namespace blink {
struct SameSizeAsBorderValue {
RGBA32 color_;
unsigned bitfield_;
};
ASSERT_SIZE(BorderValue, SameSizeAsBorderValue);
// Since different compilers/architectures pack ComputedStyle differently,
// re-create the same structure for an accurate size comparison.
struct SameSizeAsComputedStyle : public RefCounted<SameSizeAsComputedStyle> {
struct ComputedStyleBase {
void* data_refs[7];
unsigned bitfields_[4];
} base_;
void* own_ptrs[1];
void* data_ref_svg_style;
};
// If this assert fails, it means that size of ComputedStyle has changed. Please
// check that you really *do* what to increase the size of ComputedStyle, then
// update the SameSizeAsComputedStyle struct to match the updated storage of
// ComputedStyle.
ASSERT_SIZE(ComputedStyle, SameSizeAsComputedStyle);
scoped_refptr<ComputedStyle> ComputedStyle::Create() {
return base::AdoptRef(new ComputedStyle(InitialStyle()));
}
scoped_refptr<ComputedStyle> ComputedStyle::CreateInitialStyle() {
return base::AdoptRef(new ComputedStyle());
}
ComputedStyle& ComputedStyle::MutableInitialStyle() {
LEAK_SANITIZER_DISABLED_SCOPE;
DEFINE_STATIC_REF(ComputedStyle, initial_style,
(ComputedStyle::CreateInitialStyle()));
return *initial_style;
}
void ComputedStyle::InvalidateInitialStyle() {
MutableInitialStyle().SetTapHighlightColor(
ComputedStyleInitialValues::InitialTapHighlightColor());
}
scoped_refptr<ComputedStyle> ComputedStyle::CreateAnonymousStyleWithDisplay(
const ComputedStyle& parent_style,
EDisplay display) {
scoped_refptr<ComputedStyle> new_style = ComputedStyle::Create();
new_style->InheritFrom(parent_style);
new_style->SetUnicodeBidi(parent_style.GetUnicodeBidi());
new_style->SetDisplay(display);
return new_style;
}
scoped_refptr<ComputedStyle>
ComputedStyle::CreateInheritedDisplayContentsStyleIfNeeded(
const ComputedStyle& parent_style,
const ComputedStyle& layout_parent_style) {
if (&parent_style == &layout_parent_style)
return nullptr;
if (parent_style.InheritedEqual(layout_parent_style))
return nullptr;
return ComputedStyle::CreateAnonymousStyleWithDisplay(parent_style,
EDisplay::kInline);
}
scoped_refptr<ComputedStyle> ComputedStyle::Clone(const ComputedStyle& other) {
return base::AdoptRef(new ComputedStyle(other));
}
ALWAYS_INLINE ComputedStyle::ComputedStyle()
: ComputedStyleBase(), RefCounted<ComputedStyle>() {
svg_style_.Init();
}
ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o)
: ComputedStyleBase(o),
RefCounted<ComputedStyle>(),
svg_style_(o.svg_style_) {}
static StyleRecalcChange DiffPseudoStyles(const ComputedStyle& old_style,
const ComputedStyle& new_style) {
// If the pseudoStyles have changed, ensure layoutObject triggers setStyle.
if (!old_style.HasAnyPublicPseudoStyles() &&
!new_style.HasAnyPublicPseudoStyles())
return kNoChange;
for (PseudoId pseudo_id = kFirstPublicPseudoId;
pseudo_id < kFirstInternalPseudoId;
pseudo_id = static_cast<PseudoId>(pseudo_id + 1)) {
if (!old_style.HasPseudoStyle(pseudo_id) &&
!new_style.HasPseudoStyle(pseudo_id))
continue;
const ComputedStyle* new_pseudo_style =
new_style.GetCachedPseudoStyle(pseudo_id);
if (!new_pseudo_style)
return kNoInherit;
const ComputedStyle* old_pseudo_style =
old_style.GetCachedPseudoStyle(pseudo_id);
if (old_pseudo_style && *old_pseudo_style != *new_pseudo_style)
return kNoInherit;
}
return kNoChange;
}
StyleRecalcChange ComputedStyle::StylePropagationDiff(
const ComputedStyle* old_style,
const ComputedStyle* new_style) {
// If the style has changed from display none or to display none, then the
// layout subtree needs to be reattached
if ((!old_style && new_style) || (old_style && !new_style))
return kReattach;
if (!old_style && !new_style)
return kNoChange;
if (old_style->Display() != new_style->Display() ||
old_style->HasPseudoStyle(kPseudoIdFirstLetter) !=
new_style->HasPseudoStyle(kPseudoIdFirstLetter) ||
!old_style->ContentDataEquivalent(*new_style) ||
old_style->HasTextCombine() != new_style->HasTextCombine())
return kReattach;
// We need to perform a reattach if a "display: layout(foo)" has changed to a
// "display: layout(bar)". This is because one custom layout could be
// registered and the other may not, affecting the box-tree construction.
if (old_style->DisplayLayoutCustomName() !=
new_style->DisplayLayoutCustomName()) {
return kReattach;
}
if (old_style->ForceLegacyLayout() != new_style->ForceLegacyLayout())
return kReattach;
bool independent_equal = old_style->IndependentInheritedEqual(*new_style);
bool non_independent_equal =
old_style->NonIndependentInheritedEqual(*new_style);
if (!independent_equal || !non_independent_equal) {
if (non_independent_equal && !old_style->HasExplicitlyInheritedProperties())
return kIndependentInherit;
return kInherit;
}
if (!old_style->LoadingCustomFontsEqual(*new_style) ||
old_style->JustifyItems() != new_style->JustifyItems())
return kInherit;
if (*old_style == *new_style)
return DiffPseudoStyles(*old_style, *new_style);
if (old_style->HasExplicitlyInheritedProperties())
return kInherit;
return kNoInherit;
}
void ComputedStyle::PropagateIndependentInheritedProperties(
const ComputedStyle& parent_style) {
ComputedStyleBase::PropagateIndependentInheritedProperties(parent_style);
}
StyleSelfAlignmentData ResolvedSelfAlignment(
const StyleSelfAlignmentData& value,
ItemPosition normal_value_behavior) {
if (value.GetPosition() == ItemPosition::kLegacy ||
value.GetPosition() == ItemPosition::kNormal ||
value.GetPosition() == ItemPosition::kAuto)
return {normal_value_behavior, OverflowAlignment::kDefault};
return value;
}
StyleSelfAlignmentData ComputedStyle::ResolvedAlignItems(
ItemPosition normal_value_behaviour) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
return ResolvedSelfAlignment(AlignItems(), normal_value_behaviour);
}
StyleSelfAlignmentData ComputedStyle::ResolvedAlignSelf(
ItemPosition normal_value_behaviour,
const ComputedStyle* parent_style) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
if (!parent_style || AlignSelfPosition() != ItemPosition::kAuto)
return ResolvedSelfAlignment(AlignSelf(), normal_value_behaviour);
// The 'auto' keyword computes to the parent's align-items computed value.
return parent_style->ResolvedAlignItems(normal_value_behaviour);
}
StyleSelfAlignmentData ComputedStyle::ResolvedJustifyItems(
ItemPosition normal_value_behaviour) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
return ResolvedSelfAlignment(JustifyItems(), normal_value_behaviour);
}
StyleSelfAlignmentData ComputedStyle::ResolvedJustifySelf(
ItemPosition normal_value_behaviour,
const ComputedStyle* parent_style) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
if (!parent_style || JustifySelfPosition() != ItemPosition::kAuto)
return ResolvedSelfAlignment(JustifySelf(), normal_value_behaviour);
// The auto keyword computes to the parent's justify-items computed value.
return parent_style->ResolvedJustifyItems(normal_value_behaviour);
}
StyleContentAlignmentData ResolvedContentAlignment(
const StyleContentAlignmentData& value,
const StyleContentAlignmentData& normal_behaviour) {
return (value.GetPosition() == ContentPosition::kNormal &&
value.Distribution() == ContentDistributionType::kDefault)
? normal_behaviour
: value;
}
StyleContentAlignmentData ComputedStyle::ResolvedAlignContent(
const StyleContentAlignmentData& normal_behaviour) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
return ResolvedContentAlignment(AlignContent(), normal_behaviour);
}
StyleContentAlignmentData ComputedStyle::ResolvedJustifyContent(
const StyleContentAlignmentData& normal_behaviour) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
return ResolvedContentAlignment(JustifyContent(), normal_behaviour);
}
static inline ContentPosition ResolvedContentAlignmentPosition(
const StyleContentAlignmentData& value,
const StyleContentAlignmentData& normal_value_behavior) {
return (value.GetPosition() == ContentPosition::kNormal &&
value.Distribution() == ContentDistributionType::kDefault)
? normal_value_behavior.GetPosition()
: value.GetPosition();
}
static inline ContentDistributionType ResolvedContentAlignmentDistribution(
const StyleContentAlignmentData& value,
const StyleContentAlignmentData& normal_value_behavior) {
return (value.GetPosition() == ContentPosition::kNormal &&
value.Distribution() == ContentDistributionType::kDefault)
? normal_value_behavior.Distribution()
: value.Distribution();
}
ContentPosition ComputedStyle::ResolvedJustifyContentPosition(
const StyleContentAlignmentData& normal_value_behavior) const {
return ResolvedContentAlignmentPosition(JustifyContent(),
normal_value_behavior);
}
ContentDistributionType ComputedStyle::ResolvedJustifyContentDistribution(
const StyleContentAlignmentData& normal_value_behavior) const {
return ResolvedContentAlignmentDistribution(JustifyContent(),
normal_value_behavior);
}
ContentPosition ComputedStyle::ResolvedAlignContentPosition(
const StyleContentAlignmentData& normal_value_behavior) const {
return ResolvedContentAlignmentPosition(AlignContent(),
normal_value_behavior);
}
ContentDistributionType ComputedStyle::ResolvedAlignContentDistribution(
const StyleContentAlignmentData& normal_value_behavior) const {
return ResolvedContentAlignmentDistribution(AlignContent(),
normal_value_behavior);
}
void ComputedStyle::InheritFrom(const ComputedStyle& inherit_parent,
IsAtShadowBoundary is_at_shadow_boundary) {
EUserModify current_user_modify = UserModify();
ComputedStyleBase::InheritFrom(inherit_parent, is_at_shadow_boundary);
if (svg_style_ != inherit_parent.svg_style_)
svg_style_.Access()->InheritFrom(inherit_parent.svg_style_.Get());
if (is_at_shadow_boundary == kAtShadowBoundary) {
// Even if surrounding content is user-editable, shadow DOM should act as a
// single unit, and not necessarily be editable
SetUserModify(current_user_modify);
}
}
void ComputedStyle::CopyNonInheritedFromCached(const ComputedStyle& other) {
DCHECK(MatchedPropertiesCache::IsStyleCacheable(other));
ComputedStyleBase::CopyNonInheritedFromCached(other);
// The flags are copied one-by-one because they contain
// bunch of stuff other than real style data.
// See comments for each skipped flag below.
// Correctly set during selector matching:
// m_styleType
// m_pseudoBits
// Set correctly while computing style for children:
// m_explicitInheritance
// The following flags are set during matching before we decide that we get a
// match in the MatchedPropertiesCache which in turn calls this method. The
// reason why we don't copy these flags is that they're already correctly set
// and that they may differ between elements which have the same set of
// matched properties. For instance, given the rule:
//
// :-webkit-any(:hover, :focus) { background-color: green }"
//
// A hovered element, and a focused element may use the same cached matched
// properties here, but the affectedBy flags will be set differently based on
// the matching order of the :-webkit-any components.
//
// m_emptyState
// m_affectedByFocus
// m_affectedByHover
// m_affectedByActive
// m_affectedByDrag
// m_isLink
if (svg_style_ != other.svg_style_)
svg_style_.Access()->CopyNonInheritedFromCached(other.svg_style_.Get());
}
bool ComputedStyle::operator==(const ComputedStyle& o) const {
return InheritedEqual(o) && NonInheritedEqual(o);
}
bool ComputedStyle::IsStyleAvailable() const {
return this != StyleResolver::StyleNotYetAvailable();
}
ComputedStyle* ComputedStyle::GetCachedPseudoStyle(PseudoId pid) const {
if (!cached_pseudo_styles_ || !cached_pseudo_styles_->size())
return nullptr;
if (StyleType() != kPseudoIdNone)
return nullptr;
for (size_t i = 0; i < cached_pseudo_styles_->size(); ++i) {
ComputedStyle* pseudo_style = cached_pseudo_styles_->at(i).get();
if (pseudo_style->StyleType() == pid)
return pseudo_style;
}
return nullptr;
}
ComputedStyle* ComputedStyle::AddCachedPseudoStyle(
scoped_refptr<ComputedStyle> pseudo) {
DCHECK(pseudo);
DCHECK_GT(pseudo->StyleType(), kPseudoIdNone);
ComputedStyle* result = pseudo.get();
if (!cached_pseudo_styles_)
cached_pseudo_styles_ = std::make_unique<PseudoStyleCache>();
cached_pseudo_styles_->push_back(std::move(pseudo));
return result;
}
void ComputedStyle::RemoveCachedPseudoStyle(PseudoId pid) {
if (!cached_pseudo_styles_)
return;
for (size_t i = 0; i < cached_pseudo_styles_->size(); ++i) {
ComputedStyle* pseudo_style = cached_pseudo_styles_->at(i).get();
if (pseudo_style->StyleType() == pid) {
cached_pseudo_styles_->EraseAt(i);
return;
}
}
}
bool ComputedStyle::InheritedEqual(const ComputedStyle& other) const {
return IndependentInheritedEqual(other) &&
NonIndependentInheritedEqual(other);
}
bool ComputedStyle::IndependentInheritedEqual(
const ComputedStyle& other) const {
return ComputedStyleBase::IndependentInheritedEqual(other);
}
bool ComputedStyle::NonIndependentInheritedEqual(
const ComputedStyle& other) const {
return ComputedStyleBase::NonIndependentInheritedEqual(other) &&
svg_style_->InheritedEqual(*other.svg_style_);
}
bool ComputedStyle::LoadingCustomFontsEqual(const ComputedStyle& other) const {
return GetFont().LoadingCustomFonts() == other.GetFont().LoadingCustomFonts();
}
bool ComputedStyle::NonInheritedEqual(const ComputedStyle& other) const {
// compare everything except the pseudoStyle pointer
return ComputedStyleBase::NonInheritedEqual(other) &&
svg_style_->NonInheritedEqual(*other.svg_style_);
}
bool ComputedStyle::InheritedDataShared(const ComputedStyle& other) const {
// This is a fast check that only looks if the data structures are shared.
return ComputedStyleBase::InheritedDataShared(other) &&
svg_style_.Get() == other.svg_style_.Get();
}
static bool DependenceOnContentHeightHasChanged(const ComputedStyle& a,
const ComputedStyle& b) {
// If top or bottom become auto/non-auto then it means we either have to solve
// height based on the content or stop doing so
// (http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-height)
// - either way requires a layout.
return a.LogicalTop().IsAuto() != b.LogicalTop().IsAuto() ||
a.LogicalBottom().IsAuto() != b.LogicalBottom().IsAuto();
}
StyleDifference ComputedStyle::VisualInvalidationDiff(
const Document& document,
const ComputedStyle& other) const {
// Note, we use .Get() on each DataRef below because DataRef::operator== will
// do a deep compare, which is duplicate work when we're going to compare each
// property inside this function anyway.
StyleDifference diff;
if (svg_style_.Get() != other.svg_style_.Get())
diff = svg_style_->Diff(other.svg_style_.Get());
if ((!diff.NeedsFullLayout() || !diff.NeedsFullPaintInvalidation()) &&
DiffNeedsFullLayoutAndPaintInvalidation(other)) {
diff.SetNeedsFullLayout();
diff.SetNeedsPaintInvalidationObject();
}
if (!diff.NeedsFullLayout() && DiffNeedsFullLayout(document, other))
diff.SetNeedsFullLayout();
if (!diff.NeedsFullLayout() && !MarginEqual(other)) {
// Relative-positioned elements collapse their margins so need a full
// layout.
if (HasOutOfFlowPosition())
diff.SetNeedsPositionedMovementLayout();
else
diff.SetNeedsFullLayout();
}
if (!diff.NeedsFullLayout() && GetPosition() != EPosition::kStatic &&
!OffsetEqual(other)) {
// Optimize for the case where a positioned layer is moving but not changing
// size.
if (DependenceOnContentHeightHasChanged(*this, other))
diff.SetNeedsFullLayout();
else
diff.SetNeedsPositionedMovementLayout();
}
if (DiffNeedsPaintInvalidationSubtree(other))
diff.SetNeedsPaintInvalidationSubtree();
else if (DiffNeedsPaintInvalidationObject(other))
diff.SetNeedsPaintInvalidationObject();
if (DiffNeedsVisualRectUpdate(other))
diff.SetNeedsVisualRectUpdate();
UpdatePropertySpecificDifferences(other, diff);
// The following condition needs to be at last, because it may depend on
// conditions in diff computed above.
if (ScrollAnchorDisablingPropertyChanged(other, diff))
diff.SetScrollAnchorDisablingPropertyChanged();
// Cursors are not checked, since they will be set appropriately in response
// to mouse events, so they don't need to cause any paint invalidation or
// layout.
// Animations don't need to be checked either. We always set the new style on
// the layoutObject, so we will get a chance to fire off the resulting
// transition properly.
return diff;
}
bool ComputedStyle::ScrollAnchorDisablingPropertyChanged(
const ComputedStyle& other,
const StyleDifference& diff) const {
if (ComputedStyleBase::ScrollAnchorDisablingPropertyChanged(*this, other))
return true;
if (diff.TransformChanged())
return true;
return false;
}
bool ComputedStyle::DiffNeedsFullLayoutAndPaintInvalidation(
const ComputedStyle& other) const {
// FIXME: Not all cases in this method need both full layout and paint
// invalidation.
// Should move cases into DiffNeedsFullLayout() if
// - don't need paint invalidation at all;
// - or the layoutObject knows how to exactly invalidate paints caused by the
// layout change instead of forced full paint invalidation.
if (ComputedStyleBase::DiffNeedsFullLayoutAndPaintInvalidation(*this, other))
return true;
if (IsDisplayTableType(Display())) {
if (ComputedStyleBase::
DiffNeedsFullLayoutAndPaintInvalidationDisplayTableType(*this,
other))
return true;
// In the collapsing border model, 'hidden' suppresses other borders, while
// 'none' does not, so these style differences can be width differences.
if ((BorderCollapse() == EBorderCollapse::kCollapse) &&
((BorderTopStyle() == EBorderStyle::kHidden &&
other.BorderTopStyle() == EBorderStyle::kNone) ||
(BorderTopStyle() == EBorderStyle::kNone &&
other.BorderTopStyle() == EBorderStyle::kHidden) ||
(BorderBottomStyle() == EBorderStyle::kHidden &&
other.BorderBottomStyle() == EBorderStyle::kNone) ||
(BorderBottomStyle() == EBorderStyle::kNone &&
other.BorderBottomStyle() == EBorderStyle::kHidden) ||
(BorderLeftStyle() == EBorderStyle::kHidden &&
other.BorderLeftStyle() == EBorderStyle::kNone) ||
(BorderLeftStyle() == EBorderStyle::kNone &&
other.BorderLeftStyle() == EBorderStyle::kHidden) ||
(BorderRightStyle() == EBorderStyle::kHidden &&
other.BorderRightStyle() == EBorderStyle::kNone) ||
(BorderRightStyle() == EBorderStyle::kNone &&
other.BorderRightStyle() == EBorderStyle::kHidden)))
return true;
} else if (Display() == EDisplay::kListItem) {
if (ComputedStyleBase::
DiffNeedsFullLayoutAndPaintInvalidationDisplayListItem(*this,
other))
return true;
}
if ((Visibility() == EVisibility::kCollapse) !=
(other.Visibility() == EVisibility::kCollapse))
return true;
// Movement of non-static-positioned object is special cased in
// ComputedStyle::VisualInvalidationDiff().
return false;
}
bool ComputedStyle::DiffNeedsFullLayout(const Document& document,
const ComputedStyle& other) const {
if (ComputedStyleBase::DiffNeedsFullLayout(*this, other))
return true;
if (IsDisplayLayoutCustomBox()) {
if (DiffNeedsFullLayoutForLayoutCustom(document, other))
return true;
}
if (DisplayLayoutCustomParentName()) {
if (DiffNeedsFullLayoutForLayoutCustomChild(document, other))
return true;
}
return false;
}
bool ComputedStyle::DiffNeedsFullLayoutForLayoutCustom(
const Document& document,
const ComputedStyle& other) const {
DCHECK(IsDisplayLayoutCustomBox());
LayoutWorklet* worklet = LayoutWorklet::From(*document.domWindow());
const AtomicString& name = DisplayLayoutCustomName();
if (!worklet->GetDocumentDefinitionMap()->Contains(name))
return false;
const DocumentLayoutDefinition* definition =
worklet->GetDocumentDefinitionMap()->at(name);
if (definition == kInvalidDocumentLayoutDefinition)
return false;
if (!PropertiesEqual(definition->NativeInvalidationProperties(), other))
return true;
if (!CustomPropertiesEqual(definition->CustomInvalidationProperties(), other))
return true;
return false;
}
bool ComputedStyle::DiffNeedsFullLayoutForLayoutCustomChild(
const Document& document,
const ComputedStyle& other) const {
LayoutWorklet* worklet = LayoutWorklet::From(*document.domWindow());
const AtomicString& name = DisplayLayoutCustomParentName();
if (!worklet->GetDocumentDefinitionMap()->Contains(name))
return false;
const DocumentLayoutDefinition* definition =
worklet->GetDocumentDefinitionMap()->at(name);
if (definition == kInvalidDocumentLayoutDefinition)
return false;
if (!PropertiesEqual(definition->ChildNativeInvalidationProperties(), other))
return true;
if (!CustomPropertiesEqual(definition->ChildCustomInvalidationProperties(),
other))
return true;
return false;
}
bool ComputedStyle::DiffNeedsPaintInvalidationSubtree(
const ComputedStyle& other) const {
return ComputedStyleBase::DiffNeedsPaintInvalidationSubtree(*this, other);
}
bool ComputedStyle::DiffNeedsPaintInvalidationObject(
const ComputedStyle& other) const {
if (ComputedStyleBase::DiffNeedsPaintInvalidationObject(*this, other))
return true;
if (!BorderVisuallyEqual(other) || !RadiiEqual(other) ||
!BackgroundVisuallyEqual(other))
return true;
if (PaintImagesInternal()) {
for (const auto& image : *PaintImagesInternal()) {
DCHECK(image);
if (DiffNeedsPaintInvalidationObjectForPaintImage(*image, other))
return true;
}
}
return false;
}
bool ComputedStyle::DiffNeedsPaintInvalidationObjectForPaintImage(
const StyleImage& image,
const ComputedStyle& other) const {
// https://crbug.com/835589: early exit when paint target is associated with
// a link.
if (InsideLink() != EInsideLink::kNotInsideLink)
return false;
CSSPaintValue* value = ToCSSPaintValue(image.CssValue());
// NOTE: If the invalidation properties vectors are null, we are invalid as
// we haven't yet been painted (and can't provide the invalidation
// properties yet).
if (!value->NativeInvalidationProperties() ||
!value->CustomInvalidationProperties())
return true;
if (!PropertiesEqual(*value->NativeInvalidationProperties(), other))
return true;
if (!CustomPropertiesEqual(*value->CustomInvalidationProperties(), other))
return true;
return false;
}
bool ComputedStyle::PropertiesEqual(const Vector<CSSPropertyID>& properties,
const ComputedStyle& other) const {
for (CSSPropertyID property_id : properties) {
// TODO(ikilpatrick): remove IsInterpolableProperty check once
// CSSPropertyEquality::PropertiesEqual correctly handles all properties.
const CSSProperty& property = CSSProperty::Get(property_id);
if (!property.IsInterpolable() ||
!CSSPropertyEquality::PropertiesEqual(PropertyHandle(property), *this,
other))
return false;
}
return true;
}
bool ComputedStyle::CustomPropertiesEqual(
const Vector<AtomicString>& properties,
const ComputedStyle& other) const {
// Short-circuit if neither of the styles have custom properties.
if (!InheritedVariables() && !NonInheritedVariables() &&
!other.InheritedVariables() && !other.NonInheritedVariables())
return true;
for (const AtomicString& property_name : properties) {
if (!DataEquivalent(GetVariable(property_name),
other.GetVariable(property_name)))
return false;
}
return true;
}
// This doesn't include conditions needing layout or overflow recomputation
// which implies visual rect update.
bool ComputedStyle::DiffNeedsVisualRectUpdate(
const ComputedStyle& other) const {
// Visual rect is empty if visibility is hidden. Also need to update visual
// rect of the resizer.
return ComputedStyleBase::DiffNeedsVisualRectUpdate(*this, other);
}
void ComputedStyle::UpdatePropertySpecificDifferences(
const ComputedStyle& other,
StyleDifference& diff) const {
if (ComputedStyleBase::UpdatePropertySpecificDifferencesZIndex(*this, other))
diff.SetZIndexChanged();
if (UpdatePropertySpecificDifferencesTransform(*this, other))
diff.SetTransformChanged();
if (ComputedStyleBase::UpdatePropertySpecificDifferencesOpacity(*this, other))
diff.SetOpacityChanged();
if (ComputedStyleBase::UpdatePropertySpecificDifferencesFilter(*this, other))
diff.SetFilterChanged();
if (ComputedStyleBase::
UpdatePropertySpecificDifferencesNeedsRecomputeOverflow(*this, other))
diff.SetNeedsRecomputeOverflow();
if (ComputedStyleBase::UpdatePropertySpecificDifferencesBackdropFilter(*this,
other))
diff.SetBackdropFilterChanged();
if (!diff.NeedsFullPaintInvalidation() &&
ComputedStyleBase::UpdatePropertySpecificDifferencesTextDecorationOrColor(
*this, other)) {
diff.SetTextDecorationOrColorChanged();
}
bool has_clip = HasOutOfFlowPosition() && !HasAutoClip();
bool other_has_clip = other.HasOutOfFlowPosition() && !other.HasAutoClip();
if (has_clip != other_has_clip ||
(has_clip && Clip() != other.Clip()))
diff.SetCSSClipChanged();
if (GetBlendMode() != other.GetBlendMode())
diff.SetBlendModeChanged();
if (HasCurrentTransformAnimation() != other.HasCurrentTransformAnimation() ||
HasCurrentOpacityAnimation() != other.HasCurrentOpacityAnimation() ||
HasCurrentFilterAnimation() != other.HasCurrentFilterAnimation() ||
HasCurrentBackdropFilterAnimation() !=
other.HasCurrentBackdropFilterAnimation() ||
HasInlineTransform() != other.HasInlineTransform() ||
BackfaceVisibility() != other.BackfaceVisibility() ||
HasWillChangeCompositingHint() != other.HasWillChangeCompositingHint() ||
UsedTransformStyle3D() != other.UsedTransformStyle3D() ||
ContainsPaint() != other.ContainsPaint() ||
IsOverflowVisible() != other.IsOverflowVisible()) {
diff.SetCompositingReasonsChanged();
}
}
void ComputedStyle::AddPaintImage(StyleImage* image) {
if (!MutablePaintImagesInternal()) {
SetPaintImagesInternal(std::make_unique<PaintImages>());
}
MutablePaintImagesInternal()->push_back(image);
}
void ComputedStyle::AddCursor(StyleImage* image,
bool hot_spot_specified,
const IntPoint& hot_spot) {
if (!CursorDataInternal())
SetCursorDataInternal(new CursorList);
MutableCursorDataInternal()->push_back(
CursorData(image, hot_spot_specified, hot_spot));
}
void ComputedStyle::SetCursorList(CursorList* other) {
SetCursorDataInternal(other);
}
bool ComputedStyle::QuotesDataEquivalent(const ComputedStyle& other) const {
return DataEquivalent(Quotes(), other.Quotes());
}
void ComputedStyle::ClearCursorList() {
if (CursorDataInternal())
SetCursorDataInternal(nullptr);
}
static bool HasPropertyThatCreatesStackingContext(
const Vector<CSSPropertyID>& properties) {
for (CSSPropertyID property : properties) {
switch (property) {
case CSSPropertyOpacity:
case CSSPropertyTransform:
case CSSPropertyAliasWebkitTransform:
case CSSPropertyTransformStyle:
case CSSPropertyAliasWebkitTransformStyle:
case CSSPropertyPerspective:
case CSSPropertyAliasWebkitPerspective:
case CSSPropertyTranslate:
case CSSPropertyRotate:
case CSSPropertyScale:
case CSSPropertyOffsetPath:
case CSSPropertyOffsetPosition:
case CSSPropertyWebkitMask:
case CSSPropertyWebkitMaskBoxImage:
case CSSPropertyClipPath:
case CSSPropertyAliasWebkitClipPath:
case CSSPropertyWebkitBoxReflect:
case CSSPropertyFilter:
case CSSPropertyAliasWebkitFilter:
case CSSPropertyBackdropFilter:
case CSSPropertyZIndex:
case CSSPropertyPosition:
case CSSPropertyMixBlendMode:
case CSSPropertyIsolation:
return true;
default:
break;
}
}
return false;
}
void ComputedStyle::UpdateIsStackingContext(bool is_document_element,
bool is_in_top_layer,
bool is_svg_stacking) {
if (IsStackingContext())
return;
// Force a stacking context for transform-style: preserve-3d. This happens
// even if preserves-3d is ignored due to a 'grouping property' being present
// which requires flattening. See ComputedStyle::UsedTransformStyle3D() and
// ComputedStyle::HasGroupingProperty().
// This is legacy behavior that is left ambiguous in the official specs.
// See crbug.com/663650 for more details."
if (TransformStyle3D() == ETransformStyle3D::kPreserve3d) {
SetIsStackingContext(true);
return;
}
if (is_document_element || is_in_top_layer || is_svg_stacking ||
StyleType() == kPseudoIdBackdrop || HasOpacity() ||
HasTransformRelatedProperty() || HasMask() || ClipPath() ||
BoxReflect() || HasFilterInducingProperty() || HasBackdropFilter() ||
HasBlendMode() || HasIsolation() || HasViewportConstrainedPosition() ||
GetPosition() == EPosition::kSticky ||
HasPropertyThatCreatesStackingContext(WillChangeProperties()) ||
ContainsPaint()) {
SetIsStackingContext(true);
}
}
void ComputedStyle::AddCallbackSelector(const String& selector) {
if (!CallbackSelectorsInternal().Contains(selector))
MutableCallbackSelectorsInternal().push_back(selector);
}
void ComputedStyle::SetContent(ContentData* content_data) {
SetContentInternal(content_data);
}
bool ComputedStyle::HasWillChangeCompositingHint() const {
for (size_t i = 0; i < WillChangeProperties().size(); ++i) {
switch (WillChangeProperties()[i]) {
case CSSPropertyOpacity:
case CSSPropertyTransform:
case CSSPropertyAliasWebkitTransform:
case CSSPropertyTranslate:
case CSSPropertyScale:
case CSSPropertyRotate:
case CSSPropertyTop:
case CSSPropertyLeft:
case CSSPropertyBottom:
case CSSPropertyRight:
return true;
default:
break;
}
}
return false;
}
bool ComputedStyle::HasWillChangeTransformHint() const {
for (const auto& property : WillChangeProperties()) {
switch (property) {
case CSSPropertyTransform:
case CSSPropertyAliasWebkitTransform:
case CSSPropertyPerspective:
case CSSPropertyTranslate:
case CSSPropertyScale:
case CSSPropertyRotate:
case CSSPropertyOffsetPath:
case CSSPropertyOffsetPosition:
return true;
default:
break;
}
}
return false;
}
bool ComputedStyle::RequireTransformOrigin(
ApplyTransformOrigin apply_origin,
ApplyMotionPath apply_motion_path) const {
// 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 (apply_origin != kIncludeTransformOrigin)
return false;
if (apply_motion_path == kIncludeMotionPath)
return true;
for (const auto& operation : Transform().Operations()) {
TransformOperation::OperationType type = operation->GetType();
if (type != TransformOperation::kTranslateX &&
type != TransformOperation::kTranslateY &&
type != TransformOperation::kTranslate &&
type != TransformOperation::kTranslateZ &&
type != TransformOperation::kTranslate3D)
return true;
}
return Scale() || Rotate();
}
InterpolationQuality ComputedStyle::GetInterpolationQuality() const {
if (ImageRendering() == EImageRendering::kPixelated)
return kInterpolationNone;
if (ImageRendering() == EImageRendering::kWebkitOptimizeContrast)
return kInterpolationLow;
return kInterpolationDefault;
}
void ComputedStyle::ApplyTransform(
TransformationMatrix& result,
const LayoutSize& border_box_size,
ApplyTransformOrigin apply_origin,
ApplyMotionPath apply_motion_path,
ApplyIndependentTransformProperties apply_independent_transform_properties)
const {
ApplyTransform(result, FloatRect(FloatPoint(), FloatSize(border_box_size)),
apply_origin, apply_motion_path,
apply_independent_transform_properties);
}
void ComputedStyle::ApplyTransform(
TransformationMatrix& result,
const FloatRect& bounding_box,
ApplyTransformOrigin apply_origin,
ApplyMotionPath apply_motion_path,
ApplyIndependentTransformProperties apply_independent_transform_properties)
const {
if (!HasOffset())
apply_motion_path = kExcludeMotionPath;
bool apply_transform_origin =
RequireTransformOrigin(apply_origin, apply_motion_path);
float origin_x = 0;
float origin_y = 0;
float origin_z = 0;
const FloatSize& box_size = bounding_box.Size();
if (apply_transform_origin ||
// We need to calculate originX and originY for applying motion path.
apply_motion_path == kIncludeMotionPath) {
origin_x = FloatValueForLength(TransformOriginX(), box_size.Width()) +
bounding_box.X();
origin_y = FloatValueForLength(TransformOriginY(), box_size.Height()) +
bounding_box.Y();
if (apply_transform_origin) {
origin_z = TransformOriginZ();
result.Translate3d(origin_x, origin_y, origin_z);
}
}
if (apply_independent_transform_properties ==
kIncludeIndependentTransformProperties) {
if (Translate())
Translate()->Apply(result, box_size);
if (Rotate())
Rotate()->Apply(result, box_size);
if (Scale())
Scale()->Apply(result, box_size);
}
if (apply_motion_path == kIncludeMotionPath)
ApplyMotionPathTransform(origin_x, origin_y, bounding_box, result);
for (const auto& operation : Transform().Operations())
operation->Apply(result, box_size);
if (apply_transform_origin) {
result.Translate3d(-origin_x, -origin_y, -origin_z);
}
}
bool ComputedStyle::HasFilters() const {
return FilterInternal().Get() && !FilterInternal()->operations_.IsEmpty();
}
void ComputedStyle::ApplyMotionPathTransform(
float origin_x,
float origin_y,
const FloatRect& bounding_box,
TransformationMatrix& transform) const {
// TODO(ericwilligers): crbug.com/638055 Apply offset-position.
if (!OffsetPath()) {
return;
}
const LengthPoint& position = OffsetPosition();
const LengthPoint& anchor = OffsetAnchor();
const Length& distance = OffsetDistance();
const BasicShape* path = OffsetPath();
const StyleOffsetRotation& rotate = OffsetRotate();
FloatPoint point;
float angle;
if (path->GetType() == BasicShape::kStyleRayType) {
// TODO(ericwilligers): crbug.com/641245 Support <size> for ray paths.
float float_distance = FloatValueForLength(distance, 0);
angle = ToStyleRay(*path).Angle() - 90;
point.SetX(float_distance * cos(deg2rad(angle)));
point.SetY(float_distance * sin(deg2rad(angle)));
} else {
float zoom = EffectiveZoom();
const StylePath& motion_path = ToStylePath(*path);
float path_length = motion_path.length();
float float_distance =
FloatValueForLength(distance, path_length * zoom) / zoom;
float computed_distance;
if (motion_path.IsClosed() && path_length > 0) {
computed_distance = fmod(float_distance, path_length);
if (computed_distance < 0)
computed_distance += path_length;
} else {
computed_distance = clampTo<float>(float_distance, 0, path_length);
}
motion_path.GetPath().PointAndNormalAtLength(computed_distance, point,
angle);
point.Scale(zoom, zoom);
}
if (rotate.type == OffsetRotationType::kFixed)
angle = 0;
float origin_shift_x = 0;
float origin_shift_y = 0;
// If the offset-position and offset-anchor properties are not yet enabled,
// they will have the default value, auto.
FloatPoint anchor_point(origin_x, origin_y);
if (!position.X().IsAuto() || !anchor.X().IsAuto()) {
anchor_point = FloatPointForLengthPoint(anchor, bounding_box.Size());
anchor_point += bounding_box.Location();
// Shift the origin from transform-origin to offset-anchor.
origin_shift_x = anchor_point.X() - origin_x;
origin_shift_y = anchor_point.Y() - origin_y;
}
transform.Translate(point.X() - anchor_point.X() + origin_shift_x,
point.Y() - anchor_point.Y() + origin_shift_y);
transform.Rotate(angle + rotate.angle);
if (!position.X().IsAuto() || !anchor.X().IsAuto())
// Shift the origin back to transform-origin.
transform.Translate(-origin_shift_x, -origin_shift_y);
}
bool ComputedStyle::TextShadowDataEquivalent(const ComputedStyle& other) const {
return DataEquivalent(TextShadow(), other.TextShadow());
}
StyleImage* ComputedStyle::ListStyleImage() const {
return ListStyleImageInternal();
}
void ComputedStyle::SetListStyleImage(StyleImage* v) {
SetListStyleImageInternal(v);
}
Color ComputedStyle::GetColor() const {
return ColorInternal();
}
void ComputedStyle::SetColor(const Color& v) {
SetColorInternal(v);
}
static FloatRoundedRect::Radii CalcRadiiFor(const LengthSize& top_left,
const LengthSize& top_right,
const LengthSize& bottom_left,
const LengthSize& bottom_right,
FloatSize size) {
return FloatRoundedRect::Radii(FloatSizeForLengthSize(top_left, size),
FloatSizeForLengthSize(top_right, size),
FloatSizeForLengthSize(bottom_left, size),
FloatSizeForLengthSize(bottom_right, size));
}
FloatRoundedRect ComputedStyle::GetRoundedBorderFor(
const LayoutRect& border_rect,
bool include_logical_left_edge,
bool include_logical_right_edge) const {
FloatRoundedRect rounded_rect(PixelSnappedIntRect(border_rect));
if (HasBorderRadius()) {
FloatRoundedRect::Radii radii = CalcRadiiFor(
BorderTopLeftRadius(), BorderTopRightRadius(), BorderBottomLeftRadius(),
BorderBottomRightRadius(), FloatSize(border_rect.Size()));
rounded_rect.IncludeLogicalEdges(radii, IsHorizontalWritingMode(),
include_logical_left_edge,
include_logical_right_edge);
rounded_rect.ConstrainRadii();
}
return rounded_rect;
}
FloatRoundedRect ComputedStyle::GetRoundedInnerBorderFor(
const LayoutRect& border_rect,
bool include_logical_left_edge,
bool include_logical_right_edge) const {
bool horizontal = IsHorizontalWritingMode();
int left_width = (!horizontal || include_logical_left_edge)
? roundf(BorderLeftWidth())
: 0;
int right_width = (!horizontal || include_logical_right_edge)
? roundf(BorderRightWidth())
: 0;
int top_width =
(horizontal || include_logical_left_edge) ? roundf(BorderTopWidth()) : 0;
int bottom_width = (horizontal || include_logical_right_edge)
? roundf(BorderBottomWidth())
: 0;
return GetRoundedInnerBorderFor(
border_rect,
LayoutRectOutsets(-top_width, -right_width, -bottom_width, -left_width),
include_logical_left_edge, include_logical_right_edge);
}
FloatRoundedRect ComputedStyle::GetRoundedInnerBorderFor(
const LayoutRect& border_rect,
const LayoutRectOutsets& insets,
bool include_logical_left_edge,
bool include_logical_right_edge) const {
LayoutRect inner_rect(border_rect);
inner_rect.Expand(insets);
LayoutSize inner_rect_size = inner_rect.Size();
inner_rect_size.ClampNegativeToZero();
inner_rect.SetSize(inner_rect_size);
FloatRoundedRect rounded_rect(PixelSnappedIntRect(inner_rect));
if (HasBorderRadius()) {
FloatRoundedRect::Radii radii = GetRoundedBorderFor(border_rect).GetRadii();
// Insets use negative values.
radii.Shrink(-insets.Top().ToFloat(), -insets.Bottom().ToFloat(),
-insets.Left().ToFloat(), -insets.Right().ToFloat());
rounded_rect.IncludeLogicalEdges(radii, IsHorizontalWritingMode(),
include_logical_left_edge,
include_logical_right_edge);
}
return rounded_rect;
}
bool ComputedStyle::CanRenderBorderImage() const {
if (!HasBorderDecoration())
return false;
StyleImage* border_image = BorderImage().GetImage();
return border_image && border_image->CanRender() && border_image->IsLoaded();
}
static bool AllLayersAreFixed(const FillLayer& layer) {
for (const FillLayer* curr_layer = &layer; curr_layer;
curr_layer = curr_layer->Next()) {
if (!curr_layer->GetImage() ||
curr_layer->Attachment() != EFillAttachment::kFixed)
return false;
}
return true;
}
bool ComputedStyle::HasEntirelyFixedBackground() const {
return AllLayersAreFixed(BackgroundLayers());
}
const CounterDirectiveMap* ComputedStyle::GetCounterDirectives() const {
return CounterDirectivesInternal().get();
}
CounterDirectiveMap& ComputedStyle::AccessCounterDirectives() {
std::unique_ptr<CounterDirectiveMap>& map =
MutableCounterDirectivesInternal();
if (!map)
map = std::make_unique<CounterDirectiveMap>();
return *map;
}
const CounterDirectives ComputedStyle::GetCounterDirectives(
const AtomicString& identifier) const {
if (const CounterDirectiveMap* directives = GetCounterDirectives())
return directives->at(identifier);
return CounterDirectives();
}
void ComputedStyle::ClearIncrementDirectives() {
if (!GetCounterDirectives())
return;
// This makes us copy even if we may not be removing any items.
CounterDirectiveMap& map = AccessCounterDirectives();
typedef CounterDirectiveMap::iterator Iterator;
Iterator end = map.end();
for (Iterator it = map.begin(); it != end; ++it)
it->value.ClearIncrement();
}
void ComputedStyle::ClearResetDirectives() {
if (!GetCounterDirectives())
return;
// This makes us copy even if we may not be removing any items.
CounterDirectiveMap& map = AccessCounterDirectives();
typedef CounterDirectiveMap::iterator Iterator;
Iterator end = map.end();
for (Iterator it = map.begin(); it != end; ++it)
it->value.ClearReset();
}
AtomicString ComputedStyle::LocaleForLineBreakIterator() const {
LineBreakIteratorMode mode = LineBreakIteratorMode::kDefault;
switch (GetLineBreak()) {
case LineBreak::kAuto:
case LineBreak::kAfterWhiteSpace:
return Locale();
case LineBreak::kNormal:
mode = LineBreakIteratorMode::kNormal;
break;
case LineBreak::kStrict:
mode = LineBreakIteratorMode::kStrict;
break;
case LineBreak::kLoose:
mode = LineBreakIteratorMode::kLoose;
break;
}
if (const LayoutLocale* locale = GetFontDescription().Locale())
return locale->LocaleWithBreakKeyword(mode);
return Locale();
}
Hyphenation* ComputedStyle::GetHyphenation() const {
return GetHyphens() == Hyphens::kAuto
? GetFontDescription().LocaleOrDefault().GetHyphenation()
: nullptr;
}
const AtomicString& ComputedStyle::HyphenString() const {
const AtomicString& hyphenation_string = HyphenationString();
if (!hyphenation_string.IsNull())
return hyphenation_string;
// FIXME: This should depend on locale.
DEFINE_STATIC_LOCAL(AtomicString, hyphen_minus_string,
(&kHyphenMinusCharacter, 1));
DEFINE_STATIC_LOCAL(AtomicString, hyphen_string, (&kHyphenCharacter, 1));
const SimpleFontData* primary_font = GetFont().PrimaryFont();
DCHECK(primary_font);
return primary_font && primary_font->GlyphForCharacter(kHyphenCharacter)
? hyphen_string
: hyphen_minus_string;
}
ETextAlign ComputedStyle::GetTextAlign(bool is_last_line) const {
if (!is_last_line)
return GetTextAlign();
// When this is the last line of a block, or the line ends with a forced line
// break.
// https://drafts.csswg.org/css-text-3/#propdef-text-align-last
switch (TextAlignLast()) {
case ETextAlignLast::kStart:
return ETextAlign::kStart;
case ETextAlignLast::kEnd:
return ETextAlign::kEnd;
case ETextAlignLast::kLeft:
return ETextAlign::kLeft;
case ETextAlignLast::kRight:
return ETextAlign::kRight;
case ETextAlignLast::kCenter:
return ETextAlign::kCenter;
case ETextAlignLast::kJustify:
return ETextAlign::kJustify;
case ETextAlignLast::kAuto:
ETextAlign text_align = GetTextAlign();
if (text_align == ETextAlign::kJustify)
return ETextAlign::kStart;
return text_align;
}
NOTREACHED();
return GetTextAlign();
}
bool ComputedStyle::ShouldUseTextIndent(bool is_first_line,
bool is_after_forced_break) const {
bool should_use =
is_first_line || (is_after_forced_break &&
GetTextIndentLine() != TextIndentLine::kFirstLine);
return GetTextIndentType() == TextIndentType::kNormal ? should_use
: !should_use;
}
void ComputedStyle::ApplyTextTransform(String* text,
UChar previous_character) const {
switch (TextTransform()) {
case ETextTransform::kNone:
return;
case ETextTransform::kCapitalize:
*text = Capitalize(*text, previous_character);
return;
case ETextTransform::kUppercase:
*text = text->UpperUnicode(Locale());
return;
case ETextTransform::kLowercase:
*text = text->LowerUnicode(Locale());
return;
}
NOTREACHED();
}
const AtomicString& ComputedStyle::TextEmphasisMarkString() const {
switch (GetTextEmphasisMark()) {
case TextEmphasisMark::kNone:
return g_null_atom;
case TextEmphasisMark::kCustom:
return TextEmphasisCustomMark();
case TextEmphasisMark::kDot: {
DEFINE_STATIC_LOCAL(AtomicString, filled_dot_string,
(&kBulletCharacter, 1));
DEFINE_STATIC_LOCAL(AtomicString, open_dot_string,
(&kWhiteBulletCharacter, 1));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_dot_string
: open_dot_string;
}
case TextEmphasisMark::kCircle: {
DEFINE_STATIC_LOCAL(AtomicString, filled_circle_string,
(&kBlackCircleCharacter, 1));
DEFINE_STATIC_LOCAL(AtomicString, open_circle_string,
(&kWhiteCircleCharacter, 1));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_circle_string
: open_circle_string;
}
case TextEmphasisMark::kDoubleCircle: {
DEFINE_STATIC_LOCAL(AtomicString, filled_double_circle_string,
(&kFisheyeCharacter, 1));
DEFINE_STATIC_LOCAL(AtomicString, open_double_circle_string,
(&kBullseyeCharacter, 1));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_double_circle_string
: open_double_circle_string;
}
case TextEmphasisMark::kTriangle: {
DEFINE_STATIC_LOCAL(AtomicString, filled_triangle_string,
(&kBlackUpPointingTriangleCharacter, 1));
DEFINE_STATIC_LOCAL(AtomicString, open_triangle_string,
(&kWhiteUpPointingTriangleCharacter, 1));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_triangle_string
: open_triangle_string;
}
case TextEmphasisMark::kSesame: {
DEFINE_STATIC_LOCAL(AtomicString, filled_sesame_string,
(&kSesameDotCharacter, 1));
DEFINE_STATIC_LOCAL(AtomicString, open_sesame_string,
(&kWhiteSesameDotCharacter, 1));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_sesame_string
: open_sesame_string;
}
case TextEmphasisMark::kAuto:
NOTREACHED();
return g_null_atom;
}
NOTREACHED();
return g_null_atom;
}
LineLogicalSide ComputedStyle::GetTextEmphasisLineLogicalSide() const {
TextEmphasisPosition position = GetTextEmphasisPosition();
if (IsHorizontalWritingMode()) {
return position == TextEmphasisPosition::kOverRight ||
position == TextEmphasisPosition::kOverLeft
? LineLogicalSide::kOver
: LineLogicalSide::kUnder;
}
if (GetWritingMode() != WritingMode::kSidewaysLr) {
return position == TextEmphasisPosition::kOverRight ||
position == TextEmphasisPosition::kUnderRight
? LineLogicalSide::kOver
: LineLogicalSide::kUnder;
}
return position == TextEmphasisPosition::kOverLeft ||
position == TextEmphasisPosition::kUnderLeft
? LineLogicalSide::kOver
: LineLogicalSide::kUnder;
}
CSSAnimationData& ComputedStyle::AccessAnimations() {
if (!AnimationsInternal())
SetAnimationsInternal(CSSAnimationData::Create());
return *AnimationsInternal();
}
CSSTransitionData& ComputedStyle::AccessTransitions() {
if (!TransitionsInternal())
SetTransitionsInternal(CSSTransitionData::Create());
return *TransitionsInternal();
}
const Font& ComputedStyle::GetFont() const {
return FontInternal();
}
const FontDescription& ComputedStyle::GetFontDescription() const {
return FontInternal().GetFontDescription();
}
float ComputedStyle::SpecifiedFontSize() const {
return GetFontDescription().SpecifiedSize();
}
float ComputedStyle::ComputedFontSize() const {
return GetFontDescription().ComputedSize();
}
LayoutUnit ComputedStyle::ComputedFontSizeAsFixed() const {
return LayoutUnit::FromFloatRound(GetFontDescription().ComputedSize());
}
int ComputedStyle::FontSize() const {
return GetFontDescription().ComputedPixelSize();
}
float ComputedStyle::FontSizeAdjust() const {
return GetFontDescription().SizeAdjust();
}
bool ComputedStyle::HasFontSizeAdjust() const {
return GetFontDescription().HasSizeAdjust();
}
FontSelectionValue ComputedStyle::GetFontWeight() const {
return GetFontDescription().Weight();
}
FontSelectionValue ComputedStyle::GetFontStretch() const {
return GetFontDescription().Stretch();
}
FontBaseline ComputedStyle::GetFontBaseline() const {
// TODO(kojii): Incorporate 'dominant-baseline' when we support it.
// https://www.w3.org/TR/css-inline-3/#dominant-baseline-property
// Vertical flow (except 'text-orientation: sideways') uses ideographic
// baseline. https://drafts.csswg.org/css-writing-modes-3/#intro-baselines
return !GetFontDescription().IsVerticalAnyUpright() ? kAlphabeticBaseline
: kIdeographicBaseline;
}
TextDecoration ComputedStyle::TextDecorationsInEffect() const {
if (HasSimpleUnderlineInternal())
return TextDecoration::kUnderline;
if (!AppliedTextDecorationsInternal())
return TextDecoration::kNone;
TextDecoration decorations = TextDecoration::kNone;
const Vector<AppliedTextDecoration>& applied = AppliedTextDecorations();
for (size_t i = 0; i < applied.size(); ++i)
decorations |= applied[i].Lines();
return decorations;
}
const Vector<AppliedTextDecoration>& ComputedStyle::AppliedTextDecorations()
const {
if (HasSimpleUnderlineInternal()) {
DEFINE_STATIC_LOCAL(
Vector<AppliedTextDecoration>, underline,
(1, AppliedTextDecoration(
TextDecoration::kUnderline, ETextDecorationStyle::kSolid,
VisitedDependentColor(GetCSSPropertyTextDecorationColor()))));
// Since we only have one of these in memory, just update the color before
// returning.
underline.at(0).SetColor(
VisitedDependentColor(GetCSSPropertyTextDecorationColor()));
return underline;
}
if (!AppliedTextDecorationsInternal()) {
DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ());
return empty;
}
return AppliedTextDecorationsInternal()->GetVector();
}
StyleInheritedVariables* ComputedStyle::InheritedVariables() const {
return InheritedVariablesInternal().get();
}
StyleNonInheritedVariables* ComputedStyle::NonInheritedVariables() const {
return NonInheritedVariablesInternal().get();
}
StyleInheritedVariables& ComputedStyle::MutableInheritedVariables() {
scoped_refptr<StyleInheritedVariables>& variables =
MutableInheritedVariablesInternal();
if (!variables)
variables = StyleInheritedVariables::Create();
else if (!variables->HasOneRef())
variables = variables->Copy();
return *variables;
}
StyleNonInheritedVariables& ComputedStyle::MutableNonInheritedVariables() {
std::unique_ptr<StyleNonInheritedVariables>& variables =
MutableNonInheritedVariablesInternal();
if (!variables)
variables = StyleNonInheritedVariables::Create();
return *variables;
}
void ComputedStyle::SetUnresolvedInheritedVariable(
const AtomicString& name,
scoped_refptr<CSSVariableData> value) {
DCHECK(value && value->NeedsVariableResolution());
MutableInheritedVariables().SetVariable(name, std::move(value));
}
void ComputedStyle::SetUnresolvedNonInheritedVariable(
const AtomicString& name,
scoped_refptr<CSSVariableData> value) {
DCHECK(value && value->NeedsVariableResolution());
MutableNonInheritedVariables().SetVariable(name, std::move(value));
}
void ComputedStyle::SetResolvedUnregisteredVariable(
const AtomicString& name,
scoped_refptr<CSSVariableData> value) {
DCHECK(value && !value->NeedsVariableResolution());
MutableInheritedVariables().SetVariable(name, std::move(value));
}
void ComputedStyle::SetResolvedInheritedVariable(
const AtomicString& name,
scoped_refptr<CSSVariableData> value,
const CSSValue* parsed_value) {
DCHECK(!!value == !!parsed_value);
DCHECK(!(value && value->NeedsVariableResolution()));
StyleInheritedVariables& variables = MutableInheritedVariables();
variables.SetVariable(name, std::move(value));
variables.SetRegisteredVariable(name, parsed_value);
}
void ComputedStyle::SetResolvedNonInheritedVariable(
const AtomicString& name,
scoped_refptr<CSSVariableData> value,
const CSSValue* parsed_value) {
DCHECK(!!value == !!parsed_value);
DCHECK(!(value && value->NeedsVariableResolution()));
StyleNonInheritedVariables& variables = MutableNonInheritedVariables();
variables.SetVariable(name, std::move(value));
variables.SetRegisteredVariable(name, parsed_value);
}
void ComputedStyle::RemoveVariable(const AtomicString& name,
bool is_inherited_property) {
if (is_inherited_property) {
MutableInheritedVariables().RemoveVariable(name);
} else {
MutableNonInheritedVariables().RemoveVariable(name);
}
}
CSSVariableData* ComputedStyle::GetVariable(const AtomicString& name) const {
CSSVariableData* variable = GetVariable(name, true);
if (variable) {
return variable;
}
return GetVariable(name, false);
}
CSSVariableData* ComputedStyle::GetVariable(const AtomicString& name,
bool is_inherited_property) const {
if (is_inherited_property) {
return InheritedVariables() ? InheritedVariables()->GetVariable(name)
: nullptr;
}
return NonInheritedVariables() ? NonInheritedVariables()->GetVariable(name)
: nullptr;
}
const CSSValue* ComputedStyle::GetRegisteredVariable(
const AtomicString& name,
bool is_inherited_property) const {
if (is_inherited_property) {
return InheritedVariables() ? InheritedVariables()->RegisteredVariable(name)
: nullptr;
}
return NonInheritedVariables()
? NonInheritedVariables()->RegisteredVariable(name)
: nullptr;
}
const CSSValue* ComputedStyle::GetRegisteredVariable(
const AtomicString& name) const {
// Registered custom properties are by default non-inheriting so check there
// first.
const CSSValue* result = GetRegisteredVariable(name, false);
if (result) {
return result;
}
return GetRegisteredVariable(name, true);
}
float ComputedStyle::WordSpacing() const {
return GetFontDescription().WordSpacing();
}
float ComputedStyle::LetterSpacing() const {
return GetFontDescription().LetterSpacing();
}
bool ComputedStyle::SetFontDescription(const FontDescription& v) {
if (FontInternal().GetFontDescription() != v) {
SetFontInternal(Font(v));
return true;
}
return false;
}
void ComputedStyle::SetFont(const Font& font) {
SetFontInternal(font);
}
bool ComputedStyle::HasIdenticalAscentDescentAndLineGap(
const ComputedStyle& other) const {
const SimpleFontData* font_data = GetFont().PrimaryFont();
const SimpleFontData* other_font_data = other.GetFont().PrimaryFont();
return font_data && other_font_data &&
font_data->GetFontMetrics().HasIdenticalAscentDescentAndLineGap(
other_font_data->GetFontMetrics());
}
const Length& ComputedStyle::SpecifiedLineHeight() const {
return LineHeightInternal();
}
Length ComputedStyle::LineHeight() const {
const Length& lh = LineHeightInternal();
// Unlike getFontDescription().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.
if (lh.IsFixed()) {
float multiplier = TextAutosizingMultiplier();
return Length(
TextAutosizer::ComputeAutosizedFontSize(lh.Value(), multiplier),
kFixed);
}
return lh;
}
int ComputedStyle::ComputedLineHeight() const {
const Length& lh = LineHeight();
// Negative value means the line height is not set. Use the font's built-in
// spacing, if avalible.
if (lh.IsNegative() && GetFont().PrimaryFont())
return GetFont().PrimaryFont()->GetFontMetrics().LineSpacing();
if (lh.IsPercentOrCalc())
return MinimumValueForLength(lh, LayoutUnit(ComputedFontSize())).ToInt();
return std::min(lh.Value(), LayoutUnit::Max().ToFloat());
}
LayoutUnit ComputedStyle::ComputedLineHeightAsFixed() const {
const Length& lh = LineHeight();
// Negative value means the line height is not set. Use the font's built-in
// spacing, if avalible.
if (lh.IsNegative() && GetFont().PrimaryFont())
return GetFont().PrimaryFont()->GetFontMetrics().FixedLineSpacing();
if (lh.IsPercentOrCalc()) {
return LayoutUnit(
MinimumValueForLength(lh, ComputedFontSizeAsFixed()).ToInt());
}
return LayoutUnit(floorf(lh.Value()));
}
void ComputedStyle::SetWordSpacing(float word_spacing) {
FontSelector* current_font_selector = GetFont().GetFontSelector();
FontDescription desc(GetFontDescription());
desc.SetWordSpacing(word_spacing);
SetFontDescription(desc);
GetFont().Update(current_font_selector);
}
void ComputedStyle::SetLetterSpacing(float letter_spacing) {
FontSelector* current_font_selector = GetFont().GetFontSelector();
FontDescription desc(GetFontDescription());
desc.SetLetterSpacing(letter_spacing);
SetFontDescription(desc);
GetFont().Update(current_font_selector);
}
void ComputedStyle::SetTextAutosizingMultiplier(float multiplier) {
SetTextAutosizingMultiplierInternal(multiplier);
float size = SpecifiedFontSize();
DCHECK(std::isfinite(size));
if (!std::isfinite(size) || size < 0)
size = 0;
else
size = std::min(kMaximumAllowedFontSize, size);
FontSelector* current_font_selector = GetFont().GetFontSelector();
FontDescription desc(GetFontDescription());
desc.SetSpecifiedSize(size);
desc.SetComputedSize(size);
float autosized_font_size =
TextAutosizer::ComputeAutosizedFontSize(size, multiplier);
float computed_size = autosized_font_size * EffectiveZoom();
desc.SetComputedSize(std::min(kMaximumAllowedFontSize, computed_size));
SetFontDescription(desc);
GetFont().Update(current_font_selector);
}
void ComputedStyle::AddAppliedTextDecoration(
const AppliedTextDecoration& decoration) {
scoped_refptr<AppliedTextDecorationList>& list =
MutableAppliedTextDecorationsInternal();
if (!list)
list = AppliedTextDecorationList::Create();
else if (!list->HasOneRef())
list = list->Copy();
list->push_back(decoration);
}
void ComputedStyle::OverrideTextDecorationColors(Color override_color) {
scoped_refptr<AppliedTextDecorationList>& list =
MutableAppliedTextDecorationsInternal();
DCHECK(list);
if (!list->HasOneRef())
list = list->Copy();
for (size_t i = 0; i < list->size(); ++i)
list->at(i).SetColor(override_color);
}
void ComputedStyle::ApplyTextDecorations(
const Color& parent_text_decoration_color,
bool override_existing_colors) {
if (GetTextDecoration() == TextDecoration::kNone &&
!HasSimpleUnderlineInternal() && !AppliedTextDecorationsInternal())
return;
// If there are any color changes or decorations set by this element, stop
// using m_hasSimpleUnderline.
Color current_text_decoration_color =
VisitedDependentColor(GetCSSPropertyTextDecorationColor());
if (HasSimpleUnderlineInternal() &&
(GetTextDecoration() != TextDecoration::kNone ||
current_text_decoration_color != parent_text_decoration_color)) {
SetHasSimpleUnderlineInternal(false);
AddAppliedTextDecoration(AppliedTextDecoration(
TextDecoration::kUnderline, ETextDecorationStyle::kSolid,
parent_text_decoration_color));
}
if (override_existing_colors && AppliedTextDecorationsInternal())
OverrideTextDecorationColors(current_text_decoration_color);
if (GetTextDecoration() == TextDecoration::kNone)
return;
DCHECK(!HasSimpleUnderlineInternal());
// To save memory, we don't use AppliedTextDecoration objects in the common
// case of a single simple underline of currentColor.
TextDecoration decoration_lines = GetTextDecoration();
ETextDecorationStyle decoration_style = TextDecorationStyle();
bool is_simple_underline = decoration_lines == TextDecoration::kUnderline &&
decoration_style == ETextDecorationStyle::kSolid &&
TextDecorationColor().IsCurrentColor();
if (is_simple_underline && !AppliedTextDecorationsInternal()) {
SetHasSimpleUnderlineInternal(true);
return;
}
AddAppliedTextDecoration(AppliedTextDecoration(
decoration_lines, decoration_style, current_text_decoration_color));
}
void ComputedStyle::ClearAppliedTextDecorations() {
SetHasSimpleUnderlineInternal(false);
if (AppliedTextDecorationsInternal())
SetAppliedTextDecorationsInternal(nullptr);
}
void ComputedStyle::RestoreParentTextDecorations(
const ComputedStyle& parent_style) {
SetHasSimpleUnderlineInternal(parent_style.HasSimpleUnderlineInternal());
if (AppliedTextDecorationsInternal() !=
parent_style.AppliedTextDecorationsInternal()) {
SetAppliedTextDecorationsInternal(scoped_refptr<AppliedTextDecorationList>(
parent_style.AppliedTextDecorationsInternal()));
}
}
void ComputedStyle::ClearMultiCol() {
SetColumnGap(ComputedStyleInitialValues::InitialColumnGap());
SetColumnWidthInternal(ComputedStyleInitialValues::InitialColumnWidth());
SetColumnRuleStyle(ComputedStyleInitialValues::InitialColumnRuleStyle());
SetColumnRuleWidthInternal(
LayoutUnit(ComputedStyleInitialValues::InitialColumnRuleWidth()));
SetColumnRuleColorInternal(
ComputedStyleInitialValues::InitialColumnRuleColor());
SetColumnRuleColorIsCurrentColor(
ComputedStyleInitialValues::InitialColumnRuleColorIsCurrentColor());
SetVisitedLinkColumnRuleColorInternal(
ComputedStyleInitialValues::InitialVisitedLinkColumnRuleColor());
SetColumnCountInternal(ComputedStyleInitialValues::InitialColumnCount());
SetHasAutoColumnCountInternal(
ComputedStyleInitialValues::InitialHasAutoColumnCount());
SetHasAutoColumnWidthInternal(
ComputedStyleInitialValues::InitialHasAutoColumnWidth());
ResetColumnFill();
ResetColumnSpan();
}
StyleColor ComputedStyle::DecorationColorIncludingFallback(
bool visited_link) const {
StyleColor style_color =
visited_link ? VisitedLinkTextDecorationColor() : TextDecorationColor();
if (!style_color.IsCurrentColor())
return style_color;
if (TextStrokeWidth()) {
// Prefer stroke color if possible, but not if it's fully transparent.
StyleColor text_stroke_style_color =
visited_link ? VisitedLinkTextStrokeColor() : TextStrokeColor();
if (!text_stroke_style_color.IsCurrentColor() &&
text_stroke_style_color.GetColor().Alpha())
return text_stroke_style_color;
}
return visited_link ? VisitedLinkTextFillColor() : TextFillColor();
}
Color ComputedStyle::VisitedDependentColor(
const CSSProperty& color_property) const {
Color unvisited_color =
ToLonghand(color_property).ColorIncludingFallback(false, *this);
if (InsideLink() != EInsideLink::kInsideVisitedLink)
return unvisited_color;
Color visited_color =
ToLonghand(color_property).ColorIncludingFallback(true, *this);
// Take the alpha from the unvisited color, but get the RGB values from the
// visited color.
return Color(visited_color.Red(), visited_color.Green(), visited_color.Blue(),
unvisited_color.Alpha());
}
void ComputedStyle::SetMarginStart(const Length& margin) {
if (IsHorizontalWritingMode()) {
if (IsLeftToRightDirection())
SetMarginLeft(margin);
else
SetMarginRight(margin);
} else {
if (IsLeftToRightDirection())
SetMarginTop(margin);
else
SetMarginBottom(margin);
}
}
void ComputedStyle::SetMarginEnd(const Length& margin) {
if (IsHorizontalWritingMode()) {
if (IsLeftToRightDirection())
SetMarginRight(margin);
else
SetMarginLeft(margin);
} else {
if (IsLeftToRightDirection())
SetMarginBottom(margin);
else
SetMarginTop(margin);
}
}
int ComputedStyle::OutlineOutsetExtent() const {
if (!HasOutline())
return 0;
if (OutlineStyleIsAuto()) {
return GraphicsContext::FocusRingOutsetExtent(
OutlineOffset(), std::ceil(GetOutlineStrokeWidthForFocusRing()));
}
return ClampAdd(OutlineWidth(), OutlineOffset()).Max(0);
}
float ComputedStyle::GetOutlineStrokeWidthForFocusRing() const {
#if defined(OS_MACOSX)
return OutlineWidth();
#else
// Draw an outline with thickness in proportion to the zoom level, but never
// less than 1 pixel so that it remains visible.
return std::max(EffectiveZoom(), 1.f);
#endif
}
bool ComputedStyle::ColumnRuleEquivalent(
const ComputedStyle& other_style) const {
return ColumnRuleStyle() == other_style.ColumnRuleStyle() &&
ColumnRuleWidth() == other_style.ColumnRuleWidth() &&
VisitedDependentColor(GetCSSPropertyColumnRuleColor()) ==
other_style.VisitedDependentColor(GetCSSPropertyColumnRuleColor());
}
TextEmphasisMark ComputedStyle::GetTextEmphasisMark() const {
TextEmphasisMark mark = TextEmphasisMarkInternal();
if (mark != TextEmphasisMark::kAuto)
return mark;
if (IsHorizontalWritingMode())
return TextEmphasisMark::kDot;
return TextEmphasisMark::kSesame;
}
LayoutRectOutsets ComputedStyle::ImageOutsets(
const NinePieceImage& image) const {
return LayoutRectOutsets(
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 ComputedStyle::SetBorderImageSource(StyleImage* image) {
if (BorderImage().GetImage() == image)
return;
MutableBorderImageInternal().SetImage(image);
}
void ComputedStyle::SetBorderImageSlices(const LengthBox& slices) {
if (BorderImage().ImageSlices() == slices)
return;
MutableBorderImageInternal().SetImageSlices(slices);
}
void ComputedStyle::SetBorderImageSlicesFill(bool fill) {
if (BorderImage().Fill() == fill)
return;
MutableBorderImageInternal().SetFill(fill);
}
void ComputedStyle::SetBorderImageWidth(const BorderImageLengthBox& slices) {
if (BorderImage().BorderSlices() == slices)
return;
MutableBorderImageInternal().SetBorderSlices(slices);
}
void ComputedStyle::SetBorderImageOutset(const BorderImageLengthBox& outset) {
if (BorderImage().Outset() == outset)
return;
MutableBorderImageInternal().SetOutset(outset);
}
bool ComputedStyle::BorderObscuresBackground() const {
if (!HasBorder())
return false;
// Bail if we have any border-image for now. We could look at the image alpha
// to improve this.
if (BorderImage().GetImage())
return false;
BorderEdge edges[4];
GetBorderEdgeInfo(edges);
for (unsigned int i = static_cast<unsigned>(BoxSide::kTop);
i <= static_cast<unsigned>(BoxSide::kLeft); ++i) {
const BorderEdge& curr_edge = edges[i];
if (!curr_edge.ObscuresBackground())
return false;
}
return true;
}
LayoutRectOutsets ComputedStyle::BoxDecorationOutsets() const {
DCHECK(HasVisualOverflowingEffect());
LayoutRectOutsets outsets;
if (const ShadowList* box_shadow = BoxShadow())
outsets = LayoutRectOutsets(box_shadow->RectOutsetsIncludingOriginal());
if (HasBorderImageOutsets())
outsets.Unite(BorderImageOutsets());
if (HasMaskBoxImageOutsets())
outsets.Unite(MaskBoxImageOutsets());
return outsets;
}
void ComputedStyle::GetBorderEdgeInfo(BorderEdge edges[],
bool include_logical_left_edge,
bool include_logical_right_edge) const {
bool horizontal = IsHorizontalWritingMode();
edges[static_cast<unsigned>(BoxSide::kTop)] = BorderEdge(
BorderTopWidth(), VisitedDependentColor(GetCSSPropertyBorderTopColor()),
BorderTopStyle(), horizontal || include_logical_left_edge);
edges[static_cast<unsigned>(BoxSide::kRight)] =
BorderEdge(BorderRightWidth(),
VisitedDependentColor(GetCSSPropertyBorderRightColor()),
BorderRightStyle(), !horizontal || include_logical_right_edge);
edges[static_cast<unsigned>(BoxSide::kBottom)] =
BorderEdge(BorderBottomWidth(),
VisitedDependentColor(GetCSSPropertyBorderBottomColor()),
BorderBottomStyle(), horizontal || include_logical_right_edge);
edges[static_cast<unsigned>(BoxSide::kLeft)] = BorderEdge(
BorderLeftWidth(), VisitedDependentColor(GetCSSPropertyBorderLeftColor()),
BorderLeftStyle(), !horizontal || include_logical_left_edge);
}
void ComputedStyle::CopyChildDependentFlagsFrom(const ComputedStyle& other) {
if (other.HasExplicitlyInheritedProperties())
SetHasExplicitlyInheritedProperties();
}
bool ComputedStyle::ShadowListHasCurrentColor(const ShadowList* shadow_list) {
if (!shadow_list)
return false;
for (size_t i = shadow_list->Shadows().size(); i--;) {
if (shadow_list->Shadows()[i].GetColor().IsCurrentColor())
return true;
}
return false;
}
STATIC_ASSERT_ENUM(cc::OverscrollBehavior::kOverscrollBehaviorTypeAuto,
EOverscrollBehavior::kAuto);
STATIC_ASSERT_ENUM(cc::OverscrollBehavior::kOverscrollBehaviorTypeContain,
EOverscrollBehavior::kContain);
STATIC_ASSERT_ENUM(cc::OverscrollBehavior::kOverscrollBehaviorTypeNone,
EOverscrollBehavior::kNone);
} // namespace blink
|