Title: [286886] trunk/Source
Revision
286886
Author
megan_gard...@apple.com
Date
2021-12-10 16:46:51 -0800 (Fri, 10 Dec 2021)

Log Message

Image does not update after Markup Pane is dismissed.
https://bugs.webkit.org/show_bug.cgi?id=234162

Reviewed by Devin Rousso.

Once the item is retured from the Sharing Service, we need to pipe the information
back to the attachement element so that it can be properly updated.
This includes holding onto the attachment ID of the controlled image so that it
can later be found and updated.

Source/WebCore:

* dom/mac/ImageControlsMac.cpp:
(WebCore::ImageControlsMac::handleEvent):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::setAttachmentElement):
* page/ChromeClient.h:
(WebCore::ChromeClient::handleImageServiceClick):

Source/WebKit:

* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::encode const):
(WebKit::ContextMenuContextData::decode):
* Shared/ContextMenuContextData.h:
(WebKit::ContextMenuContextData::controlledImageAttachmentID const):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]):
* UIProcess/API/Cocoa/_WKAttachment.h:
* UIProcess/API/Cocoa/_WKAttachment.mm:
(-[_WKAttachment setData:newContentType:]):
* UIProcess/API/Cocoa/_WKAttachmentInternal.h:
* UIProcess/mac/WKSharingServicePickerDelegate.h:
* UIProcess/mac/WKSharingServicePickerDelegate.mm:
(-[WKSharingServicePickerDelegate setAttachmentID:]):
(-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::setupServicesMenu):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::handleImageServiceClick):
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::handleImageServiceClick):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286885 => 286886)


--- trunk/Source/WebCore/ChangeLog	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebCore/ChangeLog	2021-12-11 00:46:51 UTC (rev 286886)
@@ -1,3 +1,22 @@
+2021-12-10  Megan Gardner  <megan_gard...@apple.com>
+
+        Image does not update after Markup Pane is dismissed.
+        https://bugs.webkit.org/show_bug.cgi?id=234162
+
+        Reviewed by Devin Rousso.
+
+        Once the item is retured from the Sharing Service, we need to pipe the information
+        back to the attachement element so that it can be properly updated.
+        This includes holding onto the attachment ID of the controlled image so that it 
+        can later be found and updated.
+
+        * dom/mac/ImageControlsMac.cpp:
+        (WebCore::ImageControlsMac::handleEvent):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::setAttachmentElement):
+        * page/ChromeClient.h:
+        (WebCore::ChromeClient::handleImageServiceClick):
+
 2021-12-10  Don Olmstead  <don.olmst...@sony.com>
 
         Add FileSystem function to read a file at a path

Modified: trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp (286885 => 286886)


--- trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp	2021-12-11 00:46:51 UTC (rev 286886)
@@ -31,6 +31,7 @@
 #include "ContextMenuController.h"
 #include "ElementInlines.h"
 #include "EventHandler.h"
+#include "HTMLAttachmentElement.h"
 #include "HTMLButtonElement.h"
 #include "HTMLDivElement.h"
 #include "HTMLImageElement.h"
@@ -126,11 +127,13 @@
     auto& node = downcast<Node>(*mouseEvent.target());
 
     if (ImageControlsMac::isImageControlsButtonElement(node)) {
-        auto imageElement = node.shadowHost();
-        if (!imageElement)
+        auto shadowHost = node.shadowHost();
+        if (!is<HTMLImageElement>(*shadowHost))
             return false;
-        if (auto* image = imageFromImageElementNode(*imageElement)) {
-            page->chrome().client().handleImageServiceClick(roundedIntPoint(mouseEvent.absoluteLocation()), *image, imageElement->isContentEditable(), imageElement->renderBox()->absoluteContentQuad().enclosingBoundingBox());
+        if (auto* image = imageFromImageElementNode(*shadowHost)) {
+            HTMLImageElement& imageElement = downcast<HTMLImageElement>(*shadowHost);
+            auto attachmentID = HTMLAttachmentElement::getAttachmentIdentifier(imageElement);
+            page->chrome().client().handleImageServiceClick(roundedIntPoint(mouseEvent.absoluteLocation()), *image, imageElement.isContentEditable(), imageElement.renderBox()->absoluteContentQuad().enclosingBoundingBox(), attachmentID);
             event.setDefaultHandled();
             return true;
         }

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (286885 => 286886)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-12-11 00:46:51 UTC (rev 286886)
@@ -743,6 +743,7 @@
 
     attachment->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true);
     ensureUserAgentShadowRoot().appendChild(WTFMove(attachment));
+    setAttributeWithoutSynchronization(webkitimagemenuAttr, emptyString());
 }
 
 RefPtr<HTMLAttachmentElement> HTMLImageElement::attachmentElement() const

