Changeset 228549 in webkit


Ignore:
Timestamp:
Feb 15, 2018 7:08:06 PM (6 years ago)
Author:
Megan Gardner
Message:

Support scrolling for non-editable web-selection and start autoscroll when near screen edges
https://bugs.webkit.org/show_bug.cgi?id=182815

Source/WebCore:

Reviewed by Tim Horton.

Adjust the position we are autoscrolling to so that when we are close to an edge, we will start autoscrolling
while we are still inside the view. Autoscrolling still happens when you drag past the edge of a view.

No new tests (This is difficult to test in this state, but when we switch assistants, test will also be added).

  • page/EventHandler.h:
  • page/ios/EventHandlerIOS.mm:

(WebCore::EventHandler::startSelectionAutoscroll):
(WebCore::EventHandler::cancelSelectionAutoscroll):
(WebCore::autoscrollAdjustmentFactorForScreenBoundaries):
(WebCore::EventHandler::targetPositionInWindowForSelectionAutoscroll const):
(WebCore::EventHandler::startTextAutoscroll): Deleted.
(WebCore::EventHandler::cancelTextAutoscroll): Deleted.

Source/WebKit:

Add support for autoscrolling during a selection. This also takes into account the edges of the screen
and starts autoscrolling when you get close, while still allowing autoscrolling when you are past the bounds
of the WebView.

