Title: [268598] trunk/Source/WebCore
Revision
268598
Author
[email protected]
Date
2020-10-16 10:52:20 -0700 (Fri, 16 Oct 2020)

Log Message

[LFC][Integration] Allow images in inline content
https://bugs.webkit.org/show_bug.cgi?id=217757

Reviewed by Zalan Bujtas.

Add support for inline images in integrated modern inline layout.
This patch doesn't yet enable the support (it is behind an ifdef).

* dom/Position.cpp:
(WebCore::Position::ensureLineBoxes const):
* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::geometryForBox const):
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin const):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
* layout/integration/LayoutIntegrationBoxTree.cpp:
(WebCore::LayoutIntegration::BoxTree::buildTree):
* layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::canUseForLineLayoutWithReason):
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::updateReplacedDimensions):
(WebCore::LayoutIntegration::LineLayout::constructContent):
(WebCore::LayoutIntegration::LineLayout::prepareLayoutState):
(WebCore::LayoutIntegration::LineLayout::paint):
* layout/integration/LayoutIntegrationLineLayout.h:
* layout/layouttree/LayoutReplacedBox.h:
(WebCore::Layout::ReplacedBox::contentSizeForIntegration const):
(WebCore::Layout::ReplacedBox::setContentSizeForIntegration):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::layoutLFCLines):
* rendering/RenderLineBreak.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (268597 => 268598)


--- trunk/Source/WebCore/ChangeLog	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/ChangeLog	2020-10-16 17:52:20 UTC (rev 268598)
@@ -1,3 +1,37 @@
+2020-10-16  Antti Koivisto  <[email protected]>
+
+        [LFC][Integration] Allow images in inline content
+        https://bugs.webkit.org/show_bug.cgi?id=217757
+
+        Reviewed by Zalan Bujtas.
+
+        Add support for inline images in integrated modern inline layout.
+        This patch doesn't yet enable the support (it is behind an ifdef).
+
+        * dom/Position.cpp:
+        (WebCore::Position::ensureLineBoxes const):
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::geometryForBox const):
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
+        * layout/integration/LayoutIntegrationBoxTree.cpp:
+        (WebCore::LayoutIntegration::BoxTree::buildTree):
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+        (WebCore::LayoutIntegration::canUseForLineLayoutWithReason):
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::updateReplacedDimensions):
+        (WebCore::LayoutIntegration::LineLayout::constructContent):
+        (WebCore::LayoutIntegration::LineLayout::prepareLayoutState):
+        (WebCore::LayoutIntegration::LineLayout::paint):
+        * layout/integration/LayoutIntegrationLineLayout.h:
+        * layout/layouttree/LayoutReplacedBox.h:
+        (WebCore::Layout::ReplacedBox::contentSizeForIntegration const):
+        (WebCore::Layout::ReplacedBox::setContentSizeForIntegration):
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::layoutLFCLines):
+        * rendering/RenderLineBreak.cpp:
+
 2020-10-16  Youenn Fablet  <[email protected]>
 
         sdpFmtLine should be missing from RTCRtpCodecCapability instead of being an empty string

Modified: trunk/Source/WebCore/dom/Position.cpp (268597 => 268598)


--- trunk/Source/WebCore/dom/Position.cpp	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/dom/Position.cpp	2020-10-16 17:52:20 UTC (rev 268598)
@@ -1389,13 +1389,9 @@
     auto renderer = node->renderer();
     if (!renderer)
         return;
-
-    if (renderer->isBR()) {
-        downcast<RenderLineBreak>(*renderer).ensureLineBoxes();
-        return;
-    }
-    if (is<RenderText>(*renderer))
-        downcast<RenderText>(*renderer).ensureLineBoxes();
+    auto* parent = renderer->parent();
+    if (is<RenderBlockFlow>(parent))
+        downcast<RenderBlockFlow>(*parent).ensureLineBoxes();
 }
 
 TextDirection Position::primaryDirection() const

Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (268597 => 268598)


--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2020-10-16 17:52:20 UTC (rev 268598)
@@ -952,6 +952,9 @@
     auto usedVerticalMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
     auto& style = replacedBox.style();
 
+    if (replacedBox.contentSizeForIntegration())
+        return { replacedBox.contentSizeForIntegration()->height(), usedVerticalMargin };
+
     auto height = overriddenVerticalValues.height ? overriddenVerticalValues.height.value() : computedHeight(replacedBox, verticalConstraints ? verticalConstraints->logicalHeight : WTF::nullopt);
     auto heightIsAuto = !overriddenVerticalValues.height && isHeightAuto(replacedBox);
     auto widthIsAuto = style.logicalWidth().isAuto();
@@ -1012,6 +1015,9 @@
         return computedHorizontalMargin.end.valueOr(0_lu);
     };
 
