Diff
Modified: trunk/Source/WebCore/ChangeLog (263043 => 263044)
--- trunk/Source/WebCore/ChangeLog 2020-06-15 17:23:59 UTC (rev 263043)
+++ trunk/Source/WebCore/ChangeLog 2020-06-15 17:51:38 UTC (rev 263044)
@@ -1,3 +1,26 @@
+2020-06-15 Sihui Liu <[email protected]>
+
+ Text manipulation does not observe newly displayed element inside previously observed content
+ https://bugs.webkit.org/show_bug.cgi?id=213156
+
+ Reviewed by Darin Adler.
+
+ Fix two issues:
+ 1. Some inserted nodes are marked as manipulated, but they are inserted because they get removed in the
+ replacement process, not because they are manipulated or in the range of item.
+ 2. TextManipulationController does not perform manipulation on an element if its ancestor is manipulated. This
+ means the newly inserted/displayed children of a manipulated element are ruled out for manipulation.
+
+ Test: TextManipulation.CompleteTextManipulationForNewlyDisplayedParagraph
+
+ * editing/TextManipulationController.cpp:
+ (WebCore::TextManipulationController::observeParagraphs):
+ (WebCore::TextManipulationController::didCreateRendererForElement):
+ (WebCore::TextManipulationController::updateInsertions):
+ (WebCore::TextManipulationController::replace):
+ (WebCore::TextManipulationController::isInManipulatedElement): Deleted.
+ * editing/TextManipulationController.h:
+
2020-06-15 Víctor Manuel Jáquez Leal <[email protected]>
Suppress compiler warnings
Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (263043 => 263044)
--- trunk/Source/WebCore/editing/TextManipulationController.cpp 2020-06-15 17:23:59 UTC (rev 263043)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp 2020-06-15 17:51:38 UTC (rev 263044)
@@ -119,17 +119,6 @@
{
}
-bool TextManipulationController::isInManipulatedElement(Element& element)
-{
- if (!m_manipulatedElements.capacity())
- return false; // Fast path for startObservingParagraphs.
- for (auto& ancestorOrSelf : lineageOfType<Element>(element)) {
- if (m_manipulatedElements.contains(ancestorOrSelf))
- return true;
- }
- return false;
-}
-
void TextManipulationController::startObservingParagraphs(ManipulationItemCallback&& callback, Vector<ExclusionRule>&& exclusionRules)
{
auto document = makeRefPtr(m_document.get());
@@ -433,8 +422,7 @@
}
if (RefPtr<Element> currentElementAncestor = is<Element>(*contentNode) ? downcast<Element>(contentNode) : contentNode->parentOrShadowHostElement()) {
- // We can exit early here because scheduleObservationUpdate calls this function on each paragraph separately.
- if (isInManipulatedElement(*currentElementAncestor))
+ if (m_manipulatedElements.contains(*currentElementAncestor))
return;
}
@@ -488,7 +476,7 @@
void TextManipulationController::didCreateRendererForElement(Element& element)
{
- if (isInManipulatedElement(element))
+ if (m_manipulatedElements.contains(element))
return;
if (m_elementsWithNewRenderer.computesEmpty())
@@ -630,7 +618,7 @@
return path;
}
-void TextManipulationController::updateInsertions(Vector<NodeEntry>& lastTopDownPath, const Vector<Ref<Node>>& currentTopDownPath, Node* currentNode, HashSet<Ref<Node>>& insertedNodes, Vector<NodeInsertion>& insertions)
+void TextManipulationController::updateInsertions(Vector<NodeEntry>& lastTopDownPath, const Vector<Ref<Node>>& currentTopDownPath, Node* currentNode, HashSet<Ref<Node>>& insertedNodes, Vector<NodeInsertion>& insertions, IsNodeManipulated isNodeManipulated)
{
size_t i =0;
while (i < lastTopDownPath.size() && i < currentTopDownPath.size() && lastTopDownPath[i].first.ptr() == currentTopDownPath[i].ptr())
@@ -654,7 +642,7 @@
}
if (currentNode)
- insertions.append(NodeInsertion { lastTopDownPath.size() ? lastTopDownPath.last().second.ptr() : nullptr, *currentNode });
+ insertions.append(NodeInsertion { lastTopDownPath.size() ? lastTopDownPath.last().second.ptr() : nullptr, *currentNode, isNodeManipulated });
}
auto TextManipulationController::replace(const ManipulationItemData& item, const Vector<ManipulationToken>& replacementTokens) -> Optional<ManipulationFailureType>
@@ -783,7 +771,7 @@
RefPtr<Node> endNode = end.firstNode();
if (node && node != endNode) {
auto topDownPath = getPath(commonAncestor.get(), node->parentNode());
- updateInsertions(lastTopDownPath, topDownPath, nullptr, reusedOriginalNodes, insertions);
+ updateInsertions(lastTopDownPath, topDownPath, nullptr, reusedOriginalNodes, insertions, IsNodeManipulated::No);
}
while (node != endNode) {
Ref<Node> parentNode = *node->parentNode();
@@ -790,7 +778,7 @@
while (!lastTopDownPath.isEmpty() && lastTopDownPath.last().first.ptr() != parentNode.ptr())
lastTopDownPath.removeLast();
- insertions.append(NodeInsertion { lastTopDownPath.size() ? lastTopDownPath.last().second.ptr() : nullptr, *node });
+ insertions.append(NodeInsertion { lastTopDownPath.size() ? lastTopDownPath.last().second.ptr() : nullptr, *node, IsNodeManipulated::No });
lastTopDownPath.append({ *node, *node });
node = NodeTraversal::next(*node);
}
@@ -808,7 +796,7 @@
insertionPoint = positionInParentAfterNode(insertion.child.ptr());
} else
insertion.parentIfDifferentFromCommonAncestor->appendChild(insertion.child);
- if (is<Element>(insertion.child.get()))
+ if (is<Element>(insertion.child.get()) && insertion.isChildManipulated == IsNodeManipulated::Yes)
m_manipulatedElements.add(downcast<Element>(insertion.child.get()));
}
Modified: trunk/Source/WebCore/editing/TextManipulationController.h (263043 => 263044)
--- trunk/Source/WebCore/editing/TextManipulationController.h 2020-06-15 17:23:59 UTC (rev 263043)
+++ trunk/Source/WebCore/editing/TextManipulationController.h 2020-06-15 17:51:38 UTC (rev 263044)
@@ -136,7 +136,6 @@
WEBCORE_EXPORT Vector<ManipulationFailure> completeManipulation(const Vector<ManipulationItem>&);
private:
- bool isInManipulatedElement(Element&);
void observeParagraphs(const Position& start, const Position& end);
void scheduleObservationUpdate();
@@ -164,13 +163,15 @@
void addItemIfPossible(Vector<ManipulationUnit>&&);
void flushPendingItemsForCallback();
+ enum class IsNodeManipulated : bool { No, Yes };
struct NodeInsertion {
RefPtr<Node> parentIfDifferentFromCommonAncestor;
Ref<Node> child;
+ IsNodeManipulated isChildManipulated { IsNodeManipulated::Yes };
};
using NodeEntry = std::pair<Ref<Node>, Ref<Node>>;
Vector<Ref<Node>> getPath(Node*, Node*);
- void updateInsertions(Vector<NodeEntry>&, const Vector<Ref<Node>>&, Node*, HashSet<Ref<Node>>&, Vector<NodeInsertion>&);
+ void updateInsertions(Vector<NodeEntry>&, const Vector<Ref<Node>>&, Node*, HashSet<Ref<Node>>&, Vector<NodeInsertion>&, IsNodeManipulated = IsNodeManipulated::Yes);
Optional<ManipulationFailureType> replace(const ManipulationItemData&, const Vector<ManipulationToken>&);
WeakPtr<Document> m_document;
Modified: trunk/Tools/ChangeLog (263043 => 263044)
--- trunk/Tools/ChangeLog 2020-06-15 17:23:59 UTC (rev 263043)
+++ trunk/Tools/ChangeLog 2020-06-15 17:51:38 UTC (rev 263044)
@@ -1,3 +1,13 @@
+2020-06-15 Sihui Liu <[email protected]>
+
+ Text manipulation does not observe newly displayed element inside previously observed content
+ https://bugs.webkit.org/show_bug.cgi?id=213156
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+ (TestWebKitAPI::TEST):
+
2020-06-15 Philippe Normand <[email protected]>
[Flatpak SDK] Bump Subversion and enable Perl bindings
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (263043 => 263044)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2020-06-15 17:23:59 UTC (rev 263043)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2020-06-15 17:51:38 UTC (rev 263044)
@@ -2400,7 +2400,7 @@
EXPECT_WK_STREQ("<p><b><br><br>Hello<i>World</i></b>From WebKit</p>", [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"]);
}
-TEST(TextManipulation, InsertingContentIntoAlreadyManipulatedContentDoesNotCreateTextManipulationItem)
+TEST(TextManipulation, InsertingContentIntoAlreadyManipulatedContentCreatesTextManipulationItem)
{
auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
@@ -2442,7 +2442,7 @@
[webView stringByEvaluatingJavaScript:@"span = document.createElement('span'); span.textContent = ' WebKit!'; document.querySelector('b').after(span);"];
[webView waitForNextPresentationUpdate];
- EXPECT_FALSE(foundNewItemAfterCompletingTextManipulation);
+ EXPECT_TRUE(foundNewItemAfterCompletingTextManipulation);
EXPECT_WK_STREQ("<p><i><b>hello,</b><span> WebKit!</span></i> world</p>", [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"]);
}
@@ -2485,6 +2485,67 @@
EXPECT_WK_STREQ("world2", [webView stringByEvaluatingJavaScript:@"document.querySelector('input[type=submit]').value"]);
}
+TEST(TextManipulation, CompleteTextManipulationForNewlyDisplayedParagraph)
+{
+ auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+ [webView _setTextManipulationDelegate:delegate.get()];
+
+ [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><html><body>"
+ "<style> .hidden { display: none; } </style>"
+ "<div>"
+ "<b>webkit!</b>"
+ "<span>"
+ "hello world"
+ "<i class='hidden'>bye</i>"
+ "</span>"
+ "</div>"
+ "</body></html>"];
+
+ done = false;
+ [webView _startTextManipulationsWithConfiguration:nil completion:^{
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+
+ auto *items = [delegate items];
+ EXPECT_EQ(items.count, 1UL);
+ EXPECT_EQ(items[0].tokens.count, 2UL);
+ EXPECT_WK_STREQ("webkit!", items[0].tokens[0].content);
+ EXPECT_WK_STREQ("hello world", items[0].tokens[1].content);
+
+ done = false;
+ [webView _completeTextManipulationForItems:@[
+ createItem(items[0].identifier, {{ items[0].tokens[0].identifier, @"WebKit!" }, { items[0].tokens[1].identifier, @"Hello World" }}).get(),
+ ] completion:^(NSArray<NSError *> *errors) {
+ EXPECT_EQ(errors, nil);
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+
+ done = false;
+ delegate.get().itemCallback = ^(_WKTextManipulationItem *item) {
+ done = true;
+ };
+ [webView stringByEvaluatingJavaScript:@"document.querySelector('i').removeAttribute('class');"];
+ TestWebKitAPI::Util::run(&done);
+
+ EXPECT_EQ(items.count, 2UL);
+ EXPECT_EQ(items[1].tokens.count, 1UL);
+ EXPECT_WK_STREQ("bye", items[1].tokens[0].content);
+
+ done = false;
+ [webView _completeTextManipulationForItems:@[
+ createItem(items[1].identifier, {{ items[1].tokens[0].identifier, @"Bye" }}).get(),
+ ] completion:^(NSArray<NSError *> *errors) {
+ EXPECT_EQ(errors, nil);
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+
+ EXPECT_WK_STREQ("<b>WebKit!</b><span>Hello World<i>Bye</i></span>", [webView stringByEvaluatingJavaScript:@"document.querySelector('div').innerHTML"]);
+}
+
TEST(TextManipulation, TextManipulationTokenDebugDescription)
{
auto token = adoptNS([[_WKTextManipulationToken alloc] init]);