OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Antti Koivisto (koivisto@kde.org) | 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) | 5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) |
6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All r
ights reserved. |
7 * Copyright (C) 2009 Google Inc. All rights reserved. | 7 * Copyright (C) 2009 Google Inc. All rights reserved. |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 LayoutRect bounds; | 108 LayoutRect bounds; |
109 bool draggable; | 109 bool draggable; |
110 }; | 110 }; |
111 | 111 |
112 typedef WTF::HashMap<const DeprecatedPaintLayer*, Vector<LayoutRect>> LayerHitTe
stRects; | 112 typedef WTF::HashMap<const DeprecatedPaintLayer*, Vector<LayoutRect>> LayerHitTe
stRects; |
113 | 113 |
114 #ifndef NDEBUG | 114 #ifndef NDEBUG |
115 const int showTreeCharacterOffset = 39; | 115 const int showTreeCharacterOffset = 39; |
116 #endif | 116 #endif |
117 | 117 |
118 // Base class for all layout tree objects. | 118 // LayoutObject is the base class for all layout tree objects. |
| 119 // |
| 120 // LayoutObjects form a tree structure that is a close mapping of the DOM tree. |
| 121 // The root of the LayoutObject tree is the LayoutView, which is the LayoutObjec
t associated |
| 122 // with the Document. |
| 123 // |
| 124 // Some LayoutObjects don't have an associated Node and are called "anonymous" (
see the constructor |
| 125 // below). Anonymous LayoutObjects exists for several purposes but are usually r
equired by CSS. A |
| 126 // good example is anonymous table parts (http://www.w3.org/TR/CSS21/tables.html
#anonymous-boxes). |
| 127 // Also some Node don't have an associated LayoutObjects e.g. if display: none i
s set. For more |
| 128 // detail, see LayoutObject::createObject that creates the right LayoutObject ba
sed on the style. |
| 129 // |
| 130 // Because the SVG and CSS classes both inherit from this object, functions can
belong to either |
| 131 // realm and sometimes to both. |
| 132 // |
| 133 // The purpose of the layout tree is to do layout (aka reflow) and store its res
ults for painting and |
| 134 // hit-testing. |
| 135 // Layout is the process of sizing and positioning Nodes on the page. In Blink,
layouts always start |
| 136 // from a relayout boundary (see objectIsRelayoutBoundary in LayoutObject.cpp).
As such, we need to mark |
| 137 // the ancestors all the way to the enclosing relayout boundary in order to do a
correct layout. |
| 138 // |
| 139 // Due to the high cost of layout, a lot of effort is done to avoid doing full l
ayouts of nodes. |
| 140 // This is why there are several types of layout available to bypass the complex
operations. See the |
| 141 // comments on the layout booleans in LayoutObjectBitfields below about the diff
erent layouts. |
119 class CORE_EXPORT LayoutObject : public ImageResourceClient { | 142 class CORE_EXPORT LayoutObject : public ImageResourceClient { |
120 friend class LayoutBlock; | 143 friend class LayoutBlock; |
121 friend class LayoutBlockFlow; | 144 friend class LayoutBlockFlow; |
122 friend class DeprecatedPaintLayerReflectionInfo; // For setParent | 145 friend class DeprecatedPaintLayerReflectionInfo; // For setParent |
123 friend class DeprecatedPaintLayerScrollableArea; // For setParent. | 146 friend class DeprecatedPaintLayerScrollableArea; // For setParent. |
124 friend class LayoutObjectChildList; | 147 friend class LayoutObjectChildList; |
125 WTF_MAKE_NONCOPYABLE(LayoutObject); | 148 WTF_MAKE_NONCOPYABLE(LayoutObject); |
126 public: | 149 public: |
127 // Anonymous objects should pass the document as their node, and they will t
hen automatically be | 150 // Anonymous objects should pass the document as their node, and they will t
hen automatically be |
128 // marked as anonymous in the constructor. | 151 // marked as anonymous in the constructor. |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 void setHasOverflowClip(bool hasOverflowClip) { m_bitfields.setHasOverflowCl
ip(hasOverflowClip); } | 684 void setHasOverflowClip(bool hasOverflowClip) { m_bitfields.setHasOverflowCl
ip(hasOverflowClip); } |
662 void setHasLayer(bool hasLayer) { m_bitfields.setHasLayer(hasLayer); } | 685 void setHasLayer(bool hasLayer) { m_bitfields.setHasLayer(hasLayer); } |
663 void setHasTransformRelatedProperty(bool hasTransform) { m_bitfields.setHasT
ransformRelatedProperty(hasTransform); } | 686 void setHasTransformRelatedProperty(bool hasTransform) { m_bitfields.setHasT
ransformRelatedProperty(hasTransform); } |
664 void setHasReflection(bool hasReflection) { m_bitfields.setHasReflection(has
Reflection); } | 687 void setHasReflection(bool hasReflection) { m_bitfields.setHasReflection(has
Reflection); } |
665 | 688 |
666 // paintOffset is the offset from the origin of the GraphicsContext at which
to paint the current object. | 689 // paintOffset is the offset from the origin of the GraphicsContext at which
to paint the current object. |
667 virtual void paint(const PaintInfo&, const LayoutPoint& paintOffset); | 690 virtual void paint(const PaintInfo&, const LayoutPoint& paintOffset); |
668 | 691 |
669 // Subclasses must reimplement this method to compute the size and position | 692 // Subclasses must reimplement this method to compute the size and position |
670 // of this object and all its descendants. | 693 // of this object and all its descendants. |
| 694 // |
| 695 // By default, layout only lays out the children that are marked for layout. |
| 696 // In some cases, layout has to force laying out more children. An example i
s |
| 697 // when the width of the LayoutObject changes as this impacts children with |
| 698 // 'width' set to auto. |
671 virtual void layout() = 0; | 699 virtual void layout() = 0; |
672 virtual bool updateImageLoadingPriorities() { return false; } | 700 virtual bool updateImageLoadingPriorities() { return false; } |
673 void setHasPendingResourceUpdate(bool hasPendingResourceUpdate) { m_bitfield
s.setHasPendingResourceUpdate(hasPendingResourceUpdate); } | 701 void setHasPendingResourceUpdate(bool hasPendingResourceUpdate) { m_bitfield
s.setHasPendingResourceUpdate(hasPendingResourceUpdate); } |
674 bool hasPendingResourceUpdate() const { return m_bitfields.hasPendingResourc
eUpdate(); } | 702 bool hasPendingResourceUpdate() const { return m_bitfields.hasPendingResourc
eUpdate(); } |
675 | 703 |
676 void handleSubtreeModifications(); | 704 void handleSubtreeModifications(); |
677 virtual void subtreeDidChange() { } | 705 virtual void subtreeDidChange() { } |
678 | 706 |
679 // Flags used to mark if an object consumes subtree change notifications. | 707 // Flags used to mark if an object consumes subtree change notifications. |
680 bool consumesSubtreeChangeNotification() const { return m_bitfields.consumes
SubtreeChangeNotification(); } | 708 bool consumesSubtreeChangeNotification() const { return m_bitfields.consumes
SubtreeChangeNotification(); } |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 enum PositionedState { | 1296 enum PositionedState { |
1269 IsStaticallyPositioned = 0, | 1297 IsStaticallyPositioned = 0, |
1270 IsRelativelyPositioned = 1, | 1298 IsRelativelyPositioned = 1, |
1271 IsOutOfFlowPositioned = 2, | 1299 IsOutOfFlowPositioned = 2, |
1272 IsStickyPositioned = 3, | 1300 IsStickyPositioned = 3, |
1273 }; | 1301 }; |
1274 | 1302 |
1275 public: | 1303 public: |
1276 LayoutObjectBitfields(Node* node) | 1304 LayoutObjectBitfields(Node* node) |
1277 : m_selfNeedsLayout(false) | 1305 : m_selfNeedsLayout(false) |
| 1306 , m_needsPositionedMovementLayout(false) |
| 1307 , m_normalChildNeedsLayout(false) |
| 1308 , m_posChildNeedsLayout(false) |
| 1309 , m_needsSimplifiedNormalFlowLayout(false) |
| 1310 , m_selfNeedsOverflowRecalcAfterStyleChange(false) |
| 1311 , m_childNeedsOverflowRecalcAfterStyleChange(false) |
| 1312 , m_preferredLogicalWidthsDirty(false) |
1278 , m_shouldInvalidateOverflowForPaint(false) | 1313 , m_shouldInvalidateOverflowForPaint(false) |
1279 , m_childShouldCheckForPaintInvalidation(false) | 1314 , m_childShouldCheckForPaintInvalidation(false) |
1280 , m_mayNeedPaintInvalidation(false) | 1315 , m_mayNeedPaintInvalidation(false) |
1281 , m_shouldInvalidateSelection(false) | 1316 , m_shouldInvalidateSelection(false) |
1282 , m_neededLayoutBecauseOfChildren(false) | 1317 , m_neededLayoutBecauseOfChildren(false) |
1283 , m_needsPositionedMovementLayout(false) | |
1284 , m_normalChildNeedsLayout(false) | |
1285 , m_posChildNeedsLayout(false) | |
1286 , m_needsSimplifiedNormalFlowLayout(false) | |
1287 , m_preferredLogicalWidthsDirty(false) | |
1288 , m_floating(false) | 1318 , m_floating(false) |
1289 , m_selfNeedsOverflowRecalcAfterStyleChange(false) | |
1290 , m_childNeedsOverflowRecalcAfterStyleChange(false) | |
1291 , m_isAnonymous(!node) | 1319 , m_isAnonymous(!node) |
1292 , m_isText(false) | 1320 , m_isText(false) |
1293 , m_isBox(false) | 1321 , m_isBox(false) |
1294 , m_isInline(true) | 1322 , m_isInline(true) |
1295 , m_isReplaced(false) | 1323 , m_isReplaced(false) |
1296 , m_horizontalWritingMode(true) | 1324 , m_horizontalWritingMode(true) |
1297 , m_isDragging(false) | 1325 , m_isDragging(false) |
1298 , m_hasLayer(false) | 1326 , m_hasLayer(false) |
1299 , m_hasOverflowClip(false) | 1327 , m_hasOverflowClip(false) |
1300 , m_hasTransformRelatedProperty(false) | 1328 , m_hasTransformRelatedProperty(false) |
(...skipping 11 matching lines...) Expand all Loading... |
1312 , m_lastBoxDecorationBackgroundObscured(false) | 1340 , m_lastBoxDecorationBackgroundObscured(false) |
1313 , m_isSlowRepaintObject(false) | 1341 , m_isSlowRepaintObject(false) |
1314 , m_positionedState(IsStaticallyPositioned) | 1342 , m_positionedState(IsStaticallyPositioned) |
1315 , m_selectionState(SelectionNone) | 1343 , m_selectionState(SelectionNone) |
1316 , m_boxDecorationBackgroundState(NoBoxDecorationBackground) | 1344 , m_boxDecorationBackgroundState(NoBoxDecorationBackground) |
1317 , m_fullPaintInvalidationReason(PaintInvalidationNone) | 1345 , m_fullPaintInvalidationReason(PaintInvalidationNone) |
1318 { | 1346 { |
1319 } | 1347 } |
1320 | 1348 |
1321 // 32 bits have been used in the first word, and 16 in the second. | 1349 // 32 bits have been used in the first word, and 16 in the second. |
| 1350 |
| 1351 // Self needs layout means that this layout object is marked for a full
layout. |
| 1352 // This is the default layout but it is expensive as it recomputes every
thing. |
| 1353 // For CSS boxes, this includes the width (laying out the line boxes aga
in), the margins |
| 1354 // (due to block collapsing margins), the positions, the height and the
potential overflow. |
1322 ADD_BOOLEAN_BITFIELD(selfNeedsLayout, SelfNeedsLayout); | 1355 ADD_BOOLEAN_BITFIELD(selfNeedsLayout, SelfNeedsLayout); |
| 1356 |
| 1357 // A positioned movement layout is a specialized type of layout used on
positioned objects |
| 1358 // that only visually moved. This layout is used when changing 'top'/'le
ft' on a positioned |
| 1359 // element or margins on an out-of-flow one. Because the following opera
tions don't impact |
| 1360 // the size of the object or sibling LayoutObjects, this layout is very
lightweight. |
| 1361 // |
| 1362 // Positioned movement layout is implemented in LayoutBlock::simplifiedL
ayout. |
| 1363 ADD_BOOLEAN_BITFIELD(needsPositionedMovementLayout, NeedsPositionedMovem
entLayout); |
| 1364 |
| 1365 // This boolean is set when a normal flow ('position' == static || relat
ive) child requires |
| 1366 // layout (but this object doesn't). Due to the nature of CSS, laying ou
t a child can cause |
| 1367 // the parent to resize (e.g., if 'height' is auto). |
| 1368 ADD_BOOLEAN_BITFIELD(normalChildNeedsLayout, NormalChildNeedsLayout); |
| 1369 |
| 1370 // This boolean is set when an out-of-flow positioned ('position' == fix
ed || absolute) child |
| 1371 // requires layout (but this object doesn't). |
| 1372 ADD_BOOLEAN_BITFIELD(posChildNeedsLayout, PosChildNeedsLayout); |
| 1373 |
| 1374 // Simplified normal flow layout only relayouts the normal flow children
, ignoring the |
| 1375 // out-of-flow descendants. |
| 1376 // |
| 1377 // The implementation of this layout is in LayoutBlock::simplifiedNormal
FlowLayout. |
| 1378 ADD_BOOLEAN_BITFIELD(needsSimplifiedNormalFlowLayout, NeedsSimplifiedNor
malFlowLayout); |
| 1379 |
| 1380 // Some properties only have a visual impact and don't impact the actual
layout position and |
| 1381 // sizes of the object. An example of this is the 'transform' property,
who doesn't modify the |
| 1382 // layout but gets applied at paint time. |
| 1383 // Setting this flag only recomputes the overflow information. |
| 1384 ADD_BOOLEAN_BITFIELD(selfNeedsOverflowRecalcAfterStyleChange, SelfNeedsO
verflowRecalcAfterStyleChange); |
| 1385 |
| 1386 // This flag is set on the ancestor of a LayoutObject needing |
| 1387 // selfNeedsOverflowRecalcAfterStyleChange. This is needed as a descenda
nt overflow can |
| 1388 // bleed into its containing block's so we have to recompute it in some
cases. |
| 1389 ADD_BOOLEAN_BITFIELD(childNeedsOverflowRecalcAfterStyleChange, ChildNeed
sOverflowRecalcAfterStyleChange); |
| 1390 |
| 1391 // The preferred logical widths are the intrinsic sizes of this element. |
| 1392 // Intrinsic sizes depend mostly on the content and a limited set of sty
le |
| 1393 // properties (e.g. any font-related property for text, 'min-width'/'max
-width', |
| 1394 // 'min-height'/'max-height'). |
| 1395 // |
| 1396 // Those widths are used to determine the final layout logical width, wh
ich |
| 1397 // depends on the layout algorithm used and the available logical width. |
| 1398 // |
| 1399 // Blink stores them in LayoutBox (m_minPreferredLogicalWidth and |
| 1400 // m_maxPreferredLogicalWidth). |
| 1401 // |
| 1402 // Setting this boolean marks both widths for lazy recomputation when |
| 1403 // LayoutBox::minPreferredLogicalWidth() or maxPreferredLogicalWidth() i
s called. |
| 1404 ADD_BOOLEAN_BITFIELD(preferredLogicalWidthsDirty, PreferredLogicalWidths
Dirty); |
| 1405 |
1323 ADD_BOOLEAN_BITFIELD(shouldInvalidateOverflowForPaint, ShouldInvalidateO
verflowForPaint); // TODO(wangxianzhu): Remove for slimming paint v2. | 1406 ADD_BOOLEAN_BITFIELD(shouldInvalidateOverflowForPaint, ShouldInvalidateO
verflowForPaint); // TODO(wangxianzhu): Remove for slimming paint v2. |
1324 ADD_BOOLEAN_BITFIELD(childShouldCheckForPaintInvalidation, ChildShouldCh
eckForPaintInvalidation); | 1407 ADD_BOOLEAN_BITFIELD(childShouldCheckForPaintInvalidation, ChildShouldCh
eckForPaintInvalidation); |
1325 ADD_BOOLEAN_BITFIELD(mayNeedPaintInvalidation, MayNeedPaintInvalidation)
; | 1408 ADD_BOOLEAN_BITFIELD(mayNeedPaintInvalidation, MayNeedPaintInvalidation)
; |
1326 ADD_BOOLEAN_BITFIELD(shouldInvalidateSelection, ShouldInvalidateSelectio
n); // TODO(wangxianzhu): Remove for slimming paint v2. | 1409 ADD_BOOLEAN_BITFIELD(shouldInvalidateSelection, ShouldInvalidateSelectio
n); // TODO(wangxianzhu): Remove for slimming paint v2. |
1327 ADD_BOOLEAN_BITFIELD(neededLayoutBecauseOfChildren, NeededLayoutBecauseO
fChildren); // TODO(wangxianzhu): Remove for slimming paint v2. | 1410 ADD_BOOLEAN_BITFIELD(neededLayoutBecauseOfChildren, NeededLayoutBecauseO
fChildren); // TODO(wangxianzhu): Remove for slimming paint v2. |
1328 ADD_BOOLEAN_BITFIELD(needsPositionedMovementLayout, NeedsPositionedMovem
entLayout); | |
1329 ADD_BOOLEAN_BITFIELD(normalChildNeedsLayout, NormalChildNeedsLayout); | |
1330 ADD_BOOLEAN_BITFIELD(posChildNeedsLayout, PosChildNeedsLayout); | |
1331 ADD_BOOLEAN_BITFIELD(needsSimplifiedNormalFlowLayout, NeedsSimplifiedNor
malFlowLayout); | |
1332 ADD_BOOLEAN_BITFIELD(preferredLogicalWidthsDirty, PreferredLogicalWidths
Dirty); | |
1333 ADD_BOOLEAN_BITFIELD(floating, Floating); | 1411 ADD_BOOLEAN_BITFIELD(floating, Floating); |
1334 ADD_BOOLEAN_BITFIELD(selfNeedsOverflowRecalcAfterStyleChange, SelfNeedsO
verflowRecalcAfterStyleChange); | |
1335 ADD_BOOLEAN_BITFIELD(childNeedsOverflowRecalcAfterStyleChange, ChildNeed
sOverflowRecalcAfterStyleChange); | |
1336 | 1412 |
1337 ADD_BOOLEAN_BITFIELD(isAnonymous, IsAnonymous); | 1413 ADD_BOOLEAN_BITFIELD(isAnonymous, IsAnonymous); |
1338 ADD_BOOLEAN_BITFIELD(isText, IsText); | 1414 ADD_BOOLEAN_BITFIELD(isText, IsText); |
1339 ADD_BOOLEAN_BITFIELD(isBox, IsBox); | 1415 ADD_BOOLEAN_BITFIELD(isBox, IsBox); |
1340 ADD_BOOLEAN_BITFIELD(isInline, IsInline); | 1416 ADD_BOOLEAN_BITFIELD(isInline, IsInline); |
1341 ADD_BOOLEAN_BITFIELD(isReplaced, IsReplaced); | 1417 ADD_BOOLEAN_BITFIELD(isReplaced, IsReplaced); |
1342 ADD_BOOLEAN_BITFIELD(horizontalWritingMode, HorizontalWritingMode); | 1418 ADD_BOOLEAN_BITFIELD(horizontalWritingMode, HorizontalWritingMode); |
1343 ADD_BOOLEAN_BITFIELD(isDragging, IsDragging); | 1419 ADD_BOOLEAN_BITFIELD(isDragging, IsDragging); |
1344 | 1420 |
1345 ADD_BOOLEAN_BITFIELD(hasLayer, HasLayer); | 1421 ADD_BOOLEAN_BITFIELD(hasLayer, HasLayer); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 void showTree(const blink::LayoutObject*); | 1732 void showTree(const blink::LayoutObject*); |
1657 void showLineTree(const blink::LayoutObject*); | 1733 void showLineTree(const blink::LayoutObject*); |
1658 void showLayoutTree(const blink::LayoutObject* object1); | 1734 void showLayoutTree(const blink::LayoutObject* object1); |
1659 // We don't make object2 an optional parameter so that showLayoutTree | 1735 // We don't make object2 an optional parameter so that showLayoutTree |
1660 // can be called from gdb easily. | 1736 // can be called from gdb easily. |
1661 void showLayoutTree(const blink::LayoutObject* object1, const blink::LayoutObjec
t* object2); | 1737 void showLayoutTree(const blink::LayoutObject* object1, const blink::LayoutObjec
t* object2); |
1662 | 1738 |
1663 #endif | 1739 #endif |
1664 | 1740 |
1665 #endif // LayoutObject_h | 1741 #endif // LayoutObject_h |
OLD | NEW |