Changeset 234048 in webkit


Ignore:
Timestamp:
Jul 20, 2018 10:05:16 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC][Inline formatting context] Add basic text content handling.
https://bugs.webkit.org/show_bug.cgi?id=187860

Reviewed by Antti Koivisto.

InlineFormattingContext::layout() walks through the formatting root's descendant list in a post-order fashion and
feeds the TextContentProvider.
Eventually this would turn into a more generic loop where we stop and process the text content when finding a non-text content box (float, inline-box etc), but right now
this is about text content only.

  • layout/displaytree/DisplayBox.h:

(WebCore::Display::Box::contentBoxBottom const):
(WebCore::Display::Box::contentBoxRight const):

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::layout const):

  • layout/inlineformatting/textlayout/TextContentProvider.cpp:

(WebCore::Layout::TextContentProvider::textRuns): Add a helper function to support the case when all we need is just the run list in one go.

  • layout/inlineformatting/textlayout/TextContentProvider.h:
  • layout/layouttree/LayoutBox.cpp:

(WebCore::Layout::Box::isDescendantOf const):

  • layout/layouttree/LayoutBox.h:
  • layout/layouttree/LayoutInlineBox.h:

(WebCore::Layout::InlineBox::textContent const):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r234045 r234048  
     12018-07-20  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][Inline formatting context] Add basic text content handling.
     4        https://bugs.webkit.org/show_bug.cgi?id=187860
     5
     6        Reviewed by Antti Koivisto.
     7
     8        InlineFormattingContext::layout() walks through the formatting root's descendant list in a post-order fashion and
     9        feeds the TextContentProvider.
     10        Eventually this would turn into a more generic loop where we stop and process the text content when finding a non-text content box (float, inline-box etc), but right now
     11        this is about text content only.
     12
     13        * layout/displaytree/DisplayBox.h:
     14        (WebCore::Display::Box::contentBoxBottom const):
     15        (WebCore::Display::Box::contentBoxRight const):
     16        * layout/inlineformatting/InlineFormattingContext.cpp:
     17        (WebCore::Layout::InlineFormattingContext::layout const):
     18        * layout/inlineformatting/textlayout/TextContentProvider.cpp:
     19        (WebCore::Layout::TextContentProvider::textRuns): Add a helper function to support the case when all we need is just the run list in one go.
     20        * layout/inlineformatting/textlayout/TextContentProvider.h:
     21        * layout/layouttree/LayoutBox.cpp:
     22        (WebCore::Layout::Box::isDescendantOf const):
     23        * layout/layouttree/LayoutBox.h:
     24        * layout/layouttree/LayoutInlineBox.h:
     25        (WebCore::Layout::InlineBox::textContent const):
     26
    1272018-07-20  Youenn Fablet  <youenn@apple.com>
    228
  • trunk/Source/WebCore/layout/displaytree/DisplayBox.h

    r233350 r234048  
    147147    LayoutUnit contentBoxTop() const { return borderTop() + paddingTop(); }
    148148    LayoutUnit contentBoxLeft() const { return borderLeft() + paddingLeft(); }
     149    LayoutUnit contentBoxBottom() const { return contentBoxTop() + contentBoxHeight(); }
     150    LayoutUnit contentBoxRight() const { return contentBoxLeft() + contentBoxWidth(); }
    149151    LayoutUnit contentBoxHeight() const;
    150152    LayoutUnit contentBoxWidth() const;
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r233469 r234048  
    3232#include "InlineFormattingState.h"
    3333#include "LayoutBox.h"
     34#include "LayoutContainer.h"
    3435#include "LayoutContext.h"
     36#include "LayoutInlineBox.h"
     37#include "LayoutInlineContainer.h"
     38#include "Logging.h"
     39#include "SimpleLineBreaker.h"
     40#include "TextContentProvider.h"
    3541#include <wtf/IsoMallocInlines.h>
     42#include <wtf/text/TextStream.h>
    3643
    3744namespace WebCore {
     
    4552}
    4653
    47 void InlineFormattingContext::layout(LayoutContext&, FormattingState&) const
     54void InlineFormattingContext::layout(LayoutContext& layoutContext, FormattingState&) const
    4855{
     56    if (!is<Container>(root()))
     57        return;
     58
     59    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
     60
     61    TextContentProvider textContentProvider;
     62    auto& formattingRoot = downcast<Container>(root());
     63    auto* layoutBox = formattingRoot.firstInFlowOrFloatingChild();
     64    // Casually walk through the block's descendants and place the inline boxes one after the other as much as we can (yeah, I am looking at you floats).
     65    while (layoutBox) {
     66        if (is<Container>(layoutBox)) {
     67            ASSERT(is<InlineContainer>(layoutBox));
     68            layoutBox = downcast<Container>(*layoutBox).firstInFlowOrFloatingChild();
     69            continue;
     70        }
     71        auto& inlineBox = downcast<InlineBox>(*layoutBox);
     72        // Only text content at this point.
     73        if (inlineBox.textContent())
     74            textContentProvider.appendText(*inlineBox.textContent(), inlineBox.style(), true);
     75
     76        for (; layoutBox; layoutBox = layoutBox->containingBlock()) {
     77            if (layoutBox == &formattingRoot) {
     78                layoutBox = nullptr;
     79                break;
     80            }
     81            if (auto* nextSibling = layoutBox->nextInFlowOrFloatingSibling()) {
     82                layoutBox = nextSibling;
     83                break;
     84            }
     85        }
     86        ASSERT(!layoutBox || layoutBox->isDescendantOf(formattingRoot));
     87    }
     88
     89    auto& formattingRootDisplayBox = *layoutContext.displayBoxForLayoutBox(formattingRoot);
     90    auto lineLeft = formattingRootDisplayBox.contentBoxLeft();
     91    auto lineRight = formattingRootDisplayBox.contentBoxRight();
     92
     93    auto textRuns = textContentProvider.textRuns();
     94    SimpleLineBreaker::LineConstraintList constraints;
     95    constraints.append({ { }, lineLeft, lineRight });
     96    SimpleLineBreaker simpleLineBreaker(textRuns, textContentProvider, WTFMove(constraints), formattingRoot.style());
     97    auto layoutRuns = simpleLineBreaker.runs();
     98
     99    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
    49100}
    50101
  • trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.cpp

    r234000 r234048  
    210210}
    211211
     212TextContentProvider::TextRunList TextContentProvider::textRuns()
     213{
     214    TextRunList textRunList;
     215
     216    auto textRunIterator = iterator();
     217    while (auto textRum = textRunIterator.current()) {
     218        textRunList.append(*textRum);
     219        ++textRunIterator;
     220    }
     221    return textRunList;
     222}
     223
    212224void TextContentProvider::findNextRun()
    213225{
  • trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.h

    r234000 r234048  
    9090        TextContentProvider& m_contentProvider;
    9191    };
     92    Iterator iterator();
    9293
    93     Iterator iterator();
     94    using TextRunList = Vector<TextRun>;
     95    TextRunList textRuns();
    9496
    9597private:
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp

    r233201 r234048  
    142142}
    143143
    144 bool Box::isDescendantOf(Container& container) const
     144bool Box::isDescendantOf(const Container& container) const
    145145{
    146146    for (auto* ancestor = containingBlock(); ancestor; ancestor = ancestor->containingBlock()) {
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r233201 r234048  
    6565    const Container* containingBlock() const;
    6666    const Container& formattingContextRoot() const;
    67     bool isDescendantOf(Container&) const;
     67    bool isDescendantOf(const Container&) const;
    6868
    6969    bool isAnonymous() const { return !m_elementAttributes; }
  • trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h

    r233482 r234048  
    4343
    4444    void setTextContent(String text) { m_textContent = text; }
     45    std::optional<String> textContent() const { return m_textContent; }
    4546
    4647private:
    47     String m_textContent;
     48    std::optional<String> m_textContent;
    4849};
    4950
Note: See TracChangeset for help on using the changeset viewer.