Changeset 252915 in webkit


Ignore:
Timestamp:
Nov 27, 2019 6:34:02 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Generate fewer InlineItems when new lines are not preserved
https://bugs.webkit.org/show_bug.cgi?id=204653
<rdar://problem/57510133>

Reviewed by Antti Koivisto.

This patch reduces the number of InlineItems by merging (non-preserved)new lines with neighboring whitespace characters.
[text\n\n text] -> [text][ ][text]

  • layout/inlineformatting/InlineTextItem.cpp:

(WebCore::Layout::isWhitespaceCharacter):
(WebCore::Layout::moveToNextNonWhitespacePosition):
(WebCore::Layout::InlineTextItem::createAndAppendTextItems):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252913 r252915  
     12019-11-27  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Generate fewer InlineItems when new lines are not preserved
     4        https://bugs.webkit.org/show_bug.cgi?id=204653
     5        <rdar://problem/57510133>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This patch reduces the number of InlineItems by merging (non-preserved)new lines with neighboring whitespace characters.
     10        [text\n\n text] -> [text][   ][text]
     11
     12        * layout/inlineformatting/InlineTextItem.cpp:
     13        (WebCore::Layout::isWhitespaceCharacter):
     14        (WebCore::Layout::moveToNextNonWhitespacePosition):
     15        (WebCore::Layout::InlineTextItem::createAndAppendTextItems):
     16
    1172019-11-27  Manuel Rego Casasnovas  <rego@igalia.com>
    218
  • trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp

    r252869 r252915  
    3535namespace Layout {
    3636
    37 static inline bool isWhitespaceCharacter(char character)
     37static inline bool isWhitespaceCharacter(char character, bool preserveNewline)
    3838{
    39     return character == ' ' || character == '\t';
     39    return character == ' ' || character == '\t' || (character == '\n' && !preserveNewline);
    4040}
    4141
    42 static unsigned moveToNextNonWhitespacePosition(const StringView& textContent, unsigned startPosition)
     42static unsigned moveToNextNonWhitespacePosition(const StringView& textContent, unsigned startPosition, bool preserveNewline)
    4343{
    4444    auto nextNonWhiteSpacePosition = startPosition;
    45     while (nextNonWhiteSpacePosition < textContent.length() && isWhitespaceCharacter(textContent[nextNonWhiteSpacePosition]))
     45    while (nextNonWhiteSpacePosition < textContent.length() && isWhitespaceCharacter(textContent[nextNonWhiteSpacePosition], preserveNewline))
    4646        ++nextNonWhiteSpacePosition;
    4747    return nextNonWhiteSpacePosition - startPosition;
     
    105105        };
    106106
    107         if (isSegmentBreakCandidate(text[currentPosition])) {
    108             // Segment breaks with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line) compute to forced line break. 
    109             inlineContent.append(style.preserveNewline() ? makeUnique<InlineItem>(inlineBox, Type::ForcedLineBreak)
    110                 : InlineTextItem::createSegmentBreakItem(inlineBox, currentPosition));
     107        // Segment breaks with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line) compute to forced line break.
     108        if (isSegmentBreakCandidate(text[currentPosition]) && style.preserveNewline()) {
     109            inlineContent.append(makeUnique<InlineItem>(inlineBox, Type::ForcedLineBreak));
    111110            ++currentPosition;
    112111            continue;
    113112        }
    114113
    115         if (isWhitespaceCharacter(text[currentPosition])) {
    116             auto length = moveToNextNonWhitespacePosition(text, currentPosition);
     114        if (isWhitespaceCharacter(text[currentPosition], style.preserveNewline())) {
     115            auto length = moveToNextNonWhitespacePosition(text, currentPosition, style.preserveNewline());
    117116            auto simpleSingleWhitespaceContent = textContext.canUseSimplifiedContentMeasuring && (length == 1 || style.collapseWhiteSpace());
    118117            auto width = simpleSingleWhitespaceContent ? makeOptional(LayoutUnit { font.spaceWidth() }) : inlineItemWidth(currentPosition, length);
Note: See TracChangeset for help on using the changeset viewer.