TextManipulationController should use weak pointers to Node
https://bugs.webkit.org/show_bug.cgi?id=215913
Reviewed by Wenson Hsieh.
Use WeakHashSet for m_manipulatedTextsWithNewContent, m_textNodesWithNewRenderer, and m_manipulatedNodes.
Also made TextManipulationController::removeNode take Node& instead of Node*.
* dom/Node.cpp:
(WebCore::Node::~Node):
(WebCore::Node::moveNodeToNewDocument):
* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::observeParagraphs):
(WebCore::TextManipulationController::didCreateRendererForElement):
(WebCore::TextManipulationController::didUpdateContentForText):
(WebCore::TextManipulationController::didCreateRendererForTextNode):
(WebCore::TextManipulationController::scheduleObservationUpdate):
(WebCore::TextManipulationController::replace):
(WebCore::TextManipulationController::removeNode):
* editing/TextManipulationController.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@275859 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TextManipulationController.cpp b/Source/WebCore/editing/TextManipulationController.cpp
index 49a5cff..4191b4d 100644
--- a/Source/WebCore/editing/TextManipulationController.cpp
+++ b/Source/WebCore/editing/TextManipulationController.cpp
@@ -475,7 +475,7 @@
enclosingItemBoundaryElements.removeLast();
}
- if (m_manipulatedNodes.contains(contentNode)) {
+ if (m_manipulatedNodes.contains(*contentNode)) {
addItemIfPossible(std::exchange(unitsInCurrentParagraph, { }));
continue;
}
@@ -532,7 +532,7 @@
void TextManipulationController::didCreateRendererForElement(Element& element)
{
- if (m_manipulatedNodes.contains(&element))
+ if (m_manipulatedNodes.contains(element))
return;
scheduleObservationUpdate();
@@ -546,22 +546,22 @@
void TextManipulationController::didUpdateContentForText(Text& text)
{
- if (!m_manipulatedNodes.contains(&text))
+ if (!m_manipulatedNodes.contains(text))
return;
scheduleObservationUpdate();
- m_manipulatedTextsWithNewContent.add(&text);
+ m_manipulatedTextsWithNewContent.add(text);
}
void TextManipulationController::didCreateRendererForTextNode(Text& text)
{
- if (m_manipulatedNodes.contains(&text))
+ if (m_manipulatedNodes.contains(text))
return;
scheduleObservationUpdate();
- m_textNodesWithNewRenderer.add(&text);
+ m_textNodesWithNewRenderer.add(text);
}
void TextManipulationController::scheduleObservationUpdate()
@@ -586,16 +586,16 @@
nodesToObserve.add(weakElement);
controller->m_elementsWithNewRenderer.clear();
- for (auto* text : controller->m_manipulatedTextsWithNewContent) {
+ for (auto& text : controller->m_manipulatedTextsWithNewContent) {
if (!controller->m_manipulatedNodes.contains(text))
continue;
controller->m_manipulatedNodes.remove(text);
- nodesToObserve.add(*text);
+ nodesToObserve.add(text);
}
controller->m_manipulatedTextsWithNewContent.clear();
- for (auto* text : controller->m_textNodesWithNewRenderer)
- nodesToObserve.add(*text);
+ for (auto& text : controller->m_textNodesWithNewRenderer)
+ nodesToObserve.add(text);
controller->m_textNodesWithNewRenderer.clear();
if (nodesToObserve.isEmpty())
@@ -925,13 +925,13 @@
}
if (insertion.isChildManipulated == IsNodeManipulated::Yes)
- m_manipulatedNodes.add(insertion.child.ptr());
+ m_manipulatedNodes.add(insertion.child.get());
}
return WTF::nullopt;
}
-void TextManipulationController::removeNode(Node* node)
+void TextManipulationController::removeNode(Node& node)
{
m_manipulatedNodes.remove(node);
m_textNodesWithNewRenderer.remove(node);