Changeset 270114 in webkit
- Timestamp:
- Nov 20, 2020 6:57:43 AM (3 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r270110 r270114 1 2020-11-20 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Move horizontal space tracking from Line to LineBuilder 4 https://bugs.webkit.org/show_bug.cgi?id=219185 5 6 Reviewed by Antti Koivisto. 7 8 Let's move the available horizontal space tracking from Line to LineBuilder. Since the LineBuilder decides what to put on the line 9 the Line object does not need to know how much available space there is. 10 This is also in preparation for adding float support on (vertically) stretchy lines where the horizontal available space may vary 11 depending on how much the inline level boxes stretch the line vertically. 12 13 * layout/inlineformatting/InlineLine.cpp: 14 (WebCore::Layout::Line::initialize): 15 (WebCore::Layout::Line::removeCollapsibleContent): 16 (WebCore::Layout::Line::applyRunExpansion): 17 (WebCore::Layout::Line::removeTrailingTrimmableContent): 18 (WebCore::Layout::Line::visuallyCollapsePreWrapOverflowContent): 19 (WebCore::Layout::Line::moveLogicalLeft): 20 (WebCore::Layout::Line::moveLogicalRight): Deleted. 21 * layout/inlineformatting/InlineLine.h: 22 (WebCore::Layout::Line::contentLogicalWidth const): 23 (WebCore::Layout::Line::horizontalConstraint const): Deleted. 24 (WebCore::Layout::Line::availableWidth const): Deleted. 25 * layout/inlineformatting/InlineLineBuilder.cpp: 26 (WebCore::Layout::LineBuilder::layoutInlineContent): 27 (WebCore::Layout::LineBuilder::initialize): 28 (WebCore::Layout::LineBuilder::placeInlineContent): 29 (WebCore::Layout::LineBuilder::close): 30 (WebCore::Layout::LineBuilder::commitFloats): 31 (WebCore::Layout::LineBuilder::handleFloatsAndInlineContent): 32 (WebCore::Layout::LineBuilder::rebuildLine): 33 (WebCore::Layout::LineBuilder::rebuildLineForTrailingSoftHyphen): 34 * layout/inlineformatting/InlineLineBuilder.h: 35 (WebCore::Layout::LineBuilder::availableWidth const): 36 1 37 2020-11-20 Antti Koivisto <antti@apple.com> 2 38 -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp
r269299 r270114 57 57 } 58 58 59 void Line::initialize(InlineLayoutUnit horizontalConstraint) 60 { 61 m_horizontalConstraint = horizontalConstraint; 59 void Line::initialize() 60 { 62 61 m_contentLogicalWidth = { }; 63 62 m_runs.clear(); … … 68 67 } 69 68 70 void Line::removeCollapsibleContent( )69 void Line::removeCollapsibleContent(InlineLayoutUnit extraHorizontalSpace) 71 70 { 72 71 removeTrailingTrimmableContent(); 73 visuallyCollapsePreWrapOverflowContent( );74 } 75 76 void Line::applyRunExpansion( )72 visuallyCollapsePreWrapOverflowContent(extraHorizontalSpace); 73 } 74 75 void Line::applyRunExpansion(InlineLayoutUnit extraHorizontalSpace) 77 76 { 78 77 ASSERT(formattingContext().root().style().textAlign() == TextAlignMode::Justify); … … 98 97 } 99 98 // Anything to distribute? 100 if (!expansionOpportunityCount || ! availableWidth())99 if (!expansionOpportunityCount || !extraHorizontalSpace) 101 100 return; 102 101 // Distribute the extra space. 103 auto expansionToDistribute = availableWidth()/ expansionOpportunityCount;102 auto expansionToDistribute = extraHorizontalSpace / expansionOpportunityCount; 104 103 auto accumulatedExpansion = InlineLayoutUnit { }; 105 104 for (auto& run : m_runs) { … … 117 116 // Content grows as runs expand. 118 117 m_contentLogicalWidth += accumulatedExpansion; 119 ASSERT(m_contentLogicalWidth == m_horizontalConstraint);120 118 } 121 119 … … 134 132 }(); 135 133 136 if (m_runs.last().isLineBreak() && availableWidth() >= 0 &&!isTextAlignRight) {134 if (m_runs.last().isLineBreak() && !isTextAlignRight) { 137 135 m_trimmableTrailingContent.reset(); 138 136 return; … … 156 154 } 157 155 158 void Line::visuallyCollapsePreWrapOverflowContent( )156 void Line::visuallyCollapsePreWrapOverflowContent(InlineLayoutUnit extraHorizontalSpace) 159 157 { 160 158 ASSERT(m_trimmableTrailingContent.isEmpty()); … … 162 160 // ... 163 161 // It may also visually collapse the character advance widths of any that would otherwise overflow. 164 auto overflowWidth = - availableWidth();162 auto overflowWidth = -extraHorizontalSpace; 165 163 if (overflowWidth <= 0) 166 164 return; … … 201 199 ASSERT(delta > 0); 202 200 m_lineLogicalLeft += delta; 203 m_horizontalConstraint -= delta;204 }205 206 void Line::moveLogicalRight(InlineLayoutUnit delta)207 {208 ASSERT(delta > 0);209 m_horizontalConstraint -= delta;210 201 } 211 202 -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.h
r269299 r270114 43 43 ~Line(); 44 44 45 void initialize( InlineLayoutUnit horizontalConstraint);45 void initialize(); 46 46 47 47 void append(const InlineItem&, InlineLayoutUnit logicalWidth); … … 53 53 bool isConsideredEmpty() const { return m_isConsideredEmpty; } 54 54 55 InlineLayoutUnit horizontalConstraint() const { return m_horizontalConstraint; }56 55 InlineLayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; } 57 InlineLayoutUnit availableWidth() const { return horizontalConstraint() - contentLogicalWidth(); }58 56 59 57 InlineLayoutUnit trimmableTrailingWidth() const { return m_trimmableTrailingContent.width(); } … … 64 62 65 63 void moveLogicalLeft(InlineLayoutUnit); 66 void moveLogicalRight(InlineLayoutUnit); 67 68 void removeCollapsibleContent(); 69 void applyRunExpansion(); 64 65 void removeCollapsibleContent(InlineLayoutUnit extraHorizontalSpace); 66 void applyRunExpansion(InlineLayoutUnit extraHorizontalSpace); 70 67 71 68 struct Run { … … 151 148 152 149 void removeTrailingTrimmableContent(); 153 void visuallyCollapsePreWrapOverflowContent( );150 void visuallyCollapsePreWrapOverflowContent(InlineLayoutUnit extraHorizontalSpace); 154 151 155 152 bool isRunConsideredEmpty(const Run&) const; … … 183 180 TrimmableTrailingContent m_trimmableTrailingContent; 184 181 InlineLayoutUnit m_lineLogicalLeft { 0 }; 185 InlineLayoutUnit m_horizontalConstraint { 0 };186 182 InlineLayoutUnit m_contentLogicalWidth { 0 }; 187 183 Optional<InlineLayoutUnit> m_trailingSoftHyphenWidth { 0 }; -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp
r269299 r270114 263 263 } 264 264 265 LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength, const InlineRect& lineLogicalConstraints, bool isFirstLine)266 { 267 auto usedConstraints = constraintsForLine( lineLogicalConstraints, isFirstLine);265 LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength, const InlineRect& initialConstraintsForLine, bool isFirstLine) 266 { 267 auto usedConstraints = constraintsForLine(initialConstraintsForLine, isFirstLine); 268 268 initialize(usedConstraints); 269 269 … … 271 271 auto committedRange = close(needsLayoutRange, committedContent); 272 272 273 auto lineLogicalTopLeft = InlineLayoutPoint { usedConstraints.logicalLeft, lineLogicalConstraints.top() };273 auto lineLogicalTopLeft = InlineLayoutPoint { usedConstraints.logicalLeft, initialConstraintsForLine.top() }; 274 274 auto isLastLine = isLastLineWithInlineContent(committedRange, needsLayoutRange.end, committedContent.partialTrailingContentLength); 275 275 return LineContent { committedRange, committedContent.partialTrailingContentLength, m_floats, m_contentIsConstrainedByFloat 276 276 , lineLogicalTopLeft 277 , m_ line.horizontalConstraint()277 , m_horizontalSpaceForLine 278 278 , m_line.contentLogicalWidth() 279 279 , m_line.isConsideredEmpty() … … 296 296 m_wrapOpportunityList.clear(); 297 297 298 m_line.initialize( lineConstraints.availableLogicalWidth);298 m_line.initialize(); 299 299 m_contentIsConstrainedByFloat = lineConstraints.isConstrainedByFloat; 300 m_horizontalSpaceForLine = lineConstraints.logicalWidth; 300 301 } 301 302 … … 312 313 // 3. Check if the content fits the line and commit the content accordingly (full, partial or not commit at all). 313 314 // 4. Return if we are at the end of the line either by not being able to fit more content or because of an explicit line break. 314 nextContentForLine(lineCandidate, currentItemIndex, needsLayoutRange, partialLeadingContentLength, m_line.availableWidth() + m_line.trimmableTrailingWidth(), m_line.contentLogicalWidth());315 nextContentForLine(lineCandidate, currentItemIndex, needsLayoutRange, partialLeadingContentLength, availableWidth() + m_line.trimmableTrailingWidth(), m_line.contentLogicalWidth()); 315 316 // Now check if we can put this content on the current line. 316 317 auto result = handleFloatsAndInlineContent(inlineContentBreaker, needsLayoutRange, lineCandidate); … … 355 356 return lineRange; 356 357 } 357 m_line.removeCollapsibleContent( );358 m_line.removeCollapsibleContent(availableWidth()); 358 359 auto horizontalAlignment = root().style().textAlign(); 359 360 auto runsExpandHorizontally = horizontalAlignment == TextAlignMode::Justify && !isLastLineWithInlineContent(lineRange, needsLayoutRange.end, committedContent.partialTrailingContentLength); 360 361 if (runsExpandHorizontally) 361 m_line.applyRunExpansion( );362 m_line.applyRunExpansion(availableWidth()); 362 363 auto lineEndsWithHyphen = false; 363 364 if (!m_line.isConsideredEmpty()) { … … 572 573 } 573 574 if (leftIntrusiveFloatsWidth || rightIntrusiveFloatsWidth) { 574 if (leftIntrusiveFloatsWidth) 575 if (leftIntrusiveFloatsWidth) { 575 576 m_line.moveLogicalLeft(leftIntrusiveFloatsWidth); 577 m_horizontalSpaceForLine -= leftIntrusiveFloatsWidth; 578 } 576 579 if (rightIntrusiveFloatsWidth) 577 m_ line.moveLogicalRight(rightIntrusiveFloatsWidth);580 m_horizontalSpaceForLine -= rightIntrusiveFloatsWidth; 578 581 } 579 582 } … … 597 600 auto& floatContent = lineCandidate.floatContent; 598 601 // Check if this new content fits. 599 auto availableWidth = m_line.availableWidth() - floatContent.intrusiveWidth();602 auto availableWidth = this->availableWidth() - floatContent.intrusiveWidth(); 600 603 auto isLineConsideredEmpty = m_line.isConsideredEmpty() && !m_contentIsConstrainedByFloat; 601 604 auto lineStatus = InlineContentBreaker::LineStatus { availableWidth, m_line.trimmableTrailingWidth(), m_line.trailingSoftHyphenWidth(), m_line.isTrailingRunFullyTrimmable(), isLineConsideredEmpty }; … … 686 689 // We might already have added intrusive floats. They shrink the avilable horizontal space for the line. 687 690 // Let's just reuse what the line has at this point. 688 m_line.initialize( m_line.horizontalConstraint());691 m_line.initialize(); 689 692 auto currentItemIndex = layoutRange.start; 690 693 if (m_partialLeadingTextItem) { … … 714 717 auto trailingSoftHyphenWidth = m_line.trailingSoftHyphenWidth(); 715 718 // Check if the trailing hyphen now fits the line (or we don't need hyhen anymore). 716 if (!trailingSoftHyphenWidth || trailingSoftHyphenWidth <= m_line.availableWidth()) {719 if (!trailingSoftHyphenWidth || trailingSoftHyphenWidth <= availableWidth()) { 717 720 if (trailingSoftHyphenWidth) 718 721 m_line.addTrailingHyphen(*trailingSoftHyphenWidth); -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h
r269299 r270114 65 65 const Line::RunList& runs; 66 66 }; 67 LineContent layoutInlineContent(const InlineItemRange&, size_t partialLeadingContentLength, const InlineRect& initial LineConstraints, bool isFirstLine);67 LineContent layoutInlineContent(const InlineItemRange&, size_t partialLeadingContentLength, const InlineRect& initialConstraintsForLine, bool isFirstLine); 68 68 69 69 struct IntrinsicContent { … … 89 89 struct UsedConstraints { 90 90 InlineLayoutUnit logicalLeft { 0 }; 91 InlineLayoutUnit availableLogicalWidth { 0 };91 InlineLayoutUnit logicalWidth { 0 }; 92 92 bool isConstrainedByFloat { false }; 93 93 }; … … 108 108 InlineLayoutUnit inlineItemWidth(const InlineItem&, InlineLayoutUnit contentLogicalLeft) const; 109 109 bool isLastLineWithInlineContent(const InlineItemRange& lineRange, size_t lastInlineItemIndex, bool hasPartialTrailingContent) const; 110 InlineLayoutUnit availableWidth() const { return m_horizontalSpaceForLine - m_line.contentLogicalWidth(); } 110 111 111 112 const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; } … … 117 118 const ContainerBox& m_formattingContextRoot; 118 119 Line m_line; 120 InlineLayoutUnit m_horizontalSpaceForLine { 0 }; 119 121 const InlineItems& m_inlineItems; 120 122 LineContent::FloatList m_floats;
Note: See TracChangeset
for help on using the changeset viewer.