Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3e4e20f5b35f660ea1e3442dfcf8f7cd4724b9ec
      
https://github.com/WebKit/WebKit/commit/3e4e20f5b35f660ea1e3442dfcf8f7cd4724b9ec
  Author: Nathan Solomon <[email protected]>
  Date:   2026-08-10 (Mon, 10 Aug 2026)

  Changed paths:
    M Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp
    M Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.h
    M Source/WebCore/layout/formattingContexts/inline/IntrinsicWidthHandler.cpp
    M Source/WebCore/layout/formattingContexts/inline/IntrinsicWidthHandler.h
    M 
Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.cpp
    M 
Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.h
    M Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp
    M Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h

  Log Message:
  -----------
  Compute minimum content size for break-spaces text without running line layout
https://bugs.webkit.org/show_bug.cgi?id=320489
rdar://183456012

Reviewed by Alan Baradlay.

The minimum content size of an inline formatting context is the width of its 
widest
unbreakable piece of content, which for ordinary text is the widest word. We 
obtained it
by running a real line layout with an available width of zero, which forces one 
line per
unbreakable piece, so the line builder ran once per word and each call produced 
a full
line layout result the loop reduced to a width. Maximum content size goes 
through that
same loop with an infinite available width and lays out one line per forced 
break. The
cost difference between the two is therefore the number of lines laid out, and 
profiling
shows the minimum costing much more than the maximum.

We can skip the layout because at an available width of zero the line builder 
puts exactly
one unbreakable piece on each line, so the width the loop reads off the line is 
just that
piece's width. Building the inline item list already split the text at each 
position the
line break iterator reported and stored a width on each item, where it can. A 
piece's
width is the sum of its item widths, so laying out a line to obtain it is 
unnecessary.

Scope this optimization to content whose root style has white-space: 
break-spaces.
break-spaces keeps every space, so a piece is a word plus the space after it. 
It also
preserves spaces and tabs, which leaves no item fully trimmable so a line has 
nothing to
trim, and trailing whitespace only hangs under 'preserve', so it has nothing to 
hang
either. With both of those empty the width a line arrives at is the sum of the 
item widths
it was handed.

Add a fast path that traverses the inline item list, summing item widths and 
closing a
piece at each wrap opportunity. The fast path is only worth trusting if it 
agrees with the
line builder, so it calls the same wrap opportunity test the builder uses.
Early return from this optimization if it is possible we can break within an
item.

* Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp:
(WebCore::Layout::InlineContentBreaker::wordBreakBehavior const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.h:
(WebCore::Layout::InlineContentBreaker::wordBreakBehavior const):
* Source/WebCore/layout/formattingContexts/inline/IntrinsicWidthHandler.cpp:
(WebCore::Layout::IntrinsicWidthHandler::minimumContentSizeForBreakSpaces):
(WebCore::Layout::IntrinsicWidthHandler::lineBuilderMinimumContentSize):
(WebCore::Layout::IntrinsicWidthHandler::minimumContentSize):
(WebCore::Layout::IntrinsicWidthHandler::computedIntrinsicWidthForConstraint):
* Source/WebCore/layout/formattingContexts/inline/IntrinsicWidthHandler.h:
* Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.cpp:
(WebCore::Layout::TextOnlySimpleLineBuilder::measuredInlineTextItem):
(WebCore::Layout::TextOnlySimpleLineBuilder::isAtContentEnd):
(WebCore::Layout::TextOnlySimpleLineBuilder::isAtSoftWrapOpportunityOrContentEnd):
(WebCore::Layout::TextOnlySimpleLineBuilder::placeInlineTextContent):
(WebCore::Layout::measuredInlineTextItem): Deleted.
* Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.h:
* Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::wordBreakBehavior):
* Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h:

Canonical link: https://commits.webkit.org/318914@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to