Title: [255046] trunk/Source
Revision
255046
Author
timothy_hor...@apple.com
Date
2020-01-23 18:22:11 -0800 (Thu, 23 Jan 2020)

Log Message

macCatalyst: I-Beam is too conservative, doesn't show up in editable areas with no text
https://bugs.webkit.org/show_bug.cgi?id=206716
<rdar://problem/58359523>

Reviewed by Simon Fraser.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::lineCaretExtent):
(WebKit::populateCaretContext):
(WebKit::WebPage::positionInformation):
Instead of uniting the caret position for the first and last position
on the line to find the I-Beam region, use the bounds of the selection
rect for the line, which extends beyond existing text, matching our
traditional behavior of showing the I-Beam over blank regions.

* editing/VisiblePosition.cpp:
(WebCore::VisiblePosition::absoluteSelectionBoundsForLine const):
* editing/VisiblePosition.h:
Expose the bounds of the possible selection for the line that the given position belongs to.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (255045 => 255046)


--- trunk/Source/WebCore/ChangeLog	2020-01-24 02:04:09 UTC (rev 255045)
+++ trunk/Source/WebCore/ChangeLog	2020-01-24 02:22:11 UTC (rev 255046)
@@ -1,3 +1,16 @@
+2020-01-23  Tim Horton  <timothy_hor...@apple.com>
+
+        macCatalyst: I-Beam is too conservative, doesn't show up in editable areas with no text
+        https://bugs.webkit.org/show_bug.cgi?id=206716
+        <rdar://problem/58359523>
+
+        Reviewed by Simon Fraser.
+
+        * editing/VisiblePosition.cpp:
+        (WebCore::VisiblePosition::absoluteSelectionBoundsForLine const):
+        * editing/VisiblePosition.h:
+        Expose the bounds of the possible selection for the line that the given position belongs to.
+
 2020-01-23  Andres Gonzalez  <andresg...@apple.com>
 
         Use the same AccessibilityObjectWrapper for associated AXObject and AXIsolatedObject.

Modified: trunk/Source/WebCore/editing/VisiblePosition.cpp (255045 => 255046)


--- trunk/Source/WebCore/editing/VisiblePosition.cpp	2020-01-24 02:04:09 UTC (rev 255045)
+++ trunk/Source/WebCore/editing/VisiblePosition.cpp	2020-01-24 02:22:11 UTC (rev 255046)
@@ -667,6 +667,27 @@
     return absoluteBoundsForLocalCaretRect(renderer, localRect, insideFixed);
 }
 
+FloatRect VisiblePosition::absoluteSelectionBoundsForLine() const
+{
+    if (m_deepPosition.isNull())
+        return { };
+
+    auto* node = m_deepPosition.anchorNode();
+    if (!node->renderer())
+        return { };
+
+    InlineBox* inlineBox = nullptr;
+    int caretOffset = 0;
+    getInlineBoxAndOffset(inlineBox, caretOffset);
+
+    if (!inlineBox)
+        return { };
+
+    auto& root = inlineBox->root();
+    auto localRect = FloatRect { root.x(), root.selectionTop(), root.width(), root.selectionHeight() };
+    return root.renderer().localToAbsoluteQuad(localRect).boundingBox();
+}
+
 int VisiblePosition::lineDirectionPointForBlockDirectionNavigation() const
 {
     RenderObject* renderer;

Modified: trunk/Source/WebCore/editing/VisiblePosition.h (255045 => 255046)


--- trunk/Source/WebCore/editing/VisiblePosition.h	2020-01-24 02:04:09 UTC (rev 255045)
+++ trunk/Source/WebCore/editing/VisiblePosition.h	2020-01-24 02:22:11 UTC (rev 255046)
@@ -102,6 +102,8 @@
     // FIXME: navigation with transforms should be smarter.
     WEBCORE_EXPORT int lineDirectionPointForBlockDirectionNavigation() const;
 
+    WEBCORE_EXPORT FloatRect absoluteSelectionBoundsForLine() const;
+
     // This is a tentative enhancement of operator== to account for affinity.
     // FIXME: Combine this function with operator==
     bool equals(const VisiblePosition&) const;

Modified: trunk/Source/WebKit/ChangeLog (255045 => 255046)


--- trunk/Source/WebKit/ChangeLog	2020-01-24 02:04:09 UTC (rev 255045)
+++ trunk/Source/WebKit/ChangeLog	2020-01-24 02:22:11 UTC (rev 255046)
@@ -1,3 +1,20 @@
+2020-01-23  Tim Horton  <timothy_hor...@apple.com>
+
+        macCatalyst: I-Beam is too conservative, doesn't show up in editable areas with no text
+        https://bugs.webkit.org/show_bug.cgi?id=206716
+        <rdar://problem/58359523>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::lineCaretExtent):
+        (WebKit::populateCaretContext):
+        (WebKit::WebPage::positionInformation):
+        Instead of uniting the caret position for the first and last position
+        on the line to find the I-Beam region, use the bounds of the selection
+        rect for the line, which extends beyond existing text, matching our
+        traditional behavior of showing the I-Beam over blank regions.
+
 2020-01-23  Tomoki Imai  <tomoki.i...@sony.com>
 
         Set proper TextureMapperLayer::m_contentsLayer in updateImageBacking

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-01-24 02:04:09 UTC (rev 255045)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-01-24 02:22:11 UTC (rev 255046)
@@ -2750,6 +2750,49 @@
     return nullptr;
 }
 