Modified: trunk/Source/WebCore/page/ChromeClient.h (286885 => 286886)


--- trunk/Source/WebCore/page/ChromeClient.h	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebCore/page/ChromeClient.h	2021-12-11 00:46:51 UTC (rev 286886)
@@ -532,7 +532,7 @@
 #if ENABLE(SERVICE_CONTROLS)
     virtual void handleSelectionServiceClick(FrameSelection&, const Vector<String>&, const IntPoint&) { }
     virtual bool hasRelevantSelectionServices(bool /*isTextOnly*/) const { return false; }
-    virtual void handleImageServiceClick(const IntPoint&, Image&, bool /*isEditable*/, const IntRect&) { }
+    virtual void handleImageServiceClick(const IntPoint&, Image&, bool /*isEditable*/, const IntRect&, const String& /*attachmentID*/) { }
 #endif
 
     virtual bool shouldDispatchFakeMouseMoveEvents() const { return true; }

Modified: trunk/Source/WebKit/ChangeLog (286885 => 286886)


--- trunk/Source/WebKit/ChangeLog	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/ChangeLog	2021-12-11 00:46:51 UTC (rev 286886)
@@ -1,3 +1,40 @@
+2021-12-10  Megan Gardner  <megan_gard...@apple.com>
+
+        Image does not update after Markup Pane is dismissed.
+        https://bugs.webkit.org/show_bug.cgi?id=234162
+
+        Reviewed by Devin Rousso.
+
+        Once the item is retured from the Sharing Service, we need to pipe the information
+        back to the attachement element so that it can be properly updated.
+        This includes holding onto the attachment ID of the controlled image so that it 
+        can later be found and updated.
+
+        * Shared/ContextMenuContextData.cpp:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::ContextMenuContextData::encode const):
+        (WebKit::ContextMenuContextData::decode):
+        * Shared/ContextMenuContextData.h:
+        (WebKit::ContextMenuContextData::controlledImageAttachmentID const):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration init]):
+        * UIProcess/API/Cocoa/_WKAttachment.h:
+        * UIProcess/API/Cocoa/_WKAttachment.mm:
+        (-[_WKAttachment setData:newContentType:]):
+        * UIProcess/API/Cocoa/_WKAttachmentInternal.h:
+        * UIProcess/mac/WKSharingServicePickerDelegate.h:
+        * UIProcess/mac/WKSharingServicePickerDelegate.mm:
+        (-[WKSharingServicePickerDelegate setAttachmentID:]):
+        (-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::setupServicesMenu):
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::handleImageServiceClick):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::handleImageServiceClick):
+
 2021-12-10  Aditya Keerthi  <akeer...@apple.com>
 
         [iOS] Support find-in-page keyboard shortcuts

Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.cpp (286885 => 286886)


--- trunk/Source/WebKit/Shared/ContextMenuContextData.cpp	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.cpp	2021-12-11 00:46:51 UTC (rev 286886)
@@ -67,11 +67,12 @@
 }
 
 #if ENABLE(SERVICE_CONTROLS)
-ContextMenuContextData::ContextMenuContextData(const WebCore::IntPoint& menuLocation, WebCore::Image& image, bool isEditable, const WebCore::IntRect& imageRect)
+ContextMenuContextData::ContextMenuContextData(const WebCore::IntPoint& menuLocation, WebCore::Image& image, bool isEditable, const WebCore::IntRect& imageRect, const String& attachmentID)
     : m_type(Type::ServicesMenu)
     , m_menuLocation(menuLocation)
     , m_selectionIsEditable(isEditable)
     , m_controlledImageBounds(imageRect)
+    , m_controlledImageAttachmentID(attachmentID)
 {
     setImage(&image);
 }
@@ -104,6 +105,7 @@
     encoder << m_selectedTelephoneNumbers;
     encoder << m_selectionIsEditable;
     encoder << m_controlledImageBounds;
+    encoder << m_controlledImageAttachmentID;
 #endif
 }
 
@@ -140,6 +142,8 @@
         return false;
     if (!decoder.decode(result.m_controlledImageBounds))
         return false;
