Skip to content
Permalink
Browse files
Factor render tree mutation code from RenderListItem to RenderTreeUpd…
…ater

https://bugs.webkit.org/show_bug.cgi?id=175718

Reviewed by Andreas Kling.

We already stopped doing layout time mutations. We can now move the code out too.

* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderListItem.cpp:
(WebCore::isHTMLListElement):
(WebCore::getParentOfFirstLineBox): Deleted.
(WebCore::firstNonMarkerChild): Deleted.
(WebCore::RenderListItem::updateMarkerRenderer): Deleted.

    Moved to RenderTreeUpdater::ListItem.

* rendering/RenderListItem.h:
* rendering/RenderListMarker.cpp:
(WebCore::RenderListMarker::willBeDestroyed):
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::adjustTextNodeSizes):
* style/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::pushParent):
(WebCore::RenderTreeUpdater::popParent):
(WebCore::RenderTreeUpdater::updateBeforeDescendants):
(WebCore::RenderTreeUpdater::updateAfterDescendants):

    Factor pre/post update into functions.

(WebCore::RenderTreeUpdater::updateBeforeOrAfterPseudoElement):
* style/RenderTreeUpdater.h:
* style/RenderTreeUpdaterListItem.cpp: Added.

    Mutation functions move here.

(WebCore::getParentOfFirstLineBox):
(WebCore::firstNonMarkerChild):
(WebCore::RenderTreeUpdater::ListItem::updateMarker):
* style/RenderTreeUpdaterListItem.h: Added.


Canonical link: https://commits.webkit.org/192378@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
anttijk committed Aug 18, 2017
1 parent cf7268b commit 83566081a7754f7552b74a94535daf70a49bc134
Showing 11 changed files with 251 additions and 106 deletions.
@@ -2796,6 +2796,7 @@ set(WebCore_SOURCES
style/RenderTreePosition.cpp
style/RenderTreeUpdater.cpp
style/RenderTreeUpdaterFirstLetter.cpp
style/RenderTreeUpdaterListItem.cpp
style/StyleChange.cpp
style/StyleFontSizeFunctions.cpp
style/StyleInvalidator.cpp
@@ -1,3 +1,45 @@
2017-08-18 Antti Koivisto <antti@apple.com>

Factor render tree mutation code from RenderListItem to RenderTreeUpdater
https://bugs.webkit.org/show_bug.cgi?id=175718

Reviewed by Andreas Kling.

We already stopped doing layout time mutations. We can now move the code out too.

* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderListItem.cpp:
(WebCore::isHTMLListElement):
(WebCore::getParentOfFirstLineBox): Deleted.
(WebCore::firstNonMarkerChild): Deleted.
(WebCore::RenderListItem::updateMarkerRenderer): Deleted.

Moved to RenderTreeUpdater::ListItem.

* rendering/RenderListItem.h:
* rendering/RenderListMarker.cpp:
(WebCore::RenderListMarker::willBeDestroyed):
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::adjustTextNodeSizes):
* style/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::pushParent):
(WebCore::RenderTreeUpdater::popParent):
(WebCore::RenderTreeUpdater::updateBeforeDescendants):
(WebCore::RenderTreeUpdater::updateAfterDescendants):

Factor pre/post update into functions.

(WebCore::RenderTreeUpdater::updateBeforeOrAfterPseudoElement):
* style/RenderTreeUpdater.h:
* style/RenderTreeUpdaterListItem.cpp: Added.

Mutation functions move here.

(WebCore::getParentOfFirstLineBox):
(WebCore::firstNonMarkerChild):
(WebCore::RenderTreeUpdater::ListItem::updateMarker):
* style/RenderTreeUpdaterListItem.h: Added.

2017-08-18 Ms2ger <Ms2ger@gmail.com>