+    if (replacedBox.contentSizeForIntegration())
+        return { replacedBox.contentSizeForIntegration()->width(), { usedMarginStart(), usedMarginEnd() } };
+
     auto width = overriddenHorizontalValues.width ? overriddenHorizontalValues.width : computedWidth(replacedBox, horizontalConstraints.logicalWidth);
     auto heightIsAuto = isHeightAuto(replacedBox);
     auto height = computedHeight(replacedBox, verticalConstraints ? verticalConstraints->logicalHeight : WTF::nullopt);

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp (268597 => 268598)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp	2020-10-16 17:52:20 UTC (rev 268598)
@@ -30,8 +30,10 @@
 
 #include "LayoutInlineTextBox.h"
 #include "LayoutLineBreakBox.h"
+#include "LayoutReplacedBox.h"
 #include "RenderBlockFlow.h"
 #include "RenderChildIterator.h"
+#include "RenderImage.h"
 #include "RenderLineBreak.h"
 
 namespace WebCore {
@@ -68,6 +70,10 @@
             clonedStyle.setFloating(Float::No);
             clonedStyle.setPosition(PositionType::Static);
             childBox = makeUnique<Layout::LineBreakBox>(downcast<RenderLineBreak>(childRenderer).isWBR(), WTFMove(clonedStyle));
+        } else if (is<RenderImage>(childRenderer)) {
+            auto& image = downcast<RenderImage>(childRenderer);
+            auto clonedStyle = RenderStyle::clone(image.style());
+            childBox = makeUnique<Layout::ReplacedBox>(WTF::nullopt, WTFMove(clonedStyle));
         }
         ASSERT(childBox);
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp (268597 => 268598)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2020-10-16 17:52:20 UTC (rev 268598)
@@ -31,6 +31,7 @@
 #include "Logging.h"
 #include "RenderBlockFlow.h"
 #include "RenderChildIterator.h"
+#include "RenderImage.h"
 #include "RenderLineBreak.h"
 #include "RenderMultiColumnFlow.h"
 #include "RenderTextControl.h"
@@ -41,6 +42,8 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#define ALLOW_INLINE_IMAGES 0
+
 #ifndef NDEBUG
 #define SET_REASON_AND_RETURN_IF_NEEDED(reason, reasons, includeReasons) { \
         reasons.add(AvoidanceReason::reason); \
@@ -305,7 +308,7 @@
         SET_REASON_AND_RETURN_IF_NEEDED(FlowParentIsTextAreaWithWrapping, reasons, includeReasons);
     // This currently covers <blockflow>#text</blockflow>, <blockflow>#text<br></blockflow> and mutiple (sibling) RenderText cases.
     // The <blockflow><inline>#text</inline></blockflow> case is also popular and should be relatively easy to cover.
-    for (const auto* child = flow.firstChild(); child;) {
+    for (const auto* child = flow.firstChild(); child; child = child->nextSibling()) {
         if (child->selectionState() != RenderObject::HighlightState::None)
             SET_REASON_AND_RETURN_IF_NEEDED(FlowChildIsSelected, reasons, includeReasons);
         if (is<RenderText>(*child)) {
@@ -312,13 +315,25 @@
             const auto& renderText = downcast<RenderText>(*child);
             if (renderText.textNode() && !renderText.document().markers().markersFor(*renderText.textNode()).isEmpty())
                 SET_REASON_AND_RETURN_IF_NEEDED(FlowIncludesDocumentMarkers, reasons, includeReasons);
-            child = child->nextSibling();
             continue;
         }
-        if (is<RenderLineBreak>(child)) {
-            child = child->nextSibling();
+        if (is<RenderLineBreak>(*child))
             continue;
+#if ALLOW_INLINE_IMAGES
+        if (is<RenderImage>(*child)) {
+            auto& image = downcast<RenderImage>(*child);
+            if (image.isFloating() || image.isPositioned())
+                SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons);
+            auto& style = image.style();
+            if (style.verticalAlign() != VerticalAlign::Baseline)
+                SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons);
+            if (style.width().isPercent() || style.height().isPercent())
+                SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons);
+            if (style.objectFit() != RenderStyle::initialObjectFit())
+                SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons);
+            continue;
         }
+#endif
         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons);
         break;
     }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (268597 => 268598)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-16 17:52:20 UTC (rev 268598)
@@ -84,6 +84,14 @@
     return canUseForLineLayoutAfterStyleChange(flow, diff);
 }
 
