Title: [288721] trunk
Revision
288721
Author
[email protected]
Date
2022-01-27 21:13:26 -0800 (Thu, 27 Jan 2022)

Log Message

DocumentContext gives empty rects for blank lines.
https://bugs.webkit.org/show_bug.cgi?id=235695

Reviewed by Wenson Hsieh.

Source/WebCore:

Test: DocumentEditingContext::RectsRequestInContentEditable

When requesting the document context for the end of a document, we would give empty rects for
blank lines. This was because when calculating the absoluteBoundingRect for the range, we
would use a normal unionRect call, which would use the basic unite call, which does not combine
empty rects. And empty rect is defined as a rect that does not have a non-zero hight and width.
Since we were calculating information about <br> lines, this was causing us to union a list of
a single rect, which was an empty rect. This left us with a zero rect after unioning. The solution
is to unionIfNonZero when calculating these rects for DocumentContext. I also took the opportunity
to make some of this code more parallel to other implementations.

* platform/graphics/GeometryUtilities.cpp:
(WebCore::unionRectIfNonZero):
* platform/graphics/GeometryUtilities.h:
* platform/graphics/IntRect.cpp:
(WebCore::IntRect::uniteIfNonZero):
* platform/graphics/IntRect.h:
(WebCore::IntRect::isZero const):

Source/WebKit:

When requesting the document context for the end of a document, we would give empty rects for
blank lines. This was because when calculating the absoluteBoundingRect for the range, we
would use a normal unionRect call, which would use the basic unite call, which does not combine
empty rects. And empty rect is defined as a rect that does not have a non-zero hight and width.
Since we were calculating information about <br> lines, this was causing us to union a list of
a single rect, which was an empty rect. This left us with a zero rect after unioning. The solution
is to unionIfNonZero when calculating these rects for DocumentContext. I also took the opportunity
to make some of this code more parallel to other implementations.

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

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288720 => 288721)


--- trunk/Source/WebCore/ChangeLog	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebCore/ChangeLog	2022-01-28 05:13:26 UTC (rev 288721)
@@ -1,3 +1,29 @@
+2022-01-27  Megan Gardner  <[email protected]>
+
+        DocumentContext gives empty rects for blank lines.
+        https://bugs.webkit.org/show_bug.cgi?id=235695
+
+        Reviewed by Wenson Hsieh.
+
+        Test: DocumentEditingContext::RectsRequestInContentEditable
+
+        When requesting the document context for the end of a document, we would give empty rects for
+        blank lines. This was because when calculating the absoluteBoundingRect for the range, we 
+        would use a normal unionRect call, which would use the basic unite call, which does not combine
+        empty rects. And empty rect is defined as a rect that does not have a non-zero hight and width.
+        Since we were calculating information about <br> lines, this was causing us to union a list of 
+        a single rect, which was an empty rect. This left us with a zero rect after unioning. The solution 
+        is to unionIfNonZero when calculating these rects for DocumentContext. I also took the opportunity 
+        to make some of this code more parallel to other implementations.
+
+        * platform/graphics/GeometryUtilities.cpp:
+        (WebCore::unionRectIfNonZero):
+        * platform/graphics/GeometryUtilities.h:
+        * platform/graphics/IntRect.cpp:
+        (WebCore::IntRect::uniteIfNonZero):
+        * platform/graphics/IntRect.h:
+        (WebCore::IntRect::isZero const):
+
 2022-01-27  Michael Saboff  <[email protected]>
 
         com.apple.WebKit.WebAuthn.xpc fails to build with system content path

Modified: trunk/Source/WebCore/platform/graphics/GeometryUtilities.cpp (288720 => 288721)


--- trunk/Source/WebCore/platform/graphics/GeometryUtilities.cpp	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebCore/platform/graphics/GeometryUtilities.cpp	2022-01-28 05:13:26 UTC (rev 288721)
@@ -89,6 +89,14 @@
     return result;
 }
 
+IntRect unionRectIgnoringZeroRects(const Vector<IntRect>& rects)
+{
+    IntRect result;
+    for (auto& rect : rects)
+        result.uniteIfNonZero(rect);
+    return result;
+}
+
 FloatRect unionRect(const Vector<FloatRect>& rects)
 {
     FloatRect result;

Modified: trunk/Source/WebCore/platform/graphics/GeometryUtilities.h (288720 => 288721)


--- trunk/Source/WebCore/platform/graphics/GeometryUtilities.h	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebCore/platform/graphics/GeometryUtilities.h	2022-01-28 05:13:26 UTC (rev 288721)
@@ -42,6 +42,7 @@
 WEBCORE_EXPORT bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection);
 
 WEBCORE_EXPORT IntRect unionRect(const Vector<IntRect>&);
