File: LayoutBox.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (1634 lines) | stat: -rw-r--r-- 66,452 bytes parent folder | download
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
/*
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 * Copyright (C) 2003, 2006, 2007 Apple Inc. 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.
 *
 */

#ifndef LayoutBox_h
#define LayoutBox_h

#include "core/CoreExport.h"
#include "core/layout/LayoutBoxModelObject.h"
#include "core/layout/OverflowModel.h"
#include "platform/scroll/ScrollTypes.h"
#include "wtf/Compiler.h"
#include "wtf/PtrUtil.h"
#include <memory>

namespace blink {

class LayoutBlockFlow;
class LayoutMultiColumnSpannerPlaceholder;
class ShapeOutsideInfo;

struct PaintInfo;

enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
enum AvailableLogicalHeightType {
  ExcludeMarginBorderPadding,
  IncludeMarginBorderPadding
};
// When painting, overlay scrollbars do not take up space and should not affect
// clipping behavior. During hit testing, overlay scrollbars behave like regular
// scrollbars and should change how hit testing is clipped.
enum MarginDirection { BlockDirection, InlineDirection };
enum BackgroundRectType { BackgroundClipRect, BackgroundKnownOpaqueRect };

enum ShouldComputePreferred { ComputeActual, ComputePreferred };

using SnapAreaSet = HashSet<const LayoutBox*>;

struct LayoutBoxRareData {
  WTF_MAKE_NONCOPYABLE(LayoutBoxRareData);
  USING_FAST_MALLOC(LayoutBoxRareData);

 public:
  LayoutBoxRareData()
      : m_spannerPlaceholder(nullptr),
        m_overrideLogicalContentWidth(-1),
        m_overrideLogicalContentHeight(-1),
        m_hasOverrideContainingBlockContentLogicalWidth(false),
        m_hasOverrideContainingBlockContentLogicalHeight(false),
        m_percentHeightContainer(nullptr),
        m_snapContainer(nullptr),
        m_snapAreas(nullptr) {}

  // For spanners, the spanner placeholder that lays us out within the multicol
  // container.
  LayoutMultiColumnSpannerPlaceholder* m_spannerPlaceholder;

  LayoutUnit m_overrideLogicalContentWidth;
  LayoutUnit m_overrideLogicalContentHeight;

  bool m_hasOverrideContainingBlockContentLogicalWidth;
  bool m_hasOverrideContainingBlockContentLogicalHeight;
  LayoutUnit m_overrideContainingBlockContentLogicalWidth;
  LayoutUnit m_overrideContainingBlockContentLogicalHeight;

  LayoutUnit m_offsetToNextPage;

  LayoutUnit m_paginationStrut;

  LayoutBlock* m_percentHeightContainer;
  // For snap area, the owning snap container.
  LayoutBox* m_snapContainer;
  // For snap container, the descendant snap areas that contribute snap
  // points.
  std::unique_ptr<SnapAreaSet> m_snapAreas;

  SnapAreaSet& ensureSnapAreas() {
    if (!m_snapAreas)
      m_snapAreas = WTF::wrapUnique(new SnapAreaSet);

    return *m_snapAreas;
  }
};

// LayoutBox implements the full CSS box model.
//
// LayoutBoxModelObject only introduces some abstractions for LayoutInline and
// LayoutBox. The logic for the model is in LayoutBox, e.g. the storage for the
// rectangle and offset forming the CSS box (m_frameRect) and the getters for
// the different boxes.
//
// LayoutBox is also the uppermost class to support scrollbars, however the
// logic is delegated to PaintLayerScrollableArea.
// Per the CSS specification, scrollbars should "be inserted between the inner
// border edge and the outer padding edge".
// (see http://www.w3.org/TR/CSS21/visufx.html#overflow)
// Also the scrollbar width / height are removed from the content box. Taking
// the following example:
//
// <!DOCTYPE html>
// <style>
// ::-webkit-scrollbar {
//     /* Force non-overlay scrollbars */
//     width: 10px;
//     height: 20px;
// }
// </style>
// <div style="overflow:scroll; width: 100px; height: 100px">
//
// The <div>'s content box is not 100x100 as specified in the style but 90x80 as
// we remove the scrollbars from the box.
//
// The presence of scrollbars is determined by the 'overflow' property and can
// be conditioned on having layout overflow (see OverflowModel for more details
// on how we track overflow).
//
// There are 2 types of scrollbars:
// - non-overlay scrollbars take space from the content box.
// - overlay scrollbars don't and just overlay hang off from the border box,
//   potentially overlapping with the padding box's content.
// For more details on scrollbars, see PaintLayerScrollableArea.
//
//
// ***** THE BOX MODEL *****
// The CSS box model is based on a series of nested boxes:
// http://www.w3.org/TR/CSS21/box.html
//
//       |----------------------------------------------------|
//       |                                                    |
//       |                   margin-top                       |
//       |                                                    |
//       |     |-----------------------------------------|    |
//       |     |                                         |    |
//       |     |             border-top                  |    |
//       |     |                                         |    |
//       |     |    |--------------------------|----|    |    |
//       |     |    |                          |    |    |    |
//       |     |    |       padding-top        |####|    |    |
//       |     |    |                          |####|    |    |
//       |     |    |    |----------------|    |####|    |    |
//       |     |    |    |                |    |    |    |    |
//       | ML  | BL | PL |  content box   | PR | SW | BR | MR |
//       |     |    |    |                |    |    |    |    |
//       |     |    |    |----------------|    |    |    |    |
//       |     |    |                          |    |    |    |
//       |     |    |      padding-bottom      |    |    |    |
//       |     |    |--------------------------|----|    |    |
//       |     |    |                      ####|    |    |    |
//       |     |    |     scrollbar height ####| SC |    |    |
//       |     |    |                      ####|    |    |    |
//       |     |    |-------------------------------|    |    |
//       |     |                                         |    |
//       |     |           border-bottom                 |    |
//       |     |                                         |    |
//       |     |-----------------------------------------|    |
//       |                                                    |
//       |                 margin-bottom                      |
//       |                                                    |
//       |----------------------------------------------------|
//
// BL = border-left
// BR = border-right
// ML = margin-left
// MR = margin-right
// PL = padding-left
// PR = padding-right
// SC = scroll corner (contains UI for resizing (see the 'resize' property)
// SW = scrollbar width
//
// Those are just the boxes from the CSS model. Extra boxes are tracked by Blink
// (e.g. the overflows). Thus it is paramount to know which box a function is
// manipulating. Also of critical importance is the coordinate system used (see
// the COORDINATE SYSTEMS section in LayoutBoxModelObject).
class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
 public:
  explicit LayoutBox(ContainerNode*);

  PaintLayerType layerTypeRequired() const override;

  bool backgroundIsKnownToBeOpaqueInRect(
      const LayoutRect& localRect) const override;

  virtual bool backgroundShouldAlwaysBeClipped() const { return false; }

  // Use this with caution! No type checking is done!
  LayoutBox* firstChildBox() const;
  LayoutBox* firstInFlowChildBox() const;
  LayoutBox* lastChildBox() const;

