Title: [288849] trunk
Revision
288849
Author
[email protected]
Date
2022-01-31 15:11:41 -0800 (Mon, 31 Jan 2022)

Log Message

Collapsed ranges return zero rects in DocumentContext
https://bugs.webkit.org/show_bug.cgi?id=235844

Reviewed by Tim Horton.

Source/WebKit:

Test: DocumentEditingContext.RectsRequestInContentEditableWithDivBreaks

When getting the DocumentContext for a line, followed by a blank line, the blank link will
be represented by a collapsed range. This is a result of the emitCharacter call from representNodeOffsetZero.
This possibly a bug, but rather than try and fix this issue within TextIterator itself, we are
mitigating this issue by instead of using the collapsed range and the resulting non-existent character rect,
using the caret bounding rect. This gives us a more accurate bounding rect for situations like
this that result in collapsed ranges. And this would cover all other situations that might result in
a collapsed range from TextIterator.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestDocumentEditingContext):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (288848 => 288849)


--- trunk/Source/WebKit/ChangeLog	2022-01-31 23:04:08 UTC (rev 288848)
+++ trunk/Source/WebKit/ChangeLog	2022-01-31 23:11:41 UTC (rev 288849)
@@ -1,3 +1,23 @@
+2022-01-31  Megan Gardner  <[email protected]>
+
+        Collapsed ranges return zero rects in DocumentContext
+        https://bugs.webkit.org/show_bug.cgi?id=235844
+
+        Reviewed by Tim Horton.
+
+        Test: DocumentEditingContext.RectsRequestInContentEditableWithDivBreaks
+
+        When getting the DocumentContext for a line, followed by a blank line, the blank link will 
+        be represented by a collapsed range. This is a result of the emitCharacter call from representNodeOffsetZero.
+        This possibly a bug, but rather than try and fix this issue within TextIterator itself, we are
+        mitigating this issue by instead of using the collapsed range and the resulting non-existent character rect,
+        using the caret bounding rect. This gives us a more accurate bounding rect for situations like
+        this that result in collapsed ranges. And this would cover all other situations that might result in
+        a collapsed range from TextIterator. 
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDocumentEditingContext):
+
 2022-01-31  Patrick Angle  <[email protected]>
 
         Web Inspector: [Cocoa] Crash in WebKit::WebInspectorUIProxy::attachmentViewDidChange

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (288848 => 288849)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-31 23:04:08 UTC (rev 288848)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-31 23:11:41 UTC (rev 288849)
@@ -4571,7 +4571,11 @@
         const int stride = 1;
         while (!iterator.atEnd()) {
             if (!iterator.text().isEmpty()) {
-                auto absoluteBoundingBox = unionRectIgnoringZeroRects(RenderObject::absoluteTextRects(iterator.range(), RenderObject::BoundingRectBehavior::IgnoreEmptyTextSelections));
+                IntRect absoluteBoundingBox;
+                if (iterator.range().collapsed())
+                    absoluteBoundingBox = VisiblePosition(makeContainerOffsetPosition(iterator.range().start)).absoluteCaretBounds();
+                else
+                    absoluteBoundingBox = unionRectIgnoringZeroRects(RenderObject::absoluteTextRects(iterator.range(), RenderObject::BoundingRectBehavior::IgnoreEmptyTextSelections));
                 rects.append({ iterator.range().start.document().view()->contentsToRootView(absoluteBoundingBox), { offsetSoFar++, stride } });
             }
             iterator.advance(stride);

Modified: trunk/Tools/ChangeLog (288848 => 288849)


--- trunk/Tools/ChangeLog	2022-01-31 23:04:08 UTC (rev 288848)
+++ trunk/Tools/ChangeLog	2022-01-31 23:11:41 UTC (rev 288849)
@@ -1,3 +1,13 @@
+2022-01-31  Megan Gardner  <[email protected]>
+
+        Collapsed ranges return zero rects in DocumentContext
+        https://bugs.webkit.org/show_bug.cgi?id=235844
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
+        (TEST):
+
 2022-01-31  Jonathan Bedard  <[email protected]>
 
         [EWS] Revert pull request when retrying

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm (288848 => 288849)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2022-01-31 23:04:08 UTC (rev 288848)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2022-01-31 23:11:41 UTC (rev 288849)
@@ -500,6 +500,32 @@
     }
 }
 
+TEST(DocumentEditingContext, RectsRequestInContentEditableWithDivBreaks)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView synchronouslyLoadHTMLString:applyAhemStyle(@"<div id='text' contenteditable>Test<div><br></div><div><br></div><div><br></div></div>")];
+    [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.lastChild, text.lastChild.length, text.lastChild, text.lastChild.length)"]; // Will focus <p>.
+
+    NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
+    EXPECT_EQ(1UL, textInputContexts.count);
+
+    auto request = retainPtr(makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityCharacter, 200, [webView frame], textInputContexts[0]));
+    auto context = retainPtr([webView synchronouslyRequestDocumentContext:request.get()]);
+    auto *textRects = [context textRects];
+    EXPECT_EQ(7U, textRects.count);
+    if (textRects.count >= 7) {
+        EXPECT_EQ(CGRectMake(0, 0, 25, 25), textRects[0].CGRectValue);
+        EXPECT_EQ(CGRectMake(25, 0, 25, 25), textRects[1].CGRectValue);
+        EXPECT_EQ(CGRectMake(50, 0, 25, 25), textRects[2].CGRectValue);
+        EXPECT_EQ(CGRectMake(75, 0, 25, 25), textRects[3].CGRectValue);
+        EXPECT_EQ(CGRectMake(99, 0, 2, 25), textRects[4].CGRectValue);
+        EXPECT_EQ(CGRectMake(0, 25, 0, 25), textRects[5].CGRectValue);
+        EXPECT_EQ(CGRectMake(0, 50, 0, 25), textRects[6].CGRectValue);
+    }
+}
+
+
 TEST(DocumentEditingContext, SpatialRequest_RectEncompassingInput)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to