[GTK] Show controls if a video element isn't allowed to play inline.
@@ -6792,6 +6792,9 @@
E48284081F44594C00863AC3 /* RenderTreeUpdaterFirstLetter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48284061F44594B00863AC3 /* RenderTreeUpdaterFirstLetter.cpp */; };
E48944A2180B57D800F165D8 /* SimpleLineLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48944A0180B57D800F165D8 /* SimpleLineLayout.cpp */; };
E48944A3180B57D800F165D8 /* SimpleLineLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = E48944A1180B57D800F165D8 /* SimpleLineLayout.h */; settings = {ATTRIBUTES = (Private, ); }; };
E48E332C1F47037C00BAB0EF /* RenderTreeUpdaterFirstLetter.h in Headers */ = {isa = PBXBuildFile; fileRef = E48284091F44595600863AC3 /* RenderTreeUpdaterFirstLetter.h */; };
E48E332D1F47038000BAB0EF /* RenderTreeUpdaterListItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48E332A1F46C98000BAB0EF /* RenderTreeUpdaterListItem.cpp */; };
E48E332E1F47038000BAB0EF /* RenderTreeUpdaterListItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E48E33281F46C97F00BAB0EF /* RenderTreeUpdaterListItem.h */; };
E4916FF7195DF6A0005AB349 /* LayerFlushThrottleState.h in Headers */ = {isa = PBXBuildFile; fileRef = E4916FF6195DF6A0005AB349 /* LayerFlushThrottleState.h */; settings = {ATTRIBUTES = (Private, ); }; };
E4946EAE156E64DD00D3297F /* StyleRuleImport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4946EAC156E64DD00D3297F /* StyleRuleImport.cpp */; };
E4946EAF156E64DD00D3297F /* StyleRuleImport.h in Headers */ = {isa = PBXBuildFile; fileRef = E4946EAD156E64DD00D3297F /* StyleRuleImport.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -15405,6 +15408,8 @@
E48284091F44595600863AC3 /* RenderTreeUpdaterFirstLetter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeUpdaterFirstLetter.h; sourceTree = "<group>"; };
E48944A0180B57D800F165D8 /* SimpleLineLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleLineLayout.cpp; sourceTree = "<group>"; };
E48944A1180B57D800F165D8 /* SimpleLineLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayout.h; sourceTree = "<group>"; };
E48E33281F46C97F00BAB0EF /* RenderTreeUpdaterListItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderTreeUpdaterListItem.h; sourceTree = "<group>"; };
E48E332A1F46C98000BAB0EF /* RenderTreeUpdaterListItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeUpdaterListItem.cpp; sourceTree = "<group>"; };
E4916FF6195DF6A0005AB349 /* LayerFlushThrottleState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayerFlushThrottleState.h; sourceTree = "<group>"; };
E4946EAC156E64DD00D3297F /* StyleRuleImport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleRuleImport.cpp; sourceTree = "<group>"; };
E4946EAD156E64DD00D3297F /* StyleRuleImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleRuleImport.h; sourceTree = "<group>"; };
@@ -24917,6 +24922,8 @@
E46180281C8A06CD0026C02C /* RenderTreeUpdater.h */,
E48284061F44594B00863AC3 /* RenderTreeUpdaterFirstLetter.cpp */,
E48284091F44595600863AC3 /* RenderTreeUpdaterFirstLetter.h */,
E48E332A1F46C98000BAB0EF /* RenderTreeUpdaterListItem.cpp */,
E48E33281F46C97F00BAB0EF /* RenderTreeUpdaterListItem.h */,
E401E0A51C3C0CF700F34D10 /* StyleChange.cpp */,
E401E0A31C3C0B8300F34D10 /* StyleChange.h */,
E4D58EB617B4ED8900CBDCA8 /* StyleFontSizeFunctions.cpp */,
@@ -27807,6 +27814,7 @@
1AE96A8D1D1A0DDD00B86768 /* JSApplePayPaymentMethodSelectedEvent.h in Headers */,
7C65231A1E00DBB500677F22 /* JSApplePayPaymentPass.h in Headers */,
7C6579F21E00856600E3A27A /* JSApplePayPaymentRequest.h in Headers */,
E48E332C1F47037C00BAB0EF /* RenderTreeUpdaterFirstLetter.h in Headers */,
1AE96A8F1D1A0DDD00B86768 /* JSApplePaySession.h in Headers */,
1AE96A911D1A0DDD00B86768 /* JSApplePayShippingContactSelectedEvent.h in Headers */,
7C6579F41E00856600E3A27A /* JSApplePayShippingMethod.h in Headers */,
@@ -29807,6 +29815,7 @@
BC22747B0E8366E200E7F975 /* SVGRenderStyleDefs.h in Headers */,
436708F212D9CA4B00044234 /* SVGRenderSupport.h in Headers */,
436708F412D9CA4B00044234 /* SVGRenderTreeAsText.h in Headers */,
E48E332E1F47038000BAB0EF /* RenderTreeUpdaterListItem.h in Headers */,
436708F612D9CA4B00044234 /* SVGResources.h in Headers */,
436708F812D9CA4B00044234 /* SVGResourcesCache.h in Headers */,
436708FA12D9CA4B00044234 /* SVGResourcesCycleSolver.h in Headers */,
@@ -31936,6 +31945,7 @@
E172AF8F1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp in Sources */,
0FF3B9281EE3B6DE00B84144 /* JSDOMQuad.cpp in Sources */,
0F94A3961EF1B10500FBAFFB /* JSDOMQuadCustom.cpp in Sources */,
E48E332D1F47038000BAB0EF /* RenderTreeUpdaterListItem.cpp in Sources */,
0FF3B92A1EE3B6DE00B84144 /* JSDOMQuadInit.cpp in Sources */,
0F4710BB1DB56BE8002DCEC3 /* JSDOMRect.cpp in Sources */,
0F4710BD1DB56BE8002DCEC3 /* JSDOMRectInit.cpp in Sources */,
@@ -34,9 +34,6 @@
#include "RenderChildIterator.h"
#include "RenderInline.h"
#include "RenderListMarker.h"
#include "RenderMultiColumnFlowThread.h"
#include "RenderRuby.h"
#include "RenderTable.h"
#include "RenderView.h"
#include "StyleInheritedData.h"
#if !ASSERT_DISABLED
@@ -110,7 +107,7 @@ void RenderListItem::willBeRemovedFromTree()
updateListMarkerNumbers();
}

