Skip to content
Permalink
Browse files
[LFC][IFC] Do not generate integration runs out of IFC's display runs
https://bugs.webkit.org/show_bug.cgi?id=229719

Reviewed by Antti Koivisto.

Integration runs and IFC display runs hold the exact same set of data, so let's not duplicate then for the integration layer.

* WebCore.xcodeproj/project.pbxproj:
* display/css/DisplayTextBox.cpp:
(WebCore::Display::TextBox::debugDescription const):
* layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::build):
(WebCore::Layout::InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineSpanningInlineBoxes):
* layout/formattingContexts/inline/InlineLineRun.h:
(WebCore::Layout::Run::Text::originalContent const):
(WebCore::Layout::Run::Text::renderedContent const):
(WebCore::Layout::Run::setVerticalPositionIntegral):
* layout/formattingContexts/inline/InlineRect.h:
(WebCore::Layout::InlineRect::InlineRect):
* layout/integration/LayoutIntegrationInlineContent.h:
* layout/integration/LayoutIntegrationInlineContentBuilder.cpp:
(WebCore::LayoutIntegration::InlineContentBuilder::build const):
(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayRuns const):
(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLines const):
* layout/integration/LayoutIntegrationInlineContentBuilder.h:
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::paintTextRunUsingPhysicalCoordinates):
* layout/integration/LayoutIntegrationPagination.cpp:
(WebCore::LayoutIntegration::makeAdjustedContent):
* layout/integration/LayoutIntegrationRun.h: Removed.
* rendering/TextPainter.cpp:


Canonical link: https://commits.webkit.org/241218@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281905 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed Sep 2, 2021
1 parent 20d2744 commit 087aa2948ac8e8b309fdce171c03cab1decd6fff
Showing 15 changed files with 94 additions and 171 deletions.
@@ -1,3 +1,37 @@
2021-09-01 Alan Bujtas <zalan@apple.com>

[LFC][IFC] Do not generate integration runs out of IFC's display runs
https://bugs.webkit.org/show_bug.cgi?id=229719

Reviewed by Antti Koivisto.

Integration runs and IFC display runs hold the exact same set of data, so let's not duplicate then for the integration layer.

* WebCore.xcodeproj/project.pbxproj:
* display/css/DisplayTextBox.cpp:
(WebCore::Display::TextBox::debugDescription const):
* layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::build):
(WebCore::Layout::InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineSpanningInlineBoxes):
* layout/formattingContexts/inline/InlineLineRun.h:
(WebCore::Layout::Run::Text::originalContent const):
(WebCore::Layout::Run::Text::renderedContent const):
(WebCore::Layout::Run::setVerticalPositionIntegral):
* layout/formattingContexts/inline/InlineRect.h:
(WebCore::Layout::InlineRect::InlineRect):
* layout/integration/LayoutIntegrationInlineContent.h:
* layout/integration/LayoutIntegrationInlineContentBuilder.cpp:
(WebCore::LayoutIntegration::InlineContentBuilder::build const):
(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayRuns const):
(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLines const):
* layout/integration/LayoutIntegrationInlineContentBuilder.h:
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::paintTextRunUsingPhysicalCoordinates):
* layout/integration/LayoutIntegrationPagination.cpp:
(WebCore::LayoutIntegration::makeAdjustedContent):
* layout/integration/LayoutIntegrationRun.h: Removed.
* rendering/TextPainter.cpp:

2021-09-01 Marcos Caceres <marcos@marcosc.com>

Add "payment" permissions policy
@@ -768,14 +768,14 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
layout/LayoutUnits.h
layout/MarginTypes.h

layout/formattingContexts/inline/InlineLineRun.h
layout/formattingContexts/inline/InlineRect.h

