[iOS] Avoid using a TextIndicator if there are non-text things to indicate
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Jul 2015 19:58:02 +0000 (19:58 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Jul 2015 19:58:02 +0000 (19:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147152
<rdar://problem/21921061>

Reviewed by Beth Dakin.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView willPresentPreviewViewController:forPosition:inSourceView:]):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::shouldUseTextIndicatorForLink):
(WebKit::WebPage::getPositionInformation):
Fall back to a rectangular area instead of a TextIndicator if there are any
non-inline elements inside the link.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187117 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index f68f1f3..038dd62 100644 (file)
@@ -1,3 +1,19 @@
+2015-07-21  Tim Horton  <timothy_horton@apple.com>
+
+        [iOS] Avoid using a TextIndicator if there are non-text things to indicate
+        https://bugs.webkit.org/show_bug.cgi?id=147152
+        <rdar://problem/21921061>
+
+        Reviewed by Beth Dakin.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView willPresentPreviewViewController:forPosition:inSourceView:]):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::shouldUseTextIndicatorForLink):
+        (WebKit::WebPage::getPositionInformation):
+        Fall back to a rectangular area instead of a TextIndicator if there are any
+        non-inline elements inside the link.
+
 2015-07-21  Andreas Kling  <akling@apple.com>
 
         API::Session should clean up its storage in the network process when destroyed.
index c546f14..6ccb478 100644 (file)
@@ -3331,9 +3331,14 @@ static bool isAssistableInputType(InputType type)
 
     [_previewIndicatorView removeFromSuperview];
 
+    float deviceScaleFactor = _page->deviceScaleFactor();
+
     RefPtr<Image> image = _positionInformation.linkIndicator.contentImage;
     if (!image) {
-        [[viewController presentationController] setSourceRect:_positionInformation.bounds];
+        IntRect sourceRect = _positionInformation.bounds;
+        const float marginInPoints = 4;
+        sourceRect.inflate(marginInPoints * deviceScaleFactor);
+        [[viewController presentationController] setSourceRect:sourceRect];
         [[viewController presentationController] setSourceView:self];
         return;
     }
@@ -3341,7 +3346,6 @@ static bool isAssistableInputType(InputType type)
     RetainPtr<UIImage> indicatorImage = adoptNS([[UIImage alloc] initWithCGImage:image->getCGImageRef()]);
     _previewIndicatorView = adoptNS([[UIImageView alloc] initWithImage:indicatorImage.get()]);
 
-    float deviceScaleFactor = _page->deviceScaleFactor();
     const float cornerRadiusInPoints = 5;
     Path path = PathUtilities::pathWithShrinkWrappedRects(_positionInformation.linkIndicator.textRectsInBoundingRectCoordinates, cornerRadiusInPoints * deviceScaleFactor);
     RetainPtr<CAShapeLayer> maskLayer = adoptNS([[CAShapeLayer alloc] init]);
index 6067252..cdf8eea 100644 (file)
@@ -63,6 +63,7 @@
 #import <WebCore/GeometryUtilities.h>
 #import <WebCore/HTMLElementTypeHelpers.h>
 #import <WebCore/HTMLFormElement.h>
+#import <WebCore/HTMLImageElement.h>
 #import <WebCore/HTMLInputElement.h>
 #import <WebCore/HTMLOptGroupElement.h>
 #import <WebCore/HTMLOptionElement.h>
@@ -2143,6 +2144,19 @@ static Element* containingLinkElement(Element* element)
     return nullptr;
 }
 
+static bool shouldUseTextIndicatorForLink(Element& element)
+{
+    if (element.renderer() && !element.renderer()->isInline())
+        return false;
+
+    for (auto& child : descendantsOfType<Element>(element)) {
+        if (child.renderer() && !child.renderer()->isInline())
+            return false;
+    }
+
+    return true;
+}
+
 void WebPage::getPositionInformation(const IntPoint& point, InteractionInformationAtPosition& info)
 {
     FloatPoint adjustedPoint;
@@ -2194,13 +2208,15 @@ void WebPage::getPositionInformation(const IntPoint& point, InteractionInformati
                     if (RefPtr<WebImage> snapshot = snapshotNode(*element, SnapshotOptionsShareable, 600 * 1024))
                         info.image = snapshot->bitmap();
 
-                    RefPtr<Range> linkRange = rangeOfContents(*linkElement);
-                    if (linkRange) {
-                        float deviceScaleFactor = corePage()->deviceScaleFactor();
-                        const float marginInPoints = 4;
-                        RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(*linkRange, TextIndicatorPresentationTransition::None, marginInPoints * deviceScaleFactor);
-                        if (textIndicator)
-                            info.linkIndicator = textIndicator->data();
+                    if (shouldUseTextIndicatorForLink(*linkElement)) {
+                        RefPtr<Range> linkRange = rangeOfContents(*linkElement);
+                        if (linkRange) {
+                            float deviceScaleFactor = corePage()->deviceScaleFactor();
+                            const float marginInPoints = 4;
+                            RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(*linkRange, TextIndicatorPresentationTransition::None, marginInPoints * deviceScaleFactor);
+                            if (textIndicator)
+                                info.linkIndicator = textIndicator->data();
+                        }
                     }
                 } else if (element->renderer() && element->renderer()->isRenderImage()) {
                     auto& renderImage = downcast<RenderImage>(*(element->renderer()));