Attachment elements are missing context menu previews
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jun 2019 10:46:24 +0000 (10:46 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jun 2019 10:46:24 +0000 (10:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198946

Reviewed by Tim Horton.

When requesting position information on an <attachment> element,
we were not providing a snapshot image.

* WebProcess/WebPage/WebPage.h: New common method to take a snapshot.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::shareableBitmapSnapshotForNode): New helper.
(WebKit::WebPage::positionInformation): If the element is an attachment,
then ask for a snapshot.

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index 14e9937..5f21dbd 100644 (file)
@@ -1,3 +1,19 @@
+2019-06-18  Dean Jackson  <dino@apple.com>
+
+        Attachment elements are missing context menu previews
+        https://bugs.webkit.org/show_bug.cgi?id=198946
+
+        Reviewed by Tim Horton.
+
+        When requesting position information on an <attachment> element,
+        we were not providing a snapshot image.
+
+        * WebProcess/WebPage/WebPage.h: New common method to take a snapshot.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::shareableBitmapSnapshotForNode): New helper.
+        (WebKit::WebPage::positionInformation): If the element is an attachment,
+        then ask for a snapshot.
+
 2019-06-17  Tim Horton  <timothy_horton@apple.com>
 
         Expose DataDetectors context generation on WKContentViewInteraction
index aa73058..0bba97d 100644 (file)
@@ -1251,6 +1251,7 @@ private:
 
     void sendPositionInformation(InteractionInformationAtPosition&&);
     InteractionInformationAtPosition positionInformation(const InteractionInformationRequest&);
+    RefPtr<ShareableBitmap> shareableBitmapSnapshotForNode(WebCore::Element&);
     WebAutocorrectionContext autocorrectionContext();
     bool applyAutocorrectionInternal(const String& correction, const String& originalText);
     bool shouldIgnoreMetaViewport() const;
index c6dbee9..5aaca4b 100644 (file)
@@ -2656,6 +2656,14 @@ static void textInteractionPositionInformation(WebPage& page, const HTMLInputEle
 }
 #endif
 
+RefPtr<ShareableBitmap> WebPage::shareableBitmapSnapshotForNode(Element& element)
+{
+    // Ensure that the image contains at most 600K pixels, so that it is not too big.
+    if (RefPtr<WebImage> snapshot = snapshotNode(element, SnapshotOptionsShareable, 600 * 1024))
+        return &snapshot->bitmap();
+    return nullptr;
+}
+
 InteractionInformationAtPosition WebPage::positionInformation(const InteractionInformationRequest& request)
 {
     InteractionInformationAtPosition info;
@@ -2678,16 +2686,19 @@ InteractionInformationAtPosition WebPage::positionInformation(const InteractionI
         Element& element = downcast<Element>(*hitNode);
         elementPositionInformation(*this, element, request, info);
 
-        if (info.isLink && !info.isImage && request.includeSnapshot) {
-            // Ensure that the image contains at most 600K pixels, so that it is not too big.
-            if (RefPtr<WebImage> snapshot = snapshotNode(element, SnapshotOptionsShareable, 600 * 1024))
-                info.image = &snapshot->bitmap();
-        }
+        if (info.isLink && !info.isImage && request.includeSnapshot)
+            info.image = shareableBitmapSnapshotForNode(element);
     }
 
-    if (!(info.isLink || info.isImage))
+    if (!(info.isLink || info.isImage)) {
         selectionPositionInformation(*this, request, info);
 
+        if (info.isAttachment && request.includeSnapshot) {
+            Element& element = downcast<Element>(*hitNode);
+            info.image = shareableBitmapSnapshotForNode(element);
+        }
+    }
+
     // Prevent the callout bar from showing when tapping on the datalist button.
 #if ENABLE(DATALIST_ELEMENT)
     if (is<HTMLInputElement>(hitNode)) {