  int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
  int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }

  void setX(LayoutUnit x) {
    if (x == m_frameRect.x())
      return;
    m_frameRect.setX(x);
    locationChanged();
  }
  void setY(LayoutUnit y) {
    if (y == m_frameRect.y())
      return;
    m_frameRect.setY(y);
    locationChanged();
  }
  void setWidth(LayoutUnit width) {
    if (width == m_frameRect.width())
      return;
    m_frameRect.setWidth(width);
    sizeChanged();
  }
  void setHeight(LayoutUnit height) {
    if (height == m_frameRect.height())
      return;
    m_frameRect.setHeight(height);
    sizeChanged();
  }

  LayoutUnit logicalLeft() const {
    return style()->isHorizontalWritingMode() ? m_frameRect.x()
                                              : m_frameRect.y();
  }
  LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
  LayoutUnit logicalTop() const {
    return style()->isHorizontalWritingMode() ? m_frameRect.y()
                                              : m_frameRect.x();
  }
  LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
  LayoutUnit logicalWidth() const {
    return style()->isHorizontalWritingMode() ? m_frameRect.width()
                                              : m_frameRect.height();
  }
  LayoutUnit logicalHeight() const {
    return style()->isHorizontalWritingMode() ? m_frameRect.height()
                                              : m_frameRect.width();
  }

  // Logical height of the object, including content overflowing the
  // border-after edge.
  virtual LayoutUnit logicalHeightWithVisibleOverflow() const;

  LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit,
                                           LayoutUnit,
                                           LayoutBlock*) const;
  LayoutUnit constrainLogicalHeightByMinMax(
      LayoutUnit logicalHeight,
      LayoutUnit intrinsicContentHeight) const;
  LayoutUnit constrainContentBoxLogicalHeightByMinMax(
      LayoutUnit logicalHeight,
      LayoutUnit intrinsicContentHeight) const;

  int pixelSnappedLogicalHeight() const {
    return style()->isHorizontalWritingMode() ? pixelSnappedHeight()
                                              : pixelSnappedWidth();
  }
  int pixelSnappedLogicalWidth() const {
    return style()->isHorizontalWritingMode() ? pixelSnappedWidth()
                                              : pixelSnappedHeight();
  }

  LayoutUnit minimumLogicalHeightForEmptyLine() const {
    return borderAndPaddingLogicalHeight() + scrollbarLogicalHeight() +
           lineHeight(true,
                      isHorizontalWritingMode() ? HorizontalLine : VerticalLine,
                      PositionOfInteriorLineBoxes);
  }

  void setLogicalLeft(LayoutUnit left) {
    if (style()->isHorizontalWritingMode())
      setX(left);
    else
      setY(left);
  }
  void setLogicalTop(LayoutUnit top) {
    if (style()->isHorizontalWritingMode())
      setY(top);
    else
      setX(top);
  }
  void setLogicalLocation(const LayoutPoint& location) {
    if (style()->isHorizontalWritingMode())
      setLocation(location);
    else
      setLocation(location.transposedPoint());
  }
  void setLogicalWidth(LayoutUnit size) {
    if (style()->isHorizontalWritingMode())
      setWidth(size);
    else
      setHeight(size);
  }
  void setLogicalHeight(LayoutUnit size) {
    if (style()->isHorizontalWritingMode())
      setHeight(size);
    else
      setWidth(size);
  }

  LayoutPoint location() const { return m_frameRect.location(); }
  LayoutSize locationOffset() const {
    return LayoutSize(m_frameRect.x(), m_frameRect.y());
  }
  LayoutSize size() const { return m_frameRect.size(); }
  IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }

  void setLocation(const LayoutPoint& location) {
    if (location == m_frameRect.location())
      return;
    m_frameRect.setLocation(location);
    locationChanged();
  }

  // The ancestor box that this object's location and physicalLocation are
  // relative to.
  virtual LayoutBox* locationContainer() const;

  // FIXME: Currently scrollbars are using int geometry and positioned based on
  // pixelSnappedBorderBoxRect whose size may change when location changes
  // because of pixel snapping. This function is used to change location of the
  // LayoutBox outside of LayoutBox::layout(). Will remove when we use
  // LayoutUnits for scrollbars.
  void setLocationAndUpdateOverflowControlsIfNeeded(const LayoutPoint&);

  void setSize(const LayoutSize& size) {
    if (size == m_frameRect.size())
      return;
    m_frameRect.setSize(size);
    sizeChanged();
  }
  void move(LayoutUnit dx, LayoutUnit dy) {
    if (!dx && !dy)
      return;
    m_frameRect.move(dx, dy);
    locationChanged();
  }

  // This function is in the container's coordinate system, meaning
  // that it includes the logical top/left offset and the
  // inline-start/block-start margins.
  LayoutRect frameRect() const { return m_frameRect; }
  void setFrameRect(const LayoutRect& rect) {
    setLocation(rect.location());
    setSize(rect.size());
  }

  // Note that those functions have their origin at this box's CSS border box.
  // As such their location doesn't account for 'top'/'left'.
  LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
  LayoutRect paddingBoxRect() const {
    return LayoutRect(LayoutUnit(borderLeft()), LayoutUnit(borderTop()),
                      clientWidth(), clientHeight());
  }
  IntRect pixelSnappedBorderBoxRect() const {
    return IntRect(IntPoint(), m_frameRect.pixelSnappedSize());
  }
  IntRect borderBoundingBox() const final {
    return pixelSnappedBorderBoxRect();
  }

  // The content area of the box (excludes padding - and intrinsic padding for
  // table cells, etc... - and border).
  DISABLE_CFI_PERF LayoutRect contentBoxRect() const {
    return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(),
                      contentWidth(), contentHeight());
  }
  LayoutSize contentBoxOffset() const {
    return LayoutSize(borderLeft() + paddingLeft(), borderTop() + paddingTop());
  }
  // The content box in absolute coords. Ignores transforms.
  IntRect absoluteContentBox() const;
  // The offset of the content box in absolute coords, ignoring transforms.
  IntSize absoluteContentBoxOffset() const;
  // The content box converted to absolute coords (taking transforms into
  // account).
  FloatQuad absoluteContentQuad() const;
  // The enclosing rectangle of the background with given opacity requirement.
  LayoutRect backgroundRect(BackgroundRectType) const;

  // This returns the content area of the box (excluding padding and border).
  // The only difference with contentBoxRect is that computedCSSContentBoxRect
  // does include the intrinsic padding in the content box as this is what some
  // callers expect (like getComputedStyle).
  LayoutRect computedCSSContentBoxRect() const {
    return LayoutRect(
        borderLeft() + computedCSSPaddingLeft(),
        borderTop() + computedCSSPaddingTop(),
        clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(),
        clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom());
  }

  void addOutlineRects(Vector<LayoutRect>&,
                       const LayoutPoint& additionalOffset,
                       IncludeBlockVisualOverflowOrNot) const override;

  // Use this with caution! No type checking is done!
  LayoutBox* previousSiblingBox() const;
  LayoutBox* previousInFlowSiblingBox() const;
  LayoutBox* nextSiblingBox() const;
  LayoutBox* nextInFlowSiblingBox() const;
  LayoutBox* parentBox() const;

  // Return the previous sibling column set or spanner placeholder. Only to be
  // used on multicol container children.
  LayoutBox* previousSiblingMultiColumnBox() const;
  // Return the next sibling column set or spanner placeholder. Only to be used
  // on multicol container children.
  LayoutBox* nextSiblingMultiColumnBox() const;

  bool canResize() const;

  // Visual and layout overflow are in the coordinate space of the box. This
  // means that they aren't purely physical directions. For horizontal-tb and
  // vertical-lr they will match physical directions, but for vertical-rl, the
  // left/right are flipped when compared to their physical counterparts.
  // For example minX is on the left in vertical-lr, but it is on the right in
  // vertical-rl.
  LayoutRect noOverflowRect() const;
  LayoutRect layoutOverflowRect() const {
    return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect();
  }
  IntRect pixelSnappedLayoutOverflowRect() const {
    return pixelSnappedIntRect(layoutOverflowRect());
  }
  LayoutSize maxLayoutOverflow() const {
    return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY());
  }
  LayoutUnit logicalLeftLayoutOverflow() const {
    return style()->isHorizontalWritingMode() ? layoutOverflowRect().x()
                                              : layoutOverflowRect().y();
  }
  LayoutUnit logicalRightLayoutOverflow() const {
    return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX()
                                              : layoutOverflowRect().maxY();
  }

  LayoutRect visualOverflowRect() const override;
  LayoutUnit logicalLeftVisualOverflow() const {
    return style()->isHorizontalWritingMode() ? visualOverflowRect().x()
                                              : visualOverflowRect().y();
  }
  LayoutUnit logicalRightVisualOverflow() const {
    return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX()
                                              : visualOverflowRect().maxY();
  }

  LayoutRect selfVisualOverflowRect() const {
    return m_overflow ? m_overflow->selfVisualOverflowRect() : borderBoxRect();
  }
  LayoutRect contentsVisualOverflowRect() const {
    return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect();
  }

  // These methods don't mean the box *actually* has top/left overflow. They
  // mean that *if* the box overflows, it will overflow to the top/left rather
  // than the bottom/right. This happens when child content is laid out
  // right-to-left (e.g. direction:rtl) or or bottom-to-top (e.g. direction:rtl
  // writing-mode:vertical-rl).
  virtual bool hasTopOverflow() const;
  virtual bool hasLeftOverflow() const;

  void addLayoutOverflow(const LayoutRect&);
  void addSelfVisualOverflow(const LayoutRect&);
  void addContentsVisualOverflow(const LayoutRect&);

  void addVisualEffectOverflow();
  LayoutRectOutsets computeVisualEffectOverflowOutsets() const;
  void addOverflowFromChild(LayoutBox* child) {
    addOverflowFromChild(child, child->locationOffset());
  }
  void addOverflowFromChild(LayoutBox* child, const LayoutSize& delta);
  void clearLayoutOverflow();
  void clearAllOverflows() { m_overflow.reset(); }

  void updateLayerTransformAfterLayout();

  DISABLE_CFI_PERF LayoutUnit contentWidth() const {
    return clientWidth() - paddingLeft() - paddingRight();
  }
  DISABLE_CFI_PERF LayoutUnit contentHeight() const {
    return clientHeight() - paddingTop() - paddingBottom();
  }
  LayoutSize contentSize() const {
    return LayoutSize(contentWidth(), contentHeight());
  }
  LayoutUnit contentLogicalWidth() const {
    return style()->isHorizontalWritingMode() ? contentWidth()
                                              : contentHeight();
  }
  LayoutUnit contentLogicalHeight() const {
    return style()->isHorizontalWritingMode() ? contentHeight()
                                              : contentWidth();
  }

  // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines
  // (LayoutFlow) to return the remaining width on a given line (and the height
  // of a single line).
  LayoutUnit offsetWidth() const override { return m_frameRect.width(); }
  LayoutUnit offsetHeight() const override { return m_frameRect.height(); }

  int pixelSnappedOffsetWidth(const Element*) const final;
  int pixelSnappedOffsetHeight(const Element*) const final;

  // More IE extensions.  clientWidth and clientHeight represent the interior of
  // an object excluding border and scrollbar. clientLeft/Top are just the
  // borderLeftWidth and borderTopWidth.
  DISABLE_CFI_PERF LayoutUnit clientLeft() const {
    return LayoutUnit(borderLeft() +
                      (shouldPlaceBlockDirectionScrollbarOnLogicalLeft()
                           ? verticalScrollbarWidth()
                           : 0));
  }
  DISABLE_CFI_PERF LayoutUnit clientTop() const {
    return LayoutUnit(borderTop());
  }
  LayoutUnit clientWidth() const;
  LayoutUnit clientHeight() const;
  DISABLE_CFI_PERF LayoutUnit clientLogicalWidth() const {
    return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight();
  }
  DISABLE_CFI_PERF LayoutUnit clientLogicalHeight() const {
    return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth();
  }
  DISABLE_CFI_PERF LayoutUnit clientLogicalBottom() const {
    return borderBefore() + clientLogicalHeight();
  }
  DISABLE_CFI_PERF LayoutRect clientBoxRect() const {
    return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight());
  }

  int pixelSnappedClientWidth() const;
  int pixelSnappedClientHeight() const;

  // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight
  // unless the object has overflow:hidden/scroll/auto specified and also has
  // overflow. scrollLeft/Top return the current scroll position. These methods
  // are virtual so that objects like textareas can scroll shadow content (but
  // pretend that they are the objects that are scrolling).
  virtual LayoutUnit scrollLeft() const;
  virtual LayoutUnit scrollTop() const;
  virtual LayoutUnit scrollWidth() const;
  virtual LayoutUnit scrollHeight() const;
  int pixelSnappedScrollWidth() const;
  int pixelSnappedScrollHeight() const;
  virtual void setScrollLeft(LayoutUnit);
  virtual void setScrollTop(LayoutUnit);

  void scrollToPosition(const FloatPoint&,
                        ScrollBehavior = ScrollBehaviorInstant);
  void scrollByRecursively(const ScrollOffset& delta);
  // If makeVisibleInVisualViewport is set, the visual viewport will be scrolled
  // if required to make the rect visible.
  void scrollRectToVisible(const LayoutRect&,
                           const ScrollAlignment& alignX,
                           const ScrollAlignment& alignY,
                           ScrollType = ProgrammaticScroll,
                           bool makeVisibleInVisualViewport = true);

  LayoutRectOutsets marginBoxOutsets() const override {
    return m_marginBoxOutsets;
  }
  LayoutUnit marginTop() const override { return m_marginBoxOutsets.top(); }
  LayoutUnit marginBottom() const override {
    return m_marginBoxOutsets.bottom();
  }
  LayoutUnit marginLeft() const override { return m_marginBoxOutsets.left(); }
  LayoutUnit marginRight() const override { return m_marginBoxOutsets.right(); }
  void setMarginTop(LayoutUnit margin) { m_marginBoxOutsets.setTop(margin); }
  void setMarginBottom(LayoutUnit margin) {
    m_marginBoxOutsets.setBottom(margin);
  }
  void setMarginLeft(LayoutUnit margin) { m_marginBoxOutsets.setLeft(margin); }
  void setMarginRight(LayoutUnit margin) {
    m_marginBoxOutsets.setRight(margin);
  }

  LayoutUnit marginLogicalLeft() const {
    return m_marginBoxOutsets.logicalLeft(style()->getWritingMode());
  }
  LayoutUnit marginLogicalRight() const {
    return m_marginBoxOutsets.logicalRight(style()->getWritingMode());
  }

  LayoutUnit marginBefore(
      const ComputedStyle* overrideStyle = nullptr) const final {
    return m_marginBoxOutsets.before(
        (overrideStyle ? overrideStyle : style())->getWritingMode());
  }
  LayoutUnit marginAfter(
      const ComputedStyle* overrideStyle = nullptr) const final {
    return m_marginBoxOutsets.after(
        (overrideStyle ? overrideStyle : style())->getWritingMode());
  }
  LayoutUnit marginStart(
      const ComputedStyle* overrideStyle = nullptr) const final {
    const ComputedStyle* styleToUse = overrideStyle ? overrideStyle : style();
    return m_marginBoxOutsets.start(styleToUse->getWritingMode(),
                                    styleToUse->direction());
  }
  LayoutUnit marginEnd(
      const ComputedStyle* overrideStyle = nullptr) const final {
    const ComputedStyle* styleToUse = overrideStyle ? overrideStyle : style();
    return m_marginBoxOutsets.end(styleToUse->getWritingMode(),
                                  styleToUse->direction());
  }
  LayoutUnit marginOver() const final {
    return m_marginBoxOutsets.over(style()->getWritingMode());
  }
  LayoutUnit marginUnder() const final {
    return m_marginBoxOutsets.under(style()->getWritingMode());
  }
  void setMarginBefore(LayoutUnit value,
                       const ComputedStyle* overrideStyle = nullptr) {
    m_marginBoxOutsets.setBefore(
        (overrideStyle ? overrideStyle : style())->getWritingMode(), value);
  }
  void setMarginAfter(LayoutUnit value,
                      const ComputedStyle* overrideStyle = nullptr) {
    m_marginBoxOutsets.setAfter(
        (overrideStyle ? overrideStyle : style())->getWritingMode(), value);
  }
  void setMarginStart(LayoutUnit value,
                      const ComputedStyle* overrideStyle = nullptr) {
    const ComputedStyle* styleToUse = overrideStyle ? overrideStyle : style();
    m_marginBoxOutsets.setStart(styleToUse->getWritingMode(),
                                styleToUse->direction(), value);
  }
  void setMarginEnd(LayoutUnit value,
                    const ComputedStyle* overrideStyle = nullptr) {
    const ComputedStyle* styleToUse = overrideStyle ? overrideStyle : style();
    m_marginBoxOutsets.setEnd(styleToUse->getWritingMode(),
                              styleToUse->direction(), value);
  }

  // The following functions are used to implement collapsing margins.
  // All objects know their maximal positive and negative margins. The formula
  // for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
  // For a non-collapsing box, such as a leaf element, this formula will simply
  // return the margin of the element.  Blocks override the maxMarginBefore and
  // maxMarginAfter methods.
  virtual bool isSelfCollapsingBlock() const { return false; }
  virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
  virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
  LayoutRectOutsets collapsedMarginBoxLogicalOutsets() const {
    return LayoutRectOutsets(collapsedMarginBefore(), LayoutUnit(),
                             collapsedMarginAfter(), LayoutUnit());
  }

  void absoluteRects(Vector<IntRect>&,
                     const LayoutPoint& accumulatedOffset) const override;
  void absoluteQuads(Vector<FloatQuad>&,
                     MapCoordinatesFlags mode = 0) const override;
  FloatRect localBoundingBoxRectForAccessibility() const final;

  void layout() override;
  void paint(const PaintInfo&, const LayoutPoint&) const override;
  bool nodeAtPoint(HitTestResult&,
                   const HitTestLocation& locationInContainer,
                   const LayoutPoint& accumulatedOffset,
                   HitTestAction) override;

  LayoutUnit minPreferredLogicalWidth() const override;
  LayoutUnit maxPreferredLogicalWidth() const override;

  // FIXME: We should rename these back to overrideLogicalHeight/Width and have
  // them store the border-box height/width like the regular height/width
  // accessors on LayoutBox. Right now, these are different than contentHeight/
  // contentWidth because they still include the scrollbar height/width.
  LayoutUnit overrideLogicalContentWidth() const;
  LayoutUnit overrideLogicalContentHeight() const;
  bool hasOverrideLogicalContentHeight() const;
  bool hasOverrideLogicalContentWidth() const;
  void setOverrideLogicalContentHeight(LayoutUnit);
  void setOverrideLogicalContentWidth(LayoutUnit);
  void clearOverrideSize();
  void clearOverrideLogicalContentHeight();
  void clearOverrideLogicalContentWidth();

  LayoutUnit overrideContainingBlockContentLogicalWidth() const;
  LayoutUnit overrideContainingBlockContentLogicalHeight() const;
  bool hasOverrideContainingBlockLogicalWidth() const;
  bool hasOverrideContainingBlockLogicalHeight() const;
  void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
  void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
  void clearContainingBlockOverrideSize();
  void clearOverrideContainingBlockContentLogicalHeight();

  LayoutUnit extraInlineOffset() const;
  LayoutUnit extraBlockOffset() const;
  void setExtraInlineOffset(LayoutUnit inlineOffest);
  void setExtraBlockOffset(LayoutUnit blockOffest);
  void clearExtraInlineAndBlockOffests();

  LayoutSize offsetFromContainer(const LayoutObject*) const override;

  LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(float width) const;
  LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(float height) const;
  LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(float width) const;
  LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(float height) const;

  // ComputedMarginValues holds the actual values for margins. It ignores
  // margin collapsing as they are handled in LayoutBlockFlow.
  // The margins are stored in logical coordinates (see COORDINATE
  // SYSTEMS in LayoutBoxModel) for use during layout.
  struct ComputedMarginValues {
    DISALLOW_NEW();
    ComputedMarginValues() {}

    LayoutUnit m_before;
    LayoutUnit m_after;
    LayoutUnit m_start;
    LayoutUnit m_end;
  };

  // LogicalExtentComputedValues is used both for the
  // block-flow and inline-direction axis.
  struct LogicalExtentComputedValues {
    STACK_ALLOCATED();
    LogicalExtentComputedValues() {}

    // This is the dimension in the measured direction
    // (logical height or logical width).
    LayoutUnit m_extent;

    // This is the offset in the measured direction
    // (logical top or logical left).
    LayoutUnit m_position;

    // |m_margins| represents the margins in the measured direction.
    // Note that ComputedMarginValues has also the margins in
    // the orthogonal direction to have clearer names but they are
    // ignored in the code.
    ComputedMarginValues m_margins;
  };

  // Resolve auto margins in the chosen direction of the containing block so
  // that objects can be pushed to the start, middle or end of the containing
  // block.
  void computeMarginsForDirection(MarginDirection forDirection,
                                  const LayoutBlock* containingBlock,
                                  LayoutUnit containerWidth,
                                  LayoutUnit childWidth,
                                  LayoutUnit& marginStart,
                                  LayoutUnit& marginEnd,
                                  Length marginStartLength,
                                  Length marginStartEnd) const;

  // Used to resolve margins in the containing block's block-flow direction.
  void computeAndSetBlockDirectionMargins(const LayoutBlock* containingBlock);

  LayoutUnit offsetFromLogicalTopOfFirstPage() const;

  // The block offset from the logical top of this object to the end of the
  // first fragmentainer it lives in. If it only lives in one fragmentainer, 0
  // is returned.
  LayoutUnit offsetToNextPage() const {
    return m_rareData ? m_rareData->m_offsetToNextPage : LayoutUnit();
  }
  void setOffsetToNextPage(LayoutUnit);

  // Specify which page or column to associate with an offset, if said offset is
  // exactly at a page or column boundary.
  enum PageBoundaryRule { AssociateWithFormerPage, AssociateWithLatterPage };
  LayoutUnit pageLogicalHeightForOffset(LayoutUnit) const;
  bool isPageLogicalHeightKnown() const;
  LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit,
                                                 PageBoundaryRule) const;

  bool crossesPageBoundary(LayoutUnit offset, LayoutUnit logicalHeight) const;

  // Calculate the strut to insert in order fit content of size
  // |contentLogicalHeight|. |strutToNextPage| is the strut to add to |offset|
  // to merely get to the top of the next page or column. This is what will be
  // returned if the content can actually fit there. Otherwise, return the
  // distance to the next fragmentainer that can fit this piece of content.
  virtual LayoutUnit calculatePaginationStrutToFitContent(
      LayoutUnit offset,
      LayoutUnit strutToNextPage,
      LayoutUnit contentLogicalHeight) const;

  void positionLineBox(InlineBox*);
  void moveWithEdgeOfInlineContainerIfNecessary(bool isHorizontal);

  virtual InlineBox* createInlineBox();
  void dirtyLineBoxes(bool fullLayout);

  // For atomic inline elements, this function returns the inline box that
  // contains us. Enables the atomic inline LayoutObject to quickly determine
  // what line it is contained on and to easily iterate over structures on the
  // line.
  InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
  void setInlineBoxWrapper(InlineBox*);
  void deleteLineBoxWrapper();

  void setSpannerPlaceholder(LayoutMultiColumnSpannerPlaceholder&);
  void clearSpannerPlaceholder();
  LayoutMultiColumnSpannerPlaceholder* spannerPlaceholder() const final {
    return m_rareData ? m_rareData->m_spannerPlaceholder : 0;
  }

  // A pagination strut is the amount of space needed to push an in-flow block-
  // level object (or float) to the logical top of the next page or column. It
  // will be set both for forced breaks (e.g. page-break-before:always) and soft
  // breaks (when there's not enough space in the current page / column for the
  // object). The strut is baked into the logicalTop() of the object, so that
  // logicalTop() - paginationStrut() == the original position in the previous
  // column before deciding to break.
  //
  // Pagination struts are either set in front of a block-level box (here) or
  // before a line (RootInlineBox::paginationStrut()).
  LayoutUnit paginationStrut() const {
    return m_rareData ? m_rareData->m_paginationStrut : LayoutUnit();
  }
  void setPaginationStrut(LayoutUnit);
  void resetPaginationStrut() {
    if (m_rareData)
      m_rareData->m_paginationStrut = LayoutUnit();
  }

  // Is the specified break-before or break-after value supported on this
  // object? It needs to be in-flow all the way up to a fragmentation context
  // that supports the specified value.
  bool isBreakBetweenControllable(EBreak) const;

  // Is the specified break-inside value supported on this object? It needs to
  // be contained by a fragmentation context that supports the specified value.
  bool isBreakInsideControllable(EBreak) const;

  virtual EBreak breakAfter() const;
  virtual EBreak breakBefore() const;
  EBreak breakInside() const;

  // Join two adjacent break values specified on break-before and/or break-
  // after. avoid* values win over auto values, and forced break values win over
  // avoid* values. |firstValue| is specified on an element earlier in the flow
  // than |secondValue|. This method is used at class A break points [1], to
  // join the values of the previous break-after and the next break-before, to
  // figure out whether we may, must, or should not, break at that point. It is
  // also used when propagating break-before values from first children and
  // break-after values on last children to their container.
  //
  // [1] https://drafts.csswg.org/css-break/#possible-breaks
  static EBreak joinFragmentainerBreakValues(EBreak firstValue,
                                             EBreak secondValue);

  static bool isForcedFragmentainerBreakValue(EBreak);

  EBreak classABreakPointValue(EBreak previousBreakAfterValue) const;

  // Return true if we should insert a break in front of this box. The box needs
  // to start at a valid class A break point in order to allow a forced break.
  // To determine whether or not to break, we also need to know the break-after
  // value of the previous in-flow sibling.
  bool needsForcedBreakBefore(EBreak previousBreakAfterValue) const;

  bool paintedOutputOfObjectHasNoEffectRegardlessOfSize() const override;
  LayoutRect localVisualRect() const override;
  bool mapToVisualRectInAncestorSpace(
      const LayoutBoxModelObject* ancestor,
      LayoutRect&,
      VisualRectFlags = DefaultVisualRectFlags) const override;

  LayoutUnit containingBlockLogicalHeightForGetComputedStyle() const;

  LayoutUnit containingBlockLogicalWidthForContent() const override;
  LayoutUnit containingBlockLogicalHeightForContent(
      AvailableLogicalHeightType) const;

  LayoutUnit containingBlockAvailableLineWidth() const;
  LayoutUnit perpendicularContainingBlockLogicalHeight() const;

  virtual void updateLogicalWidth();
  void updateLogicalHeight();
  void computeLogicalHeight(LogicalExtentComputedValues&) const;
  virtual void computeLogicalHeight(LayoutUnit logicalHeight,
                                    LayoutUnit logicalTop,
                                    LogicalExtentComputedValues&) const;
  // This function will compute the logical border-box height, without laying
  // out the box. This means that the result is only "correct" when the height
  // is explicitly specified. This function exists so that intrinsic width
  // calculations have a way to deal with children that have orthogonal flows.
  // When there is no explicit height, this function assumes a content height of
  // zero (and returns just border+padding).
  LayoutUnit computeLogicalHeightWithoutLayout() const;

  void computeLogicalWidth(LogicalExtentComputedValues&) const;

  bool stretchesToViewport() const {
    return document().inQuirksMode() && stretchesToViewportInQuirksMode();
  }

  virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
  LayoutUnit intrinsicLogicalWidth() const {
    return style()->isHorizontalWritingMode() ? intrinsicSize().width()
                                              : intrinsicSize().height();
  }
  LayoutUnit intrinsicLogicalHeight() const {
    return style()->isHorizontalWritingMode() ? intrinsicSize().height()
                                              : intrinsicSize().width();
  }
  virtual LayoutUnit intrinsicContentLogicalHeight() const {
    return m_intrinsicContentLogicalHeight;
  }

  // Whether or not the element shrinks to its intrinsic width (rather than
  // filling the width of a containing block). HTML4 buttons, <select>s,
  // <input>s, legends, and floating/compact elements do this.
  bool sizesLogicalWidthToFitContent(const Length& logicalWidth) const;

  LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart,
                                             LayoutUnit childMarginEnd,
                                             const LayoutBlockFlow* cb) const;

  LayoutUnit computeLogicalWidthUsing(SizeType,
                                      const Length& logicalWidth,
                                      LayoutUnit availableLogicalWidth,
                                      const LayoutBlock* containingBlock) const;
  LayoutUnit computeLogicalHeightUsing(SizeType,
                                       const Length& height,
                                       LayoutUnit intrinsicContentHeight) const;
  LayoutUnit computeContentLogicalHeight(
      SizeType,
      const Length& height,
      LayoutUnit intrinsicContentHeight) const;
  LayoutUnit computeContentAndScrollbarLogicalHeightUsing(
      SizeType,
      const Length& height,
      LayoutUnit intrinsicContentHeight) const;
  LayoutUnit computeReplacedLogicalWidthUsing(SizeType,
                                              const Length& width) const;
  LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(
      LayoutUnit logicalWidth,
      ShouldComputePreferred = ComputeActual) const;
  LayoutUnit computeReplacedLogicalHeightUsing(SizeType,
                                               const Length& height) const;
  LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(
      LayoutUnit logicalHeight) const;

  virtual LayoutUnit computeReplacedLogicalWidth(
      ShouldComputePreferred = ComputeActual) const;
  virtual LayoutUnit computeReplacedLogicalHeight(
      LayoutUnit estimatedUsedWidth = LayoutUnit()) const;

  bool percentageLogicalHeightIsResolvable() const;
  LayoutUnit computePercentageLogicalHeight(const Length& height) const;

  // Block flows subclass availableWidth/Height to handle multi column layout
  // (shrinking the width/height available to children when laying out.)
  LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
  LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
  LayoutUnit availableLogicalHeightUsing(const Length&,
                                         AvailableLogicalHeightType) const;

  // There are a few cases where we need to refer specifically to the available
  // physical width and available physical height. Relative positioning is one
  // of those cases, since left/top offsets are physical.
  LayoutUnit availableWidth() const {
    return style()->isHorizontalWritingMode()
               ? availableLogicalWidth()
               : availableLogicalHeight(IncludeMarginBorderPadding);
  }
  LayoutUnit availableHeight() const {
    return style()->isHorizontalWritingMode()
               ? availableLogicalHeight(IncludeMarginBorderPadding)
               : availableLogicalWidth();
  }

  int verticalScrollbarWidth() const;
  int horizontalScrollbarHeight() const;
  int scrollbarLogicalWidth() const {
    return style()->isHorizontalWritingMode() ? verticalScrollbarWidth()
                                              : horizontalScrollbarHeight();
  }
  int scrollbarLogicalHeight() const {
    return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight()
                                              : verticalScrollbarWidth();
  }
  virtual ScrollResult scroll(ScrollGranularity, const FloatSize&);
  bool canBeScrolledAndHasScrollableArea() const;
  virtual bool canBeProgramaticallyScrolled() const;
  virtual void autoscroll(const IntPoint&);
  bool canAutoscroll() const;
  IntSize calculateAutoscrollDirection(const IntPoint& pointInRootFrame) const;
  static LayoutBox* findAutoscrollable(LayoutObject*);
  virtual void stopAutoscroll() {}

  DISABLE_CFI_PERF bool hasAutoVerticalScrollbar() const {
    return hasOverflowClip() && (style()->overflowY() == EOverflow::Auto ||
                                 style()->overflowY() == EOverflow::PagedY ||
                                 style()->overflowY() == EOverflow::Overlay);
  }
  DISABLE_CFI_PERF bool hasAutoHorizontalScrollbar() const {
    return hasOverflowClip() && (style()->overflowX() == EOverflow::Auto ||
                                 style()->overflowX() == EOverflow::Overlay);
  }
  DISABLE_CFI_PERF bool scrollsOverflow() const {
    return scrollsOverflowX() || scrollsOverflowY();
  }
  virtual bool shouldPlaceBlockDirectionScrollbarOnLogicalLeft() const {
    return style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft();
  }

  bool hasScrollableOverflowX() const {
    return scrollsOverflowX() &&
           pixelSnappedScrollWidth() != pixelSnappedClientWidth();
  }
  bool hasScrollableOverflowY() const {
    return scrollsOverflowY() &&
           pixelSnappedScrollHeight() != pixelSnappedClientHeight();
  }
  virtual bool scrollsOverflowX() const {
    return hasOverflowClip() && (style()->overflowX() == EOverflow::Scroll ||
                                 hasAutoHorizontalScrollbar());
  }
  virtual bool scrollsOverflowY() const {
    return hasOverflowClip() && (style()->overflowY() == EOverflow::Scroll ||
                                 hasAutoVerticalScrollbar());
  }

  // Elements such as the <input> field override this to specify that they are
  // scrollable outside the context of the CSS overflow style
  virtual bool isIntrinsicallyScrollable(
      ScrollbarOrientation orientation) const {
    return false;
  }

  bool hasUnsplittableScrollingOverflow() const;

  // Page / column breakability inside block-level objects.
  enum PaginationBreakability {
    AllowAnyBreaks,  // No restrictions on breaking. May examine children to
                     // find possible break points.
    ForbidBreaks,  // Forbid breaks inside this object. Content cannot be split
                   // nicely into smaller pieces.
    AvoidBreaks    // Preferably avoid breaks. If not possible, examine children
                   // to find possible break points.
  };
  virtual PaginationBreakability getPaginationBreakability() const;

  LayoutRect localCaretRect(
      InlineBox*,
      int caretOffset,
      LayoutUnit* extraWidthToEndOfLine = nullptr) override;

  virtual LayoutRect overflowClipRect(
      const LayoutPoint& location,
      OverlayScrollbarClipBehavior = IgnoreOverlayScrollbarSize) const;
  LayoutRect clipRect(const LayoutPoint& location) const;
  virtual bool hasControlClip() const { return false; }
  virtual LayoutRect controlClipRect(const LayoutPoint&) const {
    return LayoutRect();
  }

  // Returns the combination of overflow clip, contain: paint clip and CSS clip
  // for this object, in local space.
  LayoutRect clippingRect() const;

  virtual void paintBoxDecorationBackground(const PaintInfo&,
                                            const LayoutPoint&) const;
  virtual void paintMask(const PaintInfo&, const LayoutPoint&) const;
  void imageChanged(WrappedImagePtr, const IntRect* = nullptr) override;
  ResourcePriority computeResourcePriority() const final;

  void logicalExtentAfterUpdatingLogicalWidth(const LayoutUnit& logicalTop,
                                              LogicalExtentComputedValues&);

  PositionWithAffinity positionForPoint(const LayoutPoint&) override;

  void removeFloatingOrPositionedChildFromBlockLists();

  PaintLayer* enclosingFloatPaintingLayer() const;

  virtual int firstLineBoxBaseline() const { return -1; }
  virtual int inlineBlockBaseline(LineDirectionMode) const {
    return -1;
  }  // Returns -1 if we should skip this box when computing the baseline of an
     // inline-block.

  virtual Node* nodeForHitTest() const { return node(); }

  bool shrinkToAvoidFloats() const;
  virtual bool avoidsFloats() const;
  bool shouldBeConsideredAsReplaced() const;

  void updateFragmentationInfoForChild(LayoutBox&);
  bool childNeedsRelayoutForPagination(const LayoutBox&) const;
  void markChildForPaginationRelayoutIfNeeded(LayoutBox&, SubtreeLayoutScope&);

  bool isWritingModeRoot() const {
    return !parent() ||
           parent()->style()->getWritingMode() != style()->getWritingMode();
  }
  bool isOrthogonalWritingModeRoot() const {
    return parent() &&
           parent()->isHorizontalWritingMode() != isHorizontalWritingMode();
  }
  void markOrthogonalWritingModeRoot();
  void unmarkOrthogonalWritingModeRoot();

  bool isDeprecatedFlexItem() const {
    return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() &&
           parent()->isDeprecatedFlexibleBox();
  }
  bool isFlexItemIncludingDeprecated() const {
    return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() &&
           parent()->isFlexibleBoxIncludingDeprecated();
  }
  bool isFlexItem() const {
    return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() &&
           parent()->isFlexibleBox();
  }

  bool isGridItem() const { return parent() && parent()->isLayoutGrid(); }

  LayoutUnit lineHeight(
      bool firstLine,
      LineDirectionMode,
      LinePositionMode = PositionOnContainingLine) const override;
  int baselinePosition(
      FontBaseline,
      bool firstLine,
      LineDirectionMode,
      LinePositionMode = PositionOnContainingLine) const override;

  LayoutUnit offsetLeft(const Element*) const override;
  LayoutUnit offsetTop(const Element*) const override;

  LayoutPoint flipForWritingModeForChild(const LayoutBox* child,
                                         const LayoutPoint&) const;
  WARN_UNUSED_RESULT LayoutUnit flipForWritingMode(LayoutUnit position) const {
    // The offset is in the block direction (y for horizontal writing modes, x
    // for vertical writing modes).
    if (!UNLIKELY(hasFlippedBlocksWritingMode()))
      return position;
    return logicalHeight() - position;
  }
  WARN_UNUSED_RESULT LayoutPoint
  flipForWritingMode(const LayoutPoint& position) const {
    if (!UNLIKELY(hasFlippedBlocksWritingMode()))
      return position;
    return isHorizontalWritingMode()
               ? LayoutPoint(position.x(), m_frameRect.height() - position.y())
               : LayoutPoint(m_frameRect.width() - position.x(), position.y());
  }
  WARN_UNUSED_RESULT LayoutSize
  flipForWritingMode(const LayoutSize& offset) const {
    if (!UNLIKELY(hasFlippedBlocksWritingMode()))
      return offset;
    return LayoutSize(m_frameRect.width() - offset.width(), offset.height());
  }
  void flipForWritingMode(LayoutRect& rect) const {
    if (!UNLIKELY(hasFlippedBlocksWritingMode()))
      return;
    rect.setX(m_frameRect.width() - rect.maxX());
  }
  WARN_UNUSED_RESULT FloatPoint
  flipForWritingMode(const FloatPoint& position) const {
    if (!UNLIKELY(hasFlippedBlocksWritingMode()))
      return position;
    return FloatPoint(m_frameRect.width() - position.x(), position.y());
  }
  void flipForWritingMode(FloatRect& rect) const {
    if (!UNLIKELY(hasFlippedBlocksWritingMode()))
      return;
    rect.setX(m_frameRect.width() - rect.maxX());
  }

  // Passing |container| causes flipped-block flipping w.r.t. that container,
  // or containingBlock() otherwise.
  LayoutPoint physicalLocation(
      const LayoutBox* flippedBlocksContainer = nullptr) const;
  LayoutSize physicalLocationOffset() const {
    return toLayoutSize(physicalLocation());
  }

  LayoutRect logicalVisualOverflowRectForPropagation(
      const ComputedStyle&) const;
  LayoutRect visualOverflowRectForPropagation(const ComputedStyle&) const;
  LayoutRect logicalLayoutOverflowRectForPropagation(
      const ComputedStyle&) const;
  LayoutRect layoutOverflowRectForPropagation(const ComputedStyle&) const;

  bool hasOverflowModel() const { return m_overflow.get(); }
  bool hasSelfVisualOverflow() const {
    return m_overflow &&
           !borderBoxRect().contains(m_overflow->selfVisualOverflowRect());
  }
  bool hasVisualOverflow() const {
    return m_overflow && !borderBoxRect().contains(visualOverflowRect());
  }

  virtual bool needsPreferredWidthsRecalculation() const;

  // See README.md for an explanation of scroll origin.
  virtual IntSize originAdjustmentForScrollbars() const;
  IntSize scrolledContentOffset() const;

  // Maps a rect in scrolling contents space to box space and apply overflow
  // clip if needed. Returns true if no clipping applied or the rect actually
  // intersects the clipping region. If edgeInclusive is true, then this method
  // may return true even if the resulting rect has zero area.
  bool mapScrollingContentsRectToBoxSpace(
      LayoutRect&,
      VisualRectFlags = DefaultVisualRectFlags) const;

  virtual bool hasRelativeLogicalWidth() const;
  virtual bool hasRelativeLogicalHeight() const;

  bool hasHorizontalLayoutOverflow() const {
    if (!m_overflow)
      return false;

    LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
    LayoutRect noOverflowRect = this->noOverflowRect();
    return layoutOverflowRect.x() < noOverflowRect.x() ||
           layoutOverflowRect.maxX() > noOverflowRect.maxX();
  }

  bool hasVerticalLayoutOverflow() const {
    if (!m_overflow)
      return false;

    LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
    LayoutRect noOverflowRect = this->noOverflowRect();
    return layoutOverflowRect.y() < noOverflowRect.y() ||
           layoutOverflowRect.maxY() > noOverflowRect.maxY();
  }

  virtual LayoutBox* createAnonymousBoxWithSameTypeAs(
      const LayoutObject*) const {
    NOTREACHED();
    return nullptr;
  }

  bool hasSameDirectionAs(const LayoutBox* object) const {
    return style()->direction() == object->style()->direction();
  }

  ShapeOutsideInfo* shapeOutsideInfo() const;

  void markShapeOutsideDependentsForLayout() {
    if (isFloating())
      removeFloatingOrPositionedChildFromBlockLists();
  }

  void setIntrinsicContentLogicalHeight(
      LayoutUnit intrinsicContentLogicalHeight) const {
    m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight;
  }

  bool canRenderBorderImage() const;

  void mapLocalToAncestor(
      const LayoutBoxModelObject* ancestor,
      TransformState&,
      MapCoordinatesFlags = ApplyContainerFlip) const override;
  void mapAncestorToLocal(const LayoutBoxModelObject*,
                          TransformState&,
                          MapCoordinatesFlags) const override;

  void clearPreviousVisualRects() override;

  LayoutBlock* percentHeightContainer() const {
    return m_rareData ? m_rareData->m_percentHeightContainer : nullptr;
  }
  void setPercentHeightContainer(LayoutBlock*);
  void removeFromPercentHeightContainer();
  void clearPercentHeightDescendants();
  // For snap areas, returns the snap container that owns us.
  LayoutBox* snapContainer() const;
  void setSnapContainer(LayoutBox*);
  // For snap containers, returns all associated snap areas.
  SnapAreaSet* snapAreas() const;
  void clearSnapAreas();

  bool hitTestClippedOutByBorder(const HitTestLocation& locationInContainer,
                                 const LayoutPoint& borderBoxLocation) const;

  static bool mustInvalidateFillLayersPaintOnWidthChange(const FillLayer&);
  static bool mustInvalidateFillLayersPaintOnHeightChange(const FillLayer&);

  bool mustInvalidateBackgroundOrBorderPaintOnHeightChange() const;
  bool mustInvalidateBackgroundOrBorderPaintOnWidthChange() const;

  // Returns true if the box intersects the viewport visible to the user.
  bool intersectsVisibleViewport() const;

  bool hasNonCompositedScrollbars() const final;

  void ensureIsReadyForPaintInvalidation() override;

  virtual bool shouldClipOverflow() const;

 protected:
  void willBeDestroyed() override;

  void insertedIntoTree() override;
  void willBeRemovedFromTree() override;

  void styleWillChange(StyleDifference, const ComputedStyle& newStyle) override;
  void styleDidChange(StyleDifference, const ComputedStyle* oldStyle) override;
  void updateFromStyle() override;

  virtual ItemPosition selfAlignmentNormalBehavior() const {
    return ItemPositionStretch;
  }

  // Returns false if it could not cheaply compute the extent (e.g. fixed
  // background), in which case the returned rect may be incorrect.
  // FIXME: make this a const method once the LayoutBox reference in BoxPainter
  // is const.
  bool getBackgroundPaintedExtent(LayoutRect&) const;
  virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect,
                                                 unsigned maxDepthToTest) const;
  bool computeBackgroundIsKnownToBeObscured() const override;

  virtual void computePositionedLogicalWidth(
      LogicalExtentComputedValues&) const;

  LayoutUnit computeIntrinsicLogicalWidthUsing(
      const Length& logicalWidthLength,
      LayoutUnit availableLogicalWidth,
      LayoutUnit borderAndPadding) const;
  virtual LayoutUnit computeIntrinsicLogicalContentHeightUsing(
      const Length& logicalHeightLength,
      LayoutUnit intrinsicContentHeight,
      LayoutUnit borderAndPadding) const;

  virtual bool shouldComputeSizeAsReplaced() const {
    return isAtomicInlineLevel() && !isInlineBlockOrInlineTable();
  }

  LayoutObject* splitAnonymousBoxesAroundChild(LayoutObject* beforeChild);

  virtual bool hitTestOverflowControl(HitTestResult&,
                                      const HitTestLocation&,
                                      const LayoutPoint&) {
    return false;
  }
  virtual bool hitTestChildren(HitTestResult&,
                               const HitTestLocation& locationInContainer,
                               const LayoutPoint& accumulatedOffset,
                               HitTestAction);
  void addLayerHitTestRects(LayerHitTestRects&,
                            const PaintLayer* currentCompositedLayer,
                            const LayoutPoint& layerOffset,
                            const LayoutRect& containerRect) const override;
  void computeSelfHitTestRects(Vector<LayoutRect>&,
                               const LayoutPoint& layerOffset) const override;

  PaintInvalidationReason invalidatePaintIfNeeded(
      const PaintInvalidationState&) override;
  PaintInvalidationReason invalidatePaintIfNeeded(
      const PaintInvalidatorContext&) const override;

  bool columnFlexItemHasStretchAlignment() const;
  bool isStretchingColumnFlexItem() const;
  bool hasStretchedLogicalWidth() const;

  void excludeScrollbars(
      LayoutRect&,
      OverlayScrollbarClipBehavior = IgnoreOverlayScrollbarSize) const;

  LayoutUnit containingBlockLogicalWidthForPositioned(
      const LayoutBoxModelObject* containingBlock,
      bool checkForPerpendicularWritingMode = true) const;
  LayoutUnit containingBlockLogicalHeightForPositioned(
      const LayoutBoxModelObject* containingBlock,
      bool checkForPerpendicularWritingMode = true) const;

  static void computeBlockStaticDistance(
      Length& logicalTop,
      Length& logicalBottom,
      const LayoutBox* child,
      const LayoutBoxModelObject* containerBlock);
  static void computeInlineStaticDistance(
      Length& logicalLeft,
      Length& logicalRight,
      const LayoutBox* child,
      const LayoutBoxModelObject* containerBlock,
      LayoutUnit containerLogicalWidth);
  static void computeLogicalLeftPositionedOffset(
      LayoutUnit& logicalLeftPos,
      const LayoutBox* child,
      LayoutUnit logicalWidthValue,
      const LayoutBoxModelObject* containerBlock,
      LayoutUnit containerLogicalWidth);
  static void computeLogicalTopPositionedOffset(
      LayoutUnit& logicalTopPos,
      const LayoutBox* child,
      LayoutUnit logicalHeightValue,
      const LayoutBoxModelObject* containerBlock,
      LayoutUnit containerLogicalHeight);
  bool skipContainingBlockForPercentHeightCalculation(
      const LayoutBox* containingBlock) const;

 private:
  void updateShapeOutsideInfoAfterStyleChange(const ComputedStyle&,
                                              const ComputedStyle* oldStyle);
  void updateGridPositionAfterStyleChange(const ComputedStyle*);
  void updateScrollSnapMappingAfterStyleChange(const ComputedStyle*,
                                               const ComputedStyle* oldStyle);
  void clearScrollSnapMapping();
  void addScrollSnapMapping();

  bool autoWidthShouldFitContent() const;
  LayoutUnit shrinkToFitLogicalWidth(LayoutUnit availableLogicalWidth,
                                     LayoutUnit bordersPlusPadding) const;

  bool stretchesToViewportInQuirksMode() const;

  virtual void computePositionedLogicalHeight(
      LogicalExtentComputedValues&) const;
  void computePositionedLogicalWidthUsing(
      SizeType,
      Length logicalWidth,
      const LayoutBoxModelObject* containerBlock,
      TextDirection containerDirection,
      LayoutUnit containerLogicalWidth,
      LayoutUnit bordersPlusPadding,
      const Length& logicalLeft,
      const Length& logicalRight,
      const Length& marginLogicalLeft,
      const Length& marginLogicalRight,
      LogicalExtentComputedValues&) const;
  void computePositionedLogicalHeightUsing(
      SizeType,
      Length logicalHeightLength,
      const LayoutBoxModelObject* containerBlock,
      LayoutUnit containerLogicalHeight,
      LayoutUnit bordersPlusPadding,
      LayoutUnit logicalHeight,
      const Length& logicalTop,
      const Length& logicalBottom,
      const Length& marginLogicalTop,
      const Length& marginLogicalBottom,
      LogicalExtentComputedValues&) const;

  LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
  LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth,
                                  LayoutUnit& marginStart,
                                  LayoutUnit& marginEnd) const;

  // Calculates the intrinsic(https://drafts.csswg.org/css-sizing-3/#intrinsic)
  // logical widths for this layout box.
  //
  // intrinsicWidth is defined as:
  //     intrinsic size of content (without our border and padding) +
  //     scrollbarWidth.
  //
  // preferredWidth is defined as:
  //     fixedWidth OR (intrinsicWidth plus border and padding).
  //     Note: fixedWidth includes border and padding and scrollbarWidth.
  virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
                                             LayoutUnit& maxLogicalWidth) const;

  // This function calculates the preferred widths for an object.
  //
  // This function is only expected to be called if
  // the boolean preferredLogicalWidthsDirty is true. It also MUST clear the
  // boolean before returning.
  //
  // See INTRINSIC SIZES / PREFERRED LOGICAL WIDTHS in LayoutObject.h for more
  // details about those widths.
  virtual void computePreferredLogicalWidths() {
    clearPreferredLogicalWidthsDirty();
  }

  LayoutBoxRareData& ensureRareData() {
    if (!m_rareData)
      m_rareData = WTF::makeUnique<LayoutBoxRareData>();
    return *m_rareData.get();
  }

  bool logicalHeightComputesAsNone(SizeType) const;

  bool isBox() const =
      delete;  // This will catch anyone doing an unnecessary check.

  void locationChanged();
  void sizeChanged();

  virtual bool isInSelfHitTestingPhase(HitTestAction hitTestAction) const {
    return hitTestAction == HitTestForeground;
  }

  void updateBackgroundAttachmentFixedStatusAfterStyleChange();

  // The CSS border box rect for this box.
  //
  // The rectangle is in this box's physical coordinates but with a
  // flipped block-flow direction (see the COORDINATE SYSTEMS section
  // in LayoutBoxModelObject). The location is the distance from this
  // object's border edge to the container's border edge (which is not
  // always the parent). Thus it includes any logical top/left along
  // with this box's margins.
  LayoutRect m_frameRect;

  // Our intrinsic height, used for min-height: min-content etc. Maintained by
  // updateLogicalHeight. This is logicalHeight() before it is clamped to
  // min/max.
  mutable LayoutUnit m_intrinsicContentLogicalHeight;

  void inflateVisualRectForFilter(LayoutRect&) const;
  void inflateVisualRectForFilterUnderContainer(
      LayoutRect&,
      const LayoutObject& container,
      const LayoutBoxModelObject* ancestorToStopAt) const;

  LayoutRectOutsets m_marginBoxOutsets;

  void addSnapArea(const LayoutBox&);
  void removeSnapArea(const LayoutBox&);

  LayoutRect debugRect() const override;

 protected:
  // The logical width of the element if it were to break its lines at every
  // possible opportunity.
  //
  // See LayoutObject::minPreferredLogicalWidth() for more details.
  LayoutUnit m_minPreferredLogicalWidth;

  // The logical width of the element if it never breaks any lines at all.
  //
  // See LayoutObject::maxPreferredLogicalWidth() for more details.
  LayoutUnit m_maxPreferredLogicalWidth;

  // Our overflow information.
  std::unique_ptr<BoxOverflowModel> m_overflow;

 private:
  // The inline box containing this LayoutBox, for atomic inline elements.
  InlineBox* m_inlineBoxWrapper;

  std::unique_ptr<LayoutBoxRareData> m_rareData;
};

DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutBox, isBox());

inline LayoutBox* LayoutBox::previousSiblingBox() const {
  return toLayoutBox(previousSibling());
}

inline LayoutBox* LayoutBox::previousInFlowSiblingBox() const {
  LayoutBox* previous = previousSiblingBox();
  while (previous && previous->isOutOfFlowPositioned())
    previous = previous->previousSiblingBox();
  return previous;
}

inline LayoutBox* LayoutBox::nextSiblingBox() const {
  return toLayoutBox(nextSibling());
}

inline LayoutBox* LayoutBox::nextInFlowSiblingBox() const {
  LayoutBox* next = nextSiblingBox();
  while (next && next->isOutOfFlowPositioned())
    next = next->nextSiblingBox();
  return next;
}

inline LayoutBox* LayoutBox::parentBox() const {
  return toLayoutBox(parent());
}

inline LayoutBox* LayoutBox::firstInFlowChildBox() const {
  LayoutBox* first = firstChildBox();
  return (first && first->isOutOfFlowPositioned())
             ? first->nextInFlowSiblingBox()
             : first;
}

inline LayoutBox* LayoutBox::firstChildBox() const {
  return toLayoutBox(slowFirstChild());
}

inline LayoutBox* LayoutBox::lastChildBox() const {
  return toLayoutBox(slowLastChild());
}