Reviewed by Tim Horton.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView startAutoscroll:]):
(-[WKContentView resignFirstResponderForWebView]):
(-[WKContentView useSelectionAssistantWithGranularity:]):
(-[WKContentView selectedTextRange]):

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::startAutoscrollAtPosition):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::startAutoscrollAtPosition):
(WebKit::WebPage::cancelAutoscroll):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r228548 r228549  
     12018-02-15  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Support scrolling for non-editable web-selection and start autoscroll when near screen edges
     4        https://bugs.webkit.org/show_bug.cgi?id=182815
     5
     6        Reviewed by Tim Horton.
     7
     8        Adjust the position we are autoscrolling to so that when we are close to an edge, we will start autoscrolling
     9        while we are still inside the view. Autoscrolling still happens when you drag past the edge of a view.
     10
     11        No new tests (This is difficult to test in this state, but when we switch assistants, test will also be added).
     12
     13        * page/EventHandler.h:
     14        * page/ios/EventHandlerIOS.mm:
     15        (WebCore::EventHandler::startSelectionAutoscroll):
     16        (WebCore::EventHandler::cancelSelectionAutoscroll):
     17        (WebCore::autoscrollAdjustmentFactorForScreenBoundaries):
     18        (WebCore::EventHandler::targetPositionInWindowForSelectionAutoscroll const):
     19        (WebCore::EventHandler::startTextAutoscroll): Deleted.
     20        (WebCore::EventHandler::cancelTextAutoscroll): Deleted.
     21
    1222018-02-15  Youenn Fablet  <youenn@apple.com>
    223
  • trunk/Source/WebCore/page/EventHandler.h

    r228260 r228549  
    339339   
    340340#if PLATFORM(IOS)
    341     WEBCORE_EXPORT void startTextAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow);
    342     WEBCORE_EXPORT void cancelTextAutoscroll();
     341    WEBCORE_EXPORT void startSelectionAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow);
     342    WEBCORE_EXPORT void cancelSelectionAutoscroll();
    343343    IntPoint m_targetAutoscrollPositionInWindow;
    344344    bool m_isAutoscrolling { false };
  • trunk/Source/WebCore/page/ios/EventHandlerIOS.mm

    r228531 r228549  
    563563}
    564564   
    565 void EventHandler::startTextAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow)
    566 {
    567     m_targetAutoscrollPositionInWindow = roundedIntPoint(positionInWindow);
     565void EventHandler::startSelectionAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow)
     566{
     567    Ref<Frame> protectedFrame(m_frame);
     568
     569    m_targetAutoscrollPositionInWindow = protectedFrame->view()->contentsToView(roundedIntPoint(positionInWindow));
     570   
    568571    m_isAutoscrolling = true;
    569572    m_autoscrollController->startAutoscrollForSelection(renderer);
    570573}
    571574
    572 void EventHandler::cancelTextAutoscroll()
     575void EventHandler::cancelSelectionAutoscroll()
    573576{
    574577    m_isAutoscrolling = false;
    575578    m_autoscrollController->stopAutoscrollTimer();
    576579}
     580
     581static IntSize autoscrollAdjustmentFactorForScreenBoundaries(const IntPoint& screenPoint, const FloatRect& screenRect)
     582{
     583    // If the window is at the edge of the screen, and the touch position is also at that edge of the screen,
     584    // we need to adjust the autoscroll amount in order for the user to be able to autoscroll in that direction.
     585    // We can pretend that the touch position is slightly beyond the edge of the screen, and then autoscrolling
     586    // will occur as expected. This function figures out just how much to adjust the autoscroll amount by
     587    // in order to get autoscrolling to feel natural in this situation.
     588   
     589    IntSize adjustmentFactor;
     590   
     591#define EDGE_DISTANCE_THRESHOLD 100
     592
     593    float screenLeftEdge = screenRect.x();
     594    float insetScreenLeftEdge = screenLeftEdge + EDGE_DISTANCE_THRESHOLD;
     595    float screenRightEdge = screenRect.maxX();
     596    float insetScreenRightEdge = screenRightEdge - EDGE_DISTANCE_THRESHOLD;
     597    if (screenPoint.x() >= screenLeftEdge && screenPoint.x() < insetScreenLeftEdge) {
     598        float distanceFromEdge = screenPoint.x() - screenLeftEdge - EDGE_DISTANCE_THRESHOLD;
     599        if (distanceFromEdge < 0)
     600            adjustmentFactor.setWidth(-EDGE_DISTANCE_THRESHOLD);
     601    } else if (screenPoint.x() >= insetScreenRightEdge && screenPoint.x() < screenRightEdge) {
     602        float distanceFromEdge = EDGE_DISTANCE_THRESHOLD - (screenRightEdge - screenPoint.x());
     603        if (distanceFromEdge > 0)
     604            adjustmentFactor.setWidth(EDGE_DISTANCE_THRESHOLD);
     605    }
     606   
     607    float screenTopEdge = screenRect.y();
     608    float insetScreenTopEdge = screenTopEdge + EDGE_DISTANCE_THRESHOLD;
     609    float screenBottomEdge = screenRect.maxY();
     610    float insetScreenBottomEdge = screenBottomEdge - EDGE_DISTANCE_THRESHOLD;
     611   
     612    if (screenPoint.y() >= screenTopEdge && screenPoint.y() < insetScreenTopEdge) {
     613        float distanceFromEdge = screenPoint.y() - screenTopEdge - EDGE_DISTANCE_THRESHOLD;
     614        if (distanceFromEdge < 0)
     615            adjustmentFactor.setHeight(-EDGE_DISTANCE_THRESHOLD);
     616    } else if (screenPoint.y() >= insetScreenBottomEdge && screenPoint.y() < screenBottomEdge) {
     617        float distanceFromEdge = EDGE_DISTANCE_THRESHOLD - (screenBottomEdge - screenPoint.y());
     618        if (distanceFromEdge > 0)
     619            adjustmentFactor.setHeight(EDGE_DISTANCE_THRESHOLD);
     620    }
     621   
     622    return adjustmentFactor;
     623}
    577624   
    578625IntPoint EventHandler::targetPositionInWindowForSelectionAutoscroll() const
    579626{
    580     return m_targetAutoscrollPositionInWindow;
     627    Ref<Frame> protectedFrame(m_frame);
     628   
     629    FloatRect unobscuredContentRect = protectedFrame->view()->unobscuredContentRect();
     630   
     631    // Manually need to convert viewToContents, as it will be skipped because delegatedScrolling is on iOS
     632    IntPoint contentPosition = protectedFrame->view()->viewToContents(protectedFrame->view()->convertFromContainingWindow(m_targetAutoscrollPositionInWindow));
     633    IntSize adjustPosition = autoscrollAdjustmentFactorForScreenBoundaries(contentPosition, unobscuredContentRect);
     634    return contentPosition + adjustPosition;
    581635}
    582636   
  • trunk/Source/WebKit/ChangeLog

    r228532 r228549  
     12018-02-15  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Support scrolling for non-editable web-selection and start autoscroll when near screen edges
     4        https://bugs.webkit.org/show_bug.cgi?id=182815
     5
     6        Add support for autoscrolling during a selection. This also takes into account the edges of the screen
     7        and starts autoscrolling when you get close, while still allowing autoscrolling when you are past the bounds
     8        of the WebView.
     9
     10        Reviewed by Tim Horton.
     11
     12        * UIProcess/ios/WKContentViewInteraction.mm:
     13        (-[WKContentView startAutoscroll:]):
     14        (-[WKContentView resignFirstResponderForWebView]):
     15        (-[WKContentView useSelectionAssistantWithGranularity:]):
     16        (-[WKContentView selectedTextRange]):
     17        * UIProcess/ios/WebPageProxyIOS.mm:
     18        (WebKit::WebPageProxy::startAutoscrollAtPosition):
     19        * WebProcess/WebPage/ios/WebPageIOS.mm:
     20        (WebKit::WebPage::startAutoscrollAtPosition):
     21        (WebKit::WebPage::cancelAutoscroll):
     22
    1232018-02-15  John Wilander  <wilander@apple.com>
    224
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r228393 r228549  
    763763
    764764#pragma mark - UITextAutoscrolling
    765 - (void)startAutoscroll:(CGPoint)point
    766 {
    767     _page->startAutoscrollAtPosition(point);
     765- (void)startAutoscroll:(CGPoint)pointInDocument
     766{
     767    _page->startAutoscrollAtPosition(pointInDocument);
    768768}
    769769
     
    918918
    919919    _resigningFirstResponder = YES;
    920 
    921920    if (!_webView->_activeFocusedStateRetainCount) {
    922921        // We need to complete the editing operation before we blur the element.
     
    31343133- (UITextRange *)selectedTextRange
    31353134{
    3136     if (_page->editorState().selectionIsNone)
     3135    if (_page->editorState().selectionIsNone || _page->editorState().isMissingPostLayoutData)
    31373136        return nil;
    31383137    auto& postLayoutEditorStateData = _page->editorState().postLayoutData();
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r227377 r228549  
    735735}
    736736
    737 void WebPageProxy::startAutoscrollAtPosition(const WebCore::FloatPoint& position)
    738 {
    739     m_process->send(Messages::WebPage::StartAutoscrollAtPosition(position), m_pageID);
     737void WebPageProxy::startAutoscrollAtPosition(const WebCore::FloatPoint& positionInWindow)
     738{
     739    m_process->send(Messages::WebPage::StartAutoscrollAtPosition(positionInWindow), m_pageID);
    740740}
    741741   
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r228260 r228549  
    18251825{
    18261826    if (m_assistedNode && m_assistedNode->renderer())
    1827         m_page->mainFrame().eventHandler().startTextAutoscroll(m_assistedNode->renderer(), positionInWindow);
     1827        m_page->mainFrame().eventHandler().startSelectionAutoscroll(m_assistedNode->renderer(), positionInWindow);
     1828    else {
     1829        Frame& frame = m_page->focusController().focusedOrMainFrame();
     1830        VisibleSelection selection = frame.selection().selection();
     1831        if (selection.isRange()) {
     1832            RefPtr<Range> range = frame.selection().toNormalizedRange();
     1833            Node& node = range->startContainer();
     1834            auto* renderer = node.renderer();
     1835            if (renderer)
     1836                m_page->mainFrame().eventHandler().startSelectionAutoscroll(renderer, positionInWindow);
     1837        }
     1838    }
    18281839}
    18291840   
    18301841void WebPage::cancelAutoscroll()
    18311842{
    1832     m_page->mainFrame().eventHandler().cancelTextAutoscroll();
     1843    m_page->mainFrame().eventHandler().cancelSelectionAutoscroll();
    18331844}
    18341845
Note: See TracChangeset for help on using the changeset viewer.