Changeset 240337 in webkit
- Timestamp:
- Jan 23, 2019 8:29:53 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r240336 r240337 1 2019-01-23 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][BFC] computeStaticPosition should include estimated computation as well. 4 https://bugs.webkit.org/show_bug.cgi?id=193719 5 6 Reviewed by Antti Koivisto. 7 8 Consolidate all static position (non-estimated, estimated) computation in BlockFormattingContext::computeStaticPosition. 9 It requires to compute width/horizontal margin first, since vertical top estimation needs valid horizontal widths (margin-top: 5% is computed using 10 the containing block's width). 11 This is also in preparation for moving 'clear' positioning to computeStaticPosition. 12 13 * layout/blockformatting/BlockFormattingContext.cpp: 14 (WebCore::Layout::BlockFormattingContext::layout const): 15 (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const): 16 (WebCore::Layout::BlockFormattingContext::computeStaticPosition const): 17 (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition const): 18 (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForAncestors const): 19 (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFormattingRoot const): 20 (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFloatClear const): 21 (WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const): 22 (WebCore::Layout::BlockFormattingContext::computeWidthAndMargin const): 23 (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const): 24 (WebCore::Layout::BlockFormattingContext::adjustedVerticalPositionAfterMarginCollapsing const): 25 (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginBefore const): Deleted. 26 (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginBeforeForAncestors const): Deleted. 27 (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded const): Deleted. 28 * layout/blockformatting/BlockFormattingContext.h: 29 * layout/blockformatting/BlockFormattingContextGeometry.cpp: 30 (WebCore::Layout::BlockFormattingContext::Geometry::staticPosition): 31 * layout/blockformatting/BlockMarginCollapse.cpp: 32 (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore): 33 1 34 2019-01-22 Simon Fraser <simon.fraser@apple.com> 2 35 -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
r240253 r240337 89 89 90 90 LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Position][Border][Padding][Width][Margin] -> for layoutBox(" << &layoutBox << ")"); 91 computeStaticPosition(layoutBox);92 91 computeBorderAndPadding(layoutBox); 93 92 computeWidthAndMargin(layoutBox); 93 computeStaticPosition(layoutBox); 94 94 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild()) 95 95 break; … … 129 129 // Start laying out this formatting root in the formatting contenxt it lives in. 130 130 LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Position][Border][Padding][Width][Margin] -> for layoutBox(" << &layoutBox << ")"); 131 computeStaticPosition(layoutBox);132 131 computeBorderAndPadding(layoutBox); 133 132 computeWidthAndMargin(layoutBox); 134 135 precomputeVerticalPositionForFormattingRootIfNeeded(layoutBox); 133 computeStaticPosition(layoutBox); 136 134 // Swich over to the new formatting context (the one that the root creates). 137 135 auto formattingContext = layoutState().createFormattingContext(layoutBox); … … 183 181 auto& layoutState = this->layoutState(); 184 182 layoutState.displayBoxForLayoutBox(layoutBox).setTopLeft(Geometry::staticPosition(layoutState, layoutBox)); 185 } 186 187 void BlockFormattingContext::computeEstimatedMarginBefore(const Box& layoutBox) const 183 if (layoutBox.hasFloatClear()) 184 computeEstimatedVerticalPositionForFloatClear(layoutBox); 185 else if (layoutBox.establishesFormattingContext()) 186 computeEstimatedVerticalPositionForFormattingRoot(layoutBox); 187 } 188 189 void BlockFormattingContext::computeEstimatedVerticalPosition(const Box& layoutBox) const 188 190 { 189 191 auto& layoutState = this->layoutState(); … … 195 197 auto collapsedValues = UsedVerticalMargin::CollapsedValues { estimatedMarginBefore.collapsedValue, { }, estimatedMarginBefore.isCollapsedThrough }; 196 198 auto verticalMargin = UsedVerticalMargin { nonCollapsedValues, collapsedValues }; 199 displayBox.setVerticalMargin(verticalMargin); 197 200 displayBox.setTop(adjustedVerticalPositionAfterMarginCollapsing(layoutBox, verticalMargin)); 198 201 #if !ASSERT_DISABLED … … 201 204 } 202 205 203 void BlockFormattingContext::computeEstimated MarginBeforeForAncestors(const Box& layoutBox) const206 void BlockFormattingContext::computeEstimatedVerticalPositionForAncestors(const Box& layoutBox) const 204 207 { 205 208 // We only need to estimate margin top for float related layout (formatting context roots avoid floats). … … 214 217 // So when we get to the point where we intersect the box with the float to decide if the box needs to move, we don't yet have the final vertical position. 215 218 // 216 // 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 margin.219 // 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. 217 220 for (auto* ancestor = layoutBox.containingBlock(); ancestor && !ancestor->establishesBlockFormattingContext(); ancestor = ancestor->containingBlock()) { 218 221 // FIXME: with incremental layout, we might actually have a valid (non-estimated) margin top as well. 219 222 if (hasEstimatedMarginBefore(*ancestor)) 220 223 return; 221 222 computeEstimatedMarginBefore(*ancestor); 223 } 224 } 225 226 void BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded(const Box& layoutBox) const 224 computeEstimatedVerticalPosition(*ancestor); 225 } 226 } 227 228 void BlockFormattingContext::computeEstimatedVerticalPositionForFormattingRoot(const Box& layoutBox) const 227 229 { 228 230 ASSERT(layoutBox.establishesFormattingContext()); 229 230 auto avoidsFloats = layoutBox.isFloatingPositioned() || layoutBox.establishesBlockFormattingContext() || layoutBox.hasFloatClear(); 231 ASSERT(!layoutBox.hasFloatClear()); 232 233 auto avoidsFloats = layoutBox.isFloatingPositioned() || layoutBox.establishesBlockFormattingContext(); 231 234 if (avoidsFloats) 232 computeEstimated MarginBeforeForAncestors(layoutBox);235 computeEstimatedVerticalPositionForAncestors(layoutBox); 233 236 234 237 // If the inline formatting root is also the root for the floats (happens when the root box also establishes a block formatting context) … … 236 239 auto inlineContextInheritsFloats = layoutBox.establishesInlineFormattingContext() && !layoutBox.establishesBlockFormattingContext(); 237 240 if (inlineContextInheritsFloats) { 238 computeEstimatedMarginBefore(layoutBox); 239 computeEstimatedMarginBeforeForAncestors(layoutBox); 240 } 241 computeEstimatedVerticalPosition(layoutBox); 242 computeEstimatedVerticalPositionForAncestors(layoutBox); 243 } 244 } 245 246 void BlockFormattingContext::computeEstimatedVerticalPositionForFloatClear(const Box&) const 247 { 241 248 } 242 249 … … 294 301 // For formatting roots, we already precomputed final position. 295 302 if (!layoutBox.establishesFormattingContext()) 296 computeEstimated MarginBeforeForAncestors(layoutBox);303 computeEstimatedVerticalPositionForAncestors(layoutBox); 297 304 ASSERT(hasPrecomputedMarginBefore(layoutBox)); 298 305 … … 366 373 auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox); 367 374 displayBox.setContentBoxWidth(widthAndMargin.width); 368 displayBox.moveHorizontally(widthAndMargin.usedMargin.start);369 375 displayBox.setHorizontalMargin(widthAndMargin.usedMargin); 370 376 displayBox.setHorizontalComputedMargin(widthAndMargin.computedMargin); … … 407 413 408 414 // 1. Compute collapsed margins. 409 // 2. Adjust vertical position using the collap ed values415 // 2. Adjust vertical position using the collapsed values 410 416 // 3. Adjust previous in-flow sibling margin after using this margin. 411 417 auto collapsedMargin = MarginCollapse::collapsedVerticalValues(layoutState, layoutBox, heightAndMargin.nonCollapsedMargin); … … 500 506 ASSERT(!layoutBox.isOutOfFlowPositioned()); 501 507 // Now that we've computed the final margin before, let's shift the box's vertical position. 502 // 1. Check if the margin before collapses with the previous box's margin after. if not -> return previous box's bottom in lcuding margin after + marginBefore508 // 1. Check if the margin before collapses with the previous box's margin after. if not -> return previous box's bottom including margin after + marginBefore 503 509 // 2. Check if the previous box's margins collapse through. If not -> return previous box' bottom excluding margin after + marginBefore (they are supposed to be equal) 504 510 // 3. Go to previous box and start from step #1 until we hit the parent box. -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h
r239903 r240337 64 64 void computeVerticalPositionForFloatClear(const FloatingContext&, const Box&) const; 65 65 66 void computeEstimated MarginBeforeForAncestors(const Box&) const;67 void computeEstimated MarginBefore(const Box&) const;68 69 void precomputeVerticalPositionForFormattingRootIfNeeded(const Box&) const;66 void computeEstimatedVerticalPosition(const Box&) const; 67 void computeEstimatedVerticalPositionForAncestors(const Box&) const; 68 void computeEstimatedVerticalPositionForFormattingRoot(const Box&) const; 69 void computeEstimatedVerticalPositionForFloatClear(const Box&) const; 70 70 71 71 InstrinsicWidthConstraints instrinsicWidthConstraints() const override; -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
r240108 r240337 237 237 top = containingBlockDisplayBox.contentBoxTop(); 238 238 239 auto left = containingBlockDisplayBox.contentBoxLeft() ;239 auto left = containingBlockDisplayBox.contentBoxLeft() + layoutState.displayBoxForLayoutBox(layoutBox).marginStart(); 240 240 LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position] -> static -> top(" << top << "px) left(" << left << "px) layoutBox(" << &layoutBox << ")"); 241 241 return { left, top }; -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
r240146 r240337 188 188 return false; 189 189 190 // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children.191 if (establishesBlockFormattingContext(layoutBox))192 return false;193 194 190 // The top margin of an in-flow block element collapses with its first in-flow block-level 195 191 // child's top margin if the element has no top border...
Note: See TracChangeset
for help on using the changeset viewer.