inline LayoutBox* LayoutBox::previousSiblingMultiColumnBox() const {
  ASSERT(isLayoutMultiColumnSpannerPlaceholder() || isLayoutMultiColumnSet());
  LayoutBox* previousBox = previousSiblingBox();
  if (previousBox->isLayoutFlowThread())
    return nullptr;
  return previousBox;
}

inline LayoutBox* LayoutBox::nextSiblingMultiColumnBox() const {
  ASSERT(isLayoutMultiColumnSpannerPlaceholder() || isLayoutMultiColumnSet());
  return nextSiblingBox();
}

inline void LayoutBox::setInlineBoxWrapper(InlineBox* boxWrapper) {
  if (boxWrapper) {
    ASSERT(!m_inlineBoxWrapper);
    // m_inlineBoxWrapper should already be nullptr. Deleting it is a safeguard
    // against security issues. Otherwise, there will two line box wrappers
    // keeping the reference to this layoutObject, and only one will be notified
    // when the layoutObject is getting destroyed. The second line box wrapper
    // will keep a stale reference.
    if (UNLIKELY(m_inlineBoxWrapper != nullptr))
      deleteLineBoxWrapper();
  }

  m_inlineBoxWrapper = boxWrapper;
}

inline bool LayoutBox::isForcedFragmentainerBreakValue(EBreak breakValue) {
  return breakValue == BreakColumn || breakValue == BreakLeft ||
         breakValue == BreakPage || breakValue == BreakRecto ||
         breakValue == BreakRight || breakValue == BreakVerso;
}

}  // namespace blink

#endif  // LayoutBox_h