static inline bool isHTMLListElement(const Node& node)
bool isHTMLListElement(const Node& node)
{
return is<HTMLUListElement>(node) || is<HTMLOListElement>(node);
}
@@ -226,35 +223,6 @@ void RenderListItem::updateValueNow() const
m_isValueUpToDate = true;
}

static RenderBlock* getParentOfFirstLineBox(RenderBlock& current, RenderObject& marker)
{
bool inQuirksMode = current.document().inQuirksMode();
for (auto& child : childrenOfType<RenderObject>(current)) {
if (&child == &marker)
continue;

if (child.isInline() && (!is<RenderInline>(child) || current.generatesLineBoxesForInlineChild(&child)))
return &current;

if (child.isFloating() || child.isOutOfFlowPositioned())
continue;

if (!is<RenderBlock>(child) || is<RenderTable>(child) || is<RenderRubyAsBlock>(child))
break;

if (is<RenderBox>(child) && downcast<RenderBox>(child).isWritingModeRoot())
break;

if (is<RenderListItem>(current) && inQuirksMode && child.node() && isHTMLListElement(*child.node()))
break;

if (RenderBlock* lineBox = getParentOfFirstLineBox(downcast<RenderBlock>(child), marker))
return lineBox;
}

return nullptr;
}

void RenderListItem::updateValue()
{
if (!m_hasExplicitValue) {
@@ -264,58 +232,6 @@ void RenderListItem::updateValue()
}
}