layout/integration/LayoutIntegrationInlineContent.h
layout/integration/LayoutIntegrationLine.h
layout/integration/LayoutIntegrationLineIterator.h
layout/integration/LayoutIntegrationLineIteratorLegacyPath.h
layout/integration/LayoutIntegrationLineIteratorModernPath.h
layout/integration/LayoutIntegrationRun.h
layout/integration/LayoutIntegrationRunIterator.h
layout/integration/LayoutIntegrationRunIteratorLegacyPath.h
layout/integration/LayoutIntegrationRunIteratorModernPath.h
@@ -2176,7 +2176,6 @@
6FB7D2DE250FD82E000207AA /* FlexFormattingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB7D2DA250FD7FC000207AA /* FlexFormattingState.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FC3F9472516756700A49BEA /* InlineLineRun.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FC3F9452516756600A49BEA /* InlineLineRun.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FCBDB97265DF2C80021EA7B /* LayoutContainingBlockChainIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCBDB95265DF2C70021EA7B /* LayoutContainingBlockChainIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FCE1A1A22618ABD004F0343 /* LayoutIntegrationRun.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCE1A1822618AB3004F0343 /* LayoutIntegrationRun.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FD09543251115220098877D /* LayoutGeometryRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FD09541251115220098877D /* LayoutGeometryRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FE198172178397C00446F08 /* InlineContentBreaker.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FE198152178397C00446F08 /* InlineContentBreaker.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FE636E82647962900F0951E /* InlineFormattingQuirks.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FE636E72647962900F0951E /* InlineFormattingQuirks.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10060,7 +10059,6 @@
6FC5CA9522E3599400B13E11 /* TableFormattingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableFormattingContext.h; sourceTree = "<group>"; };
6FC5CA9622E3599500B13E11 /* TableFormattingState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableFormattingState.h; sourceTree = "<group>"; };
6FCBDB95265DF2C70021EA7B /* LayoutContainingBlockChainIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutContainingBlockChainIterator.h; sourceTree = "<group>"; };
6FCE1A1822618AB3004F0343 /* LayoutIntegrationRun.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutIntegrationRun.h; sourceTree = "<group>"; };
6FD09541251115220098877D /* LayoutGeometryRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutGeometryRect.h; sourceTree = "<group>"; };
6FE198132178397B00446F08 /* InlineContentBreaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineContentBreaker.cpp; sourceTree = "<group>"; };
6FE198152178397C00446F08 /* InlineContentBreaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineContentBreaker.h; sourceTree = "<group>"; };
@@ -29070,7 +29068,6 @@
E4ABABDB236088FD00FA4345 /* LayoutIntegrationLineLayout.h */,
E4312AB524B3265600678349 /* LayoutIntegrationPagination.cpp */,
E4312AB724B3265600678349 /* LayoutIntegrationPagination.h */,
6FCE1A1822618AB3004F0343 /* LayoutIntegrationRun.h */,
E4A664C72521B779007081DC /* LayoutIntegrationRunIterator.cpp */,
E4A664C62521B778007081DC /* LayoutIntegrationRunIterator.h */,
E4A664C52521B778007081DC /* LayoutIntegrationRunIteratorLegacyPath.h */,
@@ -33521,7 +33518,6 @@
E4D33F46252C50FC00837D05 /* LayoutIntegrationLineIteratorModernPath.h in Headers */,
E4ABABDD236088FE00FA4345 /* LayoutIntegrationLineLayout.h in Headers */,
E403B7A3251B11C10019E800 /* LayoutIntegrationPagination.h in Headers */,
6FCE1A1A22618ABD004F0343 /* LayoutIntegrationRun.h in Headers */,
E4A664CC2521D4AF007081DC /* LayoutIntegrationRunIterator.h in Headers */,
E4A664CF2521D4E2007081DC /* LayoutIntegrationRunIteratorLegacyPath.h in Headers */,
E4A664CE2521D4C9007081DC /* LayoutIntegrationRunIteratorModernPath.h in Headers */,
@@ -80,7 +80,7 @@ void BoxPainter::paintBoxContent(const Box& box, PaintingContext& paintingContex
auto baseline = textRect.y() + style.fontMetrics().ascent();
auto expansion = textBox.expansion();

auto textRun = TextRun { textBox.text().originalContent().substring(textBox.text().start(), textBox.text().length()), textRect.x(), expansion.horizontalExpansion, expansion.behavior };
auto textRun = TextRun { textBox.text().originalContent(), textRect.x(), expansion.horizontalExpansion, expansion.behavior };
textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
paintingContext.context.drawText(style.fontCascade(), textRun, { textRect.x(), baseline });
return;
@@ -53,7 +53,7 @@ String TextBox::debugDescription() const
TextStream stream;

stream << boxName() << " " << absoluteBoxRect() << " (" << this << ")";
auto textContent = text().originalContent().substring(text().start(), text().length());
auto textContent = text().originalContent().substring(text().start(), text().length()).toString();
textContent.replaceWithLiteral('\\', "\\\\");
textContent.replaceWithLiteral('\n', "\\n");
const size_t maxPrintedLength = 80;
@@ -36,6 +36,7 @@
namespace WebCore {
namespace Layout {

#define ALLOW_ROOT_AND_LINE_SPANNING_INLINE_BOX 0

InlineDisplayContentBuilder::InlineDisplayContentBuilder(const ContainerBox& formattingContextRoot, InlineFormattingState& formattingState)
: m_formattingContextRoot(formattingContextRoot)
@@ -47,11 +48,12 @@ InlineDisplayContentBuilder::InlineDisplayContentBuilder(const ContainerBox& for
void InlineDisplayContentBuilder::build(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, const size_t lineIndex)
{
auto& formattingState = this->formattingState();
#if ALLOW_ROOT_AND_LINE_SPANNING_INLINE_BOX
// Every line starts with a root run, even the empty ones.
auto rootInlineBoxRect = lineBox.logicalRectForRootInlineBox();
rootInlineBoxRect.moveBy(lineBoxLogicalTopLeft);
formattingState.addRun({ lineIndex, Run::Type::RootInlineBox, root(), rootInlineBoxRect, rootInlineBoxRect, { }, { }, lineBox.rootInlineBox().hasContent()});

#endif
// Spanning inline boxes start at the very beginning of the line.
auto lineSpanningInlineBoxIndex = formattingState.runs().size();
createRunsAndUpdateGeometryForLineContent(lineContent, lineBox, lineBoxLogicalTopLeft, lineIndex);
@@ -181,7 +183,7 @@ void InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineContent(cons
formattingState.lines().last().setNeedsIntegralPosition(lineNeedIntegralPosition);
}

void InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineSpanningInlineBoxes(const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, const size_t lineIndex, size_t lineSpanningInlineBoxIndex)
void InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineSpanningInlineBoxes(const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, const size_t /*lineIndex*/, size_t /*lineSpanningInlineBoxIndex*/)
{
if (!lineBox.hasContent()) {
// When a spanning inline box (e.g. <div>text<span><br></span></div>) lands on an empty line
@@ -202,8 +204,9 @@ void InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineSpanningInli
auto inlineBoxBorderBox = lineBox.logicalBorderBoxForInlineBox(layoutBox, boxGeometry);
inlineBoxBorderBox.moveBy(lineBoxLogicalTopLeft);

#if ALLOW_ROOT_AND_LINE_SPANNING_INLINE_BOX
formattingState.runs().insert(lineSpanningInlineBoxIndex++, { lineIndex, Run::Type::NonRootInlineBox, layoutBox, inlineBoxBorderBox, inlineBoxBorderBox, { }, { }, inlineLevelBox.hasContent(), true });

#endif
auto inlineBoxSize = LayoutSize { LayoutUnit::fromFloatCeil(inlineBoxBorderBox.width()), LayoutUnit::fromFloatCeil(inlineBoxBorderBox.height()) };
auto logicalRect = Rect { LayoutPoint { inlineBoxBorderBox.topLeft() }, inlineBoxSize };
// Middle or end of the inline box. Let's stretch the box as needed.
@@ -44,8 +44,8 @@ struct Run {
size_t start() const { return m_start; }
size_t end() const { return start() + length(); }
size_t length() const { return m_length; }
String originalContent() const { return m_originalContent; }
String renderedContent() const { return m_adjustedContentToRender; }
StringView originalContent() const { return StringView(m_originalContent).substring(m_start, m_length); }
StringView renderedContent() const { return m_adjustedContentToRender.isNull() ? originalContent() : m_adjustedContentToRender; }

bool hasHyphen() const { return m_hasHyphen; }

@@ -111,6 +111,8 @@ struct Run {

size_t lineIndex() const { return m_lineIndex; }

void setVerticalPositionIntegral();

private:
const size_t m_lineIndex;
const Type m_type;
@@ -146,6 +148,12 @@ inline Run::Text::Text(size_t start, size_t length, const String& originalConten
{
}

inline void Run::setVerticalPositionIntegral()
{
m_logicalRect.setTop(roundToInt(m_logicalRect.top()));
m_inkOverflow.setTop(roundToInt(m_inkOverflow.top()));
}

}
}
#endif
@@ -38,6 +38,7 @@ class InlineRect {
InlineRect(InlineLayoutUnit top, InlineLayoutUnit left, InlineLayoutUnit width, InlineLayoutUnit height);
InlineRect(const InlineLayoutPoint& topLeft, InlineLayoutUnit width, InlineLayoutUnit height);
InlineRect(const InlineLayoutPoint& topLeft, const InlineLayoutSize&);
InlineRect(const FloatRect&);

InlineLayoutUnit top() const;
InlineLayoutUnit left() const;
@@ -114,6 +115,11 @@ inline InlineRect::InlineRect(const InlineLayoutPoint& topLeft, const InlineLayo
{
}

inline InlineRect::InlineRect(const FloatRect& rect)
: InlineRect(rect.y(), rect.x(), rect.width(), rect.height())
{
}

#if ASSERT_ENABLED
inline void InlineRect::invalidatePosition()
{
@@ -27,8 +27,8 @@

#if ENABLE(LAYOUT_FORMATTING_CONTEXT)

#include "InlineLineRun.h"
#include "LayoutIntegrationLine.h"
#include "LayoutIntegrationRun.h"
#include <wtf/IteratorRange.h>
#include <wtf/Vector.h>
#include <wtf/WeakPtr.h>
@@ -48,6 +48,8 @@ class LineLayout;
class RunIterator;
class TextRunIterator;

using Run = Layout::Run;

struct InlineContent : public RefCounted<InlineContent> {
static Ref<InlineContent> create(const LineLayout& lineLayout) { return adoptRef(*new InlineContent(lineLayout)); }
~InlineContent();
@@ -29,10 +29,10 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)

#include "InlineFormattingState.h"
#include "InlineLineRun.h"
#include "LayoutBoxGeometry.h"
#include "LayoutIntegrationBoxTree.h"
#include "LayoutIntegrationInlineContent.h"
#include "LayoutIntegrationRun.h"
#include "LayoutReplacedBox.h"
#include "LayoutState.h"
#include "RenderBlockFlow.h"
@@ -65,38 +65,36 @@ InlineContentBuilder::InlineContentBuilder(const Layout::LayoutState& layoutStat
{
}

void InlineContentBuilder::build(const Layout::InlineFormattingState& inlineFormattingState, InlineContent& inlineContent) const
void InlineContentBuilder::build(Layout::InlineFormattingState& inlineFormattingState, InlineContent& inlineContent) const
{
createDisplayRuns(inlineFormattingState.runs(), inlineContent);
createDisplayRuns(inlineFormattingState, inlineContent);
createDisplayLines(inlineFormattingState.lines(), inlineContent);
}

void InlineContentBuilder::createDisplayRuns(const Layout::InlineRuns& runs, InlineContent& inlineContent) const
void InlineContentBuilder::createDisplayRuns(Layout::InlineFormattingState& inlineFormattingState, InlineContent& inlineContent) const
{
if (runs.isEmpty())
return;

inlineContent.runs.reserveInitialCapacity(runs.size());
for (auto& run : runs) {
if (auto text = run.text()) {
inlineContent.runs.append({ run.lineIndex(), run.layoutBox(), run.logicalRect(), run.inkOverflow(), Run::Expansion { run.expansion().behavior, run.expansion().horizontalExpansion }
, Run::Text { text->start(), text->length(), text->originalContent(), text->renderedContent(), text->hasHyphen() } });
} else if (!run.isRootInlineBox()) {
// FIXME: Teach the run iterators to ignore the root inline box runs.
auto& geometry = m_layoutState.geometryForBox(run.layoutBox());
if (!run.isInlineBox() || !run.isLineSpanning()) {
// FIXME: Run iterators with (text)runs spanning over multiple lines expect no "in-between" runs (e.g. line spanning or root inline boxes).
inlineContent.runs.append({ run.lineIndex(), run.layoutBox(), run.logicalRect(), run.inkOverflow(), { }, { } });
}
if (run.isInlineBox()) {
auto hasScrollableContent = [&] {
// In standards mode, inline boxes always start with an imaginary strut.
return m_layoutState.inStandardsMode() || run.hasContent() || geometry.horizontalBorder() || (geometry.horizontalPadding() && geometry.horizontalPadding().value());
};
inlineContent.nonRootInlineBoxes.append({ run.lineIndex(), run.layoutBox(), run.logicalRect(), hasScrollableContent() });
}
// FIXME: Remove this loop when we transitioned to the "run only" setup (i.e. each inline box is represented as a run as well)
auto& lineBoxes = const_cast<Layout::InlineFormattingState&>(inlineFormattingState).lineBoxes();
for (size_t lineIndex = 0; lineIndex < lineBoxes.size(); ++lineIndex) {
auto& lineBox = lineBoxes[lineIndex];
auto lineBoxLogicalTopLeft = inlineFormattingState.lines()[lineIndex].lineBoxLogicalRect().topLeft();
for (auto& nonRootInlineLevelBox : lineBox.nonRootInlineLevelBoxes()) {
if (!nonRootInlineLevelBox.isInlineBox())
continue;
auto& layoutBox = nonRootInlineLevelBox.layoutBox();
auto& boxGeometry = inlineFormattingState.boxGeometry(layoutBox);
auto hasScrollableContent = [&] {
// In standards mode, inline boxes always start with an imaginary strut.
return m_layoutState.inStandardsMode() || nonRootInlineLevelBox.hasContent() || boxGeometry.horizontalBorder() || (boxGeometry.horizontalPadding() && boxGeometry.horizontalPadding().value());
};
// Inline boxes may or may not be wrapped and have runs on multiple lines (e.g. <span>first line<br>second line<br>third line</span>)
auto inlineBoxBorderBox = lineBox.logicalBorderBoxForInlineBox(layoutBox, boxGeometry);
inlineBoxBorderBox.moveBy(lineBoxLogicalTopLeft);
inlineContent.nonRootInlineBoxes.append({ lineIndex, layoutBox, inlineBoxBorderBox, hasScrollableContent() });
}
}
// FIXME: This might need a different approach with partial layout where the layout code needs to know about the runs.
inlineContent.runs = WTFMove(inlineFormattingState.runs());
}

void InlineContentBuilder::createDisplayLines(const Layout::InlineLines& lines, InlineContent& inlineContent) const
@@ -131,11 +129,11 @@ void InlineContentBuilder::createDisplayLines(const Layout::InlineLines& lines,
auto runLogicalRect = run.logicalRect();
if (!box.hasSelfPaintingLayer()) {
auto childInkOverflow = box.logicalVisualOverflowRectForPropagation(&box.parent()->style());
childInkOverflow.move(runLogicalRect.x(), runLogicalRect.y());
childInkOverflow.move(runLogicalRect.left(), runLogicalRect.top());
lineInkOverflowRect.unite(childInkOverflow);
}
auto childScrollableOverflow = box.logicalLayoutOverflowRectForPropagation(&box.parent()->style());
childScrollableOverflow.move(runLogicalRect.x(), runLogicalRect.y());
childScrollableOverflow.move(runLogicalRect.left(), runLogicalRect.top());
scrollableOverflowRect.unite(childScrollableOverflow);
}
// Collect scrollable overflow from inline boxes. All other inline level boxes (e.g atomic inline level boxes) stretch the line.
@@ -43,10 +43,10 @@ class InlineContentBuilder {
public:
InlineContentBuilder(const Layout::LayoutState&, const RenderBlockFlow&, const BoxTree&);

void build(const Layout::InlineFormattingState&, InlineContent&) const;
void build(Layout::InlineFormattingState&, InlineContent&) const;

private:
void createDisplayRuns(const Layout::InlineRuns&, InlineContent&) const;
void createDisplayRuns(Layout::InlineFormattingState&, InlineContent&) const;
void createDisplayLines(const Layout::InlineLines&, InlineContent&) const;

const Layout::LayoutState& m_layoutState;

0 comments on commit 087aa29

Please sign in to comment.