Changeset 228549 in webkit
- Timestamp:
- Feb 15, 2018, 7:08:06 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r228548 r228549 1 2018-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 1 22 2018-02-15 Youenn Fablet <youenn@apple.com> 2 23 -
trunk/Source/WebCore/page/EventHandler.h
r228260 r228549 339 339 340 340 #if PLATFORM(IOS) 341 WEBCORE_EXPORT void start TextAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow);342 WEBCORE_EXPORT void cancel TextAutoscroll();341 WEBCORE_EXPORT void startSelectionAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow); 342 WEBCORE_EXPORT void cancelSelectionAutoscroll(); 343 343 IntPoint m_targetAutoscrollPositionInWindow; 344 344 bool m_isAutoscrolling { false }; -
trunk/Source/WebCore/page/ios/EventHandlerIOS.mm
r228531 r228549 563 563 } 564 564 565 void EventHandler::startTextAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow) 566 { 567 m_targetAutoscrollPositionInWindow = roundedIntPoint(positionInWindow); 565 void EventHandler::startSelectionAutoscroll(RenderObject* renderer, const FloatPoint& positionInWindow) 566 { 567 Ref<Frame> protectedFrame(m_frame); 568 569 m_targetAutoscrollPositionInWindow = protectedFrame->view()->contentsToView(roundedIntPoint(positionInWindow)); 570 568 571 m_isAutoscrolling = true; 569 572 m_autoscrollController->startAutoscrollForSelection(renderer); 570 573 } 571 574 572 void EventHandler::cancel TextAutoscroll()575 void EventHandler::cancelSelectionAutoscroll() 573 576 { 574 577 m_isAutoscrolling = false; 575 578 m_autoscrollController->stopAutoscrollTimer(); 576 579 } 580 581 static 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 } 577 624 578 625 IntPoint EventHandler::targetPositionInWindowForSelectionAutoscroll() const 579 626 { 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; 581 635 } 582 636 -
trunk/Source/WebKit/ChangeLog
r228532 r228549 1 2018-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 1 23 2018-02-15 John Wilander <wilander@apple.com> 2 24 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r228393 r228549 763 763 764 764 #pragma mark - UITextAutoscrolling 765 - (void)startAutoscroll:(CGPoint)point 766 { 767 _page->startAutoscrollAtPosition(point );765 - (void)startAutoscroll:(CGPoint)pointInDocument 766 { 767 _page->startAutoscrollAtPosition(pointInDocument); 768 768 } 769 769 … … 918 918 919 919 _resigningFirstResponder = YES; 920 921 920 if (!_webView->_activeFocusedStateRetainCount) { 922 921 // We need to complete the editing operation before we blur the element. … … 3134 3133 - (UITextRange *)selectedTextRange 3135 3134 { 3136 if (_page->editorState().selectionIsNone )3135 if (_page->editorState().selectionIsNone || _page->editorState().isMissingPostLayoutData) 3137 3136 return nil; 3138 3137 auto& postLayoutEditorStateData = _page->editorState().postLayoutData(); -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r227377 r228549 735 735 } 736 736 737 void WebPageProxy::startAutoscrollAtPosition(const WebCore::FloatPoint& position )738 { 739 m_process->send(Messages::WebPage::StartAutoscrollAtPosition(position ), m_pageID);737 void WebPageProxy::startAutoscrollAtPosition(const WebCore::FloatPoint& positionInWindow) 738 { 739 m_process->send(Messages::WebPage::StartAutoscrollAtPosition(positionInWindow), m_pageID); 740 740 } 741 741 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r228260 r228549 1825 1825 { 1826 1826 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 } 1828 1839 } 1829 1840 1830 1841 void WebPage::cancelAutoscroll() 1831 1842 { 1832 m_page->mainFrame().eventHandler().cancel TextAutoscroll();1843 m_page->mainFrame().eventHandler().cancelSelectionAutoscroll(); 1833 1844 } 1834 1845
Note:
See TracChangeset
for help on using the changeset viewer.