static RenderObject* firstNonMarkerChild(RenderBlock& parent)
{
RenderObject* child = parent.firstChild();
while (is<RenderListMarker>(child))
child = child->nextSibling();
return child;
}

void RenderListItem::updateMarkerRenderer()
{
ASSERT_WITH_SECURITY_IMPLICATION(!view().layoutState());

if (style().listStyleType() == NoneListStyle && (!style().listStyleImage() || style().listStyleImage()->errorOccurred())) {
if (m_marker) {
m_marker->destroy();
ASSERT(!m_marker);
}
return;
}

auto newStyle = computeMarkerStyle();
if (m_marker)
m_marker->setStyle(WTFMove(newStyle));
else {
m_marker = createRenderer<RenderListMarker>(*this, WTFMove(newStyle)).leakPtr();
m_marker->initializeStyle();
}

RenderElement* currentParent = m_marker->parent();
RenderBlock* newParent = getParentOfFirstLineBox(*this, *m_marker);
if (!newParent) {
// If the marker is currently contained inside an anonymous box,
// then we are the only item in that anonymous box (since no line box
// parent was found). It's ok to just leave the marker where it is
// in this case.
if (currentParent && currentParent->isAnonymousBlock())
return;
if (multiColumnFlowThread())
newParent = multiColumnFlowThread();
else
newParent = this;
}

if (newParent != currentParent) {
m_marker->removeFromParent();
newParent->addChild(m_marker, firstNonMarkerChild(*newParent));
// If current parent is an anonymous block that has lost all its children, destroy it.
if (currentParent && currentParent->isAnonymousBlock() && !currentParent->firstChild() && !downcast<RenderBlock>(*currentParent).continuation())
currentParent->destroy();
}
}

void RenderListItem::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
@@ -54,9 +54,10 @@ class RenderListItem final : public RenderBlockFlow {
static void updateItemValuesForOrderedList(const HTMLOListElement&);
static unsigned itemCountForOrderedList(const HTMLOListElement&);

void didDestroyListMarker() { m_marker = nullptr; }
RenderStyle computeMarkerStyle() const;

void updateMarkerRenderer();
RenderListMarker* markerRenderer() { return m_marker; }
void setMarkerRenderer(RenderListMarker* marker) { m_marker = marker; }

#if !ASSERT_DISABLED
bool inLayout() const { return m_inLayout; }
@@ -85,7 +86,6 @@ class RenderListItem final : public RenderBlockFlow {
void updateValueNow() const;
void explicitValueChanged();

RenderStyle computeMarkerStyle() const;

int m_explicitValue;
RenderListMarker* m_marker;
@@ -98,6 +98,8 @@ class RenderListItem final : public RenderBlockFlow {
bool m_notInList : 1;
};

bool isHTMLListElement(const Node&);

} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListItem, isListItem())
@@ -1133,7 +1133,7 @@ RenderListMarker::~RenderListMarker()

