Diff
Modified: trunk/Source/WebCore/ChangeLog (283233 => 283234)
--- trunk/Source/WebCore/ChangeLog 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/ChangeLog 2021-09-29 17:58:33 UTC (rev 283234)
@@ -1,3 +1,39 @@
+2021-09-29 Alan Bujtas <[email protected]>
+
+ [LFC][IFC] Layout::Box should be able to return the first-line style when applicable
+ https://bugs.webkit.org/show_bug.cgi?id=230921
+
+ Reviewed by Antti Koivisto.
+
+ This is in preparation for supporting first-line style.
+
+ * layout/integration/LayoutIntegrationBoxTree.cpp:
+ (WebCore::LayoutIntegration::rootBoxFirstLineStyle):
+ (WebCore::LayoutIntegration::BoxTree::BoxTree):
+ (WebCore::LayoutIntegration::BoxTree::buildTree):
+ (WebCore::LayoutIntegration::BoxTree::updateStyle):
+ * layout/layouttree/LayoutBox.cpp:
+ (WebCore::Layout::Box::Box): Use the rare data to store first-line style.
+ (WebCore::Layout::Box::updateStyle):
+ * layout/layouttree/LayoutBox.h:
+ (WebCore::Layout::Box::firstLineStyle const):
+ * layout/layouttree/LayoutContainerBox.cpp:
+ (WebCore::Layout::ContainerBox::ContainerBox):
+ * layout/layouttree/LayoutContainerBox.h:
+ (WebCore::Layout::ContainerBox::ContainerBox):
+ * layout/layouttree/LayoutInitialContainingBlock.cpp:
+ (WebCore::Layout::InitialContainingBlock::InitialContainingBlock):
+ * layout/layouttree/LayoutInitialContainingBlock.h:
+ * layout/layouttree/LayoutInlineTextBox.cpp:
+ (WebCore::Layout::InlineTextBox::InlineTextBox):
+ * layout/layouttree/LayoutInlineTextBox.h:
+ * layout/layouttree/LayoutLineBreakBox.cpp:
+ (WebCore::Layout::LineBreakBox::LineBreakBox):
+ * layout/layouttree/LayoutLineBreakBox.h:
+ * layout/layouttree/LayoutReplacedBox.cpp:
+ (WebCore::Layout::ReplacedBox::ReplacedBox):
+ * layout/layouttree/LayoutReplacedBox.h:
+
2021-09-29 Alexey Shvayka <[email protected]>
[WebIDL] Align property order of DOM constructors with ECMA-262 counterparts
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -43,6 +43,9 @@
static constexpr size_t smallTreeThreshold = 8;
+// FIXME: see webkit.org/b/230964
+#define CAN_USE_FIRST_LINE_STYLE_RESOLVE 0
+
static RenderStyle rootBoxStyle(const RenderStyle& style)
{
auto clonedStyle = RenderStyle::clone(style);
@@ -50,9 +53,24 @@
return clonedStyle;
}
+static std::unique_ptr<RenderStyle> rootBoxFirstLineStyle(const RenderBlockFlow& root)
+{
+#if CAN_USE_FIRST_LINE_STYLE_RESOLVE
+ auto& firstLineStyle = root.firstLineStyle();
+ if (root.style() == firstLineStyle)
+ return { };
+ auto clonedStyle = RenderStyle::clonePtr(firstLineStyle);
+ clonedStyle->setEffectiveDisplay(DisplayType::Block);
+ return clonedStyle;
+#else
+ UNUSED_PARAM(root);
+ return { };
+#endif
+}
+
BoxTree::BoxTree(RenderBlockFlow& flow)
: m_flow(flow)
- , m_root(rootBoxStyle(flow.style()))
+ , m_root(rootBoxStyle(flow.style()), rootBoxFirstLineStyle(flow))
{
if (flow.isAnonymous())
m_root.setIsAnonymous();
@@ -63,27 +81,38 @@
void BoxTree::buildTree()
{
auto createChildBox = [&](RenderObject& childRenderer) -> std::unique_ptr<Layout::Box> {
+ std::unique_ptr<RenderStyle> firstLineStyle;
+#if CAN_USE_FIRST_LINE_STYLE_RESOLVE
+ if (&childRenderer.style() != &childRenderer.firstLineStyle())
+ firstLineStyle = RenderStyle::clonePtr(childRenderer.firstLineStyle());
+#endif
if (is<RenderText>(childRenderer)) {
auto& textRenderer = downcast<RenderText>(childRenderer);
auto style = RenderStyle::createAnonymousStyleWithDisplay(textRenderer.style(), DisplayType::Inline);
return makeUnique<Layout::InlineTextBox>(
style.textSecurity() == TextSecurity::None ? textRenderer.text() : RenderBlock::updateSecurityDiscCharacters(style, textRenderer.text())
- , textRenderer.canUseSimplifiedTextMeasuring(), WTFMove(style));
+ , textRenderer.canUseSimplifiedTextMeasuring(), WTFMove(style), WTFMove(firstLineStyle));
}
auto style = RenderStyle::clone(childRenderer.style());
if (childRenderer.isLineBreak()) {
- style.setDisplay(DisplayType::Inline);
- style.setFloating(Float::None);
- style.setPosition(PositionType::Static);
- return makeUnique<Layout::LineBreakBox>(downcast<RenderLineBreak>(childRenderer).isWBR(), WTFMove(style));
+ auto adjustStyle = [&] (auto& styleToAdjust) {
+ styleToAdjust.setDisplay(DisplayType::Inline);
+ styleToAdjust.setFloating(Float::None);
+ styleToAdjust.setPosition(PositionType::Static);
+ };
+ adjustStyle(style);
+ if (firstLineStyle)
+ adjustStyle(*firstLineStyle);
+
+ return makeUnique<Layout::LineBreakBox>(downcast<RenderLineBreak>(childRenderer).isWBR(), WTFMove(style), WTFMove(firstLineStyle));
}
if (is<RenderReplaced>(childRenderer))
- return makeUnique<Layout::ReplacedBox>(Layout::Box::ElementAttributes { is<RenderImage>(childRenderer) ? Layout::Box::ElementType::Image : Layout::Box::ElementType::GenericElement }, WTFMove(style));
+ return makeUnique<Layout::ReplacedBox>(Layout::Box::ElementAttributes { is<RenderImage>(childRenderer) ? Layout::Box::ElementType::Image : Layout::Box::ElementType::GenericElement }, WTFMove(style), WTFMove(firstLineStyle));
if (is<RenderBlock>(childRenderer))
- return makeUnique<Layout::ReplacedBox>(Layout::Box::ElementAttributes { Layout::Box::ElementType::GenericElement }, WTFMove(style));
+ return makeUnique<Layout::ReplacedBox>(Layout::Box::ElementAttributes { Layout::Box::ElementType::GenericElement }, WTFMove(style), WTFMove(firstLineStyle));
if (is<RenderInline>(childRenderer)) {
if (childRenderer.parent()->isAnonymousBlock()) {
@@ -91,18 +120,23 @@
auto& renderInline = downcast<RenderInline>(childRenderer);
auto shouldNotRetainBorderPaddingAndMarginStart = renderInline.isContinuation();
auto shouldNotRetainBorderPaddingAndMarginEnd = !renderInline.isContinuation() && renderInline.inlineContinuation();
- if (shouldNotRetainBorderPaddingAndMarginStart) {
- style.setMarginStart(RenderStyle::initialMargin());
- style.resetBorderLeft();
- style.setPaddingLeft(RenderStyle::initialPadding());
- }
- if (shouldNotRetainBorderPaddingAndMarginEnd) {
- style.setMarginEnd(RenderStyle::initialMargin());
- style.resetBorderRight();
- style.setPaddingRight(RenderStyle::initialPadding());
- }
+ auto adjustStyleForContinuation = [&] (auto& styleToAdjust) {
+ if (shouldNotRetainBorderPaddingAndMarginStart) {
+ styleToAdjust.setMarginStart(RenderStyle::initialMargin());
+ styleToAdjust.resetBorderLeft();
+ styleToAdjust.setPaddingLeft(RenderStyle::initialPadding());
+ }
+ if (shouldNotRetainBorderPaddingAndMarginEnd) {
+ styleToAdjust.setMarginEnd(RenderStyle::initialMargin());
+ styleToAdjust.resetBorderRight();
+ styleToAdjust.setPaddingRight(RenderStyle::initialPadding());
+ }
+ };
+ adjustStyleForContinuation(style);
+ if (firstLineStyle)
+ adjustStyleForContinuation(*firstLineStyle);
}
- return makeUnique<Layout::ContainerBox>(Layout::Box::ElementAttributes { Layout::Box::ElementType::GenericElement }, WTFMove(style));
+ return makeUnique<Layout::ContainerBox>(Layout::Box::ElementAttributes { Layout::Box::ElementType::GenericElement }, WTFMove(style), WTFMove(firstLineStyle));
}
ASSERT_NOT_REACHED();
@@ -138,15 +172,25 @@
{
auto& layoutBox = layoutBoxForRenderer(renderer);
auto& style = renderer.style();
+ auto firstLineStyle = [&] () -> std::unique_ptr<RenderStyle> {
+#if CAN_USE_FIRST_LINE_STYLE_RESOLVE
+ if (&renderer.style() != &renderer.firstLineStyle())
+ return RenderStyle::clonePtr(renderer.firstLineStyle());
+ return nullptr;
+#else
+ return nullptr;
+#endif
+ };
+
if (&layoutBox == &rootLayoutBox())
- layoutBox.updateStyle(rootBoxStyle(style));
+ layoutBox.updateStyle(rootBoxStyle(style), rootBoxFirstLineStyle(downcast<RenderBlockFlow>(renderer)));
else
- layoutBox.updateStyle(style);
+ layoutBox.updateStyle(style, firstLineStyle());
if (is<Layout::ContainerBox>(layoutBox)) {
for (auto* child = downcast<Layout::ContainerBox>(layoutBox).firstChild(); child; child = child->nextSibling()) {
if (child->isInlineTextBox())
- child->updateStyle(RenderStyle::createAnonymousStyleWithDisplay(style, DisplayType::Inline));
+ child->updateStyle(RenderStyle::createAnonymousStyleWithDisplay(style, DisplayType::Inline), firstLineStyle());
}
}
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -42,7 +42,7 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(Box);
-Box::Box(std::optional<ElementAttributes> attributes, RenderStyle&& style, OptionSet<BaseTypeFlag> baseTypeFlags)
+Box::Box(std::optional<ElementAttributes> attributes, RenderStyle&& style, std::unique_ptr<RenderStyle>&& firstLineStyle, OptionSet<BaseTypeFlag> baseTypeFlags)
: m_style(WTFMove(style))
, m_elementAttributes(attributes)
, m_baseTypeFlags(baseTypeFlags.toRaw())
@@ -49,6 +49,8 @@
, m_hasRareData(false)
, m_isAnonymous(false)
{
+ if (firstLineStyle)
+ ensureRareData().firstLineStyle = WTFMove(firstLineStyle);
}
Box::~Box()
@@ -57,9 +59,11 @@
removeRareData();
}
-void Box::updateStyle(const RenderStyle& newStyle)
+void Box::updateStyle(const RenderStyle& newStyle, std::unique_ptr<RenderStyle>&& newFirstLineStyle)
{
m_style = RenderStyle::clone(newStyle);
+ if (newFirstLineStyle)
+ ensureRareData().firstLineStyle = WTFMove(newFirstLineStyle);
}
bool Box::establishesFormattingContext() const
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2021-09-29 17:58:33 UTC (rev 283234)
@@ -159,8 +159,9 @@
bool isPaddingApplicable() const;
bool isOverflowVisible() const;
- void updateStyle(const RenderStyle& newStyle);
+ void updateStyle(const RenderStyle& newStyle, std::unique_ptr<RenderStyle>&& newFirstLineStyle);
const RenderStyle& style() const { return m_style; }
+ const RenderStyle& firstLineStyle() const { return hasRareData() && rareData().firstLineStyle ? *rareData().firstLineStyle : m_style; }
// FIXME: Find a better place for random DOM things.
void setRowSpan(size_t);
@@ -183,7 +184,7 @@
void setCachedGeometryForLayoutState(LayoutState&, std::unique_ptr<BoxGeometry>) const;
protected:
- Box(std::optional<ElementAttributes>, RenderStyle&&, OptionSet<BaseTypeFlag>);
+ Box(std::optional<ElementAttributes>, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle, OptionSet<BaseTypeFlag>);
private:
class BoxRareData {
@@ -193,6 +194,7 @@
CellSpan tableCellSpan;
std::optional<LayoutUnit> columnWidth;
+ std::unique_ptr<RenderStyle> firstLineStyle;
};
bool hasRareData() const { return m_hasRareData; }
Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ContainerBox);
-ContainerBox::ContainerBox(std::optional<ElementAttributes> attributes, RenderStyle&& style, OptionSet<BaseTypeFlag> baseTypeFlags)
- : Box(attributes, WTFMove(style), baseTypeFlags | ContainerBoxFlag)
+ContainerBox::ContainerBox(std::optional<ElementAttributes> attributes, RenderStyle&& style, std::unique_ptr<RenderStyle>&& firstLineStyle, OptionSet<BaseTypeFlag> baseTypeFlags)
+ : Box(attributes, WTFMove(style), WTFMove(firstLineStyle), baseTypeFlags | ContainerBoxFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h 2021-09-29 17:58:33 UTC (rev 283234)
@@ -39,7 +39,7 @@
class ContainerBox : public Box {
WTF_MAKE_ISO_ALLOCATED(ContainerBox);
public:
- ContainerBox(std::optional<ElementAttributes>, RenderStyle&&, OptionSet<BaseTypeFlag> = { ContainerBoxFlag });
+ ContainerBox(std::optional<ElementAttributes>, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle = nullptr, OptionSet<BaseTypeFlag> = { ContainerBoxFlag });
const Box* firstChild() const { return m_firstChild; }
const Box* firstInFlowChild() const;
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(InitialContainingBlock);
-InitialContainingBlock::InitialContainingBlock(RenderStyle&& style)
- : ContainerBox({ }, WTFMove(style), Box::InitialContainingBlockFlag)
+InitialContainingBlock::InitialContainingBlock(RenderStyle&& style, std::unique_ptr<RenderStyle>&& firstLineStyle)
+ : ContainerBox({ }, WTFMove(style), WTFMove(firstLineStyle), Box::InitialContainingBlockFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.h (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.h 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.h 2021-09-29 17:58:33 UTC (rev 283234)
@@ -36,7 +36,7 @@
class InitialContainingBlock final : public ContainerBox {
WTF_MAKE_ISO_ALLOCATED(InitialContainingBlock);
public:
- InitialContainingBlock(RenderStyle&&);
+ InitialContainingBlock(RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle = nullptr);
virtual ~InitialContainingBlock() = default;
private:
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(InlineTextBox);
-InlineTextBox::InlineTextBox(String content, bool canUseSimplifiedContentMeasuring, RenderStyle&& style)
- : Box({ }, WTFMove(style), Box::InlineTextBoxFlag)
+InlineTextBox::InlineTextBox(String content, bool canUseSimplifiedContentMeasuring, RenderStyle&& style, std::unique_ptr<RenderStyle>&& firstLineStyle)
+ : Box({ }, WTFMove(style), WTFMove(firstLineStyle), Box::InlineTextBoxFlag)
, m_content(content)
, m_canUseSimplifiedContentMeasuring(canUseSimplifiedContentMeasuring)
{
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.h (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.h 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.h 2021-09-29 17:58:33 UTC (rev 283234)
@@ -37,7 +37,7 @@
class InlineTextBox : public Box {
WTF_MAKE_ISO_ALLOCATED(InlineTextBox);
public:
- InlineTextBox(String, bool canUseSimplifiedContentMeasuring, RenderStyle&&);
+ InlineTextBox(String, bool canUseSimplifiedContentMeasuring, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle = nullptr);
virtual ~InlineTextBox() = default;
String content() const { return m_content; }
Modified: trunk/Source/WebCore/layout/layouttree/LayoutLineBreakBox.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutLineBreakBox.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutLineBreakBox.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(LineBreakBox);
-LineBreakBox::LineBreakBox(bool isOptional, RenderStyle&& style)
- : Box({ }, WTFMove(style), Box::LineBreakBoxFlag)
+LineBreakBox::LineBreakBox(bool isOptional, RenderStyle&& style, std::unique_ptr<RenderStyle>&& firstLineStyle)
+ : Box({ }, WTFMove(style), WTFMove(firstLineStyle), Box::LineBreakBoxFlag)
, m_isOptional(isOptional)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutLineBreakBox.h (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutLineBreakBox.h 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutLineBreakBox.h 2021-09-29 17:58:33 UTC (rev 283234)
@@ -37,7 +37,7 @@
class LineBreakBox : public Box {
WTF_MAKE_ISO_ALLOCATED(LineBreakBox);
public:
- LineBreakBox(bool isOptional, RenderStyle&&);
+ LineBreakBox(bool isOptional, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle = nullptr);
bool isOptional() const { return m_isOptional; }
Modified: trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.cpp (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.cpp 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.cpp 2021-09-29 17:58:33 UTC (rev 283234)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ReplacedBox);
-ReplacedBox::ReplacedBox(std::optional<ElementAttributes> elementAttributes, RenderStyle&& style)
- : Box(elementAttributes, WTFMove(style), Box::ReplacedBoxFlag)
+ReplacedBox::ReplacedBox(std::optional<ElementAttributes> elementAttributes, RenderStyle&& style, std::unique_ptr<RenderStyle>&& firstLineStyle)
+ : Box(elementAttributes, WTFMove(style), WTFMove(firstLineStyle), Box::ReplacedBoxFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.h (283233 => 283234)
--- trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.h 2021-09-29 17:17:05 UTC (rev 283233)
+++ trunk/Source/WebCore/layout/layouttree/LayoutReplacedBox.h 2021-09-29 17:58:33 UTC (rev 283234)
@@ -39,7 +39,7 @@
class ReplacedBox : public Box {
WTF_MAKE_ISO_ALLOCATED(ReplacedBox);
public:
- ReplacedBox(std::optional<ElementAttributes>, RenderStyle&&);
+ ReplacedBox(std::optional<ElementAttributes>, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle = nullptr);
virtual ~ReplacedBox() = default;
void setCachedImage(CachedImage& cachedImage) { m_cachedImage = &cachedImage; }