Changeset 251857 in webkit


Ignore:
Timestamp:
Oct 31, 2019 10:37:56 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Add expansion context to Line::Run
https://bugs.webkit.org/show_bug.cgi?id=203683
<rdar://problem/56785012>

Reviewed by Antti Koivisto.

This is in preparation for adding text-align: justify support.
The temporary Line::Run holds the number of expansion opportunities, while Display::Run holds both the expansion behavior and
the final expansion width.
The number of opportunities is used to compute the final expansion width for each run.

  • layout/displaytree/DisplayPainter.cpp:

(WebCore::Display::paintInlineContent):

  • layout/displaytree/DisplayRun.h:

(WebCore::Display::Run::TextContext::TextContext):
(WebCore::Display::Run::TextContext::setExpansion):
(WebCore::Display::Run::TextContext::expansion const):
(WebCore::Display::Run::TextContext::expansionBehavior const): Deleted.

  • layout/inlineformatting/InlineLine.h:

(WebCore::Layout::Line::Run::hasExpansionOpportunity const):
(WebCore::Layout::Line::Run::expansionOpportunityCount const):
(WebCore::Layout::Line::Run::expansionBehavior const):
(WebCore::Layout::Line::Run::setHasExpansionOpportunity):
(WebCore::Layout::Line::Run::setComputedHorizontalExpansion):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251851 r251857  
     12019-10-31  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add expansion context to Line::Run
     4        https://bugs.webkit.org/show_bug.cgi?id=203683
     5        <rdar://problem/56785012>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is in preparation for adding text-align: justify support.
     10        The temporary Line::Run holds the number of expansion opportunities, while Display::Run holds both the expansion behavior and
     11        the final expansion width.
     12        The number of opportunities is used to compute the final expansion width for each run.
     13
     14        * layout/displaytree/DisplayPainter.cpp:
     15        (WebCore::Display::paintInlineContent):
     16        * layout/displaytree/DisplayRun.h:
     17        (WebCore::Display::Run::TextContext::TextContext):
     18        (WebCore::Display::Run::TextContext::setExpansion):
     19        (WebCore::Display::Run::TextContext::expansion const):
     20        (WebCore::Display::Run::TextContext::expansionBehavior const): Deleted.
     21        * layout/inlineformatting/InlineLine.h:
     22        (WebCore::Layout::Line::Run::hasExpansionOpportunity const):
     23        (WebCore::Layout::Line::Run::expansionOpportunityCount const):
     24        (WebCore::Layout::Line::Run::expansionBehavior const):
     25        (WebCore::Layout::Line::Run::setHasExpansionOpportunity):
     26        (WebCore::Layout::Line::Run::setComputedHorizontalExpansion):
     27
    1282019-10-31  Zalan Bujtas  <zalan@apple.com>
    229
  • trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp

    r251844 r251857  
    127127            auto& lineBox = formattingState.lineBoxForRun(*run);
    128128            auto baselineOffset = rootAbsoluteDisplayBox.top() + lineBox.logicalTop() + lineBox.baselineOffset();
    129             context.drawText(style.fontCascade(),
    130                 TextRun { textContext->content(), logicalLeft, textContext->expansion().valueOr(0), textContext->expansionBehavior().valueOr(ForbidLeadingExpansion | ForbidTrailingExpansion)},
    131                 { logicalLeft, baselineOffset });
     129            if (auto expansionContext = textContext->expansion())
     130                context.drawText(style.fontCascade(), TextRun { textContext->content(), logicalLeft, expansionContext->horiztontalExpansion, expansionContext->behavior }, { logicalLeft, baselineOffset });
     131            else
     132                context.drawText(style.fontCascade(), TextRun { textContext->content(), logicalLeft }, { logicalLeft, baselineOffset });
    132133        } else if (auto* cachedImage = run->image()) {
    133134            auto runAbsoluteRect = FloatRect { rootAbsoluteDisplayBox.left() + run->logicalLeft(), rootAbsoluteDisplayBox.top() + run->logicalTop(), run->logicalWidth(), run->logicalHeight() };
  • trunk/Source/WebCore/layout/displaytree/DisplayRun.h

    r251844 r251857  
    4444        WTF_MAKE_STRUCT_FAST_ALLOCATED;
    4545    public:
    46         TextContext(unsigned position, unsigned length, String content, Optional<ExpansionBehavior> = { }, Optional<LayoutUnit> expansion = { });
     46        struct ExpansionContext;
     47        TextContext(unsigned position, unsigned length, String content, Optional<ExpansionContext> = { });
    4748
    4849        unsigned start() const { return m_start; }
     
    5152        String content() const { return m_content; }
    5253
    53         Optional<ExpansionBehavior> expansionBehavior() const { return m_expansionBehavior; }
    54         Optional<LayoutUnit> expansion() const { return m_expansion; }
     54        struct ExpansionContext {
     55            ExpansionBehavior behavior;
     56            LayoutUnit horiztontalExpansion;
     57        };
     58        void setExpansion(ExpansionContext expansionContext) { m_expansionContext = expansionContext; }
     59        Optional<ExpansionContext> expansion() const { return m_expansionContext; }
    5560
    5661        void expand(const TextContext& other);
     
    5964        unsigned m_start { 0 };
    6065        unsigned m_length { 0 };
    61         Optional<ExpansionBehavior> m_expansionBehavior;
    62         Optional<LayoutUnit> m_expansion;
     66        Optional<ExpansionContext> m_expansionContext;
    6367        // FIXME: This is temporary. We should have some mapping setup to identify associated text content instead.
    6468        String m_content;
     
    111115}
    112116
    113 inline Run::TextContext::TextContext(unsigned start, unsigned length, String content, Optional<ExpansionBehavior> expansionBehavior, Optional<LayoutUnit> expansion)
     117inline Run::TextContext::TextContext(unsigned start, unsigned length, String content, Optional<ExpansionContext> expansionContext)
    114118    : m_start(start)
    115119    , m_length(length)
    116     , m_expansionBehavior(expansionBehavior)
    117     , m_expansion(expansion)
     120    , m_expansionContext(expansionContext)
    118121    , m_content(content)
    119122{
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r251851 r251857  
    9494        void setCollapsesToZeroAdvanceWidth();
    9595
     96        void setHasExpansionOpportunity(ExpansionBehavior);
     97        bool hasExpansionOpportunity() const { return m_expansionOpportunityCount.hasValue(); }
     98        Optional<ExpansionBehavior> expansionBehavior() const;
     99        Optional<unsigned> expansionOpportunityCount() const { return m_expansionOpportunityCount; }
     100        void setComputedHorizontalExpansion(LayoutUnit logicalExpansion);
     101
    96102        bool isCollapsible() const { return m_isCollapsible; }
    97103        bool hasTrailingCollapsedContent() const { return m_hasTrailingCollapsedContent; }
     
    106112        bool m_collapsedToZeroAdvanceWidth { false };
    107113        bool m_hasTrailingCollapsedContent { false };
     114        Optional<unsigned> m_expansionOpportunityCount;
    108115    };
    109116    using RunList = Vector<std::unique_ptr<Run>>;
     
    191198}
    192199
     200inline Optional<ExpansionBehavior> Line::Run::expansionBehavior() const
     201{
     202    ASSERT(isText());
     203    if (auto expansionContext = m_displayRun.textContext()->expansion())
     204        return expansionContext->behavior;
     205    return { };
     206}
     207
     208inline void Line::Run::setHasExpansionOpportunity(ExpansionBehavior expansionBehavior)
     209{
     210    ASSERT(isText());
     211    ASSERT(!hasExpansionOpportunity());
     212    m_expansionOpportunityCount = 1;
     213    m_displayRun.textContext()->setExpansion({ expansionBehavior, { } });
     214}
     215
     216inline void Line::Run::setComputedHorizontalExpansion(LayoutUnit logicalExpansion)
     217{
     218    ASSERT(isText());
     219    ASSERT(hasExpansionOpportunity());
     220    ASSERT(m_displayRun.textContext()->expansion());
     221    m_displayRun.expandHorizontally(logicalExpansion);
     222    m_displayRun.textContext()->setExpansion({ m_displayRun.textContext()->expansion()->behavior, logicalExpansion });
     223}
     224
    193225}
    194226}
Note: See TracChangeset for help on using the changeset viewer.