+    if (!decoder.decode(result.m_controlledImageAttachmentID))
+        return false;
 #endif
 
     return true;

Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.h (286885 => 286886)


--- trunk/Source/WebKit/Shared/ContextMenuContextData.h	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.h	2021-12-11 00:46:51 UTC (rev 286886)
@@ -64,7 +64,7 @@
     {
     }
     
-    ContextMenuContextData(const WebCore::IntPoint& menuLocation, WebCore::Image&, bool isEditable, const WebCore::IntRect& imageRect);
+    ContextMenuContextData(const WebCore::IntPoint& menuLocation, WebCore::Image&, bool isEditable, const WebCore::IntRect& imageRect, const String& attachmentID);
 
     ShareableBitmap* controlledImage() const { return m_controlledImage.get(); }
     const Vector<uint8_t>& controlledSelectionData() const { return m_controlledSelectionData; }
@@ -73,6 +73,7 @@
     bool isServicesMenu() const { return m_type == ContextMenuContextData::Type::ServicesMenu; }
     bool controlledDataIsEditable() const;
     WebCore::IntRect controlledImageBounds() const { return m_controlledImageBounds; };
+    String controlledImageAttachmentID() const { return m_controlledImageAttachmentID; };
 #endif
 
     void encode(IPC::Encoder&) const;
@@ -95,6 +96,7 @@
     Vector<String> m_selectedTelephoneNumbers;
     bool m_selectionIsEditable;
     WebCore::IntRect m_controlledImageBounds;
+    String m_controlledImageAttachmentID;
 #endif
 };
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm (286885 => 286886)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm	2021-12-11 00:46:51 UTC (rev 286886)
@@ -150,6 +150,12 @@
     });
 }
 
+- (void)setData:(NSData *)data newContentType:(NSString *)newContentType
+{
+    auto fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data]);
+    [self setFileWrapper:fileWrapper.get() contentType:newContentType completion:nil];
+}
+
 - (void)setData:(NSData *)data newContentType:(NSString *)newContentType newFilename:(NSString *)newFilename completion:(void(^)(NSError *))completionHandler
 {
     auto fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data]);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachmentInternal.h (286885 => 286886)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachmentInternal.h	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachmentInternal.h	2021-12-11 00:46:51 UTC (rev 286886)
@@ -38,4 +38,6 @@
 @package
     API::ObjectStorage<API::Attachment> _attachment;
 }
+
+- (void)setData:(NSData *)data newContentType:(NSString *)newContentType;
 @end

Modified: trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.h (286885 => 286886)


--- trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.h	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.h	2021-12-11 00:46:51 UTC (rev 286886)
@@ -39,6 +39,7 @@
     BOOL _filterEditingServices;
     BOOL _handleEditingReplacement;
     NSRect _sourceFrame;
+    String _attachmentID;
 }
 
 + (WKSharingServicePickerDelegate *)sharedSharingServicePickerDelegate;
@@ -48,6 +49,7 @@
 - (void)setFiltersEditingServices:(BOOL)filtersEditingServices;
 - (void)setHandlesEditingReplacement:(BOOL)handlesEditingReplacement;
 - (void)setSourceFrame:(NSRect)sourceFrame;
+- (void)setAttachmentID:(String)attachmentID;
 
 @end
 

Modified: trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm (286885 => 286886)


--- trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm	2021-12-11 00:46:51 UTC (rev 286886)
@@ -28,9 +28,12 @@
 
 #if ENABLE(SERVICE_CONTROLS)
 
+#import "APIAttachment.h"
 #import "DataReference.h"
+#import "WKObject.h"
 #import "WebContextMenuProxyMac.h"
 #import "WebPageProxy.h"
+#import "_WKAttachmentInternal.h"
 #import <WebCore/LegacyNSPasteboardTypes.h>
 #import <pal/spi/mac/NSSharingServicePickerSPI.h>
 #import <pal/spi/mac/NSSharingServiceSPI.h>
@@ -75,6 +78,11 @@
     _sourceFrame = sourceFrame;
 }
 
