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
|
/*
* 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 THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_BOX_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_BOX_H_
#include <memory>
#include "base/check_op.h"
#include "base/dcheck_is_on.h"
#include "base/gtest_prod_util.h"
#include "base/notreached.h"
#include "third_party/blink/public/mojom/scroll/scroll_into_view_params.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/min_max_sizes.h"
#include "third_party/blink/renderer/core/layout/min_max_sizes_cache.h"
#include "third_party/blink/renderer/core/layout/overflow_model.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scrollbar_theme.h"
#include "third_party/blink/renderer/core/style/style_overflow_clip_margin.h"
#include "third_party/blink/renderer/platform/graphics/overlay_scrollbar_clip_behavior.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
class AnchorPositionScrollData;
class BlockBreakToken;
class ColumnSpannerPath;
class ConstraintSpace;
class CustomLayoutChild;
class EarlyBreak;
class Element;
class LayoutMultiColumnSpannerPlaceholder;
class LayoutResult;
class MeasureCache;
class PhysicalBoxFragment;
class ShapeOutsideInfo;
class WritingModeConverter;
enum class LayoutCacheStatus;
struct FragmentGeometry;
struct NonOverflowingScrollRange;
struct PaintInfo;
struct PhysicalBoxStrut;
enum BackgroundRectType {
kBackgroundPaintedExtent,
kBackgroundKnownOpaqueRect,
};
enum ShouldClampToContentBox { kDoNotClampToContentBox, kClampToContentBox };
enum ShouldIncludeScrollbarGutter {
kExcludeScrollbarGutter,
kIncludeScrollbarGutter
};
struct LayoutBoxRareData final : public GarbageCollected<LayoutBoxRareData> {
public:
LayoutBoxRareData();
LayoutBoxRareData(const LayoutBoxRareData&) = delete;
LayoutBoxRareData& operator=(const LayoutBoxRareData&) = delete;
void Trace(Visitor* visitor) const;
// For spanners, the spanner placeholder that lays us out within the multicol
// container.
Member<LayoutMultiColumnSpannerPlaceholder> spanner_placeholder_;
bool has_override_containing_block_content_logical_width_ : 1;
bool has_previous_content_box_rect_ : 1;
LayoutUnit override_containing_block_content_logical_width_;
// Used by BoxPaintInvalidator. Stores the previous content rect after the
// last paint invalidation. It's valid if has_previous_content_box_rect_ is
// true.
PhysicalRect previous_physical_content_box_rect_;
// Used by CSSLayoutDefinition::Instance::Layout. Represents the script
// object for this box that web developers can query style, and perform
// layout upon. Only created if IsCustomItem() is true.
Member<CustomLayoutChild> layout_child_;
};
// 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 (frame_location_ and frame_size_)
// 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 scrollable 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
//
// Note that the vertical scrollbar (if existing) will be on the left in
// right-to-left direction and horizontal writing-mode. The horizontal scrollbar
// (if existing) is always at the bottom.
//
// 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*);
void Trace(Visitor*) const override;
PaintLayerType LayerTypeRequired() const override;
bool BackgroundIsKnownToBeOpaqueInRect(
const PhysicalRect& local_rect) const override;
virtual bool BackgroundShouldAlwaysBeClipped() const {
NOT_DESTROYED();
return false;
}
// Use this with caution! No type checking is done!
LayoutBox* FirstChildBox() const;
LayoutBox* LastChildBox() const;
// Returns the LogicalRect of this box for LocationContainer()'s writing-mode.
// The coordinate origin is the border corner of the LocationContainer().
// This function doesn't take into account of TextDirection.
LogicalRect LogicalRectInContainer() const;
// Returns the inline-size for this box's writing-mode. It might be
// different from container's writing-mode.
LayoutUnit LogicalWidth() const {
NOT_DESTROYED();
PhysicalSize size = Size();
return StyleRef().IsHorizontalWritingMode() ? size.width : size.height;
}
// Returns the block-size for this box's writing-mode. It might be
// different from container's writing-mode.
LayoutUnit LogicalHeight() const {
NOT_DESTROYED();
PhysicalSize size = Size();
return StyleRef().IsHorizontalWritingMode() ? size.height : size.width;
}
LayoutUnit LogicalHeightForEmptyLine() const {
NOT_DESTROYED();
return FirstLineHeight();
}
virtual PhysicalSize Size() const;
void SetLocation(PhysicalOffset location) {
NOT_DESTROYED();
DCHECK(RuntimeEnabledFeatures::LayoutBoxVisualLocationEnabled());
if (location == frame_location_.physical_offset) {
return;
}
frame_location_.physical_offset = location;
LocationChanged();
}
void SetLocation(const DeprecatedLayoutPoint& location) {
NOT_DESTROYED();
DCHECK(!RuntimeEnabledFeatures::LayoutBoxVisualLocationEnabled());
if (location == frame_location_.layout_point) {
return;
}
frame_location_.layout_point = location;
LocationChanged();
}
// The ancestor box that this object's PhysicalLocation is relative to.
virtual LayoutBox* LocationContainer() const;
// Note that those functions have their origin at this box's CSS border box.
// As such their location doesn't account for 'top'/'left'.
PhysicalRect PhysicalBorderBoxRect() const {
NOT_DESTROYED();
return PhysicalRect(PhysicalOffset(), Size());
}
// Client rect and padding box rect are the same concept.
DISABLE_CFI_PERF PhysicalRect PhysicalPaddingBoxRect() const {
NOT_DESTROYED();
return PhysicalRect(ClientLeft(), ClientTop(), ClientWidth(),
ClientHeight());
}
// The content area of the box (excludes padding - and intrinsic padding for
// table cells, etc... - and scrollbars and border).
DISABLE_CFI_PERF PhysicalRect PhysicalContentBoxRect() const {
NOT_DESTROYED();
return PhysicalRect(ContentLeft(), ContentTop(), ContentWidth(),
ContentHeight());
}
PhysicalOffset PhysicalContentBoxOffset() const {
NOT_DESTROYED();
return PhysicalOffset(ContentLeft(), ContentTop());
}
PhysicalSize PhysicalContentBoxSize() const {
NOT_DESTROYED();
return PhysicalSize(ContentWidth(), ContentHeight());
}
// The content box converted to absolute coords (taking transforms into
// account).
gfx::QuadF AbsoluteContentQuad(MapCoordinatesFlags = 0) const;
// The enclosing rectangle of the background with given opacity requirement.
PhysicalRect PhysicalBackgroundRect(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).
PhysicalRect ComputedCSSContentBoxRect() const {
NOT_DESTROYED();
return PhysicalRect(
BorderLeft() + ComputedCSSPaddingLeft(),
BorderTop() + ComputedCSSPaddingTop(),
ClientWidth() - ComputedCSSPaddingLeft() - ComputedCSSPaddingRight(),
ClientHeight() - ComputedCSSPaddingTop() - ComputedCSSPaddingBottom());
}
void AddOutlineRects(OutlineRectCollector&,
OutlineInfo*,
const PhysicalOffset& additional_offset,
OutlineType) const override;
// Use this with caution! No type checking is done!
LayoutBox* PreviousSiblingBox() const;
LayoutBox* NextSiblingBox() 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;
DISABLE_CFI_PERF PhysicalRect NoOverflowRect() const {
NOT_DESTROYED();
return PhysicalPaddingBoxRect();
}
PhysicalRect ScrollableOverflowRect() const {
NOT_DESTROYED();
DCHECK(!IsLayoutMultiColumnSet());
return ScrollableOverflowIsSet()
? overflow_->scrollable_overflow->ScrollableOverflowRect()
: NoOverflowRect();
}
PhysicalRect VisualOverflowRect() const final;
// VisualOverflow has DCHECK for reading before it is computed. These
// functions pretend there is no visual overflow when it is not computed.
// TODO(crbug.com/1205708): Audit the usages and fix issues.
#if DCHECK_IS_ON()
PhysicalRect VisualOverflowRectAllowingUnset() const;
#else
ALWAYS_INLINE PhysicalRect VisualOverflowRectAllowingUnset() const {
NOT_DESTROYED();
return VisualOverflowRect();
}
#endif
PhysicalRect SelfVisualOverflowRect() const {
NOT_DESTROYED();
return VisualOverflowIsSet()
? overflow_->visual_overflow->SelfVisualOverflowRect()
: PhysicalBorderBoxRect();
}
PhysicalRect ContentsVisualOverflowRect() const {
NOT_DESTROYED();
return VisualOverflowIsSet()
? overflow_->visual_overflow->ContentsVisualOverflowRect()
: PhysicalRect();
}
// 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;
// Sets the scrollable-overflow from the current set of layout-results.
void SetScrollableOverflowFromLayoutResults();
void AddSelfVisualOverflow(const PhysicalRect& r);
void AddContentsVisualOverflow(const PhysicalRect& r);
void UpdateHasSubpixelVisualEffectOutsets(const PhysicalBoxStrut&);
PhysicalBoxStrut ComputeVisualEffectOverflowOutsets();
void ClearVisualOverflow();
bool CanUseFragmentsForVisualOverflow() const;
void CopyVisualOverflowFromFragments();
virtual void UpdateAfterLayout();
DISABLE_CFI_PERF LayoutUnit ContentLeft() const {
NOT_DESTROYED();
return ClientLeft() + PaddingLeft();
}
DISABLE_CFI_PERF LayoutUnit ContentTop() const {
NOT_DESTROYED();
return ClientTop() + PaddingTop();
}
DISABLE_CFI_PERF LayoutUnit ContentWidth() const {
NOT_DESTROYED();
// We're dealing with LayoutUnit and saturated arithmetic here, so we need
// to guard against negative results. The value returned from clientWidth()
// may in itself be a victim of saturated arithmetic; e.g. if both border
// sides were sufficiently wide (close to LayoutUnit::max()). Here we
// subtract two padding values from that result, which is another source of
// saturated arithmetic.
return (ClientWidth() - PaddingLeft() - PaddingRight())
.ClampNegativeToZero();
}
DISABLE_CFI_PERF LayoutUnit ContentHeight() const {
NOT_DESTROYED();
// We're dealing with LayoutUnit and saturated arithmetic here, so we need
// to guard against negative results. The value returned from clientHeight()
// may in itself be a victim of saturated arithmetic; e.g. if both border
// sides were sufficiently wide (close to LayoutUnit::max()). Here we
// subtract two padding values from that result, which is another source of
// saturated arithmetic.
return (ClientHeight() - PaddingTop() - PaddingBottom())
.ClampNegativeToZero();
}
PhysicalSize ContentSize() const {
NOT_DESTROYED();
return PhysicalSize(ContentWidth(), ContentHeight());
}
LayoutUnit ContentLogicalWidth() const {
NOT_DESTROYED();
return StyleRef().IsHorizontalWritingMode() ? ContentWidth()
: ContentHeight();
}
LayoutUnit ContentLogicalHeight() const {
NOT_DESTROYED();
return StyleRef().IsHorizontalWritingMode() ? ContentHeight()
: ContentWidth();
}
// CSS intrinsic sizing getters.
// https://drafts.csswg.org/css-sizing-4/#intrinsic-size-override
LayoutUnit OverrideIntrinsicContentInlineSize() const;
LayoutUnit OverrideIntrinsicContentBlockSize() const;
// Returns element-native intrinsic size. Returns kIndefiniteSize if no such
// size.
LayoutUnit DefaultIntrinsicContentInlineSize() const;
LayoutUnit DefaultIntrinsicContentBlockSize() const;
// 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 final;
LayoutUnit OffsetHeight() const final;
bool UsesOverlayScrollbars() const;
// Physical client rect (a.k.a. PhysicalPaddingBoxRect(), defined by
// ClientLeft, ClientTop, ClientWidth and ClientHeight) represents the
// interior of an object excluding borders and scrollbars.
// Clamps the left scrollbar size so it is not wider than the content box.
DISABLE_CFI_PERF LayoutUnit ClientLeft() const {
NOT_DESTROYED();
if (CanSkipComputeScrollbars())
return BorderLeft();
else
return BorderLeft() + ComputeScrollbarsInternal(kClampToContentBox).left;
}
DISABLE_CFI_PERF LayoutUnit ClientTop() const {
NOT_DESTROYED();
if (CanSkipComputeScrollbars())
return BorderTop();
else
return BorderTop() + ComputeScrollbarsInternal(kClampToContentBox).top;
}
// Size without borders and scrollbars.
LayoutUnit ClientWidth() const;
LayoutUnit ClientHeight() const;
// Similar to ClientWidth() and ClientHeight(), but based on the specified
// border-box size.
LayoutUnit ClientWidthFrom(LayoutUnit width) const;
LayoutUnit ClientHeightFrom(LayoutUnit height) const;
DISABLE_CFI_PERF LayoutUnit ClientLogicalWidth() const {
NOT_DESTROYED();
return IsHorizontalWritingMode() ? ClientWidth() : ClientHeight();
}
DISABLE_CFI_PERF LayoutUnit ClientLogicalHeight() const {
NOT_DESTROYED();
return IsHorizontalWritingMode() ? ClientHeight() : ClientWidth();
}
LayoutUnit ClientWidthWithTableSpecialBehavior() const;
LayoutUnit ClientHeightWithTableSpecialBehavior() const;
// scrollWidth/scrollHeight will be the same as clientWidth/clientHeight
// unless the object has overflow:hidden/scroll/auto specified and also has
// overflow. These methods are virtual so that objects like textareas can
// scroll shadow content (but pretend that they are the objects that are
// scrolling).
// Replaced ScrollLeft/Top by using Element::GetLayoutBoxForScrolling to
// return the correct ScrollableArea.
// TODO(cathiechen): We should do the same with ScrollWidth|Height .
virtual LayoutUnit ScrollWidth() const;
virtual LayoutUnit ScrollHeight() const;
PhysicalBoxStrut MarginBoxOutsets() const;
LayoutUnit MarginTop() const override {
NOT_DESTROYED();
return MarginBoxOutsets().top;
}
LayoutUnit MarginBottom() const override {
NOT_DESTROYED();
return MarginBoxOutsets().bottom;
}
LayoutUnit MarginLeft() const override {
NOT_DESTROYED();
return MarginBoxOutsets().left;
}
LayoutUnit MarginRight() const override {
NOT_DESTROYED();
return MarginBoxOutsets().right;
}
// Get the scroll marker group associated with this box, if any.
LayoutBlock* GetScrollMarkerGroup();
// Get the scroller that owns this scroll marker group.
LayoutBlock* ScrollerFromScrollMarkerGroup() const;
void QuadsInAncestorInternal(Vector<gfx::QuadF>&,
const LayoutBoxModelObject* ancestor,
MapCoordinatesFlags) const override;
gfx::RectF LocalBoundingBoxRectForAccessibility() const override;
void LayoutSubtreeRoot();
void Paint(const PaintInfo&) const override;
virtual bool IsInSelfHitTestingPhase(HitTestPhase phase) const {
NOT_DESTROYED();
return phase == HitTestPhase::kForeground;
}
bool HitTestAllPhases(HitTestResult&,
const HitTestLocation&,
const PhysicalOffset& accumulated_offset) final;
bool NodeAtPoint(HitTestResult&,
const HitTestLocation&,
const PhysicalOffset& accumulated_offset,
HitTestPhase) override;
bool HasHitTestableOverflow() const;
// Fast check if |NodeAtPoint| may find a hit.
bool MayIntersect(const HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& accumulated_offset) const;
LayoutUnit OverrideContainingBlockContentLogicalWidth() const;
bool HasOverrideContainingBlockContentLogicalWidth() const;
void SetOverrideContainingBlockContentLogicalWidth(LayoutUnit);
void ClearOverrideContainingBlockContentSize();
enum PageBoundaryRule { kAssociateWithFormerPage, kAssociateWithLatterPage };
bool HasInlineFragments() const final;
wtf_size_t FirstInlineFragmentItemIndex() const final;
void ClearFirstInlineFragmentItemIndex() final;
void SetFirstInlineFragmentItemIndex(wtf_size_t) final;
static void InvalidateItems(const LayoutResult&);
void AddMeasureLayoutResult(const LayoutResult*);
void SetCachedLayoutResult(const LayoutResult*, wtf_size_t index);
// Store one layout result (with its physical fragment) at the specified
// index.
//
// If there's already a result at the specified index, use
// ReplaceLayoutResult() to do the job. Otherwise, use AppendLayoutResult().
//
// If it's going to be the last result, we'll also perform any necessary
// finalization (see FinalizeLayoutResults()), and also delete all the old
// entries following it (if there used to be more results in a previous
// layout).
//
// In a few specific cases we'll even delete the entries following this
// result, even if it's *not* going to be the last one. This is necessary when
// we might read out the layout results again before we've got to the end (OOF
// block fragmentation, etc.). In all other cases, we'll leave the old results
// until we're done, as deleting entries will trigger unnecessary paint
// invalidation. With any luck, we'll end up with the same number of results
// as the last time, so that paint invalidation might not be necessary.
void SetLayoutResult(const LayoutResult*, wtf_size_t index);
// Append one layout result at the end.
void AppendLayoutResult(const LayoutResult*);
// Replace a specific layout result. Also perform finalization if it's the
// last result (see FinalizeLayoutResults()), but this function does not
// delete any (old) results following this one. Callers should generally use
// SetLayoutResult() instead of this one, unless they have good reasons not
// to.
void ReplaceLayoutResult(const LayoutResult*, wtf_size_t index);
void ShrinkLayoutResults(wtf_size_t results_to_keep);
// Perform any finalization needed after all the layout results have been
// added.
void FinalizeLayoutResults();
void RebuildFragmentTreeSpine();
const LayoutResult* GetCachedLayoutResult(const BlockBreakToken*) const;
const LayoutResult* GetCachedMeasureResult(
const ConstraintSpace&,
std::optional<FragmentGeometry>* fragment_geometry) const;
// Call in situations where we know that there's at most one fragment. A
// DCHECK will fail if there are multiple fragments.
const LayoutResult* GetSingleCachedLayoutResult() const;
// Retrieves the last (retrieved or set) measure LayoutResult, for
// unit-testing purposes only.
const LayoutResult* GetSingleCachedMeasureResultForTesting() const;
// Returns the last layout result for this block flow with the given
// constraint space and break token, or null if it is not up-to-date or
// otherwise unavailable.
//
// This method (while determining if the layout result can be reused), *may*
// calculate the |initial_fragment_geometry| of the node.
//
// |out_cache_status| indicates what type of layout pass is required.
//
// TODO(ikilpatrick): Move this function into BlockNode.
const LayoutResult* CachedLayoutResult(
const ConstraintSpace&,
const BlockBreakToken*,
const EarlyBreak*,
const ColumnSpannerPath*,
std::optional<FragmentGeometry>* initial_fragment_geometry,
LayoutCacheStatus* out_cache_status);
using LayoutResultList = HeapVector<Member<const LayoutResult>, 1>;
class PhysicalFragmentList {
STACK_ALLOCATED();
public:
explicit PhysicalFragmentList(const LayoutResultList& layout_results)
: layout_results_(layout_results) {}
wtf_size_t Size() const { return layout_results_.size(); }
bool IsEmpty() const { return layout_results_.empty(); }
bool MayHaveFragmentItems() const;
bool HasFragmentItems() const {
return MayHaveFragmentItems() && SlowHasFragmentItems();
}
bool SlowHasFragmentItems() const;
wtf_size_t IndexOf(const PhysicalBoxFragment& fragment) const;
bool Contains(const PhysicalBoxFragment& fragment) const;
// Note: We can't use std::views. It's banned in Chromium.
class CORE_EXPORT Iterator {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = PhysicalBoxFragment;
using difference_type = std::ptrdiff_t;
using pointer = PhysicalBoxFragment*;
using reference = PhysicalBoxFragment&;
constexpr Iterator() = default;
explicit Iterator(const LayoutResultList::const_iterator& iterator)
: iterator_(iterator) {}
const PhysicalBoxFragment& operator*() const;
UNSAFE_BUFFER_USAGE Iterator& operator++() {
// SAFETY: This is not safe. We should not use this operator directly.
UNSAFE_BUFFERS(++iterator_);
return *this;
}
UNSAFE_BUFFER_USAGE Iterator operator++(int) {
Iterator copy = *this;
// SAFETY: This is not safe. We should not use this operator directly.
UNSAFE_BUFFERS(++*this);
return copy;
}
bool operator==(const Iterator& other) const {
return iterator_ == other.iterator_;
}
bool operator!=(const Iterator& other) const {
return !operator==(other);
}
private:
LayoutResultList::const_iterator iterator_;
};
Iterator begin() const { return Iterator(layout_results_.begin()); }
Iterator end() const { return Iterator(layout_results_.end()); }
const PhysicalBoxFragment& front() const;
const PhysicalBoxFragment& back() const;
private:
const LayoutResultList& layout_results_;
};
PhysicalFragmentList PhysicalFragments() const {
NOT_DESTROYED();
return PhysicalFragmentList(layout_results_);
}
const LayoutResult* GetLayoutResult(wtf_size_t i) const;
const LayoutResultList& GetLayoutResults() const {
NOT_DESTROYED();
return layout_results_;
}
const PhysicalBoxFragment* GetPhysicalFragment(wtf_size_t i) const;
const FragmentData* FragmentDataFromPhysicalFragment(
const PhysicalBoxFragment&) const;
wtf_size_t PhysicalFragmentCount() const {
NOT_DESTROYED();
return layout_results_.size();
}
bool IsFragmentLessBox() const final {
NOT_DESTROYED();
return !PhysicalFragmentCount();
}
void SetSpannerPlaceholder(LayoutMultiColumnSpannerPlaceholder&);
void ClearSpannerPlaceholder();
LayoutMultiColumnSpannerPlaceholder* SpannerPlaceholder() const final {
NOT_DESTROYED();
return rare_data_ ? rare_data_->spanner_placeholder_.Get() : nullptr;
}
bool IsValidColumnSpanner() const final;
bool MapToVisualRectInAncestorSpaceInternal(
const LayoutBoxModelObject* ancestor,
TransformState&,
VisualRectFlags = kDefaultVisualRectFlags) const override;
LayoutUnit ContainingBlockLogicalHeightForRelPositioned() const;
LayoutUnit ContainingBlockLogicalWidthForContent() const override;
// Block flows subclass availableWidth/Height to handle multi column layout
// (shrinking the width/height available to children when laying out.)
LayoutUnit AvailableLogicalWidth() const {
NOT_DESTROYED();
return ContentLogicalWidth();
}
// Return both scrollbars and scrollbar gutters (defined by scrollbar-gutter).
inline PhysicalBoxStrut ComputeScrollbars() const {
NOT_DESTROYED();
if (CanSkipComputeScrollbars())
return PhysicalBoxStrut();
else
return ComputeScrollbarsInternal();
}
inline BoxStrut ComputeLogicalScrollbars() const {
NOT_DESTROYED();
if (CanSkipComputeScrollbars()) {
return BoxStrut();
} else {
return ComputeScrollbarsInternal().ConvertToLogical(
StyleRef().GetWritingDirection());
}
}
bool IsUserScrollable() const;
virtual void Autoscroll(const PhysicalOffset&);
PhysicalOffset CalculateAutoscrollDirection(
const gfx::PointF& point_in_root_frame) const;
static LayoutBox* FindAutoscrollable(LayoutObject*,
bool is_middle_click_autoscroll);
static bool HasHorizontallyScrollableAncestor(LayoutObject*);
DISABLE_CFI_PERF bool HasAutoVerticalScrollbar() const {
NOT_DESTROYED();
return HasNonVisibleOverflow() && StyleRef().HasAutoVerticalScroll();
}
DISABLE_CFI_PERF bool HasAutoHorizontalScrollbar() const {
NOT_DESTROYED();
return HasNonVisibleOverflow() && StyleRef().HasAutoHorizontalScroll();
}
DISABLE_CFI_PERF bool ScrollsOverflow() const {
NOT_DESTROYED();
return HasNonVisibleOverflow() && StyleRef().ScrollsOverflow();
}
// We place block-direction scrollbar on the left only if the writing-mode
// is horizontal, so ShouldPlaceVerticalScrollbarOnLeft() is the same as
// ShouldPlaceBlockDirectionScrollbarOnLogicalLeft(). The two forms can be
// used in different contexts, e.g. the former for physical coordinate
// contexts, and the later for logical coordinate contexts.
bool ShouldPlaceVerticalScrollbarOnLeft() const {
NOT_DESTROYED();
return ShouldPlaceBlockDirectionScrollbarOnLogicalLeft();
}
virtual bool ShouldPlaceBlockDirectionScrollbarOnLogicalLeft() const {
NOT_DESTROYED();
return StyleRef().ShouldPlaceBlockDirectionScrollbarOnLogicalLeft();
}
bool HasScrollableOverflowX() const {
NOT_DESTROYED();
return ScrollsOverflowX() && ScrollWidth() != ClientWidth();
}
bool HasScrollableOverflowY() const {
NOT_DESTROYED();
return ScrollsOverflowY() && ScrollHeight() != ClientHeight();
}
bool ScrollsOverflowX() const {
NOT_DESTROYED();
return HasNonVisibleOverflow() && StyleRef().ScrollsOverflowX();
}
bool ScrollsOverflowY() const {
NOT_DESTROYED();
return HasNonVisibleOverflow() && StyleRef().ScrollsOverflowY();
}
// Return true if this box is monolithic, i.e. unbreakable in a fragmentation
// context.
virtual bool IsMonolithic() const;
bool HasUnsplittableScrollingOverflow() const;
PhysicalRect LocalCaretRect(int caret_offset) const override;
// Returns the intersection of all overflow clips which apply.
virtual PhysicalRect OverflowClipRect(
const PhysicalOffset& location,
OverlayScrollbarClipBehavior = kIgnoreOverlayScrollbarSize) const;
PhysicalRect ClipRect(const PhysicalOffset& location) const;
// Returns the combination of overflow clip, contain: paint clip and CSS clip
// for this object.
PhysicalRect ClippingRect(const PhysicalOffset& location) const;
void ImageChanged(WrappedImagePtr, CanDeferInvalidation) override;
ResourcePriority ComputeResourcePriority() const override;
PositionWithAffinity PositionForPointInFragments(const PhysicalOffset&) const;
virtual bool CreatesNewFormattingContext() const {
NOT_DESTROYED();
return true;
}
bool ShouldBeConsideredAsReplaced() const;
// Return true if this block establishes a fragmentation context root (e.g. a
// multicol container).
virtual bool IsFragmentationContextRoot() const {
NOT_DESTROYED();
return false;
}
bool IsWritingModeRoot() const {
NOT_DESTROYED();
return !Parent() ||
Parent()->StyleRef().GetWritingMode() != StyleRef().GetWritingMode();
}
bool IsCustomItem() const;
bool IsFlexItem() const {
NOT_DESTROYED();
return !IsInline() && !IsOutOfFlowPositioned() && Parent() &&
Parent()->IsFlexibleBox();
}
bool IsGridItem() const {
NOT_DESTROYED();
return Parent() && Parent()->IsLayoutGrid();
}
bool IsMasonryItem() const {
NOT_DESTROYED();
return Parent() && Parent()->IsLayoutMasonry();
}
bool IsMathItem() const {
NOT_DESTROYED();
return Parent() && Parent()->IsMathML();
}
LayoutUnit FirstLineHeight() const override;
PhysicalOffset OffsetPoint(const Element* parent) const;
LayoutUnit OffsetLeft(const Element*) const final;
LayoutUnit OffsetTop(const Element*) const final;
// Create a new WritingModeConverter to handle offsets and rectangles inside
// this container. This ignores TextDirection.
WritingModeConverter CreateWritingModeConverter() const;
// Passing |location_container| causes flipped-block flipping w.r.t.
// that container, or LocationContainer() otherwise.
//
// TODO(crbug.com/40855022): Get rid of the parameter.
virtual PhysicalOffset PhysicalLocation(
const LayoutBox* location_container = nullptr) const;
PhysicalRect BoundingBoxRelativeToFirstFragment() const override;
bool HasSelfVisualOverflow() const {
NOT_DESTROYED();
return VisualOverflowIsSet() &&
!PhysicalBorderBoxRect().Contains(
overflow_->visual_overflow->SelfVisualOverflowRect());
}
bool HasVisualOverflow() const {
NOT_DESTROYED();
return VisualOverflowIsSet();
}
bool HasScrollableOverflow() const {
NOT_DESTROYED();
return ScrollableOverflowIsSet();
}
// Returns true if reading flow should be used on this LayoutBox's content.
// https://drafts.csswg.org/css-display-4/#reading-flow
bool IsReadingFlowContainer() const;
// Returns the nodes corresponding to this LayoutBox's layout children,
// sorted in reading flow if IsReadingFlowContainer().
const HeapVector<Member<Node>>& ReadingFlowNodes() const;
// See README.md for an explanation of scroll origin.
gfx::Vector2d OriginAdjustmentForScrollbars() const;
gfx::Point ScrollOrigin() const;
PhysicalOffset ScrolledContentOffset() const;
// Scroll offset as snapped to physical pixels. This value should be used in
// any values used after layout and inside "layout code" that cares about
// where the content is displayed, rather than what the ideal offset is. For
// most other cases ScrolledContentOffset is probably more appropriate. This
// is the offset that's actually drawn to the screen.
// TODO(crbug.com/962299): Pixel-snapping before PrePaint (when we know the
// paint offset) is incorrect.
gfx::Vector2d PixelSnappedScrolledContentOffset() const;
// Maps from scrolling contents space to box space and apply overflow
// clip if needed. Returns true if no clipping applied or the flattened quad
// bounds actually intersects the clipping region. If edgeInclusive is true,
// then this method may return true even if the resulting rect has zero area.
//
// When applying offsets and not clips, the TransformAccumulation is
// respected. If there is a clip, the TransformState is flattened first.
bool MapContentsRectToBoxSpace(
TransformState&,
TransformState::TransformAccumulation,
const LayoutObject& contents,
VisualRectFlags = kDefaultVisualRectFlags) const;
// True if the contents scroll relative to this object. |this| must be a
// containing block for |contents|.
bool ContainedContentsScroll(const LayoutObject& contents) const;
// Applies the box clip. This is like mapScrollingContentsRectToBoxSpace,
// except it does not apply scroll.
bool ApplyBoxClips(TransformState&,
TransformState::TransformAccumulation,
VisualRectFlags) const;
// The optional |size| parameter is used if the size of the object isn't
// correct yet.
gfx::PointF PerspectiveOrigin(const PhysicalSize* size = nullptr) const;
// Maps the visual rect state |transform_state| from this box into its
// container, applying adjustments for the given container offset,
// scrolling, container clipping, and transform (including container
// perspective).
bool MapVisualRectToContainer(const LayoutObject* container_object,
const PhysicalOffset& container_offset,
const LayoutObject* ancestor,
VisualRectFlags,
TransformState&) const;
virtual LayoutBox* CreateAnonymousBoxWithSameTypeAs(
const LayoutObject*) const {
NOT_DESTROYED();
NOTREACHED();
}
// Get the LayoutBox for the actual content. That's usually `this`, but if the
// element creates multiple boxes (e.g. fieldsets and their anonymous content
// child box), it may return something else. The box returned will be the one
// that's created according to display type, scrollable overflow, and so on.
virtual LayoutBox* ContentLayoutBox() {
NOT_DESTROYED();
return this;
}
ShapeOutsideInfo* GetShapeOutsideInfo() const;
// CustomLayoutChild only exists if this LayoutBox is a IsCustomItem (aka. a
// child of a LayoutCustom). This is created/destroyed when this LayoutBox is
// inserted/removed from the layout tree.
CustomLayoutChild* GetCustomLayoutChild() const;
void AddCustomLayoutChildIfNeeded();
void ClearCustomLayoutChild();
bool HitTestClippedOutByBorder(
const HitTestLocation&,
const PhysicalOffset& border_box_location) const;
bool HitTestOverflowControl(HitTestResult&,
const HitTestLocation&,
const PhysicalOffset&) const;
// Returns true if the box intersects the viewport visible to the user.
bool IntersectsVisibleViewport() const;
void EnsureIsReadyForPaintInvalidation() override;
void ClearPaintFlags() override;
bool HasControlClip() const;
class MutableForPainting : public LayoutObject::MutableForPainting {
public:
void SavePreviousSize() {
GetLayoutBox().previous_size_ = GetLayoutBox().Size();
}
void ClearPreviousSize() { GetLayoutBox().previous_size_ = PhysicalSize(); }
void SavePreviousOverflowData();
void ClearPreviousOverflowData() {
DCHECK(!GetLayoutBox().HasVisualOverflow());
DCHECK(!GetLayoutBox().HasScrollableOverflow());
GetLayoutBox().overflow_ = nullptr;
}
void SavePreviousContentBoxRect() {
auto& rare_data = GetLayoutBox().EnsureRareData();
rare_data.has_previous_content_box_rect_ = true;
rare_data.previous_physical_content_box_rect_ =
GetLayoutBox().PhysicalContentBoxRect();
}
void ClearPreviousContentBoxRect() {
if (auto* rare_data = GetLayoutBox().rare_data_.Get())
rare_data->has_previous_content_box_rect_ = false;
}
// Called from LayoutShiftTracker when we attach this LayoutBox to a node
// for which we saved these values when the node was detached from its
// original LayoutBox.
void SetPreviousGeometryForLayoutShiftTracking(
const PhysicalOffset& paint_offset,
const PhysicalSize& size,
const PhysicalRect& visual_overflow_rect);
void UpdateBackgroundPaintLocation(bool needs_root_element_group);
protected:
friend class LayoutBox;
MutableForPainting(const LayoutBox& box)
: LayoutObject::MutableForPainting(box) {}
LayoutBox& GetLayoutBox() {
return static_cast<LayoutBox&>(layout_object_);
}
};
MutableForPainting GetMutableForPainting() const {
NOT_DESTROYED();
return MutableForPainting(*this);
}
PhysicalSize PreviousSize() const {
NOT_DESTROYED();
return previous_size_;
}
PhysicalRect PreviousPhysicalContentBoxRect() const {
NOT_DESTROYED();
return rare_data_ && rare_data_->has_previous_content_box_rect_
? rare_data_->previous_physical_content_box_rect_
: PhysicalRect(PhysicalOffset(), PreviousSize());
}
PhysicalRect PreviousVisualOverflowRect() const {
NOT_DESTROYED();
return overflow_ && overflow_->previous_overflow_data
? overflow_->previous_overflow_data
->previous_visual_overflow_rect
: PhysicalRect(PhysicalOffset(), PreviousSize());
}
PhysicalRect PreviousScrollableOverflowRect() const {
NOT_DESTROYED();
return overflow_ && overflow_->previous_overflow_data
? overflow_->previous_overflow_data
->previous_scrollable_overflow_rect
: PhysicalRect(PhysicalOffset(), PreviousSize());
}
PhysicalRect PreviousSelfVisualOverflowRect() const {
NOT_DESTROYED();
return overflow_ && overflow_->previous_overflow_data
? overflow_->previous_overflow_data
->previous_self_visual_overflow_rect
: PhysicalRect(PhysicalOffset(), PreviousSize());
}
// Returns the cached intrinsic logical widths when no children depend on the
// block constraints.
MinMaxSizesResult CachedIndefiniteIntrinsicLogicalWidths() const {
NOT_DESTROYED();
DCHECK(!IntrinsicLogicalWidthsDirty());
return {intrinsic_logical_widths_,
IntrinsicLogicalWidthsDependsOnBlockConstraints()};
}
// Returns the cached intrinsic logical widths if the initial block-size
// matches.
std::optional<MinMaxSizesResult> CachedIntrinsicLogicalWidths(
LayoutUnit initial_block_size) const {
NOT_DESTROYED();
DCHECK(!IntrinsicLogicalWidthsDirty());
if (initial_block_size == kIndefiniteSize) {
if (IndefiniteIntrinsicLogicalWidthsDirty()) {
return std::nullopt;
}
return MinMaxSizesResult(
intrinsic_logical_widths_,
IntrinsicLogicalWidthsDependsOnBlockConstraints());
}
if (min_max_sizes_cache_) {
if (DefiniteIntrinsicLogicalWidthsDirty()) {
return std::nullopt;
}
return min_max_sizes_cache_->Find(initial_block_size);
}
return std::nullopt;
}
// Sets the min/max sizes for this box.
void SetIntrinsicLogicalWidths(LayoutUnit initial_block_size,
const MinMaxSizesResult& result) {
NOT_DESTROYED();
// Write to the "indefinite" cache slot if:
// - If the initial block-size is indefinite.
// - If we don't have any children which depend on the initial block-size
// (it can change and we wouldn't give a different answer).
if (initial_block_size == kIndefiniteSize ||
!result.depends_on_block_constraints) {
intrinsic_logical_widths_ = result.sizes;
SetIntrinsicLogicalWidthsDependsOnBlockConstraints(
result.depends_on_block_constraints);
SetIndefiniteIntrinsicLogicalWidthsDirty(false);
} else {
if (!min_max_sizes_cache_) {
min_max_sizes_cache_ = MakeGarbageCollected<MinMaxSizesCache>();
} else if (DefiniteIntrinsicLogicalWidthsDirty()) {
min_max_sizes_cache_->Clear();
}
min_max_sizes_cache_->Add(result.sizes, initial_block_size,
result.depends_on_block_constraints);
SetDefiniteIntrinsicLogicalWidthsDirty(false);
}
ClearIntrinsicLogicalWidthsDirty();
}
// Make it public.
using LayoutObject::BackgroundIsKnownToBeObscured;
// Sets the coordinates of find-in-page scrollbar tickmarks, bypassing
// DocumentMarkerController. This is used by the PDF plugin.
void OverrideTickmarks(Vector<gfx::Rect> tickmarks);
// Issues a paint invalidation on the layout viewport's vertical scrollbar
// (which is responsible for painting the tickmarks).
void InvalidatePaintForTickmarks();
bool MayHaveFragmentItems() const {
NOT_DESTROYED();
// When the tree is not clean, `ChildrenInline()` is not reliable.
return (ChildrenInline() || NeedsLayout()) &&
PhysicalFragments().MayHaveFragmentItems();
}
bool HasFragmentItems() const {
NOT_DESTROYED();
// See `MayHaveFragmentItems()`.
return (ChildrenInline() || NeedsLayout()) &&
PhysicalFragments().HasFragmentItems();
}
#if EXPENSIVE_DCHECKS_ARE_ON()
void CheckMayHaveFragmentItems() const;
#endif
// Returns true if this box is fixed position and will not move with
// scrolling. If the caller can pre-calculate |container_for_fixed_position|,
// it should pass it to avoid recalculation.
bool IsFixedToView(
const LayoutObject* container_for_fixed_position = nullptr) const;
// See StickyPositionScrollingConstraints::constraining_rect.
PhysicalRect ComputeStickyConstrainingRect() const;
AnchorPositionScrollData* GetAnchorPositionScrollData() const;
bool NeedsAnchorPositionScrollAdjustment() const;
PhysicalOffset AnchorPositionScrollTranslationOffset() const;
bool AnchorPositionScrollAdjustmentAfectedByViewportScrolling() const;
bool HasScrollbarGutters(ScrollbarOrientation orientation) const;
// This should be called when the border-box size of this box is changed.
void SizeChanged();
// Finds the target anchor element for the given name in the containing block.
// https://drafts.csswg.org/css-anchor-position-1/#target-anchor-element
const LayoutObject* FindTargetAnchor(const ScopedCSSName&) const;
// Returns this element's implicit anchor element if there is one and it is an
// acceptable anchor element.
// https://drafts.csswg.org/css-anchor-position-1/#ref-for-valdef-anchor-implicit
const LayoutObject* AcceptableImplicitAnchor() const;
const HeapVector<NonOverflowingScrollRange>* NonOverflowingScrollRanges()
const;
const BoxStrut& OutOfFlowInsetsForGetComputedStyle() const;
Element* AccessibilityAnchor() const;
const GCedHeapHashSet<Member<Element>>* DisplayLocksAffectedByAnchors() const;
void NotifyContainingDisplayLocksForAnchorPositioning(
const GCedHeapHashSet<Member<Element>>*
past_display_locks_affected_by_anchors,
const GCedHeapHashSet<Member<Element>>* display_locks_affected_by_anchors)
const;
bool NeedsAnchorPositionScrollAdjustmentInX() const;
bool NeedsAnchorPositionScrollAdjustmentInY() const;
using LayoutObject::GetBackgroundPaintLocation;
protected:
~LayoutBox() override;
virtual OverflowClipAxes ComputeOverflowClipAxes() const;
void WillBeDestroyed() override;
void InsertedIntoTree() override;
void WillBeRemovedFromTree() override;
void StyleWillChange(StyleDifference,
const ComputedStyle& new_style) override;
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
virtual bool ShouldBeHandledAsFloating(const ComputedStyle& style) const;
bool ShouldBeHandledAsFloating() const {
NOT_DESTROYED();
return ShouldBeHandledAsFloating(StyleRef());
}
void UpdateFromStyle() override;
void InLayoutNGInlineFormattingContextWillChange(bool) final;
virtual ItemPosition SelfAlignmentNormalBehavior(
const LayoutBox* child = nullptr) const {
NOT_DESTROYED();
DCHECK(!child);
return ItemPosition::kStretch;
}
PhysicalRect BackgroundPaintedExtent() const;
virtual bool ForegroundIsKnownToBeOpaqueInRect(
const PhysicalRect& local_rect,
unsigned max_depth_to_test) const;
virtual bool ComputeBackgroundIsKnownToBeObscured() const;
bool ComputeCanCompositeBackgroundAttachmentFixed() const override;
virtual bool HitTestChildren(HitTestResult&,
const HitTestLocation&,
const PhysicalOffset& accumulated_offset,
HitTestPhase);
void InvalidatePaint(const PaintInvalidatorContext&) const override;
void ExcludeScrollbars(
PhysicalRect&,
OverlayScrollbarClipBehavior = kIgnoreOverlayScrollbarSize,
ShouldIncludeScrollbarGutter = kIncludeScrollbarGutter) const;
LayoutUnit ContainingBlockLogicalHeightForPositioned(
const LayoutBoxModelObject* containing_block) const;
virtual DeprecatedLayoutPoint DeprecatedLocationInternal() const {
NOT_DESTROYED();
return frame_location_.layout_point;
}
// Allow LayoutMultiColumnSpannerPlaceholder to call
// DeprecatedLocationInternal() of other instances.
friend class LayoutMultiColumnSpannerPlaceholder;
PhysicalOffset OffsetFromContainerInternal(
const LayoutObject*,
MapCoordinatesFlags mode) const override;
// For atomic inlines, returns its resolved direction in text flow. Not to be
// confused with the CSS property 'direction'.
// Returns the CSS 'direction' property value when it is not atomic inline.
TextDirection ResolvedDirection() const;
// RecalcScrollableOverflow implementations for LayoutNG.
RecalcScrollableOverflowResult RecalcScrollableOverflowNG();
RecalcScrollableOverflowResult RecalcChildScrollableOverflowNG();
private:
inline bool ScrollableOverflowIsSet() const {
NOT_DESTROYED();
return overflow_ && overflow_->scrollable_overflow;
}
#if DCHECK_IS_ON()
void CheckIsVisualOverflowComputed() const;
#else
ALWAYS_INLINE void CheckIsVisualOverflowComputed() const { NOT_DESTROYED(); }
#endif
inline bool VisualOverflowIsSet() const {
NOT_DESTROYED();
CheckIsVisualOverflowComputed();
return overflow_ && overflow_->visual_overflow;
}
// The outsets from this box's border-box that the element's content should be
// clipped to, including overflow-clip-margin.
PhysicalBoxStrut BorderOutsetsForClipping() const;
void SetVisualOverflow(const PhysicalRect& self,
const PhysicalRect& contents);
void CopyVisualOverflowFromFragmentsWithoutInvalidations();
void UpdateShapeOutsideInfoAfterStyleChange(const ComputedStyle&,
const ComputedStyle* old_style);
void UpdateGridPositionAfterStyleChange(const ComputedStyle*);
void UpdateScrollSnapMappingAfterStyleChange(const ComputedStyle& old_style);
LayoutBoxRareData& EnsureRareData() {
NOT_DESTROYED();
if (!rare_data_)
rare_data_ = MakeGarbageCollected<LayoutBoxRareData>();
return *rare_data_.Get();
}
bool IsBox() const final {
NOT_DESTROYED();
return true;
}
void LocationChanged();
void InflateVisualRectForFilter(TransformState&) const;
void InflateVisualRectForFilterUnderContainer(
TransformState&,
const LayoutObject& container,
const LayoutBoxModelObject* ancestor_to_stop_at) const;
PhysicalRect DebugRect() const override;
RasterEffectOutset VisualRectOutsetForRasterEffects() const override;
inline bool CanSkipComputeScrollbars() const {
NOT_DESTROYED();
return (StyleRef().IsOverflowVisibleAlongBothAxes() ||
!HasNonVisibleOverflow() ||
(GetScrollableArea() &&
!GetScrollableArea()->HasHorizontalScrollbar() &&
!GetScrollableArea()->HasVerticalScrollbar())) &&
StyleRef().IsScrollbarGutterAuto();
}
PhysicalBoxStrut ComputeScrollbarsInternal(
ShouldClampToContentBox = kDoNotClampToContentBox,
OverlayScrollbarClipBehavior = kIgnoreOverlayScrollbarSize,
ShouldIncludeScrollbarGutter = kIncludeScrollbarGutter) const;
PhysicalOffset DeprecatedPhysicalLocationInternal(
const LayoutBox* container_box) const {
NOT_DESTROYED();
DCHECK(!RuntimeEnabledFeatures::LayoutBoxVisualLocationEnabled());
DCHECK_EQ(container_box, LocationContainer());
DeprecatedLayoutPoint location = DeprecatedLocationInternal();
if (!container_box || !container_box->HasFlippedBlocksWritingMode())
[[likely]] {
return PhysicalOffset(location);
}
return PhysicalOffset(
container_box->Size().width - Size().width - location.X(),
location.Y());
}
bool BackgroundClipBorderBoxIsEquivalentToPaddingBox() const;
BackgroundPaintLocation ComputeBackgroundPaintLocation(
bool needs_root_element_group) const;
// Compute the border-box size from physical fragments.
PhysicalSize ComputeSize() const;
void InvalidateCachedGeometry();
// Clear LayoutObject fields of physical fragments.
void DisassociatePhysicalFragments();
protected:
// The CSS border box rect for this box.
//
// The location is the distance from the border edge of the first fragment of
// this object, to the border edge of the first fragment of
// LocationContainer(). It doesn't include transforms, relative position
// offsets etc.
union Location {
Location() : physical_offset(PhysicalOffset()) {}
DeprecatedLayoutPoint layout_point;
PhysicalOffset physical_offset;
} frame_location_;
// TODO(crbug.com/1353190): Remove frame_size_.
PhysicalSize frame_size_;
private:
// Previous value of frame_size_, updated after paint invalidation.
PhysicalSize previous_size_;
protected:
MinMaxSizes intrinsic_logical_widths_;
Member<MinMaxSizesCache> min_max_sizes_cache_;
Member<MeasureCache> measure_cache_;
LayoutResultList layout_results_;
friend class LayoutBoxTest;
private:
// The index of the first fragment item associated with this object in
// |FragmentItems::Items()|. Zero means there are no such item.
// Valid only when IsInLayoutNGInlineFormattingContext().
wtf_size_t first_fragment_item_index_ = 0u;
Member<BoxOverflowModel> overflow_;
Member<LayoutBoxRareData> rare_data_;
FRIEND_TEST_ALL_PREFIXES(LayoutMultiColumnSetTest, ScrollAnchroingCrash);
};
template <>
struct DowncastTraits<LayoutBox> {
static bool AllowFrom(const LayoutObject& object) { return object.IsBox(); }
};
inline LayoutBox* LayoutBox::PreviousSiblingBox() const {
NOT_DESTROYED();
return To<LayoutBox>(PreviousSibling());
}
inline LayoutBox* LayoutBox::NextSiblingBox() const {
NOT_DESTROYED();
return To<LayoutBox>(NextSibling());
}
inline LayoutBox* LayoutBox::ParentBox() const {
NOT_DESTROYED();
return To<LayoutBox>(Parent());
}
inline LayoutBox* LayoutBox::FirstChildBox() const {
NOT_DESTROYED();
return To<LayoutBox>(SlowFirstChild());
}
inline LayoutBox* LayoutBox::LastChildBox() const {
NOT_DESTROYED();
return To<LayoutBox>(SlowLastChild());
}
inline LayoutBox* LayoutBox::PreviousSiblingMultiColumnBox() const {
NOT_DESTROYED();
DCHECK(IsLayoutMultiColumnSpannerPlaceholder() || IsLayoutMultiColumnSet());
LayoutBox* previous_box = PreviousSiblingBox();
if (previous_box->IsLayoutFlowThread())
return nullptr;
return previous_box;
}
inline LayoutBox* LayoutBox::NextSiblingMultiColumnBox() const {
NOT_DESTROYED();
DCHECK(IsLayoutMultiColumnSpannerPlaceholder() || IsLayoutMultiColumnSet());
return NextSiblingBox();
}
inline wtf_size_t LayoutBox::FirstInlineFragmentItemIndex() const {
NOT_DESTROYED();
if (!IsInLayoutNGInlineFormattingContext())
return 0u;
return first_fragment_item_index_;
}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_BOX_H_
|