- Revision
- 234048
- Author
- [email protected]
- Date
- 2018-07-20 10:05:16 -0700 (Fri, 20 Jul 2018)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (234047 => 234048)
--- trunk/Source/WebCore/ChangeLog 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/ChangeLog 2018-07-20 17:05:16 UTC (rev 234048)
@@ -1,3 +1,29 @@
+2018-07-20 Zalan Bujtas <[email protected]>
+
+ [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):
+
2018-07-20 Youenn Fablet <[email protected]>
FetchResponse should close its stream when loading finishes
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (234047 => 234048)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-07-20 17:05:16 UTC (rev 234048)
@@ -146,6 +146,8 @@
LayoutUnit contentBoxTop() const { return borderTop() + paddingTop(); }
LayoutUnit contentBoxLeft() const { return borderLeft() + paddingLeft(); }
+ LayoutUnit contentBoxBottom() const { return contentBoxTop() + contentBoxHeight(); }
+ LayoutUnit contentBoxRight() const { return contentBoxLeft() + contentBoxWidth(); }
LayoutUnit contentBoxHeight() const;
LayoutUnit contentBoxWidth() const;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (234047 => 234048)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2018-07-20 17:05:16 UTC (rev 234048)
@@ -31,8 +31,15 @@
#include "FloatingState.h"
#include "InlineFormattingState.h"
#include "LayoutBox.h"
+#include "LayoutContainer.h"
#include "LayoutContext.h"
+#include "LayoutInlineBox.h"
+#include "LayoutInlineContainer.h"
+#include "Logging.h"
+#include "SimpleLineBreaker.h"
+#include "TextContentProvider.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/TextStream.h>
namespace WebCore {
namespace Layout {
@@ -44,8 +51,52 @@
{
}
-void InlineFormattingContext::layout(LayoutContext&, FormattingState&) const
+void InlineFormattingContext::layout(LayoutContext& layoutContext, FormattingState&) const
{
+ if (!is<Container>(root()))
+ return;
+
+ LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
+
+ TextContentProvider textContentProvider;
+ auto& formattingRoot = downcast<Container>(root());
+ auto* layoutBox = formattingRoot.firstInFlowOrFloatingChild();
+ // 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).
+ while (layoutBox) {
+ if (is<Container>(layoutBox)) {
+ ASSERT(is<InlineContainer>(layoutBox));
+ layoutBox = downcast<Container>(*layoutBox).firstInFlowOrFloatingChild();
+ continue;
+ }
+ auto& inlineBox = downcast<InlineBox>(*layoutBox);
+ // Only text content at this point.
+ if (inlineBox.textContent())
+ textContentProvider.appendText(*inlineBox.textContent(), inlineBox.style(), true);
+
+ for (; layoutBox; layoutBox = layoutBox->containingBlock()) {
+ if (layoutBox == &formattingRoot) {
+ layoutBox = nullptr;
+ break;
+ }
+ if (auto* nextSibling = layoutBox->nextInFlowOrFloatingSibling()) {
+ layoutBox = nextSibling;
+ break;
+ }
+ }
+ ASSERT(!layoutBox || layoutBox->isDescendantOf(formattingRoot));
+ }
+
+ auto& formattingRootDisplayBox = *layoutContext.displayBoxForLayoutBox(formattingRoot);
+ auto lineLeft = formattingRootDisplayBox.contentBoxLeft();
+ auto lineRight = formattingRootDisplayBox.contentBoxRight();
+
+ auto textRuns = textContentProvider.textRuns();
+ SimpleLineBreaker::LineConstraintList constraints;
+ constraints.append({ { }, lineLeft, lineRight });
+ SimpleLineBreaker simpleLineBreaker(textRuns, textContentProvider, WTFMove(constraints), formattingRoot.style());
+ auto layoutRuns = simpleLineBreaker.runs();
+
+ LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
}
std::unique_ptr<FormattingState> InlineFormattingContext::createFormattingState(Ref<FloatingState>&& floatingState, const LayoutContext& layoutContext) const
Modified: trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.cpp (234047 => 234048)
--- trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.cpp 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.cpp 2018-07-20 17:05:16 UTC (rev 234048)
@@ -209,6 +209,18 @@
return Iterator(*this);
}
+TextContentProvider::TextRunList TextContentProvider::textRuns()
+{
+ TextRunList textRunList;
+
+ auto textRunIterator = iterator();
+ while (auto textRum = textRunIterator.current()) {
+ textRunList.append(*textRum);
+ ++textRunIterator;
+ }
+ return textRunList;
+}
+
void TextContentProvider::findNextRun()
{
m_simpleTextRunGenerator->findNextRun();
Modified: trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.h (234047 => 234048)
--- trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.h 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/inlineformatting/textlayout/TextContentProvider.h 2018-07-20 17:05:16 UTC (rev 234048)
@@ -89,9 +89,11 @@
TextContentProvider& m_contentProvider;
};
-
Iterator iterator();
+ using TextRunList = Vector<TextRun>;
+ TextRunList textRuns();
+
private:
friend class Iterator;
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (234047 => 234048)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-07-20 17:05:16 UTC (rev 234048)
@@ -141,7 +141,7 @@
RELEASE_ASSERT_NOT_REACHED();
}
-bool Box::isDescendantOf(Container& container) const
+bool Box::isDescendantOf(const Container& container) const
{
for (auto* ancestor = containingBlock(); ancestor; ancestor = ancestor->containingBlock()) {
if (ancestor == &container)
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (234047 => 234048)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-07-20 17:05:16 UTC (rev 234048)
@@ -64,7 +64,7 @@
const Container* containingBlock() const;
const Container& formattingContextRoot() const;
- bool isDescendantOf(Container&) const;
+ bool isDescendantOf(const Container&) const;
bool isAnonymous() const { return !m_elementAttributes; }
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h (234047 => 234048)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h 2018-07-20 17:01:30 UTC (rev 234047)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h 2018-07-20 17:05:16 UTC (rev 234048)
@@ -42,9 +42,10 @@
InlineBox(std::optional<ElementAttributes>, RenderStyle&&);
void setTextContent(String text) { m_textContent = text; }
+ std::optional<String> textContent() const { return m_textContent; }
private:
- String m_textContent;
+ std::optional<String> m_textContent;
};
}