Title: [260583] trunk
- Revision
- 260583
- Author
- [email protected]
- Date
- 2020-04-23 11:09:29 -0700 (Thu, 23 Apr 2020)
Log Message
Add a heuristic for text manipulation to treat some list items as paragraph boundaries
https://bugs.webkit.org/show_bug.cgi?id=210915
<rdar://problem/61907080>
Reviewed by Megan Gardner.
Source/WebCore:
Adds a mechanism to allow text manipulation to emit an item containing the current list of text manipulation
tokens early, in the case where the paragraph content iterator crosses the boundary of an element that encloses
a paragraph. Currently, the only enclosing paragraph element will be list items that have `display: block;`,
which we can take as a hint that the text in these list items should be vended as separate items, rather than as
tokens in a single item.
This may be extended in the future to other situations by adjusting logic in `isEnclosingParagraphElement`.
Test: TextManipulation.StartTextManipulationBreaksParagraphInBetweenListItems
* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::observeParagraphs):
Tools:
Add a new API test to exercise text manipulation over several different cases of lists and list items.
* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (260582 => 260583)
--- trunk/Source/WebCore/ChangeLog 2020-04-23 17:49:44 UTC (rev 260582)
+++ trunk/Source/WebCore/ChangeLog 2020-04-23 18:09:29 UTC (rev 260583)
@@ -1,3 +1,24 @@
+2020-04-23 Wenson Hsieh <[email protected]>
+
+ Add a heuristic for text manipulation to treat some list items as paragraph boundaries
+ https://bugs.webkit.org/show_bug.cgi?id=210915
+ <rdar://problem/61907080>
+
+ Reviewed by Megan Gardner.
+
+ Adds a mechanism to allow text manipulation to emit an item containing the current list of text manipulation
+ tokens early, in the case where the paragraph content iterator crosses the boundary of an element that encloses
+ a paragraph. Currently, the only enclosing paragraph element will be list items that have `display: block;`,
+ which we can take as a hint that the text in these list items should be vended as separate items, rather than as
+ tokens in a single item.
+
+ This may be extended in the future to other situations by adjusting logic in `isEnclosingParagraphElement`.
+
+ Test: TextManipulation.StartTextManipulationBreaksParagraphInBetweenListItems
+
+ * editing/TextManipulationController.cpp:
+ (WebCore::TextManipulationController::observeParagraphs):
+
2020-04-23 Zalan Bujtas <[email protected]>
[LFC][TFC] Add support for basic baseline align inside a table row
Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (260582 => 260583)
--- trunk/Source/WebCore/editing/TextManipulationController.cpp 2020-04-23 17:49:44 UTC (rev 260582)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp 2020-04-23 18:09:29 UTC (rev 260583)
@@ -274,9 +274,24 @@
Vector<ManipulationToken> tokensInCurrentParagraph;
Position startOfCurrentParagraph;
Position endOfCurrentParagraph;
+ RefPtr<Element> enclosingParagraphElement;
+
+ auto isEnclosingParagraphElement = [](const Element& element) {
+ if (element.hasTagName(liTag)) {
+ auto* renderer = element.renderer();
+ return renderer && renderer->style().display() == DisplayType::Block;
+ }
+ return false;
+ };
+
for (; !iterator.atEnd(); iterator.advance()) {
auto content = iterator.currentContent();
if (content.node) {
+ if (enclosingParagraphElement && !enclosingParagraphElement->contains(content.node.get())) {
+ if (!tokensInCurrentParagraph.isEmpty())
+ addItem(ManipulationItemData { startOfCurrentParagraph, endOfCurrentParagraph, nullptr, nullQName(), std::exchange(tokensInCurrentParagraph, { }) });
+ enclosingParagraphElement = nullptr;
+ }
if (RefPtr<Element> currentElementAncestor = is<Element>(*content.node) ? downcast<Element>(content.node.get()) : content.node->parentOrShadowHostElement()) {
if (isInManipulatedElement(*currentElementAncestor))
return; // We can exit early here because scheduleObservartionUpdate calls this function on each paragraph separately.
@@ -296,6 +311,8 @@
}
}
}
+ if (isEnclosingParagraphElement(currentElement))
+ enclosingParagraphElement = ¤tElement;
}
}
Modified: trunk/Tools/ChangeLog (260582 => 260583)
--- trunk/Tools/ChangeLog 2020-04-23 17:49:44 UTC (rev 260582)
+++ trunk/Tools/ChangeLog 2020-04-23 18:09:29 UTC (rev 260583)
@@ -1,3 +1,16 @@
+2020-04-23 Wenson Hsieh <[email protected]>
+
+ Add a heuristic for text manipulation to treat some list items as paragraph boundaries
+ https://bugs.webkit.org/show_bug.cgi?id=210915
+ <rdar://problem/61907080>
+
+ Reviewed by Megan Gardner.
+
+ Add a new API test to exercise text manipulation over several different cases of lists and list items.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+ (TestWebKitAPI::TEST):
+
2020-04-23 Commit Queue <[email protected]>
Unreviewed, reverting r260562.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (260582 => 260583)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2020-04-23 17:49:44 UTC (rev 260582)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2020-04-23 18:09:29 UTC (rev 260583)
@@ -524,6 +524,64 @@
EXPECT_TRUE(items[0].tokens[2].isExcluded);
}
+TEST(TextManipulation, StartTextManipulationBreaksParagraphInBetweenListItems)
+{
+ 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>"
+ "<head>"
+ " <style>"
+ " li.block { display: block; }"
+ " li.float-left { float: left; margin: 1em; }"
+ " li.inline { display: inline; }"
+ " </style>"
+ "</head>"
+ "<body>"
+ " <ul><li class='block'>One</li><li class='block'>Two<span>-three</span></li></ul>"
+ " <div><br></div>"
+ " <ul><li class='block float-left'>Four</li><li class='block float-left'>Five<span>-six</span></li></ul>"
+ " <div><br></div>"
+ " <ol><li class='inline'>Seven</li><li class='inline'>Eight</li></ol>"
+ " <div><br></div>"
+ " <ul><li>Nine</li><li>Ten</li></ol>"
+ "</body>"];
+
+ done = false;
+ [webView _startTextManipulationsWithConfiguration:nil completion:^{
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+
+ NSArray<_WKTextManipulationItem *> *items = [delegate items];
+ EXPECT_EQ(items.count, 7UL);
+
+ EXPECT_EQ(items[0].tokens.count, 1UL);
+ EXPECT_WK_STREQ("One", items[0].tokens[0].content);
+
+ EXPECT_EQ(items[1].tokens.count, 2UL);
+ EXPECT_WK_STREQ("Two", items[1].tokens[0].content);
+ EXPECT_WK_STREQ("-three", items[1].tokens[1].content);
+
+ EXPECT_EQ(items[2].tokens.count, 1UL);
+ EXPECT_WK_STREQ("Four", items[2].tokens[0].content);
+
+ EXPECT_EQ(items[3].tokens.count, 2UL);
+ EXPECT_WK_STREQ("Five", items[3].tokens[0].content);
+ EXPECT_WK_STREQ("-six", items[3].tokens[1].content);
+
+ EXPECT_EQ(items[4].tokens.count, 2UL);
+ EXPECT_WK_STREQ("Seven", items[4].tokens[0].content);
+ EXPECT_WK_STREQ("Eight", items[4].tokens[1].content);
+
+ EXPECT_EQ(items[5].tokens.count, 1UL);
+ EXPECT_WK_STREQ("Nine", items[5].tokens[0].content);
+
+ EXPECT_EQ(items[6].tokens.count, 1UL);
+ EXPECT_WK_STREQ("Ten", items[6].tokens[0].content);
+}
+
struct Token {
NSString *identifier;
NSString *content;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes