Changeset 258819 in webkit
- Timestamp:
- Mar 22, 2020 7:02:37 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r258817 r258819 1 2020-03-22 Zalan Bujtas <zalan@apple.com> 2 3 [LFC] Layout::Box::containingBlock should return a const ContainerBox& 4 https://bugs.webkit.org/show_bug.cgi?id=209381 5 <rdar://problem/60732278> 6 7 Reviewed by Antti Koivisto. 8 9 Layout tree is immutable during layout, so every box should be able to return a valid containing block (except the ICB). 10 (This patch also removes the unused isDescendantOf() function and renames isDescendantOfFormattingRoot to isInFormattingContextOf). 11 12 * layout/FormattingContext.cpp: 13 (WebCore::Layout::FormattingContext::layoutOutOfFlowContent): 14 (WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const): 15 * layout/FormattingContextGeometry.cpp: 16 (WebCore::Layout::isHeightAuto): 17 (WebCore::Layout::FormattingContext::Geometry::computedHeightValue const): 18 (WebCore::Layout::FormattingContext::Geometry::staticVerticalPositionForOutOfFlowPositioned const): 19 (WebCore::Layout::FormattingContext::Geometry::staticHorizontalPositionForOutOfFlowPositioned const): 20 (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry): 21 (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const): 22 (WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const): 23 * layout/FormattingContextQuirks.cpp: 24 (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight): 25 * layout/Verification.cpp: 26 (WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded): 27 * layout/blockformatting/BlockFormattingContext.cpp: 28 (WebCore::Layout::BlockFormattingContext::layoutInFlowContent): 29 (WebCore::Layout::BlockFormattingContext::usedAvailableWidthForFloatAvoider): 30 (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForAncestors): 31 (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors): 32 (WebCore::Layout::BlockFormattingContext::verticalPositionWithMargin const): 33 * layout/blockformatting/BlockFormattingContextGeometry.cpp: 34 (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const): 35 * layout/blockformatting/BlockFormattingContextQuirks.cpp: 36 (WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight): 37 (WebCore::Layout::initialContainingBlock): Deleted. 38 * layout/blockformatting/BlockMarginCollapse.cpp: 39 (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const): 40 * layout/blockformatting/PrecomputedBlockMarginCollapse.cpp: 41 (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const): 42 * layout/displaytree/DisplayPainter.cpp: 43 (WebCore::Display::absoluteDisplayBox): 44 * layout/floats/FloatingContext.cpp: 45 (WebCore::Layout::FloatingContext::verticalPositionWithClearance const): 46 (WebCore::Layout::FloatingContext::absoluteDisplayBoxCoordinates const): 47 (WebCore::Layout::FloatingContext::mapToFloatingStateRoot const): 48 (WebCore::Layout::FloatingContext::mapTopToFloatingStateRoot const): 49 (WebCore::Layout::FloatingContext::mapPointFromFormattingContextRootToFloatingStateRoot const): 50 * layout/floats/FloatingState.cpp: 51 (WebCore::Layout::FloatingState::bottom const): 52 (WebCore::Layout::FloatingState::top const): 53 * layout/floats/FloatingState.h: 54 (WebCore::Layout::FloatingState::FloatItem::isInFormattingContextOf const): 55 (WebCore::Layout::FloatingState::FloatItem::isDescendantOfFormattingRoot const): Deleted. 56 * layout/layouttree/LayoutBox.cpp: 57 (WebCore::Layout::Box::containingBlock const): 58 (WebCore::Layout::Box::formattingContextRoot const): 59 (WebCore::Layout::Box::isInFormattingContextOf const): 60 (WebCore::Layout::Box::isDescendantOf const): Deleted. 61 (WebCore::Layout::Box::isContainingBlockDescendantOf const): Deleted. 62 * layout/layouttree/LayoutBox.h: 63 1 64 2020-03-21 Said Abou-Hallawa <sabouhallawa@apple.com> 2 65 -
trunk/Source/WebCore/layout/FormattingContext.cpp
r257059 r258819 140 140 141 141 auto horizontalConstraintsForLayoutBox = [&] (const auto& outOfFlowBox) { 142 auto* containingBlock = outOfFlowBox.containingBlock(); 143 ASSERT(containingBlock); 144 if (containingBlock == &root()) 142 auto& containingBlock = outOfFlowBox.containingBlock(); 143 if (&containingBlock == &root()) 145 144 return rootHorizontalConstraints; 146 return Geometry::horizontalConstraintsForOutOfFlow(geometryForBox( *containingBlock));145 return Geometry::horizontalConstraintsForOutOfFlow(geometryForBox(containingBlock)); 147 146 }; 148 147 149 148 auto verticalConstraintsForLayoutBox = [&] (const auto& outOfFlowBox) { 150 auto* containingBlock = outOfFlowBox.containingBlock(); 151 ASSERT(containingBlock); 152 if (containingBlock == &root()) 149 auto& containingBlock = outOfFlowBox.containingBlock(); 150 if (&containingBlock == &root()) 153 151 return rootVerticalConstraints; 154 return Geometry::verticalConstraintsForOutOfFlow(geometryForBox( *containingBlock));152 return Geometry::verticalConstraintsForOutOfFlow(geometryForBox(containingBlock)); 155 153 }; 156 154 … … 304 302 if (&layoutBox.formattingContextRoot() != &formattingContextRoot) 305 303 continue; 306 auto& containingBlockGeometry = geometryForBox( *layoutBox.containingBlock());304 auto& containingBlockGeometry = geometryForBox(layoutBox.containingBlock()); 307 305 auto& boxGeometry = geometryForBox(layoutBox); 308 306 -
trunk/Source/WebCore/layout/FormattingContextGeometry.cpp
r257537 r258819 55 55 return false; 56 56 57 return !layoutBox.containingBlock() ->style().logicalHeight().isFixed();57 return !layoutBox.containingBlock().style().logicalHeight().isFixed(); 58 58 } 59 59 … … 77 77 containingBlockHeight = formattingContext().quirks().heightValueOfNearestContainingBlockWithFixedHeight(layoutBox); 78 78 else { 79 auto containingBlockHeightFromStyle = layoutBox.containingBlock() ->style().logicalHeight();79 auto containingBlockHeightFromStyle = layoutBox.containingBlock().style().logicalHeight(); 80 80 if (containingBlockHeightFromStyle.isFixed()) 81 81 containingBlockHeight = LayoutUnit { containingBlockHeightFromStyle.value() }; … … 239 239 240 240 // Resolve top all the way up to the containing block. 241 auto& containingBlock = *layoutBox.containingBlock();241 auto& containingBlock = layoutBox.containingBlock(); 242 242 // Start with the parent since we pretend that this box is normal flow. 243 for (auto* containerBox = layoutBox.parent(); containerBox != &containingBlock; containerBox = containerBox->containingBlock()) {244 auto& boxGeometry = formattingContext.geometryForBox(* containerBox, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);243 for (auto* ancestor = layoutBox.parent(); ancestor != &containingBlock; ancestor = &ancestor->containingBlock()) { 244 auto& boxGeometry = formattingContext.geometryForBox(*ancestor, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry); 245 245 // Display::Box::top is the border box top position in its containing block's coordinate system. 246 246 top += boxGeometry.top(); 247 ASSERT(! containerBox->isPositioned() || layoutBox.isFixedPositioned());247 ASSERT(!ancestor->isPositioned() || layoutBox.isFixedPositioned()); 248 248 } 249 249 // Move the static position relative to the padding box. This is very specific to abolutely positioned boxes. … … 262 262 263 263 // Resolve left all the way up to the containing block. 264 auto& containingBlock = *layoutBox.containingBlock();264 auto& containingBlock = layoutBox.containingBlock(); 265 265 // Start with the parent since we pretend that this box is normal flow. 266 for (auto* containerBox = layoutBox.parent(); containerBox != &containingBlock; containerBox = containerBox->containingBlock()) {267 auto& boxGeometry = formattingContext.geometryForBox(* containerBox, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);266 for (auto* ancestor = layoutBox.parent(); ancestor != &containingBlock; ancestor = &ancestor->containingBlock()) { 267 auto& boxGeometry = formattingContext.geometryForBox(*ancestor, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry); 268 268 // Display::Box::left is the border box left position in its containing block's coordinate system. 269 269 left += boxGeometry.left(); 270 ASSERT(! containerBox->isPositioned() || layoutBox.isFixedPositioned());270 ASSERT(!ancestor->isPositioned() || layoutBox.isFixedPositioned()); 271 271 } 272 272 // Move the static position relative to the padding box. This is very specific to abolutely positioned boxes. … … 452 452 auto& boxGeometry = formattingContext.geometryForBox(layoutBox); 453 453 auto containingBlockWidth = horizontalConstraints.logicalWidth; 454 auto isLeftToRightDirection = layoutBox.containingBlock() ->style().isLeftToRightDirection();454 auto isLeftToRightDirection = layoutBox.containingBlock().style().isLeftToRightDirection(); 455 455 456 456 auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth); … … 665 665 auto& boxGeometry = formattingContext.geometryForBox(replacedBox); 666 666 auto containingBlockWidth = horizontalConstraints.logicalWidth; 667 auto isLeftToRightDirection = replacedBox.containingBlock() ->style().isLeftToRightDirection();667 auto isLeftToRightDirection = replacedBox.containingBlock().style().isLeftToRightDirection(); 668 668 669 669 auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth); … … 1026 1026 } else { 1027 1027 // #4 1028 auto isLeftToRightDirection = layoutBox.containingBlock() ->style().isLeftToRightDirection();1028 auto isLeftToRightDirection = layoutBox.containingBlock().style().isLeftToRightDirection(); 1029 1029 if (isLeftToRightDirection) 1030 1030 right = -*left; -
trunk/Source/WebCore/layout/FormattingContextQuirks.cpp
r254666 r258819 40 40 // the current formatting context. FIXME: surely we need to do some tricks here when block direction support is added. 41 41 auto& formattingContext = this->formattingContext(); 42 auto* containingBlock = layoutBox.containingBlock();42 auto* containingBlock = &layoutBox.containingBlock(); 43 43 LayoutUnit bodyAndDocumentVerticalMarginPaddingAndBorder; 44 44 while (containingBlock) { … … 52 52 auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk); 53 53 54 auto& containingBlockDisplayBox = formattingContext.geometryForBox( *containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);54 auto& containingBlockDisplayBox = formattingContext.geometryForBox(containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk); 55 55 auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(containingBlockDisplayBox); 56 56 auto verticalMargin = formattingContext.geometry().computedVerticalMargin(*containingBlock, horizontalConstraints); … … 60 60 } 61 61 62 containingBlock = containingBlock->containingBlock(); 62 if (containingBlock->isInitialContainingBlock()) 63 break; 64 containingBlock = &containingBlock->containingBlock(); 63 65 } 64 66 // Initial containing block has to have a height. -
trunk/Source/WebCore/layout/Verification.cpp
r258079 r258819 252 252 // When the <table> is out-of-flow positioned, the wrapper table box has the offset 253 253 // while the actual table box is static, inflow. 254 auto& tableWrapperDisplayBox = context.displayBoxForLayoutBox( *layoutBox.containingBlock());254 auto& tableWrapperDisplayBox = context.displayBoxForLayoutBox(layoutBox.containingBlock()); 255 255 displayBox.moveBy(tableWrapperDisplayBox.topLeft()); 256 256 } -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
r257718 r258819 92 92 93 93 auto horizontalConstraintsForLayoutBox = [&] (const auto& layoutBox) { 94 auto* containingBlock = layoutBox.containingBlock(); 95 ASSERT(containingBlock); 96 if (containingBlock == &formattingRoot) 94 auto& containingBlock = layoutBox.containingBlock(); 95 if (&containingBlock == &formattingRoot) 97 96 return rootHorizontalConstraints; 98 return Geometry::horizontalConstraintsForInFlow(geometryForBox( *containingBlock));97 return Geometry::horizontalConstraintsForInFlow(geometryForBox(containingBlock)); 99 98 }; 100 99 101 100 auto verticalConstraintsForLayoutBox = [&] (const auto& layoutBox) { 102 auto* containingBlock = layoutBox.containingBlock(); 103 ASSERT(containingBlock); 104 if (containingBlock == &formattingRoot) 101 auto& containingBlock = layoutBox.containingBlock(); 102 if (&containingBlock == &formattingRoot) 105 103 return rootVerticalConstraints; 106 return Geometry::verticalConstraintsForInFlow(geometryForBox( *containingBlock));104 return Geometry::verticalConstraintsForInFlow(geometryForBox(containingBlock)); 107 105 }; 108 106 … … 212 210 auto mapLogicalTopToFormattingContextRoot = [&] { 213 211 auto& formattingContextRoot = root(); 214 ASSERT(layoutBox.is ContainingBlockDescendantOf(formattingContextRoot));212 ASSERT(layoutBox.isInFormattingContextOf(formattingContextRoot)); 215 213 auto top = geometryForBox(layoutBox).top(); 216 for (auto* containerBox = layoutBox.containingBlock(); containerBox && containerBox != &formattingContextRoot; containerBox = containerBox->containingBlock())217 top += geometryForBox(* containerBox).top();214 for (auto* ancestor = &layoutBox.containingBlock(); ancestor != &formattingContextRoot; ancestor = &ancestor->containingBlock()) 215 top += geometryForBox(*ancestor).top(); 218 216 return top; 219 217 }; … … 260 258 { 261 259 ASSERT(layoutBox.isFloatAvoider()); 262 precomputeVerticalPositionForBoxAndAncestors( *layoutBox.containingBlock(), horizontalConstraints, verticalConstraints);260 precomputeVerticalPositionForBoxAndAncestors(layoutBox.containingBlock(), horizontalConstraints, verticalConstraints); 263 261 } 264 262 … … 275 273 // The idea here is that as long as we don't cross the block formatting context boundary, we should be able to pre-compute the final top position. 276 274 // FIXME: we currently don't account for the "clear" property when computing the final position for an ancestor. 277 for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = ancestor->containingBlock()) {275 for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = &ancestor->containingBlock()) { 278 276 auto horizontalConstraintsForAncestor = [&] { 279 auto *containingBlock = ancestor->containingBlock();280 return containingBlock == &root() ? horizontalConstraints.root : Geometry::horizontalConstraintsForInFlow(geometryForBox(*containingBlock));277 auto& containingBlock = ancestor->containingBlock(); 278 return &containingBlock == &root() ? horizontalConstraints.root : Geometry::horizontalConstraintsForInFlow(geometryForBox(containingBlock)); 281 279 }; 282 280 auto verticalConstraintsForAncestor = [&] { 283 auto *containingBlock = ancestor->containingBlock();284 return containingBlock == &root() ? verticalConstraints.root : Geometry::verticalConstraintsForInFlow(geometryForBox(*containingBlock));281 auto& containingBlock = ancestor->containingBlock(); 282 return &containingBlock == &root() ? verticalConstraints.root : Geometry::verticalConstraintsForInFlow(geometryForBox(containingBlock)); 285 283 }; 286 284 … … 554 552 } 555 553 // At this point this box indirectly (via collapsed through previous in-flow siblings) adjoins the parent. Let's check if it margin collapses with the parent. 556 auto& containingBlock = *layoutBox.containingBlock();554 auto& containingBlock = layoutBox.containingBlock(); 557 555 ASSERT(containingBlock.firstInFlowChild()); 558 556 ASSERT(containingBlock.firstInFlowChild() != &layoutBox); -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
r256840 r258819 159 159 // #2 160 160 if (width && computedHorizontalMargin.start && computedHorizontalMargin.end) { 161 if (layoutBox.containingBlock() ->style().isLeftToRightDirection()) {161 if (layoutBox.containingBlock().style().isLeftToRightDirection()) { 162 162 usedHorizontalMargin.start = *computedHorizontalMargin.start; 163 163 usedHorizontalMargin.end = containingBlockWidth - (usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight); -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp
r257690 r258819 38 38 namespace Layout { 39 39 40 static const ContainerBox& initialContainingBlock(const Box& layoutBox)41 {42 auto* containingBlock = layoutBox.containingBlock();43 while (containingBlock->containingBlock())44 containingBlock = containingBlock->containingBlock();45 return *containingBlock;46 }47 48 40 static bool isQuirkContainer(const Box& layoutBox) 49 41 { … … 72 64 if (layoutBox.isDocumentBox()) { 73 65 // Let's stretch the inflow document box(<html>) to the height of the initial containing block (view). 74 auto documentBoxContentHeight = formattingContext.geometryForBox( initialContainingBlock(layoutBox), EscapeReason::DocumentBoxStrechesToViewportQuirk).contentBoxHeight();66 auto documentBoxContentHeight = formattingContext.geometryForBox(layoutBox.initialContainingBlock(), EscapeReason::DocumentBoxStrechesToViewportQuirk).contentBoxHeight(); 75 67 // Document box's own vertical margin/border/padding values always shrink the content height. 76 68 auto& documentBoxGeometry = formattingContext.geometryForBox(layoutBox); … … 81 73 // Here is the quirky part for body box when it stretches all the way to the ICB even when the document box does not (e.g. out-of-flow positioned). 82 74 ASSERT(layoutBox.isBodyBox()); 83 auto& initialContainingBlockGeometry = formattingContext.geometryForBox( initialContainingBlock(layoutBox), EscapeReason::BodyStrechesToViewportQuirk);75 auto& initialContainingBlockGeometry = formattingContext.geometryForBox(layoutBox.initialContainingBlock(), EscapeReason::BodyStrechesToViewportQuirk); 84 76 // Start the content height with the ICB. 85 77 auto bodyBoxContentHeight = initialContainingBlockGeometry.contentBoxHeight(); -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
r257701 r258819 407 407 auto& floats = formattingState.floatingState().floats(); 408 408 for (auto& floatItem : floats) { 409 if (floatItem.is DescendantOfFormattingRoot(containerBox))409 if (floatItem.isInFormattingContextOf(containerBox)) 410 410 return false; 411 411 } -
trunk/Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp
r257748 r258819 45 45 return blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox).before; 46 46 47 auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox( *layoutBox.containingBlock()));47 auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox(layoutBox.containingBlock())); 48 48 auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, horizontalConstraints); 49 49 auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) }; -
trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp
r256701 r258819 151 151 152 152 auto absoluteBox = Box { layoutState.displayBoxForLayoutBox(layoutBox) }; 153 for (auto* contain erBox = layoutBox.containingBlock(); containerBox != &layoutBox.initialContainingBlock(); containerBox = containerBox->containingBlock())154 absoluteBox.moveBy(layoutState.displayBoxForLayoutBox(*contain erBox).topLeft());153 for (auto* containingBlock = &layoutBox.containingBlock(); !containingBlock->isInitialContainingBlock(); containingBlock = &containingBlock->containingBlock()) 154 absoluteBox.moveBy(layoutState.displayBoxForLayoutBox(*containingBlock).topLeft()); 155 155 return absoluteBox; 156 156 } -
trunk/Source/WebCore/layout/floats/FloatingContext.cpp
r256928 r258819 252 252 253 253 // The return vertical position is in the containing block's coordinate system. Convert it to the formatting root's coordinate system if needed. 254 if ( layoutBox.containingBlock() == &m_floatingState.root())254 if (&layoutBox.containingBlock() == &m_floatingState.root()) 255 255 return { Position { rootRelativeTop }, clearance }; 256 256 257 auto containingBlockRootRelativeTop = mapTopToFloatingStateRoot( *layoutBox.containingBlock());257 auto containingBlockRootRelativeTop = mapTopToFloatingStateRoot(layoutBox.containingBlock()); 258 258 return { Position { rootRelativeTop - containingBlockRootRelativeTop }, clearance }; 259 259 }; … … 419 419 FloatingContext::AbsoluteCoordinateValuesForFloatAvoider FloatingContext::absoluteDisplayBoxCoordinates(const Box& floatAvoider) const 420 420 { 421 auto& containingBlock = *floatAvoider.containingBlock();421 auto& containingBlock = floatAvoider.containingBlock(); 422 422 auto displayBox = mapToFloatingStateRoot(floatAvoider); 423 423 … … 436 436 auto& boxGeometry = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates); 437 437 auto topLeft = boxGeometry.topLeft(); 438 for (auto* containingBlock = floatBox.containingBlock(); containingBlock && containingBlock != &floatingStateRoot; containingBlock =containingBlock->containingBlock())438 for (auto* containingBlock = &floatBox.containingBlock(); containingBlock != &floatingStateRoot; containingBlock = &containingBlock->containingBlock()) 439 439 topLeft.moveBy(formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft()); 440 440 … … 448 448 auto& floatingStateRoot = floatingState().root(); 449 449 auto top = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top(); 450 for (auto* contain erBox = floatBox.containingBlock(); containerBox && containerBox != &floatingStateRoot; containerBox = containerBox->containingBlock())451 top += formattingContext().geometryForBox(*contain erBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top();450 for (auto* containingBlock = &floatBox.containingBlock(); containingBlock != &floatingStateRoot; containingBlock = &containingBlock->containingBlock()) 451 top += formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top(); 452 452 return top; 453 453 } … … 460 460 return position; 461 461 auto mappedPosition = position; 462 for (auto* contain erBox = &from; containerBox && containerBox != &to; containerBox = containerBox->containingBlock())463 mappedPosition.moveBy(formattingContext().geometryForBox(*contain erBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft());462 for (auto* containingBlock = &from; containingBlock != &to; containingBlock = &containingBlock->containingBlock()) 463 mappedPosition.moveBy(formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft()); 464 464 return mappedPosition; 465 465 } -
trunk/Source/WebCore/layout/floats/FloatingState.cpp
r257683 r258819 98 98 for (auto& floatItem : m_floats) { 99 99 // Ignore floats from ancestor formatting contexts when the floating state is inherited. 100 if (!floatItem.is DescendantOfFormattingRoot(formattingContextRoot))100 if (!floatItem.isInFormattingContextOf(formattingContextRoot)) 101 101 continue; 102 102 … … 123 123 for (auto& floatItem : m_floats) { 124 124 // Ignore floats from ancestor formatting contexts when the floating state is inherited. 125 if (!floatItem.is DescendantOfFormattingRoot(formattingContextRoot))125 if (!floatItem.isInFormattingContextOf(formattingContextRoot)) 126 126 continue; 127 127 -
trunk/Source/WebCore/layout/floats/FloatingState.h
r256417 r258819 67 67 68 68 bool isLeftPositioned() const { return m_position == Position::Left; } 69 bool is DescendantOfFormattingRoot(const ContainerBox&) const;69 bool isInFormattingContextOf(const ContainerBox& formattingContextRoot) const { return m_layoutBox->isInFormattingContextOf(formattingContextRoot); } 70 70 71 71 Display::Rect rectWithMargin() const { return m_absoluteDisplayBox.rectWithMargin(); } … … 116 116 } 117 117 118 inline bool FloatingState::FloatItem::isDescendantOfFormattingRoot(const ContainerBox& formattingContextRoot) const119 {120 ASSERT(formattingContextRoot.establishesFormattingContext());121 return m_layoutBox->isContainingBlockDescendantOf(downcast<ContainerBox>(formattingContextRoot));122 }123 124 118 } 125 119 } -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r257970 r258819 179 179 } 180 180 181 const ContainerBox *Box::containingBlock() const181 const ContainerBox& Box::containingBlock() const 182 182 { 183 183 // Finding the containing block by traversing the tree during tree construction could provide incorrect result. 184 184 ASSERT(!Phase::isInTreeBuilding()); 185 // If we ever end up here with the ICB, we must be doing something not-so-great. 186 RELEASE_ASSERT(!isInitialContainingBlock()); 185 187 // The containing block in which the root element lives is a rectangle called the initial containing block. 186 188 // For other elements, if the element's position is 'relative' or 'static', the containing block is formed by the … … 189 191 // If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 190 192 // 'position' of 'absolute', 'relative' or 'fixed'. 191 if (!parent())192 return nullptr;193 194 193 if (!isPositioned() || isInFlowPositioned()) { 195 for (auto* nearestBlockContainerOrFormattingContextRoot = parent(); nearestBlockContainerOrFormattingContextRoot; nearestBlockContainerOrFormattingContextRoot = nearestBlockContainerOrFormattingContextRoot->parent()) { 196 if (nearestBlockContainerOrFormattingContextRoot->isBlockContainerBox() || nearestBlockContainerOrFormattingContextRoot->establishesFormattingContext()) 197 return nearestBlockContainerOrFormattingContextRoot; 194 auto* ancestor = parent(); 195 for (; !ancestor->isInitialContainingBlock(); ancestor = ancestor->parent()) { 196 if (ancestor->isBlockContainerBox() || ancestor->establishesFormattingContext()) 197 return *ancestor; 198 198 } 199 // We should always manage to find the ICB. 200 ASSERT_NOT_REACHED(); 201 return nullptr; 199 return *ancestor; 202 200 } 203 201 204 202 if (isFixedPositioned()) { 205 203 auto* ancestor = parent(); 206 for (; ancestor->parent() && !ancestor->style().hasTransform(); ancestor = ancestor->parent()) { } 207 return ancestor; 204 for (; !ancestor->isInitialContainingBlock(); ancestor = ancestor->parent()) { 205 if (ancestor->style().hasTransform()) 206 return *ancestor; 207 } 208 return *ancestor; 208 209 } 209 210 210 211 if (isOutOfFlowPositioned()) { 211 212 auto* ancestor = parent(); 212 for (; ancestor->parent() && !ancestor->isPositioned() && !ancestor->style().hasTransform(); ancestor = ancestor->parent()) { } 213 return ancestor; 213 for (; !ancestor->isInitialContainingBlock(); ancestor = ancestor->parent()) { 214 if (ancestor->isPositioned() || ancestor->style().hasTransform()) 215 return *ancestor; 216 } 217 return *ancestor; 214 218 } 215 219 216 220 ASSERT_NOT_REACHED(); 217 return nullptr;221 return initialContainingBlock(); 218 222 } 219 223 … … 231 235 // While the relatively positioned inline container (span) is placed relative to its containing block "outer", it lives in the inline 232 236 // formatting context established by "inner". 233 const ContainerBox* ancestor = nullptr; 234 if (isInlineLevelBox() && isInFlowPositioned()) 235 ancestor = parent(); 236 else 237 ancestor = containingBlock(); 238 ASSERT(ancestor); 239 if (ancestor->establishesFormattingContext()) 240 return *ancestor; 241 return ancestor->formattingContextRoot(); 237 auto& ancestor = isInlineLevelBox() && isInFlowPositioned() ? *parent() : containingBlock(); 238 if (ancestor.establishesFormattingContext()) 239 return ancestor; 240 return ancestor.formattingContextRoot(); 242 241 } 243 242 … … 253 252 } 254 253 255 bool Box::isDescendantOf(const ContainerBox& ancestorCandidate) const 256 { 257 for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { 258 if (ancestor == &ancestorCandidate) 254 bool Box::isInFormattingContextOf(const ContainerBox& formattingContextRoot) const 255 { 256 ASSERT(formattingContextRoot.establishesFormattingContext()); 257 ASSERT(!isInitialContainingBlock()); 258 auto* ancestor = &containingBlock(); 259 while (ancestor) { 260 if (ancestor == &formattingContextRoot) 259 261 return true; 260 } 261 return false; 262 } 263 264 bool Box::isContainingBlockDescendantOf(const ContainerBox& ancestorCandidate) const 265 { 266 for (auto* ancestor = containingBlock(); ancestor; ancestor = ancestor->containingBlock()) { 267 if (ancestor == &ancestorCandidate) 268 return true; 269 } 262 if (ancestor->isInitialContainingBlock()) 263 return false; 264 ancestor = &ancestor->containingBlock(); 265 } 266 ASSERT_NOT_REACHED(); 270 267 return false; 271 268 } -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r256417 r258819 94 94 bool isFloatingOrOutOfFlowPositioned() const { return isFloatingPositioned() || isOutOfFlowPositioned(); } 95 95 96 const ContainerBox *containingBlock() const;96 const ContainerBox& containingBlock() const; 97 97 const ContainerBox& formattingContextRoot() const; 98 98 const ContainerBox& initialContainingBlock() const; 99 99 100 bool isDescendantOf(const ContainerBox&) const; 101 bool isContainingBlockDescendantOf(const ContainerBox&) const; 100 bool isInFormattingContextOf(const ContainerBox&) const; 102 101 103 102 bool isAnonymous() const { return m_isAnonymous; }
Note: See TracChangeset
for help on using the changeset viewer.