+- (void)setAttachmentID:(String)attachmentID
+{
+    _attachmentID = attachmentID;
+}
+
 - (NSArray *)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker sharingServicesForItems:(NSArray *)items mask:(NSSharingServiceMask)mask proposedSharingServices:(NSArray *)proposedServices
 {
     if (!_filterEditingServices)
@@ -108,7 +116,7 @@
 - (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items
 {
     // We only care about what item was shared if we were interested in editor services
-    // (i.e., if we plan on replacing the selection with the returned item)
+    // (i.e., if we plan on replacing the selection or controlled image with the returned item)
     if (!_handleEditingReplacement)
         return;
 
@@ -136,6 +144,20 @@
 
         dataReference = IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length]);
         types.append(NSPasteboardTypeTIFF);
+    } else if ([item isKindOfClass:[NSItemProvider class]]) {
+        NSItemProvider *itemProvider = (NSItemProvider *)item;
+        
+        ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+        [itemProvider loadDataRepresentationForTypeIdentifier:(NSString *)kUTTypeData completionHandler:^(NSData *data, NSError *error) {
+            if (error)
+                return;
+            
+            auto apiAttachment = _menuProxy->page()->attachmentForIdentifier(_attachmentID);
+            auto attachment = wrapper(apiAttachment);
+            [attachment setData:data newContentType:String(NSPasteboardTypeTIFF)];
+        }];
+        ALLOW_DEPRECATED_DECLARATIONS_END
+        return;
     } else {
         LOG_ERROR("sharingService:didShareItems: - Unknown item type returned\n");
         return;

Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (286885 => 286886)


--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm	2021-12-11 00:46:51 UTC (rev 286886)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(MAC)
 
+#import "APIAttachment.h"
 #import "APIContextMenuClient.h"
 #import "MenuUtilities.h"
 #import "PageClientImplMac.h"
@@ -243,6 +244,7 @@
     imageRect = [m_webView convertRect:imageRect toView:nil];
     imageRect = [[m_webView window] convertRectToScreen:imageRect];
     [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setSourceFrame:imageRect];
+    [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setAttachmentID:m_context.controlledImageAttachmentID()];
 
     m_menu = adoptNS([[picker menu] copy]);
 

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (286885 => 286886)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2021-12-11 00:46:51 UTC (rev 286886)
@@ -1347,9 +1347,9 @@
     return (isTextOnly && WebProcess::singleton().hasSelectionServices()) || WebProcess::singleton().hasRichContentServices();
 }
 
-void WebChromeClient::handleImageServiceClick(const IntPoint& point, Image& image, bool isEditable, const IntRect& imageRect)
+void WebChromeClient::handleImageServiceClick(const IntPoint& point, Image& image, bool isEditable, const IntRect& imageRect, const String& attachmentID)
 {
-    m_page.handleImageServiceClick(point, image, isEditable, imageRect);
+    m_page.handleImageServiceClick(point, image, isEditable, imageRect, attachmentID);
 }
 
 #endif

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (286885 => 286886)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2021-12-11 00:46:51 UTC (rev 286886)
@@ -381,7 +381,7 @@
 #if ENABLE(SERVICE_CONTROLS)
     void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&) final;
     bool hasRelevantSelectionServices(bool isTextOnly) const final;
-    void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable, const WebCore::IntRect&) final;
+    void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable, const WebCore::IntRect&, const String& /*attachmentID*/) final;
 #endif
 
     bool shouldDispatchFakeMouseMoveEvents() const final;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (286885 => 286886)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-12-11 00:46:51 UTC (rev 286886)
@@ -1204,7 +1204,7 @@
 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
     void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&);
     void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&);
-    void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable, const WebCore::IntRect&);
+    void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable, const WebCore::IntRect&, const String& attachmentID);
 #endif
 
     void didChangeScrollOffsetForFrame(WebCore::Frame*);

Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (286885 => 286886)


--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2021-12-11 00:40:58 UTC (rev 286885)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2021-12-11 00:46:51 UTC (rev 286886)
@@ -828,9 +828,9 @@
     send(Messages::WebPageProxy::ShowContextMenu(ContextMenuContextData(point, selectionDataVector, phoneNumbers, selection.selection().isContentEditable()), UserData()));
 }
 
-void WebPage::handleImageServiceClick(const IntPoint& point, Image& image, bool isEditable, const IntRect& imageRect)
+void WebPage::handleImageServiceClick(const IntPoint& point, Image& image, bool isEditable, const IntRect& imageRect, const String& attachmentID)
 {
-    send(Messages::WebPageProxy::ShowContextMenu(ContextMenuContextData(point, image, isEditable, imageRect), UserData()));
+    send(Messages::WebPageProxy::ShowContextMenu(ContextMenuContextData(point, image, isEditable, imageRect, attachmentID), UserData()));
 }
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to