Modified: trunk/LayoutTests/ChangeLog (253106 => 253107)
--- trunk/LayoutTests/ChangeLog 2019-12-04 17:46:02 UTC (rev 253106)
+++ trunk/LayoutTests/ChangeLog 2019-12-04 18:00:36 UTC (rev 253107)
@@ -1,3 +1,13 @@
+2019-12-04 Antti Koivisto <[email protected]>
+
+ [LFC][Integration] Paint with TextPainter
+ https://bugs.webkit.org/show_bug.cgi?id=204852
+
+ Reviewed by Zalan Bujtas.
+
+ * fast/layoutformattingcontext/flow-integration-basic-paint-expected.html: Added.
+ * fast/layoutformattingcontext/flow-integration-basic-paint.html: Added.
+
2019-12-04 Simon Fraser <[email protected]>
Implement the CSS clamp() function
Added: trunk/LayoutTests/fast/layoutformattingcontext/flow-integration-basic-paint-expected.html (0 => 253107)
--- trunk/LayoutTests/fast/layoutformattingcontext/flow-integration-basic-paint-expected.html (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/flow-integration-basic-paint-expected.html 2019-12-04 18:00:36 UTC (rev 253107)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<style>
+.margin { margin: 10px 400px 20px 5px; }
+.border { border-left: 10px solid black; border-top: 5px solid black; border-right: 15px solid black; border-bottom: 20px solid black; }
+.padding { padding: 10px 50px 20px 5px; }
+</style>
+<div class="margin">Text text text text text text text text text text text text text text text text text </div>
+<div class="margin border">Text text text text text text text text text text text text text text text text text </div>
+<div class="margin border padding">Text text text text text text text text text text text text text text text text text </div>
+</html>
Added: trunk/LayoutTests/fast/layoutformattingcontext/flow-integration-basic-paint.html (0 => 253107)
--- trunk/LayoutTests/fast/layoutformattingcontext/flow-integration-basic-paint.html (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/flow-integration-basic-paint.html 2019-12-04 18:00:36 UTC (rev 253107)
@@ -0,0 +1,11 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextIntegrationEnabled=true ] -->
+<html>
+<style>
+.margin { margin: 10px 400px 20px 5px; }
+.border { border-left: 10px solid black; border-top: 5px solid black; border-right: 15px solid black; border-bottom: 20px solid black; }
+.padding { padding: 10px 50px 20px 5px; }
+</style>
+<div class="margin">Text text text text text text text text text text text text text text text text text </div>
+<div class="margin border">Text text text text text text text text text text text text text text text text text </div>
+<div class="margin border padding">Text text text text text text text text text text text text text text text text text </div>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (253106 => 253107)
--- trunk/Source/WebCore/ChangeLog 2019-12-04 17:46:02 UTC (rev 253106)
+++ trunk/Source/WebCore/ChangeLog 2019-12-04 18:00:36 UTC (rev 253107)
@@ -1,3 +1,29 @@
+2019-12-04 Antti Koivisto <[email protected]>
+
+ [LFC][Integration] Paint with TextPainter
+ https://bugs.webkit.org/show_bug.cgi?id=204852
+
+ Reviewed by Zalan Bujtas.
+
+ Display::Painter is very rudimentary and turning it into a full painting implementation
+ requires lot of refactoring. Instead, for now use separate painting code in the integration
+ layer that invokes the existing render tree based painting helpers.
+
+ This also enables writing reftests for intergrated LFC layout.
+
+ Test: fast/layoutformattingcontext/flow-integration-basic-paint.html
+
+ * layout/displaytree/DisplayInlineContent.h:
+ (WebCore::Display:: const):
+ * layout/integration/LayoutIntegrationLineLayout.cpp:
+ (WebCore::LayoutIntegration::computeOverflow):
+ (WebCore::LayoutIntegration::LineLayout::paint):
+
+ Adopted from SimpleLineLayout::paintFlow with support for per-run style added.
+
+ (WebCore::LayoutIntegration::LineLayout::debugTextShadow):
+ * layout/integration/LayoutIntegrationLineLayout.h:
+
2019-12-04 Simon Fraser <[email protected]>
Implement the CSS clamp() function
Modified: trunk/Source/WebCore/layout/displaytree/DisplayInlineContent.h (253106 => 253107)
--- trunk/Source/WebCore/layout/displaytree/DisplayInlineContent.h 2019-12-04 17:46:02 UTC (rev 253106)
+++ trunk/Source/WebCore/layout/displaytree/DisplayInlineContent.h 2019-12-04 18:00:36 UTC (rev 253107)
@@ -29,6 +29,7 @@
#include "DisplayRun.h"
#include "InlineLineBox.h"
+#include <wtf/IteratorRange.h>
#include <wtf/Vector.h>
namespace WebCore {
@@ -42,9 +43,36 @@
LineBoxes lineBoxes;
const Layout::LineBox& lineBoxForRun(const Run& run) const { return lineBoxes[run.lineIndex()]; }
+ WTF::IteratorRange<const Run*> runsForRect(const LayoutRect&) const;
};
+inline WTF::IteratorRange<const Run*> InlineContent::runsForRect(const LayoutRect& rect) const
+{
+ // FIXME: Do something efficient.
+ const Run* first = nullptr;
+ for (auto& run : runs) {
+ LayoutRect runRect = run.logicalRect();
+ if (runRect.intersects(rect)) {
+ first = &run;
+ break;
+ }
+ }
+ if (!first)
+ return { nullptr, nullptr };
+
+ const Run* last = nullptr;
+ for (auto& run : WTF::makeReversedRange(runs)) {
+ LayoutRect runRect = run.logicalRect();
+ if (runRect.intersects(rect)) {
+ last = &run;
+ break;
+ }
+ }
+
+ return { first, last + 1 };
}
+
}
+}
#endif
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (253106 => 253107)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp 2019-12-04 17:46:02 UTC (rev 253106)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp 2019-12-04 18:00:36 UTC (rev 253107)
@@ -29,7 +29,7 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "DisplayBox.h"
-#include "DisplayPainter.h"
+#include "EventRegion.h"
#include "InlineFormattingState.h"
#include "InvalidationState.h"
#include "LayoutContext.h"
@@ -36,9 +36,13 @@
#include "LayoutTreeBuilder.h"
#include "PaintInfo.h"
#include "RenderBlockFlow.h"
+#include "RenderChildIterator.h"
#include "RenderLineBreak.h"
#include "RuntimeEnabledFeatures.h"
+#include "Settings.h"
#include "SimpleLineLayout.h"
+#include "TextDecorationPainter.h"
+#include "TextPainter.h"
namespace WebCore {
namespace LayoutIntegration {
@@ -100,18 +104,6 @@
return downcast<Layout::InlineFormattingState>(m_layoutState->establishedFormattingState(rootLayoutBox())).displayInlineContent();
}
-void LineLayout::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
-{
- auto& graphicsContext = paintInfo.context();
-
- graphicsContext.save();
- graphicsContext.translate(paintOffset);
-
- Display::Painter::paintInlineFlow(*m_layoutState, paintInfo.context());
-
- graphicsContext.restore();
-}
-
LineLayoutTraversal::TextBoxIterator LineLayout::textBoxesFor(const RenderText& renderText) const
{
auto* inlineContent = displayInlineContent();
@@ -158,7 +150,101 @@
return m_treeContent->rootLayoutBox();
}
+static LayoutRect computeOverflow(const RenderStyle& style, const LayoutRect& boxRect, IntSize& viewportSize)
+{
+ auto overflowRect = boxRect;
+ auto strokeOverflow = std::ceil(style.computedStrokeWidth(viewportSize));
+ overflowRect.inflate(strokeOverflow);
+
+ auto letterSpacing = style.fontCascade().letterSpacing();
+ if (letterSpacing >= 0)
+ return overflowRect;
+ // Last letter's negative spacing shrinks layout rect. Push it to visual overflow.
+ overflowRect.expand(-letterSpacing, 0);
+ return overflowRect;
}
+
+void LineLayout::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+{
+ if (!displayInlineContent())
+ return;
+
+ if (paintInfo.phase != PaintPhase::Foreground && paintInfo.phase != PaintPhase::EventRegion)
+ return;
+
+ auto& inlineContent = *displayInlineContent();
+
+ auto viewportSize = m_flow.frame().view()->size();
+ float deviceScaleFactor = m_flow.document().deviceScaleFactor();
+
+ auto paintRect = paintInfo.rect;
+ paintRect.moveBy(-paintOffset);
+
+ for (auto& run : inlineContent.runsForRect(paintRect)) {
+ if (!run.textContext())
+ continue;
+
+ auto& textContext = *run.textContext();
+ if (!textContext.length())
+ continue;
+
+ auto& style = run.style();
+ if (style.visibility() != Visibility::Visible)
+ return;
+
+ LayoutRect rect = run.logicalRect();
+ auto visualOverflowRect = computeOverflow(style, rect, viewportSize);
+ if (paintRect.y() > visualOverflowRect.maxY() || paintRect.maxY() < visualOverflowRect.y())
+ continue;
+
+ if (paintInfo.eventRegionContext) {
+ if (style.pointerEvents() != PointerEvents::None)
+ paintInfo.eventRegionContext->unite(enclosingIntRect(visualOverflowRect), style);
+ continue;
+ }
+
+ // FIXME: Hyphens.
+
+ auto& lineBox = inlineContent.lineBoxForRun(run);
+ auto baselineOffset = paintOffset.y() + lineBox.logicalTop() + lineBox.baselineOffset();
+
+ auto behavior = textContext.expansion() ? textContext.expansion()->behavior : DefaultExpansion;
+ auto horizontalExpansion = textContext.expansion() ? textContext.expansion()->horizontalExpansion : 0_lu;
+ auto logicalLeft = paintOffset.x() + run.logicalLeft();
+
+ TextRun textRun { textContext.content(), logicalLeft, horizontalExpansion, behavior };
+ textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
+ FloatPoint textOrigin { rect.x() + paintOffset.x(), roundToDevicePixel(baselineOffset, deviceScaleFactor) };
+
+ TextPainter textPainter(paintInfo.context());
+ textPainter.setFont(style.fontCascade());
+ textPainter.setStyle(computeTextPaintStyle(m_flow.frame(), style, paintInfo));
+ if (auto* debugShadow = debugTextShadow())
+ textPainter.setShadow(debugShadow);
+
+ textPainter.paint(textRun, rect, textOrigin);
+
+ if (!style.textDecorationsInEffect().isEmpty()) {
+ // FIXME: Use correct RenderText.
+ if (auto* textRenderer = childrenOfType<RenderText>(m_flow).first()) {
+ auto painter = TextDecorationPainter { paintInfo.context(), style.textDecorationsInEffect(), *textRenderer, false, style.fontCascade() };
+ painter.setWidth(rect.width());
+ painter.paintTextDecoration(textRun, textOrigin, rect.location() + paintOffset);
+ }
+ }
+ }
}
+ShadowData* LineLayout::debugTextShadow()
+{
+ if (!m_flow.settings().simpleLineLayoutDebugBordersEnabled())
+ return nullptr;
+
+ static NeverDestroyed<ShadowData> debugTextShadow(IntPoint(0, 0), 10, 20, ShadowStyle::Normal, true, Color(0, 0, 150, 150));
+ return &debugTextShadow.get();
+}
+
+}
+}
+
#endif
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h (253106 => 253107)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h 2019-12-04 17:46:02 UTC (rev 253106)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h 2019-12-04 18:00:36 UTC (rev 253107)
@@ -69,6 +69,7 @@
private:
const Layout::Container& rootLayoutBox() const;
void prepareRootGeometryForLayout();
+ ShadowData* debugTextShadow();
const RenderBlockFlow& m_flow;
std::unique_ptr<const Layout::LayoutTreeContent> m_treeContent;