⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285863 in webkit


Ignore:
Timestamp:
Nov 16, 2021, 8:38:52 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Fix fast/text/basic/005.html
https://bugs.webkit.org/show_bug.cgi?id=233150

Reviewed by Antti Koivisto.

Negative word-spacing acts as negative margin, pulling the content to the left. In this patch we account for such negative values when
computing the overall content width.

Note that this patch is in preparation for enabling IFC preferred width computation.

  • layout/formattingContexts/inline/InlineLine.cpp:

(WebCore::Layout::Line::appendTextContent):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285862 r285863  
     12021-11-16  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Fix fast/text/basic/005.html
     4        https://bugs.webkit.org/show_bug.cgi?id=233150
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Negative word-spacing acts as negative margin, pulling the content to the left. In this patch we account for such negative values when
     9        computing the overall content width.
     10
     11        Note that this patch is in preparation for enabling IFC preferred width computation.
     12
     13        * layout/formattingContexts/inline/InlineLine.cpp:
     14        (WebCore::Layout::Line::appendTextContent):
     15
    1162021-11-16  Wenson Hsieh  <wenson_hsieh@apple.com>
    217
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp

    r285826 r285863  
    344344        m_contentLogicalWidth = std::max(oldContentLogicalWidth, contentLogicalRight);
    345345    } else if (style.letterSpacing() >= 0) {
    346         m_runs.last().expand(inlineTextItem, logicalWidth);
    347         m_contentLogicalWidth += logicalWidth;
     346        auto& lastRun = m_runs.last();
     347        lastRun.expand(inlineTextItem, logicalWidth);
     348        // Ensure that property values that act like negative margin are not making the line wider.
     349        m_contentLogicalWidth = std::max(oldContentLogicalWidth, lastRun.logicalRight());
    348350    } else {
    349351        auto& lastRun = m_runs.last();
     
    351353        // Negative letter spacing should only shorten the content to the boundary of the previous run.
    352354        // FIXME: We may need to traverse all the way to the previous non-text run (or even across inline boxes).
    353         auto lastRunLogicalWidth = lastRun.logicalWidth();
    354         auto contentWidthWithoutLastTextRun = m_contentLogicalWidth - std::max(0.f, lastRunLogicalWidth);
     355        auto contentWidthWithoutLastTextRun = [&] {
     356            if (style.fontCascade().wordSpacing() >= 0)
     357                return m_contentLogicalWidth - std::max(0.f, lastRun.logicalWidth());
     358            // FIXME: Let's see if we need to optimize for this is the rare case of both letter and word spacing being negative.
     359            auto rightMostPosition = InlineLayoutUnit { };
     360            for (auto& run : makeReversedRange(m_runs))
     361                rightMostPosition = std::max(rightMostPosition, run.logicalRight());
     362            return std::max(0.f, rightMostPosition);
     363        }();
     364        auto lastRunLogicalRight = lastRun.logicalRight();
    355365        lastRun.expand(inlineTextItem, logicalWidth);
    356         m_contentLogicalWidth = std::max(contentWidthWithoutLastTextRun, lastRunLogicalWidth + logicalWidth);
     366        m_contentLogicalWidth = std::max(contentWidthWithoutLastTextRun, lastRunLogicalRight + logicalWidth);
    357367    }
    358368
Note: See TracChangeset for help on using the changeset viewer.