Skip to content

Commit b541bbc

Browse files
committed
Reduce use of downcast<>() in WebCore
https://bugs.webkit.org/show_bug.cgi?id=266679 Reviewed by Simon Fraser. * Source/WebCore/rendering/updating/RenderTreeBuilderMultiColumn.cpp: (WebCore::isValidColumnSpanner): (WebCore::RenderTreeBuilder::MultiColumn::createFragmentedFlow): (WebCore::RenderTreeBuilder::MultiColumn::resolveMovedChild): (WebCore::RenderTreeBuilder::MultiColumn::multiColumnDescendantInserted): (WebCore::RenderTreeBuilder::MultiColumn::processPossibleSpannerDescendant): (WebCore::RenderTreeBuilder::MultiColumn::multiColumnRelativeWillBeRemoved): (WebCore::RenderTreeBuilder::MultiColumn::adjustBeforeChildForMultiColumnSpannerIfNeeded): * Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * Source/WebCore/rendering/updating/RenderTreeBuilderTable.cpp: (WebCore::RenderTreeBuilder::Table::findOrCreateParentForChild): (WebCore::RenderTreeBuilder::Table::attach): (WebCore::RenderTreeBuilder::Table::childRequiresTable): * Source/WebCore/rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::nextSiblingRenderer const): * Source/WebCore/rendering/updating/RenderTreeUpdater.cpp: (WebCore::RenderTreeUpdater::updateRebuildRoots): (WebCore::RenderTreeUpdater::updateRenderTree): (WebCore::RenderTreeUpdater::tearDownRenderers): (WebCore::RenderTreeUpdater::tearDownLeftoverChildrenOfComposedTree): * Source/WebCore/rendering/updating/RenderTreeUpdaterGeneratedContent.cpp: (WebCore::elementIsTargetedByKeyframeEffectRequiringPseudoElement): * Source/WebCore/style/ElementRuleCollector.cpp: (WebCore::Style::ElementRuleCollector::matchAllRules): (WebCore::Style::ElementRuleCollector::addElementInlineStyleProperties): * Source/WebCore/style/FilterOperationsBuilder.cpp: (WebCore::Style::createFilterOperations): * Source/WebCore/style/InlineTextBoxStyle.cpp: (WebCore::minLogicalTopForTextDecorationLineUnder): (WebCore::maxLogicalBottomForTextDecorationLineUnder): * Source/WebCore/style/InspectorCSSOMWrappers.cpp: (WebCore::Style::InspectorCSSOMWrappers::collect): * Source/WebCore/style/RuleSetBuilder.cpp: (WebCore::Style::RuleSetBuilder::addChildRule): (WebCore::Style::RuleSetBuilder::addMutatingRulesToResolver): * Source/WebCore/style/StyleAdjuster.cpp: (WebCore::Style::Adjuster::computeEventListenerRegionTypes): * Source/WebCore/style/StyleInvalidator.cpp: (WebCore::Style::invalidateAssignedElements): * Source/WebCore/style/StyleSharingResolver.cpp: (WebCore::Style::SharingResolver::findSibling const): Canonical link: https://commits.webkit.org/272366@main
1 parent bdc9ba2 commit b541bbc

14 files changed

+173
-176
lines changed