+void LineLayout::updateReplacedDimensions(const RenderBox& replaced)
+{
+    auto& layoutBox = *m_boxTree.layoutBoxForRenderer(replaced);
+    auto& replacedBox = const_cast<Layout::ReplacedBox&>(downcast<Layout::ReplacedBox>(layoutBox));
+
+    replacedBox.setContentSizeForIntegration({ replaced.contentLogicalWidth(), replaced.contentLogicalHeight() });
+}
+
 void LineLayout::updateStyle()
 {
     auto& root = rootLayoutBox();
@@ -155,6 +163,11 @@
             auto expansion = Run::Expansion { lineRun.expansion().behavior, lineRun.expansion().horizontalExpansion };
             auto displayRun = Run { lineIndex, layoutBox, runRect, computedInkOverflow(runRect), expansion, textContent };
             displayInlineContent.runs.append(displayRun);
+
+            if (layoutBox.isReplacedBox()) {
+                auto& renderer = downcast<RenderBox>(*rendererForLayoutBox(layoutBox));
+                const_cast<RenderBox&>(renderer).setLocation(flooredLayoutPoint(runRect.location()));
+            }
         }
     };
     constructDisplayLineRuns();
@@ -203,6 +216,13 @@
 void LineLayout::prepareLayoutState()
 {
     m_layoutState.setViewportSize(m_flow.frame().view()->size());
+
+    auto& rootGeometry = m_layoutState.ensureGeometryForBox(rootLayoutBox());
+    rootGeometry.setContentBoxWidth(m_flow.contentSize().width());
+    rootGeometry.setPadding({ { } });
+    rootGeometry.setBorder({ });
+    rootGeometry.setHorizontalMargin({ });
+    rootGeometry.setVerticalMargin({ });
 }
 
 void LineLayout::prepareFloatingState()
@@ -377,8 +397,14 @@
     paintRect.moveBy(-paintOffset);
 
     for (auto& run : inlineContent.runsForRect(paintRect)) {
-        if (!run.textContent())
+        if (!run.textContent()) {
+            auto* renderer = m_boxTree.rendererForLayoutBox(run.layoutBox());
+            if (renderer && renderer->isReplaced() && is<RenderElement>(*renderer)) {
+                auto& renderElement = const_cast<RenderElement&>(downcast<RenderElement>(*renderer));
+                renderElement.paint(paintInfo, paintOffset);
+            }
             continue;
+        }
 
         auto& textContent = *run.textContent();
         if (!textContent.length())

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h (268597 => 268598)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h	2020-10-16 17:52:20 UTC (rev 268598)
@@ -41,7 +41,7 @@
 class HitTestRequest;
 class HitTestResult;
 class RenderBlockFlow;
-class RenderLineBreak;
+class RenderBox;
 struct PaintInfo;
 
 namespace LayoutIntegration {
@@ -58,6 +58,7 @@
     static bool canUseFor(const RenderBlockFlow&);
     static bool canUseForAfterStyleChange(const RenderBlockFlow&, StyleDifference);
 
+    void updateReplacedDimensions(const RenderBox&);
     void updateStyle();
     void layout();
 

Modified: trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.h (268597 => 268598)


--- trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.h	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.h	2020-10-16 17:52:20 UTC (rev 268598)
@@ -50,6 +50,9 @@
     void setIntrinsicSize(LayoutSize size) { m_intrinsicSize = size; }
     void setIntrinsicRatio(LayoutUnit ratio) { m_intrinsicRatio = ratio; };
 
+    Optional<LayoutSize> contentSizeForIntegration() const { return m_contentSizeForIntegration; }
+    void setContentSizeForIntegration(LayoutSize size) { m_contentSizeForIntegration = size; }
+
     bool hasIntrinsicWidth() const;
     bool hasIntrinsicHeight() const;
     bool hasIntrinsicRatio() const;
@@ -62,6 +65,7 @@
 
     Optional<LayoutSize> m_intrinsicSize;
     Optional<LayoutUnit> m_intrinsicRatio;
+    Optional<LayoutSize> m_contentSizeForIntegration;
     CachedImage* m_cachedImage { nullptr };
 };
 

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (268597 => 268598)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2020-10-16 17:49:59 UTC (rev 268597)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2020-10-16 17:52:20 UTC (rev 268598)
@@ -3661,8 +3661,14 @@
     auto& layoutFormattingContextLineLayout = *this->layoutFormattingContextLineLayout();
 
     for (auto& renderer : childrenOfType<RenderObject>(*this)) {
-        if (is<RenderText>(renderer))
-            downcast<RenderText>(renderer).deleteLineBoxes();
+        if (!renderer.needsLayout())
+            continue;
+        if (is<RenderReplaced>(renderer)) {
+            auto& replaced = downcast<RenderReplaced>(renderer);
+            replaced.layoutIfNeeded();
+            layoutFormattingContextLineLayout.updateReplacedDimensions(replaced);
+            continue;
+        }
         renderer.clearNeedsLayout();
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to