Changeset 255046 in webkit


Ignore:
Timestamp:
Jan 23, 2020 6:22:11 PM (4 years ago)
Author:
timothy_horton@apple.com
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.

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r255044 r255046  
     12020-01-23  Tim Horton  <timothy_horton@apple.com>
     2
     3        macCatalyst: I-Beam is too conservative, doesn't show up in editable areas with no text
     4        https://bugs.webkit.org/show_bug.cgi?id=206716
     5        <rdar://problem/58359523>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * editing/VisiblePosition.cpp:
     10        (WebCore::VisiblePosition::absoluteSelectionBoundsForLine const):
     11        * editing/VisiblePosition.h:
     12        Expose the bounds of the possible selection for the line that the given position belongs to.
     13
    1142020-01-23  Andres Gonzalez  <andresg_22@apple.com>
    215
  • trunk/Source/WebCore/editing/VisiblePosition.cpp

    r252647 r255046  
    668668}
    669669
     670FloatRect VisiblePosition::absoluteSelectionBoundsForLine() const
     671{
     672    if (m_deepPosition.isNull())
     673        return { };
     674
     675    auto* node = m_deepPosition.anchorNode();
     676    if (!node->renderer())
     677        return { };
     678
     679    InlineBox* inlineBox = nullptr;
     680    int caretOffset = 0;
     681    getInlineBoxAndOffset(inlineBox, caretOffset);
     682
     683    if (!inlineBox)
     684        return { };
     685
     686    auto& root = inlineBox->root();
     687    auto localRect = FloatRect { root.x(), root.selectionTop(), root.width(), root.selectionHeight() };
     688    return root.renderer().localToAbsoluteQuad(localRect).boundingBox();
     689}
     690
    670691int VisiblePosition::lineDirectionPointForBlockDirectionNavigation() const
    671692{
  • trunk/Source/WebCore/editing/VisiblePosition.h

    r252647 r255046  
    103103    WEBCORE_EXPORT int lineDirectionPointForBlockDirectionNavigation() const;
    104104
     105    WEBCORE_EXPORT FloatRect absoluteSelectionBoundsForLine() const;
     106
    105107    // This is a tentative enhancement of operator== to account for affinity.
    106108    // FIXME: Combine this function with operator==
  • trunk/Source/WebKit/ChangeLog

    r255045 r255046  
     12020-01-23  Tim Horton  <timothy_horton@apple.com>
     2
     3        macCatalyst: I-Beam is too conservative, doesn't show up in editable areas with no text
     4        https://bugs.webkit.org/show_bug.cgi?id=206716
     5        <rdar://problem/58359523>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * WebProcess/WebPage/ios/WebPageIOS.mm:
     10        (WebKit::lineCaretExtent):
     11        (WebKit::populateCaretContext):
     12        (WebKit::WebPage::positionInformation):
     13        Instead of uniting the caret position for the first and last position
     14        on the line to find the I-Beam region, use the bounds of the selection
     15        rect for the line, which extends beyond existing text, matching our
     16        traditional behavior of showing the I-Beam over blank regions.
     17
    1182020-01-23  Tomoki Imai  <Tomoki.Imai@sony.com>
    219
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r254755 r255046  
    27512751}
    27522752
     2753static FloatRect lineCaretExtent(const InteractionInformationRequest& request, const HitTestResult& hitTestResult)
     2754{
     2755    auto* frame = hitTestResult.innerNodeFrame();
     2756    if (!frame)
     2757        return { };
     2758
     2759    auto* renderer = hitTestResult.innerNode()->renderer();
     2760    if (!renderer)
     2761        return { };
     2762
     2763    while (renderer && !is<RenderBlockFlow>(*renderer))
     2764        renderer = renderer->parent();
     2765
     2766    if (!renderer)
     2767        return { };
     2768
     2769    // FIXME: We should be able to retrieve this geometry information without
     2770    // forcing the text to fall out of Simple Line Layout.
     2771    auto& blockFlow = downcast<RenderBlockFlow>(*renderer);
     2772    VisiblePosition position = frame->visiblePositionForPoint(request.point);
     2773    auto lineRect = position.absoluteSelectionBoundsForLine();
     2774    lineRect.setWidth(blockFlow.contentWidth());
     2775    return lineRect;
     2776}
     2777
     2778static void populateCaretContext(const HitTestResult& hitTestResult, const InteractionInformationRequest& request, InteractionInformationAtPosition& info)
     2779{
     2780    auto* frame = hitTestResult.innerNodeFrame();
     2781    if (!frame)
     2782        return;
     2783
     2784    auto* frameView = frame->view();
     2785    if (!frameView)
     2786        return;
     2787
     2788    info.lineCaretExtent = frameView->contentsToRootView(lineCaretExtent(request, hitTestResult));
     2789    info.caretHeight = info.lineCaretExtent.height();
     2790
     2791    // Force an I-beam cursor if the page didn't request a hand, and we're inside the bounds of the line.
     2792    if (info.lineCaretExtent.contains(request.point) && info.cursor->type() != Cursor::Hand)
     2793        info.cursor = Cursor::fromType(Cursor::IBeam);
     2794}
     2795
    27532796InteractionInformationAtPosition WebPage::positionInformation(const InteractionInformationRequest& request)
    27542797{
     
    27652808    HitTestResult hitTestResult = eventHandler.hitTestResultAtPoint(request.point, HitTestRequest::ReadOnly | HitTestRequest::AllowFrameScrollbars);
    27662809    info.cursor = eventHandler.selectCursor(hitTestResult, false);
    2767     if (request.includeCaretContext) {
    2768         if (auto* frame = hitTestResult.innerNodeFrame()) {
    2769             if (auto* frameView = frame->view()) {
    2770                 VisiblePosition position = frame->visiblePositionForPoint(request.point);
    2771                 info.caretHeight = frameView->contentsToRootView(position.absoluteCaretBounds()).height();
    2772 
    2773                 VisiblePosition startPosition = startOfLine(position);
    2774                 VisiblePosition endPosition = endOfLine(position);
    2775                 info.lineCaretExtent = unionRect(frameView->contentsToRootView(startPosition.absoluteCaretBounds()), frameView->contentsToRootView(endPosition.absoluteCaretBounds()));
    2776             }
    2777         }
    2778     }
     2810    if (request.includeCaretContext)
     2811        populateCaretContext(hitTestResult, request, info);
    27792812
    27802813#if ENABLE(DATA_INTERACTION)
Note: See TracChangeset for help on using the changeset viewer.