Diff
Modified: branches/safari-610.1.7-branch/Source/WebCore/ChangeLog (258352 => 258353)
--- branches/safari-610.1.7-branch/Source/WebCore/ChangeLog 2020-03-12 20:47:31 UTC (rev 258352)
+++ branches/safari-610.1.7-branch/Source/WebCore/ChangeLog 2020-03-12 21:01:41 UTC (rev 258353)
@@ -1,3 +1,7 @@
+2020-03-12 Russell Epstein <repst...@apple.com>
+
+ Revert r258093. rdar://problem/60382950
+
2020-03-11 Alan Coon <alanc...@apple.com>
Cherry-pick r258297. rdar://problem/60347323
Modified: branches/safari-610.1.7-branch/Source/WebCore/editing/TextManipulationController.cpp (258352 => 258353)
--- branches/safari-610.1.7-branch/Source/WebCore/editing/TextManipulationController.cpp 2020-03-12 20:47:31 UTC (rev 258352)
+++ branches/safari-610.1.7-branch/Source/WebCore/editing/TextManipulationController.cpp 2020-03-12 21:01:41 UTC (rev 258353)
@@ -30,7 +30,6 @@
#include "Editing.h"
#include "ElementAncestorIterator.h"
#include "EventLoop.h"
-#include "HTMLNames.h"
#include "NodeTraversal.h"
#include "PseudoElement.h"
#include "Range.h"
@@ -133,7 +132,10 @@
m_callback = WTFMove(callback);
m_exclusionRules = WTFMove(exclusionRules);
- observeParagraphs(firstPositionInNode(m_document.get()), lastPositionInNode(m_document.get()));
+ VisiblePosition start = firstPositionInNode(m_document.get());
+ VisiblePosition end = lastPositionInNode(m_document.get());
+
+ observeParagraphs(start, end);
flushPendingItemsForCallback();
}
@@ -217,38 +219,17 @@
RefPtr<Node> m_pastEndNode;
};
-static bool isAttributeForTextManipulation(const QualifiedName& nameToCheck)
+void TextManipulationController::observeParagraphs(VisiblePosition& start, VisiblePosition& end)
{
- using namespace HTMLNames;
- static const QualifiedName* const attributeNames[] = {
- &titleAttr.get(),
- &altAttr.get(),
- &placeholderAttr.get(),
- &aria_labelAttr.get(),
- &aria_placeholderAttr.get(),
- &aria_roledescriptionAttr.get(),
- &aria_valuetextAttr.get(),
- };
- for (auto& entry : attributeNames) {
- if (*entry == nameToCheck)
- return true;
- }
- return false;
-}
-
-void TextManipulationController::observeParagraphs(const Position& start, const Position& end)
-{
- auto document = makeRefPtr(start.document());
+ auto document = makeRefPtr(start.deepEquivalent().document());
ASSERT(document);
- ParagraphContentIterator iterator { start, end };
- VisiblePosition visibleStart = start;
- VisiblePosition visibleEnd = end;
- if (document != start.document() || document != end.document())
+ ParagraphContentIterator iterator { start.deepEquivalent(), end.deepEquivalent() };
+ if (document != start.deepEquivalent().document() || document != end.deepEquivalent().document())
return; // TextIterator's constructor may have updated the layout and executed arbitrary scripts.
ExclusionRuleMatcher exclusionRuleMatcher(m_exclusionRules);
Vector<ManipulationToken> tokensInCurrentParagraph;
- Position startOfCurrentParagraph = visibleStart.deepEquivalent();
+ Position startOfCurrentParagraph = start.deepEquivalent();
for (; !iterator.atEnd(); iterator.advance()) {
auto content = iterator.currentContent();
if (content.node) {
@@ -257,23 +238,7 @@
return; // We can exit early here because scheduleObservartionUpdate calls this function on each paragraph separately.
}
- if (is<Element>(*content.node)) {
- auto& currentElement = downcast<Element>(*content.node);
- if (!content.isTextContent && (content.node->hasTagName(HTMLNames::titleTag) || content.node->hasTagName(HTMLNames::optionTag))) {
- addItem(ManipulationItemData { Position(), Position(), makeWeakPtr(currentElement), nullQName(),
- { ManipulationToken { m_tokenIdentifier.generate(), currentElement.textContent() } } });
- }
- if (currentElement.hasAttributes()) {
- for (auto& attribute : currentElement.attributesIterator()) {
- if (isAttributeForTextManipulation(attribute.name())) {
- addItem(ManipulationItemData { Position(), Position(), makeWeakPtr(currentElement), attribute.name(),
- { ManipulationToken { m_tokenIdentifier.generate(), attribute.value() } } });
- }
- }
- }
- }
-
- if (startOfCurrentParagraph.isNull() && content.isTextContent)
+ if (startOfCurrentParagraph.isNull())
startOfCurrentParagraph = iterator.startPosition();
}
@@ -301,7 +266,7 @@
endOfCurrentParagraph = Position(&textNode, offsetOfNextNewLine);
startOfCurrentParagraph = Position(&textNode, offsetOfNextNewLine + 1);
}
- addItem(ManipulationItemData { startOfCurrentParagraph, endOfCurrentParagraph, nullptr, nullQName(), WTFMove(tokensInCurrentParagraph) });
+ addItem(startOfCurrentParagraph, endOfCurrentParagraph, WTFMove(tokensInCurrentParagraph));
startOfCurrentParagraph.clear();
}
startOfCurrentLine = offsetOfNextNewLine + 1;
@@ -313,7 +278,7 @@
}
if (!tokensInCurrentParagraph.isEmpty())
- addItem(ManipulationItemData { startOfCurrentParagraph, visibleEnd.deepEquivalent(), nullptr, nullQName(), WTFMove(tokensInCurrentParagraph) });
+ addItem(startOfCurrentParagraph, end.deepEquivalent(), WTFMove(tokensInCurrentParagraph));
}
void TextManipulationController::didCreateRendererForElement(Element& element)
@@ -378,13 +343,13 @@
if (!controller)
return; // Finding the start/end of paragraph may have updated layout & executed arbitrary scripts.
- controller->observeParagraphs(start.deepEquivalent(), end.deepEquivalent());
+ controller->observeParagraphs(start, end);
}
controller->flushPendingItemsForCallback();
});
}
-void TextManipulationController::addItem(ManipulationItemData&& itemData)
+void TextManipulationController::addItem(const Position& startOfParagraph, const Position& endOfParagraph, Vector<ManipulationToken>&& tokens)
{
const unsigned itemCallbackBatchingSize = 128;
@@ -392,9 +357,9 @@
auto newID = m_itemIdentifier.generate();
m_pendingItemsForCallback.append(ManipulationItem {
newID,
- itemData.tokens.map([](auto& token) { return token; })
+ tokens.map([](auto& token) { return token; })
});
- m_items.add(newID, WTFMove(itemData));
+ m_items.add(newID, ManipulationItemData { startOfParagraph, endOfParagraph, WTFMove(tokens) });
if (m_pendingItemsForCallback.size() >= itemCallbackBatchingSize)
flushPendingItemsForCallback();
@@ -459,26 +424,6 @@
size_t currentTokenIndex = 0;
HashMap<TokenIdentifier, TokenExchangeData> tokenExchangeMap;
- if (item.start.isNull() && item.end.isNull()) {
- RELEASE_ASSERT(item.tokens.size() == 1);
- auto element = makeRefPtr(item.element.get());
- if (!element)
- return ManipulationFailureType::ContentChanged;
- if (replacementTokens.size() > 1)
- return ManipulationFailureType::InvalidToken;
- String newValue;
- if (!replacementTokens.isEmpty()) {
- if (replacementTokens[0].identifier != item.tokens[0].identifier)
- return ManipulationFailureType::InvalidToken;
- newValue = replacementTokens[0].content;
- }
- if (item.attributeName == nullQName())
- element->setTextContent(newValue);
- else
- element->setAttribute(item.attributeName, newValue);
- return WTF::nullopt;
- }
-
RefPtr<Node> commonAncestor;
ParagraphContentIterator iterator { item.start, item.end };
HashSet<Ref<Node>> excludedNodes;
Modified: branches/safari-610.1.7-branch/Source/WebCore/editing/TextManipulationController.h (258352 => 258353)
--- branches/safari-610.1.7-branch/Source/WebCore/editing/TextManipulationController.h 2020-03-12 20:47:31 UTC (rev 258352)
+++ branches/safari-610.1.7-branch/Source/WebCore/editing/TextManipulationController.h 2020-03-12 21:01:41 UTC (rev 258353)
@@ -26,7 +26,6 @@
#pragma once
#include "Position.h"
-#include "QualifiedName.h"
#include <wtf/CompletionHandler.h>
#include <wtf/EnumTraits.h>
#include <wtf/ObjectIdentifier.h>
@@ -127,20 +126,16 @@
private:
bool isInManipulatedElement(Element&);
- void observeParagraphs(const Position& start, const Position& end);
+ void observeParagraphs(VisiblePosition& start, VisiblePosition& end);
void scheduleObservartionUpdate();
struct ManipulationItemData {
Position start;
Position end;
-
- WeakPtr<Element> element;
- QualifiedName attributeName { nullQName() };
-
Vector<ManipulationToken> tokens;
};
- void addItem(ManipulationItemData&&);
+ void addItem(const Position& startOfParagraph, const Position& endOfParagraph, Vector<ManipulationToken>&&);
void flushPendingItemsForCallback();
Optional<ManipulationFailureType> replace(const ManipulationItemData&, const Vector<ManipulationToken>&);
Modified: branches/safari-610.1.7-branch/Tools/ChangeLog (258352 => 258353)
--- branches/safari-610.1.7-branch/Tools/ChangeLog 2020-03-12 20:47:31 UTC (rev 258352)
+++ branches/safari-610.1.7-branch/Tools/ChangeLog 2020-03-12 21:01:41 UTC (rev 258353)
@@ -1,3 +1,7 @@
+2020-03-12 Russell Epstein <repst...@apple.com>
+
+ Revert r258093. rdar://problem/60382950
+
2020-03-09 Russell Epstein <repst...@apple.com>
Cherry-pick r258174. rdar://problem/60250780
Modified: branches/safari-610.1.7-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (258352 => 258353)
--- branches/safari-610.1.7-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2020-03-12 20:47:31 UTC (rev 258352)
+++ branches/safari-610.1.7-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2020-03-12 21:01:41 UTC (rev 258353)
@@ -216,42 +216,6 @@
EXPECT_STREQ("Kit", items[1].tokens[1].content.UTF8String);
}
-TEST(TextManipulation, StartTextManipulationFindAttributeContent)
-{
- 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><head><title>hey</title></head>"
- "<body><div><span aria-label=\"this is greet\">hello</span><img src="" alt=\"fruit\"></body></html>"];
-
- done = false;
- [webView _startTextManipulationsWithConfiguration:nil completion:^{
- done = true;
- }];
- TestWebKitAPI::Util::run(&done);
-
- auto *items = [delegate items];
- EXPECT_EQ(items.count, 4UL);
- EXPECT_EQ(items[0].tokens.count, 1UL);
- EXPECT_STREQ("hey", items[0].tokens[0].content.UTF8String);
- EXPECT_FALSE(items[0].tokens[0].isExcluded);
-
- EXPECT_EQ(items[1].tokens.count, 1UL);
- EXPECT_STREQ("this is greet", items[1].tokens[0].content.UTF8String);
- EXPECT_FALSE(items[1].tokens[0].isExcluded);
-
- EXPECT_EQ(items[2].tokens.count, 1UL);
- EXPECT_STREQ("fruit", items[2].tokens[0].content.UTF8String);
- EXPECT_FALSE(items[2].tokens[0].isExcluded);
-
- EXPECT_EQ(items[3].tokens.count, 2UL);
- EXPECT_STREQ("hello", items[3].tokens[0].content.UTF8String);
- EXPECT_FALSE(items[3].tokens[0].isExcluded);
- EXPECT_STREQ("[]", items[3].tokens[1].content.UTF8String);
- EXPECT_TRUE(items[3].tokens[1].isExcluded);
-}
-
TEST(TextManipulation, StartTextManipulationSupportsLegacyDelegateCallback)
{
auto delegate = adoptNS([[LegacyTextManipulationDelegate alloc] init]);
@@ -836,11 +800,9 @@
auto *items = [delegate items];
EXPECT_EQ(items.count, 2UL);
- EXPECT_EQ(items[0].tokens.count, 2UL);
+ EXPECT_EQ(items[0].tokens.count, 1UL);
EXPECT_STREQ("[]", items[0].tokens[0].content.UTF8String);
EXPECT_TRUE(items[0].tokens[0].isExcluded);
- EXPECT_STREQ("[]", items[0].tokens[1].content.UTF8String);
- EXPECT_TRUE(items[0].tokens[1].isExcluded);
auto *tokens = items[1].tokens;
EXPECT_EQ(tokens.count, 1UL);
@@ -862,50 +824,6 @@
[webView stringByEvaluatingJavaScript:@"document.body.innerHTML"]);
}
-TEST(TextManipulation, CompleteTextManipulationShouldReplaceAttributeContent)
-{
- 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><head><title>hey</title></head>"
- "<body><div><span aria-label=\"this is greet\">hello</span><img src="" alt=\"fruit\"></div></body></html>"];
-
- done = false;
- [webView _startTextManipulationsWithConfiguration:nil completion:^{
- done = true;
- }];
- TestWebKitAPI::Util::run(&done);
-
- auto *items = [delegate items];
- EXPECT_EQ(items.count, 4UL);
- EXPECT_EQ(items[0].tokens.count, 1UL);
- EXPECT_STREQ("hey", items[0].tokens[0].content.UTF8String);
-
- EXPECT_EQ(items[1].tokens.count, 1UL);
- EXPECT_STREQ("this is greet", items[1].tokens[0].content.UTF8String);
-
- EXPECT_EQ(items[2].tokens.count, 1UL);
- EXPECT_STREQ("fruit", items[2].tokens[0].content.UTF8String);
-
- EXPECT_EQ(items[3].tokens.count, 2UL);
- EXPECT_STREQ("hello", items[3].tokens[0].content.UTF8String);
- EXPECT_STREQ("[]", items[3].tokens[1].content.UTF8String);
-
- done = false;
- [webView _completeTextManipulationForItems:@[
- (_WKTextManipulationItem *)createItem(items[0].identifier, { { items[0].tokens[0].identifier, @"Hello" } }),
- (_WKTextManipulationItem *)createItem(items[1].identifier, { { items[1].tokens[0].identifier, @"This is a greeting" } }),
- (_WKTextManipulationItem *)createItem(items[2].identifier, { { items[2].tokens[0].identifier, @"Apple" } }),
- ] completion:^(NSArray<NSError *> *errors) {
- EXPECT_EQ(errors, nil);
- done = true;
- }];
- TestWebKitAPI::Util::run(&done);
- EXPECT_WK_STREQ("<head><title>Hello</title></head><body><div><span aria-label=\"This is a greeting\">hello</span>"
- "<img src="" alt=\"Apple\"></div></body>", [webView stringByEvaluatingJavaScript:@"document.documentElement.innerHTML"]);
-}
-
TEST(TextManipulation, CompleteTextManipulationShouldBatchItemCallback)
{
auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);