Title: [246090] trunk/Source/WebKit
Revision
246090
Author
[email protected]
Date
2019-06-04 17:23:59 -0700 (Tue, 04 Jun 2019)

Log Message

Unreviewed, rolling out r246086.
https://bugs.webkit.org/show_bug.cgi?id=198549

Causing Internal build failures (Requested by ShawnRoberts on
#webkit).

Reverted changeset:

"Remove some unused selection code"
https://bugs.webkit.org/show_bug.cgi?id=198451
https://trac.webkit.org/changeset/246086

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (246089 => 246090)


--- trunk/Source/WebKit/ChangeLog	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/ChangeLog	2019-06-05 00:23:59 UTC (rev 246090)
@@ -1,3 +1,17 @@
+2019-06-04  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r246086.
+        https://bugs.webkit.org/show_bug.cgi?id=198549
+
+        Causing Internal build failures (Requested by ShawnRoberts on
+        #webkit).
+
+        Reverted changeset:
+
+        "Remove some unused selection code"
+        https://bugs.webkit.org/show_bug.cgi?id=198451
+        https://trac.webkit.org/changeset/246086
+
 2019-06-04  Tim Horton  <[email protected]>
 
         Turn on background color estimation for all link indicators

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (246089 => 246090)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2019-06-05 00:23:59 UTC (rev 246090)
@@ -530,10 +530,33 @@
 - (UIColor *)_inheritedInteractionTintColor;
 @end
 
+@interface UIWebSelectionView : UIView
+@end
+
+@interface UIWebSelectionAssistant : NSObject <UIGestureRecognizerDelegate>
+@end
+
 @protocol UISelectionInteractionAssistant
 - (void)showSelectionCommands;
 @end
 
+@interface UIWebSelectionAssistant ()
+- (BOOL)isSelectionGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
+- (id)initWithView:(UIView *)view;
+- (void)clearSelection;
+- (void)didEndScrollingOrZoomingPage;
+- (void)didEndScrollingOverflow;
+- (void)resignedFirstResponder;
+- (void)selectionChanged;
+- (void)setGestureRecognizers;
+- (void)willStartScrollingOrZoomingPage;
+- (void)willStartScrollingOverflow;
+#if !PLATFORM(IOSMAC)
+@property (nonatomic, retain) UIWebSelectionView *selectionView;
+#endif
+@property (nonatomic, readonly) CGRect selectionFrame;
+@end
+
 typedef NS_ENUM(NSInteger, UIWKSelectionTouch) {
     UIWKSelectionTouchStarted = 0,
     UIWKSelectionTouchMoved = 1,
@@ -563,18 +586,22 @@
     UIWKGestureTwoFingerSingleTap = 10,
     UIWKGestureTwoFingerRangedSelectGesture = 11,
     UIWKGestureTapOnLinkWithGesture = 12,
+    UIWKGestureMakeWebSelection = 13,
     UIWKGesturePhraseBoundary = 14,
 };
 
-@interface UIWebSelectionAssistant : NSObject
-@end
-
 @interface UIWKSelectionAssistant : UIWebSelectionAssistant
 @end
 
 @interface UIWKSelectionAssistant ()
-- (id)initWithView:(UIView *)view;
+- (BOOL)shouldHandleSingleTapAtPoint:(CGPoint)point;
+- (void)selectionChangedWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)gestureState withFlags:(UIWKSelectionFlags)flags;
+- (void)selectionChangedWithTouchAt:(CGPoint)point withSelectionTouch:(UIWKSelectionTouch)touch withFlags:(UIWKSelectionFlags)flags;
+- (void)showDictionaryFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect;
 - (void)showShareSheetFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect;
+- (void)showTextServiceFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect;
+- (void)lookup:(NSString *)textWithContext withRange:(NSRange)range fromRect:(CGRect)presentationRect;
+@property (nonatomic, readonly) UILongPressGestureRecognizer *selectionLongPressRecognizer;
 @end
 
 @interface UIWKAutocorrectionRects : NSObject

Modified: trunk/Source/WebKit/Shared/ios/GestureTypes.h (246089 => 246090)


--- trunk/Source/WebKit/Shared/ios/GestureTypes.h	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/Shared/ios/GestureTypes.h	2019-06-05 00:23:59 UTC (rev 246090)
@@ -42,6 +42,7 @@
     TwoFingerSingleTap,
     TwoFingerRangedSelectGesture,
     TapOnLinkWithGesture,
+    MakeWebSelection,
     PhraseBoundary
 };
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (246089 => 246090)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-05 00:23:59 UTC (rev 246090)
@@ -3278,6 +3278,8 @@
         return WebKit::GestureType::TwoFingerRangedSelectGesture;
     case UIWKGestureTapOnLinkWithGesture:
         return WebKit::GestureType::TapOnLinkWithGesture;