+WEBCORE_EXPORT IntRect unionRectIgnoringZeroRects(const Vector<IntRect>&);
 WEBCORE_EXPORT FloatRect unionRect(const Vector<FloatRect>&);
 WEBCORE_EXPORT FloatRect unionRectIgnoringZeroRects(const Vector<FloatRect>&);
 

Modified: trunk/Source/WebCore/platform/graphics/IntRect.cpp (288720 => 288721)


--- trunk/Source/WebCore/platform/graphics/IntRect.cpp	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebCore/platform/graphics/IntRect.cpp	2022-01-28 05:13:26 UTC (rev 288721)
@@ -105,9 +105,9 @@
 void IntRect::uniteIfNonZero(const IntRect& other)
 {
     // Handle empty special cases first.
-    if (!other.width() && !other.height())
+    if (other.isZero())
         return;
-    if (!width() && !height()) {
+    if (isZero()) {
         *this = other;
         return;
     }

Modified: trunk/Source/WebCore/platform/graphics/IntRect.h (288720 => 288721)


--- trunk/Source/WebCore/platform/graphics/IntRect.h	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebCore/platform/graphics/IntRect.h	2022-01-28 05:13:26 UTC (rev 288721)
@@ -97,6 +97,7 @@
     void setHeight(int height) { m_size.setHeight(height); }
 
     bool isEmpty() const { return m_size.isEmpty(); }
+    bool isZero() const { return m_size.isZero(); }
 
     // NOTE: The result is rounded to integer values, and thus may be not the exact
     // center point.

Modified: trunk/Source/WebKit/ChangeLog (288720 => 288721)


--- trunk/Source/WebKit/ChangeLog	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebKit/ChangeLog	2022-01-28 05:13:26 UTC (rev 288721)
@@ -1,3 +1,22 @@
+2022-01-27  Megan Gardner  <[email protected]>
+
+        DocumentContext gives empty rects for blank lines.
+        https://bugs.webkit.org/show_bug.cgi?id=235695
+
+        Reviewed by Wenson Hsieh.
+
+        When requesting the document context for the end of a document, we would give empty rects for
+        blank lines. This was because when calculating the absoluteBoundingRect for the range, we 
+        would use a normal unionRect call, which would use the basic unite call, which does not combine
+        empty rects. And empty rect is defined as a rect that does not have a non-zero hight and width.
+        Since we were calculating information about <br> lines, this was causing us to union a list of 
+        a single rect, which was an empty rect. This left us with a zero rect after unioning. The solution 
+        is to unionIfNonZero when calculating these rects for DocumentContext. I also took the opportunity 
+        to make some of this code more parallel to other implementations.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDocumentEditingContext):
+
 2022-01-27  Tim Horton  <[email protected]>
 
         Remove ENABLE(HOVER_GESTURE_RECOGNIZER) and related code

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-28 05:13:26 UTC (rev 288721)
@@ -4571,7 +4571,7 @@
         const int stride = 1;
         while (!iterator.atEnd()) {
             if (!iterator.text().isEmpty()) {
-                auto absoluteBoundingBox = unionRect(RenderObject::absoluteTextRects(iterator.range(), RenderObject::BoundingRectBehavior::IgnoreEmptyTextSelections));
+                auto 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 (288720 => 288721)


--- trunk/Tools/ChangeLog	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Tools/ChangeLog	2022-01-28 05:13:26 UTC (rev 288721)
@@ -1,3 +1,13 @@
+2022-01-27  Megan Gardner  <[email protected]>
+
+        DocumentContext gives empty rects for blank lines.
+        https://bugs.webkit.org/show_bug.cgi?id=235695
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
+        (TEST): DocumentEditingContext::RectsRequestInContentEditable
+
 2022-01-27  Jonathan Bedard  <[email protected]>
 
         [git-webkit] Respect EMAIL_ADDRESS environment variable during setup

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm (288720 => 288721)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2022-01-28 03:11:02 UTC (rev 288720)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2022-01-28 05:13:26 UTC (rev 288721)
@@ -475,6 +475,31 @@
     return CGRectMake([domRect[@"left"] floatValue], [domRect[@"top"] floatValue], [domRect[@"width"] floatValue], [domRect[@"height"] floatValue]);
 }
 
+TEST(DocumentEditingContext, RectsRequestInContentEditable)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView synchronouslyLoadHTMLString:applyAhemStyle(@"<p id='text' contenteditable>Test<br><br><br><br></p>")];
+    [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(100, 0, 0, 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