Changeset 256490 in webkit


Ignore:
Timestamp:
Feb 12, 2020 4:24:44 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] LineBuilder should be able to take a partial trailing inline text item
https://bugs.webkit.org/show_bug.cgi?id=207640
<rdar://problem/59390284>

Reviewed by Antti Koivisto.

With this patch, now the trailing run on the line has the needsHyphen bit set.
When constructing the final Display:Runs in InlineFormattingContext::setDisplayBoxesForLine using
the line runs, we transfer the needsHyphen bit instead of explicitly set on the trailing run.

  • layout/displaytree/DisplayRun.h:

(WebCore::Display::Run::TextContent::TextContent):

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):

  • layout/inlineformatting/InlineLineBuilder.cpp:

(WebCore::Layout::LineBuilder::appendPartialTrailingTextItem):
(WebCore::Layout::LineBuilder::appendTextContent):
(WebCore::Layout::m_textContent):
(WebCore::Layout::LineBuilder::Run::Run):

  • layout/inlineformatting/InlineLineBuilder.h:

(WebCore::Layout::LineBuilder::Run::setNeedsHyphen):

  • layout/inlineformatting/LineLayoutContext.cpp:

(WebCore::Layout::LineLayoutContext::close):
(WebCore::Layout::LineLayoutContext::tryAddingInlineItems):
(WebCore::Layout::LineLayoutContext::commitPartialContent):

  • layout/inlineformatting/LineLayoutContext.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r256487 r256490  
     12020-02-12  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] LineBuilder should be able to take a partial trailing inline text item
     4        https://bugs.webkit.org/show_bug.cgi?id=207640
     5        <rdar://problem/59390284>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        With this patch, now the trailing run on the line has the needsHyphen bit set.
     10        When constructing the final Display:Runs in InlineFormattingContext::setDisplayBoxesForLine using
     11        the line runs, we transfer the needsHyphen bit instead of explicitly set on the trailing run. 
     12
     13        * layout/displaytree/DisplayRun.h:
     14        (WebCore::Display::Run::TextContent::TextContent):
     15        * layout/inlineformatting/InlineFormattingContext.cpp:
     16        (WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
     17        * layout/inlineformatting/InlineLineBuilder.cpp:
     18        (WebCore::Layout::LineBuilder::appendPartialTrailingTextItem):
     19        (WebCore::Layout::LineBuilder::appendTextContent):
     20        (WebCore::Layout::m_textContent):
     21        (WebCore::Layout::LineBuilder::Run::Run):
     22        * layout/inlineformatting/InlineLineBuilder.h:
     23        (WebCore::Layout::LineBuilder::Run::setNeedsHyphen):
     24        * layout/inlineformatting/LineLayoutContext.cpp:
     25        (WebCore::Layout::LineLayoutContext::close):
     26        (WebCore::Layout::LineLayoutContext::tryAddingInlineItems):
     27        (WebCore::Layout::LineLayoutContext::commitPartialContent):
     28        * layout/inlineformatting/LineLayoutContext.h:
     29
    1302020-02-12  Basuke Suzuki  <basuke.suzuki@sony.com>
    231
  • trunk/Source/WebCore/layout/displaytree/DisplayRun.h

    r256458 r256490  
    4444        WTF_MAKE_STRUCT_FAST_ALLOCATED;
    4545    public:
    46         TextContent(unsigned position, unsigned length, const String&);
     46        TextContent(unsigned position, unsigned length, const String&, bool needsHyphen);
    4747
    4848        unsigned start() const { return m_start; }
     
    117117}
    118118
    119 inline Run::TextContent::TextContent(unsigned start, unsigned length, const String& contentString)
     119inline Run::TextContent::TextContent(unsigned start, unsigned length, const String& contentString, bool needsHyphen)
    120120    : m_start(start)
    121121    , m_length(length)
     122    , m_needsHyphen(needsHyphen)
    122123    , m_contentString(contentString)
    123124{
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r256466 r256490  
    455455    auto lineIndex = inlineContent.lineBoxes.size();
    456456    auto lineInkOverflow = lineBox.scrollableOverflow();
    457     Optional<unsigned> lastTextItemIndex;
    458457    // Compute box final geometry.
    459458    auto& lineRuns = lineContent.runList;
     
    487486            inlineContent.runs.append({ lineIndex, lineRun.layoutBox(), logicalRect, inkOverflow, lineRun.expansion(), lineRun.textContent() });
    488487        }
     488
     489        if (lineRun.isText())
     490            continue;
    489491
    490492        if (lineRun.isLineBreak()) {
     
    526528        }
    527529
    528         if (lineRun.isText()) {
    529             // Anonymous inline text boxes do not create display boxes.
    530             lastTextItemIndex = inlineContent.runs.size() - 1;
    531             continue;
    532         }
    533530        ASSERT_NOT_REACHED();
    534531    }
    535     // Make sure the trailing text run gets a hyphen when it needs one.
    536     if (lineContent.partialContent && lineContent.partialContent->trailingContentNeedsHyphen)
    537         inlineContent.runs[*lastTextItemIndex].textContent()->setNeedsHyphen();
    538532    // FIXME: This is where the logical to physical translate should happen.
    539533    auto& baseline = lineBox.baseline();
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp

    r256437 r256490  
    394394void LineBuilder::append(const InlineItem& inlineItem, InlineLayoutUnit logicalWidth)
    395395{
     396    appendWith(inlineItem, { logicalWidth, false });
     397}
     398
     399void LineBuilder::appendPartialTrailingTextItem(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalWidth, bool needsHyphen)
     400{
     401    appendWith(inlineTextItem, { logicalWidth, needsHyphen });
     402}
     403
     404void LineBuilder::appendWith(const InlineItem& inlineItem, const InlineRunDetails& inlineRunDetails)
     405{
    396406    if (inlineItem.isText())
    397         appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth);
     407        appendTextContent(downcast<InlineTextItem>(inlineItem), inlineRunDetails.logicalWidth, inlineRunDetails.needsHyphen);
    398408    else if (inlineItem.isLineBreak())
    399409        appendLineBreak(inlineItem);
    400410    else if (inlineItem.isContainerStart())
    401         appendInlineContainerStart(inlineItem, logicalWidth);
     411        appendInlineContainerStart(inlineItem, inlineRunDetails.logicalWidth);
    402412    else if (inlineItem.isContainerEnd())
    403         appendInlineContainerEnd(inlineItem, logicalWidth);
     413        appendInlineContainerEnd(inlineItem, inlineRunDetails.logicalWidth);
    404414    else if (inlineItem.layoutBox().isReplacedBox())
    405         appendReplacedInlineBox(inlineItem, logicalWidth);
     415        appendReplacedInlineBox(inlineItem, inlineRunDetails.logicalWidth);
    406416    else if (inlineItem.isBox())
    407         appendNonReplacedInlineBox(inlineItem, logicalWidth);
     417        appendNonReplacedInlineBox(inlineItem, inlineRunDetails.logicalWidth);
    408418    else
    409419        ASSERT_NOT_REACHED();
     
    440450}
    441451
    442 void LineBuilder::appendTextContent(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalWidth)
     452void LineBuilder::appendTextContent(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalWidth, bool needsHyphen)
    443453{
    444454    auto willCollapseCompletely = [&] {
     
    471481        auto& lastRun = m_runs.last();
    472482        inlineTextItemNeedsNewRun = lastRun.hasCollapsedTrailingWhitespace() || !lastRun.isText() || &lastRun.layoutBox() != &inlineTextItem.layoutBox();
    473         if (!inlineTextItemNeedsNewRun)
     483        if (!inlineTextItemNeedsNewRun) {
    474484            lastRun.expand(inlineTextItem, logicalWidth);
     485            if (needsHyphen) {
     486                ASSERT(!lastRun.textContent()->needsHyphen());
     487                lastRun.setNeedsHyphen();
     488            }
     489        }
    475490    }
    476491    if (inlineTextItemNeedsNewRun)
    477         m_runs.append({ inlineTextItem, contentLogicalWidth(), logicalWidth });
     492        m_runs.append({ inlineTextItem, contentLogicalWidth(), logicalWidth, needsHyphen });
    478493
    479494    m_lineBox.expandHorizontally(logicalWidth);
     
    751766    , m_layoutBox(&softLineBreakItem.layoutBox())
    752767    , m_logicalRect({ 0, logicalLeft, 0, 0 })
    753     , m_textContent({ softLineBreakItem.position(), 1, softLineBreakItem.inlineTextBox().content() })
    754 {
    755 }
    756 
    757 LineBuilder::Run::Run(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
     768    , m_textContent({ softLineBreakItem.position(), 1, softLineBreakItem.inlineTextBox().content(), false })
     769{
     770}
     771
     772LineBuilder::Run::Run(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth, bool needsHyphen)
    758773    : m_type(InlineItem::Type::Text)
    759774    , m_layoutBox(&inlineTextItem.layoutBox())
    760775    , m_logicalRect({ 0, logicalLeft, logicalWidth, 0 })
    761776    , m_trailingWhitespaceType(trailingWhitespaceType(inlineTextItem))
    762     , m_textContent({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length(), inlineTextItem.inlineTextBox().content() })
     777    , m_textContent({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length(), inlineTextItem.inlineTextBox().content(), needsHyphen })
    763778{
    764779    if (m_trailingWhitespaceType != TrailingWhitespace::None) {
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h

    r256437 r256490  
    6262    void initialize(const Constraints&);
    6363    void append(const InlineItem&, InlineLayoutUnit logicalWidth);
     64    void appendPartialTrailingTextItem(const InlineTextItem&, InlineLayoutUnit logicalWidth, bool needsHypen);
    6465    void resetContent();
    6566    bool isVisuallyEmpty() const { return m_lineBox.isConsideredEmpty(); }
     
    9495        friend class LineBuilder;
    9596
    96         Run(const InlineTextItem&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
     97        Run(const InlineTextItem&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth, bool needsHypen);
    9798        Run(const InlineSoftLineBreakItem&, InlineLayoutUnit logicalLeft);
    9899        Run(const InlineItem&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
     
    114115        void setComputedHorizontalExpansion(InlineLayoutUnit logicalExpansion);
    115116        void setExpansionBehavior(ExpansionBehavior);
     117
     118        void setNeedsHyphen() { m_textContent->setNeedsHyphen(); }
    116119
    117120        enum class TrailingWhitespace {
     
    162165    InlineLayoutUnit baselineOffset() const { return m_lineBox.baselineOffset(); }
    163166
     167    struct InlineRunDetails {
     168        InlineLayoutUnit logicalWidth { 0 };
     169        bool needsHyphen { false };
     170    };
     171    void appendWith(const InlineItem&, const InlineRunDetails&);
    164172    void appendNonBreakableSpace(const InlineItem&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
    165     void appendTextContent(const InlineTextItem&, InlineLayoutUnit logicalWidth);
     173    void appendTextContent(const InlineTextItem&, InlineLayoutUnit logicalWidth, bool needsHyphen);
    166174    void appendNonReplacedInlineBox(const InlineItem&, InlineLayoutUnit logicalWidth);
    167175    void appendReplacedInlineBox(const InlineItem&, InlineLayoutUnit logicalWidth);
  • trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp

    r256417 r256490  
    312312
    313313    // Adjust hyphenated line count.
    314     if (partialContent && partialContent->trailingContentNeedsHyphen)
     314    if (partialContent && partialContent->trailingContentHasHyphen)
    315315        ++m_successiveHyphenatedLineCount;
    316316    else
    317317        m_successiveHyphenatedLineCount = 0;
    318 
    319318    unsigned trailingInlineItemIndex = layoutRange.start + committedInlineItemCount - 1;
    320319    ASSERT(trailingInlineItemIndex < layoutRange.end);
     
    468467                ASSERT(!m_partialTrailingTextItem);
    469468                m_partialTrailingTextItem = trailingInlineTextItem.left(partialRun->length);
    470                 line.append(*m_partialTrailingTextItem, partialRun->logicalWidth);
     469                line.appendPartialTrailingTextItem(*m_partialTrailingTextItem, partialRun->logicalWidth, partialRun->needsHyphen);
    471470                return;
    472471            }
  • trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h

    r256417 r256490  
    4242    struct LineContent {
    4343        struct PartialContent {
    44             bool trailingContentNeedsHyphen { false };
     44            bool trailingContentHasHyphen { false };
    4545            unsigned overflowContentLength { 0 };
    4646        };
Note: See TracChangeset for help on using the changeset viewer.