Changeset 240975 in webkit
- Timestamp:
- Feb 5, 2019 8:01:30 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r240971 r240975 1 2019-02-05 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] collectInlineContent should use pre-computed margins, paddings and borders 4 https://bugs.webkit.org/show_bug.cgi?id=194269 5 6 Reviewed by Antti Koivisto. 7 8 In this patch we pre-compute the margins padding and borders for formatting context roots, replaced boxes and non-replaced containers. 9 These property values are input to collectInlineContent's inline item detaching logic. 10 11 * layout/inlineformatting/InlineFormattingContext.cpp: 12 (WebCore::Layout::nextInPreOrder): 13 (WebCore::Layout::InlineFormattingContext::layout const): 14 (WebCore::Layout::InlineFormattingContext::computeMarginBorderAndPadding const): 15 (WebCore::Layout::InlineFormattingContext::collectInlineContent const): 16 * layout/inlineformatting/InlineFormattingContext.h: 17 * layout/layouttree/LayoutBox.h: ran out bits. 18 1 19 2019-02-05 Antoine Quint <graouts@apple.com> 2 20 -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
r240924 r240975 54 54 } 55 55 56 static inline const Box* nextInPreOrder(const Box& layoutBox, const Container& root) 57 { 58 const Box* nextInPreOrder = nullptr; 59 if (!layoutBox.establishesFormattingContext() && is<Container>(layoutBox) && downcast<Container>(layoutBox).hasInFlowOrFloatingChild()) 60 return downcast<Container>(layoutBox).firstInFlowOrFloatingChild(); 61 62 for (nextInPreOrder = &layoutBox; nextInPreOrder && nextInPreOrder != &root; nextInPreOrder = nextInPreOrder->parent()) { 63 if (auto* nextSibling = nextInPreOrder->nextInFlowOrFloatingSibling()) 64 return nextSibling; 65 } 66 return nullptr; 67 } 68 56 69 void InlineFormattingContext::layout() const 57 70 { … … 60 73 61 74 LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")"); 75 auto& root = downcast<Container>(this->root()); 76 auto* layoutBox = root.firstInFlowOrFloatingChild(); 77 // Compute width/height for non-text content and margin/border/padding for inline containers. 78 while (layoutBox) { 79 if (layoutBox->establishesFormattingContext()) 80 layoutFormattingContextRoot(*layoutBox); 81 else if (is<Container>(*layoutBox)) 82 computeMarginBorderAndPadding(downcast<InlineContainer>(*layoutBox)); 83 else if (layoutBox->isReplaced()) 84 computeWidthAndHeightForReplacedInlineBox(*layoutBox); 85 layoutBox = nextInPreOrder(*layoutBox, root); 86 } 62 87 63 88 InlineRunProvider inlineRunProvider; 64 89 collectInlineContent(inlineRunProvider); 65 // Compute width/height for non-text content.66 for (auto& inlineRun : inlineRunProvider.runs()) {67 if (inlineRun.isText())68 continue;69 70 auto& layoutBox = inlineRun.inlineItem().layoutBox();71 if (layoutBox.establishesFormattingContext()) {72 layoutFormattingContextRoot(layoutBox);73 continue;74 }75 computeWidthAndHeightForReplacedInlineBox(layoutBox);76 }77 78 90 layoutInlineContent(inlineRunProvider); 79 LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root ()<< ")");91 LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root << ")"); 80 92 } 81 93 … … 330 342 } 331 343 344 void InlineFormattingContext::computeMarginBorderAndPadding(const InlineContainer& inlineContainer) const 345 { 346 // Non-replaced, non-formatting root containers (<span></span>) don't have width property -> non width computation. 347 ASSERT(!inlineContainer.replaced()); 348 ASSERT(!inlineContainer.establishesFormattingContext()); 349 350 computeBorderAndPadding(inlineContainer); 351 auto& displayBox = layoutState().displayBoxForLayoutBox(inlineContainer); 352 auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState(), inlineContainer); 353 displayBox.setHorizontalComputedMargin(computedHorizontalMargin); 354 displayBox.setHorizontalMargin({ computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) }); 355 } 356 332 357 void InlineFormattingContext::computeWidthAndMargin(const Box& layoutBox) const 333 358 { … … 471 496 enum class NonBreakableWidthType { Start, End }; 472 497 auto nonBreakableWidth = [&](auto& container, auto type) { 473 auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState, container); 474 auto horizontalMargin = UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) }; 475 auto border = Geometry::computedBorder(layoutState, container); 476 auto padding = Geometry::computedPadding(layoutState, container); 477 498 auto& displayBox = layoutState.displayBoxForLayoutBox(container); 478 499 if (type == NonBreakableWidthType::Start) 479 return border.horizontal.left + horizontalMargin.start + (padding ? padding->horizontal.left : LayoutUnit());480 return border.horizontal.right + horizontalMargin.end + (padding ? padding->horizontal.right : LayoutUnit());500 return displayBox.marginStart() + displayBox.borderLeft() + displayBox.paddingLeft().valueOr(0); 501 return displayBox.marginEnd() + displayBox.borderRight() + displayBox.paddingRight().valueOr(0); 481 502 }; 482 503 … … 497 518 // Formatting contexts are treated as leaf nodes. 498 519 auto& inlineItem = createAndAppendInlineItem(inlineRunProvider, inlineContent, container); 499 auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState,container);500 auto currentNonBreakableStartWidth = nonBreakableStartWidth.valueOr(0) + computedHorizontalMargin.start.valueOr(0) + nonBreakableEndWidth.valueOr(0);501 addDetachingRules(inlineItem, currentNonBreakableStartWidth, computedHorizontalMargin.end);520 auto& displayBox = layoutState.displayBoxForLayoutBox(container); 521 auto currentNonBreakableStartWidth = nonBreakableStartWidth.valueOr(0) + displayBox.marginStart() + nonBreakableEndWidth.valueOr(0); 522 addDetachingRules(inlineItem, currentNonBreakableStartWidth, displayBox.marginEnd()); 502 523 nonBreakableStartWidth = { }; 503 524 nonBreakableEndWidth = { }; -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
r240924 r240975 36 36 namespace Layout { 37 37 38 class InlineContainer; 38 39 class InlineFormattingState; 39 40 class InlineRunProvider; … … 113 114 void layoutFormattingContextRoot(const Box&) const; 114 115 void computeWidthAndHeightForReplacedInlineBox(const Box&) const; 116 void computeMarginBorderAndPadding(const InlineContainer&) const; 115 117 void computeHeightAndMargin(const Box&) const; 116 118 void computeWidthAndMargin(const Box&) const; -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r240845 r240975 156 156 std::unique_ptr<Replaced> m_replaced; 157 157 158 unsigned m_baseTypeFlags : 4;158 unsigned m_baseTypeFlags : 5; 159 159 }; 160 160
Note: See TracChangeset
for help on using the changeset viewer.