Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (276132 => 276133)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2021-04-16 10:32:02 UTC (rev 276132)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2021-04-16 11:09:40 UTC (rev 276133)
@@ -43,6 +43,7 @@
#include "NodeTraversal.h"
#include "RenderObject.h"
#include "RenderText.h"
+#include "ScriptDisallowedScope.h"
#include "StyleProperties.h"
#include "StyleResolver.h"
#include "Text.h"
@@ -344,7 +345,7 @@
// Calculate loop end point.
// If the end node is before the start node (can only happen if the end node is
// an ancestor of the start node), we gather nodes up to the next sibling of the end node
- Node* beyondEnd;
+ RefPtr<Node> beyondEnd;
ASSERT(start.deprecatedNode());
ASSERT(end.deprecatedNode());
if (start.deprecatedNode()->isDescendantOf(*end.deprecatedNode()))
@@ -353,7 +354,7 @@
beyondEnd = NodeTraversal::next(*end.deprecatedNode());
start = start.upstream(); // Move upstream to ensure we do not add redundant spans.
- Node* startNode = start.deprecatedNode();
+ auto startNode = makeRefPtr(start.deprecatedNode());
// Make sure we're not already at the end or the next NodeTraversal::next() will traverse past it.
if (startNode == beyondEnd)
@@ -368,18 +369,18 @@
// Store away font size before making any changes to the document.
// This ensures that changes to one node won't effect another.
- HashMap<Node*, float> startingFontSizes;
- for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
+ HashMap<Ref<Node>, float> startingFontSizes;
+ for (auto node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
ASSERT(node);
- startingFontSizes.set(node, computedFontSize(node));
+ startingFontSizes.set(*node, computedFontSize(node.get()));
}
// These spans were added by us. If empty after font size changes, they can be removed.
Vector<Ref<HTMLElement>> unstyledSpans;
-
- Node* lastStyledNode = nullptr;
+
+ RefPtr<Node> lastStyledNode;
bool reachedEnd = false;
- for (auto node = makeRefPtr(startNode); node != beyondEnd && !reachedEnd; node = NodeTraversal::next(*node)) {
+ for (auto node = startNode; node != beyondEnd && !reachedEnd; node = NodeTraversal::next(*node)) {
ASSERT(node);
RefPtr<HTMLElement> element;
if (is<HTMLElement>(*node)) {
@@ -391,15 +392,15 @@
// Last styled node was not parent node of this text node, but we wish to style this
// text node. To make this possible, add a style span to surround this text node.
auto span = createStyleSpanElement(document());
- if (!surroundNodeRangeWithElement(*node, *node, span.copyRef()))
+ if (!surroundNodeRangeWithElement(*node, *node, span))
continue;
- reachedEnd = node->isDescendantOf(beyondEnd);
+ reachedEnd = node->isDescendantOf(beyondEnd.get());
element = WTFMove(span);
} else {
// Only handle HTML elements and text nodes.
continue;
}
- lastStyledNode = node.get();
+ lastStyledNode = node;
RefPtr<MutableStyleProperties> inlineStyle = copyStyleOrCreateEmpty(element->inlineStyle());
float currentFontSize = computedFontSize(node.get());
@@ -424,12 +425,12 @@
removeNodePreservingChildren(unstyledSpan);
}
-static ContainerNode* dummySpanAncestorForNode(const Node* node)
+static ContainerNode* dummySpanAncestorForNode(Node* node)
{
- while (node && (!is<Element>(*node) || !isStyleSpanOrSpanWithOnlyStyleAttribute(downcast<Element>(*node))))
- node = node->parentNode();
-
- return node ? node->parentNode() : nullptr;
+ RefPtr<Node> currentNode = node;
+ while (currentNode && (!is<Element>(*currentNode) || !isStyleSpanOrSpanWithOnlyStyleAttribute(downcast<Element>(*currentNode))))
+ currentNode = currentNode->parentNode();
+ return currentNode ? currentNode->parentNode() : nullptr;
}
void ApplyStyleCommand::cleanupUnstyledAppleStyleSpans(ContainerNode* dummySpanAncestor)
@@ -442,48 +443,48 @@
// cloned/split, the new node is always a sibling of it. Therefore, we scan
// all the children of the dummy's parent
- Vector<Element*> toRemove;
+ Vector<Ref<Element>> toRemove;
for (auto& child : childrenOfType<Element>(*dummySpanAncestor)) {
if (isSpanWithoutAttributesOrUnstyledStyleSpan(child))
- toRemove.append(&child);
+ toRemove.append(child);
}
for (auto& element : toRemove)
- removeNodePreservingChildren(*element);
+ removeNodePreservingChildren(element.get());
}
-HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, WritingDirection allowedDirection)
+RefPtr<HTMLElement> ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, WritingDirection allowedDirection)
{
// We are allowed to leave the highest ancestor with unicode-bidi unsplit if it is unicode-bidi: embed and direction: allowedDirection.
// In that case, we return the unsplit ancestor. Otherwise, we return 0.
- Element* block = enclosingBlock(node);
+ auto block = makeRefPtr(enclosingBlock(node));
if (!block || block == node)
- return 0;
+ return nullptr;
- Node* highestAncestorWithUnicodeBidi = nullptr;
- Node* nextHighestAncestorWithUnicodeBidi = nullptr;
+ RefPtr<Node> highestAncestorWithUnicodeBidi;
+ RefPtr<Node> nextHighestAncestorWithUnicodeBidi;
int highestAncestorUnicodeBidi = 0;
- for (Node* n = node->parentNode(); n != block; n = n->parentNode()) {
- int unicodeBidi = toIdentifier(ComputedStyleExtractor(n).propertyValue(CSSPropertyUnicodeBidi));
+ for (auto ancestor = makeRefPtr(node->parentNode()); ancestor != block; ancestor = ancestor->parentNode()) {
+ int unicodeBidi = toIdentifier(ComputedStyleExtractor(ancestor.get()).propertyValue(CSSPropertyUnicodeBidi));
if (unicodeBidi && unicodeBidi != CSSValueNormal) {
highestAncestorUnicodeBidi = unicodeBidi;
nextHighestAncestorWithUnicodeBidi = highestAncestorWithUnicodeBidi;
- highestAncestorWithUnicodeBidi = n;
+ highestAncestorWithUnicodeBidi = ancestor;
}
}
if (!highestAncestorWithUnicodeBidi)
- return 0;
+ return nullptr;
- HTMLElement* unsplitAncestor = nullptr;
+ RefPtr<HTMLElement> unsplitAncestor;
if (allowedDirection != WritingDirection::Natural && highestAncestorUnicodeBidi != CSSValueBidiOverride && is<HTMLElement>(*highestAncestorWithUnicodeBidi)) {
- auto highestAncestorDirection = EditingStyle::create(highestAncestorWithUnicodeBidi, EditingStyle::AllProperties)->textDirection();
+ auto highestAncestorDirection = EditingStyle::create(highestAncestorWithUnicodeBidi.get(), EditingStyle::AllProperties)->textDirection();
if (highestAncestorDirection && *highestAncestorDirection == allowedDirection) {
if (!nextHighestAncestorWithUnicodeBidi)
- return downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
+ return static_pointer_cast<HTMLElement>(WTFMove(highestAncestorWithUnicodeBidi));
- unsplitAncestor = downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
+ unsplitAncestor = static_pointer_cast<HTMLElement>(highestAncestorWithUnicodeBidi);
highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi;
}
}
@@ -498,17 +499,17 @@
break;
currentNode = parent;
}
+
return unsplitAncestor;
}
void ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsplitAncestor)
{
- Element* block = enclosingBlock(node);
+ auto block = makeRefPtr(enclosingBlock(node));
if (!block || block == node)
return;
- Node* parent = nullptr;
- for (Node* ancestor = node->parentNode(); ancestor != block && ancestor != unsplitAncestor; ancestor = parent) {
+ for (RefPtr<Node> ancestor = node->parentNode(), parent; ancestor != block && ancestor != unsplitAncestor; ancestor = parent) {
parent = ancestor->parentNode();
if (!is<StyledElement>(*ancestor))
continue;
@@ -527,7 +528,7 @@
// other attributes, like we (should) do with B and I elements.
removeNodeAttribute(element, dirAttr);
} else {
- RefPtr<MutableStyleProperties> inlineStyle = copyStyleOrCreateEmpty(element.inlineStyle());
+ auto inlineStyle = copyStyleOrCreateEmpty(element.inlineStyle());
inlineStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
inlineStyle->removeProperty(CSSPropertyDirection);
setNodeAttribute(element, styleAttr, inlineStyle->asText());
@@ -537,14 +538,14 @@
}
}
-static Node* highestEmbeddingAncestor(Node* startNode, Node* enclosingNode)
+static RefPtr<Node> highestEmbeddingAncestor(Node* startNode, Node* enclosingNode)
{
- for (Node* n = startNode; n && n != enclosingNode; n = n->parentNode()) {
- if (n->isHTMLElement() && toIdentifier(ComputedStyleExtractor(n).propertyValue(CSSPropertyUnicodeBidi)) == CSSValueEmbed)
- return n;
+ for (auto currentNode = makeRefPtr(startNode); currentNode && currentNode != enclosingNode; currentNode = currentNode->parentNode()) {
+ if (currentNode->isHTMLElement() && toIdentifier(ComputedStyleExtractor(currentNode.get()).propertyValue(CSSPropertyUnicodeBidi)) == CSSValueEmbed)
+ return currentNode;
}
- return 0;
+ return nullptr;
}
void ApplyStyleCommand::applyInlineStyle(EditingStyle& style)
@@ -601,19 +602,19 @@
RefPtr<EditingStyle> embeddingStyle;
if (textDirection.hasValue()) {
// Leave alone an ancestor that provides the desired single level embedding, if there is one.
- auto* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, *textDirection);
- auto* endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.deprecatedNode(), false, *textDirection);
- removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAncestor);
- removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncestor);
+ auto startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, *textDirection);
+ auto endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.deprecatedNode(), false, *textDirection);
+ removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAncestor.get());
+ removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncestor.get());
// Avoid removing the dir attribute and the unicode-bidi and direction properties from the unsplit ancestors.
Position embeddingRemoveStart = removeStart;
if (startUnsplitAncestor && nodeFullySelected(*startUnsplitAncestor, removeStart, end))
- embeddingRemoveStart = positionInParentAfterNode(startUnsplitAncestor);
+ embeddingRemoveStart = positionInParentAfterNode(startUnsplitAncestor.get());
Position embeddingRemoveEnd = end;
if (endUnsplitAncestor && nodeFullySelected(*endUnsplitAncestor, removeStart, end))
- embeddingRemoveEnd = positionInParentBeforeNode(endUnsplitAncestor).downstream();
+ embeddingRemoveEnd = positionInParentBeforeNode(endUnsplitAncestor.get()).downstream();
if (embeddingRemoveEnd != removeStart || embeddingRemoveEnd != end) {
styleWithoutEmbedding = style.copy();
@@ -652,12 +653,12 @@
RefPtr<EditingStyle> styleToApply = &style;
if (textDirection.hasValue()) {
// Avoid applying the unicode-bidi and direction properties beneath ancestors that already have them.
- Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode(), enclosingBlock(start.deprecatedNode()));
- Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode()));
+ auto embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode(), enclosingBlock(start.deprecatedNode()));
+ auto embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode()));
if (embeddingStartNode || embeddingEndNode) {
- Position embeddingApplyStart = embeddingStartNode ? positionInParentAfterNode(embeddingStartNode) : start;
- Position embeddingApplyEnd = embeddingEndNode ? positionInParentBeforeNode(embeddingEndNode) : end;
+ Position embeddingApplyStart = embeddingStartNode ? positionInParentAfterNode(embeddingStartNode.get()) : start;
+ Position embeddingApplyEnd = embeddingEndNode ? positionInParentBeforeNode(embeddingEndNode.get()) : end;
ASSERT(embeddingApplyStart.isNotNull() && embeddingApplyEnd.isNotNull());
if (!embeddingStyle) {
@@ -680,15 +681,15 @@
void ApplyStyleCommand::fixRangeAndApplyInlineStyle(EditingStyle& style, const Position& start, const Position& end)
{
- Node* startNode = start.deprecatedNode();
+ auto startNode = makeRefPtr(start.deprecatedNode());
if (start.deprecatedEditingOffset() >= caretMaxOffset(*startNode)) {
startNode = NodeTraversal::next(*startNode);
- if (!startNode || end < firstPositionInOrBeforeNode(startNode))
+ if (!startNode || end < firstPositionInOrBeforeNode(startNode.get()))
return;
}
- Node* pastEndNode = end.deprecatedNode();
+ auto pastEndNode = makeRefPtr(end.deprecatedNode());
if (end.deprecatedEditingOffset() >= caretMaxOffset(*pastEndNode))
pastEndNode = NodeTraversal::nextSkippingChildren(*pastEndNode);
@@ -702,13 +703,13 @@
// e.g. When applying font-size: large on <font color="blue">hello</font>, we need to include the font element in our run
// to generate <font color="blue" size="4">hello</font> instead of <font color="blue"><font size="4">hello</font></font>
auto range = *makeSimpleRange(start, end);
- auto* editableRoot = startNode->rootEditableElement();
+ auto editableRoot = makeRefPtr(startNode->rootEditableElement());
if (startNode != editableRoot) {
while (editableRoot && startNode->parentNode() != editableRoot && isNodeVisiblyContainedWithin(*startNode->parentNode(), range))
startNode = startNode->parentNode();
}
- applyInlineStyleToNodeRange(style, *startNode, pastEndNode);
+ applyInlineStyleToNodeRange(style, *startNode, pastEndNode.get());
}
static bool containsNonEditableRegion(Node& node)
@@ -716,8 +717,8 @@
if (!node.hasEditableStyle())
return true;
- Node* sibling = NodeTraversal::nextSkippingChildren(node);
- for (Node* descendant = node.firstChild(); descendant && descendant != sibling; descendant = NodeTraversal::next(*descendant)) {
+ auto sibling = makeRefPtr(NodeTraversal::nextSkippingChildren(node));
+ for (auto descendant = makeRefPtr(node.firstChild()); descendant && descendant != sibling; descendant = NodeTraversal::next(*descendant)) {
if (!descendant->hasEditableStyle())
return true;
}
@@ -771,7 +772,7 @@
// Add to this element's inline style and skip over its contents.
HTMLElement& element = downcast<HTMLElement>(*node);
RefPtr<MutableStyleProperties> inlineStyle = copyStyleOrCreateEmpty(element.inlineStyle());
- if (MutableStyleProperties* otherStyle = style.style())
+ if (auto otherStyle = makeRefPtr(style.style()))
inlineStyle->mergeAndOverrideOnConflict(*otherStyle);
setNodeAttribute(element, styleAttr, inlineStyle->asText());
next = NodeTraversal::nextSkippingChildren(*node);
@@ -790,20 +791,20 @@
}
}
- Node* runStart = node.get();
- Node* runEnd = node.get();
- Node* sibling = node->nextSibling();
- while (sibling && sibling != pastEndNode && !sibling->contains(pastEndNode) && (!isBlock(sibling) || sibling->hasTagName(brTag)) && !containsNonEditableRegion(*sibling)) {
+ auto runStart = node;
+ auto runEnd = node;
+ auto sibling = makeRefPtr(node->nextSibling());
+ while (sibling && sibling != pastEndNode && !sibling->contains(pastEndNode) && (!isBlock(sibling.get()) || sibling->hasTagName(brTag)) && !containsNonEditableRegion(*sibling)) {
runEnd = sibling;
sibling = runEnd->nextSibling();
}
next = NodeTraversal::nextSkippingChildren(*runEnd);
- Node* pastEndNode = NodeTraversal::nextSkippingChildren(*runEnd);
- if (!shouldApplyInlineStyleToRun(style, runStart, pastEndNode))
+ auto pastEndNode = makeRefPtr(NodeTraversal::nextSkippingChildren(*runEnd));
+ if (!shouldApplyInlineStyleToRun(style, runStart.get(), pastEndNode.get()))
continue;
- runs.append(InlineRunToApplyStyle(runStart, runEnd, pastEndNode));
+ runs.append(InlineRunToApplyStyle(runStart.get(), runEnd.get(), pastEndNode.get()));
}
for (auto& run : runs) {
@@ -835,13 +836,13 @@
{
ASSERT(runStart);
- for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversal::next(*node)) {
+ for (auto node = makeRefPtr(runStart); node && node != pastEndNode; node = NodeTraversal::next(*node)) {
if (node->hasChildNodes())
continue;
// We don't consider m_isInlineElementToRemoveFunction here because we never apply style when m_isInlineElementToRemoveFunction is specified
if (!style.styleIsPresentInComputedStyleOfNode(*node))
return true;
- if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode(node), m_styledInlineElement->tagQName()))
+ if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode(node.get()), m_styledInlineElement->tagQName()))
return true;
}
return false;
@@ -961,17 +962,17 @@
return true;
}
-HTMLElement* ApplyStyleCommand::highestAncestorWithConflictingInlineStyle(EditingStyle& style, Node* node)
+RefPtr<HTMLElement> ApplyStyleCommand::highestAncestorWithConflictingInlineStyle(EditingStyle& style, Node* node)
{
if (!node)
return nullptr;
- HTMLElement* result = nullptr;
- Node* unsplittableElement = unsplittableElementForPosition(firstPositionInOrBeforeNode(node));
+ RefPtr<HTMLElement> result;
+ auto unsplittableElement = makeRefPtr(unsplittableElementForPosition(firstPositionInOrBeforeNode(node)));
- for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
+ for (auto ancestor = makeRefPtr(node); ancestor; ancestor = ancestor->parentNode()) {
if (is<HTMLElement>(*ancestor) && shouldRemoveInlineStyleFromElement(style, downcast<HTMLElement>(*ancestor)))
- result = downcast<HTMLElement>(ancestor);
+ result = static_pointer_cast<HTMLElement>(ancestor);
// Should stop at the editable root (cannot cross editing boundary) and
// also stop at the unsplittable element to be consistent with other UAs
if (ancestor == unsplittableElement)
@@ -1001,11 +1002,15 @@
return;
}
- if (node.renderer()->isText() && static_cast<RenderText*>(node.renderer())->isAllCollapsibleWhitespace())
- return;
- if (node.renderer()->isBR() && !node.renderer()->style().preserveNewline())
- return;
+ {
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+ if (node.renderer()->isText() && static_cast<RenderText*>(node.renderer())->isAllCollapsibleWhitespace())
+ return;
+ if (node.renderer()->isBR() && !node.renderer()->style().preserveNewline())
+ return;
+ }
+
// We can't wrap node with the styled element here because new styled element will never be removed if we did.
// If we modified the child pointer in pushDownInlineStyleAroundNode to point to new style element
// then we fall into an infinite loop where we keep removing and adding styled element wrapping node.
@@ -1014,7 +1019,7 @@
void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle& style, Node* targetNode)
{
- HTMLElement* highestAncestor = highestAncestorWithConflictingInlineStyle(style, targetNode);
+ auto highestAncestor = highestAncestorWithConflictingInlineStyle(style, targetNode);
if (!highestAncestor)
return;
@@ -1076,13 +1081,13 @@
// If the pushDownStart is at the end of a text node, then this node is not fully selected.
// Move it to the next deep quivalent position to avoid removing the style from this node.
// e.g. if pushDownStart was at Position("hello", 5) in <b>hello<div>world</div></b>, we want Position("world", 0) instead.
- auto* pushDownStartContainer = pushDownStart.containerNode();
+ auto pushDownStartContainer = makeRefPtr(pushDownStart.containerNode());
if (is<Text>(pushDownStartContainer) && static_cast<unsigned>(pushDownStart.computeOffsetInContainerNode()) == downcast<Text>(*pushDownStartContainer).length())
pushDownStart = nextVisuallyDistinctCandidate(pushDownStart);
// If pushDownEnd is at the start of a text node, then this node is not fully selected.
// Move it to the previous deep equivalent position to avoid removing the style from this node.
Position pushDownEnd = end.upstream();
- auto* pushDownEndContainer = pushDownEnd.containerNode();
+ auto pushDownEndContainer = makeRefPtr(pushDownEnd.containerNode());
if (is<Text>(pushDownEndContainer) && !pushDownEnd.computeOffsetInContainerNode())
pushDownEnd = previousVisuallyDistinctCandidate(pushDownEnd);
@@ -1243,11 +1248,11 @@
bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start, const Position& end)
{
- auto* startNode = start.containerNode();
+ auto startNode = makeRefPtr(start.containerNode());
if (start.computeOffsetInContainerNode())
return false;
- if (isAtomicNode(startNode)) {
+ if (isAtomicNode(startNode.get())) {
// note: prior siblings could be unrendered elements. it's silly to miss the
// merge opportunity just for that.
if (startNode->previousSibling())
@@ -1256,7 +1261,7 @@
startNode = startNode->parentNode();
}
- auto* previousSibling = startNode->previousSibling();
+ auto previousSibling = makeRefPtr(startNode->previousSibling());
if (!previousSibling || !areIdenticalElements(*startNode, *previousSibling))
return false;
@@ -1269,7 +1274,7 @@
// FIXME: Inconsistent that we use computeOffsetInContainerNode for start, but deprecatedEditingOffset for end.
unsigned startOffset = startChild->computeNodeIndex();
unsigned endOffset = end.deprecatedEditingOffset() + (startNode == end.deprecatedNode() ? startOffset : 0);
- updateStartEnd({ startNode, startOffset, Position::PositionIsOffsetInAnchor },
+ updateStartEnd({ startNode.get(), startOffset, Position::PositionIsOffsetInAnchor },
{ end.deprecatedNode(), endOffset, Position::PositionIsOffsetInAnchor });
return true;
}
@@ -1276,11 +1281,11 @@
bool ApplyStyleCommand::mergeEndWithNextIfIdentical(const Position& start, const Position& end)
{
- Node* endNode = end.containerNode();
+ auto endNode = makeRefPtr(end.containerNode());
- if (isAtomicNode(endNode)) {
+ if (isAtomicNode(endNode.get())) {
int endOffset = end.computeOffsetInContainerNode();
- if (offsetIsBeforeLastNodeOffset(endOffset, endNode) || end.deprecatedNode()->nextSibling())
+ if (offsetIsBeforeLastNodeOffset(endOffset, endNode.get()) || end.deprecatedNode()->nextSibling())
return false;
endNode = end.deprecatedNode()->parentNode();
@@ -1289,7 +1294,7 @@
if (endNode->hasTagName(brTag))
return false;
- Node* nextSibling = endNode->nextSibling();
+ auto nextSibling = makeRefPtr(endNode->nextSibling());
if (!nextSibling || !areIdenticalElements(*endNode, *nextSibling))
return false;
@@ -1336,7 +1341,7 @@
mergeIdenticalElements(element, downcast<Element>(*nextSibling));
if (is<Element>(previousSibling) && previousSibling->hasEditableStyle()) {
- auto* mergedElement = previousSibling->nextSibling();
+ auto mergedElement = makeRefPtr(previousSibling->nextSibling());
ASSERT(mergedElement);
if (mergedElement->hasEditableStyle() && areIdenticalElements(*previousSibling, *mergedElement))
mergeIdenticalElements(downcast<Element>(*previousSibling), downcast<Element>(*mergedElement));
@@ -1399,8 +1404,8 @@
ASSERT(endNode->isConnected());
// Find appropriate font and span elements top-down.
- HTMLFontElement* fontContainer = nullptr;
- HTMLElement* styleContainer = nullptr;
+ RefPtr<HTMLFontElement> fontContainer;
+ RefPtr<HTMLElement> styleContainer;
while (startNode == endNode) {
if (is<HTMLElement>(*startNode)) {
auto& container = downcast<HTMLElement>(*startNode);
@@ -1497,7 +1502,7 @@
textNodes.append(*textNode);
for (auto& childText : textNodes) {
- Node* next = childText->nextSibling();
+ auto next = makeRefPtr(childText->nextSibling());
if (!is<Text>(next))
continue;