+    case UIWKGestureMakeWebSelection:
+        return WebKit::GestureType::MakeWebSelection;
     case UIWKGesturePhraseBoundary:
         return WebKit::GestureType::PhraseBoundary;
     }
@@ -3314,6 +3316,8 @@
         return UIWKGestureTwoFingerRangedSelectGesture;
     case WebKit::GestureType::TapOnLinkWithGesture:
         return UIWKGestureTapOnLinkWithGesture;
+    case WebKit::GestureType::MakeWebSelection:
+        return UIWKGestureMakeWebSelection;
     case WebKit::GestureType::PhraseBoundary:
         return UIWKGesturePhraseBoundary;
     }

Modified: trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (246089 => 246090)


--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2019-06-05 00:23:59 UTC (rev 246090)
@@ -522,7 +522,6 @@
 
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithURL:(NSURL *)url rect:(CGRect)boundingRect
 {
-    // FIXME: We should use WKShareSheet instead of UIWKSelectionAssistant for this.
     auto selectionAssistant = adoptNS([[UIWKSelectionAssistant alloc] initWithView:[_hostViewController view]]);
     [selectionAssistant showShareSheetFor:WTF::userVisibleString(url) fromRect:boundingRect];
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (246089 => 246090)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2019-06-05 00:23:59 UTC (rev 246090)
@@ -1238,6 +1238,7 @@
     void updateViewportSizeForCSSViewportUnits();
 
     static void convertSelectionRectsToRootView(WebCore::FrameView*, Vector<WebCore::SelectionRect>&);
+    RefPtr<WebCore::Range> rangeForWebSelectionAtPosition(const WebCore::IntPoint&, const WebCore::VisiblePosition&, SelectionFlags&);
     void getFocusedElementInformation(FocusedElementInformation&);
     void platformInitializeAccessibility();
     void generateSyntheticEditingCommand(SyntheticEditingCommandType);
@@ -1849,6 +1850,7 @@
 
     RefPtr<WebCore::Range> m_initialSelection;
     WebCore::VisibleSelection m_storedSelectionForAccessibility { WebCore::VisibleSelection() };
+    WebCore::IntSize m_blockSelectionDesiredSize;
     WebCore::FloatSize m_maximumUnobscuredSize;
     int32_t m_deviceOrientation { 0 };
     bool m_keyboardIsAttached { false };

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-06-05 00:11:10 UTC (rev 246089)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-06-05 00:23:59 UTC (rev 246090)
@@ -133,6 +133,9 @@
 namespace WebKit {
 using namespace WebCore;
 
+const int blockSelectionStartWidth = 100;
+const int blockSelectionStartHeight = 100;
+
 void WebPage::platformInitialize()
 {
     platformInitializeAccessibility();
@@ -1232,6 +1235,93 @@
     return boundingRect;
 }
 
+static bool canShrinkToTextSelection(Node* node)
+{
+    if (node && !is<Element>(*node))
+        node = node->parentElement();
+    
+    auto* renderer = (node) ? node->renderer() : nullptr;
+    return renderer && renderer->childrenInline() && (is<RenderBlock>(*renderer) && !downcast<RenderBlock>(*renderer).inlineContinuation()) && !renderer->isTable();
+}
+
+static bool hasCustomLineHeight(Node& node)
+{
+    auto* renderer = node.renderer();
+    return renderer && renderer->style().lineHeight().isSpecified();
+}
+    
+RefPtr<Range> WebPage::rangeForWebSelectionAtPosition(const IntPoint& point, const VisiblePosition& position, SelectionFlags& flags)
+{
+    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowUserAgentShadowContent | HitTestRequest::AllowChildFrameContent);
+
+    Node* currentNode = result.innerNode();
+    if (!currentNode)
+        return nullptr;
+    RefPtr<Range> range;
+    FloatRect boundingRectInScrollViewCoordinates;
+
+    if (!currentNode->isTextNode() && !canShrinkToTextSelection(currentNode) && hasCustomLineHeight(*currentNode)) {
+        auto* renderer = currentNode->renderer();
+        if (is<RenderBlockFlow>(renderer)) {
+            auto* renderText = downcast<RenderBlockFlow>(*renderer).findClosestTextAtAbsolutePoint(point);
+            if (renderText && renderText->textNode())
+                currentNode = renderText->textNode();
+        }
+    }
+
+    if (currentNode->isTextNode()) {
+        range = enclosingTextUnitOfGranularity(position, ParagraphGranularity, DirectionForward);
+        if (!range || range->collapsed())
+            range = Range::create(currentNode->document(), position, position);
+        else {
+            m_blockRectForTextSelection = selectionBoxForRange(range.get());
+            range = wordRangeFromPosition(position);
+        }
+
+        return range;
+    }
+
+    if (!currentNode->isElementNode())
+        currentNode = currentNode->parentElement();
+
+    Node* bestChoice = currentNode;
+    while (currentNode) {
+        if (currentNode->renderer()) {
+            boundingRectInScrollViewCoordinates = currentNode->renderer()->absoluteBoundingBoxRect(true);
+            boundingRectInScrollViewCoordinates.scale(m_page->pageScaleFactor());
+            if (boundingRectInScrollViewCoordinates.width() > m_blockSelectionDesiredSize.width() && boundingRectInScrollViewCoordinates.height() > m_blockSelectionDesiredSize.height())
+                break;
+            bestChoice = currentNode;
+        }
+        currentNode = currentNode->parentElement();
+    }
+
+    if (!bestChoice)
+        return nullptr;
+
+    RenderObject* renderer = bestChoice->renderer();
+    if (!renderer || renderer->style().userSelect() == UserSelect::None)
+        return nullptr;
+
+    if (renderer->childrenInline() && (is<RenderBlock>(*renderer) && !downcast<RenderBlock>(*renderer).inlineContinuation()) && !renderer->isTable()) {
+        range = enclosingTextUnitOfGranularity(position, WordGranularity, DirectionBackward);
+        if (range && !range->collapsed())
+            return range;
+    }
+
+    // If all we could find is a block whose height is very close to the height
+    // of the visible area, don't use it.
+    const float adjustmentFactor = .97;
+    boundingRectInScrollViewCoordinates = renderer->absoluteBoundingBoxRect(true);
+
+    if (boundingRectInScrollViewCoordinates.height() > m_page->mainFrame().view()->exposedContentRect().height() * adjustmentFactor)
+        return nullptr;
+
+    range = Range::create(bestChoice->document());
+    range->selectNodeContents(*bestChoice);
+    return range->collapsed() ? nullptr : range;
+}
+
 void WebPage::selectWithGesture(const IntPoint& point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithFocusedElement, CallbackID callbackID)
 {
     auto& frame = m_page->focusController().focusedOrMainFrame();
@@ -1375,6 +1465,14 @@
             range = enclosingTextUnitOfGranularity(position, ParagraphGranularity, DirectionForward);
         break;
 
+    case GestureType::MakeWebSelection:
+        if (wkGestureState == GestureRecognizerState::Began) {
+            m_blockSelectionDesiredSize.setWidth(blockSelectionStartWidth);
+            m_blockSelectionDesiredSize.setHeight(blockSelectionStartHeight);
+        }
+        range = rangeForWebSelectionAtPosition(point, position, flags);
+        break;
+
     default:
         break;
     }
@@ -1958,6 +2056,8 @@
     auto& frame = m_page->focusController().focusedOrMainFrame();
     RefPtr<Range> range = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
     if (!isInteractingWithFocusedElement) {
+        m_blockSelectionDesiredSize.setWidth(blockSelectionStartWidth);
+        m_blockSelectionDesiredSize.setHeight(blockSelectionStartHeight);
         auto* renderer = range ? range->startContainer().renderer() : nullptr;
         if (renderer && renderer->style().preserveNewline())
             m_blockRectForTextSelection = renderer->absoluteBoundingBoxRect(true);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to