Diff
Modified: trunk/Source/WebCore/ChangeLog (268958 => 268959)
--- trunk/Source/WebCore/ChangeLog 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/ChangeLog 2020-10-25 20:26:01 UTC (rev 268959)
@@ -1,3 +1,74 @@
+2020-10-25 Simon Fraser <[email protected]>
+
+ [LFC Display] Move display box creation and geometry computation out of Display::TreeBuilder
+ https://bugs.webkit.org/show_bug.cgi?id=218160
+
+ Reviewed by Zalan Bujtas.
+
+ Make Display::BoxFactory, which has the responsibility of making Display::Boxes,
+ and setting up their style and geometry. This moves all of the pixel snapping
+ code out of Display::TreeBuilder.
+
+ Display::Box subclasses declare Display::BoxFactory as a friend class so that the factory
+ can call geometry setter functions (to avoid passing long lists of arguments down through
+ constructors).
+
+ Display::TextBox's text() is no longer Optional<> because we only make text boxes
+ for runs with text.
+
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * display/DisplayTreeBuilder.cpp:
+ (WebCore::Display::TreeBuilder::TreeBuilder):
+ (WebCore::Display::TreeBuilder::build const):
+ (WebCore::Display::TreeBuilder::buildInlineDisplayTree const):
+ (WebCore::Display::TreeBuilder::recursiveBuildDisplayTree const):
+ (WebCore::Display::TreeBuilder::computeBoxDecorationData const): Deleted.
+ (WebCore::Display::TreeBuilder::displayBoxForRootBox const): Deleted.
+ (WebCore::Display::TreeBuilder::displayBoxForLayoutBox const): Deleted.
+ * display/DisplayTreeBuilder.h:
+ * display/css/DisplayBoxDecorationData.cpp:
+ (WebCore::Display::BoxDecorationData::create): Deleted.
+ * display/css/DisplayBoxDecorationData.h:
+ * display/css/DisplayBoxFactory.cpp: Added.
+ (WebCore::Display::BoxFactory::BoxFactory):
+ (WebCore::Display::BoxFactory::displayBoxForRootBox const):
+ (WebCore::Display::BoxFactory::displayBoxForLayoutBox const):
+ (WebCore::Display::BoxFactory::displayBoxForTextRun const):
+ (WebCore::Display::BoxFactory::setupBoxGeometry const):
+ (WebCore::Display::BoxFactory::constructBoxDecorationData const):
+ (WebCore::Display::BoxFactory::setupBoxModelBox const):
+ * display/css/DisplayBoxFactory.h: Copied from Source/WebCore/display/DisplayTreeBuilder.h.
+ * display/css/DisplayBoxModelBox.cpp:
+ * display/css/DisplayBoxModelBox.h:
+ (WebCore::Display::BoxModelBox::absoluteBorderBoxRect const):
+ (WebCore::Display::BoxModelBox::absolutePaddingBoxRect const):
+ (WebCore::Display::BoxModelBox::absoluteContentBoxRect const):
+ (WebCore::Display::BoxModelBox::boxDecorationData const):
+ (WebCore::Display::BoxModelBox::setAbsolutePaddingBoxRect):
+ (WebCore::Display::BoxModelBox::setAbsoluteContentBoxRect):
+ * display/css/DisplayCSSPainter.cpp:
+ (WebCore::Display::CSSPainter::paintBoxContent):
+ * display/css/DisplayFillLayerImageGeometry.cpp:
+ (WebCore::Display::calculateFillLayerImageGeometry):
+ * display/css/DisplayFillLayerImageGeometry.h:
+ * display/css/DisplayImageBox.cpp:
+ (WebCore::Display::ImageBox::ImageBox):
+ (WebCore::Display::m_image):
+ (): Deleted.
+ (WebCore::Display::ImageBox::setImage): Deleted.
+ * display/css/DisplayImageBox.h:
+ (WebCore::Display::ImageBox::image const):
+ * display/css/DisplayReplacedBox.cpp:
+ (WebCore::Display::ReplacedBox::ReplacedBox):
+ * display/css/DisplayReplacedBox.h:
+ (WebCore::Display::ReplacedBox::setReplacedContentRect):
+ * display/css/DisplayTextBox.cpp:
+ (WebCore::Display::m_text):
+ (WebCore::Display::TextBox::debugDescription const):
+ * display/css/DisplayTextBox.h:
+ (WebCore::Display::TextBox::text const):
+
2020-10-25 Sam Weinig <[email protected]>
Remove support for 'pixel' and 'pos' CSSOM prefixes
Modified: trunk/Source/WebCore/Sources.txt (268958 => 268959)
--- trunk/Source/WebCore/Sources.txt 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/Sources.txt 2020-10-25 20:26:01 UTC (rev 268959)
@@ -814,6 +814,7 @@
cssjit/SelectorCompiler.cpp
display/css/DisplayBox.cpp
display/css/DisplayBoxDecorationData.cpp
+display/css/DisplayBoxFactory.cpp
display/css/DisplayBoxModelBox.cpp
display/css/DisplayContainerBox.cpp
display/css/DisplayCSSPainter.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (268958 => 268959)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-10-25 20:26:01 UTC (rev 268959)
@@ -5988,6 +5988,8 @@
0F60F32A1DFBB10400416D6C /* CommonVM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonVM.h; sourceTree = "<group>"; };
0F6383DB18615B29003E5DB5 /* ThreadedScrollingTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadedScrollingTree.cpp; sourceTree = "<group>"; };
0F6383DC18615B29003E5DB5 /* ThreadedScrollingTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadedScrollingTree.h; sourceTree = "<group>"; };
+ 0F656FB525452E5400219F4C /* DisplayBoxFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayBoxFactory.h; sourceTree = "<group>"; };
+ 0F656FB625452E5400219F4C /* DisplayBoxFactory.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayBoxFactory.cpp; sourceTree = "<group>"; };
0F69F2B6228B98FF008D3565 /* LayerOverlapMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayerOverlapMap.h; sourceTree = "<group>"; };
0F69F2B7228B98FF008D3565 /* LayerOverlapMap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayerOverlapMap.cpp; sourceTree = "<group>"; };
0F6A12BB1A00923700C6DE72 /* DebugPageOverlays.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DebugPageOverlays.cpp; sourceTree = "<group>"; };
@@ -17623,6 +17625,8 @@
0FFF1B78251BC6570098795A /* DisplayBox.h */,
0F94722B2534B04500F153C8 /* DisplayBoxDecorationData.cpp */,
0F9472292534B04500F153C8 /* DisplayBoxDecorationData.h */,
+ 0F656FB625452E5400219F4C /* DisplayBoxFactory.cpp */,
+ 0F656FB525452E5400219F4C /* DisplayBoxFactory.h */,
0F9472202534010900F153C8 /* DisplayBoxModelBox.cpp */,
0F94721E2534010900F153C8 /* DisplayBoxModelBox.h */,
0FFF1B74251BC6570098795A /* DisplayContainerBox.cpp */,
Modified: trunk/Source/WebCore/display/DisplayTreeBuilder.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/DisplayTreeBuilder.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/DisplayTreeBuilder.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -28,11 +28,9 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-#include "DisplayBoxDecorationData.h"
+#include "DisplayBoxFactory.h"
#include "DisplayContainerBox.h"
-#include "DisplayImageBox.h"
#include "DisplayStyle.h"
-#include "DisplayTextBox.h"
#include "DisplayTree.h"
#include "InlineFormattingState.h"
#include "LayoutBoxGeometry.h"
@@ -49,7 +47,7 @@
namespace Display {
TreeBuilder::TreeBuilder(float pixelSnappingFactor)
- : m_pixelSnappingFactor(pixelSnappingFactor)
+ : m_boxFactory(pixelSnappingFactor)
{
}
@@ -62,7 +60,7 @@
LOG_WITH_STREAM(FormattingContextLayout, stream << "Building display tree for:\n" << layoutTreeAsText(rootLayoutBox, &layoutState));
auto geometry = layoutState.geometryForBox(rootLayoutBox);
- auto rootDisplayBox = displayBoxForRootBox(geometry, rootLayoutBox);
+ auto rootDisplayBox = m_boxFactory.displayBoxForRootBox(rootLayoutBox, geometry);
auto rootDisplayContainerBox = std::unique_ptr<ContainerBox> { downcast<ContainerBox>(rootDisplayBox.release()) };
if (!rootLayoutBox.firstChild())
@@ -98,17 +96,7 @@
for (auto& run : inlineFormattingState.lineRuns()) {
if (run.text()) {
auto& lineGeometry = inlineFormattingState.lines().at(run.lineIndex());
-
- auto lineRect = lineGeometry.logicalRect();
- auto lineLayoutRect = LayoutRect { lineRect.left(), lineRect.top(), lineRect.width(), lineRect.height() };
-
- auto runRect = LayoutRect { run.logicalLeft(), run.logicalTop(), run.logicalWidth(), run.logicalHeight() };
- runRect.moveBy(lineLayoutRect.location());
- runRect.move(offsetFromRoot);
-
- auto style = Style { run.layoutBox().style() };
- auto textBox = makeUnique<TextBox>(snapRectToDevicePixels(runRect, m_pixelSnappingFactor), WTFMove(style), run);
-
+ auto textBox = m_boxFactory.displayBoxForTextRun(run, lineGeometry, offsetFromRoot);
insert(WTFMove(textBox), insertionPosition);
continue;
}
@@ -119,44 +107,22 @@
}
auto geometry = layoutState.geometryForBox(run.layoutBox());
- auto displayBox = displayBoxForLayoutBox(geometry, run.layoutBox(), offsetFromRoot);
+ auto displayBox = m_boxFactory.displayBoxForLayoutBox(run.layoutBox(), geometry, offsetFromRoot);
insert(WTFMove(displayBox), insertionPosition);
}
}
-// FIXME: This should happen as part of Display::Box creation.
-void TreeBuilder::computeBoxDecorationData(BoxModelBox& box, const Layout::Box& layoutBox, const Layout::BoxGeometry& geometry, LayoutSize offsetFromRoot) const
+void TreeBuilder::recursiveBuildDisplayTree(const Layout::LayoutState& layoutState, LayoutSize offsetFromRoot, const Layout::Box& layoutBox, InsertionPosition& insertionPosition) const
{
- auto borderBoxRect = LayoutRect { Layout::BoxGeometry::borderBoxRect(geometry) };
- borderBoxRect.move(offsetFromRoot);
-
- auto paddingBoxRect = LayoutRect { geometry.paddingBox() };
- paddingBoxRect.moveBy(borderBoxRect.location());
- box.setAbsolutePaddingBoxRect(snapRectToDevicePixels(paddingBoxRect, m_pixelSnappingFactor));
-
- auto contentBoxRect = LayoutRect { geometry.contentBox() };
- contentBoxRect.moveBy(borderBoxRect.location());
- box.setAbsoluteContentBoxRect(snapRectToDevicePixels(contentBoxRect, m_pixelSnappingFactor));
-
- // FIXME: Check for rounded borders when supported.
- if (!box.style().hasBackground())
- return;
-
- auto boxDecorationData = BoxDecorationData::create(box, layoutBox, geometry, offsetFromRoot, m_pixelSnappingFactor);
- box.setBoxDecorationData(WTFMove(boxDecorationData));
-}
-
-void TreeBuilder::recursiveBuildDisplayTree(const Layout::LayoutState& layoutState, LayoutSize offsetFromRoot, const Layout::Box& box, InsertionPosition& insertionPosition) const
-{
- auto geometry = layoutState.geometryForBox(box);
- auto displayBox = displayBoxForLayoutBox(geometry, box, offsetFromRoot);
+ auto geometry = layoutState.geometryForBox(layoutBox);
+ auto displayBox = m_boxFactory.displayBoxForLayoutBox(layoutBox, geometry, offsetFromRoot);
insert(WTFMove(displayBox), insertionPosition);
- if (!is<Layout::ContainerBox>(box))
+ if (!is<Layout::ContainerBox>(layoutBox))
return;
- auto& layoutContainerBox = downcast<Layout::ContainerBox>(box);
+ auto& layoutContainerBox = downcast<Layout::ContainerBox>(layoutBox);
if (!layoutContainerBox.hasChild())
return;
@@ -176,54 +142,6 @@
}
}
-std::unique_ptr<Box> TreeBuilder::displayBoxForRootBox(const Layout::BoxGeometry& geometry, const Layout::ContainerBox& rootBox) const
-{
- // FIXME: Need to do logical -> physical coordinate mapping here.
- auto borderBoxRect = LayoutRect { Layout::BoxGeometry::borderBoxRect(geometry) };
-
- auto style = Style { rootBox.style() };
- return makeUnique<ContainerBox>(snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style));
-}
-
-std::unique_ptr<Box> TreeBuilder::displayBoxForLayoutBox(const Layout::BoxGeometry& geometry, const Layout::Box& layoutBox, LayoutSize offsetFromRoot) const
-{
- // FIXME: Need to map logical to physical rects.
- auto borderBoxRect = LayoutRect { Layout::BoxGeometry::borderBoxRect(geometry) };
- borderBoxRect.move(offsetFromRoot);
- auto pixelSnappedBorderBoxRect = snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor);
-
- // FIXME: Handle isAnonymous()
- // FIXME: Do hoisting of <body> styles to the root where appropriate.
-
- // FIXME: Need to do logical -> physical coordinate mapping here.
- auto style = Style { layoutBox.style() };
-
- if (is<Layout::ReplacedBox>(layoutBox)) {
- // FIXME: Wrong; geometry needs to vend the correct replaced content rect.
- auto replacedContentRect = LayoutRect { geometry.contentBoxLeft(), geometry.contentBoxTop(), geometry.contentBoxWidth(), geometry.contentBoxHeight() };
- replacedContentRect.moveBy(borderBoxRect.location());
- auto pixelSnappedReplacedContentRect = snapRectToDevicePixels(replacedContentRect, m_pixelSnappingFactor);
-
- // FIXME: Don't assume it's an image.
- auto imageBox = makeUnique<ImageBox>(pixelSnappedBorderBoxRect, WTFMove(style), pixelSnappedReplacedContentRect);
-
- if (auto* cachedImage = downcast<Layout::ReplacedBox>(layoutBox).cachedImage())
- imageBox->setImage(cachedImage->image());
-
- computeBoxDecorationData(*imageBox, layoutBox, geometry, offsetFromRoot);
- return imageBox;
- }
-
- if (is<Layout::ContainerBox>(layoutBox)) {
- // FIXME: The decision to make a ContainerBox should be made based on whether this Display::Box will have children.
- auto containerBox = makeUnique<ContainerBox>(pixelSnappedBorderBoxRect, WTFMove(style));
- computeBoxDecorationData(*containerBox, layoutBox, geometry, offsetFromRoot);
- return containerBox;
- }
-
- return makeUnique<Box>(snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style));
-}
-
#if ENABLE(TREE_DEBUGGING)
static void outputDisplayBox(TextStream& stream, const Box& displayBox, unsigned)
Modified: trunk/Source/WebCore/display/DisplayTreeBuilder.h (268958 => 268959)
--- trunk/Source/WebCore/display/DisplayTreeBuilder.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/DisplayTreeBuilder.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -27,6 +27,7 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+#include "DisplayBoxFactory.h"
#include <wtf/IsoMalloc.h>
#if ENABLE(TREE_DEBUGGING)
@@ -62,11 +63,6 @@
Display::Box* currentChild { nullptr };
};
- std::unique_ptr<Box> displayBoxForRootBox(const Layout::BoxGeometry&, const Layout::ContainerBox&) const;
- std::unique_ptr<Box> displayBoxForLayoutBox(const Layout::BoxGeometry&, const Layout::Box&, LayoutSize offsetFromRoot) const;
-
- void computeBoxDecorationData(BoxModelBox&, const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot) const;
-
void recursiveBuildDisplayTree(const Layout::LayoutState&, LayoutSize offsetFromRoot, const Layout::Box&, InsertionPosition&) const;
void buildInlineDisplayTree(const Layout::LayoutState&, LayoutSize offsetFromRoot, const Layout::ContainerBox&, InsertionPosition&) const;
@@ -73,7 +69,7 @@
void insert(std::unique_ptr<Box>&&, InsertionPosition&) const;
- float m_pixelSnappingFactor { 1 };
+ BoxFactory m_boxFactory;
};
#if ENABLE(TREE_DEBUGGING)
Modified: trunk/Source/WebCore/display/css/DisplayBoxDecorationData.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayBoxDecorationData.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayBoxDecorationData.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -24,7 +24,7 @@
*/
#include "config.h"
-#include "DisplayBox.h"
+#include "DisplayBoxDecorationData.h"
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
@@ -34,20 +34,9 @@
namespace WebCore {
namespace Display {
-std::unique_ptr<BoxDecorationData> BoxDecorationData::create(const Box& displayBox, const Layout::Box& layoutBox, const Layout::BoxGeometry& layoutGeometry, LayoutSize offsetFromRoot, float pixelSnappingFactor)
-{
- auto backgroundImageGeometry = calculateFillLayerImageGeometry(displayBox, layoutBox, layoutGeometry, offsetFromRoot, pixelSnappingFactor);
+BoxDecorationData::BoxDecorationData() = default;
- auto boxDecorationData = makeUnique<BoxDecorationData>();
- boxDecorationData->setBackgroundImageGeometry(backgroundImageGeometry);
- // FIXME: Compute rounded border rect.
-
- return boxDecorationData;
-}
-
-BoxDecorationData::BoxDecorationData() = default;
-
} // namespace Display
} // namespace WebCore
Modified: trunk/Source/WebCore/display/css/DisplayBoxDecorationData.h (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayBoxDecorationData.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayBoxDecorationData.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -44,8 +44,6 @@
class BoxDecorationData {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(BoxDecorationData);
public:
- static std::unique_ptr<BoxDecorationData> create(const Box&, const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot, float pixelSnappingFactor);
-
BoxDecorationData();
const Vector<FillLayerImageGeometry, 1> backgroundImageGeometry() const { return m_backgroundImageGeometry; }
Added: trunk/Source/WebCore/display/css/DisplayBoxFactory.cpp (0 => 268959)
--- trunk/Source/WebCore/display/css/DisplayBoxFactory.cpp (rev 0)
+++ trunk/Source/WebCore/display/css/DisplayBoxFactory.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DisplayBoxFactory.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "DisplayBoxDecorationData.h"
+#include "DisplayFillLayerImageGeometry.h"
+#include "DisplayImageBox.h"
+#include "DisplayTextBox.h"
+#include "LayoutBoxGeometry.h"
+#include "LayoutContainerBox.h"
+#include "LayoutReplacedBox.h"
+
+namespace WebCore {
+namespace Display {
+
+BoxFactory::BoxFactory(float pixelSnappingFactor)
+ : m_pixelSnappingFactor(pixelSnappingFactor)
+{
+}
+
+std::unique_ptr<Box> BoxFactory::displayBoxForRootBox(const Layout::ContainerBox& rootLayoutBox, const Layout::BoxGeometry& geometry) const
+{
+ // FIXME: Need to do logical -> physical coordinate mapping here.
+ auto borderBoxRect = LayoutRect { Layout::BoxGeometry::borderBoxRect(geometry) };
+
+ auto style = Style { rootLayoutBox.style() };
+ auto rootBox = makeUnique<ContainerBox>(snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style));
+ setupBoxModelBox(*rootBox, rootLayoutBox, geometry, { });
+ return rootBox;
+}
+
+std::unique_ptr<Box> BoxFactory::displayBoxForLayoutBox(const Layout::Box& layoutBox, const Layout::BoxGeometry& geometry, LayoutSize offsetFromRoot) const
+{
+ // FIXME: Need to map logical to physical rects.
+ auto borderBoxRect = LayoutRect { Layout::BoxGeometry::borderBoxRect(geometry) };
+ borderBoxRect.move(offsetFromRoot);
+ auto pixelSnappedBorderBoxRect = snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor);
+
+ // FIXME: Handle isAnonymous()
+ // FIXME: Do hoisting of <body> styles to the root where appropriate.
+
+ // FIXME: Need to do logical -> physical coordinate mapping here.
+ auto style = Style { layoutBox.style() };
+
+ if (is<Layout::ReplacedBox>(layoutBox)) {
+ // FIXME: Don't assume it's an image.
+ RefPtr<Image> image;
+ if (auto* cachedImage = downcast<Layout::ReplacedBox>(layoutBox).cachedImage())
+ image = cachedImage->image();
+
+ auto imageBox = makeUnique<ImageBox>(pixelSnappedBorderBoxRect, WTFMove(style), WTFMove(image));
+ setupBoxModelBox(*imageBox, layoutBox, geometry, offsetFromRoot);
+ return imageBox;
+ }
+
+ if (is<Layout::ContainerBox>(layoutBox)) {
+ // FIXME: The decision to make a ContainerBox should be made based on whether this Display::Box will have children.
+ auto containerBox = makeUnique<ContainerBox>(pixelSnappedBorderBoxRect, WTFMove(style));
+ setupBoxModelBox(*containerBox, layoutBox, geometry, offsetFromRoot);
+ return containerBox;
+ }
+
+ return makeUnique<Box>(snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style));
+}
+
+std::unique_ptr<Box> BoxFactory::displayBoxForTextRun(const Layout::LineRun& run, const Layout::InlineLineGeometry& lineGeometry, LayoutSize offsetFromRoot) const
+{
+ ASSERT(run.text());
+ auto lineRect = lineGeometry.logicalRect();
+ auto lineLayoutRect = LayoutRect { lineRect.left(), lineRect.top(), lineRect.width(), lineRect.height() };
+
+ auto runRect = LayoutRect { run.logicalLeft(), run.logicalTop(), run.logicalWidth(), run.logicalHeight() };
+ runRect.moveBy(lineLayoutRect.location());
+ runRect.move(offsetFromRoot);
+
+ auto style = Style { run.layoutBox().style() };
+ return makeUnique<TextBox>(snapRectToDevicePixels(runRect, m_pixelSnappingFactor), WTFMove(style), run);
+}
+
+void BoxFactory::setupBoxGeometry(BoxModelBox& box, const Layout::Box&, const Layout::BoxGeometry& layoutGeometry, LayoutSize offsetFromRoot) const
+{
+ auto borderBoxRect = LayoutRect { Layout::BoxGeometry::borderBoxRect(layoutGeometry) };
+ borderBoxRect.move(offsetFromRoot);
+
+ auto paddingBoxRect = LayoutRect { layoutGeometry.paddingBox() };
+ paddingBoxRect.moveBy(borderBoxRect.location());
+ box.setAbsolutePaddingBoxRect(snapRectToDevicePixels(paddingBoxRect, m_pixelSnappingFactor));
+
+ auto contentBoxRect = LayoutRect { layoutGeometry.contentBox() };
+ contentBoxRect.moveBy(borderBoxRect.location());
+ box.setAbsoluteContentBoxRect(snapRectToDevicePixels(contentBoxRect, m_pixelSnappingFactor));
+
+ if (is<ReplacedBox>(box)) {
+ auto& replacedBox = downcast<ReplacedBox>(box);
+ // FIXME: Need to get the correct rect taking object-fit etc into account.
+ auto replacedContentRect = LayoutRect { layoutGeometry.contentBoxLeft(), layoutGeometry.contentBoxTop(), layoutGeometry.contentBoxWidth(), layoutGeometry.contentBoxHeight() };
+ replacedContentRect.moveBy(borderBoxRect.location());
+ auto pixelSnappedReplacedContentRect = snapRectToDevicePixels(replacedContentRect, m_pixelSnappingFactor);
+ replacedBox.setReplacedContentRect(pixelSnappedReplacedContentRect);
+ }
+}
+
+std::unique_ptr<BoxDecorationData> BoxFactory::constructBoxDecorationData(const Layout::Box& layoutBox, const Layout::BoxGeometry& layoutGeometry, LayoutSize offsetFromRoot) const
+{
+ auto backgroundImageGeometry = calculateFillLayerImageGeometry(layoutBox, layoutGeometry, offsetFromRoot, m_pixelSnappingFactor);
+
+ auto boxDecorationData = makeUnique<BoxDecorationData>();
+ boxDecorationData->setBackgroundImageGeometry(backgroundImageGeometry);
+
+ // FIXME: Compute rounded border rect.
+
+ return boxDecorationData;
+}
+
+void BoxFactory::setupBoxModelBox(BoxModelBox& box, const Layout::Box& layoutBox, const Layout::BoxGeometry& layoutGeometry, LayoutSize offsetFromRoot) const
+{
+ setupBoxGeometry(box, layoutBox, layoutGeometry, offsetFromRoot);
+
+ // FIXME: Check for rounded borders when supported.
+ if (!box.style().hasBackground())
+ return;
+
+ auto boxDecorationData = constructBoxDecorationData(layoutBox, layoutGeometry, offsetFromRoot);
+ box.setBoxDecorationData(WTFMove(boxDecorationData));
+}
+
+
+
+} // namespace Display
+} // namespace WebCore
+
+#endif // ENABLE(LAYOUT_FORMATTING_CONTEXT)
Copied: trunk/Source/WebCore/display/css/DisplayBoxFactory.h (from rev 268958, trunk/Source/WebCore/display/DisplayTreeBuilder.h) (0 => 268959)
--- trunk/Source/WebCore/display/css/DisplayBoxFactory.h (rev 0)
+++ trunk/Source/WebCore/display/css/DisplayBoxFactory.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutSize.h"
+#include <wtf/IsoMalloc.h>
+
+namespace WebCore {
+
+namespace Layout {
+class Box;
+class BoxGeometry;
+class InlineLineGeometry;
+class ReplacedBox;
+struct LineRun;
+}
+
+namespace Display {
+
+class Box;
+class BoxDecorationData;
+class BoxModelBox;
+
+class BoxFactory {
+public:
+ explicit BoxFactory(float pixelSnappingFactor);
+
+ std::unique_ptr<Box> displayBoxForRootBox(const Layout::ContainerBox&, const Layout::BoxGeometry&) const;
+ std::unique_ptr<Box> displayBoxForLayoutBox(const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot) const;
+
+ std::unique_ptr<Box> displayBoxForTextRun(const Layout::LineRun&, const Layout::InlineLineGeometry&, LayoutSize offsetFromRoot) const;
+private:
+
+ void setupBoxGeometry(BoxModelBox&, const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot) const;
+ void setupBoxModelBox(BoxModelBox&, const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot) const;
+
+ std::unique_ptr<BoxDecorationData> constructBoxDecorationData(const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot) const;
+
+ float m_pixelSnappingFactor { 1 };
+};
+
+} // namespace Display
+} // namespace WebCore
+
+
+#endif // ENABLE(LAYOUT_FORMATTING_CONTEXT)
Modified: trunk/Source/WebCore/display/css/DisplayBoxModelBox.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayBoxModelBox.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayBoxModelBox.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -47,7 +47,6 @@
m_boxDecorationData = WTFMove(decorationData);
}
-
String BoxModelBox::debugDescription() const
{
TextStream stream;
Modified: trunk/Source/WebCore/display/css/DisplayBoxModelBox.h (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayBoxModelBox.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayBoxModelBox.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -43,19 +43,19 @@
virtual ~BoxModelBox();
AbsoluteFloatRect absoluteBorderBoxRect() const { return absoluteBoxRect(); }
-
AbsoluteFloatRect absolutePaddingBoxRect() const { return m_paddingBoxRect; }
- void setAbsolutePaddingBoxRect(const AbsoluteFloatRect& box) { m_paddingBoxRect = box; }
-
AbsoluteFloatRect absoluteContentBoxRect() const { return m_contentBoxRect; }
- void setAbsoluteContentBoxRect(const AbsoluteFloatRect& box) { m_contentBoxRect = box; }
const BoxDecorationData* boxDecorationData() const { return m_boxDecorationData.get(); }
- void setBoxDecorationData(std::unique_ptr<BoxDecorationData>&&);
virtual String debugDescription() const;
private:
+ friend class BoxFactory;
+ void setAbsolutePaddingBoxRect(const AbsoluteFloatRect& box) { m_paddingBoxRect = box; }
+ void setAbsoluteContentBoxRect(const AbsoluteFloatRect& box) { m_contentBoxRect = box; }
+ void setBoxDecorationData(std::unique_ptr<BoxDecorationData>&&);
+
AbsoluteFloatRect m_paddingBoxRect;
AbsoluteFloatRect m_contentBoxRect;
Modified: trunk/Source/WebCore/display/css/DisplayCSSPainter.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayCSSPainter.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayCSSPainter.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -202,8 +202,6 @@
if (is<TextBox>(box)) {
auto& textBox = downcast<TextBox>(box);
- if (!textBox.text())
- return;
auto& style = box.style();
auto textRect = box.absoluteBoxRect();
@@ -215,7 +213,7 @@
auto baseline = textRect.y() + style.fontMetrics().ascent();
auto expansion = textBox.expansion();
- auto textRun = TextRun { textBox.text()->content().substring(textBox.text()->start(), textBox.text()->length()), textRect.x(), expansion.horizontalExpansion, expansion.behavior };
+ auto textRun = TextRun { textBox.text().content().substring(textBox.text().start(), textBox.text().length()), textRect.x(), expansion.horizontalExpansion, expansion.behavior };
textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
context.drawText(style.fontCascade(), textRun, { textRect.x(), baseline });
Modified: trunk/Source/WebCore/display/css/DisplayFillLayerImageGeometry.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayFillLayerImageGeometry.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayFillLayerImageGeometry.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -374,7 +374,7 @@
return pixelSnappedFillLayerImageGeometry(destinationRect, tileSize, phase, spaceSize, fillLayer.attachment(), pixelSnappingFactor);
}
-Vector<FillLayerImageGeometry, 1> calculateFillLayerImageGeometry(const Box&, const Layout::Box& layoutBox, const Layout::BoxGeometry& boxGeometry, LayoutSize offsetFromRoot, float pixelSnappingFactor)
+Vector<FillLayerImageGeometry, 1> calculateFillLayerImageGeometry(const Layout::Box& layoutBox, const Layout::BoxGeometry& boxGeometry, LayoutSize offsetFromRoot, float pixelSnappingFactor)
{
auto& renderStyle = layoutBox.style();
Modified: trunk/Source/WebCore/display/css/DisplayFillLayerImageGeometry.h (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayFillLayerImageGeometry.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayFillLayerImageGeometry.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -29,6 +29,7 @@
#include "FloatRect.h"
#include "LayoutRect.h"
+#include "RenderStyleConstants.h"
namespace WebCore {
class FillLayer;
@@ -79,7 +80,7 @@
bool m_hasNonLocalGeometry { false }; // Has background-attachment: fixed. Implies that we can't always cheaply compute destRect.
};
-Vector<FillLayerImageGeometry, 1> calculateFillLayerImageGeometry(const Box&, const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot, float pixelSnappingFactor);
+Vector<FillLayerImageGeometry, 1> calculateFillLayerImageGeometry(const Layout::Box&, const Layout::BoxGeometry&, LayoutSize offsetFromRoot, float pixelSnappingFactor);
} // namespace Display
} // namespace WebCore
Modified: trunk/Source/WebCore/display/css/DisplayImageBox.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayImageBox.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayImageBox.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -34,16 +34,12 @@
namespace WebCore {
namespace Display {
-ImageBox::ImageBox(AbsoluteFloatRect borderBox, Style&& displayStyle, AbsoluteFloatRect replacedContentRect)
- : ReplacedBox(borderBox, WTFMove(displayStyle), { Flags::ImageBox }, replacedContentRect)
+ImageBox::ImageBox(AbsoluteFloatRect borderBox, Style&& displayStyle, RefPtr<Image>&& image)
+ : ReplacedBox(borderBox, WTFMove(displayStyle), { Flags::ImageBox })
+ , m_image(WTFMove(image))
{
}
-void ImageBox::setImage(Image* image)
-{
- m_image = image;
-}
-
String ImageBox::debugDescription() const
{
TextStream stream;
Modified: trunk/Source/WebCore/display/css/DisplayImageBox.h (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayImageBox.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayImageBox.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -40,10 +40,9 @@
class ImageBox : public ReplacedBox {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ImageBox);
public:
- ImageBox(AbsoluteFloatRect borderBox, Style&&, AbsoluteFloatRect replacedContentRect);
-
+ ImageBox(AbsoluteFloatRect borderBox, Style&&, RefPtr<Image>&&);
+
Image* image() const { return m_image.get(); }
- void setImage(Image*);
private:
String debugDescription() const final;
Modified: trunk/Source/WebCore/display/css/DisplayReplacedBox.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayReplacedBox.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayReplacedBox.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -33,9 +33,8 @@
namespace WebCore {
namespace Display {
-ReplacedBox::ReplacedBox(AbsoluteFloatRect borderBox, Style&& displayStyle, OptionSet<Flags> flags, AbsoluteFloatRect replacedContentRect)
+ReplacedBox::ReplacedBox(AbsoluteFloatRect borderBox, Style&& displayStyle, OptionSet<Flags> flags)
: BoxModelBox(borderBox, WTFMove(displayStyle), flags)
- , m_replacedContentRect(replacedContentRect)
{
}
Modified: trunk/Source/WebCore/display/css/DisplayReplacedBox.h (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayReplacedBox.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayReplacedBox.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -35,11 +35,14 @@
class ReplacedBox : public BoxModelBox {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ReplacedBox);
public:
- ReplacedBox(AbsoluteFloatRect borderBox, Style&&, OptionSet<Flags>, AbsoluteFloatRect replacedContentRect);
+ ReplacedBox(AbsoluteFloatRect borderBox, Style&&, OptionSet<Flags>);
AbsoluteFloatRect replacedContentRect() const { return m_replacedContentRect; }
private:
+ friend class BoxFactory;
+ void setReplacedContentRect(const AbsoluteFloatRect& box) { m_replacedContentRect = box; }
+
AbsoluteFloatRect m_replacedContentRect;
};
Modified: trunk/Source/WebCore/display/css/DisplayTextBox.cpp (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayTextBox.cpp 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayTextBox.cpp 2020-10-25 20:26:01 UTC (rev 268959)
@@ -37,7 +37,7 @@
TextBox::TextBox(AbsoluteFloatRect borderBox, Style&& displayStyle, const Layout::LineRun& lineRun)
: Box(borderBox, WTFMove(displayStyle), { Flags::TextBox })
, m_expansion(lineRun.expansion())
- , m_text(lineRun.text())
+ , m_text(lineRun.text().value())
{
}
@@ -46,17 +46,15 @@
TextStream stream;
stream << "text box " << absoluteBoxRect() << " (" << this << ")";
- if (text()) {
- auto textContent = text()->content().substring(text()->start(), text()->length());
- textContent.replaceWithLiteral('\\', "\\\\");
- textContent.replaceWithLiteral('\n', "\\n");
- const size_t maxPrintedLength = 80;
- if (textContent.length() > maxPrintedLength) {
- auto substring = textContent.substring(0, maxPrintedLength);
- stream << " \"" << substring << "\"…";
- } else
- stream << " \"" << textContent << "\"";
- }
+ auto textContent = text().content().substring(text().start(), text().length());
+ textContent.replaceWithLiteral('\\', "\\\\");
+ textContent.replaceWithLiteral('\n', "\\n");
+ const size_t maxPrintedLength = 80;
+ if (textContent.length() > maxPrintedLength) {
+ auto substring = textContent.substring(0, maxPrintedLength);
+ stream << " \"" << substring << "\"…";
+ } else
+ stream << " \"" << textContent << "\"";
return stream.release();
}
Modified: trunk/Source/WebCore/display/css/DisplayTextBox.h (268958 => 268959)
--- trunk/Source/WebCore/display/css/DisplayTextBox.h 2020-10-25 19:52:34 UTC (rev 268958)
+++ trunk/Source/WebCore/display/css/DisplayTextBox.h 2020-10-25 20:26:01 UTC (rev 268959)
@@ -40,7 +40,7 @@
TextBox(AbsoluteFloatRect borderBox, Style&&, const Layout::LineRun&);
Layout::LineRun::Expansion expansion() const { return m_expansion; }
- Optional<Layout::LineRun::Text> text() const {return m_text; }
+ const Layout::LineRun::Text& text() const { return m_text; }
private:
@@ -47,7 +47,7 @@
String debugDescription() const final;
Layout::LineRun::Expansion m_expansion;
- Optional<Layout::LineRun::Text> m_text;
+ Layout::LineRun::Text m_text;
};
} // namespace Display