Skip to content
Permalink
Browse files
[macOS 13] Share Sheet header displays a generic icon and is missing …
…a title when sharing an image

https://bugs.webkit.org/show_bug.cgi?id=245790
rdar://99706364

Reviewed by Tim Horton.

On macOS 13, the Share Sheet has a header representing the content being
shared. WebKit is currently not providing any preview information when sharing
an image, resulting in a generic icon and missing title in the header.

To fix, provide an `NSPreviewRepresentingActivityItem` to the Share Sheet when
an image is being shared.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/en.lproj/Localizable.strings:
* Source/WebKit/Shared/WebHitTestResultData.cpp:
(WebKit::WebHitTestResultData::WebHitTestResultData):

Use the "title" attribute to provide a title for the preview. If a title is
missing, use the alt text instead.

(WebKit::WebHitTestResultData::encode const):
(WebKit::WebHitTestResultData::decode):
* Source/WebKit/Shared/WebHitTestResultData.h:
* Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::getShareMenuItem):

If no title is available from the web content, fallback to using a generic title.

Canonical link: https://commits.webkit.org/254976@main
  • Loading branch information
pxlcoder committed Sep 28, 2022
1 parent 4d1b746 commit f0f73dc0e8a5b5c59348fcd6458095294e01024a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
@@ -1293,6 +1293,10 @@
#define HAVE_POWERLOG_TASK_MODE_QUERY 1
#endif

#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000)
#define HAVE_NSPREVIEWREPRESENTINGACTIVITYITEM 1
#endif

#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 160000) \
|| PLATFORM(WATCHOS) \
|| PLATFORM(APPLETV)
@@ -553,6 +553,9 @@
/* Ignore Spelling context menu item */
"Ignore Spelling" = "Ignore Spelling";

/* Fallback title for images in the share sheet */
"Image" = "Image";

/* Undo action name */
"Indent (Undo action name)" = "Indent";

@@ -23,6 +23,7 @@
#include "ShareableBitmapUtilities.h"
#include "WebCoreArgumentCoders.h"
#include <WebCore/Document.h>
#include <WebCore/ElementInlines.h>
#include <WebCore/Frame.h>
#include <WebCore/FrameView.h>
#include <WebCore/HitTestResult.h>
@@ -95,6 +96,16 @@ WebHitTestResultData::WebHitTestResultData(const HitTestResult& hitTestResult, b
if (auto* image = cachedImage->image())
sourceImageMIMEType = image->mimeType();
}

imageText = [&]() -> String {
if (auto* element = dynamicDowncast<Element>(target.get())) {
auto& title = element->attributeWithoutSynchronization(HTMLNames::titleAttr);
if (!title.isEmpty())
return title;
}

return renderer->altText();
}();
}
}
}
@@ -121,6 +132,7 @@ void WebHitTestResultData::encode(IPC::Encoder& encoder) const
encoder << isDownloadableMedia;
encoder << lookupText;
encoder << toolTipText;
encoder << imageText;
encoder << dictionaryPopupInfo;

WebKit::SharedMemory::Handle imageHandle;
@@ -161,6 +173,7 @@ bool WebHitTestResultData::decode(IPC::Decoder& decoder, WebHitTestResultData& h
|| !decoder.decode(hitTestResultData.isDownloadableMedia)
|| !decoder.decode(hitTestResultData.lookupText)
|| !decoder.decode(hitTestResultData.toolTipText)
|| !decoder.decode(hitTestResultData.imageText)
|| !decoder.decode(hitTestResultData.dictionaryPopupInfo))
return false;

@@ -63,6 +63,7 @@ struct WebHitTestResultData {

String lookupText;
String toolTipText;
String imageText;
RefPtr<SharedMemory> imageSharedMemory;
RefPtr<ShareableBitmap> imageBitmap;
String sourceImageMIMEType;
@@ -420,8 +420,18 @@ static void getStandardShareMenuItem(NSArray *items, void (^completionHandler)(N
}

if (hitTestData.imageSharedMemory) {
if (auto image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSharedMemory->size()]]))
if (auto image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSharedMemory->size()]])) {
#if HAVE(NSPREVIEWREPRESENTINGACTIVITYITEM)
NSString *title = hitTestData.imageText;
if (!title.length)
title = WEB_UI_NSSTRING(@"Image", "Fallback title for images in the share sheet");

auto activityItem = adoptNS([[NSPreviewRepresentingActivityItem alloc] initWithItem:image.get() title:title image:image.get() icon:nil]);
[items addObject:activityItem.get()];
#else
[items addObject:image.get()];
#endif
}
}

if (!m_context.selectedText().isEmpty())

0 comments on commit f0f73dc

Please sign in to comment.