+static FloatRect lineCaretExtent(const InteractionInformationRequest& request, const HitTestResult& hitTestResult)
+{
+    auto* frame = hitTestResult.innerNodeFrame();
+    if (!frame)
+        return { };
+
+    auto* renderer = hitTestResult.innerNode()->renderer();
+    if (!renderer)
+        return { };
+
+    while (renderer && !is<RenderBlockFlow>(*renderer))
+        renderer = renderer->parent();
+
+    if (!renderer)
+        return { };
+
+    // FIXME: We should be able to retrieve this geometry information without
+    // forcing the text to fall out of Simple Line Layout.
+    auto& blockFlow = downcast<RenderBlockFlow>(*renderer);
+    VisiblePosition position = frame->visiblePositionForPoint(request.point);
+    auto lineRect = position.absoluteSelectionBoundsForLine();
+    lineRect.setWidth(blockFlow.contentWidth());
+    return lineRect;
+}
+
+static void populateCaretContext(const HitTestResult& hitTestResult, const InteractionInformationRequest& request, InteractionInformationAtPosition& info)
+{
+    auto* frame = hitTestResult.innerNodeFrame();
+    if (!frame)
+        return;
+
+    auto* frameView = frame->view();
+    if (!frameView)
+        return;
+
+    info.lineCaretExtent = frameView->contentsToRootView(lineCaretExtent(request, hitTestResult));
+    info.caretHeight = info.lineCaretExtent.height();
+
+    // Force an I-beam cursor if the page didn't request a hand, and we're inside the bounds of the line.
+    if (info.lineCaretExtent.contains(request.point) && info.cursor->type() != Cursor::Hand)
+        info.cursor = Cursor::fromType(Cursor::IBeam);
+}
+
 InteractionInformationAtPosition WebPage::positionInformation(const InteractionInformationRequest& request)
 {
     InteractionInformationAtPosition info;
@@ -2764,19 +2807,9 @@
     auto& eventHandler = m_page->mainFrame().eventHandler();
     HitTestResult hitTestResult = eventHandler.hitTestResultAtPoint(request.point, HitTestRequest::ReadOnly | HitTestRequest::AllowFrameScrollbars);
     info.cursor = eventHandler.selectCursor(hitTestResult, false);
-    if (request.includeCaretContext) {
-        if (auto* frame = hitTestResult.innerNodeFrame()) {
-            if (auto* frameView = frame->view()) {
-                VisiblePosition position = frame->visiblePositionForPoint(request.point);
-                info.caretHeight = frameView->contentsToRootView(position.absoluteCaretBounds()).height();
+    if (request.includeCaretContext)
+        populateCaretContext(hitTestResult, request, info);
 
-                VisiblePosition startPosition = startOfLine(position);
-                VisiblePosition endPosition = endOfLine(position);
-                info.lineCaretExtent = unionRect(frameView->contentsToRootView(startPosition.absoluteCaretBounds()), frameView->contentsToRootView(endPosition.absoluteCaretBounds()));
-            }
-        }
-    }
-
 #if ENABLE(DATA_INTERACTION)
     info.hasSelectionAtPosition = m_page->hasSelectionAtPosition(adjustedPoint);
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to