void RenderListMarker::willBeDestroyed()
{
m_listItem.didDestroyListMarker();
m_listItem.setMarkerRenderer(nullptr);
if (m_image)
m_image->removeClient(this);

@@ -33,11 +33,11 @@
#include "FontCascade.h"
#include "Logging.h"
#include "RenderBlock.h"
#include "RenderListItem.h"
#include "RenderListMarker.h"
#include "RenderText.h"
#include "RenderTextFragment.h"
#include "RenderTreeUpdaterFirstLetter.h"
#include "RenderTreeUpdaterListItem.h"
#include "StyleResolver.h"

namespace WebCore {
@@ -159,7 +159,7 @@ auto TextAutoSizingValue::adjustTextNodeSizes() -> StillHasNodes
parentRenderer->setStyle(WTFMove(newParentStyle));

if (is<RenderListItem>(*parentRenderer))
downcast<RenderListItem>(*parentRenderer).updateMarkerRenderer();
RenderTreeUpdater::ListItem::updateMarker(downcast<RenderListItem>(*parentRenderer));
}

for (auto& node : m_autoSizedNodes) {
@@ -43,6 +43,7 @@
#include "RenderNamedFlowThread.h"
#include "RenderQuote.h"
#include "RenderTreeUpdaterFirstLetter.h"
#include "RenderTreeUpdaterListItem.h"
#include "StyleResolver.h"
#include "StyleTreeResolver.h"
#include <wtf/SystemTracing.h>
@@ -224,26 +225,15 @@ void RenderTreeUpdater::pushParent(Element& element, Style::Change changeType)
{
m_parentStack.append(Parent(element, changeType));

updateBeforeOrAfterPseudoElement(element, BEFORE);
updateBeforeDescendants(element);
}

void RenderTreeUpdater::popParent()
{
auto& parent = m_parentStack.last();
if (parent.element)
updateAfterDescendants(*parent.element, parent.styleChange);

if (parent.element) {
updateBeforeOrAfterPseudoElement(*parent.element, AFTER);

if (auto* renderer = parent.element->renderer()) {
if (is<RenderBlock>(*renderer))
FirstLetter::update(downcast<RenderBlock>(*renderer));
if (is<RenderListItem>(*renderer))
downcast<RenderListItem>(*renderer).updateMarkerRenderer();

if (parent.element->hasCustomStyleResolveCallbacks() && parent.styleChange == Style::Detach)
parent.element->didAttachRenderers();
}
}
m_parentStack.removeLast();
}

@@ -255,6 +245,29 @@ void RenderTreeUpdater::popParentsToDepth(unsigned depth)
popParent();
}

void RenderTreeUpdater::updateBeforeDescendants(Element& element)
{
updateBeforeOrAfterPseudoElement(element, BEFORE);
}

void RenderTreeUpdater::updateAfterDescendants(Element& element, Style::Change styleChange)
{
updateBeforeOrAfterPseudoElement(element, AFTER);

auto* renderer = element.renderer();
if (!renderer)
return;

// These functions do render tree mutations that require descendant renderers.
if (is<RenderBlock>(*renderer))
FirstLetter::update(downcast<RenderBlock>(*renderer));
if (is<RenderListItem>(*renderer))
ListItem::updateMarker(downcast<RenderListItem>(*renderer));

if (element.hasCustomStyleResolveCallbacks() && styleChange == Style::Detach)
element.didAttachRenderers();
}

static bool pseudoStyleCacheIsInvalid(RenderElement* renderer, RenderStyle* newStyle)
{
const RenderStyle& currentStyle = renderer->style();
@@ -571,7 +584,7 @@ void RenderTreeUpdater::updateBeforeOrAfterPseudoElement(Element& current, Pseud
updateQuotesUpTo(&child);
}
if (is<RenderListItem>(*pseudoRenderer))
downcast<RenderListItem>(*pseudoRenderer).updateMarkerRenderer();
ListItem::updateMarker(downcast<RenderListItem>(*pseudoRenderer));
}

void RenderTreeUpdater::tearDownRenderers(Element& root, TeardownType teardownType)
@@ -52,13 +52,16 @@ class RenderTreeUpdater {
static void tearDownRenderer(Text&);

class FirstLetter;
class ListItem;

private:
void updateRenderTree(ContainerNode& root);
void updateTextRenderer(Text&, const Style::TextUpdate*);
void updateElementRenderer(Element&, const Style::ElementUpdate&);
void createRenderer(Element&, RenderStyle&&);
void invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node&);
void updateBeforeDescendants(Element&);
void updateAfterDescendants(Element&, Style::Change);
void updateBeforeOrAfterPseudoElement(Element&, PseudoId);

struct Parent {

0 comments on commit 8356608

Please sign in to comment.