Source/WebCore/rendering/updating/RenderTreeBuilderMultiColumn.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,29 @@ static bool isValidColumnSpanner(const RenderMultiColumnFlow& fragmentedFlow, co
7777
// We assume that we're inside the flow thread. This function is not to be called otherwise.
7878
ASSERT(descendant.isDescendantOf(&fragmentedFlow));
7979
// First make sure that the renderer itself has the right properties for becoming a spanner.
80-
if (!is<RenderBox>(descendant))
80+
auto* descendantBox = dynamicDowncast<RenderBox>(descendant);
81+
if (!descendantBox)
8182
return false;
8283

83-
auto& descendantBox = downcast<RenderBox>(descendant);
84-
if (descendantBox.isFloatingOrOutOfFlowPositioned())
84+
if (descendantBox->isFloatingOrOutOfFlowPositioned())
8585
return false;
8686

87-
if (descendantBox.style().columnSpan() != ColumnSpan::All)
87+
if (descendantBox->style().columnSpan() != ColumnSpan::All)
8888
return false;
8989

90-
auto* parent = descendantBox.parent();
90+
auto* parent = descendantBox->parent();
9191
if (!is<RenderBlockFlow>(*parent) || parent->childrenInline()) {
9292
// Needs to be block-level.
9393
return false;
9494
}
9595

9696
// We need to have the flow thread as the containing block. A spanner cannot break out of the flow thread.
97-
auto* enclosingFragmentedFlow = descendantBox.enclosingFragmentedFlow();
97+
auto* enclosingFragmentedFlow = descendantBox->enclosingFragmentedFlow();
9898
if (enclosingFragmentedFlow != &fragmentedFlow)
9999
return false;
100100

101101
// This looks like a spanner, but if we're inside something unbreakable, it's not to be treated as one.
102-
for (auto* ancestor = descendantBox.containingBlock(); ancestor; ancestor = ancestor->containingBlock()) {
102+
for (auto* ancestor = descendantBox->containingBlock(); ancestor; ancestor = ancestor->containingBlock()) {
103103
if (is<RenderView>(*ancestor))
104104
return false;
105105
if (ancestor->isLegend())
@@ -112,13 +112,12 @@ static bool isValidColumnSpanner(const RenderMultiColumnFlow& fragmentedFlow, co
112112
// implement (not to mention specify behavior).
113113
return ancestor == &fragmentedFlow;
114114
}
115-
if (is<RenderBlockFlow>(*ancestor)) {
116-
auto& blockFlowAncestor = downcast<RenderBlockFlow>(*ancestor);
117-
if (blockFlowAncestor.willCreateColumns()) {
115+
if (auto* blockFlowAncestor = dynamicDowncast<RenderBlockFlow>(*ancestor)) {
116+
if (blockFlowAncestor->willCreateColumns()) {
118117
// This ancestor (descendent of the fragmentedFlow) will create columns later. The spanner belongs to it.
119118
return false;
120119
}
121-
if (blockFlowAncestor.multiColumnFlow()) {
120+
if (blockFlowAncestor->multiColumnFlow()) {
122121
// While this ancestor (descendent of the fragmentedFlow) has a fragmented flow context, this context is being destroyed.
123122
// However the spanner still belongs to it (will most likely be moved to the parent fragmented context as the next step).
124123
return false;
@@ -158,8 +157,8 @@ void RenderTreeBuilder::MultiColumn::createFragmentedFlow(RenderBlockFlow& flow)
158157
flow.deleteLines();
159158
// If this soon-to-be multicolumn flow is already part of a multicolumn context, we need to move back the descendant spanners
160159
// to their original position before moving subtrees around.
161-
if (auto* enclosingflow = flow.enclosingFragmentedFlow(); is<RenderMultiColumnFlow>(enclosingflow))
162-
restoreColumnSpannersForContainer(flow, downcast<RenderMultiColumnFlow>(*enclosingflow));
160+
if (auto* enclosingflow = dynamicDowncast<RenderMultiColumnFlow>(flow.enclosingFragmentedFlow()))
161+
restoreColumnSpannersForContainer(flow, *enclosingflow);
163162

164163
auto newFragmentedFlow = WebCore::createRenderer<RenderMultiColumnFlow>(flow.document(), RenderStyle::createAnonymousStyleWithDisplay(flow.style(), DisplayType::Block));
165164
newFragmentedFlow->initializeStyle();
@@ -256,7 +255,8 @@ RenderObject* RenderTreeBuilder::MultiColumn::resolveMovedChild(RenderFragmented
256255
if (!is<RenderBox>(*beforeChild))
257256
return beforeChild;
258257

259-
if (!is<RenderMultiColumnFlow>(enclosingFragmentedFlow))
258+
auto* renderMultiColumnFlow = dynamicDowncast<RenderMultiColumnFlow>(enclosingFragmentedFlow);
259+
if (!renderMultiColumnFlow)
260260
return beforeChild;
261261

262262
// We only need to resolve for column spanners.
@@ -269,7 +269,7 @@ RenderObject* RenderTreeBuilder::MultiColumn::resolveMovedChild(RenderFragmented
269269
// create and insert a renderer for the sibling node immediately preceding the spanner, we need
270270
// to map that spanner renderer to the spanner's placeholder, which is where the new inserted
271271
// renderer belongs.
272-
if (auto* placeholder = downcast<RenderMultiColumnFlow>(enclosingFragmentedFlow).findColumnSpannerPlaceholder(downcast<RenderBox>(beforeChild)))
272+
if (auto* placeholder = renderMultiColumnFlow->findColumnSpannerPlaceholder(downcast<RenderBox>(beforeChild)))
273273
return placeholder;
274274

275275
// This is an invalid spanner, or its placeholder hasn't been created yet. This happens when
@@ -294,14 +294,13 @@ void RenderTreeBuilder::MultiColumn::multiColumnDescendantInserted(RenderMultiCo
294294
descendant = descendant->nextSibling();
295295
continue;
296296
}
297-
if (is<RenderMultiColumnSpannerPlaceholder>(*descendant)) {
297+
if (auto* placeholder = dynamicDowncast<RenderMultiColumnSpannerPlaceholder>(*descendant)) {
298298
// A spanner's placeholder has been inserted. The actual spanner renderer is moved from
299299
// where it would otherwise occur (if it weren't a spanner) to becoming a sibling of the
300300
// column sets.
301-
RenderMultiColumnSpannerPlaceholder& placeholder = downcast<RenderMultiColumnSpannerPlaceholder>(*descendant);
302-
ASSERT(!flow.spannerMap().get(placeholder.spanner()));
303-
flow.spannerMap().add(placeholder.spanner(), downcast<RenderMultiColumnSpannerPlaceholder>(descendant));
304-
ASSERT(!placeholder.firstChild()); // There should be no children here, but if there are, we ought to skip them.
301+
ASSERT(!flow.spannerMap().get(placeholder->spanner()));
302+
flow.spannerMap().add(placeholder->spanner(), placeholder);
303+
ASSERT(!placeholder->firstChild()); // There should be no children here, but if there are, we ought to skip them.
305304
} else
306305
descendant = processPossibleSpannerDescendant(flow, subtreeRoot, *descendant);
307306
if (descendant)
@@ -358,14 +357,13 @@ RenderObject* RenderTreeBuilder::MultiColumn::processPossibleSpannerDescendant(R
358357
nextDescendant = &placeholder;
359358
} else {
360359
// This is regular multicol content, i.e. not part of a spanner.
361-
if (is<RenderMultiColumnSpannerPlaceholder>(nextRendererInFragmentedFlow)) {
360+
if (auto* placeholder = dynamicDowncast<RenderMultiColumnSpannerPlaceholder>(nextRendererInFragmentedFlow)) {
362361
// Inserted right before a spanner. Is there a set for us there?
363-
RenderMultiColumnSpannerPlaceholder& placeholder = downcast<RenderMultiColumnSpannerPlaceholder>(*nextRendererInFragmentedFlow);
364-
if (RenderObject* previous = placeholder.spanner()->previousSibling()) {
362+
if (RenderObject* previous = placeholder->spanner()->previousSibling()) {
365363
if (is<RenderMultiColumnSet>(*previous))
366364
return nextDescendant; // There's already a set there. Nothing to do.
367365
}
368-
insertBeforeMulticolChild = placeholder.spanner();
366+
insertBeforeMulticolChild = placeholder->spanner();
369367
} else if (RenderMultiColumnSet* lastSet = flow.lastMultiColumnSet()) {
370368
// This child is not an immediate predecessor of a spanner, which means that if this
371369
// child precedes a spanner at all, there has to be a column set created for us there
@@ -419,12 +417,12 @@ void RenderTreeBuilder::MultiColumn::handleSpannerRemoval(RenderMultiColumnFlow&
419417
void RenderTreeBuilder::MultiColumn::multiColumnRelativeWillBeRemoved(RenderMultiColumnFlow& flow, RenderObject& relative, RenderTreeBuilder::CanCollapseAnonymousBlock canCollapseAnonymousBlock)
420418
{
421419
flow.invalidateFragments();
422-
if (is<RenderMultiColumnSpannerPlaceholder>(relative)) {
420+
if (auto* placeholder = dynamicDowncast<RenderMultiColumnSpannerPlaceholder>(relative)) {
423421
// Remove the map entry for this spanner, but leave the actual spanner renderer alone. Also
424422
// keep the reference to the spanner, since the placeholder may be about to be re-inserted
425423
// in the tree.
426424
ASSERT(relative.isDescendantOf(&flow));
427-
flow.spannerMap().remove(downcast<RenderMultiColumnSpannerPlaceholder>(relative).spanner());
425+
flow.spannerMap().remove(placeholder->spanner());
428426
return;
429427
}
430428
if (relative.style().columnSpan() == ColumnSpan::All) {
@@ -440,21 +438,23 @@ void RenderTreeBuilder::MultiColumn::multiColumnRelativeWillBeRemoved(RenderMult
440438

441439
RenderObject* RenderTreeBuilder::MultiColumn::adjustBeforeChildForMultiColumnSpannerIfNeeded(RenderObject& beforeChild)
442440
{
443-
if (!is<RenderBox>(beforeChild))
441+
auto* beforeChildBox = dynamicDowncast<RenderBox>(beforeChild);
442+
if (!beforeChildBox)
444443
return &beforeChild;
445444

446-
auto* nextSibling = beforeChild.nextSibling();
445+
auto* nextSibling = beforeChildBox->nextSibling();
447446
if (!nextSibling)
448447
return &beforeChild;
449448

450-
if (!is<RenderMultiColumnSet>(*nextSibling))
449+
auto* renderMultiColumnSet = dynamicDowncast<RenderMultiColumnSet>(*nextSibling);
450+
if (!renderMultiColumnSet)
451451
return &beforeChild;
452452

453-
auto* multiColumnFlow = downcast<RenderMultiColumnSet>(*nextSibling).multiColumnFlow();
453+
auto* multiColumnFlow = renderMultiColumnSet->multiColumnFlow();
454454
if (!multiColumnFlow)
455455
return &beforeChild;
456456

457-
return multiColumnFlow->findColumnSpannerPlaceholder(downcast<RenderBox>(&beforeChild));
457+
return multiColumnFlow->findColumnSpannerPlaceholder(beforeChildBox);
458458
}
459459

460460
}

Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,18 @@ RenderPtr<RenderObject> RenderTreeBuilder::Ruby::detach(RenderRubyRun& parent, R
369369
// If the child is a ruby text, then merge the ruby base with the base of
370370
// the right sibling run, if possible.
371371
if (!parent.beingDestroyed() && !parent.renderTreeBeingDestroyed() && child.isRenderRubyText()) {
372-
RenderRubyBase* base = parent.rubyBase();
373-
RenderObject* rightNeighbour = parent.nextSibling();
374-
if (base && is<RenderRubyRun>(rightNeighbour)) {
375-
// Ruby run without a base can happen only at the first run.
376-
RenderRubyRun& rightRun = downcast<RenderRubyRun>(*rightNeighbour);
377-
if (rightRun.hasRubyBase()) {
378-
RenderRubyBase* rightBase = rightRun.rubyBase();
379-
// Collect all children in a single base, then swap the bases.
380-
moveChildren(*rightBase, *base);
381-
m_builder.move(parent, rightRun, *base, RenderTreeBuilder::NormalizeAfterInsertion::No);
382-
m_builder.move(rightRun, parent, *rightBase, RenderTreeBuilder::NormalizeAfterInsertion::No);
383-
// The now empty ruby base will be removed below.
384-
ASSERT(!parent.rubyBase()->firstChild());
372+
if (auto* base = parent.rubyBase()) {
373+
if (auto* rightRun = dynamicDowncast<RenderRubyRun>(parent.nextSibling())) {
374+
// Ruby run without a base can happen only at the first run.
375+
if (rightRun->hasRubyBase()) {
376+
RenderRubyBase* rightBase = rightRun->rubyBase();
377+
// Collect all children in a single base, then swap the bases.
378+
moveChildren(*rightBase, *base);
379+
m_builder.move(parent, *rightRun, *base, RenderTreeBuilder::NormalizeAfterInsertion::No);
380+
m_builder.move(*rightRun, parent, *rightBase, RenderTreeBuilder::NormalizeAfterInsertion::No);
381+
// The now empty ruby base will be removed below.
382+
ASSERT(!parent.rubyBase()->firstChild());
383+
}
385384
}
386385
}
387386
}

0 commit comments

Comments
 (0)