Changeset 252835 in webkit
- Timestamp:
- Nov 23, 2019 1:36:33 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252832 r252835 1 2019-11-23 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Defer run height/baseline adjustment computation until Line::close 4 https://bugs.webkit.org/show_bug.cgi?id=204550 5 <rdar://problem/57454497> 6 7 Reviewed by Antti Koivisto. 8 9 Currently we measure run height and adjust the line's baseline/height on every append. 10 We could do all that in Line::close after we've merged the neighboring runs. 11 ([text][ ][content] vs. [text content]) 12 This is about ~5% win on line-layout-simple.html 13 14 * layout/inlineformatting/InlineLine.cpp: 15 (WebCore::Layout::Line::alignContentVertically): 16 (WebCore::Layout::Line::append): 17 (WebCore::Layout::Line::appendInlineContainerStart): 18 (WebCore::Layout::Line::appendInlineContainerEnd): 19 (WebCore::Layout::Line::appendTextContent): 20 (WebCore::Layout::Line::appendNonReplacedInlineBox): 21 (WebCore::Layout::Line::appendLineBreak): 22 (WebCore::Layout::Line::adjustBaselineAndLineHeight): 23 (WebCore::Layout::Line::runContentHeight const): 24 (WebCore::Layout::Line::alignContentVertically const): Deleted. 25 (WebCore::Layout::Line::inlineItemContentHeight const): Deleted. 26 * layout/inlineformatting/InlineLine.h: 27 (WebCore::Layout::Line::Run::setLogicalHeight): 28 1 29 2019-11-23 Andres Gonzalez <andresg_22@apple.com> 2 30 -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp
r252816 r252835 316 316 } 317 317 318 void Line::alignContentVertically(RunList& runList) const318 void Line::alignContentVertically(RunList& runList) 319 319 { 320 320 ASSERT(!m_skipAlignment); 321 for (auto& run : runList) { 322 adjustBaselineAndLineHeight(run); 323 run.setLogicalHeight(runContentHeight(run)); 324 } 325 321 326 for (auto& run : runList) { 322 327 LayoutUnit logicalTop; … … 480 485 void Line::append(const InlineItem& inlineItem, LayoutUnit logicalWidth) 481 486 { 487 if (inlineItem.isText()) 488 return appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth); 482 489 if (inlineItem.isForcedLineBreak()) 483 490 return appendLineBreak(inlineItem); 484 if (is<InlineTextItem>(inlineItem))485 return appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth);486 491 if (inlineItem.isContainerStart()) 487 492 return appendInlineContainerStart(inlineItem, logicalWidth); … … 504 509 { 505 510 // This is really just a placeholder to mark the start of the inline level container <span>. 506 auto logicalRect = Display::Rect { 0, contentLogicalWidth(), logicalWidth, 0 }; 507 508 if (!m_skipAlignment) { 509 adjustBaselineAndLineHeight(inlineItem); 510 logicalRect.setHeight(inlineItemContentHeight(inlineItem)); 511 } 512 appendNonBreakableSpace(inlineItem, logicalRect); 511 appendNonBreakableSpace(inlineItem, Display::Rect { 0, contentLogicalWidth(), logicalWidth, { } }); 513 512 } 514 513 … … 516 515 { 517 516 // This is really just a placeholder to mark the end of the inline level container </span>. 518 auto logicalRect = Display::Rect { 0, contentLogicalRight(), logicalWidth, m_skipAlignment ? LayoutUnit() : inlineItemContentHeight(inlineItem) }; 519 appendNonBreakableSpace(inlineItem, logicalRect); 517 appendNonBreakableSpace(inlineItem, Display::Rect { 0, contentLogicalRight(), logicalWidth, { } }); 520 518 } 521 519 … … 555 553 }; 556 554 557 auto logicalRect = Display::Rect { };558 logicalRect.setLeft(contentLogicalWidth());559 logicalRect.setWidth(logicalWidth);560 if (!m_skipAlignment) {561 adjustBaselineAndLineHeight(inlineItem);562 logicalRect.setHeight(inlineItemContentHeight(inlineItem));563 }564 565 555 auto collapsedRun = inlineItem.isCollapsible() && inlineItem.length() > 1; 566 556 auto contentStart = inlineItem.start(); 567 557 auto contentLength = collapsedRun ? 1 : inlineItem.length(); 568 auto lineRun = makeUnique<InlineItemRun>(inlineItem, logicalRect, Display::Run::TextContext { contentStart, contentLength, inlineItem.layoutBox().textContext()->content.substring(contentStart, contentLength) }); 558 auto lineRun = makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth(), logicalWidth, { } }, 559 Display::Run::TextContext { contentStart, contentLength, inlineItem.layoutBox().textContext()->content.substring(contentStart, contentLength) }); 569 560 570 561 auto collapsesToZeroAdvanceWidth = willCollapseCompletely(); … … 585 576 void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, LayoutUnit logicalWidth) 586 577 { 587 auto& boxGeometry = formattingContext().geometryForBox(inlineItem.layoutBox()); 588 auto horizontalMargin = boxGeometry.horizontalMargin(); 589 auto logicalRect = Display::Rect { }; 590 591 logicalRect.setLeft(contentLogicalWidth() + horizontalMargin.start); 592 logicalRect.setWidth(logicalWidth); 593 if (!m_skipAlignment) { 594 adjustBaselineAndLineHeight(inlineItem); 595 auto runHeight = formattingContext().geometryForBox(inlineItem.layoutBox()).marginBoxHeight(); 596 logicalRect.setHeight(runHeight); 597 } 598 599 m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, logicalRect)); 578 auto horizontalMargin = formattingContext().geometryForBox(inlineItem.layoutBox()).horizontalMargin(); 579 m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth() + horizontalMargin.start, logicalWidth, { } })); 600 580 m_lineBox.expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end); 601 581 m_lineBox.setIsConsideredNonEmpty(); … … 613 593 void Line::appendLineBreak(const InlineItem& inlineItem) 614 594 { 615 auto logicalRect = Display::Rect { };616 logicalRect.setLeft(contentLogicalWidth());617 logicalRect.setWidth({ });618 if (!m_skipAlignment) {619 adjustBaselineAndLineHeight(inlineItem);620 logicalRect.setHeight(logicalHeight());621 }622 595 m_lineBox.setIsConsideredNonEmpty(); 623 m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, logicalRect)); 624 } 625 626 void Line::adjustBaselineAndLineHeight(const InlineItem& inlineItem) 627 { 628 ASSERT(!inlineItem.isContainerEnd()); 629 auto& layoutBox = inlineItem.layoutBox(); 596 m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth(), { }, { } })); 597 } 598 599 void Line::adjustBaselineAndLineHeight(const Run& run) 600 { 601 auto& baseline = m_lineBox.baseline(); 602 if (run.isText() || run.isForcedLineBreak()) { 603 // For text content we set the baseline either through the initial strut (set by the formatting context root) or 604 // through the inline container (start) -see above. Normally the text content itself does not stretch the line. 605 if (!m_initialStrut) 606 return; 607 m_lineBox.setAscentIfGreater(m_initialStrut->ascent()); 608 m_lineBox.setDescentIfGreater(m_initialStrut->descent()); 609 m_lineBox.setLogicalHeightIfGreater(baseline.height()); 610 m_initialStrut = { }; 611 return; 612 } 613 614 auto& layoutBox = run.layoutBox(); 630 615 auto& style = layoutBox.style(); 631 auto& baseline = m_lineBox.baseline(); 632 633 if (inlineItem.isContainerStart()) { 616 if (run.isContainerStart()) { 634 617 // Inline containers stretch the line by their font size. 635 618 // Vertical margins, paddings and borders don't contribute to the line height. … … 648 631 } 649 632 650 if (inlineItem.isText() || inlineItem.isForcedLineBreak()) { 651 // For text content we set the baseline either through the initial strut (set by the formatting context root) or 652 // through the inline container (start) -see above. Normally the text content itself does not stretch the line. 653 if (!m_initialStrut) 654 return; 655 m_lineBox.setAscentIfGreater(m_initialStrut->ascent()); 656 m_lineBox.setDescentIfGreater(m_initialStrut->descent()); 657 m_lineBox.setLogicalHeightIfGreater(baseline.height()); 658 m_initialStrut = { }; 659 return; 660 } 661 662 if (inlineItem.isBox()) { 633 if (run.isContainerEnd()) { 634 // The line's baseline and height have already been adjusted at ContainerStart. 635 return; 636 } 637 638 if (run.isBox()) { 663 639 auto& boxGeometry = formattingContext().geometryForBox(layoutBox); 664 640 auto marginBoxHeight = boxGeometry.marginBoxHeight(); … … 709 685 } 710 686 711 LayoutUnit Line:: inlineItemContentHeight(const InlineItem& inlineItem) const687 LayoutUnit Line::runContentHeight(const Run& run) const 712 688 { 713 689 ASSERT(!m_skipAlignment); 714 auto& fontMetrics = inlineItem.style().fontMetrics();715 if ( inlineItem.isForcedLineBreak() || is<InlineTextItem>(inlineItem))690 auto& fontMetrics = run.layoutBox().style().fontMetrics(); 691 if (run.isText() || run.isForcedLineBreak()) 716 692 return fontMetrics.height(); 717 693 718 if ( inlineItem.isContainerStart() || inlineItem.isContainerEnd())694 if (run.isContainerStart() || run.isContainerEnd()) 719 695 return fontMetrics.height(); 720 696 721 auto& layoutBox = inlineItem.layoutBox();697 auto& layoutBox = run.layoutBox(); 722 698 auto& boxGeometry = formattingContext().geometryForBox(layoutBox); 723 699 if (layoutBox.replaced() || layoutBox.isFloatingPositioned()) -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.h
r252807 r252835 92 92 void moveHorizontally(LayoutUnit offset) { m_logicalRect.moveHorizontally(offset); } 93 93 void moveVertically(LayoutUnit offset) { m_logicalRect.moveVertically(offset); } 94 void setLogicalHeight(LayoutUnit logicalHeight) { m_logicalRect.setHeight(logicalHeight); } 94 95 95 96 bool hasExpansionOpportunity() const { return m_expansionOpportunityCount; } … … 136 137 void removeTrailingTrimmableContent(); 137 138 void alignContentHorizontally(RunList&, IsLastLineWithInlineContent) const; 138 void alignContentVertically(RunList&) const;139 void alignContentVertically(RunList&); 139 140 140 void adjustBaselineAndLineHeight(const InlineItem&);141 LayoutUnit inlineItemContentHeight(const InlineItem&) const;141 void adjustBaselineAndLineHeight(const Run&); 142 LayoutUnit runContentHeight(const Run&) const; 142 143 bool isVisuallyEmpty() const; 143 144
Note: See TracChangeset
for help on using the changeset viewer.